summaryrefslogtreecommitdiff
path: root/src/bin/engine_software_16_wince.c
blob: fd9d5d8b2838b957a1e83da6d237f4dfd758e377 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include "main.h"

#include <windows.h>
#include <aygshell.h>
#include <Evas_Engine_Software_16_WinCE.h>


static HINSTANCE instance = NULL;
static HWND window = NULL;
static int  backend = 0;

typedef int (*suspend) (int backend);
typedef int (*resume) (int backend);

static suspend _suspend = NULL;
static resume _resume = NULL;


typedef BOOL (__stdcall *UnregisterFunc1Proc)(UINT, UINT);

static int
_wince_hardware_keys_register(HWND window)
{
   HINSTANCE           core_dll;
   UnregisterFunc1Proc unregister_fct;
   int                 i;

   core_dll = LoadLibrary(L"coredll.dll");
   if (!core_dll)
     return 0;

   unregister_fct = (UnregisterFunc1Proc)GetProcAddress(core_dll, L"UnregisterFunc1");
   if (!unregister_fct)
     {
        FreeLibrary(core_dll);
        return 0;
     }

   for (i = 0xc1; i <= 0xcf; i++)
     {
        unregister_fct(MOD_WIN, i);
        RegisterHotKey(window, i, MOD_WIN, i);
     }

   FreeLibrary(core_dll);

   return 1;
}

static void
_wince_key_down(WPARAM wParam)
{
   int key;

   key = LOWORD(wParam);

   if ((key == VK_SHIFT) ||
       (key == VK_LSHIFT) ||
       (key == VK_RSHIFT))
     evas_key_modifier_on(evas, "Shift");

   if (key == VK_CAPITAL)
     {
        if (evas_key_lock_is_set(evas_key_lock_get(evas), "Caps_Lock"))
          evas_key_lock_off(evas, "Caps_Lock");
        else
          evas_key_lock_on(evas, "Caps_Lock");
     }
   if ((key == VK_RETURN) || (key == VK_APP1))
     evas_event_feed_key_down(evas, "Return", "Return", NULL, NULL, 0, NULL);
   if (key == VK_LEFT)
     evas_event_feed_key_down(evas, "Left", "Left", NULL, NULL, 0, NULL);
   if (key == VK_RIGHT)
     evas_event_feed_key_down(evas, "Right", "Right", NULL, NULL, 0, NULL);
   if ((key == 81) || (key == VK_APP2))
     evas_event_feed_key_down(evas, "Q", "Q", NULL, NULL, 0, NULL);
   if ((key == 113) || (key == VK_APP3))
     evas_event_feed_key_down(evas, "q", "q", NULL, NULL, 0, NULL);
}

static void
_wince_key_up(WPARAM wParam)
{
   int key;

   key = LOWORD(wParam);

   if ((key == VK_SHIFT) ||
       (key == VK_LSHIFT) ||
       (key == VK_RSHIFT))
     evas_key_modifier_off(evas, "Shift");
   if ((key == VK_RETURN) || (key == VK_APP1))
     evas_event_feed_key_up(evas, "Return", "Return", NULL, NULL, 0, NULL);
   if (key == VK_LEFT)
     evas_event_feed_key_up(evas, "Left", "Left", NULL, NULL, 0, NULL);
   if (key == VK_RIGHT)
     evas_event_feed_key_up(evas, "Right", "Right", NULL, NULL, 0, NULL);
   if ((key == 81) || (key == VK_APP2))
     evas_event_feed_key_up(evas, "Q", "Q", NULL, NULL, 0, NULL);
   if ((key == 113) || (key == VK_APP3))
     evas_event_feed_key_up(evas, "q", "q", NULL, NULL, 0, NULL);
}

static LRESULT CALLBACK
MainWndProc(HWND   hwnd,
            UINT   uMsg,
            WPARAM wParam,
            LPARAM lParam)
{
   switch (uMsg)
     {
     case WM_DESTROY:
       PostQuitMessage(0);
       return 0;
     case WM_CLOSE:
       PostQuitMessage(0);
       return 0;
     case WM_PAINT:
       ValidateRect(hwnd, NULL);
       return 0;
     case WM_HOTKEY:
       _wince_key_down(wParam);
       return 0;
     case WM_KEYDOWN:
       _wince_key_down(wParam);
       return 0;
     case WM_KEYUP:
       _wince_key_up(wParam);
       return 0;
     case WM_KILLFOCUS:
       if (_suspend)
         _suspend (backend);
       return 0;
     case WM_SETFOCUS:
       if (_resume)
         _resume (backend);
       return 0;
     case WM_SIZE:
       {
          Evas_Engine_Info_Software_16_WinCE *einfo;

          printf ("WM_SIZE %dx%d\n", LOWORD(lParam), HIWORD(lParam));
          einfo = (Evas_Engine_Info_Software_16_WinCE *)evas_engine_info_get(evas);
          if (!einfo)
            return 0;

          if (einfo->info.rotation != 0)
            {
               einfo->info.width = win_h;
               einfo->info.height = win_w;
               einfo->info.rotation = 90;
            }
          else
            {
               einfo->info.width = win_w;
               einfo->info.height = win_h;
               einfo->info.rotation = 0;
            }

          evas_engine_info_set(evas, (Evas_Engine_Info *)einfo);

          return 0;
       }
     default:
       return DefWindowProc(hwnd, uMsg, wParam, lParam);
     }
}

Eina_Bool
engine_software_16_wince_args(const char *engine, int width, int height)
{
   WNDCLASS                            wc;
   RECT                                rect;
   Evas_Engine_Info_Software_16_WinCE *einfo;
   HWND                                task_bar;
   HWND                                sip_window;
   HWND                                sip_icon;
   int                                 width;
   int                                 height;
   int                                 stride_x;
   int                                 stride_y;
   int                                 bpp;
   int                                 format;
   void                               *buffer;
   int                                 ok = 0;
   int                                 i;

   if (!strcmp(engine, "wince")) ok = 1;
   if (!strcmp(engine, "wince-fb")) { ok = 1; backend = 1; }
   if (!strcmp(engine, "wince-gapi")) { ok = 1; backend = 2; }
   if (!strcmp(engine, "wince-ddraw")) { ok = 1; backend = 3; }
   if (!strcmp(engine, "wince-gdi")) { ok = 1; backend = 4; }
   if (!ok) return EINA_FALSE;

   instance = GetModuleHandle(NULL);
   if (!instance) return EINA_FALSE;

   memset (&wc, 0, sizeof (wc));
   wc.style = CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc = MainWndProc;
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = instance;
   wc.hIcon = NULL;
   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
   wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
   wc.lpszMenuName =  NULL;
   wc.lpszClassName = L"Evas_Software_16_WinCE_Test";

   if(!RegisterClass(&wc))
     goto free_library;

   SetRect(&rect, 0, 0,
           GetSystemMetrics(SM_CXSCREEN),
           GetSystemMetrics(SM_CYSCREEN));

   window = CreateWindowEx(WS_EX_TOPMOST,
                           L"Evas_Software_16_WinCE_Test",
                           L"Evas_Software_16_WinCE_Test",
                           WS_VISIBLE | WS_POPUP,
                           rect.left, rect.top,
                           rect.right - rect.left,
                           rect.bottom - rect.top,
                           NULL, NULL, instance, NULL);
   if (!window)
     goto unregister_class;

   /* hide top level windows (Task bar, SIP and SIP button */
   task_bar = FindWindow(L"HHTaskBar", NULL);
   ShowWindow(task_bar, SW_HIDE);
   EnableWindow(task_bar, FALSE);
   sip_window = FindWindow(L"SipWndClass", NULL);
   ShowWindow(sip_window, SW_HIDE);
   EnableWindow(sip_window, FALSE);
   sip_icon = FindWindow(L"MS_SIPBUTTON", NULL);
   ShowWindow(sip_icon, SW_HIDE);
   EnableWindow(sip_icon, FALSE);

   if (!_wince_hardware_keys_register(window))
     goto destroy_window;

   evas_output_method_set(evas, evas_render_method_lookup("software_16_wince"));

   einfo = (Evas_Engine_Info_Software_16_WinCE *)evas_engine_info_get(evas);
   if (!einfo)
     {
        printf("Evas does not support the 16bit Software WinCE Engine\n");
        goto destroy_window;
     }

   einfo->info.window = window;
   einfo->info.width = width;
   einfo->info.height = height;
   einfo->info.backend = backend;
   einfo->info.rotation = 0;
   if (!evas_engine_info_set(evas, (Evas_Engine_Info *) einfo))
     {
	printf("Evas can not setup the informations of the 16 bits Software WinCE Engine\n");
        goto destroy_window;
     }

   _suspend = einfo->func.suspend;
   _resume = einfo->func.resume;

   /* the second parameter is ignored, as it's the first call of ShowWindow */
   ShowWindow(window, SW_SHOWDEFAULT);
   UpdateWindow(window);

   return EINA_TRUE;

 destroy_window:
   DestroyWindow(window);
   ShowWindow(task_bar, SW_SHOW);
   EnableWindow(task_bar, TRUE);
   ShowWindow(sip_window, SW_SHOW);
   EnableWindow(sip_window, TRUE);
   ShowWindow(sip_icon, SW_SHOW);
   EnableWindow(sip_icon, TRUE);
 unregister_class:
   UnregisterClass(L"Evas_Software_16_WinCE_Test", instance);
 free_library:
   FreeLibrary(instance);

   return EINA_FALSE;
}

void
engine_software_16_wince_loop(void)
{
   MSG msg;
   int res;

 again:
   if (!PeekMessage (&msg, window, 0, 0, PM_NOREMOVE))
     return;

   res = GetMessage (&msg, NULL, 0, 0);
   TranslateMessage (&msg);
   DispatchMessage (&msg);

   goto again;
}

void
engine_software_16_wince_shutdown(void)
{
   HWND task_bar;
   HWND sip_window;
   HWND sip_icon;

   DestroyWindow(window);

   /* show top level windows (Task bar, SIP and SIP button */
   task_bar = FindWindow(L"HHTaskBar", NULL);
   ShowWindow(task_bar, SW_SHOW);
   EnableWindow(task_bar, TRUE);
   sip_window = FindWindow(L"SipWndClass", NULL);
   ShowWindow(sip_window, SW_SHOW);
   EnableWindow(sip_window, TRUE);
   sip_icon = FindWindow(L"MS_SIPBUTTON", NULL);
   ShowWindow(sip_icon, SW_SHOW);
   EnableWindow(sip_icon, TRUE);

   UnregisterClass(L"Evas_Software_16_WinCE_Test", instance);
   FreeLibrary(instance);
}