Mercurial > projects > dynamin
annotate dynamin/gui/windows_window.d @ 55:c138461bf845
Add focusing and other changes that are related
like descendantAdded/Removed events, Window.activated event, and updating List.
Window.state was also added, even though focusing does not depend on it.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 08 Aug 2009 15:42:27 -0500 |
parents | 2a194d52fdb5 |
children | 8dac206ea523 |
rev | line source |
---|---|
0 | 1 // Written in the D programming language |
2 // www.digitalmars.com/d/ | |
3 | |
4 /* | |
5 * The contents of this file are subject to the Mozilla Public License Version | |
6 * 1.1 (the "License"); you may not use this file except in compliance with | |
7 * the License. You may obtain a copy of the License at | |
8 * http://www.mozilla.org/MPL/ | |
9 * | |
10 * Software distributed under the License is distributed on an "AS IS" basis, | |
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 * for the specific language governing rights and limitations under the | |
13 * License. | |
14 * | |
15 * The Original Code is the Dynamin library. | |
16 * | |
17 * The Initial Developer of the Original Code is Jordan Miner. | |
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009 | |
19 * the Initial Developer. All Rights Reserved. | |
20 * | |
21 * Contributor(s): | |
22 * Jordan Miner <jminer7@gmail.com> | |
23 * | |
24 */ | |
25 | |
26 module dynamin.gui.windows_window; | |
27 | |
28 public import dynamin.c.windows; | |
29 public import dynamin.c.cairo; | |
30 public import dynamin.c.cairo_win32; | |
31 public import dynamin.all_core; | |
32 public import dynamin.all_gui; | |
33 public import dynamin.gui.window; | |
34 public import dynamin.gui.key; | |
35 public import dynamin.all_painting; | |
36 public import tango.io.Stdout; | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
37 public import tango.core.sync.Semaphore; |
0 | 38 |
39 /// | |
40 enum WindowsVersion { | |
41 /// | |
17
ef81af74a306
Add Windows 7 to version checking
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
42 Windows95, /// |
ef81af74a306
Add Windows 7 to version checking
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
43 Windows98, /// |
ef81af74a306
Add Windows 7 to version checking
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
44 WindowsMe, /// |
ef81af74a306
Add Windows 7 to version checking
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
45 Windows2000, /// |
ef81af74a306
Add Windows 7 to version checking
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
46 WindowsXP, /// |
ef81af74a306
Add Windows 7 to version checking
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
47 WindowsVista,/// |
ef81af74a306
Add Windows 7 to version checking
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
48 Windows7 |
0 | 49 } |
50 /** | |
51 * Returns true if the version of Windows that is runninng now is the | |
52 * specified version or newer. | |
53 */ | |
54 bool checkWindowsVersion(WindowsVersion ver) { | |
55 // Windows Server "Longhorn" is 6.0 | |
56 // Windows Vista is 6.0 | |
57 // Windows Server 2003 is 5.2 | |
58 // Windows XP is 5.1 | |
59 // Windows Me is 4.90 | |
60 // Windows 98 is 4.10 | |
61 // Windows 95 is 4.0 | |
62 // Windows NT is 4.0 | |
63 OSVERSIONINFO info; | |
64 info.dwOSVersionInfoSize = OSVERSIONINFO.sizeof; | |
65 GetVersionEx(&info); | |
66 DWORD major, minor; | |
67 switch(ver) { | |
68 case WindowsVersion.Windows95: major = 4; minor = 0; break; | |
69 case WindowsVersion.Windows98: major = 4; minor = 10; break; | |
70 case WindowsVersion.WindowsMe: major = 4; minor = 90; break; | |
71 case WindowsVersion.Windows2000: major = 5; minor = 0; break; | |
72 case WindowsVersion.WindowsXP: major = 5; minor = 1; break; | |
73 case WindowsVersion.WindowsVista: major = 6; minor = 0; break; | |
17
ef81af74a306
Add Windows 7 to version checking
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
74 case WindowsVersion.Windows7: major = 6; minor = 1; break; |
0 | 75 } |
76 return info.dwMajorVersion > major || | |
77 (info.dwMajorVersion == major && info.dwMinorVersion >= minor); | |
78 } | |
79 /* unittest { | |
80 Stdout.format("Windows95 or newer: {}", checkWindowsVersion(WindowsVersion.Windows95)).newline; | |
81 Stdout.format("Windows98 or newer: {}", checkWindowsVersion(WindowsVersion.Windows98)).newline; | |
82 Stdout.format("WindowsMe or newer: {}", checkWindowsVersion(WindowsVersion.WindowsMe)).newline; | |
83 Stdout.format("Windows2000 or newer: {}", checkWindowsVersion(WindowsVersion.Windows2000)).newline; | |
84 Stdout.format("WindowsXP or newer: {}", checkWindowsVersion(WindowsVersion.WindowsXP)).newline; | |
85 } */ | |
86 | |
87 // TODO: the way I have stored references using SetProp() will not work | |
88 // if/when D gets a copying collector. I will need to store a key with | |
89 // SetProp() and use that key to store the reference in either an | |
90 // array or a hashtable. | |
91 Window[HWND] windows; | |
92 void setControl(HWND hwnd, Window win) { | |
93 if(win is null) | |
94 windows.remove(hwnd); | |
95 else | |
96 windows[hwnd] = win; | |
97 } | |
98 /** | |
99 * Returns: the Dynamin NativeControl that wraps the specified handle | |
100 */ | |
101 // TODO: change return type to NativeControl | |
102 Window getControl(HWND hwnd) { | |
103 assert(IsWindow(hwnd), "Invalid HWND"); | |
104 auto tmp = hwnd in windows; | |
105 return tmp is null ? null : *tmp; | |
106 } | |
107 | |
108 template ApplicationBackend() { | |
109 void backend_run(Window w) { | |
110 bool isWindowVisible() { | |
111 if(w is null) return true; | |
112 return w.visible; | |
113 } | |
114 MSG msg; | |
115 BOOL ret; | |
116 while(isWindowVisible() && (ret = GetMessage(&msg, null, 0, 0)) != 0) { | |
117 if(ret == -1) | |
118 Stdout("GetMessage() failed!").newline; | |
119 TranslateMessage(&msg); | |
120 DispatchMessage(&msg); | |
121 } | |
122 } | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
123 void backend_invoke(void delegate() dg) { |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
124 PostMessage(msgWnd, WM_USER + 7, |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
125 cast(word)dg.ptr, cast(word)dg.funcptr); |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
126 } |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
127 void backend_invokeNow(void delegate() dg) { |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
128 SendMessage(msgWnd, WM_USER + 7, |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
129 cast(word)dg.ptr, cast(word)dg.funcptr); |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
130 } |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
131 |
0 | 132 } |
133 /* | |
134 * The reason backends use the backend_ prefix and: | |
135 * mixin Backend(); | |
136 * instead of using just the method name and | |
137 * mixin Backend() backend; | |
138 * is that D mistakenly calls the method in the class, rather than | |
139 * the one mixed-in...causing infinite recursion/stack overflow | |
140 */ | |
141 //{{{ WindowBackend | |
142 template WindowBackend() { | |
143 HWND _handle; | |
144 bool backend_handleCreated() { return _handle !is null; } | |
145 //WS_CAPTION == WS_BORDER | WS_DLGFRAME; | |
146 void backend_recreateHandle() { | |
147 LONG style, exStyle; | |
148 backend_getWindowStyles(style, exStyle); | |
149 style &= ~WS_VISIBLE; // don't create visible | |
150 // TODO: set the owner with CreateWindowEx | |
151 HWND newHandle = CreateWindowEx(exStyle, "DynaminWindow", _text.toWcharPtr(), | |
152 style, cast(int)x, cast(int)y, cast(int)width, cast(int)height, | |
153 null, null, GetModuleHandle(null), null); | |
154 if(!newHandle) | |
155 Stdout("CreateWindowEx() failed").newline; | |
156 setControl(newHandle, this); | |
157 | |
158 // Windows does not completely obey the styles given in CreateWindowEx() | |
159 SetWindowLong(newHandle, GWL_STYLE, style); | |
160 SetWindowLong(newHandle, GWL_EXSTYLE, exStyle); | |
161 SetWindowPos(newHandle, null, 0, 0, 0, 0, | |
162 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); | |
163 | |
164 if(handleCreated) { | |
165 // TODO: move native children to new window? | |
166 | |
167 // set z-order to right above old window | |
168 // SetWindowPos() puts the window above the specified | |
169 // window in the z-order | |
170 SetWindowPos(newHandle, _handle, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); | |
171 if(IsWindowVisible(_handle)) | |
172 ShowWindow(newHandle, SW_SHOWNA); | |
173 DestroyWindow(_handle); | |
174 } | |
175 _handle = newHandle; | |
176 backend_nativeToBorderSize(); | |
177 } | |
178 extern(C) static void freeDC(void* hdc) { | |
179 ReleaseDC(null, hdc); | |
180 } | |
181 Graphics backend_quickCreateGraphics() { | |
182 HDC hdc = GetDC(handle); | |
183 cairo_surface_t* surface = cairo_win32_surface_create(hdc); | |
184 cairo_surface_set_user_data(surface, cast(cairo_user_data_key_t*)1, | |
185 hdc, &freeDC); | |
186 cairo_t* cr = cairo_create(surface); | |
187 cairo_surface_destroy(surface); | |
188 cairo_translate(cr, -borderSize.left, -borderSize.top); | |
189 auto g = new Graphics(cr); | |
190 cairo_destroy(cr); | |
191 return g; | |
192 } | |
193 void backend_visible(bool b) { | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
194 if(b) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
195 // visible has been set to true by now...use state() to show window |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
196 backend_state = _state; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
197 else |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
198 //if not created, create the handle by calling handle() |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
199 ShowWindow(handle, SW_HIDE); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
200 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
201 void backend_state(WindowState s) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
202 if(!visible) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
203 return; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
204 //if not created, create the handle by calling handle() |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
205 if(s == WindowState.Normal) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
206 ShowWindow(handle, SW_RESTORE); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
207 else if(s == WindowState.Minimized) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
208 ShowWindow(handle, SW_MINIMIZE); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
209 else if(s == WindowState.Maximized) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
210 ShowWindow(handle, SW_MAXIMIZE); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
211 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
212 void backend_activate() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
213 SetForegroundWindow(_handle); |
0 | 214 } |
215 void backend_borderStyle(WindowBorderStyle border) { | |
216 backend_updateWindowStyles(); | |
217 } | |
23
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
17
diff
changeset
|
218 void backend_setCurrentCursor(Cursor cur) { |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
17
diff
changeset
|
219 SetCursor(cur.handle); |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
17
diff
changeset
|
220 } |
0 | 221 void backend_repaint(Rect rect) { |
222 RECT wrect; | |
223 wrect.left = cast(int)(rect.x-_borderSize.left); | |
224 wrect.top = cast(int)(rect.y-_borderSize.top); | |
225 wrect.right = wrect.left+cast(int)rect.width; | |
226 wrect.bottom = wrect.top+cast(int)rect.height; | |
227 InvalidateRect(handle, &wrect, false); | |
228 } | |
229 void backend_resizable(bool b) { | |
230 backend_updateWindowStyles(); | |
231 } | |
232 void backend_contentMinSizeChanged() { | |
233 } | |
234 void backend_contentMaxSizeChanged() { | |
235 backend_updateWindowStyles(); | |
236 } | |
237 void backend_location(Point pt) { | |
238 SetWindowPos(handle, null, | |
239 cast(int)pt.x, cast(int)pt.y, 0, 0, | |
240 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); | |
241 } | |
242 void backend_size(Size size) { | |
243 SetWindowPos(handle, null, | |
244 0, 0, cast(int)size.width, cast(int)size.height, | |
245 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); | |
246 } | |
247 void backend_text(string str) { | |
248 SetWindowText(handle, str.toWcharPtr()); | |
249 } | |
250 //{{{ backend specific | |
251 | |
252 void backend_nativeToLocationSize() { | |
253 RECT winRect; | |
254 GetWindowRect(handle, &winRect); | |
255 _location.x = winRect.left; | |
256 _location.y = winRect.top; | |
257 _size.width = winRect.right-winRect.left; | |
258 _size.height = winRect.bottom-winRect.top; | |
259 } | |
260 package void backend_nativeToBorderSize() { | |
261 RECT clientRect, winRect; | |
262 POINT clientLoc; | |
263 GetClientRect(handle, &clientRect); | |
264 GetWindowRect(handle, &winRect); | |
265 ClientToScreen(handle, &clientLoc); | |
266 _borderSize.left = clientLoc.x-winRect.left; | |
267 _borderSize.top = clientLoc.y-winRect.top; | |
268 _borderSize.right = winRect.right-clientLoc.x-clientRect.right; | |
269 _borderSize.bottom = winRect.bottom-clientLoc.y-clientRect.bottom; | |
270 backend_nativeToLocationSize(); | |
271 } | |
272 void backend_getWindowStyles(out LONG style, out LONG exStyle) { | |
273 if(handleCreated) { | |
274 style = GetWindowLong(handle, GWL_STYLE); | |
275 exStyle = GetWindowLong(handle, GWL_EXSTYLE); | |
276 } | |
277 void SetIf(LONG s, bool b) { | |
278 // if condition satisfied, add style, otherwise clear style | |
279 b ? (style |= s) : (style &= ~s); | |
280 } | |
281 SetIf(WS_DLGFRAME, borderStyle != WindowBorderStyle.None); | |
282 SetIf(WS_BORDER, borderStyle != WindowBorderStyle.None); | |
283 SetIf(WS_THICKFRAME, | |
284 resizable && borderStyle != WindowBorderStyle.None); | |
285 SetIf(WS_MINIMIZEBOX, borderStyle == WindowBorderStyle.Normal); | |
286 SetIf(WS_MAXIMIZEBOX, | |
287 borderStyle == WindowBorderStyle.Normal && resizable && | |
288 content.maxWidth == 0 && content.maxHeight == 0); | |
289 SetIf(WS_SYSMENU, borderStyle != WindowBorderStyle.None); | |
290 if(borderStyle == WindowBorderStyle.Tool) | |
291 exStyle |= WS_EX_TOOLWINDOW; | |
292 else | |
293 exStyle &= ~WS_EX_TOOLWINDOW; | |
294 } | |
295 void backend_updateWindowStyles() { | |
296 if(!handleCreated) | |
297 return; | |
298 LONG style, exStyle; | |
299 backend_getWindowStyles(style, exStyle); | |
300 SetWindowLong(handle, GWL_STYLE, style); | |
301 SetWindowLong(handle, GWL_EXSTYLE, exStyle); | |
302 SetWindowPos(handle, null, 0, 0, 0, 0, | |
303 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); | |
304 } | |
305 //--FixedToorWindow-- | |
306 //Style: 0x16c80000 | |
307 //ExStyle: 0x10180 | |
308 //--SizableToorWindow-- | |
309 //Style: 0x16cc0000 | |
310 //ExStyle: 0x10180 | |
311 //--FixedDialog-- | |
312 //Style: 0x16c80000 | |
313 //ExStyle: 0x10101 | |
314 //--None-- | |
315 //Style: 0x16010000 | |
316 //ExStyle: 0x10000 | |
317 //--FixedSingle-- | |
318 //Style: 0x16c80000 | |
319 //ExStyle: 0x10100 | |
320 //--Sizable-- | |
321 //Style: 0x16cc0000 | |
322 //ExStyle: 0x10100 | |
323 //}}} | |
324 } | |
325 //}}} | |
326 | |
327 //{{{ Ux class | |
328 class Ux { | |
329 static: | |
330 private: | |
331 HMODULE uxLib = null; | |
332 // TODO: these are the wrong calling convention!! | |
333 extern(Windows) { | |
334 BOOL function() _IsAppThemed; | |
335 BOOL function() _IsThemeActive; | |
336 HTHEME function(HWND hwnd, LPCWSTR pszClassList) _OpenThemeData; | |
337 HRESULT function(HTHEME hTheme) _CloseThemeData; | |
338 HRESULT function(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, | |
339 RECT* pRect, RECT* pClipRect) _DrawThemeBackground; | |
340 } | |
341 static this() { | |
342 uxLib = LoadLibrary("uxtheme"); | |
343 if(uxLib) { | |
344 _IsAppThemed = cast(typeof(_IsAppThemed)) | |
345 GetProcAddress(uxLib, "IsAppThemed"); | |
346 _IsThemeActive = cast(typeof(_IsThemeActive)) | |
347 GetProcAddress(uxLib, "IsThemeActive"); | |
348 _OpenThemeData = cast(typeof(_OpenThemeData)) | |
349 GetProcAddress(uxLib, "OpenThemeData"); | |
350 _CloseThemeData = cast(typeof(_CloseThemeData)) | |
351 GetProcAddress(uxLib, "CloseThemeData"); | |
352 _DrawThemeBackground = cast(typeof(_DrawThemeBackground)) | |
353 GetProcAddress(uxLib, "DrawThemeBackground"); | |
354 } | |
355 } | |
356 HTHEME[string] cache; | |
357 // opens an HTHEME for the specified controlName and caches it | |
358 // next time, just returns the HTHEME from the cache | |
359 HTHEME getHTHEME(string controlName) { | |
360 HTHEME* hthemePtr = controlName in cache; | |
361 HTHEME htheme = controlName in cache; | |
362 if(hthemePtr) { | |
363 htheme = *hthemePtr; | |
364 } else { | |
365 htheme = _OpenThemeData(null, controlName.toWcharPtr()); | |
366 if(!htheme) { | |
367 if(_IsThemeActive()) | |
368 throw new Exception("invalid uxtheme controlName"); | |
369 else | |
370 throw new Exception("no theme active"); | |
371 } | |
372 cache[controlName] = htheme; | |
373 } | |
374 return htheme; | |
375 } | |
376 // This is called when the WM_THEMECHANGED message is sent | |
377 package void themeChanged() { | |
378 foreach(htheme; cache.values) | |
379 _CloseThemeData(htheme); | |
380 cache = null; | |
381 updateThemeActive = true; | |
382 } | |
383 bool themeActive; | |
384 bool updateThemeActive = true; | |
385 public: | |
386 // cache this value, as this function was showing up in profiles | |
387 bool isThemeActive() { | |
388 if(updateThemeActive) { | |
389 themeActive = uxLib && _IsThemeActive() && _IsAppThemed(); | |
390 updateThemeActive = false; | |
391 } | |
392 return themeActive; | |
393 } | |
394 // draw directly onto the HDC with the uxTheme API if the following | |
395 // three conditions are met: | |
396 // - the Graphics must be drawing to an HDC (duh) | |
397 // - there cannot be a scale or rotation...translation can be handled | |
398 // - the clip must be a pixel-aligned rectangle | |
399 bool drawBackground(Graphics g, Rect rect, string controlName, int part, int state) { | |
400 if(!uxLib) | |
401 throw new Exception("UxPaintBackground(): uxtheme library not found!"); | |
402 HTHEME htheme = getHTHEME(controlName); | |
403 static if(true) { | |
404 | |
405 HDC hdc = cairo_win32_surface_get_dc(cairo_get_target(g.handle)); | |
406 //HDC hdc = null; | |
407 bool isMatrixTranslationOnly() { | |
408 cairo_matrix_t matrix; | |
409 cairo_get_matrix(g.handle, &matrix); | |
410 return matrix.xx == 1 && matrix.xy == 0 && | |
411 matrix.xy == 0 && matrix.yy == 1; | |
412 } | |
413 bool isClipIntegerRect(cairo_rectangle_list_t* list) { | |
414 return list.status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE; | |
415 } | |
416 RECT locRect; | |
417 auto list = cairo_copy_clip_rectangle_list(g.handle); | |
418 scope(exit) cairo_rectangle_list_destroy(list); | |
419 if(hdc && isMatrixTranslationOnly() && isClipIntegerRect(list)) { | |
420 double x = rect.x, y = rect.y; | |
421 double right = rect.right, bottom = rect.bottom; | |
422 cairo_user_to_device(g.handle, &x, &y); | |
423 cairo_user_to_device(g.handle, &right, &bottom); | |
424 locRect.left = cast(int)x; | |
425 locRect.top = cast(int)y; | |
426 locRect.right = cast(int)right; | |
427 locRect.bottom = cast(int)bottom; | |
428 cairo_surface_flush(cairo_get_target(g.handle)); | |
429 | |
430 RECT clip; | |
431 for(int i = 0; i < list.num_rectangles; ++i) { | |
432 cairo_user_to_device(g.handle, &(list.rectangles[i].x), &(list.rectangles[i].y)); | |
433 clip.left = cast(int)list.rectangles[i].x; | |
434 clip.top = cast(int)list.rectangles[i].y; | |
435 clip.right = clip.left + cast(int)list.rectangles[i].width; | |
436 clip.bottom = clip.top + cast(int)list.rectangles[i].height; | |
437 _DrawThemeBackground(htheme, hdc, part, state, &locRect, &clip); | |
438 } | |
439 | |
440 cairo_surface_mark_dirty(cairo_get_target(g.handle)); | |
441 } else { | |
442 assert(0, "So far, visual styles are supported only with no rotation, no scaling, a rectangular clip, and HDC surfaces."); | |
443 static if(0) { | |
444 BITMAPINFO bmi; | |
445 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
446 bmi.bmiHeader.biWidth = width; | |
447 bmi.bmiHeader.biHeight = -height; // top-down DIB | |
448 bmi.bmiHeader.biPlanes = 1; | |
449 bmi.bmiHeader.biBitCount = 32; | |
450 bmi.bmiHeader.biCompression = BI_RGB; | |
451 //bmi.bmiHeader.biSizeImage = width * height * 4; | |
452 hbmpBlack = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, | |
453 &bmpBits, NULL, 0); | |
454 hbmpWhite = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, | |
455 &bmpBits, NULL, 0); | |
456 //draw on a black background and on a white background | |
457 //calculate alpha and colors and draw that image with cairo | |
458 // DO TESTS WITH ROTATION AND SCALING | |
459 _DrawThemeBackground(htheme, hdc, part, state, null/*change*/, null); | |
460 DeleteObject(hbmpBlack); | |
461 DeleteObject(hbmpWhite); | |
462 } | |
463 } | |
464 | |
465 } | |
466 return false; | |
467 } | |
468 } | |
469 //}}} | |
470 | |
471 //{{{ module constructor and destructor | |
472 HWND msgWnd; | |
473 static this() { | |
474 assert(cairo_version() >= CAIRO_VERSION_ENCODE(1, 4, 0), | |
475 "cairo version 1.4.0 or newer is required"); | |
476 | |
477 /* create window classes */ | |
478 WNDCLASSEX wc; | |
479 wc.cbSize = wc.sizeof; | |
480 wc.style = 0; | |
481 wc.hInstance = GetModuleHandle(null); | |
482 | |
483 wc.lpfnWndProc = &dynaminMsgWindowProc; | |
484 wc.lpszClassName = "DynaminMsgWindow"; | |
485 if(!RegisterClassExW(&wc)) | |
486 Stdout("RegisterClassEx() failed registering class 'DynaminMsgWindow'").newline; | |
487 | |
488 wc.lpfnWndProc = &dynaminWindowProc; | |
489 //wc.hbrBackground = cast(HBRUSH)16; | |
490 | |
491 wc.lpszClassName = "DynaminWindow"; | |
492 if(!RegisterClassEx(&wc)) | |
493 Stdout("RegisterClassEx() failed registering class 'DynaminWindow'").newline; | |
494 | |
495 wc.style = CS_SAVEBITS; | |
496 wc.lpszClassName = "DynaminPopup"; | |
497 if(!RegisterClassExW(&wc)) | |
498 Stdout("RegisterClassEx() failed registering class 'DynaminPopup'").newline; | |
499 | |
500 | |
501 msgWnd = CreateWindowEx(0, "DynaminMsgWindow", "", | |
502 0, | |
503 0, 0, 0, 0, | |
504 null, null, GetModuleHandle(null), null); | |
505 if(!msgWnd) | |
506 Stdout("CreateWindowEx() failed").newline; | |
507 | |
508 /* initialize COM */ | |
509 auto ret = CoInitializeEx(null, COINIT_APARTMENTTHREADED); | |
510 if(ret != S_OK && ret != S_FALSE) | |
511 Stdout("Failed to initialize COM").newline; | |
512 | |
513 } | |
514 static ~this() { | |
515 CoUninitialize(); | |
516 } | |
517 //}}} | |
518 | |
519 //{{{ dynaminWindowProc() | |
520 extern(Windows) | |
521 LRESULT dynaminWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { | |
522 //used in WM_MOVING | |
523 static int dragX, dragY; //the cursor location in window coordinates when the drag was started | |
524 static bool trackingMouseLeave = false; | |
525 auto c = getControl(hwnd); | |
526 //{{{ helper functions | |
527 void createMouseEvent(MouseButton button, void delegate(MouseEventArgs args) func) { | |
528 scope args = new MouseEventArgs( | |
529 cast(short)LOWORD(lParam)+c.borderSize.left, | |
530 cast(short)HIWORD(lParam)+c.borderSize.top, button); | |
531 func(args); | |
532 } | |
533 void snapSide(inout int sideToSnap, float side1, float side2) { | |
534 if(sideToSnap >= side1-c.snapDistance && sideToSnap <= side1+c.snapDistance) | |
535 sideToSnap = cast(int)side1; | |
536 if(sideToSnap >= side2-c.snapDistance && sideToSnap <= side2+c.snapDistance) | |
537 sideToSnap = cast(int)side2; | |
538 } | |
539 auto emptyFunc = (Rect snapRect) {}; | |
540 // used to snap vertical sides, left and right | |
541 void snapVSide(inout int side, RECT* rect, void delegate(Rect snapRect) func = emptyFunc) { | |
542 if(c.snapRects is null) | |
543 return; | |
544 foreach(snapRect; c.snapRects) { | |
545 if(rect.bottom >= snapRect.y && rect.top <= snapRect.bottom) { | |
546 snapSide(side, snapRect.x, snapRect.right); | |
547 func(snapRect); | |
548 } | |
549 } | |
550 } | |
551 // used to snap horizontal sides, top and bottom | |
552 void snapHSide(inout int side, RECT* rect, void delegate(Rect snapRect) func = emptyFunc) { | |
553 if(c.snapRects is null) | |
554 return; | |
555 foreach(snapRect; c.snapRects) { | |
556 if(rect.right >= snapRect.x && rect.left <= snapRect.right) { | |
557 snapSide(side, snapRect.y, snapRect.bottom); | |
558 func(snapRect); | |
559 } | |
560 } | |
561 } | |
562 MouseButton getFromXBUTTONX() { | |
563 switch(HIWORD(wParam)) { | |
564 case XBUTTON1: return MouseButton.XButton1; | |
565 case XBUTTON2: return MouseButton.XButton2; | |
566 default: return MouseButton.None; | |
567 } | |
568 } | |
569 //}}} | |
570 switch(uMsg) { | |
571 case WM_ENTERSIZEMOVE: //when the user starts moving or resizing the window | |
572 //{{{ | |
573 POINT cursor; | |
574 GetCursorPos(&cursor); | |
575 RECT rect; | |
576 GetWindowRect(hwnd, &rect); | |
577 dragX = cursor.x-rect.left; | |
578 dragY = cursor.y-rect.top; | |
579 return 0; | |
580 //}}} | |
581 case WM_MOVING: | |
582 //{{{ | |
583 if(c.snapRects is null || c.snapRects.length == 0) | |
584 break; | |
585 RECT* rect = cast(RECT*)lParam; | |
586 int rectWidth = rect.right-rect.left; | |
587 int rectHeight = rect.bottom-rect.top; | |
588 POINT cursor; | |
589 GetCursorPos(&cursor); | |
590 rect.left = cursor.x-dragX; | |
591 rect.top = cursor.y-dragY; | |
592 void updateRightAndBottom() { | |
593 rect.right = rect.left+rectWidth; | |
594 rect.bottom = rect.top+rectHeight; | |
595 } | |
596 updateRightAndBottom(); | |
597 snapVSide(rect.left, rect, (Rect snapRect) { | |
598 snapSide(rect.left, snapRect.x-rectWidth, snapRect.right-rectWidth); | |
599 }); | |
600 updateRightAndBottom(); | |
601 snapHSide(rect.top, rect, (Rect snapRect) { | |
602 snapSide(rect.top, snapRect.y-rectHeight, snapRect.bottom-rectHeight); | |
603 }); | |
604 updateRightAndBottom(); | |
605 snapVSide(rect.left, rect, (Rect snapRect) { | |
606 snapSide(rect.left, snapRect.x-rectWidth, snapRect.right-rectWidth); | |
607 }); | |
608 updateRightAndBottom(); | |
609 return true; | |
610 //}}} | |
611 case WM_SIZING: | |
612 //{{{ | |
613 Size minSize = c.content.minSize+c.borderSize; | |
614 Size maxSize = c.content.maxSize+c.borderSize; | |
615 RECT* rect = cast(RECT*)lParam; | |
616 switch(wParam) { | |
617 case WMSZ_TOPLEFT: | |
618 snapHSide(rect.top, rect); | |
619 goto case WMSZ_LEFT; | |
620 case WMSZ_BOTTOMLEFT: | |
621 snapHSide(rect.bottom, rect); | |
622 case WMSZ_LEFT: | |
623 snapVSide(rect.left, rect); | |
624 // adjust left according to min and max | |
625 if(c.content.maxWidth != 0) | |
626 rect.left = max(rect.left, rect.right-cast(int)maxSize.width); | |
627 if(c.content.minWidth != 0) | |
628 rect.left = min(rect.left, rect.right-cast(int)minSize.width); | |
629 break; | |
630 case WMSZ_TOPRIGHT: | |
631 snapHSide(rect.top, rect); | |
632 goto case WMSZ_RIGHT; | |
633 case WMSZ_BOTTOMRIGHT: | |
634 snapHSide(rect.bottom, rect); | |
635 case WMSZ_RIGHT: | |
636 snapVSide(rect.right, rect); | |
637 // adjust right according to min and max | |
638 if(c.content.maxWidth != 0) | |
639 rect.right = min(rect.right, rect.left+cast(int)maxSize.width); | |
640 if(c.content.minWidth != 0) | |
641 rect.right = max(rect.right, rect.left+cast(int)minSize.width); | |
642 break; | |
643 default: break; | |
644 } | |
645 switch(wParam) { | |
646 case WMSZ_TOPLEFT: //already snapped left above | |
647 case WMSZ_TOPRIGHT: //already snapped right above | |
648 case WMSZ_TOP: | |
649 snapHSide(rect.top, rect); | |
650 // adjust top according to min and max | |
651 if(c.content.maxHeight != 0) | |
652 rect.top = max(rect.top, rect.bottom-cast(int)maxSize.height); | |
653 if(c.content.minHeight != 0) | |
654 rect.top = min(rect.top, rect.bottom-cast(int)minSize.height); | |
655 break; | |
656 case WMSZ_BOTTOMLEFT: //already snapped left above | |
657 case WMSZ_BOTTOMRIGHT: //already snapped right above | |
658 case WMSZ_BOTTOM: | |
659 snapHSide(rect.bottom, rect); | |
660 // adjust bottom according to min and max | |
661 if(c.content.maxHeight != 0) | |
662 rect.bottom = min(rect.bottom, rect.top+cast(int)maxSize.height); | |
663 if(c.content.minHeight != 0) | |
664 rect.bottom = max(rect.bottom, rect.top+cast(int)minSize.height); | |
665 break; | |
666 default: break; | |
667 } | |
668 return true; | |
669 //}}} | |
670 case WM_MOVE: | |
671 RECT rect; | |
672 GetWindowRect(hwnd, &rect); | |
673 c._location = Point(rect.left, rect.top); | |
674 scope args = new EventArgs(); | |
675 c.moved(args); | |
676 return 0; | |
677 case WM_SIZE: | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
678 if(wParam == SIZE_RESTORED) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
679 c._state = WindowState.Normal; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
680 else if(wParam == SIZE_MINIMIZED) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
681 c._state = WindowState.Minimized; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
682 break; // don't update size if minimized (would be wierd size) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
683 } else if(wParam == SIZE_MAXIMIZED) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
684 c._state = WindowState.Maximized; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
685 |
0 | 686 RECT rect; |
687 GetWindowRect(hwnd, &rect); | |
688 c._size = Size(rect.right-rect.left, rect.bottom-rect.top); | |
689 c.backend_nativeToBorderSize(); | |
690 scope args = new EventArgs(); | |
691 c.resized(args); | |
692 return 0; | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
693 case WM_ACTIVATE: |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
694 scope e = new EventArgs; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
695 if(LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
696 c._active = true; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
697 c.activated(e); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
698 } else if(LOWORD(wParam) == WA_INACTIVE) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
699 c._active = false; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
700 c.deactivated(e); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
701 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
702 return 0; |
0 | 703 case WM_MOUSEMOVE: |
704 if(!trackingMouseLeave) { | |
705 TRACKMOUSEEVENT tme; | |
706 tme.cbSize = TRACKMOUSEEVENT.sizeof; | |
707 tme.dwFlags = TME_LEAVE; | |
708 tme.hWndTrack = hwnd; | |
709 tme.dwHoverTime = 0; | |
710 TrackMouseEvent(&tme); | |
711 trackingMouseLeave = true; | |
712 } | |
713 auto pt = Point(cast(short)LOWORD(lParam)+c.borderSize.left, cast(short)HIWORD(lParam)+c.borderSize.top); | |
714 Control captor = getCaptorControl(); | |
715 if(captor) | |
716 pt = c.contentToContent(pt, captor); | |
717 else | |
718 captor = c; | |
28
00efca2c1545
Rename variable to be consistent.
Jordan Miner <jminer7@gmail.com>
parents:
23
diff
changeset
|
719 scope args = new MouseEventArgs( |
0 | 720 pt.x, pt.y, MouseButton.None); |
721 if(wParam & | |
722 (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | | |
723 MK_XBUTTON1 | MK_XBUTTON2)) { | |
28
00efca2c1545
Rename variable to be consistent.
Jordan Miner <jminer7@gmail.com>
parents:
23
diff
changeset
|
724 captor.mouseDragged(args); |
0 | 725 } else { |
28
00efca2c1545
Rename variable to be consistent.
Jordan Miner <jminer7@gmail.com>
parents:
23
diff
changeset
|
726 captor.mouseMoved(args); |
0 | 727 } |
728 return 0; | |
729 case WM_MOUSELEAVE: | |
730 trackingMouseLeave = false; | |
731 setHotControl(null); | |
732 return 0; | |
733 case WM_LBUTTONDOWN: | |
734 SetCapture(hwnd); | |
735 createMouseEvent(MouseButton.Left, (MouseEventArgs args) { | |
736 c.mouseDown(args); | |
737 }); | |
738 return 0; | |
739 case WM_MBUTTONDOWN: | |
740 SetCapture(hwnd); | |
741 createMouseEvent(MouseButton.Middle, (MouseEventArgs args) { | |
742 c.mouseDown(args); | |
743 }); | |
744 return 0; | |
745 case WM_RBUTTONDOWN: | |
746 SetCapture(hwnd); | |
747 createMouseEvent(MouseButton.Right, (MouseEventArgs args) { | |
748 c.mouseDown(args); | |
749 }); | |
750 return 0; | |
751 case WM_XBUTTONDOWN: | |
752 SetCapture(hwnd); | |
753 auto button = getFromXBUTTONX(); | |
754 if(!button) break; | |
755 createMouseEvent(button, (MouseEventArgs args) { | |
756 c.mouseDown(args); | |
757 }); | |
758 return true; | |
759 case WM_LBUTTONUP: | |
760 ReleaseCapture(); | |
761 createMouseEvent(MouseButton.Left, (MouseEventArgs args) { | |
762 c.mouseUp(args); | |
763 }); | |
764 return 0; | |
765 case WM_MBUTTONUP: | |
766 ReleaseCapture(); | |
767 createMouseEvent(MouseButton.Middle, (MouseEventArgs args) { | |
768 c.mouseUp(args); | |
769 }); | |
770 return 0; | |
771 case WM_RBUTTONUP: | |
772 ReleaseCapture(); | |
773 createMouseEvent(MouseButton.Right, (MouseEventArgs args) { | |
774 c.mouseUp(args); | |
775 }); | |
776 return 0; | |
777 case WM_XBUTTONUP: | |
778 ReleaseCapture(); | |
779 auto button = getFromXBUTTONX(); | |
780 if(!button) break; | |
781 createMouseEvent(button, (MouseEventArgs args) { | |
782 c.mouseUp(args); | |
783 }); | |
784 return true; | |
785 case WM_MOUSEWHEEL: | |
786 int scrollLines; | |
787 SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0); | |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
788 bool sScreen = (scrollLines == 0xFFFFFFFF); |
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
789 if(sScreen) |
0 | 790 scrollLines = 3; |
791 int delta = -cast(short)HIWORD(wParam); | |
792 auto screenPt = Point(LOWORD(lParam), HIWORD(lParam)); | |
793 auto des = c.getDescendantAtPoint(c.screenToContent(screenPt)); | |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
794 scope args = new MouseTurnedEventArgs(delta*scrollLines/120.0, sScreen); |
29
e6843df719a8
Use scope when creating EventArgs to avoid unnecessary heap usage.
Jordan Miner <jminer7@gmail.com>
parents:
28
diff
changeset
|
795 des.mouseTurned(args); |
0 | 796 return 0; |
797 case WM_SYSKEYDOWN: | |
798 //Stdout.format("WM_SYSKEYDOWN: {:x}", cast(int)wParam).newline; | |
799 if(wParam == 0x79) return 0; | |
800 break; | |
801 case WM_KEYDOWN: | |
802 //Stdout.format("WM_KEYDOWN: {:x}", cast(int)wParam).newline; | |
803 Control focused = c.focusedControl ? c.focusedControl : c; | |
29
e6843df719a8
Use scope when creating EventArgs to avoid unnecessary heap usage.
Jordan Miner <jminer7@gmail.com>
parents:
28
diff
changeset
|
804 scope args = new KeyEventArgs( |
e6843df719a8
Use scope when creating EventArgs to avoid unnecessary heap usage.
Jordan Miner <jminer7@gmail.com>
parents:
28
diff
changeset
|
805 VKToKey(wParam), cast(bool)(lParam & (1 << 30)) ); |
e6843df719a8
Use scope when creating EventArgs to avoid unnecessary heap usage.
Jordan Miner <jminer7@gmail.com>
parents:
28
diff
changeset
|
806 focused.keyDown(args); |
0 | 807 return 0; |
808 case WM_SYSKEYUP: | |
809 //Stdout.format("WM_SYSKEYUP: {:x}", cast(int)wParam).newline; | |
810 if(wParam == 0x79) return 0; | |
811 break; | |
812 case WM_KEYUP: | |
813 //Stdout.format("WM_KEYUP: {:x}", cast(int)wParam).newline; | |
814 Control focused = c.focusedControl ? c.focusedControl : c; | |
29
e6843df719a8
Use scope when creating EventArgs to avoid unnecessary heap usage.
Jordan Miner <jminer7@gmail.com>
parents:
28
diff
changeset
|
815 scope args = new KeyEventArgs( VKToKey(wParam), false ); |
e6843df719a8
Use scope when creating EventArgs to avoid unnecessary heap usage.
Jordan Miner <jminer7@gmail.com>
parents:
28
diff
changeset
|
816 focused.keyUp(args); |
0 | 817 return 0; |
818 case WM_CHAR: | |
819 // DO NOT use the repeat count from the lParam to send multiple events | |
820 // I hate when programs do that | |
821 | |
822 //stop backspace and escape and shift+enter | |
823 if(wParam == 0x08 || wParam == 0x1B || wParam == 0x0A) | |
824 break; | |
825 // don't process characters typed while control is down | |
826 if(HIBYTE(GetKeyState(VK_CONTROL))) | |
827 break; | |
828 if(wParam == 0x0D) // change \r to \n | |
829 wParam = 0x0A; | |
830 bool repeat; | |
831 repeat = cast(bool)(lParam & (1 << 30)); | |
832 Control focused = c.focusedControl ? c.focusedControl : c; | |
29
e6843df719a8
Use scope when creating EventArgs to avoid unnecessary heap usage.
Jordan Miner <jminer7@gmail.com>
parents:
28
diff
changeset
|
833 scope args = new KeyTypedEventArgs(cast(dchar)wParam, repeat); |
e6843df719a8
Use scope when creating EventArgs to avoid unnecessary heap usage.
Jordan Miner <jminer7@gmail.com>
parents:
28
diff
changeset
|
834 focused.keyTyped(args); |
0 | 835 return 0; |
836 case WM_PRINT: | |
837 paintToHDC(cast(HDC)wParam, getControl(hwnd), null); | |
838 return 0; | |
839 case WM_PAINT: | |
840 PAINTSTRUCT ps; | |
841 BeginPaint(hwnd, &ps); | |
842 RECT* clip = &ps.rcPaint; | |
843 | |
844 HDC hdcBuffer = CreateCompatibleDC(ps.hdc); | |
845 HBITMAP hbmpBuffer = CreateCompatibleBitmap(ps.hdc, | |
846 clip.right-clip.left, clip.bottom-clip.top); | |
847 HBITMAP hbmpDefault = SelectObject(hdcBuffer, hbmpBuffer); | |
848 | |
849 paintToHDC(hdcBuffer, getControl(hwnd), clip); | |
850 | |
851 BitBlt(ps.hdc, clip.left, clip.top, clip.right-clip.left, clip.bottom-clip.top, | |
852 hdcBuffer, 0, 0, SRCCOPY); | |
853 SelectObject(hdcBuffer, hbmpDefault); | |
854 DeleteDC(hdcBuffer); | |
855 DeleteObject(hbmpBuffer); | |
856 | |
857 EndPaint(hwnd, &ps); | |
858 return 0; | |
859 case WM_CLOSE: | |
860 c.visible = false; | |
861 //DestroyWindow(hwnd); | |
862 //PostQuitMessage(0); | |
863 return 0; | |
864 case WM_DESTROY: | |
865 return 0; | |
866 default: | |
867 break; | |
868 } | |
869 return DefWindowProc(hwnd, uMsg, wParam, lParam); | |
870 } | |
871 //}}} | |
872 | |
873 //{{{ paintToHDC() | |
874 void paintToHDC(HDC hdc, Window w, RECT* clip) { | |
875 cairo_surface_t* surface = cairo_win32_surface_create(hdc); | |
876 cairo_t* cr = cairo_create(surface); | |
877 cairo_surface_destroy(surface); | |
878 | |
879 if(clip) { | |
880 cairo_translate(cr, | |
881 -clip.left-w.borderSize.left, -clip.top-w.borderSize.top); | |
882 | |
883 //cairo_rectangle(cr, clip.left, clip.top, clip.right-clip.left, clip.bottom-clip.top); | |
884 } | |
885 //if(w.Opaque) { | |
886 //cairo_set_source_rgb(cr, w.content.backColor.R/255.0, w.content.backColor.G/255.0, w.content.backColor.B/255.0); | |
887 //cairo_paint(cr); | |
888 //} | |
889 | |
890 //cairo_set_source_rgb(cr, .3, .3, .3); | |
891 //cairo_paint(cr); | |
892 | |
893 //cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); | |
894 //cairo_paint(cr); | |
895 //cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | |
896 | |
897 cairo_set_source_rgb(cr, 0, 0, 0); | |
898 cairo_set_line_width(cr, 1.0); | |
899 | |
900 //HBITMAP hbmp = LoadImage(null, cast(wchar*)cast(ushort)OIC_WARNING, | |
901 // IMAGE_ICON, 0, 0, LR_SHARED); | |
902 //if(hbmp == null) | |
903 // Stdout.format("LoadImage failed. GetLastError()={}", GetLastError()).newline; | |
904 | |
905 //auto imgSurface = cairo_image_surface_create_for_data(); | |
906 //cairo_set_source_surface(cr, imgSurface, 50, 50); | |
907 //cairo_paint(cr); | |
908 //cairo_surface_destroy(imgSurface); | |
909 | |
910 auto g = new Graphics(cr); | |
911 scope args = new PaintingEventArgs(g); | |
912 w.painting(args); | |
913 delete g; | |
914 cairo_destroy(cr); | |
915 } | |
916 //}}} | |
917 | |
918 //{{{ VKToKey() | |
919 Key VKToKey(int code) { | |
920 switch(code) { | |
921 case VK_F1: return Key.F1; | |
922 case VK_F2: return Key.F2; | |
923 case VK_F3: return Key.F3; | |
924 case VK_F4: return Key.F4; | |
925 case VK_F5: return Key.F5; | |
926 case VK_F6: return Key.F6; | |
927 case VK_F7: return Key.F7; | |
928 case VK_F8: return Key.F8; | |
929 case VK_F9: return Key.F9; | |
930 case VK_F10: return Key.F10; | |
931 case VK_F11: return Key.F11; | |
932 case VK_F12: return Key.F12; | |
933 | |
934 case VK_ESCAPE: return Key.Escape; | |
935 case VK_TAB: return Key.Tab; | |
936 case VK_BACK: return Key.Backspace; | |
937 case VK_RETURN: return Key.Enter; | |
938 case VK_SPACE: return Key.Space; | |
939 | |
940 case VK_LEFT: return Key.Left; | |
941 case VK_RIGHT: return Key.Right; | |
942 case VK_UP: return Key.Up; | |
943 case VK_DOWN: return Key.Down; | |
944 | |
945 case VK_INSERT: return Key.Insert; | |
946 case VK_DELETE: return Key.Delete; | |
947 case VK_HOME: return Key.Home; | |
948 case VK_END: return Key.End; | |
949 case VK_PRIOR: return Key.PageUp; | |
950 case VK_NEXT: return Key.PageDown; | |
951 | |
952 case VK_SNAPSHOT: return Key.PrintScreen; | |
953 case VK_PAUSE: return Key.Pause; | |
954 | |
955 case VK_CAPITAL: return Key.CapsLock; | |
956 case VK_NUMLOCK: return Key.NumLock; | |
957 case VK_SCROLL: return Key.ScrollLock; | |
958 | |
959 case VK_NUMPAD0: return Key.NumPad0; | |
960 case VK_NUMPAD1: return Key.NumPad1; | |
961 case VK_NUMPAD2: return Key.NumPad2; | |
962 case VK_NUMPAD3: return Key.NumPad3; | |
963 case VK_NUMPAD4: return Key.NumPad4; | |
964 case VK_NUMPAD5: return Key.NumPad5; | |
965 case VK_NUMPAD6: return Key.NumPad6; | |
966 case VK_NUMPAD7: return Key.NumPad7; | |
967 case VK_NUMPAD8: return Key.NumPad8; | |
968 case VK_NUMPAD9: return Key.NumPad9; | |
969 case VK_DIVIDE: return Key.NumPadDivide; | |
970 case VK_MULTIPLY: return Key.NumPadMultiply; | |
971 case VK_SUBTRACT: return Key.NumPadSubtract; | |
972 case VK_ADD: return Key.NumPadAdd; | |
973 case VK_DECIMAL: return Key.NumPadDecimal; | |
974 | |
975 case VK_OEM_3: return Key.Backquote; | |
976 case VK_OEM_MINUS: return Key.Minus; | |
977 case VK_OEM_PLUS: return Key.Equals; | |
978 case VK_OEM_4: return Key.OpenBracket; | |
979 case VK_OEM_6: return Key.CloseBracket; | |
980 case VK_OEM_5: return Key.Backslash; | |
981 case VK_OEM_1: return Key.Semicolon; | |
982 case VK_OEM_7: return Key.Quote; | |
983 case VK_OEM_COMMA: return Key.Comma; | |
984 case VK_OEM_PERIOD: return Key.Period; | |
985 case VK_OEM_2: return Key.Slash; | |
986 | |
987 //case VK_APPS: return Key.Menu; | |
988 | |
989 case VK_SHIFT: return Key.Shift; | |
990 case VK_CONTROL: return Key.Control; | |
991 case VK_MENU: return Key.Alt; | |
992 | |
993 //case VK_: return Key.; | |
994 default: | |
995 if(code >= 0x30 && code <= 0x39) // Key.D0 - Key.D9 | |
996 return cast(Key)code; | |
997 if(code >= 0x41 && code <= 0x5A) // Key.A - Key.Z | |
998 return cast(Key)code; | |
999 return cast(Key)0; | |
1000 } | |
1001 } | |
1002 //}}} | |
1003 | |
1004 // Use the msgWnd for the following: | |
1005 // Timers | |
1006 // Clipboard.DataChanged event | |
1007 // Clipboard? | |
1008 // Taskbar created event using RegisterWindowMessage("TaskbarCreated") | |
1009 // different settings changed events? | |
1010 // screen saver enabled? | |
1011 extern(Windows) | |
1012 LRESULT dynaminMsgWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { | |
1013 switch(uMsg) { | |
1014 case WM_THEMECHANGED: | |
1015 Ux.themeChanged(); | |
1016 return 0; | |
1017 case WM_POWERBROADCAST: | |
1018 if(wParam == PBT_APMRESUMESUSPEND || wParam == PBT_APMRESUMECRITICAL) | |
1019 Environment.backend_increaseTimerRes(); | |
1020 return 0; | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
1021 case WM_USER + 7: |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
1022 void delegate() dg; |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
1023 dg.ptr = cast(void*)wParam; |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
1024 dg.funcptr = cast(void function())lParam; |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
1025 dg(); |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
1026 return 0; |
0 | 1027 case WM_TIMER: |
1028 case WM_CHANGECBCHAIN: | |
1029 case WM_DRAWCLIPBOARD: | |
1030 case WM_TIMECHANGE: //?? | |
1031 default: | |
1032 break; | |
1033 } | |
1034 return DefWindowProc(hwnd, uMsg, wParam, lParam); | |
1035 } | |
1036 |