summaryrefslogtreecommitdiff
path: root/src/lib/ecore_cocoa
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-12-02 22:35:45 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-12-02 22:35:45 +0000
commit7d6010b12c47a20e492da808e3192c3f87dab619 (patch)
tree26c6fd189e046a76560c0bc740b85f4d767ae399 /src/lib/ecore_cocoa
parent53fc441d5475155965d92da89502fe4634a561b2 (diff)
merge: add escape ecore, fix several bugs
SVN revision: 79995
Diffstat (limited to 'src/lib/ecore_cocoa')
-rw-r--r--src/lib/ecore_cocoa/Ecore_Cocoa.h147
-rw-r--r--src/lib/ecore_cocoa/Ecore_Cocoa_Keys.h285
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa.m283
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_private.h11
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_window.m163
5 files changed, 889 insertions, 0 deletions
diff --git a/src/lib/ecore_cocoa/Ecore_Cocoa.h b/src/lib/ecore_cocoa/Ecore_Cocoa.h
new file mode 100644
index 0000000000..51c8ead21b
--- /dev/null
+++ b/src/lib/ecore_cocoa/Ecore_Cocoa.h
@@ -0,0 +1,147 @@
1#ifndef __ECORE_COCOA_H__
2#define __ECORE_COCOA_H__
3
4/*
5 * DO NOT USE THIS HEADER. IT IS WORK IN PROGRESS. IT IS NOT FINAL AND
6 * THE API MAY CHANGE.
7 */
8
9#ifndef ECORE_COCOA_WIP_GNSIDNQI
10# warning "You are using a work in progress API. This API is not stable"
11# warning "and is subject to change. You use this at your own risk."
12#endif
13
14#ifdef EAPI
15# undef EAPI
16#endif
17
18#ifdef __GNUC__
19# if __GNUC__ >= 4
20# define EAPI __attribute__ ((visibility("default")))
21# else
22# define EAPI
23# endif
24#else
25# define EAPI
26#endif
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32typedef struct _Ecore_Cocoa_Window Ecore_Cocoa_Window;
33
34EAPI extern int ECORE_COCOA_EVENT_GOT_FOCUS;
35EAPI extern int ECORE_COCOA_EVENT_LOST_FOCUS;
36EAPI extern int ECORE_COCOA_EVENT_RESIZE;
37EAPI extern int ECORE_COCOA_EVENT_EXPOSE;
38
39typedef struct _Ecore_Cocoa_Event_Video_Resize Ecore_Cocoa_Event_Video_Resize;
40struct _Ecore_Cocoa_Event_Video_Resize
41{
42 int w;
43 int h;
44};
45
46
47/* Core */
48
49EAPI int ecore_cocoa_init(void);
50EAPI int ecore_cocoa_shutdown(void);
51EAPI void ecore_cocoa_feed_events(void);
52
53/* Window */
54
55EAPI Ecore_Cocoa_Window *ecore_cocoa_window_new(int x,
56 int y,
57 int width,
58 int height);
59
60EAPI void ecore_cocoa_window_free(Ecore_Cocoa_Window *window);
61
62EAPI void *ecore_cocoa_window_hwnd_get(Ecore_Cocoa_Window *window);
63
64EAPI void ecore_cocoa_window_move(Ecore_Cocoa_Window *window,
65 int x,
66 int y);
67
68EAPI void ecore_cocoa_window_resize(Ecore_Cocoa_Window *window,
69 int width,
70 int height);
71
72EAPI void ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window,
73 int x,
74 int y,
75 int width,
76 int height);
77
78EAPI void ecore_cocoa_window_geometry_get(Ecore_Cocoa_Window *window,
79 int *x,
80 int *y,
81 int *width,
82 int *height);
83
84EAPI void ecore_cocoa_window_size_get(Ecore_Cocoa_Window *window,
85 int *width,
86 int *height);
87
88EAPI void ecore_cocoa_window_size_min_set(Ecore_Cocoa_Window *window,
89 unsigned int min_width,
90 unsigned int min_height);
91
92EAPI void ecore_cocoa_window_size_min_get(Ecore_Cocoa_Window *window,
93 unsigned int *min_width,
94 unsigned int *min_height);
95
96EAPI void ecore_cocoa_window_size_max_set(Ecore_Cocoa_Window *window,
97 unsigned int max_width,
98 unsigned int max_height);
99
100EAPI void ecore_cocoa_window_size_max_get(Ecore_Cocoa_Window *window,
101 unsigned int *max_width,
102 unsigned int *max_height);
103
104EAPI void ecore_cocoa_window_size_base_set(Ecore_Cocoa_Window *window,
105 unsigned int base_width,
106 unsigned int base_height);
107
108EAPI void ecore_cocoa_window_size_base_get(Ecore_Cocoa_Window *window,
109 unsigned int *base_width,
110 unsigned int *base_height);
111
112EAPI void ecore_cocoa_window_size_step_set(Ecore_Cocoa_Window *window,
113 unsigned int step_width,
114 unsigned int step_height);
115
116EAPI void ecore_cocoa_window_size_step_get(Ecore_Cocoa_Window *window,
117 unsigned int *step_width,
118 unsigned int *step_height);
119
120EAPI void ecore_cocoa_window_show(Ecore_Cocoa_Window *window);
121
122EAPI void ecore_cocoa_window_hide(Ecore_Cocoa_Window *window);
123
124EAPI void ecore_cocoa_window_raise(Ecore_Cocoa_Window *window);
125
126EAPI void ecore_cocoa_window_lower(Ecore_Cocoa_Window *window);
127
128EAPI void ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window,
129 const char *title);
130
131EAPI void ecore_cocoa_window_focus_set(Ecore_Cocoa_Window *window);
132
133EAPI void ecore_cocoa_window_iconified_set(Ecore_Cocoa_Window *window,
134 int on);
135
136EAPI void ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window,
137 int on);
138
139EAPI void ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
140 void *view);
141
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif
diff --git a/src/lib/ecore_cocoa/Ecore_Cocoa_Keys.h b/src/lib/ecore_cocoa/Ecore_Cocoa_Keys.h
new file mode 100644
index 0000000000..7068bc22a8
--- /dev/null
+++ b/src/lib/ecore_cocoa/Ecore_Cocoa_Keys.h
@@ -0,0 +1,285 @@
1#ifndef ECORE_COCOA_KEYS_H__
2#define ECORE_COCOA_KEYS_H__
3
4struct _ecore_cocoa_keys_s
5{
6 int code;
7 const char *name;
8 const char *compose;
9};
10
11static const struct _ecore_cocoa_keys_s keystable[] =
12{
13
14{ 0, "0x00", "" },
15{ 0, "First", "" },
16{ 3, "Return", "\015" },
17{ 8, "BackSpace", "\010" },
18{ 9, "Tab", "\011" },
19{ 12, "Clear", "" },
20{ 13, "Return", "\015" },
21{ 19, "Pause", "" },
22{ 25, "BackTab", ""},
23{ 27, "Escape", "" },
24{ 32, "space", " " },
25{ 33, "exclam", "!" },
26{ 34, "quotedbl", "\"" },
27{ 35, "numbersign", "#" },
28{ 36, "dollar", "$" },
29{ 37, "percent", "%%" },
30{ 38, "ampersand", "&" },
31{ 39, "apostrophe", "'" },
32{ 40, "parenleft", "(" },
33{ 41, "parenright", ")" },
34{ 42, "asterisk", "*" },
35{ 43, "plus", "+" },
36{ 44, "comma", "," },
37{ 45, "minus", "-" },
38{ 46, "period", "." },
39{ 47, "slash", "/" },
40{ 48, "0", "0" },
41{ 49, "1", "1" },
42{ 50, "2", "2" },
43{ 51, "3", "3" },
44{ 52, "4", "4" },
45{ 53, "5", "5" },
46{ 54, "6", "6" },
47{ 55, "7", "7" },
48{ 56, "8", "8" },
49{ 57, "9", "9" },
50{ 58, "colon", ";" },
51{ 59, "semicolon", ";" },
52{ 60, "less", "<" },
53{ 61, "equal", "=" },
54{ 62, "greater", ">" },
55{ 63, "question", "?" },
56{ 64, "at", "@" },
57
58{ 91, "bracketleft", "[" },
59{ 92, "backslash", "\\" },
60{ 93, "bracketright", "]" },
61{ 94, "asciicircumm", "^" },
62{ 95, "underscore", "_" },
63{ 96, "backquote", "`" },
64{ 97, "a", "a" },
65{ 98, "b", "b" },
66{ 99, "c", "c" },
67{ 100, "d", "d" },
68{ 101, "e", "e" },
69{ 102, "f", "f" },
70{ 103, "g", "g" },
71{ 104, "h", "h" },
72{ 105, "i", "i" },
73{ 106, "j", "j" },
74{ 107, "k", "k" },
75{ 108, "l", "l" },
76{ 109, "m", "m" },
77{ 110, "n", "n" },
78{ 111, "o", "o" },
79{ 112, "p", "p" },
80{ 113, "q", "q" },
81{ 114, "r", "r" },
82{ 115, "s", "s" },
83{ 116, "t", "t" },
84{ 117, "u", "u" },
85{ 118, "v", "v" },
86{ 119, "w", "w" },
87{ 120, "x", "x" },
88{ 121, "y", "y" },
89{ 122, "z", "z" },
90{ 123, "braceleft", "" },
91{ 124, "pipe", "" },
92{ 125, "braceright", "" },
93{ 127, "Delete", "\177" },
94{ 126, "asciitilde", "~" },
95
96{ 160, "w0", "" },
97{ 161, "w1", "" },
98{ 162, "w2", "" },
99{ 163, "w3", "" },
100{ 164, "w4", "" },
101{ 165, "w5", "" },
102{ 166, "w6", "" },
103{ 167, "w7", "" },
104{ 168, "w8", "" },
105{ 169, "w9", "" },
106{ 170, "w10", "" },
107{ 171, "w11", "" },
108{ 172, "w12", "" },
109{ 173, "w13", "" },
110{ 174, "w14", "" },
111{ 175, "w15", "" },
112{ 176, "w16", "" },
113{ 177, "w17", "" },
114{ 178, "w18", "" },
115{ 179, "w19", "" },
116{ 180, "w20", "" },
117{ 181, "w21", "" },
118{ 182, "w22", "" },
119{ 183, "w23", "" },
120{ 184, "w24", "" },
121{ 185, "w25", "" },
122{ 186, "w26", "" },
123{ 187, "w27", "" },
124{ 188, "w28", "" },
125{ 189, "w29", "" },
126{ 190, "w30", "" },
127{ 191, "w31", "" },
128{ 192, "w32", "" },
129{ 193, "w33", "" },
130{ 194, "w34", "" },
131{ 195, "w35", "" },
132{ 196, "w36", "" },
133{ 197, "w37", "" },
134{ 198, "w38", "" },
135{ 199, "w39", "" },
136{ 200, "w40", "" },
137{ 201, "w41", "" },
138{ 202, "w42", "" },
139{ 203, "w43", "" },
140{ 204, "w44", "" },
141{ 205, "w45", "" },
142{ 206, "w46", "" },
143{ 207, "w47", "" },
144{ 208, "w48", "" },
145{ 209, "w49", "" },
146{ 210, "w50", "" },
147{ 211, "w51", "" },
148{ 212, "w52", "" },
149{ 213, "w53", "" },
150{ 214, "w54", "" },
151{ 215, "w55", "" },
152{ 216, "w56", "" },
153{ 217, "w57", "" },
154{ 218, "w58", "" },
155{ 219, "w59", "" },
156{ 220, "w60", "" },
157{ 221, "w61", "" },
158{ 222, "w62", "" },
159{ 223, "w63", "" },
160{ 224, "w64", "" },
161{ 225, "w65", "" },
162{ 226, "w66", "" },
163{ 227, "w67", "" },
164{ 228, "w68", "" },
165{ 229, "w69", "" },
166{ 230, "w70", "" },
167{ 231, "w71", "" },
168{ 232, "w72", "" },
169{ 233, "w73", "" },
170{ 234, "w74", "" },
171{ 235, "w75", "" },
172{ 236, "w76", "" },
173{ 237, "w77", "" },
174{ 238, "w78", "" },
175{ 239, "w79", "" },
176{ 240, "w80", "" },
177{ 241, "w81", "" },
178{ 242, "w82", "" },
179{ 243, "w83", "" },
180{ 244, "w84", "" },
181{ 245, "w85", "" },
182{ 246, "w86", "" },
183{ 247, "w87", "" },
184{ 248, "w88", "" },
185{ 249, "w89", "" },
186{ 250, "w90", "" },
187{ 251, "w91", "" },
188{ 252, "w92", "" },
189{ 253, "w93", "" },
190{ 254, "w94", "" },
191{ 255, "w95", "" },
192
193{ 256, "KP0", "0" },
194{ 257, "KP1", "1" },
195{ 258, "KP2", "2" },
196{ 259, "KP3", "3" },
197{ 260, "KP4", "4" },
198{ 261, "KP5", "5" },
199{ 262, "KP6", "6" },
200{ 263, "KP7", "7" },
201{ 264, "KP8", "8" },
202{ 265, "KP9", "9" },
203{ 266, "period", "." },
204{ 267, "KP_Divide", "/" },
205{ 268, "KP_Multiply", "*" },
206{ 269, "KP_Minus", "-" },
207{ 270, "KP_Plus", "+" },
208{ 271, "KP_Enter", "\015" },
209{ 272, "KP_Equals", "=" },
210
211{ NSUpArrowFunctionKey, "Up", "" },
212{ NSDownArrowFunctionKey, "Down", "" },
213{ NSRightArrowFunctionKey, "Right", "" },
214{ NSLeftArrowFunctionKey, "Left", "" },
215{ NSInsertFunctionKey, "Insert", "" },
216{ NSHomeFunctionKey, "Home", "" },
217{ NSEndFunctionKey, "End", "" },
218{ NSPageUpFunctionKey, "Page_Up", "" },
219{ NSPageDownFunctionKey, "Page_Down", "" },
220
221{ NSF1FunctionKey, "F1", "" },
222{ NSF2FunctionKey, "F2", "" },
223{ NSF3FunctionKey, "F3", "" },
224{ NSF4FunctionKey, "F4", "" },
225{ NSF5FunctionKey, "F5", "" },
226{ NSF6FunctionKey, "F6", "" },
227{ NSF7FunctionKey, "F7", "" },
228{ NSF8FunctionKey, "F8", "" },
229{ NSF9FunctionKey, "F9", "" },
230{ NSF10FunctionKey, "F10", "" },
231{ NSF11FunctionKey, "F11", "" },
232{ NSF12FunctionKey, "F12", "" },
233{ NSF13FunctionKey, "F13", "" },
234{ NSF14FunctionKey, "F14", "" },
235{ NSF15FunctionKey, "F15", "" },
236{ NSF16FunctionKey, "F16", "" },
237{ NSF17FunctionKey, "F17", "" },
238{ NSF18FunctionKey, "F18", "" },
239{ NSF19FunctionKey, "F19", "" },
240{ NSF20FunctionKey, "F20", "" },
241{ NSF21FunctionKey, "F21", "" },
242{ NSF22FunctionKey, "F22", "" },
243{ NSF23FunctionKey, "F23", "" },
244{ NSF24FunctionKey, "F24", "" },
245{ NSF25FunctionKey, "F25", "" },
246{ NSF26FunctionKey, "F26", "" },
247{ NSF27FunctionKey, "F27", "" },
248{ NSF28FunctionKey, "F28", "" },
249{ NSF29FunctionKey, "F29", "" },
250{ NSF30FunctionKey, "F30", "" },
251{ NSF31FunctionKey, "F31", "" },
252{ NSF32FunctionKey, "F32", "" },
253{ NSF33FunctionKey, "F33", "" },
254{ NSF34FunctionKey, "F34", "" },
255{ NSF35FunctionKey, "F35", "" },
256
257{ NSClearLineFunctionKey, "Num_Lock", "" },
258{ 301, "Caps_Lock", "" },
259{ NSScrollLockFunctionKey, "Scroll_Lock", "" },
260{ 303, "Shift_R", "" },
261{ 304, "Shift_L", "" },
262{ 305, "Control_R", "" },
263{ 306, "Control_L", "" },
264{ 307, "Alt_R", "" },
265{ 308, "Alt_L", "" },
266{ 309, "Meta_R", "" },
267{ 310, "Meta_L", "" },
268{ 311, "Super_L", "" },
269{ 312, "Super_R", "" },
270
271{ NSModeSwitchFunctionKey, "Mode", "" },
272{ 314, "Compose", "" },
273
274{ NSHelpFunctionKey, "Help", "" },
275{ NSPrintFunctionKey, "Print", "" },
276{ NSSysReqFunctionKey, "SysReq", "" },
277{ NSBreakFunctionKey, "Break", "" },
278{ NSMenuFunctionKey, "Menu", "" },
279{ 320, "Power", "" },
280{ 321, "Euro", "" },
281{ NSUndoFunctionKey, "Undo", "" }
282
283};
284
285#endif /* ECORE_COCOA_KEYS_H__ */
diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m
new file mode 100644
index 0000000000..3f6023af1f
--- /dev/null
+++ b/src/lib/ecore_cocoa/ecore_cocoa.m
@@ -0,0 +1,283 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Cocoa/Cocoa.h>
6
7#include <Eina.h>
8
9#include <Ecore.h>
10#include <ecore_private.h>
11#include <Ecore_Input.h>
12
13#include "Ecore_Cocoa.h"
14#include "Ecore_Cocoa_Keys.h"
15
16
17EAPI int ECORE_COCOA_EVENT_GOT_FOCUS = 0;
18EAPI int ECORE_COCOA_EVENT_LOST_FOCUS = 0;
19EAPI int ECORE_COCOA_EVENT_RESIZE = 0;
20EAPI int ECORE_COCOA_EVENT_EXPOSE = 0;
21
22static int _ecore_cocoa_init_count = 0;
23
24static int old_flags;
25
26EAPI int
27ecore_cocoa_init(void)
28{
29 if (++_ecore_cocoa_init_count != 1)
30 return _ecore_cocoa_init_count;
31
32 if (!ecore_event_init())
33 return --_ecore_cocoa_init_count;
34
35 NSApplicationLoad();
36
37 ECORE_COCOA_EVENT_GOT_FOCUS = ecore_event_type_new();
38 ECORE_COCOA_EVENT_LOST_FOCUS = ecore_event_type_new();
39 ECORE_COCOA_EVENT_RESIZE = ecore_event_type_new();
40 ECORE_COCOA_EVENT_EXPOSE = ecore_event_type_new();
41
42 return _ecore_cocoa_init_count;
43}
44
45/**
46 * Shuts down the Ecore_Cocoa library.
47 * @return @c The number of times the system has been initialised without
48 * being shut down.
49 * @ingroup Ecore_Cocoa_Library_Group
50 */
51EAPI int
52ecore_cocoa_shutdown(void)
53{
54 if (--_ecore_cocoa_init_count != 0)
55 return _ecore_cocoa_init_count;
56
57 ecore_event_shutdown();
58
59 return _ecore_cocoa_init_count;
60}
61
62EAPI void
63ecore_cocoa_feed_events(void)
64{
65 NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0.001];
66 NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
67 untilDate:date
68 inMode:NSDefaultRunLoopMode
69 dequeue:YES];
70 [date release];
71 if (!event) return; // SDL loops until null; maybe we should do that too. or not.
72
73 unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
74
75 switch([event type])
76 {
77 case NSMouseMoved:
78 case NSLeftMouseDragged:
79 case NSRightMouseDragged:
80 case NSOtherMouseDragged:
81 {
82 Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move));
83 if (!ev) return;
84 ev->x = [event locationInWindow].x;
85 ev->y = [event locationInWindow].y;
86 ev->root.x = ev->x;
87 ev->root.y = ev->y;
88 ev->timestamp = time;
89 ev->window = [event window];
90 ev->modifiers = 0; /* FIXME: keep modifier around. */
91
92 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
93
94 [NSApp sendEvent:event]; // pass along mouse events, for window manager
95 break;
96 }
97 case NSLeftMouseDown:
98 case NSRightMouseDown:
99 case NSOtherMouseDown:
100 {
101 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
102 if (!ev) return;
103 ev->x = [event locationInWindow].x;
104 ev->y = [event locationInWindow].y;
105 ev->root.x = ev->x;
106 ev->root.y = ev->y;
107 ev->timestamp = time;
108 ev->buttons = [event buttonNumber] + 1; // Apple indexes buttons from 0
109
110 if ([event clickCount] == 2)
111 ev->double_click = 1;
112 else
113 ev->double_click = 0;
114
115 if ([event clickCount] >= 3)
116 ev->triple_click = 1;
117 else
118 ev->triple_click = 0;
119
120 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
121
122 [NSApp sendEvent:event]; // pass along mouse events, for window manager
123 break;
124 }
125 case NSLeftMouseUp:
126 case NSRightMouseUp:
127 case NSOtherMouseUp:
128 {
129 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
130 if (!ev) return;
131 ev->x = [event locationInWindow].x;
132 ev->y = [event locationInWindow].y;
133 ev->root.x = ev->x;
134 ev->root.y = ev->y;
135 ev->timestamp = time;
136 ev->buttons = [event buttonNumber] + 1; // Apple indexes buttons from 0
137
138 if ([event clickCount] == 2)
139 ev->double_click = 1;
140 else
141 ev->double_click = 0;
142
143 if ([event clickCount] >= 3)
144 ev->triple_click = 1;
145 else
146 ev->triple_click = 0;
147
148 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
149
150 [NSApp sendEvent:event]; // pass along mouse events, for window manager
151 break;
152 }
153 case NSKeyDown:
154 {
155 Ecore_Event_Key *ev;
156 unsigned int i;
157
158 ev = calloc(1, sizeof (Ecore_Event_Key));
159 if (!ev) return;
160 ev->timestamp = time;
161
162 for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_cocoa_keys_s); ++i)
163 {
164 if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0]))
165 {
166 ev->keyname = keystable[i].name;
167 ev->string = keystable[i].compose;
168
169 ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL);
170 return;
171 }
172 }
173
174 break;
175 }
176 case NSKeyUp:
177 {
178 Ecore_Event_Key *ev;
179 unsigned int i;
180
181 ev = calloc(1, sizeof (Ecore_Event_Key));
182 if (!ev) return;
183 ev->timestamp = time;
184
185 for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_cocoa_keys_s); ++i)
186 {
187 if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0]))
188 {
189 ev->keyname = keystable[i].name;
190 ev->string = keystable[i].compose;
191
192 ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
193 return;
194 }
195 }
196
197 break;
198 }
199 case NSFlagsChanged:
200 {
201 int flags = [event modifierFlags];
202
203 Ecore_Event_Key *evDown = NULL;
204 Ecore_Event_Key *evUp = NULL;
205
206 evDown = calloc(1, sizeof (Ecore_Event_Key));
207 if (!evDown) return;
208
209 evUp = calloc(1, sizeof (Ecore_Event_Key));
210 if (!evUp)
211 {
212 free(evDown);
213 return;
214 }
215
216 // Turn special key flags on
217 if (flags & NSShiftKeyMask)
218 evDown->keyname = "Shift_L";
219 else if (flags & NSControlKeyMask)
220 evDown->keyname = "Control_L";
221 else if (flags & NSAlternateKeyMask)
222 evDown->keyname = "Alt_L";
223 else if (flags & NSCommandKeyMask)
224 evDown->keyname = "Super_L";
225 else if (flags & NSAlphaShiftKeyMask)
226 evDown->keyname = "Caps_Lock";
227
228 if (evDown->keyname)
229 {
230 evDown->timestamp = time;
231 evDown->string = "";
232 ecore_event_add(ECORE_EVENT_KEY_DOWN, evDown, NULL, NULL);
233 old_flags = flags;
234 break;
235 }
236
237 int changed_flags = flags ^ old_flags;
238
239 // Turn special key flags off
240 if (changed_flags & NSShiftKeyMask)
241 evUp->keyname = "Shift_L";
242 else if (changed_flags & NSControlKeyMask)
243 evUp->keyname = "Control_L";
244 else if (changed_flags & NSAlternateKeyMask)
245 evUp->keyname = "Alt_L";
246 else if (changed_flags & NSCommandKeyMask)
247 evUp->keyname = "Super_L";
248 else if (changed_flags & NSAlphaShiftKeyMask)
249 evUp->keyname = "Caps_Lock";
250
251 if (evUp->keyname)
252 {
253 evUp->timestamp = time;
254 evUp->string = "";
255 ecore_event_add(ECORE_EVENT_KEY_UP, evUp, NULL, NULL);
256 old_flags = flags;
257 break;
258 }
259
260 break;
261 }
262 case NSAppKitDefined:
263 {
264 if ([event subtype] == NSApplicationActivatedEventType)
265 ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, NULL, NULL, NULL);
266 else if ([event subtype] == NSApplicationDeactivatedEventType)
267 ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, NULL, NULL, NULL);
268 [NSApp sendEvent:event]; // pass along AppKit events, for window manager
269 break;
270 }
271 case NSScrollWheel:
272 {
273 break;
274 }
275 default:
276 {
277 [NSApp sendEvent:event];
278 break;
279 }
280 }
281
282 [event release];
283}
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_private.h b/src/lib/ecore_cocoa/ecore_cocoa_private.h
new file mode 100644
index 0000000000..0b4cf3178e
--- /dev/null
+++ b/src/lib/ecore_cocoa/ecore_cocoa_private.h
@@ -0,0 +1,11 @@
1#ifndef _ECORE_COCOA_PRIVATE_H
2#define _ECORE_COCOA_PRIVATE_H
3
4struct _Ecore_Cocoa_Window
5{
6 NSWindow *window;
7 unsigned int borderless : 1;
8};
9
10
11#endif
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.m b/src/lib/ecore_cocoa/ecore_cocoa_window.m
new file mode 100644
index 0000000000..2091a69b32
--- /dev/null
+++ b/src/lib/ecore_cocoa/ecore_cocoa_window.m
@@ -0,0 +1,163 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Cocoa/Cocoa.h>
6
7#include "Ecore_Cocoa.h"
8#include "ecore_cocoa_private.h"
9
10Ecore_Cocoa_Window *
11ecore_cocoa_window_new(int x,
12 int y,
13 int width,
14 int height)
15{
16 Ecore_Cocoa_Window *w;
17
18 NSWindow *window = [[NSWindow alloc]
19 initWithContentRect:NSMakeRect(x, y, width, height)
20 styleMask:(NSTitledWindowMask |
21 NSClosableWindowMask |
22 NSResizableWindowMask |
23 NSMiniaturizableWindowMask)
24 backing:NSBackingStoreBuffered
25 defer:NO
26 screen:nil
27 ];
28
29 if (!window)
30 return NULL;
31
32 [window setBackgroundColor:[NSColor whiteColor]];
33
34 w = calloc(1, sizeof(Ecore_Cocoa_Window));
35 w->window = window;
36 w->borderless = 0;
37
38 return w;
39}
40
41void
42ecore_cocoa_window_free(Ecore_Cocoa_Window *window)
43{
44 if (!window)
45 return;
46
47 [window->window release];
48 free(window);
49}
50
51void
52ecore_cocoa_window_move(Ecore_Cocoa_Window *window,
53 int x,
54 int y)
55{
56 NSRect win_frame;
57
58 if (!window)
59 return;
60
61 win_frame = [window->window frame];
62 win_frame.origin.x = x;
63 win_frame.origin.y = y;
64
65 [window->window setFrame:win_frame display:YES];
66}
67
68void
69ecore_cocoa_window_resize(Ecore_Cocoa_Window *window,
70 int width,
71 int height)
72{
73 if (!window)
74 return;
75
76 NSRect win_frame;
77
78 if (!window)
79 return;
80
81 win_frame = [window->window frame];
82 win_frame.size.height = height;
83 win_frame.size.width = width;
84
85 [window->window setFrame:win_frame display:YES];
86}
87
88void
89ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window,
90 int x,
91 int y,
92 int width,
93 int height)
94{
95 if (!window)
96 return;
97
98 NSRect win_frame;
99
100 if (!window)
101 return;
102
103 win_frame = [window->window frame];
104 win_frame.size.height = height;
105 win_frame.size.width = width;
106 win_frame.origin.x = x;
107 win_frame.origin.y = y;
108
109 [window->window setFrame:win_frame display:YES];
110}
111
112void
113ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title)
114{
115 if (!window || !title)
116 return;
117
118 [window->window setTitle:[NSString stringWithUTF8String:title]];
119}
120
121void
122ecore_cocoa_window_show(Ecore_Cocoa_Window *window)
123{
124 if (!window || [window->window isVisible])
125 {
126 printf("Window(%p) is not visible\n", window->window);
127 return;
128 }
129
130 [window->window makeKeyAndOrderFront:NSApp];
131}
132
133void
134ecore_cocoa_window_hide(Ecore_Cocoa_Window *window)
135{
136 if (!window || ![window->window isVisible])
137 return;
138
139 [window->window orderOut:NSApp];
140}
141
142void
143ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window,
144 int on)
145{
146 if (!window)
147 return;
148
149 if (on)
150 [window->window setContentBorderThickness:0.0
151 forEdje:NSMinXEdge | NSMinYEdge | NSMaxXEdge | NSMaxYEdge];
152}
153
154void
155ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
156 void *view)
157{
158 if (!window || !view)
159 return;
160
161 [[window->window contentView] addSubview:view];
162
163}