diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa_window.m | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa_window.m b/libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa_window.m new file mode 100644 index 0000000..2091a69 --- /dev/null +++ b/libraries/ecore/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 | |||
10 | Ecore_Cocoa_Window * | ||
11 | ecore_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 | |||
41 | void | ||
42 | ecore_cocoa_window_free(Ecore_Cocoa_Window *window) | ||
43 | { | ||
44 | if (!window) | ||
45 | return; | ||
46 | |||
47 | [window->window release]; | ||
48 | free(window); | ||
49 | } | ||
50 | |||
51 | void | ||
52 | ecore_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 | |||
68 | void | ||
69 | ecore_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 | |||
88 | void | ||
89 | ecore_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 | |||
112 | void | ||
113 | ecore_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 | |||
121 | void | ||
122 | ecore_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 | |||
133 | void | ||
134 | ecore_cocoa_window_hide(Ecore_Cocoa_Window *window) | ||
135 | { | ||
136 | if (!window || ![window->window isVisible]) | ||
137 | return; | ||
138 | |||
139 | [window->window orderOut:NSApp]; | ||
140 | } | ||
141 | |||
142 | void | ||
143 | ecore_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 | |||
154 | void | ||
155 | ecore_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 | } | ||