aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_wince/ecore_wince.c
blob: 5638ad3a60256cbe2b18f638e1349b51533db33b (plain)
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>   /* for printf */

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN

#include <Eina.h>
#include <Ecore.h>
#include <Ecore_Input.h>

#include "Ecore_WinCE.h"
#include "ecore_wince_private.h"

/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/

/**
 * @cond LOCAL
 */

static int       _ecore_wince_init_count = 0;

LRESULT CALLBACK
_ecore_wince_window_procedure(HWND   window,
                              UINT   message,
                              WPARAM window_param,
                              LPARAM data_param)
{
   Ecore_WinCE_Callback_Data *data;
   POINTS                     pt;
   DWORD                      coord;

   data = (Ecore_WinCE_Callback_Data *)malloc(sizeof(Ecore_WinCE_Callback_Data));
   if (!data) return DefWindowProc(window, message, window_param, data_param);

   data->window = window;
   data->message = message;
   data->window_param = window_param;
   data->data_param = data_param;
   data->time = GetTickCount();
   coord = GetMessagePos();
   pt = MAKEPOINTS(coord);
   data->x = pt.x;
   data->y = pt.y;

   switch (data->message)
     {
       /* Keyboard input notifications */
     case WM_CHAR:
       _ecore_wince_event_handle_key_press(data, 0);
       break;
     case WM_HOTKEY:
       _ecore_wince_event_handle_key_press(data, 1);
       break;
     case WM_KEYDOWN:
     case WM_SYSKEYDOWN:
       _ecore_wince_event_handle_key_press(data, 1);
       break;
     case WM_KEYUP:
     case WM_SYSKEYUP:
       _ecore_wince_event_handle_key_release(data, 1);
       break;
     case WM_SETFOCUS:
       _ecore_wince_event_handle_focus_in(data);
       break;
     case WM_KILLFOCUS:
       _ecore_wince_event_handle_focus_out(data);
       break;
       /* Mouse input notifications */
     case WM_LBUTTONDOWN:
       _ecore_wince_event_handle_button_press(data, 1);
       break;
     case WM_LBUTTONUP:
       _ecore_wince_event_handle_button_release(data, 1);
       break;
     case WM_MOUSEMOVE:
       {
          RECT                rect;
          Ecore_WinCE_Window *w = NULL;

          w = (Ecore_WinCE_Window *)GetWindowLong(window, GWL_USERDATA);

          if (GetClientRect(window, &rect))
            {
               POINT pt;

               INF("mouse in window");

               pt.x = LOWORD(data_param);
               pt.y = HIWORD(data_param);
               if (!PtInRect(&rect, pt))
                 {
                    if (w->pointer_is_in)
                      {
                         w->pointer_is_in = 0;
                         _ecore_wince_event_handle_leave_notify(data);
                      }
                 }
               else
                 {
                    if (!w->pointer_is_in)
                      {
                         w->pointer_is_in = 1;
                         _ecore_wince_event_handle_enter_notify(data);
                      }
                 }
            }
          else
            {
               ERR("GetClientRect() failed");
            }
          _ecore_wince_event_handle_motion_notify(data);

          break;
       }
       /* Window notifications */
     case WM_CREATE:
       _ecore_wince_event_handle_create_notify(data);
       break;
     case WM_DESTROY:
       _ecore_wince_event_handle_destroy_notify(data);
       break;
     case WM_SHOWWINDOW:
       if ((data->data_param == SW_OTHERUNZOOM) ||
           (data->data_param == SW_OTHERZOOM))
         break;

       if (data->window_param)
         _ecore_wince_event_handle_map_notify(data);
       else
         _ecore_wince_event_handle_unmap_notify(data);

       break;
     case WM_CLOSE:
       _ecore_wince_event_handle_delete_request(data);
       break;
       /* GDI notifications */
     case WM_ERASEBKGND:
       return 1;
     case WM_PAINT:
       {
          PAINTSTRUCT paint;

          if (BeginPaint(window, &paint))
            {
               data->update = paint.rcPaint;
               _ecore_wince_event_handle_expose(data);
               EndPaint(window, &paint);
            }
          break;
       }
     default:
       return DefWindowProc(window, message, window_param, data_param);
     }

   return 0;
}

static void
_ecore_wince_error_print_cb(const Eina_Log_Domain *d __UNUSED__,
                            Eina_Log_Level  level __UNUSED__,
                            const char     *file __UNUSED__,
                            const char     *fnc,
                            int             line,
                            const char     *fmt,
                            void           *data __UNUSED__,
                            va_list         args)
{
   fprintf(stderr, "[%s:%d] ", fnc, line);
   vfprintf(stderr, fmt, args);
}

/**
 * @endcond
 */


/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/


double              _ecore_wince_double_click_time = 0.25;
long                _ecore_wince_event_last_time = 0;
Ecore_WinCE_Window *_ecore_wince_event_last_window = NULL;
HINSTANCE           _ecore_wince_instance = NULL;
int                 _ecore_wince_log_dom_global = -1;

int ECORE_WINCE_EVENT_MOUSE_IN              = 0;
int ECORE_WINCE_EVENT_MOUSE_OUT             = 0;
int ECORE_WINCE_EVENT_WINDOW_FOCUS_IN       = 0;
int ECORE_WINCE_EVENT_WINDOW_FOCUS_OUT      = 0;
int ECORE_WINCE_EVENT_WINDOW_DAMAGE         = 0;
int ECORE_WINCE_EVENT_WINDOW_CREATE         = 0;
int ECORE_WINCE_EVENT_WINDOW_DESTROY        = 0;
int ECORE_WINCE_EVENT_WINDOW_SHOW           = 0;
int ECORE_WINCE_EVENT_WINDOW_HIDE           = 0;
int ECORE_WINCE_EVENT_WINDOW_DELETE_REQUEST = 0;

/*============================================================================*
 *                                   API                                      *
 *============================================================================*/

/**
 * @addtogroup Ecore_WinCE_Group Ecore_WinCE library
 *
 * Ecore_WinCE is a library that wraps Windows CE graphic functions
 * and integrate them nicely into the Ecore main loop.
 *
 * @{
 */

/**
 * @brief Initialize the Ecore_WinCE library.
 *
 * @return 1 or greater on success, 0 on error.
 *
 * This function sets up the Windows CE graphic system. It returns 0 on
 * failure, otherwise it returns the number of times it has already been
 * called.
 *
 * When Ecore_WinCE is not used anymore, call ecore_wince_shutdown()
 * to shut down the Ecore_WinCE library.
 */
EAPI int
ecore_wince_init()
{
   WNDCLASS wc;

   if (++_ecore_wince_init_count != 1)
     return _ecore_wince_init_count;

   if (!eina_init())
     return --_ecore_wince_init_count;

   eina_log_print_cb_set(_ecore_wince_error_print_cb, NULL);
   _ecore_wince_log_dom_global = eina_log_domain_register
     ("ecore_wince", ECORE_WINCE_DEFAULT_LOG_COLOR);
   if (_ecore_wince_log_dom_global < 0)
     {
        EINA_LOG_ERR("Ecore_WinCE: Could not register log domain");
        goto shutdown_eina;
      }

   if (!ecore_event_init())
     {
        ERR("Ecore_WinCE: Could not init ecore_event");
        goto unregister_log_domain;
     }

   _ecore_wince_instance = GetModuleHandle(NULL);
   if (!_ecore_wince_instance)
     {
        ERR("GetModuleHandle() failed");
        goto shutdown_ecore_event;
     }

   memset (&wc, 0, sizeof (wc));
   wc.style = CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc = _ecore_wince_window_procedure;
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = _ecore_wince_instance;
   wc.hIcon = NULL;
   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
   wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
   wc.lpszMenuName =  NULL;
   wc.lpszClassName = ECORE_WINCE_WINDOW_CLASS;

   if(!RegisterClass(&wc))
     {
        ERR("RegisterClass() failed");
        goto free_library;
     }

   if (!ECORE_WINCE_EVENT_MOUSE_IN)
     {
        ECORE_WINCE_EVENT_MOUSE_IN              = ecore_event_type_new();
        ECORE_WINCE_EVENT_MOUSE_OUT             = ecore_event_type_new();
        ECORE_WINCE_EVENT_WINDOW_FOCUS_IN       = ecore_event_type_new();
        ECORE_WINCE_EVENT_WINDOW_FOCUS_OUT      = ecore_event_type_new();
        ECORE_WINCE_EVENT_WINDOW_DAMAGE         = ecore_event_type_new();
        ECORE_WINCE_EVENT_WINDOW_CREATE         = ecore_event_type_new();
        ECORE_WINCE_EVENT_WINDOW_DESTROY        = ecore_event_type_new();
        ECORE_WINCE_EVENT_WINDOW_SHOW           = ecore_event_type_new();
        ECORE_WINCE_EVENT_WINDOW_HIDE           = ecore_event_type_new();
        ECORE_WINCE_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
     }

   return _ecore_wince_init_count;

 free_library:
   FreeLibrary(_ecore_wince_instance);
 shutdown_ecore_event:
   ecore_event_shutdown();
 unregister_log_domain:
   eina_log_domain_unregister(_ecore_wince_log_dom_global);
 shutdown_eina:
   eina_shutdown();

   return --_ecore_wince_init_count;
}

/**
 * @brief Shut down the Ecore_WinCE library.
 *
 * @return 0 when the library is completely shut down, 1 or
 * greater otherwise.
 *
 * This function shuts down the Ecore_WinCE library. It returns 0 when it has
 * been called the same number of times than ecore_wince_init(). In that case
 * it shuts down all the Windows CE graphic system.
 */
EAPI int
ecore_wince_shutdown()
{
   HWND task_bar;

   if (--_ecore_wince_init_count != 0)
     return _ecore_wince_init_count;

   /* force task bar to be shown (in case the application exits */
   /* while being fullscreen) */
   task_bar = FindWindow(L"HHTaskBar", NULL);
   if (task_bar)
     {
        ShowWindow(task_bar, SW_SHOW);
        EnableWindow(task_bar, TRUE);
     }

   if (!UnregisterClass(ECORE_WINCE_WINDOW_CLASS, _ecore_wince_instance))
     ERR("UnregisterClass() failed");

   if (!FreeLibrary(_ecore_wince_instance))
     ERR("FreeLibrary() failed");

   _ecore_wince_instance = NULL;

   ecore_event_shutdown();
   eina_log_domain_unregister(_ecore_wince_log_dom_global);
   _ecore_wince_log_dom_global = -1;
   eina_shutdown();

   return _ecore_wince_init_count;
}

/**
 * @brief Set the timeout for a double and triple clicks to be flagged.
 *
 * @param t The time in seconds.
 *
 * This function sets the time @p t between clicks before the
 * double_click flag is set in a button down event. If 3 clicks occur
 * within double this time, the triple_click flag is also set.
 */
EAPI void
ecore_wince_double_click_time_set(double t)
{
   if (t < 0.0) t = 0.0;
   _ecore_wince_double_click_time = t;
}

/**
 * @brief Retrieve the double and triple click flag timeout.
 *
 * @return The timeout for double clicks in seconds.
 *
 * This function returns the double clicks in seconds. If
 * ecore_wince_double_click_time_set() has not been called, the
 * default value is returned. See ecore_wince_double_click_time_set()
 * for more informations.
 */
EAPI double
ecore_wince_double_click_time_get(void)
{
   return _ecore_wince_double_click_time;
}

/**
 * @brief Return the last event time.
 *
 * @return The last envent time.
 *
 * This function returns the last event time.
 */
EAPI long
ecore_wince_current_time_get(void)
{
   return _ecore_wince_event_last_time;
}

/**
 * @}
 */