Mercurial > projects > dynamin
annotate dynamin/gui/windows_window.d @ 28:00efca2c1545
Rename variable to be consistent.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 25 Jul 2009 15:14:00 -0500 |
parents | d55b5b998412 |
children | e6843df719a8 |
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) { | |
194 //if not created, create the handle by calling Handle() | |
195 ShowWindow(handle, b ? SW_SHOW : SW_HIDE); | |
196 } | |
197 void backend_borderStyle(WindowBorderStyle border) { | |
198 backend_updateWindowStyles(); | |
199 } | |
23
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
17
diff
changeset
|
200 void backend_setCurrentCursor(Cursor cur) { |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
17
diff
changeset
|
201 SetCursor(cur.handle); |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
17
diff
changeset
|
202 } |
0 | 203 void backend_repaint(Rect rect) { |
204 RECT wrect; | |
205 wrect.left = cast(int)(rect.x-_borderSize.left); | |
206 wrect.top = cast(int)(rect.y-_borderSize.top); | |
207 wrect.right = wrect.left+cast(int)rect.width; | |
208 wrect.bottom = wrect.top+cast(int)rect.height; | |
209 InvalidateRect(handle, &wrect, false); | |
210 } | |
211 void backend_resizable(bool b) { | |
212 backend_updateWindowStyles(); | |
213 } | |
214 void backend_contentMinSizeChanged() { | |
215 } | |
216 void backend_contentMaxSizeChanged() { | |
217 backend_updateWindowStyles(); | |
218 } | |
219 void backend_location(Point pt) { | |
220 SetWindowPos(handle, null, | |
221 cast(int)pt.x, cast(int)pt.y, 0, 0, | |
222 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); | |
223 } | |
224 void backend_size(Size size) { | |
225 SetWindowPos(handle, null, | |
226 0, 0, cast(int)size.width, cast(int)size.height, | |
227 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); | |
228 } | |
229 void backend_text(string str) { | |
230 SetWindowText(handle, str.toWcharPtr()); | |
231 } | |
232 //{{{ backend specific | |
233 | |
234 void backend_nativeToLocationSize() { | |
235 RECT winRect; | |
236 GetWindowRect(handle, &winRect); | |
237 _location.x = winRect.left; | |
238 _location.y = winRect.top; | |
239 _size.width = winRect.right-winRect.left; | |
240 _size.height = winRect.bottom-winRect.top; | |
241 } | |
242 package void backend_nativeToBorderSize() { | |
243 RECT clientRect, winRect; | |
244 POINT clientLoc; | |
245 GetClientRect(handle, &clientRect); | |
246 GetWindowRect(handle, &winRect); | |
247 ClientToScreen(handle, &clientLoc); | |
248 _borderSize.left = clientLoc.x-winRect.left; | |
249 _borderSize.top = clientLoc.y-winRect.top; | |
250 _borderSize.right = winRect.right-clientLoc.x-clientRect.right; | |
251 _borderSize.bottom = winRect.bottom-clientLoc.y-clientRect.bottom; | |
252 backend_nativeToLocationSize(); | |
253 } | |
254 void backend_getWindowStyles(out LONG style, out LONG exStyle) { | |
255 if(handleCreated) { | |
256 style = GetWindowLong(handle, GWL_STYLE); | |
257 exStyle = GetWindowLong(handle, GWL_EXSTYLE); | |
258 } | |
259 void SetIf(LONG s, bool b) { | |
260 // if condition satisfied, add style, otherwise clear style | |
261 b ? (style |= s) : (style &= ~s); | |
262 } | |
263 SetIf(WS_DLGFRAME, borderStyle != WindowBorderStyle.None); | |
264 SetIf(WS_BORDER, borderStyle != WindowBorderStyle.None); | |
265 SetIf(WS_THICKFRAME, | |
266 resizable && borderStyle != WindowBorderStyle.None); | |
267 SetIf(WS_MINIMIZEBOX, borderStyle == WindowBorderStyle.Normal); | |
268 SetIf(WS_MAXIMIZEBOX, | |
269 borderStyle == WindowBorderStyle.Normal && resizable && | |
270 content.maxWidth == 0 && content.maxHeight == 0); | |
271 SetIf(WS_SYSMENU, borderStyle != WindowBorderStyle.None); | |
272 if(borderStyle == WindowBorderStyle.Tool) | |
273 exStyle |= WS_EX_TOOLWINDOW; | |
274 else | |
275 exStyle &= ~WS_EX_TOOLWINDOW; | |
276 } | |
277 void backend_updateWindowStyles() { | |
278 if(!handleCreated) | |
279 return; | |
280 LONG style, exStyle; | |
281 backend_getWindowStyles(style, exStyle); | |
282 SetWindowLong(handle, GWL_STYLE, style); | |
283 SetWindowLong(handle, GWL_EXSTYLE, exStyle); | |
284 SetWindowPos(handle, null, 0, 0, 0, 0, | |
285 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); | |
286 } | |
287 //--FixedToorWindow-- | |
288 //Style: 0x16c80000 | |
289 //ExStyle: 0x10180 | |
290 //--SizableToorWindow-- | |
291 //Style: 0x16cc0000 | |
292 //ExStyle: 0x10180 | |
293 //--FixedDialog-- | |
294 //Style: 0x16c80000 | |
295 //ExStyle: 0x10101 | |
296 //--None-- | |
297 //Style: 0x16010000 | |
298 //ExStyle: 0x10000 | |
299 //--FixedSingle-- | |
300 //Style: 0x16c80000 | |
301 //ExStyle: 0x10100 | |
302 //--Sizable-- | |
303 //Style: 0x16cc0000 | |
304 //ExStyle: 0x10100 | |
305 //}}} | |
306 } | |
307 //}}} | |
308 | |
309 //{{{ Ux class | |
310 class Ux { | |
311 static: | |
312 private: | |
313 HMODULE uxLib = null; | |
314 // TODO: these are the wrong calling convention!! | |
315 extern(Windows) { | |
316 BOOL function() _IsAppThemed; | |
317 BOOL function() _IsThemeActive; | |
318 HTHEME function(HWND hwnd, LPCWSTR pszClassList) _OpenThemeData; | |
319 HRESULT function(HTHEME hTheme) _CloseThemeData; | |
320 HRESULT function(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, | |
321 RECT* pRect, RECT* pClipRect) _DrawThemeBackground; | |
322 } | |
323 static this() { | |
324 uxLib = LoadLibrary("uxtheme"); | |
325 if(uxLib) { | |
326 _IsAppThemed = cast(typeof(_IsAppThemed)) | |
327 GetProcAddress(uxLib, "IsAppThemed"); | |
328 _IsThemeActive = cast(typeof(_IsThemeActive)) | |
329 GetProcAddress(uxLib, "IsThemeActive"); | |
330 _OpenThemeData = cast(typeof(_OpenThemeData)) | |
331 GetProcAddress(uxLib, "OpenThemeData"); | |
332 _CloseThemeData = cast(typeof(_CloseThemeData)) | |
333 GetProcAddress(uxLib, "CloseThemeData"); | |
334 _DrawThemeBackground = cast(typeof(_DrawThemeBackground)) | |
335 GetProcAddress(uxLib, "DrawThemeBackground"); | |
336 } | |
337 } | |
338 HTHEME[string] cache; | |
339 // opens an HTHEME for the specified controlName and caches it | |
340 // next time, just returns the HTHEME from the cache | |
341 HTHEME getHTHEME(string controlName) { | |
342 HTHEME* hthemePtr = controlName in cache; | |
343 HTHEME htheme = controlName in cache; | |
344 if(hthemePtr) { | |
345 htheme = *hthemePtr; | |
346 } else { | |
347 htheme = _OpenThemeData(null, controlName.toWcharPtr()); | |
348 if(!htheme) { | |
349 if(_IsThemeActive()) | |
350 throw new Exception("invalid uxtheme controlName"); | |
351 else | |
352 throw new Exception("no theme active"); | |
353 } | |
354 cache[controlName] = htheme; | |
355 } | |
356 return htheme; | |
357 } | |
358 // This is called when the WM_THEMECHANGED message is sent | |
359 package void themeChanged() { | |
360 foreach(htheme; cache.values) | |
361 _CloseThemeData(htheme); | |
362 cache = null; | |
363 updateThemeActive = true; | |
364 } | |
365 bool themeActive; | |
366 bool updateThemeActive = true; | |
367 public: | |
368 // cache this value, as this function was showing up in profiles | |
369 bool isThemeActive() { | |
370 if(updateThemeActive) { | |
371 themeActive = uxLib && _IsThemeActive() && _IsAppThemed(); | |
372 updateThemeActive = false; | |
373 } | |
374 return themeActive; | |
375 } | |
376 // draw directly onto the HDC with the uxTheme API if the following | |
377 // three conditions are met: | |
378 // - the Graphics must be drawing to an HDC (duh) | |
379 // - there cannot be a scale or rotation...translation can be handled | |
380 // - the clip must be a pixel-aligned rectangle | |
381 bool drawBackground(Graphics g, Rect rect, string controlName, int part, int state) { | |
382 if(!uxLib) | |
383 throw new Exception("UxPaintBackground(): uxtheme library not found!"); | |
384 HTHEME htheme = getHTHEME(controlName); | |
385 static if(true) { | |
386 | |
387 HDC hdc = cairo_win32_surface_get_dc(cairo_get_target(g.handle)); | |
388 //HDC hdc = null; | |
389 bool isMatrixTranslationOnly() { | |
390 cairo_matrix_t matrix; | |
391 cairo_get_matrix(g.handle, &matrix); | |
392 return matrix.xx == 1 && matrix.xy == 0 && | |
393 matrix.xy == 0 && matrix.yy == 1; | |
394 } | |
395 bool isClipIntegerRect(cairo_rectangle_list_t* list) { | |
396 return list.status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE; | |
397 } | |
398 RECT locRect; | |
399 auto list = cairo_copy_clip_rectangle_list(g.handle); | |
400 scope(exit) cairo_rectangle_list_destroy(list); | |
401 if(hdc && isMatrixTranslationOnly() && isClipIntegerRect(list)) { | |
402 double x = rect.x, y = rect.y; | |
403 double right = rect.right, bottom = rect.bottom; | |
404 cairo_user_to_device(g.handle, &x, &y); | |
405 cairo_user_to_device(g.handle, &right, &bottom); | |
406 locRect.left = cast(int)x; | |
407 locRect.top = cast(int)y; | |
408 locRect.right = cast(int)right; | |
409 locRect.bottom = cast(int)bottom; | |
410 cairo_surface_flush(cairo_get_target(g.handle)); | |
411 | |
412 RECT clip; | |
413 for(int i = 0; i < list.num_rectangles; ++i) { | |
414 cairo_user_to_device(g.handle, &(list.rectangles[i].x), &(list.rectangles[i].y)); | |
415 clip.left = cast(int)list.rectangles[i].x; | |
416 clip.top = cast(int)list.rectangles[i].y; | |
417 clip.right = clip.left + cast(int)list.rectangles[i].width; | |
418 clip.bottom = clip.top + cast(int)list.rectangles[i].height; | |
419 _DrawThemeBackground(htheme, hdc, part, state, &locRect, &clip); | |
420 } | |
421 | |
422 cairo_surface_mark_dirty(cairo_get_target(g.handle)); | |
423 } else { | |
424 assert(0, "So far, visual styles are supported only with no rotation, no scaling, a rectangular clip, and HDC surfaces."); | |
425 static if(0) { | |
426 BITMAPINFO bmi; | |
427 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
428 bmi.bmiHeader.biWidth = width; | |
429 bmi.bmiHeader.biHeight = -height; // top-down DIB | |
430 bmi.bmiHeader.biPlanes = 1; | |
431 bmi.bmiHeader.biBitCount = 32; | |
432 bmi.bmiHeader.biCompression = BI_RGB; | |
433 //bmi.bmiHeader.biSizeImage = width * height * 4; | |
434 hbmpBlack = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, | |
435 &bmpBits, NULL, 0); | |
436 hbmpWhite = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, | |
437 &bmpBits, NULL, 0); | |
438 //draw on a black background and on a white background | |
439 //calculate alpha and colors and draw that image with cairo | |
440 // DO TESTS WITH ROTATION AND SCALING | |
441 _DrawThemeBackground(htheme, hdc, part, state, null/*change*/, null); | |
442 DeleteObject(hbmpBlack); | |
443 DeleteObject(hbmpWhite); | |
444 } | |
445 } | |
446 | |
447 } | |
448 return false; | |
449 } | |
450 } | |
451 //}}} | |
452 | |
453 //{{{ module constructor and destructor | |
454 HWND msgWnd; | |
455 static this() { | |
456 assert(cairo_version() >= CAIRO_VERSION_ENCODE(1, 4, 0), | |
457 "cairo version 1.4.0 or newer is required"); | |
458 | |
459 /* create window classes */ | |
460 WNDCLASSEX wc; | |
461 wc.cbSize = wc.sizeof; | |
462 wc.style = 0; | |
463 wc.hInstance = GetModuleHandle(null); | |
464 | |
465 wc.lpfnWndProc = &dynaminMsgWindowProc; | |
466 wc.lpszClassName = "DynaminMsgWindow"; | |
467 if(!RegisterClassExW(&wc)) | |
468 Stdout("RegisterClassEx() failed registering class 'DynaminMsgWindow'").newline; | |
469 | |
470 wc.lpfnWndProc = &dynaminWindowProc; | |
471 //wc.hbrBackground = cast(HBRUSH)16; | |
472 | |
473 wc.lpszClassName = "DynaminWindow"; | |
474 if(!RegisterClassEx(&wc)) | |
475 Stdout("RegisterClassEx() failed registering class 'DynaminWindow'").newline; | |
476 | |
477 wc.style = CS_SAVEBITS; | |
478 wc.lpszClassName = "DynaminPopup"; | |
479 if(!RegisterClassExW(&wc)) | |
480 Stdout("RegisterClassEx() failed registering class 'DynaminPopup'").newline; | |
481 | |
482 | |
483 msgWnd = CreateWindowEx(0, "DynaminMsgWindow", "", | |
484 0, | |
485 0, 0, 0, 0, | |
486 null, null, GetModuleHandle(null), null); | |
487 if(!msgWnd) | |
488 Stdout("CreateWindowEx() failed").newline; | |
489 | |
490 /* initialize COM */ | |
491 auto ret = CoInitializeEx(null, COINIT_APARTMENTTHREADED); | |
492 if(ret != S_OK && ret != S_FALSE) | |
493 Stdout("Failed to initialize COM").newline; | |
494 | |
495 } | |
496 static ~this() { | |
497 CoUninitialize(); | |
498 } | |
499 //}}} | |
500 | |
501 //{{{ dynaminWindowProc() | |
502 extern(Windows) | |
503 LRESULT dynaminWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { | |
504 //used in WM_MOVING | |
505 static int dragX, dragY; //the cursor location in window coordinates when the drag was started | |
506 static bool trackingMouseLeave = false; | |
507 auto c = getControl(hwnd); | |
508 //{{{ helper functions | |
509 void createMouseEvent(MouseButton button, void delegate(MouseEventArgs args) func) { | |
510 scope args = new MouseEventArgs( | |
511 cast(short)LOWORD(lParam)+c.borderSize.left, | |
512 cast(short)HIWORD(lParam)+c.borderSize.top, button); | |
513 func(args); | |
514 } | |
515 void snapSide(inout int sideToSnap, float side1, float side2) { | |
516 if(sideToSnap >= side1-c.snapDistance && sideToSnap <= side1+c.snapDistance) | |
517 sideToSnap = cast(int)side1; | |
518 if(sideToSnap >= side2-c.snapDistance && sideToSnap <= side2+c.snapDistance) | |
519 sideToSnap = cast(int)side2; | |
520 } | |
521 auto emptyFunc = (Rect snapRect) {}; | |
522 // used to snap vertical sides, left and right | |
523 void snapVSide(inout int side, RECT* rect, void delegate(Rect snapRect) func = emptyFunc) { | |
524 if(c.snapRects is null) | |
525 return; | |
526 foreach(snapRect; c.snapRects) { | |
527 if(rect.bottom >= snapRect.y && rect.top <= snapRect.bottom) { | |
528 snapSide(side, snapRect.x, snapRect.right); | |
529 func(snapRect); | |
530 } | |
531 } | |
532 } | |
533 // used to snap horizontal sides, top and bottom | |
534 void snapHSide(inout int side, RECT* rect, void delegate(Rect snapRect) func = emptyFunc) { | |
535 if(c.snapRects is null) | |
536 return; | |
537 foreach(snapRect; c.snapRects) { | |
538 if(rect.right >= snapRect.x && rect.left <= snapRect.right) { | |
539 snapSide(side, snapRect.y, snapRect.bottom); | |
540 func(snapRect); | |
541 } | |
542 } | |
543 } | |
544 MouseButton getFromXBUTTONX() { | |
545 switch(HIWORD(wParam)) { | |
546 case XBUTTON1: return MouseButton.XButton1; | |
547 case XBUTTON2: return MouseButton.XButton2; | |
548 default: return MouseButton.None; | |
549 } | |
550 } | |
551 //}}} | |
552 switch(uMsg) { | |
553 case WM_ENTERSIZEMOVE: //when the user starts moving or resizing the window | |
554 //{{{ | |
555 POINT cursor; | |
556 GetCursorPos(&cursor); | |
557 RECT rect; | |
558 GetWindowRect(hwnd, &rect); | |
559 dragX = cursor.x-rect.left; | |
560 dragY = cursor.y-rect.top; | |
561 return 0; | |
562 //}}} | |
563 case WM_MOVING: | |
564 //{{{ | |
565 if(c.snapRects is null || c.snapRects.length == 0) | |
566 break; | |
567 RECT* rect = cast(RECT*)lParam; | |
568 int rectWidth = rect.right-rect.left; | |
569 int rectHeight = rect.bottom-rect.top; | |
570 POINT cursor; | |
571 GetCursorPos(&cursor); | |
572 rect.left = cursor.x-dragX; | |
573 rect.top = cursor.y-dragY; | |
574 void updateRightAndBottom() { | |
575 rect.right = rect.left+rectWidth; | |
576 rect.bottom = rect.top+rectHeight; | |
577 } | |
578 updateRightAndBottom(); | |
579 snapVSide(rect.left, rect, (Rect snapRect) { | |
580 snapSide(rect.left, snapRect.x-rectWidth, snapRect.right-rectWidth); | |
581 }); | |
582 updateRightAndBottom(); | |
583 snapHSide(rect.top, rect, (Rect snapRect) { | |
584 snapSide(rect.top, snapRect.y-rectHeight, snapRect.bottom-rectHeight); | |
585 }); | |
586 updateRightAndBottom(); | |
587 snapVSide(rect.left, rect, (Rect snapRect) { | |
588 snapSide(rect.left, snapRect.x-rectWidth, snapRect.right-rectWidth); | |
589 }); | |
590 updateRightAndBottom(); | |
591 return true; | |
592 //}}} | |
593 case WM_SIZING: | |
594 //{{{ | |
595 Size minSize = c.content.minSize+c.borderSize; | |
596 Size maxSize = c.content.maxSize+c.borderSize; | |
597 RECT* rect = cast(RECT*)lParam; | |
598 switch(wParam) { | |
599 case WMSZ_TOPLEFT: | |
600 snapHSide(rect.top, rect); | |
601 goto case WMSZ_LEFT; | |
602 case WMSZ_BOTTOMLEFT: | |
603 snapHSide(rect.bottom, rect); | |
604 case WMSZ_LEFT: | |
605 snapVSide(rect.left, rect); | |
606 // adjust left according to min and max | |
607 if(c.content.maxWidth != 0) | |
608 rect.left = max(rect.left, rect.right-cast(int)maxSize.width); | |
609 if(c.content.minWidth != 0) | |
610 rect.left = min(rect.left, rect.right-cast(int)minSize.width); | |
611 break; | |
612 case WMSZ_TOPRIGHT: | |
613 snapHSide(rect.top, rect); | |
614 goto case WMSZ_RIGHT; | |
615 case WMSZ_BOTTOMRIGHT: | |
616 snapHSide(rect.bottom, rect); | |
617 case WMSZ_RIGHT: | |
618 snapVSide(rect.right, rect); | |
619 // adjust right according to min and max | |
620 if(c.content.maxWidth != 0) | |
621 rect.right = min(rect.right, rect.left+cast(int)maxSize.width); | |
622 if(c.content.minWidth != 0) | |
623 rect.right = max(rect.right, rect.left+cast(int)minSize.width); | |
624 break; | |
625 default: break; | |
626 } | |
627 switch(wParam) { | |
628 case WMSZ_TOPLEFT: //already snapped left above | |
629 case WMSZ_TOPRIGHT: //already snapped right above | |
630 case WMSZ_TOP: | |
631 snapHSide(rect.top, rect); | |
632 // adjust top according to min and max | |
633 if(c.content.maxHeight != 0) | |
634 rect.top = max(rect.top, rect.bottom-cast(int)maxSize.height); | |
635 if(c.content.minHeight != 0) | |
636 rect.top = min(rect.top, rect.bottom-cast(int)minSize.height); | |
637 break; | |
638 case WMSZ_BOTTOMLEFT: //already snapped left above | |
639 case WMSZ_BOTTOMRIGHT: //already snapped right above | |
640 case WMSZ_BOTTOM: | |
641 snapHSide(rect.bottom, rect); | |
642 // adjust bottom according to min and max | |
643 if(c.content.maxHeight != 0) | |
644 rect.bottom = min(rect.bottom, rect.top+cast(int)maxSize.height); | |
645 if(c.content.minHeight != 0) | |
646 rect.bottom = max(rect.bottom, rect.top+cast(int)minSize.height); | |
647 break; | |
648 default: break; | |
649 } | |
650 return true; | |
651 //}}} | |
652 case WM_MOVE: | |
653 RECT rect; | |
654 GetWindowRect(hwnd, &rect); | |
655 c._location = Point(rect.left, rect.top); | |
656 scope args = new EventArgs(); | |
657 c.moved(args); | |
658 return 0; | |
659 case WM_SIZE: | |
660 if(wParam == SIZE_MINIMIZED) | |
661 break; | |
662 RECT rect; | |
663 GetWindowRect(hwnd, &rect); | |
664 c._size = Size(rect.right-rect.left, rect.bottom-rect.top); | |
665 c.backend_nativeToBorderSize(); | |
666 scope args = new EventArgs(); | |
667 c.resized(args); | |
668 return 0; | |
669 case WM_MOUSEMOVE: | |
670 if(!trackingMouseLeave) { | |
671 TRACKMOUSEEVENT tme; | |
672 tme.cbSize = TRACKMOUSEEVENT.sizeof; | |
673 tme.dwFlags = TME_LEAVE; | |
674 tme.hWndTrack = hwnd; | |
675 tme.dwHoverTime = 0; | |
676 TrackMouseEvent(&tme); | |
677 trackingMouseLeave = true; | |
678 } | |
679 auto pt = Point(cast(short)LOWORD(lParam)+c.borderSize.left, cast(short)HIWORD(lParam)+c.borderSize.top); | |
680 Control captor = getCaptorControl(); | |
681 if(captor) | |
682 pt = c.contentToContent(pt, captor); | |
683 else | |
684 captor = c; | |
28
00efca2c1545
Rename variable to be consistent.
Jordan Miner <jminer7@gmail.com>
parents:
23
diff
changeset
|
685 scope args = new MouseEventArgs( |
0 | 686 pt.x, pt.y, MouseButton.None); |
687 if(wParam & | |
688 (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | | |
689 MK_XBUTTON1 | MK_XBUTTON2)) { | |
28
00efca2c1545
Rename variable to be consistent.
Jordan Miner <jminer7@gmail.com>
parents:
23
diff
changeset
|
690 captor.mouseDragged(args); |
0 | 691 } else { |
28
00efca2c1545
Rename variable to be consistent.
Jordan Miner <jminer7@gmail.com>
parents:
23
diff
changeset
|
692 captor.mouseMoved(args); |
0 | 693 } |
694 return 0; | |
695 case WM_MOUSELEAVE: | |
696 trackingMouseLeave = false; | |
697 setHotControl(null); | |
698 return 0; | |
699 case WM_LBUTTONDOWN: | |
700 SetCapture(hwnd); | |
701 createMouseEvent(MouseButton.Left, (MouseEventArgs args) { | |
702 c.mouseDown(args); | |
703 }); | |
704 return 0; | |
705 case WM_MBUTTONDOWN: | |
706 SetCapture(hwnd); | |
707 createMouseEvent(MouseButton.Middle, (MouseEventArgs args) { | |
708 c.mouseDown(args); | |
709 }); | |
710 return 0; | |
711 case WM_RBUTTONDOWN: | |
712 SetCapture(hwnd); | |
713 createMouseEvent(MouseButton.Right, (MouseEventArgs args) { | |
714 c.mouseDown(args); | |
715 }); | |
716 return 0; | |
717 case WM_XBUTTONDOWN: | |
718 SetCapture(hwnd); | |
719 auto button = getFromXBUTTONX(); | |
720 if(!button) break; | |
721 createMouseEvent(button, (MouseEventArgs args) { | |
722 c.mouseDown(args); | |
723 }); | |
724 return true; | |
725 case WM_LBUTTONUP: | |
726 ReleaseCapture(); | |
727 createMouseEvent(MouseButton.Left, (MouseEventArgs args) { | |
728 c.mouseUp(args); | |
729 }); | |
730 return 0; | |
731 case WM_MBUTTONUP: | |
732 ReleaseCapture(); | |
733 createMouseEvent(MouseButton.Middle, (MouseEventArgs args) { | |
734 c.mouseUp(args); | |
735 }); | |
736 return 0; | |
737 case WM_RBUTTONUP: | |
738 ReleaseCapture(); | |
739 createMouseEvent(MouseButton.Right, (MouseEventArgs args) { | |
740 c.mouseUp(args); | |
741 }); | |
742 return 0; | |
743 case WM_XBUTTONUP: | |
744 ReleaseCapture(); | |
745 auto button = getFromXBUTTONX(); | |
746 if(!button) break; | |
747 createMouseEvent(button, (MouseEventArgs args) { | |
748 c.mouseUp(args); | |
749 }); | |
750 return true; | |
751 case WM_MOUSEWHEEL: | |
752 int scrollLines; | |
753 SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0); | |
754 if(scrollLines == 0xFFFFFFFF) | |
755 scrollLines = 3; | |
756 int delta = -cast(short)HIWORD(wParam); | |
757 auto screenPt = Point(LOWORD(lParam), HIWORD(lParam)); | |
758 auto des = c.getDescendantAtPoint(c.screenToContent(screenPt)); | |
759 des.mouseTurned( | |
760 new MouseTurnedEventArgs(delta, delta*scrollLines/120.0) ); | |
761 return 0; | |
762 case WM_SYSKEYDOWN: | |
763 //Stdout.format("WM_SYSKEYDOWN: {:x}", cast(int)wParam).newline; | |
764 if(wParam == 0x79) return 0; | |
765 break; | |
766 case WM_KEYDOWN: | |
767 //Stdout.format("WM_KEYDOWN: {:x}", cast(int)wParam).newline; | |
768 Control focused = c.focusedControl ? c.focusedControl : c; | |
769 focused.keyDown(new KeyEventArgs( | |
770 VKToKey(wParam), cast(bool)(lParam & (1 << 30)) )); | |
771 return 0; | |
772 case WM_SYSKEYUP: | |
773 //Stdout.format("WM_SYSKEYUP: {:x}", cast(int)wParam).newline; | |
774 if(wParam == 0x79) return 0; | |
775 break; | |
776 case WM_KEYUP: | |
777 //Stdout.format("WM_KEYUP: {:x}", cast(int)wParam).newline; | |
778 Control focused = c.focusedControl ? c.focusedControl : c; | |
779 focused.keyUp(new KeyEventArgs( VKToKey(wParam), false )); | |
780 return 0; | |
781 case WM_CHAR: | |
782 // DO NOT use the repeat count from the lParam to send multiple events | |
783 // I hate when programs do that | |
784 | |
785 //stop backspace and escape and shift+enter | |
786 if(wParam == 0x08 || wParam == 0x1B || wParam == 0x0A) | |
787 break; | |
788 // don't process characters typed while control is down | |
789 if(HIBYTE(GetKeyState(VK_CONTROL))) | |
790 break; | |
791 if(wParam == 0x0D) // change \r to \n | |
792 wParam = 0x0A; | |
793 bool repeat; | |
794 repeat = cast(bool)(lParam & (1 << 30)); | |
795 Control focused = c.focusedControl ? c.focusedControl : c; | |
796 focused.keyTyped(new KeyTypedEventArgs(cast(dchar)wParam, repeat)); | |
797 return 0; | |
798 case WM_PRINT: | |
799 paintToHDC(cast(HDC)wParam, getControl(hwnd), null); | |
800 return 0; | |
801 case WM_PAINT: | |
802 PAINTSTRUCT ps; | |
803 BeginPaint(hwnd, &ps); | |
804 RECT* clip = &ps.rcPaint; | |
805 | |
806 HDC hdcBuffer = CreateCompatibleDC(ps.hdc); | |
807 HBITMAP hbmpBuffer = CreateCompatibleBitmap(ps.hdc, | |
808 clip.right-clip.left, clip.bottom-clip.top); | |
809 HBITMAP hbmpDefault = SelectObject(hdcBuffer, hbmpBuffer); | |
810 | |
811 paintToHDC(hdcBuffer, getControl(hwnd), clip); | |
812 | |
813 BitBlt(ps.hdc, clip.left, clip.top, clip.right-clip.left, clip.bottom-clip.top, | |
814 hdcBuffer, 0, 0, SRCCOPY); | |
815 SelectObject(hdcBuffer, hbmpDefault); | |
816 DeleteDC(hdcBuffer); | |
817 DeleteObject(hbmpBuffer); | |
818 | |
819 EndPaint(hwnd, &ps); | |
820 return 0; | |
821 case WM_CLOSE: | |
822 c.visible = false; | |
823 //DestroyWindow(hwnd); | |
824 //PostQuitMessage(0); | |
825 return 0; | |
826 case WM_DESTROY: | |
827 return 0; | |
828 default: | |
829 break; | |
830 } | |
831 return DefWindowProc(hwnd, uMsg, wParam, lParam); | |
832 } | |
833 //}}} | |
834 | |
835 //{{{ paintToHDC() | |
836 void paintToHDC(HDC hdc, Window w, RECT* clip) { | |
837 cairo_surface_t* surface = cairo_win32_surface_create(hdc); | |
838 cairo_t* cr = cairo_create(surface); | |
839 cairo_surface_destroy(surface); | |
840 | |
841 if(clip) { | |
842 cairo_translate(cr, | |
843 -clip.left-w.borderSize.left, -clip.top-w.borderSize.top); | |
844 | |
845 //cairo_rectangle(cr, clip.left, clip.top, clip.right-clip.left, clip.bottom-clip.top); | |
846 } | |
847 //if(w.Opaque) { | |
848 //cairo_set_source_rgb(cr, w.content.backColor.R/255.0, w.content.backColor.G/255.0, w.content.backColor.B/255.0); | |
849 //cairo_paint(cr); | |
850 //} | |
851 | |
852 //cairo_set_source_rgb(cr, .3, .3, .3); | |
853 //cairo_paint(cr); | |
854 | |
855 //cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); | |
856 //cairo_paint(cr); | |
857 //cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | |
858 | |
859 cairo_set_source_rgb(cr, 0, 0, 0); | |
860 cairo_set_line_width(cr, 1.0); | |
861 | |
862 //HBITMAP hbmp = LoadImage(null, cast(wchar*)cast(ushort)OIC_WARNING, | |
863 // IMAGE_ICON, 0, 0, LR_SHARED); | |
864 //if(hbmp == null) | |
865 // Stdout.format("LoadImage failed. GetLastError()={}", GetLastError()).newline; | |
866 | |
867 //auto imgSurface = cairo_image_surface_create_for_data(); | |
868 //cairo_set_source_surface(cr, imgSurface, 50, 50); | |
869 //cairo_paint(cr); | |
870 //cairo_surface_destroy(imgSurface); | |
871 | |
872 auto g = new Graphics(cr); | |
873 scope args = new PaintingEventArgs(g); | |
874 w.painting(args); | |
875 delete g; | |
876 cairo_destroy(cr); | |
877 } | |
878 //}}} | |
879 | |
880 //{{{ VKToKey() | |
881 Key VKToKey(int code) { | |
882 switch(code) { | |
883 case VK_F1: return Key.F1; | |
884 case VK_F2: return Key.F2; | |
885 case VK_F3: return Key.F3; | |
886 case VK_F4: return Key.F4; | |
887 case VK_F5: return Key.F5; | |
888 case VK_F6: return Key.F6; | |
889 case VK_F7: return Key.F7; | |
890 case VK_F8: return Key.F8; | |
891 case VK_F9: return Key.F9; | |
892 case VK_F10: return Key.F10; | |
893 case VK_F11: return Key.F11; | |
894 case VK_F12: return Key.F12; | |
895 | |
896 case VK_ESCAPE: return Key.Escape; | |
897 case VK_TAB: return Key.Tab; | |
898 case VK_BACK: return Key.Backspace; | |
899 case VK_RETURN: return Key.Enter; | |
900 case VK_SPACE: return Key.Space; | |
901 | |
902 case VK_LEFT: return Key.Left; | |
903 case VK_RIGHT: return Key.Right; | |
904 case VK_UP: return Key.Up; | |
905 case VK_DOWN: return Key.Down; | |
906 | |
907 case VK_INSERT: return Key.Insert; | |
908 case VK_DELETE: return Key.Delete; | |
909 case VK_HOME: return Key.Home; | |
910 case VK_END: return Key.End; | |
911 case VK_PRIOR: return Key.PageUp; | |
912 case VK_NEXT: return Key.PageDown; | |
913 | |
914 case VK_SNAPSHOT: return Key.PrintScreen; | |
915 case VK_PAUSE: return Key.Pause; | |
916 | |
917 case VK_CAPITAL: return Key.CapsLock; | |
918 case VK_NUMLOCK: return Key.NumLock; | |
919 case VK_SCROLL: return Key.ScrollLock; | |
920 | |
921 case VK_NUMPAD0: return Key.NumPad0; | |
922 case VK_NUMPAD1: return Key.NumPad1; | |
923 case VK_NUMPAD2: return Key.NumPad2; | |
924 case VK_NUMPAD3: return Key.NumPad3; | |
925 case VK_NUMPAD4: return Key.NumPad4; | |
926 case VK_NUMPAD5: return Key.NumPad5; | |
927 case VK_NUMPAD6: return Key.NumPad6; | |
928 case VK_NUMPAD7: return Key.NumPad7; | |
929 case VK_NUMPAD8: return Key.NumPad8; | |
930 case VK_NUMPAD9: return Key.NumPad9; | |
931 case VK_DIVIDE: return Key.NumPadDivide; | |
932 case VK_MULTIPLY: return Key.NumPadMultiply; | |
933 case VK_SUBTRACT: return Key.NumPadSubtract; | |
934 case VK_ADD: return Key.NumPadAdd; | |
935 case VK_DECIMAL: return Key.NumPadDecimal; | |
936 | |
937 case VK_OEM_3: return Key.Backquote; | |
938 case VK_OEM_MINUS: return Key.Minus; | |
939 case VK_OEM_PLUS: return Key.Equals; | |
940 case VK_OEM_4: return Key.OpenBracket; | |
941 case VK_OEM_6: return Key.CloseBracket; | |
942 case VK_OEM_5: return Key.Backslash; | |
943 case VK_OEM_1: return Key.Semicolon; | |
944 case VK_OEM_7: return Key.Quote; | |
945 case VK_OEM_COMMA: return Key.Comma; | |
946 case VK_OEM_PERIOD: return Key.Period; | |
947 case VK_OEM_2: return Key.Slash; | |
948 | |
949 //case VK_APPS: return Key.Menu; | |
950 | |
951 case VK_SHIFT: return Key.Shift; | |
952 case VK_CONTROL: return Key.Control; | |
953 case VK_MENU: return Key.Alt; | |
954 | |
955 //case VK_: return Key.; | |
956 default: | |
957 if(code >= 0x30 && code <= 0x39) // Key.D0 - Key.D9 | |
958 return cast(Key)code; | |
959 if(code >= 0x41 && code <= 0x5A) // Key.A - Key.Z | |
960 return cast(Key)code; | |
961 return cast(Key)0; | |
962 } | |
963 } | |
964 //}}} | |
965 | |
966 // Use the msgWnd for the following: | |
967 // Timers | |
968 // Clipboard.DataChanged event | |
969 // Clipboard? | |
970 // Taskbar created event using RegisterWindowMessage("TaskbarCreated") | |
971 // different settings changed events? | |
972 // screen saver enabled? | |
973 extern(Windows) | |
974 LRESULT dynaminMsgWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { | |
975 switch(uMsg) { | |
976 case WM_THEMECHANGED: | |
977 Ux.themeChanged(); | |
978 return 0; | |
979 case WM_POWERBROADCAST: | |
980 if(wParam == PBT_APMRESUMESUSPEND || wParam == PBT_APMRESUMECRITICAL) | |
981 Environment.backend_increaseTimerRes(); | |
982 return 0; | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
983 case WM_USER + 7: |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
984 void delegate() dg; |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
985 dg.ptr = cast(void*)wParam; |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
986 dg.funcptr = cast(void function())lParam; |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
987 dg(); |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
988 return 0; |
0 | 989 case WM_TIMER: |
990 case WM_CHANGECBCHAIN: | |
991 case WM_DRAWCLIPBOARD: | |
992 case WM_TIMECHANGE: //?? | |
993 default: | |
994 break; | |
995 } | |
996 return DefWindowProc(hwnd, uMsg, wParam, lParam); | |
997 } | |
998 |