7e89f9a274e8098aa489b213e8555bd270d81218
[framework/uifw/ecore.git] / src / lib / ecore_win32 / ecore_win32_cursor.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #define WIN32_LEAN_AND_MEAN
10 #include <windows.h>
11 #undef WIN32_LEAN_AND_MEAN
12
13 #include "Ecore_Win32.h"
14 #include "ecore_win32_private.h"
15
16
17 /***** API *****/
18
19 Ecore_Win32_Cursor *
20 ecore_win32_cursor_new(const void *pixels_and,
21                        const void *pixels_xor,
22                        int         width,
23                        int         height,
24                        int         hot_x,
25                        int         hot_y)
26 {
27    Ecore_Win32_Cursor *cursor = NULL;
28    int                 cursor_width;
29    int                 cursor_height;
30
31    cursor_width = GetSystemMetrics(SM_CXCURSOR);
32    cursor_height = GetSystemMetrics(SM_CYCURSOR);
33
34    if ((cursor_width != width) ||
35        (cursor_height != height))
36      return NULL;
37
38    if (!(cursor = CreateCursor(_ecore_win32_instance,
39                                hot_x, hot_y,
40                                width, height,
41                                pixels_and,
42                                pixels_xor)))
43      return NULL;
44
45    return cursor;
46 }
47
48 void
49 ecore_win32_cursor_free(Ecore_Win32_Cursor *cursor)
50 {
51    DestroyCursor(cursor);
52 }
53
54 Ecore_Win32_Cursor *
55 ecore_win32_cursor_shape_get(Ecore_Win32_Cursor_Shape shape)
56 {
57    Ecore_Win32_Cursor *cursor = NULL;
58    const char         *cursor_name;
59
60    switch (shape)
61      {
62        case ECORE_WIN32_CURSOR_SHAPE_APP_STARTING:
63          cursor_name = IDC_APPSTARTING;
64          break;
65        case ECORE_WIN32_CURSOR_SHAPE_ARROW:
66          cursor_name = IDC_ARROW;
67          break;
68        case ECORE_WIN32_CURSOR_SHAPE_CROSS:
69          cursor_name = IDC_CROSS;
70          break;
71        case ECORE_WIN32_CURSOR_SHAPE_HAND:
72          cursor_name = IDC_HAND;
73          break;
74        case ECORE_WIN32_CURSOR_SHAPE_HELP:
75          cursor_name = IDC_HELP;
76          break;
77        case ECORE_WIN32_CURSOR_SHAPE_I_BEAM:
78          cursor_name = IDC_IBEAM;
79          break;
80        case ECORE_WIN32_CURSOR_SHAPE_NO:
81          cursor_name = IDC_NO;
82          break;
83        case ECORE_WIN32_CURSOR_SHAPE_SIZE_ALL:
84          cursor_name = IDC_SIZEALL;
85          break;
86        case ECORE_WIN32_CURSOR_SHAPE_SIZE_NESW:
87          cursor_name = IDC_SIZENESW;
88          break;
89        case ECORE_WIN32_CURSOR_SHAPE_SIZE_NS:
90          cursor_name = IDC_SIZENS;
91          break;
92        case ECORE_WIN32_CURSOR_SHAPE_SIZE_NWSE:
93          cursor_name = IDC_SIZENWSE;
94          break;
95        case ECORE_WIN32_CURSOR_SHAPE_SIZE_WE:
96          cursor_name = IDC_SIZEWE;
97          break;
98        case ECORE_WIN32_CURSOR_SHAPE_UP_ARROW:
99          cursor_name = IDC_UPARROW;
100          break;
101        case ECORE_WIN32_CURSOR_SHAPE_WAIT:
102          cursor_name = IDC_WAIT;
103          break;
104      default:
105          return NULL;
106      }
107
108    if (!(cursor = LoadCursor(NULL, cursor_name)))
109      return NULL;
110
111    return cursor;
112 }
113
114 int
115 ecore_win32_cursor_size_get(void)
116 {
117    int width;
118    int height;
119
120    width = GetSystemMetrics(SM_CXCURSOR);
121    height = GetSystemMetrics(SM_CYCURSOR);
122    return (width > height) ? width : height;
123 }