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