2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
9 #define WIN32_LEAN_AND_MEAN
11 #undef WIN32_LEAN_AND_MEAN
16 #include "Ecore_WinCE.h"
17 #include "ecore_wince_private.h"
20 /***** Private declarations *****/
22 typedef BOOL (__stdcall *UnregisterFunc1Proc)(UINT, UINT);
24 static int _ecore_wince_hardware_keys_register(HWND window);
30 ecore_wince_window_new(Ecore_WinCE_Window *parent,
36 struct _Ecore_WinCE_Window *w;
40 INF("creating window");
42 w = (struct _Ecore_WinCE_Window *)calloc(1, sizeof(struct _Ecore_WinCE_Window));
45 ERR("malloc() failed");
53 if (!AdjustWindowRectEx(&rect, WS_CAPTION | WS_SYSMENU | WS_VISIBLE, FALSE, WS_EX_TOPMOST))
55 ERR("AdjustWindowRectEx() failed");
60 window = CreateWindowEx(WS_EX_TOPMOST,
61 ECORE_WINCE_WINDOW_CLASS,
63 WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
65 rect.right - rect.left, rect.bottom - rect.top,
66 parent ? ((struct _Ecore_WinCE_Window *)parent)->window : NULL,
67 NULL, _ecore_wince_instance, NULL);
70 ERR("CreateWindowEx() failed");
75 if (!_ecore_wince_hardware_keys_register(window))
77 ERR("_ecore_wince_hardware_keys_register() failed");
78 DestroyWindow(window);
86 if (!SetWindowLong(window, GWL_USERDATA, (LONG)w) && (GetLastError() != 0))
88 ERR("SetWindowLong() failed");
89 DestroyWindow(window);
100 ecore_wince_window_free(Ecore_WinCE_Window *window)
104 INF("destroying window");
106 DestroyWindow(((struct _Ecore_WinCE_Window *)window)->window);
111 ecore_wince_window_hwnd_get(Ecore_WinCE_Window *window)
116 return ((struct _Ecore_WinCE_Window *)window)->window;
120 ecore_wince_window_move(Ecore_WinCE_Window *window,
127 if (!window || ((struct _Ecore_WinCE_Window *)window)->fullscreen)
130 INF("moving window (%dx%d)", x, y);
132 w = ((struct _Ecore_WinCE_Window *)window)->window;
133 if (!GetWindowRect(w, &rect))
135 ERR("GetWindowRect() failed");
139 if (!MoveWindow(w, x, y,
140 rect.right - rect.left,
141 rect.bottom - rect.top,
144 ERR("MoveWindow() failed");
149 ecore_wince_window_resize(Ecore_WinCE_Window *window,
154 struct _Ecore_WinCE_Window *w;
160 if (!window || ((struct _Ecore_WinCE_Window *)window)->fullscreen)
163 INF("resizing window (%dx%d)", width, height);
165 w = (struct _Ecore_WinCE_Window *)window;
166 if (!GetWindowRect(w->window, &rect))
168 ERR("GetWindowRect() failed");
177 rect.bottom = height;
178 if (!(style = GetWindowLong(w->window, GWL_STYLE)))
180 ERR("GetWindowLong() failed");
183 if (!(exstyle = GetWindowLong(w->window, GWL_EXSTYLE)))
185 ERR("GetWindowLong() failed");
188 if (!AdjustWindowRectEx(&rect, style, FALSE, exstyle))
190 ERR("AdjustWindowRectEx() failed");
194 if (!MoveWindow(w->window, x, y,
195 rect.right - rect.left,
196 rect.bottom - rect.top,
199 ERR("MoveWindow() failed");
204 ecore_wince_window_move_resize(Ecore_WinCE_Window *window,
211 struct _Ecore_WinCE_Window *w;
215 if (!window || ((struct _Ecore_WinCE_Window *)window)->fullscreen)
218 INF("moving and resizing window (%dx%d %dx%d)", x, y, width, height);
220 w = ((struct _Ecore_WinCE_Window *)window);
224 rect.bottom = height;
225 if (!(style = GetWindowLong(w->window, GWL_STYLE)))
227 ERR("GetWindowLong() failed");
230 if (!(exstyle = GetWindowLong(w->window, GWL_EXSTYLE)))
232 ERR("GetWindowLong() failed");
235 if (!AdjustWindowRectEx(&rect, style, FALSE, exstyle))
237 ERR("AdjustWindowRectEx() failed");
241 if (!MoveWindow(w->window, x, y,
242 rect.right - rect.left,
243 rect.bottom - rect.top,
246 ERR("MoveWindow() failed");
251 ecore_wince_window_show(Ecore_WinCE_Window *window)
255 INF("showing window");
257 if (!ShowWindow(((struct _Ecore_WinCE_Window *)window)->window, SW_SHOWNORMAL))
259 ERR("ShowWindow() failed");
262 if (!UpdateWindow(((struct _Ecore_WinCE_Window *)window)->window))
264 ERR("UpdateWindow() failed");
266 if (!SendMessage(((struct _Ecore_WinCE_Window *)window)->window, WM_SHOWWINDOW, 1, 0))
268 ERR("SendMessage() failed");
273 ecore_wince_window_hide(Ecore_WinCE_Window *window)
277 INF("hiding window");
279 if (!ShowWindow(((struct _Ecore_WinCE_Window *)window)->window, SW_HIDE))
281 ERR("ShowWindow() failed");
284 if (!SendMessage(((struct _Ecore_WinCE_Window *)window)->window, WM_SHOWWINDOW, 0, 0))
286 ERR("SendMessage() failed");
291 ecore_wince_window_title_set(Ecore_WinCE_Window *window,
298 if (!title || !title[0]) return;
300 INF("setting window title");
302 wtitle = evil_char_to_wchar(title);
305 if (!SetWindowText(((struct _Ecore_WinCE_Window *)window)->window, wtitle))
307 ERR("SetWindowText() failed");
313 ecore_wince_window_backend_set(Ecore_WinCE_Window *window, int backend)
315 struct _Ecore_WinCE_Window *w;
320 INF("setting backend");
322 w = (struct _Ecore_WinCE_Window *)window;
323 w->backend = backend;
327 ecore_wince_window_suspend_set(Ecore_WinCE_Window *window, int (*suspend)(int))
329 struct _Ecore_WinCE_Window *w;
334 INF("setting suspend callback");
336 w = (struct _Ecore_WinCE_Window *)window;
337 w->suspend = suspend;
341 ecore_wince_window_resume_set(Ecore_WinCE_Window *window, int (*resume)(int))
343 struct _Ecore_WinCE_Window *w;
348 INF("setting resume callback");
350 w = (struct _Ecore_WinCE_Window *)window;
355 ecore_wince_window_geometry_get(Ecore_WinCE_Window *window,
365 INF("getting window geometry");
371 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
372 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
377 if (!GetClientRect(((struct _Ecore_WinCE_Window *)window)->window,
380 ERR("GetClientRect() failed");
384 if (width) *width = 0;
385 if (height) *height = 0;
390 w = rect.right - rect.left;
391 h = rect.bottom - rect.top;
393 if (!GetWindowRect(((struct _Ecore_WinCE_Window *)window)->window,
396 ERR("GetWindowRect() failed");
400 if (width) *width = 0;
401 if (height) *height = 0;
406 if (x) *x = rect.left;
407 if (y) *y = rect.top;
408 if (width) *width = w;
409 if (height) *height = h;
413 ecore_wince_window_size_get(Ecore_WinCE_Window *window,
419 INF("getting window size");
423 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
424 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
429 if (!GetClientRect(((struct _Ecore_WinCE_Window *)window)->window,
432 ERR("GetClientRect() failed");
434 if (width) *width = 0;
435 if (height) *height = 0;
438 if (width) *width = rect.right - rect.left;
439 if (height) *height = rect.bottom - rect.top;
443 ecore_wince_window_fullscreen_set(Ecore_WinCE_Window *window,
446 struct _Ecore_WinCE_Window *ew;
452 ew = (struct _Ecore_WinCE_Window *)window;
453 if (((ew->fullscreen) && (on)) ||
454 ((!ew->fullscreen) && (!on)))
457 INF("setting fullscreen: %s", on ? "yes" : "no");
459 ew->fullscreen = !!on;
464 /* save the position and size of the window */
465 if (!GetWindowRect(w, &ew->rect))
467 ERR("GetWindowRect() failed");
472 task_bar = FindWindow(L"HHTaskBar", NULL);
475 INF("FindWindow(): can not find task bar");
477 if (!ShowWindow(task_bar, SW_HIDE))
479 INF("ShowWindow(): task bar already hidden");
481 if (!EnableWindow(task_bar, FALSE))
483 INF("EnableWindow(): input already disabled");
486 /* style: visible + popup */
487 if (!SetWindowLong(w, GWL_STYLE, WS_POPUP | WS_VISIBLE))
489 INF("SetWindowLong() failed");
492 /* resize window to fit the entire screen */
493 if (!SetWindowPos(w, HWND_TOPMOST,
495 GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
496 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED))
498 INF("SetWindowPos() failed");
501 * It seems that SetWindowPos is not sufficient.
502 * Call MoveWindow with the correct size and force painting.
503 * Note that UpdateWindow (forcing repainting) is not sufficient
507 GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
510 INF("MoveWindow() failed");
516 task_bar = FindWindow(L"HHTaskBar", NULL);
519 INF("FindWindow(): can not find task bar");
521 if (!ShowWindow(task_bar, SW_SHOW))
523 INF("ShowWindow(): task bar already visible");
525 if (!EnableWindow(task_bar, TRUE))
527 INF("EnableWindow(): input already enabled");
530 /* style: visible + caption + sysmenu */
531 if (!SetWindowLong(w, GWL_STYLE, WS_CAPTION | WS_SYSMENU | WS_VISIBLE))
533 INF("SetWindowLong() failed");
535 /* restaure the position and size of the window */
536 if (!SetWindowPos(w, HWND_TOPMOST,
539 ew->rect.right - ew->rect.left,
540 ew->rect.bottom - ew->rect.top,
541 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED))
543 INF("SetWindowLong() failed");
546 * It seems that SetWindowPos is not sufficient.
547 * Call MoveWindow with the correct size and force painting.
548 * Note that UpdateWindow (forcing repainting) is not sufficient
553 ew->rect.right - ew->rect.left,
554 ew->rect.bottom - ew->rect.top,
557 INF("MoveWindow() failed");
563 /***** Private functions definitions *****/
566 _ecore_wince_hardware_keys_register(HWND window)
569 UnregisterFunc1Proc unregister_fct;
572 core_dll = LoadLibrary(L"coredll.dll");
575 ERR("LoadLibrary() failed");
579 unregister_fct = (UnregisterFunc1Proc)GetProcAddress(core_dll, L"UnregisterFunc1");
582 ERR("GetProcAddress() failed");
583 FreeLibrary(core_dll);
587 for (i = 0xc1; i <= 0xcf; i++)
589 unregister_fct(MOD_WIN, i);
590 RegisterHotKey(window, i, MOD_WIN, i);
593 FreeLibrary(core_dll);