summaryrefslogtreecommitdiff
path: root/src/lib/ecore_cocoa/ecore_cocoa_window.m
diff options
context:
space:
mode:
authorNicolas Aguirre <aguirre.nicolas@gmail.com>2014-01-05 19:45:01 +0100
committerCedric BAIL <c.bail@partner.samsung.com>2014-06-18 11:34:06 +0200
commit7e0d7a2c5487dd8cd9ca1f8d6da5e264b1d39006 (patch)
treeb54c99baf4b14961d1a05c422454660d9a63e023 /src/lib/ecore_cocoa/ecore_cocoa_window.m
parentc7993e2cb4d9f4620311707892383a36c0b30b2f (diff)
ecore_cocoa: indent with efl style
Diffstat (limited to '')
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_window.m400
1 files changed, 237 insertions, 163 deletions
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.m b/src/lib/ecore_cocoa/ecore_cocoa_window.m
index 2091a69b32..b58854f472 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa_window.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa_window.m
@@ -1,163 +1,237 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <Cocoa/Cocoa.h> 5#import "ecore_cocoa_window.h"
6 6#include "Ecore_Cocoa.h"
7#include "Ecore_Cocoa.h" 7#include "ecore_cocoa_private.h"
8#include "ecore_cocoa_private.h" 8
9 9@implementation EcoreCocoaWindow
10Ecore_Cocoa_Window * 10
11ecore_cocoa_window_new(int x, 11@synthesize ecore_window_data;
12 int y, 12
13 int width, 13- (id) initWithContentRect: (NSRect) contentRect
14 int height) 14 styleMask: (unsigned int) aStyle
15{ 15 backing: (NSBackingStoreType) bufferingType
16 Ecore_Cocoa_Window *w; 16 defer: (BOOL) flag
17 17{
18 NSWindow *window = [[NSWindow alloc] 18 if (![super initWithContentRect: contentRect
19 initWithContentRect:NSMakeRect(x, y, width, height) 19 styleMask: aStyle
20 styleMask:(NSTitledWindowMask | 20 backing: bufferingType
21 NSClosableWindowMask | 21 defer: flag]) return nil;
22 NSResizableWindowMask | 22
23 NSMiniaturizableWindowMask) 23 [self setBackgroundColor: [NSColor whiteColor]];
24 backing:NSBackingStoreBuffered 24 [self makeKeyWindow];
25 defer:NO 25 [self setDelegate:self];
26 screen:nil 26 [self setAcceptsMouseMovedEvents:YES];
27 ]; 27
28 28 return self;
29 if (!window) 29}
30 return NULL; 30
31 31- (BOOL)acceptsFirstResponder
32 [window setBackgroundColor:[NSColor whiteColor]]; 32{
33 33 return YES;
34 w = calloc(1, sizeof(Ecore_Cocoa_Window)); 34}
35 w->window = window; 35
36 w->borderless = 0; 36- (BOOL)canBecomeKeyWindow
37 37{
38 return w; 38 return YES;
39} 39}
40 40
41void 41- (void)windowWillClose:(NSNotification *)notification
42ecore_cocoa_window_free(Ecore_Cocoa_Window *window) 42{
43{ 43 NSLog(@"window is going to be closed");
44 if (!window) 44}
45 return; 45
46 46- (void)windowDidResize:(NSNotification *)notification {
47 [window->window release]; 47 NSRect content_rect = [self contentRectForFrameRect:[self frame]];
48 free(window); 48 Ecore_Cocoa_Window *window = ecore_window_data;
49} 49 ecore_cocoa_window_resize(window, content_rect.size.width, content_rect.size.height);
50 50 printf("THIS IS A RESIZE......................%gx%g\n", content_rect.size.width, content_rect.size.height);
51void 51}
52ecore_cocoa_window_move(Ecore_Cocoa_Window *window, 52
53 int x, 53@end
54 int y) 54
55{ 55
56 NSRect win_frame; 56
57 57static float _title_bar_height(void)
58 if (!window) 58{
59 return; 59 NSRect frame = NSMakeRect (0, 0, 100, 100);
60 60 NSRect contentRect;
61 win_frame = [window->window frame]; 61
62 win_frame.origin.x = x; 62 contentRect = [NSWindow contentRectForFrameRect: frame
63 win_frame.origin.y = y; 63 styleMask: NSTitledWindowMask];
64 64
65 [window->window setFrame:win_frame display:YES]; 65 return (frame.size.height - contentRect.size.height);
66} 66}
67 67
68void 68Ecore_Cocoa_Window *
69ecore_cocoa_window_resize(Ecore_Cocoa_Window *window, 69ecore_cocoa_window_new(int x,
70 int width, 70 int y,
71 int height) 71 int width,
72{ 72 int height)
73 if (!window) 73{
74 return; 74 Ecore_Cocoa_Window *w;
75 75
76 NSRect win_frame; 76 EcoreCocoaWindow *window = [[EcoreCocoaWindow alloc] initWithContentRect:NSMakeRect(x, y, width, height)
77 77 styleMask:(NSTitledWindowMask |
78 if (!window) 78 NSClosableWindowMask |
79 return; 79 NSResizableWindowMask |
80 80 NSMiniaturizableWindowMask)
81 win_frame = [window->window frame]; 81 backing:NSBackingStoreBuffered
82 win_frame.size.height = height; 82 defer:NO];
83 win_frame.size.width = width; 83
84 84 if (!window)
85 [window->window setFrame:win_frame display:YES]; 85 return NULL;
86} 86
87 87 //Set the process to be a foreground process,
88void 88 //without that it prevents the window to become the key window and
89ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window, 89 //receive all mouse mouve events.
90 int x, 90 ProcessSerialNumber psn;
91 int y, 91 GetCurrentProcess(&psn);
92 int width, 92 TransformProcessType(&psn, kProcessTransformToForegroundApplication);
93 int height) 93 SetFrontProcess(&psn);
94{ 94
95 if (!window) 95 w = calloc(1, sizeof(Ecore_Cocoa_Window));
96 return; 96 w->window = window;
97 97 w->borderless = 0;
98 NSRect win_frame; 98
99 99 window.ecore_window_data = w;
100 if (!window) 100
101 return; 101 return w;
102 102}
103 win_frame = [window->window frame]; 103
104 win_frame.size.height = height; 104void
105 win_frame.size.width = width; 105ecore_cocoa_window_free(Ecore_Cocoa_Window *window)
106 win_frame.origin.x = x; 106{
107 win_frame.origin.y = y; 107 if (!window)
108 108 return;
109 [window->window setFrame:win_frame display:YES]; 109
110} 110 [window->window release];
111 111 free(window);
112void 112}
113ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title) 113
114{ 114void
115 if (!window || !title) 115ecore_cocoa_window_move(Ecore_Cocoa_Window *window,
116 return; 116 int x,
117 117 int y)
118 [window->window setTitle:[NSString stringWithUTF8String:title]]; 118{
119} 119 NSRect win_frame;
120 120
121void 121 if (!window)
122ecore_cocoa_window_show(Ecore_Cocoa_Window *window) 122 return;
123{ 123
124 if (!window || [window->window isVisible]) 124 win_frame = [window->window frame];
125 { 125 win_frame.origin.x = x;
126 printf("Window(%p) is not visible\n", window->window); 126 win_frame.origin.y = y;
127 return; 127
128 } 128 [window->window setFrame:win_frame display:YES];
129 129}
130 [window->window makeKeyAndOrderFront:NSApp]; 130
131} 131void
132 132ecore_cocoa_window_resize(Ecore_Cocoa_Window *window,
133void 133 int width,
134ecore_cocoa_window_hide(Ecore_Cocoa_Window *window) 134 int height)
135{ 135{
136 if (!window || ![window->window isVisible]) 136 if (!window)
137 return; 137 return;
138 138
139 [window->window orderOut:NSApp]; 139 NSRect win_frame;
140} 140
141 141 if (!window)
142void 142 return;
143ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window, 143
144 int on) 144 win_frame = [window->window frame];
145{ 145 win_frame.size.height = height + _title_bar_height();
146 if (!window) 146 win_frame.size.width = width;
147 return; 147 printf("Resize ..............\n");
148 148 [window->window setFrame:win_frame display:YES];
149 if (on) 149 //ecore_event_add(ECORE_COCOA_EVENT_RESIZE, NULL, NULL, NULL);
150 [window->window setContentBorderThickness:0.0 150}
151 forEdje:NSMinXEdge | NSMinYEdge | NSMaxXEdge | NSMaxYEdge]; 151
152} 152void
153 153ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window,
154void 154 int x,
155ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window, 155 int y,
156 void *view) 156 int width,
157{ 157 int height)
158 if (!window || !view) 158{
159 return; 159 if (!window)
160 160 return;
161 [[window->window contentView] addSubview:view]; 161
162 162 NSRect win_frame;
163} 163
164 if (!window)
165 return;
166
167 win_frame = [window->window frame];
168 win_frame.size.height = height + _title_bar_height();
169 win_frame.size.width = width;
170 win_frame.origin.x = x;
171 win_frame.origin.y = y;
172
173 [window->window setFrame:win_frame display:YES];
174}
175
176void
177ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title)
178{
179 if (!window || !title)
180 return;
181
182 [window->window setTitle:[NSString stringWithUTF8String:title]];
183}
184
185void
186ecore_cocoa_window_show(Ecore_Cocoa_Window *window)
187{
188 if (!window || [window->window isVisible])
189 {
190 printf("Window(%p) is not visible\n", window->window);
191 return;
192 }
193
194 [window->window makeKeyAndOrderFront:NSApp];
195}
196
197void
198ecore_cocoa_window_hide(Ecore_Cocoa_Window *window)
199{
200 if (!window || ![window->window isVisible])
201 return;
202
203 [window->window orderOut:NSApp];
204}
205
206void
207ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window,
208 int on)
209{
210 if (!window)
211 return;
212
213 if (on)
214 [window->window setContentBorderThickness:0.0
215 forEdje:NSMinXEdge | NSMinYEdge | NSMaxXEdge | NSMaxYEdge];
216}
217
218void
219ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
220 void *view)
221{
222 if (!window || !view)
223 return;
224
225 //[[window->window contentView] addSubview:view];
226 [window->window setContentView:view];
227
228 NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[view frame]
229 options:NSTrackingMouseMoved |
230 NSTrackingActiveInActiveApp |
231 NSTrackingInVisibleRect
232 owner:view
233 userInfo:nil];
234 [view addTrackingArea:area];
235
236 [area release];
237}