Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Windows/Window.h
3 #ifndef __WINDOWS_WINDOW_H
4 #define __WINDOWS_WINDOW_H
6 #include "Windows/Defs.h"
7 #include "Common/String.h"
9 namespace NWindows {
11 inline ATOM MyRegisterClass(CONST WNDCLASS *wndClass)
12 { return ::RegisterClass(wndClass); }
14 #ifndef _UNICODE
15 ATOM MyRegisterClass(CONST WNDCLASSW *wndClass);
16 #endif
18 #ifdef _UNICODE
19 inline bool MySetWindowText(HWND wnd, LPCWSTR s) { return BOOLToBool(::SetWindowText(wnd, s)); }
20 #else
21 bool MySetWindowText(HWND wnd, LPCWSTR s);
22 #endif
26 class CWindow
27 {
28 private:
29 // bool ModifyStyleBase(int styleOffset, DWORD remove, DWORD add, UINT flags);
30 protected:
31 HWND _window;
32 public:
33 CWindow(HWND newWindow = NULL): _window(newWindow){};
34 CWindow& operator=(HWND newWindow)
35 {
36 _window = newWindow;
37 return *this;
38 }
39 operator HWND() const { return _window; }
40 void Attach(HWND newWindow) { _window = newWindow; }
41 HWND Detach()
42 {
43 HWND window = _window;
44 _window = NULL;
45 return window;
46 }
48 HWND GetParent() const { return ::GetParent(_window); }
49 bool GetWindowRect(LPRECT rect) const { return BOOLToBool(::GetWindowRect(_window,rect )); }
50 bool IsZoomed() const { return BOOLToBool(::IsZoomed(_window)); }
51 bool ClientToScreen(LPPOINT point) const { return BOOLToBool(::ClientToScreen(_window, point)); }
52 bool ScreenToClient(LPPOINT point) const { return BOOLToBool(::ScreenToClient(_window, point)); }
54 bool CreateEx(DWORD exStyle, LPCTSTR className,
55 LPCTSTR windowName, DWORD style,
56 int x, int y, int width, int height,
57 HWND parentWindow, HMENU idOrHMenu,
58 HINSTANCE instance, LPVOID createParam)
59 {
60 _window = ::CreateWindowEx(exStyle, className, windowName,
61 style, x, y, width, height, parentWindow,
62 idOrHMenu, instance, createParam);
63 return (_window != NULL);
64 }
66 bool Create(LPCTSTR className,
67 LPCTSTR windowName, DWORD style,
68 int x, int y, int width, int height,
69 HWND parentWindow, HMENU idOrHMenu,
70 HINSTANCE instance, LPVOID createParam)
71 {
72 _window = ::CreateWindow(className, windowName,
73 style, x, y, width, height, parentWindow,
74 idOrHMenu, instance, createParam);
75 return (_window != NULL);
76 }
78 #ifndef _UNICODE
79 bool Create(LPCWSTR className,
80 LPCWSTR windowName, DWORD style,
81 int x, int y, int width, int height,
82 HWND parentWindow, HMENU idOrHMenu,
83 HINSTANCE instance, LPVOID createParam);
84 bool CreateEx(DWORD exStyle, LPCWSTR className,
85 LPCWSTR windowName, DWORD style,
86 int x, int y, int width, int height,
87 HWND parentWindow, HMENU idOrHMenu,
88 HINSTANCE instance, LPVOID createParam);
89 #endif
92 bool Destroy()
93 {
94 if (_window == NULL)
95 return true;
96 bool result = BOOLToBool(::DestroyWindow(_window));
97 if(result)
98 _window = NULL;
99 return result;
100 }
101 bool IsWindow() { return BOOLToBool(::IsWindow(_window)); }
102 bool Move(int x, int y, int width, int height, bool repaint = true)
103 { return BOOLToBool(::MoveWindow(_window, x, y, width, height, BoolToBOOL(repaint))); }
104 bool GetClientRect(LPRECT rect) { return BOOLToBool(::GetClientRect(_window, rect)); }
105 bool Show(int cmdShow) { return BOOLToBool(::ShowWindow(_window, cmdShow)); }
106 bool SetPlacement(CONST WINDOWPLACEMENT *placement) { return BOOLToBool(::SetWindowPlacement(_window, placement)); }
107 bool GetPlacement(WINDOWPLACEMENT *placement) { return BOOLToBool(::GetWindowPlacement(_window, placement)); }
108 bool Update() { return BOOLToBool(::UpdateWindow(_window)); }
109 bool InvalidateRect(LPCRECT rect, bool backgroundErase = true)
110 { return BOOLToBool(::InvalidateRect(_window, rect, BoolToBOOL(backgroundErase))); }
111 void SetRedraw(bool redraw = true) { SendMessage(WM_SETREDRAW, BoolToBOOL(redraw), 0); }
113 #ifndef _WIN32_WCE
114 LONG SetStyle(LONG_PTR style)
115 { return SetLongPtr(GWL_STYLE, style); }
116 DWORD GetStyle( ) const
117 { return GetLongPtr(GWL_STYLE); }
118 #else
119 LONG SetStyle(LONG_PTR style)
120 { return SetLong(GWL_STYLE, style); }
121 DWORD GetStyle( ) const
122 { return GetLong(GWL_STYLE); }
123 #endif
125 LONG_PTR SetLong(int index, LONG_PTR newLongPtr )
126 { return ::SetWindowLong(_window, index, newLongPtr); }
127 LONG_PTR GetLong(int index) const
128 { return ::GetWindowLong(_window, index ); }
129 LONG_PTR SetUserDataLong(LONG_PTR newLongPtr )
130 { return SetLong(GWLP_USERDATA, newLongPtr); }
131 LONG_PTR GetUserDataLong() const
132 { return GetLong(GWLP_USERDATA); }
134 #ifndef _WIN32_WCE
135 LONG_PTR SetLongPtr(int index, LONG_PTR newLongPtr )
136 { return ::SetWindowLongPtr(_window, index, newLongPtr); }
137 #ifndef _UNICODE
138 LONG_PTR SetLongPtrW(int index, LONG_PTR newLongPtr )
139 { return ::SetWindowLongPtrW(_window, index, newLongPtr); }
140 #endif
142 LONG_PTR GetLongPtr(int index) const
143 { return ::GetWindowLongPtr(_window, index ); }
144 LONG_PTR SetUserDataLongPtr(LONG_PTR newLongPtr )
145 { return SetLongPtr(GWLP_USERDATA, newLongPtr); }
146 LONG_PTR GetUserDataLongPtr() const
147 { return GetLongPtr(GWLP_USERDATA); }
148 #endif
150 /*
151 bool ModifyStyle(HWND hWnd, DWORD remove, DWORD add, UINT flags = 0)
152 { return ModifyStyleBase(GWL_STYLE, remove, add, flags); }
153 bool ModifyStyleEx(HWND hWnd, DWORD remove, DWORD add, UINT flags = 0)
154 { return ModifyStyleBase(GWL_EXSTYLE, remove, add, flags); }
155 */
157 HWND SetFocus() { return ::SetFocus(_window); }
159 LRESULT SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
160 { return ::SendMessage(_window, message, wParam, lParam) ;}
161 #ifndef _UNICODE
162 LRESULT SendMessageW(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
163 { return ::SendMessageW(_window, message, wParam, lParam) ;}
164 #endif
166 bool PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
167 { return BOOLToBool(::PostMessage(_window, message, wParam, lParam)) ;}
168 #ifndef _UNICODE
169 LRESULT PostMessageW(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
170 { return ::PostMessageW(_window, message, wParam, lParam) ;}
171 #endif
173 bool SetText(LPCTSTR s) { return BOOLToBool(::SetWindowText(_window, s)); }
174 #ifndef _UNICODE
175 bool CWindow::SetText(LPCWSTR s) { return MySetWindowText(_window, s); }
176 #endif
178 int GetTextLength() const
179 { return GetWindowTextLength(_window); }
180 UINT GetText(LPTSTR string, int maxCount) const
181 { return GetWindowText(_window, string, maxCount); }
182 bool GetText(CSysString &s);
183 #ifndef _UNICODE
184 /*
185 UINT GetText(LPWSTR string, int maxCount) const
186 { return GetWindowTextW(_window, string, maxCount); }
187 */
188 bool GetText(UString &s);
189 #endif
191 bool Enable(bool enable)
192 { return BOOLToBool(::EnableWindow(_window, BoolToBOOL(enable))); }
194 bool IsEnabled()
195 { return BOOLToBool(::IsWindowEnabled(_window)); }
197 #ifndef _WIN32_WCE
198 HMENU GetSystemMenu(bool revert)
199 { return ::GetSystemMenu(_window, BoolToBOOL(revert)); }
200 #endif
202 UINT_PTR SetTimer(UINT_PTR idEvent, UINT elapse, TIMERPROC timerFunc = 0)
203 { return ::SetTimer(_window, idEvent, elapse, timerFunc); }
204 bool KillTimer(UINT_PTR idEvent)
205 {return BOOLToBool(::KillTimer(_window, idEvent)); }
206 };
208 }
210 #endif