1 namespace gui::drivers;
12 #define _WIN32_WINNT 0x0501
19 #define WIN32_LEAN_AND_MEAN
20 #define Method _Method
23 #define String _String
25 #define Platform _Platform
31 #if defined(ECERE_VANILLA)
32 #define ECERE_NOJOYSTICK
35 #ifndef ECERE_NODINPUT
36 #ifndef ECERE_NOJOYSTICK
37 #define DIRECTINPUT_VERSION 0x700
40 #define DIRECTINPUT_VERSION 0x300
50 #define VK_EQUALS 0xBB
53 #define VK_PERIOD 0xBE
56 #define VK_LBRACKET 0xDB
57 #define VK_BACK_SLASH 0xDC
58 #define VK_RBRACKET 0xDD
62 #define WM_MOUSEWHEEL 0x20A
66 #define IDC_HAND (char *)0x7F89
71 #define LWA_COLORKEY 0x00000001
72 #define LWA_ALPHA 0x00000002
74 #define WS_EX_LAYERED 0x00080000
79 SetLayeredWindowAttributes(
97 #define ECERE_NODINPUT
98 #define ECERE_NOJOYSTICK
99 #define ECERE_NOBLENDING
102 static byte key2VK[256] =
104 0,VK_ESCAPE,'1','2','3','4','5','6','7','8','9','0',VK_MINUS,VK_EQUALS,VK_BACK,VK_TAB,
105 'Q','W','E','R','T','Y','U','I','O','P',VK_LBRACKET,VK_RBRACKET,VK_RETURN,VK_CONTROL,'A','S',
106 'D','F','G','H','J','K','L',VK_SEMI,VK_QUOTE,VK_TILDE,VK_SHIFT,VK_BACK_SLASH,'Z','X','C','V',
107 'B','N','M',VK_COMMA,VK_PERIOD,VK_DIVIDE,VK_SHIFT,VK_MULTIPLY,VK_LMENU,VK_SPACE,VK_CAPITAL,VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,
108 VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,VK_NUMLOCK,VK_SCROLL,VK_NUMPAD7,VK_NUMPAD8,VK_NUMPAD9,VK_SUBTRACT,VK_NUMPAD4,VK_NUMPAD5,VK_NUMPAD6,VK_ADD,VK_NUMPAD1,
109 VK_NUMPAD2,VK_NUMPAD3,VK_NUMPAD0,VK_DELETE,0,0,0,VK_F11,VK_F12,0,0,0,0,0,0,0,
110 0,0,0,0,0,0,VK_HOME,VK_UP,VK_PRIOR,VK_LEFT,VK_RIGHT,VK_END,VK_DOWN,VK_NEXT,VK_INSERT,VK_DELETE,
111 0,0,0,VK_SHIFT,VK_MENU,VK_CONTROL
113 static char className[] = "ECERE Application";
114 static HINSTANCE hInstance;
116 static DEVMODE devMode;
117 static HWND acquiredWindow = null;
118 static HCURSOR systemCursors[SystemCursor];
119 static bool fullScreenMode;
120 static int desktopX = 0, desktopY = 0, desktopW = 0, desktopH = 0;
121 static DWORD hiResTimer;
122 // static HWND topWindow;
124 static HWND startBar;
126 #ifndef ECERE_NODINPUT
128 static HMODULE dInputDll = null;
129 static BOOL * (WINAPI * directInputCreate)(HINSTANCE, DWORD, IDirectInput **, void *);
130 static IDirectInput * dInput = null;
131 static IDirectInputDevice * directMouse = null;
132 #ifndef ECERE_NOJOYSTICK
133 static int numJoysticks = 0;
134 static IDirectInputDevice2 * directJoysticks[NUMJOY] = {null,null,null,null};
139 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit;
140 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp;
141 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
142 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit;
143 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;
144 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick;
145 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown;
146 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp;
147 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick;
148 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown;
149 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp;
150 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick;
151 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown;
152 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp;
156 static Box lastMonitorAreas[32];
157 static Box monitorAreas[32];
160 static bool EnumerateMonitors(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
162 MONITORINFO info = { 0 };
163 info.cbSize = sizeof(MONITORINFO);
164 GetMonitorInfo(hMonitor, &info);
165 monitorAreas[monitor] = { info.rcWork.left, info.rcWork.top, info.rcWork.right, info.rcWork.bottom };
170 static bool externalDisplayChange;
172 static int taskBarState;
173 static WINDOWPLACEMENT taskBarPlacement;
174 static bool activateApp;
176 static SystemCursor lastCursor = (SystemCursor)-1;
178 void AeroSnapPosition(Window window, int x, int y, int w, int h)
180 int oldX = window.absPosition.x;
182 // To prevent having a window < minClientSize with Aero Snap, because we don't receive a WM_SIZING!
183 // The sensible implementation of this is in WM_SIZING
187 window.GetDecorationsSize(&ew, &eh);
195 gw = Max(gw, window.minSize.w);
196 gh = Max(gh, window.minSize.h);
197 gw = Min(gw, window.maxSize.w);
198 gh = Min(gh, window.maxSize.h);
200 if(!window.OnResizing(&gw, &gh))
202 gw = window.clientSize.w;
203 gh = window.clientSize.h;
206 gw = Max(gw, window.skinMinSize.w);
207 gh = Max(gh, window.skinMinSize.h);
212 if(w != gw || h != gh)
215 // Adjust x position if we resized from top or bottom left corner
223 guiApp.interfaceDriver.PositionRootWindow(window, x, y, w, h, move, true);
226 window.ExternalPosition(x, y, w, h);
229 class Win32Interface : Interface
231 class_property(name) = "Win32";
233 void ::RepositionDesktop(bool updateChildren)
236 static double lastTime = 0, time;
239 static Size lastScreen;
240 static Point lastScreenPos;
241 static WINDOWPLACEMENT lastPlacement;
243 static double lastAutoHideCheck = 0;
244 int newTaskBarState = taskBarState;
245 HMONITOR primaryMonitor;
248 if(time - lastTime < 0.1) return;
251 // Every sec, check for the auto hide property
252 if(time - lastAutoHideCheck > 1)
254 APPBARDATA appBarData = { 0 };
255 newTaskBarState = (int)SHAppBarMessage(ABM_GETSTATE, &appBarData);
256 lastAutoHideCheck = time;
260 EnumDisplayMonitors(null, null, EnumerateMonitors, 0);
261 for(c = 0; c<monitor; c++)
263 if(monitorAreas[c].left != lastMonitorAreas[c].left ||
264 monitorAreas[c].top != lastMonitorAreas[c].top ||
265 monitorAreas[c].right != lastMonitorAreas[c].right ||
266 monitorAreas[c].bottom != lastMonitorAreas[c].bottom)
272 memcpy(lastMonitorAreas, monitorAreas, sizeof(monitorAreas));
274 guiApp.virtualScreen =
276 GetSystemMetrics(SM_CXVIRTUALSCREEN),
277 GetSystemMetrics(SM_CYVIRTUALSCREEN)
279 guiApp.virtualScreenPos =
281 x = GetSystemMetrics(SM_XVIRTUALSCREEN),
282 y = GetSystemMetrics(SM_YVIRTUALSCREEN)
286 HMONITOR monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
289 MONITORINFO info = { 0 };
290 info.cbSize = sizeof(MONITORINFO);
291 primaryMonitor = monitor;
292 GetMonitorInfo(monitor, &info);
293 x = info.rcMonitor.left;
294 y = info.rcMonitor.top;
295 w = info.rcMonitor.right - info.rcWork.left;
296 h = info.rcMonitor.bottom - info.rcWork.top;
301 WINDOWPLACEMENT placement = { 0 };
302 placement.length = sizeof(WINDOWPLACEMENT);
304 if(!GetWindowPlacement(startBar, &placement))
306 startBar = FindWindowA("Shell_TrayWnd", null);
307 GetWindowPlacement(startBar, &placement);
310 HMONITOR taskBarMonitor = MonitorFromWindow(startBar, MONITOR_DEFAULTTONEAREST);
311 if(primaryMonitor == taskBarMonitor)
313 if(placement.rcNormalPosition.top <= 0 && placement.rcNormalPosition.bottom >= h - 1)
315 if(placement.rcNormalPosition.left <= 0)
317 x = (taskBarState & ABS_AUTOHIDE) ? 1 : placement.rcNormalPosition.right;
321 w = (taskBarState & ABS_AUTOHIDE) ? (w - 1) : Min(placement.rcNormalPosition.left, w);
323 else if(placement.rcNormalPosition.left <= 0 && placement.rcNormalPosition.right >= w - 1)
325 if(placement.rcNormalPosition.top <= 0)
327 y = (taskBarState & ABS_AUTOHIDE) ? 1 : placement.rcNormalPosition.bottom;
331 h = (taskBarState & ABS_AUTOHIDE) ? (h - 1) : Min(placement.rcNormalPosition.top, h);
337 placement.rcNormalPosition.left != taskBarPlacement.rcNormalPosition.left ||
338 placement.rcNormalPosition.top != taskBarPlacement.rcNormalPosition.top ||
339 placement.rcNormalPosition.right != taskBarPlacement.rcNormalPosition.right ||
340 placement.rcNormalPosition.bottom != taskBarPlacement.rcNormalPosition.bottom ||
341 newTaskBarState != taskBarState)
343 taskBarState = newTaskBarState;
344 guiApp.desktop.size.w = 0;
349 taskBarPlacement = placement;
350 guiApp.SetDesktopPosition(x, y, w, h, updateChildren);
353 lastScreen = guiApp.virtualScreen;
354 lastScreenPos = guiApp.virtualScreenPos;
358 /****************************************************************************
359 /// PRIVATE UTILITY FUNCTIONS /////////////
360 ****************************************************************************/
361 // --- Keyboard Input ---
362 bool ::ProcessKeyMessage(Window window, DWORD msg, WPARAM wParam, LPARAM lParam, unichar ch)
368 bool frenchShift = (ch < 0x10000) ? (((VkKeyScan((uint16)ch) >> 8) & 6) == 6) : false;
370 if(msg == WM_CHAR || msg == WM_DEADCHAR)
375 if(msg == WM_MOUSEWHEEL)
376 code = (((short) HIWORD(wParam)) < 0) ? wheelDown : wheelUp;
379 key = (byte)((lParam & 0xFF0000)>>16);
380 if(lParam & 0x1000000)
382 key = Interface::GetExtendedKey(key);
392 if(msg == WM_MOUSEWHEEL)
394 if(::GetAsyncKeyState(VK_SHIFT) & 0x80000)
396 if(::GetAsyncKeyState(VK_CONTROL) & 0x80000)
398 if(::GetAsyncKeyState(VK_MENU) & 0x80000)
401 result = window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit, code, 0);
405 if(key != leftShift && key != rightShift && ::GetKeyState(VK_SHIFT) & 0x80000)
407 if(key != leftControl && key != rightControl && ::GetKeyState(VK_CONTROL) & 0x80000 && !frenchShift)
409 if(key != leftAlt && key != rightAlt && ::GetKeyState(VK_MENU) & 0x80000 && !frenchShift)
412 byte ch = Interface::TranslateKeykey, code.shift);
413 if(::GetKeyState(VK_CAPITAL))
417 if(msg == WM_KEYUP || msg == WM_SYSKEYUP)
419 result = window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, code, ch);
423 if(!(lParam & 0x40000000))
428 Class * keyClass = eSystem_FindClass(__ecereModule, "Key");
429 code.OnGetString(string, null, null);
430 eSystem_Logf("%s\n", string);
434 result = window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, code, ch);
437 result = window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit, code,ch);
444 // --- Window procedure ---
445 DWORD CALLBACK ::ApplicationWindow(HWND windowHandle, UINT msg, WPARAM wParam, LPARAM lParam)
448 Window window = (Window)GetWindowLongPtr(windowHandle, GWLP_USERDATA);
450 Window window = (Window)GetWindowLong(windowHandle, GWL_USERDATA);
452 static Point lastPos;
459 case WM_QUERYNEWPALETTE:
460 case WM_PALETTECHANGED:
462 window.display.RestorePalette();
463 UpdateWindow(windowHandle);
467 if(!fullScreenMode && !guiApp.IsModeSwitching())
471 Window modalRoot = window.FindModal();
473 HWND modalWindow = modalRoot ? modalRoot.windowHandle : null;
475 FLASHWINFO flashInfo = { 0 };
476 flashInfo.cbSize = sizeof(FLASHWINFO);
477 flashInfo.hwnd = window.windowHandle;
478 flashInfo.uCount = 0;
479 flashInfo.dwFlags = FLASHW_STOP;
480 FlashWindowEx((void *)&flashInfo);
482 if(modalWindow && modalWindow != windowHandle)
483 modalRoot.ExternalActivate(true, true, window, null);
485 window.ExternalActivate(true, true, window, null);
492 foreground = GetForegroundWindow();
493 if(foreground == windowHandle && lParam)
494 foreground = (HWND)lParam;
496 GetWindowThreadProcessId(foreground, &id);
499 windowLong = (void*)GetWindowLongPtr(foreground, GWLP_WNDPROC);
501 windowLong = (void*)GetWindowLong(foreground, GWL_WNDPROC);
503 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
504 // The != ApplicationWindow check is for not recognizing the Console window as an Ecere Window
505 // That check causes a problem with the OpenGL driver which seems to popup a window of a different class
506 if(window.displaySystem && window.displaySystem.driver == class(OpenGLDisplayDriver))
507 windowLong = (void *)ApplicationWindow;
509 if(id != GetCurrentProcessId() || windowLong != (void *)ApplicationWindow)
510 window.ExternalActivate(false, true, window, null);
511 // DefWindowProc for WM_NCACTIVATE draws the decorations, make sure it's drawn in the right state
512 return (uint)DefWindowProc(windowHandle, msg, window.active, lParam);
517 for(window = guiApp.desktop.firstChild; window; window = window.next)
518 SetWindowPos(window.windowHandle, window.style.stayOnTop ? HWND_TOPMOST : HWND_TOP, 0,0,0,0,
519 SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOSIZE); //|SWP_NOREDRAW);
523 return (uint)DefWindowProc(windowHandle, msg, window ? window.active : wParam, lParam);
526 if(!guiApp.IsModeSwitching())
530 HDC hdc = GetDC(windowHandle);
533 guiApp.SetAppFocus(false);
534 ShowWindow(windowHandle, SW_MINIMIZE);
535 ChangeDisplaySettings(null,0);
536 SetSystemPaletteUse(hdc, SYSPAL_STATIC);
540 ChangeDisplaySettings(&devMode, CDS_FULLSCREEN);
541 SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC);
543 window.display.RestorePalette();
544 ShowWindow(windowHandle, SW_SHOWNORMAL);
545 guiApp.SetAppFocus(true);
547 window.display.Resize(window.clientSize.w, window.clientSize.h);
550 ReleaseDC(windowHandle, hdc);
556 if(wParam && !guiApp.desktop.active /*&& lParam != GetCurrentThreadID()*/)
560 for(window = guiApp.desktop.firstChild; window; window = window.next)
561 SetWindowPos(window.windowHandle, window.style.stayOnTop ? HWND_TOPMOST : HWND_TOP, 0,0,0,0,
562 SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOSIZE); //|SWP_NOREDRAW);
565 guiApp.SetAppFocus((bool)wParam);
569 guiApp.SetAppFocus((bool)wParam);
573 if(!window.alphaBlend || window.display.pixelFormat != pixelFormat888)
578 #define ACCESS_ITEM(l, id) \
579 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
582 #define ACCESS_ITEM(l, id) \
585 BoxItem item = window.dirtyArea.count ? (BoxItem)ACCESS_ITEM(window.dirtyArea, window.dirtyArea.first) : null;
587 BeginPaint(windowHandle, &ps);
589 // Prevent flickering if we're going to update anyways
591 printf(" Paint message (%d, %d)-(%d, %d)\n",
592 item ? item.box.left : 0,
593 item ? item.box.top : 0,
594 item ? item.box.right : 0,
595 item ? item.box.bottom : 0);
597 // Causes redraw bug...
598 if(!window.manageDisplay || !item ||
601 item.box.right < window.size.w - 1 ||
602 item.box.bottom < window.size.h - 1)
604 Box box { ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-1, ps.rcPaint.bottom-1 };
605 window.UpdateDirty(box);
607 // TODO: Fix precompiler with
608 // window.UpdateDirty((Box *)&ps.rcPaint);
609 EndPaint(windowHandle, &ps);
613 case WM_DISPLAYCHANGE:
615 static int lastBits = 0;
616 static int lastRes = 0;
617 if(lastBits != wParam || lastRes != lParam)
619 lastBits = (int)wParam;
620 lastRes = (int)lParam;
622 externalDisplayChange = true;
623 if(guiApp.desktop.DisplayModeChanged())
626 if(!window.style.hidden)
627 ShowWindow(windowHandle, SW_SHOWNOACTIVATE /*SW_SHOWNORMAL*/);
628 window.FigureCaption(caption);
629 SetRootWindowCaption(window, caption);
631 externalDisplayChange = false;
646 if(msg != WM_CHAR && window.composing)
651 case WM_SYSKEYDOWN: min = max = WM_SYSCHAR; break;
652 case WM_KEYDOWN: min = max = WM_CHAR; break;
653 case WM_SYSKEYUP: min = WM_SYSCHAR; max = WM_SYSDEADCHAR; break;
654 case WM_KEYUP: min = WM_CHAR; max = WM_DEADCHAR; break;
657 // This is very annoying.
658 // PeekMessage somehow invokes this function directly... don't know why.
659 // Only crashes when running through debug mode in visual studio
661 if(msg == WM_CHAR || msg == WM_DEADCHAR || PeekMessage(&charMsg, windowHandle, min, max, PM_REMOVE))
663 ch = (msg == WM_CHAR || msg == WM_DEADCHAR) ? (unichar)wParam : (unichar)charMsg.wParam;
664 // TOCHECK: What is this for again? Fixing some obscure activation status?
665 // -- I believe this was somehow allowing 'unmaximizing', but was causing problems
666 // as there was no way to prevent AltEnter from doing so (e.g. when it is used for a node property)
667 // Worked around by fixing ProcessHotKeys to properly check for sysButtons in parent.parent when sys buttons
668 // are placed inside a menu bar for a document
670 if(msg == WM_SYSKEYDOWN && ch == 13)
672 ShowWindow(window.windowHandle, window.state == maximized ? SW_MAXIMIZE : SW_SHOWNORMAL);
673 // This last line been commented out for a long time:
674 // window.ExternalActivate(true, true, window, null);
677 if(msg == WM_SYSKEYUP || msg == WM_KEYUP)
679 if(!ProcessKeyMessage(window, WM_KEYDOWN, 0x40000000, 0, ch))
685 ProcessKeyMessage(window, msg, wParam, lParam, ch);
686 if(window.composing && msg == WM_CHAR)
688 COMPOSITIONFORM form;
689 Window caretOwner = guiApp.caretOwner;
692 HIMC ctx = ImmGetContext(windowHandle);
693 form.dwStyle = CFS_POINT;
694 form.ptCurrentPos.x = caretOwner.caretPos.x - caretOwner.scroll.x + caretOwner.absPosition.x - window.absPosition.x + 4;
695 form.ptCurrentPos.y = caretOwner.caretPos.y - caretOwner.scroll.x + caretOwner.absPosition.y - window.absPosition.y + 2;
696 window.composing = true;
697 ImmSetCompositionWindow(ctx, &form);
698 ImmReleaseContext(windowHandle, ctx);
701 if(msg != WM_MOUSEWHEEL)
705 case WM_IME_STARTCOMPOSITION:
707 COMPOSITIONFORM form;
708 Window caretOwner = guiApp.caretOwner;
711 HIMC ctx = ImmGetContext(windowHandle);
712 form.dwStyle = CFS_POINT;
713 form.ptCurrentPos.x = caretOwner.caretPos.x - caretOwner.scroll.x + caretOwner.absPosition.x - window.absPosition.x + 4;
714 form.ptCurrentPos.y = caretOwner.caretPos.y - caretOwner.scroll.y + caretOwner.absPosition.y - window.absPosition.y + 2;
716 form.rcArea.left = window.caretPos.x;
717 form.rcArea.top = 250;
718 form.rcArea.right = 500;
719 form.rcArea.bottom = 300;
721 window.composing = true;
722 DefWindowProc(windowHandle, msg, wParam, lParam);
723 ImmSetCompositionWindow(ctx, &form);
724 ImmSetStatusWindowPos(ctx, &form.ptCurrentPos);
726 FontResource res = caretOwner.font;
727 LOGFONT font = { 0 };
729 int pixels = GetDeviceCaps(hdc, LOGPIXELSY);
731 font.lfHeight = -(int)((float)res.size * pixels / 72 + 0.5);
732 font.lfWeight = res.flags.bold ? FW_BOLD : FW_NORMAL;
733 font.lfItalic = res.flags.italic ? TRUE : FALSE,
734 font.lfUnderline = res.flags.underline ? TRUE : FALSE;
735 font.lfCharSet = DEFAULT_CHARSET;
736 font.lfOutPrecision = OUT_DEFAULT_PRECIS;
737 font.lfClipPrecision = CLIP_DEFAULT_PRECIS;
738 font.lfQuality = DEFAULT_QUALITY;
739 font.lfPitchAndFamily = (byte)(DEFAULT_PITCH|FF_DONTCARE); // TODO: Fix compiler 0 | 0 to produce byte, not int
740 UTF8toUTF16Buffer(res.faceName, font.lfFaceName, LF_FACESIZE);
742 ImmSetCompositionFont(ctx, &font);
743 ImmReleaseContext(windowHandle, ctx);
749 case WM_IME_ENDCOMPOSITION:
750 window.composing = false;
751 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
752 /*case WM_IME_COMPOSITION:
753 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
755 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
757 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
759 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
761 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
763 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
764 case WM_IME_SETCONTEXT:
765 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
767 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
769 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
770 case WM_IME_COMPOSITIONFULL:
771 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
774 if(window.nativeDecorations)
775 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
785 case WM_LBUTTONDBLCLK:
787 case WM_RBUTTONDBLCLK:
789 case WM_MBUTTONDBLCLK:
791 x = window.absPosition.x;
792 y = window.absPosition.y;
793 /*case WM_NCLBUTTONUP:
796 case WM_NCLBUTTONDOWN:
797 case WM_NCLBUTTONDBLCLK:
798 case WM_NCRBUTTONDOWN:
799 case WM_NCRBUTTONDBLCLK:
800 case WM_NCMBUTTONDOWN:
801 case WM_NCMBUTTONDBLCLK:*/
805 bool consequential = false;
807 x += (short)LOWORD(lParam);
808 y += (short)HIWORD(lParam);
810 if(window.nativeDecorations && msg != WM_NCMOUSEMOVE)
812 x += window.clientStart.x;
813 y += window.clientStart.y - (window.hasMenuBar ? skinMenuHeight : 0);
816 if(::GetKeyState(VK_SHIFT) & 0x80000) code.shift = true;
817 if(::GetKeyState(VK_CONTROL) & 0x80000) code.ctrl = true;
818 if(::GetKeyState(VK_MENU) & 0x80000) code.alt = true;
819 if(wParam & MK_LBUTTON) code.left = true;
820 if(wParam & MK_MBUTTON) code.middle = true;
821 if(wParam & MK_RBUTTON) code.right = true;
823 if(msg == WM_MOUSEMOVE)
825 if(lastPos.x == x && lastPos.y == y)
826 consequential = true;
836 window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x,y,&code, consequential, false);
838 //case WM_NCLBUTTONDBLCLK:
839 case WM_LBUTTONDBLCLK:
840 if(!window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick, x,y,&code, false, true))
842 //case WM_NCLBUTTONDOWN:
844 window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown,x,y,&code, false,
845 /*(msg == WM_LBUTTONDBLCLK) ? false: */true);
847 //case WM_NCLBUTTONUP:
848 case WM_LBUTTONUP: window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp, x,y,&code, false, false);break;
849 //case WM_NCMBUTTONDBLCLK:
850 case WM_MBUTTONDBLCLK:
851 if(!window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick, x,y,&code, false, false))
853 //case WM_NCMBUTTONDOWN:
855 window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown, x,y,&code, false,
856 (msg == WM_LBUTTONDBLCLK) ? false: true);
858 //case WM_NCMBUTTONUP:
860 window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp, x,y,&code, false, false);
862 //case WM_NCRBUTTONDBLCLK:
863 case WM_RBUTTONDBLCLK:
864 if(!window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick, x,y,&code, false, true))
866 //case WM_NCRBUTTONDOWN:
868 window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown, x,y,&code, false,
869 (msg == WM_LBUTTONDBLCLK) ? false: true);
871 //case WM_NCRBUTTONUP:
873 window.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp, x,y,&code, false, false);
877 if(msg == WM_NCMOUSEMOVE)
878 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
883 if(window.nativeDecorations)
885 if(DefWindowProc(windowHandle, msg, wParam, lParam))
888 // SetCursor(systemCursors[0]);
889 SetCursor((lastCursor == (SystemCursor)-1) ? null : systemCursors[lastCursor]);
892 case WM_EXITMENULOOP:
893 case WM_EXITSIZEMOVE:
894 // We had some DirectInput stuff in here
896 case WM_ENTERMENULOOP:
897 case WM_ENTERSIZEMOVE:
898 // We had some DirectInput stuff in here
908 WINDOWPLACEMENT placement = { 0 };
910 placement.length = sizeof(WINDOWPLACEMENT);
911 GetWindowRect(windowHandle, &rcWindow);
912 GetWindowPlacement(windowHandle, &placement);
914 x = rcWindow.left - desktopX;
915 y = rcWindow.top - desktopY;
916 w = rcWindow.right - rcWindow.left;
917 h = rcWindow.bottom - rcWindow.top;
919 AeroSnapPosition(window, x, y, w, h);
926 RECT * rect = (RECT *)lParam;
930 window.GetDecorationsSize(&ew, &eh);
932 w = rect->right - rect->left;
933 h = rect->bottom - rect->top;
941 w = Max(w, window.minSize.w);
942 h = Max(h, window.minSize.h);
943 w = Min(w, window.maxSize.w);
944 h = Min(h, window.maxSize.h);
946 if(!window.OnResizing(&w, &h))
948 w = window.clientSize.w;
949 h = window.clientSize.h;
952 w = Max(w, window.skinMinSize.w);
953 h = Max(h, window.skinMinSize.h);
958 if(wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT)
959 rect->left = rect->right - w;
961 rect->right = rect->left + w;
963 if(wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOP || wParam == WMSZ_TOPRIGHT)
964 rect->top = rect->bottom - h;
966 rect->bottom = rect->top + h;
972 if(window.nativeDecorations)
976 GetWindowRect(windowHandle, &rcWindow);
978 if(wParam == SIZE_MAXIMIZED && window.state != maximized)
979 window.state = maximized;
980 else if(wParam == SIZE_MINIMIZED && window.state != minimized)
981 window.state = minimized;
982 else if(wParam == SIZE_RESTORED && window.state != normal && window.visible)
983 window.state = normal;
985 x = rcWindow.left - desktopX;
986 y = rcWindow.top - desktopY;
987 w = rcWindow.right - rcWindow.left;
988 h = rcWindow.bottom - rcWindow.top;
990 AeroSnapPosition(window, x, y, w, h);
991 if(!guiApp.modeSwitching)
992 window.UpdateVisual(null);
995 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
999 return (uint)DefWindowProc(windowHandle, msg, wParam, lParam);
1003 return (uint)DefMDIChildProc(windowHandle, msg, wParam, lParam);
1004 // return DefWindowProc(windowHandle, msg, wParam, lParam);
1008 // --- DirectInput ---
1010 #ifndef ECERE_NODINPUT
1012 #ifndef ECERE_NOJOYSTICK
1013 bool CALLBACK ::JoystickCallback( const DIDEVICEINSTANCE* pdidInstance, void * context )
1015 if(!dInput->lpVtbl->CreateDevice(dInput, &GUID_Joystick,
1016 (IDirectInputDevice **)&directJoysticks[numJoysticks], null ))
1018 return DIENUM_CONTINUE;
1021 bool CALLBACK ::JoystickAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, void * context )
1024 IDirectInputDevice2 * curJoy = (IDirectInputDevice2 *)context;
1026 diprg.diph.dwSize = sizeof(DIPROPRANGE);
1027 diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
1028 diprg.diph.dwHow = DIPH_BYOFFSET;
1029 diprg.diph.dwObj = pdidoi->dwOfs;
1032 if(curJoy->lpVtbl->SetProperty(curJoy, DIPROP_RANGE, &diprg.diph))
1034 return DIENUM_CONTINUE;
1038 void ::TerminateDirectInput()
1043 directMouse->lpVtbl->Unacquire(directMouse);
1044 directMouse->lpVtbl->Release(directMouse);
1047 #ifndef ECERE_NOJOYSTICK
1048 for(j=0; j<numJoysticks; j++)
1050 if (directJoysticks[j])
1052 directJoysticks[j]->lpVtbl->Unacquire(directJoysticks[j]);
1053 directJoysticks[j]->lpVtbl->Release(directJoysticks[j]);
1054 directJoysticks[j] = null;
1061 dInput->lpVtbl->Release(dInput);
1065 directInputCreate = null;
1069 FreeLibrary(dInputDll);
1074 bool ::InitDirectInput()
1076 bool result = false;
1078 dInputDll = LoadLibraryA("dinput.dll");
1081 if((directInputCreate = (void *)GetProcAddress(dInputDll, "DirectInputCreateA")))
1083 if(!directInputCreate( hInstance, DIRECTINPUT_VERSION, &dInput, null ))
1088 if(!dInput->lpVtbl->CreateDevice(dInput, &GUID_SysMouse, &directMouse, null ))
1089 directMouse->lpVtbl->SetDataFormat(directMouse, &c_dfDIMouse );
1091 #ifndef ECERE_NOJOYSTICK
1093 dInput->lpVtbl->EnumDevices(dInput, DIDEVTYPE_JOYSTICK, JoystickCallback, null, DIEDFL_ATTACHEDONLY );
1094 for(j=0; j<NUMJOY; j++)
1095 if(directJoysticks[j])
1096 if(!directJoysticks[j]->lpVtbl->SetDataFormat(directJoysticks[j], &c_dfDIJoystick ))
1097 directJoysticks[j]->lpVtbl->EnumObjects(directJoysticks[j], JoystickAxesCallback, directJoysticks[j], DIDFT_AXIS );
1106 void ::AcquireDirectInput(HWND windowHandle, bool state)
1110 if((state && !acquiredWindow) || (!state && acquiredWindow == windowHandle))
1117 directMouse->lpVtbl->SetCooperativeLevel(directMouse, /*fullScreenMode ? */windowHandle /*: HWND_DESKTOP*/, DISCL_EXCLUSIVE|DISCL_FOREGROUND);
1118 directMouse->lpVtbl->Acquire(directMouse);
1121 directMouse->lpVtbl->Unacquire(directMouse);
1123 #ifndef ECERE_NOJOYSTICK
1124 for(j = 0; j<NUMJOY; j++)
1125 if(directJoysticks[j])
1129 directJoysticks[j]->lpVtbl->SetCooperativeLevel(directJoysticks[j], /*fullScreenMode ? */windowHandle /*: HWND_DESKTOP*/, DISCL_EXCLUSIVE|DISCL_FOREGROUND);
1130 directJoysticks[j]->lpVtbl->Acquire(directJoysticks[j]);
1133 directJoysticks[j]->lpVtbl->Unacquire(directJoysticks[j]);
1136 acquiredWindow = state ? windowHandle : null;
1141 /****************************************************************************
1142 /// INTEGRATION FUNCTIONALITY /////////////
1143 ****************************************************************************/
1144 bool eisWIN32ProcessKey(Window window, DWORD msg, DWORD wParam, DWORD lParam, byte ch)
1146 return ProcessKeyMessage(window, msg, wParam, lParam, ch);
1149 HWND eisWIN32GetWindowHandle(Window window)
1151 return window.windowHandle ? window.windowHandle : window.rootWindow.windowHandle;
1154 /****************************************************************************
1155 /// DRIVER IMPLEMENTATION /////////////
1156 ****************************************************************************/
1159 void CALLBACK ::TimerProc(UINT uTimerID, UINT uMsg, uint64 dwUser, uint64 dw1, uint64 dw2)
1161 void CALLBACK ::TimerProc(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
1164 guiApp.SignalEvent();
1167 // --- User Interface System ---
1172 CS_DBLCLKS, ApplicationWindow, 0L, 0L, 0,
1173 LoadIcon(null, IDI_APPLICATION),
1180 wcl.hInstance = hInstance = GetModuleHandle(null);
1181 RegisterClass(&wcl);
1183 // Move that in reposition desktop
1184 startBar = FindWindowA("Shell_TrayWnd", null);
1186 systemCursors[arrow] = LoadCursor(null, IDC_ARROW);
1187 systemCursors[iBeam] = LoadCursor(null, IDC_IBEAM);
1188 systemCursors[cross] = LoadCursor(null, IDC_CROSS);
1189 systemCursors[moving] = LoadCursor(null, IDC_SIZEALL);
1190 systemCursors[sizeNESW] = LoadCursor(null, IDC_SIZENESW);
1191 systemCursors[sizeNS ] = LoadCursor(null, IDC_SIZENS);
1192 systemCursors[sizeNWSE] = LoadCursor(null, IDC_SIZENWSE);
1193 systemCursors[sizeWE ] = LoadCursor(null, IDC_SIZEWE);
1194 systemCursors[hand ] = LoadCursor(null, IDC_HAND);
1196 SetTimer(null, 0, (DWORD)(1000.0 / 18.2), null);
1197 //SetTimer(null, 0, 1, null);
1201 hiResTimer = timeSetEvent(
1204 TimerProc,0,TIME_PERIODIC);
1207 hiResTimer = timeSetEvent(
1210 TimerProc,0,TIME_PERIODIC);
1214 topWindow = CreateWindowEx(0, className, "",WS_POPUP,0,0,1,1,HWND_DESKTOP,
1215 null, hInstance, null);
1222 if(hiResTimer) timeKillEvent(hiResTimer);
1223 #ifndef ECERE_NODINPUT
1224 TerminateDirectInput();
1228 void SetTimerResolution(uint hertz)
1230 if(hiResTimer) timeKillEvent(hiResTimer);
1232 hiResTimer = timeSetEvent(1000 / hertz, 1000 / hertz, TimerProc, 0, TIME_PERIODIC);
1235 bool ProcessInput(bool processAll)
1239 RepositionDesktop(true);
1240 if(PeekMessage(&msg,0,0,0,PM_NOREMOVE))
1242 while(PeekMessage(&msg,0,0,0,PM_REMOVE))
1244 TranslateMessage(&msg);
1245 DispatchMessage(&msg);
1246 // printf("%d\n", msg.message);
1247 if(!processAll || msg.message == WM_TIMER) break;
1256 MsgWaitForMultipleObjects(1, (void **)guiApp.semaphore, FALSE, (uint)(1000 / 18.2) /*INFINITE*/, QS_ALLINPUT);
1259 void Lock(Window window)
1264 void Unlock(Window window)
1269 char ** GraphicsDrivers(int * numDrivers)
1271 static char *graphicsDrivers[] = { "GDI", "DirectDraw", "OpenGL", "Direct3D", "Direct3D8", "Direct3D9" };
1272 *numDrivers = sizeof(graphicsDrivers) / sizeof(char *);
1273 return (char **)graphicsDrivers;
1276 void GetCurrentMode(bool * fullScreen, Resolution * resolution, PixelFormat * colorDepth, int * refreshRate)
1278 *fullScreen = fullScreenMode;
1282 for(c = 0; c<Resolution::enumSize; c++)
1283 if(GetResolutionWidth(c) == devMode.dmPelsWidth && GetResolutionHeight(c) == devMode.dmPelsHeight)
1288 switch(devMode.dmBitsPerPel)
1290 case 8: *colorDepth = pixelFormat8; break;
1291 case 16: *colorDepth = pixelFormat555; break;
1292 default: *colorDepth = pixelFormat888; break;
1294 * refreshRate = devMode.dmDisplayFrequency;
1298 void EnsureFullScreen(bool *fullScreen)
1303 bool ScreenMode(bool fullScreen, Resolution resolution, PixelFormat colorDepth, int refreshRate, bool * textMode)
1308 fullScreenMode = fullScreen;
1312 FillBytes(&devMode, 0, sizeof(DEVMODE));
1313 devMode.dmSize = (uint16)sizeof(devMode);
1314 devMode.dmFields |=DM_BITSPERPEL;
1315 devMode.dmFields |=DM_PELSWIDTH|DM_PELSHEIGHT;
1316 devMode.dmFields |= DM_DISPLAYFREQUENCY;
1317 devMode.dmBitsPerPel = colorDepth ? GetDepthBits(colorDepth) : GetDeviceCaps(hdc, BITSPIXEL);
1318 devMode.dmPelsWidth = resolution ? GetResolutionWidth(resolution) : GetSystemMetrics(SM_CXSCREEN);
1319 devMode.dmPelsHeight = resolution ? GetResolutionHeight(resolution) : GetSystemMetrics(SM_CYSCREEN);
1320 devMode.dmDisplayFrequency = refreshRate ? refreshRate : GetDeviceCaps(hdc, VREFRESH);
1321 if(ChangeDisplaySettings(&devMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
1325 SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC);
1326 guiApp.SetDesktopPosition(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), false);
1331 static bool firstTime = true;
1333 ChangeDisplaySettings(null, 0);
1335 SetSystemPaletteUse(hdc, SYSPAL_STATIC);
1336 desktopX = desktopY = desktopW = desktopH = 0;
1338 RepositionDesktop(false);
1345 // --- Window Creation ---
1346 void * CreateRootWindow(Window window)
1349 uint16 * text = UTF8toUTF16(window.text, null);
1352 windowHandle = CreateWindowEx(0, className, text,
1354 0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),
1356 null, hInstance, null);
1357 ShowWindow(windowHandle, SW_SHOWNORMAL);
1359 else if(window.systemParent)
1360 windowHandle = CreateWindowEx(0, className, text,
1361 WS_CHILD,0,0,1,1, window.systemParent, null, hInstance, null);
1366 HWND parentWindow = null; //HWND_DESKTOP; // we get different behaviors with desktop...
1367 Window master = window.master, rootWindow = (master && master != guiApp.desktop) ? master.rootWindow : null;
1368 if(window.style.stayOnTop)
1369 exStyle |= WS_EX_TOPMOST;
1371 if(rootWindow && (window._isModal || window.style.interim))
1372 parentWindow = rootWindow.is3D ? rootWindow.parent.windowHandle : rootWindow.windowHandle;
1374 if(window.alphaBlend)
1375 // if(window.background.a < 255) //&& window.style & ES_REDRAW) Not needed anymore?
1376 exStyle |= WS_EX_LAYERED; // | WS_EX_TRANSPARENT;
1378 // Toolwindow will disappear if they don't have AppWindow set
1379 if(window.style.showInTaskBar || (!parentWindow && window.style.thin))
1381 exStyle |= WS_EX_APPWINDOW;
1382 parentWindow = null;
1385 if(window.style.thin)
1386 exStyle |= WS_EX_TOOLWINDOW;
1388 if(window.windowHandle)
1389 windowHandle = window.windowHandle;
1392 if(window.nativeDecorations)
1394 BorderBits borderStyle = window.borderStyle; // FIXME!
1395 style = WS_OVERLAPPED;
1396 if(borderStyle.fixed)
1397 style |= WS_CAPTION;
1399 style |= WS_SYSMENU;
1400 if(borderStyle.sizable)
1401 style |= WS_THICKFRAME;
1402 if(window.hasMinimize)
1403 style |= WS_MINIMIZEBOX;
1404 if(window.hasMaximize)
1405 style |= WS_MAXIMIZEBOX;
1407 windowHandle = CreateWindowEx(
1410 style | (window.systemParent ? WS_CHILD :
1411 (WS_POPUP | (window.style.hasMinimize ? WS_MINIMIZEBOX : 0))),
1412 0,0,1,1, parentWindow, null, hInstance, null);
1414 if(exStyle & WS_EX_LAYERED)
1415 SetLayeredWindowAttributes(windowHandle, 0, 255 /*A(window.background)*/, LWA_ALPHA);
1421 SetWindowLongPtr(windowHandle, GWLP_USERDATA, (int64)window);
1423 SetWindowLong(windowHandle, GWL_USERDATA, (DWORD)window);
1426 return windowHandle;
1429 void DestroyRootWindow(Window window)
1432 int c, lockCount = guiApp.lockMutex.lockCount;
1433 for(c = 0; c < lockCount; c++)
1434 guiApp.lockMutex.Release();
1436 oldIcon = (HICON)SendMessage(window.windowHandle, WM_GETICON, ICON_BIG, 0);
1438 if(oldIcon && oldIcon != (HICON)GetClassLongPtr(window.windowHandle, GCLP_HICON))
1440 if(oldIcon && oldIcon != (HICON)GetClassLong(window.windowHandle, GCL_HICON))
1442 DestroyIcon(oldIcon);
1444 ShowWindow(window.windowHandle, SW_HIDE);
1447 SetWindowLongPtr(window.windowHandle, GWLP_USERDATA, (int64)null);
1449 SetWindowLong(window.windowHandle, GWL_USERDATA, 0);
1451 DestroyWindow(window.windowHandle);
1453 for(c = 0; c < lockCount; c++)
1454 guiApp.lockMutex.Wait();
1456 window.windowHandle = null;
1459 // -- Window manipulation ---
1461 void SetRootWindowCaption(Window window, char * name)
1463 uint16 * text = UTF8toUTF16(name, null);
1465 SetWindowText(window.windowHandle, text);
1470 void PositionRootWindow(Window window, int x, int y, int w, int h, bool move, bool resize)
1472 int flags = SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS;
1474 if(!window.systemParent && !fullScreenMode)
1480 if(!move) flags |= SWP_NOMOVE;
1481 if(!resize) flags |= SWP_NOSIZE;
1483 /*if(move && resize)
1485 flags |= SWP_NOMOVE;
1486 SetWindowPos(window.windowHandle, null, x, y, w, h, flags);
1487 flags &=~SWP_NOMOVE;
1488 flags |= SWP_NOSIZE;
1490 if(!window.nativeDecorations || window.state != maximized || !window.visible || guiApp.modeSwitching)
1491 SetWindowPos(window.windowHandle, null, x, y, w, h, flags);
1494 void OrderRootWindow(Window window, bool topMost)
1496 SetWindowPos(window.windowHandle, topMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0,0,0,0,
1497 SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW);
1500 void SetRootWindowColor(Window window)
1502 DWORD style = GetWindowLong(window.windowHandle, GWL_EXSTYLE);
1503 if(window.alphaBlend && window.display.pixelFormat == pixelFormat888)
1505 /*if(A(window.background) == 255)
1507 if((style & WS_EX_LAYERED) == WS_EX_LAYERED)
1508 SetWindowLong(window.windowHandle, GWL_EXSTYLE, style &~WS_EX_LAYERED);
1512 #ifndef ECERE_NOBLENDING
1513 if((style & WS_EX_LAYERED) != WS_EX_LAYERED)
1514 SetWindowLong(window.windowHandle, GWL_EXSTYLE, style | WS_EX_LAYERED);
1516 // SetLayeredWindowAttributes(window.windowHandle, 0, 255 /*Max(A(window.background),1)*/, LWA_ALPHA);
1521 void OffsetWindow(Window window, int * x, int * y)
1523 if(window.systemParent)
1525 POINT point = {*x,*y};
1526 ClientToScreen(GetParent(window.windowHandle), &point);
1532 void UpdateRootWindow(Window window)
1534 UpdateWindow(window.windowHandle);
1537 void SetRootWindowState(Window window, WindowState state, bool visible)
1545 ShowWindow(window.windowHandle, ((window.active || window.creationActivation == activate) && !externalDisplayChange) ?
1546 ((window.nativeDecorations && state == maximized) ? SW_MAXIMIZE : SW_SHOWNORMAL) : SW_SHOWNOACTIVATE);
1549 ShowWindow(window.windowHandle, SW_MINIMIZE);
1555 ShowWindow(window.windowHandle, SW_HIDE);
1559 void ActivateRootWindow(Window window)
1561 if(!externalDisplayChange)
1562 SetForegroundWindow(window.windowHandle);
1565 void FlashRootWindow(Window window)
1567 FLASHWINFO flashInfo = { 0 };
1568 flashInfo.cbSize = sizeof(FLASHWINFO);
1569 flashInfo.hwnd = window.windowHandle;
1570 flashInfo.uCount = 1;
1571 flashInfo.dwFlags = FLASHW_TRAY; // FLASHW_ALL;
1573 FlashWindowEx((void *)&flashInfo);
1577 // --- Mouse-based window movement ---
1578 void StartMoving(Window window, int x, int y, bool fromKeyBoard)
1580 if(!fullScreenMode && !window.systemParent)
1581 // Commented out for Chess game because AI thread takes over the moving of main window... Still required?
1582 //SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE);
1583 ; //SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
1586 SetWindowPos(window.windowHandle, HWND_TOPMOST, 0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
1587 mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
1588 SetWindowPos(window.windowHandle, HWND_NOTOPMOST, 0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
1592 void StopMoving(Window window)
1594 if(!fullScreenMode && !window.systemParent)
1595 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
1598 // -- Mouse manipulation ---
1600 void GetMousePosition(int *x, int *y)
1603 GetCursorPos(&point);
1608 void SetMousePosition(int x, int y)
1613 void SetMouseRange(Window window, Box box)
1615 ClipCursor((RECT *) box);
1618 void SetMouseCapture(Window window)
1621 SetCapture(window.windowHandle);
1626 // -- Mouse cursor ---
1628 void SetMouseCursor(SystemCursor cursor)
1630 if(lastCursor != cursor)
1632 lastCursor = cursor;
1633 SetCursor((cursor == (SystemCursor)-1) ? null : systemCursors[cursor]);
1639 void SetCaret(int x, int y, int size)
1644 // --- Clipboard manipulation ---
1646 void ClearClipboard()
1648 if(OpenClipboard(null))
1655 bool AllocateClipboard(ClipBoard clipBoard, uint size)
1657 bool result = false;
1658 clipBoard.text = new byte[size];
1663 bool SaveClipboard(ClipBoard clipBoard)
1665 bool result = false;
1669 uint16 * u16text = UTF8toUTF16(clipBoard.text, &wordCount);
1671 clipBoard.handle = GlobalAlloc(GHND | GMEM_DDESHARE, wordCount * 2);
1672 if(clipBoard.handle)
1674 uint16 * text = GlobalLock(clipBoard.handle);
1677 memcpy(text, u16text, wordCount * 2);
1678 GlobalUnlock(clipBoard.handle);
1679 if(OpenClipboard(null))
1682 if(SetClipboardData(CF_UNICODETEXT, clipBoard.handle))
1690 GlobalFree(clipBoard.handle);
1697 bool LoadClipboard(ClipBoard clipBoard)
1699 bool result = false;
1700 if(OpenClipboard(null))
1702 if((clipBoard.handle = GetClipboardData(CF_UNICODETEXT)))
1704 uint16 * u16text = GlobalLock(clipBoard.handle);
1707 clipBoard.text = UTF16toUTF8(u16text);
1709 GlobalUnlock(clipBoard.handle);
1717 void UnloadClipboard(ClipBoard clipBoard)
1719 delete clipBoard.text;
1722 // --- State based input ---
1724 bool AcquireInput(Window window, bool state)
1726 #ifndef ECERE_NODINPUT
1727 if(dInput || InitDirectInput())
1729 AcquireDirectInput(window.windowHandle, state);
1736 bool GetMouseState(MouseButtons * buttons, int * x, int * y)
1738 bool result = false;
1739 #ifndef ECERE_NODINPUT
1740 DIMOUSESTATE dims = {0};
1742 if(acquiredWindow && directMouse)
1744 if(directMouse->lpVtbl->GetDeviceState(directMouse, sizeof(DIMOUSESTATE), &dims ))
1746 FillBytes(&dims, 0, sizeof(dims));
1747 directMouse->lpVtbl->Acquire(directMouse);
1751 /* We don't really want this...
1754 if(GetAsyncKeyState(VK_LBUTTON))
1755 dims.rgbButtons[0] |= 0x80;
1756 if(GetAsyncKeyState(VK_RBUTTON))
1757 dims.rgbButtons[1] |= 0x80;
1758 if(GetAsyncKeyState(VK_MBUTTON))
1759 dims.rgbButtons[2] |= 0x80;
1767 *buttons = MouseButtons {
1768 left = (dims.rgbButtons[0] & 0x80) ? true : false,
1769 right = (dims.rgbButtons[1] & 0x80) ? true : false,
1770 middle = (dims.rgbButtons[2] & 0x80) ? true : false };
1777 bool GetJoystickState(int device, Joystick joystick)
1779 bool result = false;
1780 #ifndef ECERE_NODINPUT
1781 if(joystick != null)
1783 DIJOYSTATE dijs = {0};
1784 #ifndef ECERE_NOJOYSTICK
1785 if(acquiredWindow && device < numJoysticks)
1787 if(directJoysticks[device])
1789 directJoysticks[device]->lpVtbl->Poll(directJoysticks[device]);
1790 if(directJoysticks[device]->lpVtbl->GetDeviceState(directJoysticks[device], sizeof(DIJOYSTATE), &dijs ))
1791 directJoysticks[device]->lpVtbl->Acquire(directJoysticks[device]);
1796 joystick.x = dijs.lX;
1797 joystick.y = dijs.lY;
1798 joystick.z = dijs.lZ;
1799 joystick.rx = dijs.lRx;
1800 joystick.ry = dijs.lRy;
1801 joystick.rz = dijs.lRz;
1803 ((dijs.rgbButtons[0] & 0x80) ? JOY_BUTTON1 : 0)
1804 | ((dijs.rgbButtons[1] & 0x80) ? JOY_BUTTON2 : 0)
1805 | ((dijs.rgbButtons[2] & 0x80) ? JOY_BUTTON3 : 0)
1806 | ((dijs.rgbButtons[3] & 0x80) ? JOY_BUTTON4 : 0);
1812 bool GetKeyState(Key key)
1814 bool keyState = false;
1818 keyState = GetAsyncKeyState(key2VK[key]);
1819 keyState = (keyState & 0x80000) ? true : false;
1821 else if(key == capsState)
1822 keyState = ::GetKeyState(VK_CAPITAL) & 0x00000001;
1823 else if(key == numState)
1824 keyState = ::GetKeyState(VK_NUMLOCK) & 0x00000001;
1825 else if(key == scrollState)
1826 keyState = ::GetKeyState(VK_SCROLL) & 0x00000001;
1830 bool SetIcon(Window window, BitmapResource resource)
1833 HICON oldIcon = (HICON)SendMessage(window.windowHandle, WM_GETICON, ICON_BIG, 0);
1835 // Dialogs Inherit master's icon if none set
1836 if(!window.style.showInTaskBar && window.hasClose)
1838 Window master = window.master;
1839 while(master && !resource)
1841 Window rootWindow = (master && master != guiApp.desktop) ? master.rootWindow : null;
1842 if(rootWindow && rootWindow.icon)
1843 resource = rootWindow.icon;
1845 master = master.master;
1849 // WARNING -- putting this here as it is right after CreateRootWindow
1850 // Take out Layered flag if we're not in 24 bit
1852 if(window.alphaBlend && window.display.pixelFormat != pixelFormat888)
1854 #ifndef ECERE_NOBLENDING
1855 DWORD style = GetWindowLong(window.windowHandle, GWL_EXSTYLE);
1856 style &= ~WS_EX_LAYERED;
1857 SetWindowLong(window.windowHandle, GWL_EXSTYLE, style);
1863 if(oldIcon && oldIcon != (HICON)GetClassLongPtr(window.windowHandle, GCLP_HICON))
1865 if(oldIcon && oldIcon != (HICON)GetClassLong(window.windowHandle, GCL_HICON))
1868 DestroyIcon(oldIcon);
1874 if(bitmap.Load(resource.fileName, null, null))
1877 PixelFormat format = window.display.pixelFormat;
1878 int bits = GetDepthBits(format);
1881 bitmap.Convert(null, pixelFormat888, null);
1882 and.Allocate(null, (bitmap.width+7/8), bitmap.height, 0, pixelFormat8, false);
1884 blend = bits == 32 || bitmap.pixelFormat != pixelFormat888;
1887 byte * picture = and.picture;
1890 uint size = bitmap.height * bitmap.width;
1895 while(m < 8 && c < size)
1898 mask |= blend ? (!((ColorAlpha *)bitmap.picture)[c].a) : (((ColorAlpha *)bitmap.picture)[c].a <= 192);
1902 picture[b++] = mask;
1907 ColorAlpha color = ((ColorAlpha *)bitmap.picture)[c];
1908 if(blend ? (!color.a) : (color.a <= 192))
1910 color.color = { 0, 0, 0 };
1911 ((ColorAlpha *)bitmap.picture)[c] = color;
1916 if(bits == 15) { bits = 16; format = pixelFormat565; };
1917 bitmap.Convert(null, format, null);
1919 icon = CreateIcon(hInstance, bitmap.width, bitmap.height, 1, (byte)bits, and.picture, bitmap.picture);
1924 SendMessage(window.windowHandle, WM_SETICON, ICON_BIG, (LPARAM)icon);
1925 SendMessage(window.windowHandle, WM_SETICON, ICON_SMALL, (LPARAM)icon);
1929 void ::GetScreenArea(Window window, Box box)
1931 HMONITOR monitor = MonitorFromWindow(window.windowHandle, MONITOR_DEFAULTTONEAREST);
1932 HMONITOR taskBarMonitor = MonitorFromWindow(startBar, MONITOR_DEFAULTTONEAREST);
1935 MONITORINFO info = { 0 };
1936 info.cbSize = sizeof(MONITORINFO);
1937 GetMonitorInfo(monitor, &info);
1938 // box = { info.rcWork.left, info.rcWork.top, info.rcWork.right, info.rcWork.bottom };
1939 box = { info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right-1, info.rcMonitor.bottom-1 };
1941 if(taskBarMonitor == monitor)
1943 if(taskBarPlacement.rcNormalPosition.top <= box.top && taskBarPlacement.rcNormalPosition.bottom >= box.bottom)
1945 if(taskBarPlacement.rcNormalPosition.left <= box.left)
1947 if(taskBarState & ABS_AUTOHIDE)
1950 box.left = taskBarPlacement.rcNormalPosition.right;
1952 else if(taskBarState & ABS_AUTOHIDE)
1955 box.right = taskBarPlacement.rcNormalPosition.left;
1957 else if(taskBarPlacement.rcNormalPosition.left <= box.left && taskBarPlacement.rcNormalPosition.right >= box.right)
1959 if(taskBarPlacement.rcNormalPosition.top <= box.top)
1961 if(taskBarState & ABS_AUTOHIDE)
1964 box.top = taskBarPlacement.rcNormalPosition.bottom;
1966 else if(taskBarState & ABS_AUTOHIDE)
1969 box.bottom = taskBarPlacement.rcNormalPosition.top;
1973 box.left -= desktopX;
1974 box.top -= desktopY;
1975 box.right -= desktopX;
1976 box.bottom -= desktopY;