aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_wince/ecore_wince_window.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/lib/ecore_wince/ecore_wince_window.c')
-rw-r--r--libraries/ecore/src/lib/ecore_wince/ecore_wince_window.c775
1 files changed, 775 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_wince/ecore_wince_window.c b/libraries/ecore/src/lib/ecore_wince/ecore_wince_window.c
new file mode 100644
index 0000000..4e8b7b1
--- /dev/null
+++ b/libraries/ecore/src/lib/ecore_wince/ecore_wince_window.c
@@ -0,0 +1,775 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#define WIN32_LEAN_AND_MEAN
6#include <windows.h>
7#undef WIN32_LEAN_AND_MEAN
8
9#include <Evil.h>
10#include <Eina.h>
11
12#include "Ecore_WinCE.h"
13#include "ecore_wince_private.h"
14
15/*============================================================================*
16 * Local *
17 *============================================================================*/
18
19/**
20 * @cond LOCAL
21 */
22
23
24typedef BOOL (__stdcall *UnregisterFunc1Proc)(UINT, UINT);
25
26static int
27_ecore_wince_hardware_keys_register(HWND window)
28{
29 HINSTANCE core_dll;
30 UnregisterFunc1Proc unregister_fct;
31 int i;
32
33 core_dll = LoadLibrary(L"coredll.dll");
34 if (!core_dll)
35 {
36 ERR("LoadLibrary() failed");
37 return 0;
38 }
39
40 unregister_fct = (UnregisterFunc1Proc)GetProcAddress(core_dll, L"UnregisterFunc1");
41 if (!unregister_fct)
42 {
43 ERR("GetProcAddress() failed");
44 FreeLibrary(core_dll);
45 return 0;
46 }
47
48 for (i = 0xc1; i <= 0xcf; i++)
49 {
50 unregister_fct(MOD_WIN, i);
51 RegisterHotKey(window, i, MOD_WIN, i);
52 }
53
54 FreeLibrary(core_dll);
55
56 return 1;
57}
58
59/**
60 * @endcond
61 */
62
63
64/*============================================================================*
65 * Global *
66 *============================================================================*/
67
68/*============================================================================*
69 * API *
70 *============================================================================*/
71
72/**
73 * @addtogroup Ecore_WinCE_Group Ecore_WinCE library
74 *
75 * @{
76 */
77
78/**
79 * @brief Creates a new window.
80 *
81 * @param parent The parent window.
82 * @param x The x coordinate of the top-left corner of the window.
83 * @param y The y coordinate of the top-left corner of the window.
84 * @param width The width of the window.
85 * @param height The height of hte window.
86 * @return A newly allocated window.
87 *
88 * This function creates a new window which parent is @p parent. @p width and
89 * @p height are the size of the window content (the client part),
90 * without the border and title bar. @p x and @p y are the system
91 * coordinates of the top left cerner of the window (that is, of the
92 * title bar). This function returns a newly created window on
93 * success, and @c NULL on failure.
94 */
95EAPI Ecore_WinCE_Window *
96ecore_wince_window_new(Ecore_WinCE_Window *parent,
97 int x,
98 int y,
99 int width,
100 int height)
101{
102 Ecore_WinCE_Window *w;
103 HWND window;
104 RECT rect;
105
106 INF("creating window");
107
108 w = (Ecore_WinCE_Window *)calloc(1, sizeof(Ecore_WinCE_Window));
109 if (!w)
110 {
111 ERR("malloc() failed");
112 return NULL;
113 }
114
115 rect.left = 0;
116 rect.top = 0;
117 rect.right = width;
118 rect.bottom = height;
119 if (!AdjustWindowRectEx(&rect, WS_CAPTION | WS_SYSMENU | WS_VISIBLE, FALSE, WS_EX_TOPMOST))
120 {
121 ERR("AdjustWindowRectEx() failed");
122 free(w);
123 return NULL;
124 }
125
126 window = CreateWindowEx(WS_EX_TOPMOST,
127 ECORE_WINCE_WINDOW_CLASS,
128 L"",
129 WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
130 x, y,
131 rect.right - rect.left, rect.bottom - rect.top,
132 parent ? ((Ecore_WinCE_Window *)parent)->window : NULL,
133 NULL, _ecore_wince_instance, NULL);
134 if (!window)
135 {
136 ERR("CreateWindowEx() failed");
137 free(w);
138 return NULL;
139 }
140
141 if (!_ecore_wince_hardware_keys_register(window))
142 {
143 ERR("_ecore_wince_hardware_keys_register() failed");
144 DestroyWindow(window);
145 free(w);
146 return NULL;
147 }
148
149 w->window = window;
150
151 SetLastError(0);
152 if (!SetWindowLong(window, GWL_USERDATA, (LONG)w) && (GetLastError() != 0))
153 {
154 ERR("SetWindowLong() failed");
155 DestroyWindow(window);
156 free(w);
157 return NULL;
158 }
159
160 w->pointer_is_in = 0;
161
162 return w;
163}
164
165/**
166 * @brief Free the given window.
167 *
168 * @param window The window to free.
169 *
170 * This function frees @p window. If @p window is @c NULL, this
171 * function does nothing.
172 */
173EAPI void
174ecore_wince_window_free(Ecore_WinCE_Window *window)
175{
176 if (!window) return;
177
178 INF("destroying window");
179
180 DestroyWindow(window->window);
181 free(window);
182}
183
184/**
185 * @brief Return the window HANDLE associated to the given window.
186 *
187 * @param window The window to retrieve the HANDLE from.
188 *
189 * This function returns the window HANDLE associated to @p window. If
190 * @p window is @c NULL, this function returns @c NULL.
191 */
192EAPI void *
193ecore_wince_window_hwnd_get(Ecore_WinCE_Window *window)
194{
195 if (!window)
196 return NULL;
197
198 return window->window;
199}
200
201/**
202 * @brief Move the given window to a given position.
203 *
204 * @param window The window to move.
205 * @param x The x coordinate of the destination position.
206 * @param y The y coordinate of the destination position.
207 *
208 * This function move @p window to the new position of coordinates @p x
209 * and @p y. If @p window is @c NULL, or if it is fullscreen, or on
210 * error, this function does nothing.
211 */
212EAPI void
213ecore_wince_window_move(Ecore_WinCE_Window *window,
214 int x,
215 int y)
216{
217 RECT rect;
218
219 if (!window || window->fullscreen)
220 return;
221
222 INF("moving window (%dx%d)", x, y);
223
224 if (!GetWindowRect(window->window, &rect))
225 {
226 ERR("GetWindowRect() failed");
227 return;
228 }
229
230 if (!MoveWindow(window->window, x, y,
231 rect.right - rect.left,
232 rect.bottom - rect.top,
233 TRUE))
234 {
235 ERR("MoveWindow() failed");
236 }
237}
238
239/**
240 * @brief Resize the given window to a given size.
241 *
242 * @param window The window to resize.
243 * @param width The new width.
244 * @param height The new height.
245 *
246 * This function resize @p window to the new @p width and @p height.
247 * If @p window is @c NULL, or if it is fullscreen, or on error, this
248 * function does nothing.
249 */
250EAPI void
251ecore_wince_window_resize(Ecore_WinCE_Window *window,
252 int width,
253 int height)
254{
255 RECT rect;
256 DWORD style;
257 DWORD exstyle;
258 int x;
259 int y;
260
261 if (!window || window->fullscreen)
262 return;
263
264 INF("resizing window (%dx%d)", width, height);
265
266 if (!GetWindowRect(window->window, &rect))
267 {
268 ERR("GetWindowRect() failed");
269 return;
270 }
271
272 x = rect.left;
273 y = rect.top;
274 rect.left = 0;
275 rect.top = 0;
276 rect.right = width;
277 rect.bottom = height;
278 if (!(style = GetWindowLong(window->window, GWL_STYLE)))
279 {
280 ERR("GetWindowLong() failed");
281 return;
282 }
283 if (!(exstyle = GetWindowLong(window->window, GWL_EXSTYLE)))
284 {
285 ERR("GetWindowLong() failed");
286 return;
287 }
288 if (!AdjustWindowRectEx(&rect, style, FALSE, exstyle))
289 {
290 ERR("AdjustWindowRectEx() failed");
291 return;
292 }
293
294 if (!MoveWindow(window->window, x, y,
295 rect.right - rect.left,
296 rect.bottom - rect.top,
297 FALSE))
298 {
299 ERR("MoveWindow() failed");
300 }
301}
302
303/**
304 * @brief Move and resize the given window to a given position and size.
305 *
306 * @param window The window to move and resize.
307 * @param x The x coordinate of the destination position.
308 * @param y The x coordinate of the destination position.
309 * @param width The new width.
310 * @param height The new height.
311 *
312 * This function resize @p window to the new position of coordinates @p x
313 * and @p y and the new @p width and @p height. If @p window is @c NULL,
314 * or if it is fullscreen, or on error, this function does nothing.
315 */
316EAPI void
317ecore_wince_window_move_resize(Ecore_WinCE_Window *window,
318 int x,
319 int y,
320 int width,
321 int height)
322{
323 RECT rect;
324 DWORD style;
325 DWORD exstyle;
326
327 if (!window || window->fullscreen)
328 return;
329
330 INF("moving and resizing window (%dx%d %dx%d)", x, y, width, height);
331
332 rect.left = 0;
333 rect.top = 0;
334 rect.right = width;
335 rect.bottom = height;
336 if (!(style = GetWindowLong(window->window, GWL_STYLE)))
337 {
338 ERR("GetWindowLong() failed");
339 return;
340 }
341 if (!(exstyle = GetWindowLong(window->window, GWL_EXSTYLE)))
342 {
343 ERR("GetWindowLong() failed");
344 return;
345 }
346 if (!AdjustWindowRectEx(&rect, style, FALSE, exstyle))
347 {
348 ERR("AdjustWindowRectEx() failed");
349 return;
350 }
351
352 if (!MoveWindow(window->window, x, y,
353 rect.right - rect.left,
354 rect.bottom - rect.top,
355 TRUE))
356 {
357 ERR("MoveWindow() failed");
358 }
359}
360
361/**
362 * @brief Show the given window.
363 *
364 * @param window The window to show.
365 *
366 * This function shows @p window. If @p window is @c NULL, or on
367 * error, this function does nothing.
368 */
369EAPI void
370ecore_wince_window_show(Ecore_WinCE_Window *window)
371{
372 if (!window) return;
373
374 INF("showing window");
375
376 if (!ShowWindow(window->window, SW_SHOWNORMAL))
377 {
378 ERR("ShowWindow() failed");
379 return;
380 }
381 if (!UpdateWindow(window->window))
382 {
383 ERR("UpdateWindow() failed");
384 }
385 if (!SendMessage(window->window, WM_SHOWWINDOW, 1, 0))
386 {
387 ERR("SendMessage() failed");
388 }
389}
390
391/**
392 * @brief Hide the given window.
393 *
394 * @param window The window to show.
395 *
396 * This function hides @p window. If @p window is @c NULL, or on
397 * error, this function does nothing.
398 */
399EAPI void
400ecore_wince_window_hide(Ecore_WinCE_Window *window)
401{
402 if (!window) return;
403
404 INF("hiding window");
405
406 if (!ShowWindow(window->window, SW_HIDE))
407 {
408 ERR("ShowWindow() failed");
409 return;
410 }
411 if (!SendMessage(window->window, WM_SHOWWINDOW, 0, 0))
412 {
413 ERR("SendMessage() failed");
414 }
415}
416
417/**
418 * @brief Set the title of the given window.
419 *
420 * @param window The window to set the title.
421 * @param title The new title.
422 *
423 * This function sets the title of @p window to @p title. If @p window
424 * is @c NULL, or if @p title is @c NULL or empty, or on error, this
425 * function does nothing.
426 */
427EAPI void
428ecore_wince_window_title_set(Ecore_WinCE_Window *window,
429 const char *title)
430{
431 wchar_t *wtitle;
432
433 if (!window) return;
434
435 if (!title || !title[0]) return;
436
437 INF("setting window title");
438
439 wtitle = evil_char_to_wchar(title);
440 if (!wtitle) return;
441
442 if (!SetWindowText(window->window, wtitle))
443 {
444 ERR("SetWindowText() failed");
445 }
446 free(wtitle);
447}
448
449/**
450 * @brief Set the graphic backend used for the given window.
451 *
452 * @param window The window.
453 * @param backend The backend.
454 *
455 * This function sets the graphic backend to use with @p window to
456 * @p backend. If @p window if @c NULL, this function does nothing.
457 *
458 * The valid values for @p backend are
459 *
460 * @li 0: automatic choice of the backend.
461 * @li 1: the framebuffer (fast but could be not well suported).
462 * @li 2: GAPI (less fast but almost always supported).
463 * @li 3: DirectDraw (less fast than GAPI but almost always
464 * supported).
465 * @li 4: GDI (the slowest but always supported).
466 *
467 * The @p backend is used only in Evas and Ecore_Evas. So this
468 * function should not be called if Ecore_Evas is used.
469 */
470EAPI void
471ecore_wince_window_backend_set(Ecore_WinCE_Window *window,
472 int backend)
473{
474 if (!window)
475 return;
476
477 INF("setting backend");
478
479 window->backend = backend;
480}
481
482/**
483 * @brief Set the suspend callback used for the given window.
484 *
485 * @param window The window.
486 * @param suspend_cb The suspend callback.
487 *
488 * This function sets the suspend callback to use with @p window to
489 * @p suspend_cb. If @p window if @c NULL, this function does nothing.
490 *
491 * The @p suspend_cb is used only in Evas and Ecore_Evas. So this
492 * function should not be called if Ecore_Evas is used.
493 */
494EAPI void
495ecore_wince_window_suspend_cb_set(Ecore_WinCE_Window *window, int (*suspend_cb)(int))
496{
497 if (!window)
498 return;
499
500 INF("setting suspend callback");
501
502 window->suspend_cb = suspend_cb;
503}
504
505/**
506 * @brief Set the resume callback used for the given window.
507 *
508 * @param window The window.
509 * @param resume_cb The resume callback.
510 *
511 * This function sets the resume callback to use with @p window to
512 * @p resume_cb. If @p window if @c NULL, this function does nothing.
513 *
514 * The @p resume_cb is used only in Evas and Ecore_Evas. So this
515 * function should not be called if Ecore_Evas is used.
516 */
517EAPI void
518ecore_wince_window_resume_cb_set(Ecore_WinCE_Window *window, int (*resume_cb)(int))
519{
520 if (!window)
521 return;
522
523 INF("setting resume callback");
524
525 window->resume_cb = resume_cb;
526}
527
528/**
529 * @brief Get the geometry of the given window.
530 *
531 * @param window The window to retrieve the geometry from.
532 * @param x The x coordinate of the position.
533 * @param y The x coordinate of the position.
534 * @param width The width.
535 * @param height The height.
536 *
537 * This function retrieves the position and size of @p window. @p x,
538 * @p y, @p width and @p height can be buffers that will be filled with
539 * the corresponding values. If one of them is @c NULL, nothing will
540 * be done for that parameter. If @p window is @c NULL, and if the
541 * buffers are not @c NULL, they will be filled with respectively 0,
542 * 0, the size of the screen and the height of the screen.
543 */
544EAPI void
545ecore_wince_window_geometry_get(Ecore_WinCE_Window *window,
546 int *x,
547 int *y,
548 int *width,
549 int *height)
550{
551 RECT rect;
552 int w;
553 int h;
554
555 INF("getting window geometry");
556
557 if (!window)
558 {
559 if (x) *x = 0;
560 if (y) *y = 0;
561 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
562 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
563
564 return;
565 }
566
567 if (!GetClientRect(window->window, &rect))
568 {
569 ERR("GetClientRect() failed");
570
571 if (x) *x = 0;
572 if (y) *y = 0;
573 if (width) *width = 0;
574 if (height) *height = 0;
575
576 return;
577 }
578
579 w = rect.right - rect.left;
580 h = rect.bottom - rect.top;
581
582 if (!GetWindowRect(window->window, &rect))
583 {
584 ERR("GetWindowRect() failed");
585
586 if (x) *x = 0;
587 if (y) *y = 0;
588 if (width) *width = 0;
589 if (height) *height = 0;
590
591 return;
592 }
593
594 if (x) *x = rect.left;
595 if (y) *y = rect.top;
596 if (width) *width = w;
597 if (height) *height = h;
598}
599
600/**
601 * @brief Get the size of the given window.
602 *
603 * @param window The window to retrieve the size from.
604 * @param width The width.
605 * @param height The height.
606 *
607 * This function retrieves the size of @p window. @p width and
608 * @p height can be buffers that will be filled with the corresponding
609 * values. If one of them is @c NULL, nothing will be done for that
610 * parameter. If @p window is @c NULL, and if the buffers are not
611 * @c NULL, they will be filled with respectively the size of the screen
612 * and the height of the screen.
613 */
614EAPI void
615ecore_wince_window_size_get(Ecore_WinCE_Window *window,
616 int *width,
617 int *height)
618{
619 RECT rect;
620
621 INF("getting window size");
622
623 if (!window)
624 {
625 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
626 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
627
628 return;
629 }
630
631 if (!GetClientRect(window->window, &rect))
632 {
633 ERR("GetClientRect() failed");
634
635 if (width) *width = 0;
636 if (height) *height = 0;
637 }
638
639 if (width) *width = rect.right - rect.left;
640 if (height) *height = rect.bottom - rect.top;
641}
642
643/**
644 * @brief Set the given window to fullscreen.
645 *
646 * @param window The window.
647 * @param on EINA_TRUE for fullscreen mode, EINA_FALSE for windowed mode.
648 *
649 * This function set @p window to fullscreen or windowed mode. If @p on
650 * is set to EINA_TRUE, the window will be fullscreen, if it is set to
651 * EINA_FALSE, it will be windowed. If @p window is @c NULL or if the
652 * state does not change (like setting to fullscreen while the window
653 * is already fullscreen), this function does nothing.
654 */
655EAPI void
656ecore_wince_window_fullscreen_set(Ecore_WinCE_Window *window,
657 Eina_Bool on)
658{
659 HWND task_bar;
660
661 if (!window) return;
662
663 if (((window->fullscreen) && (on)) ||
664 ((!window->fullscreen) && (!on)))
665 return;
666
667 INF("setting fullscreen: %s", on ? "yes" : "no");
668
669 window->fullscreen = !!on;
670
671 if (on)
672 {
673 /* save the position and size of the window */
674 if (!GetWindowRect(window->window, &window->rect))
675 {
676 ERR("GetWindowRect() failed");
677 return;
678 }
679
680 /* hide task bar */
681 task_bar = FindWindow(L"HHTaskBar", NULL);
682 if (!task_bar)
683 {
684 INF("FindWindow(): can not find task bar");
685 }
686 if (!ShowWindow(task_bar, SW_HIDE))
687 {
688 INF("ShowWindow(): task bar already hidden");
689 }
690 if (!EnableWindow(task_bar, FALSE))
691 {
692 INF("EnableWindow(): input already disabled");
693 }
694
695 /* style: visible + popup */
696 if (!SetWindowLong(window->window, GWL_STYLE, WS_POPUP | WS_VISIBLE))
697 {
698 INF("SetWindowLong() failed");
699 }
700
701 /* resize window to fit the entire screen */
702 if (!SetWindowPos(window->window, HWND_TOPMOST,
703 0, 0,
704 GetSystemMetrics(SM_CXSCREEN),
705 GetSystemMetrics(SM_CYSCREEN),
706 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED))
707 {
708 INF("SetWindowPos() failed");
709 }
710 /*
711 * It seems that SetWindowPos is not sufficient.
712 * Call MoveWindow with the correct size and force painting.
713 * Note that UpdateWindow (forcing repainting) is not sufficient
714 */
715 if (!MoveWindow(window->window,
716 0, 0,
717 GetSystemMetrics(SM_CXSCREEN),
718 GetSystemMetrics(SM_CYSCREEN),
719 TRUE))
720 {
721 INF("MoveWindow() failed");
722 }
723 }
724 else
725 {
726 /* show task bar */
727 task_bar = FindWindow(L"HHTaskBar", NULL);
728 if (!task_bar)
729 {
730 INF("FindWindow(): can not find task bar");
731 }
732 if (!ShowWindow(task_bar, SW_SHOW))
733 {
734 INF("ShowWindow(): task bar already visible");
735 }
736 if (!EnableWindow(task_bar, TRUE))
737 {
738 INF("EnableWindow(): input already enabled");
739 }
740
741 /* style: visible + caption + sysmenu */
742 if (!SetWindowLong(window->window, GWL_STYLE, WS_CAPTION | WS_SYSMENU | WS_VISIBLE))
743 {
744 INF("SetWindowLong() failed");
745 }
746 /* restaure the position and size of the window */
747 if (!SetWindowPos(window->window, HWND_TOPMOST,
748 window->rect.left,
749 window->rect.top,
750 window->rect.right - window->rect.left,
751 window->rect.bottom - window->rect.top,
752 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED))
753 {
754 INF("SetWindowLong() failed");
755 }
756 /*
757 * It seems that SetWindowPos is not sufficient.
758 * Call MoveWindow with the correct size and force painting.
759 * Note that UpdateWindow (forcing repainting) is not sufficient
760 */
761 if (!MoveWindow(window->window,
762 window->rect.left,
763 window->rect.top,
764 window->rect.right - window->rect.left,
765 window->rect.bottom - window->rect.top,
766 TRUE))
767 {
768 INF("MoveWindow() failed");
769 }
770 }
771}
772
773/**
774 * @}
775 */