]>
Commit | Line | Data |
---|---|---|
33e90275 | 1 | ///////////////////////////////////////////////////////////////////////////// |
0f9b48d1 | 2 | // Name: src/osx/cocoa/nonownedwnd.mm |
33e90275 SC |
3 | // Purpose: non owned window for cocoa |
4 | // Author: DavidStefan Csomor | |
5 | // Modified by: | |
6 | // Created: 2008-06-20 | |
7 | // RCS-ID: $Id: nonownedwnd.mm 48805 2007-09-19 14:52:25Z SC $ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
05cf95ed SC |
13 | #ifndef WX_PRECOMP |
14 | #include "wx/nonownedwnd.h" | |
15 | #include "wx/frame.h" | |
33e90275 SC |
16 | #endif |
17 | ||
33e90275 | 18 | #include "wx/osx/private.h" |
33e90275 | 19 | |
33e90275 SC |
20 | NSRect wxToNSRect( NSView* parent, const wxRect& r ) |
21 | { | |
22 | NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame]; | |
23 | int y = r.y; | |
24 | int x = r.x ; | |
94929e7b | 25 | if ( parent == NULL || ![ parent isFlipped ] ) |
e490b0d2 | 26 | y = (int)(frame.size.height - ( r.y + r.height )); |
33e90275 SC |
27 | return NSMakeRect(x, y, r.width , r.height); |
28 | } | |
29 | ||
30 | wxRect wxFromNSRect( NSView* parent, const NSRect& rect ) | |
31 | { | |
32 | NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame]; | |
e490b0d2 VZ |
33 | int y = (int)rect.origin.y; |
34 | int x = (int)rect.origin.x; | |
94929e7b | 35 | if ( parent == NULL || ![ parent isFlipped ] ) |
e490b0d2 VZ |
36 | y = (int)(frame.size.height - (rect.origin.y + rect.size.height)); |
37 | return wxRect( x, y, (int)rect.size.width, (int)rect.size.height ); | |
33e90275 SC |
38 | } |
39 | ||
40 | NSPoint wxToNSPoint( NSView* parent, const wxPoint& p ) | |
41 | { | |
42 | NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame]; | |
43 | int x = p.x ; | |
44 | int y = p.y; | |
94929e7b | 45 | if ( parent == NULL || ![ parent isFlipped ] ) |
e490b0d2 | 46 | y = (int)(frame.size.height - ( p.y )); |
33e90275 SC |
47 | return NSMakePoint(x, y); |
48 | } | |
49 | ||
50 | wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p ) | |
51 | { | |
52 | NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame]; | |
e490b0d2 VZ |
53 | int x = (int)p.x; |
54 | int y = (int)p.y; | |
94929e7b | 55 | if ( parent == NULL || ![ parent isFlipped ] ) |
e490b0d2 | 56 | y = (int)(frame.size.height - ( p.y )); |
33e90275 SC |
57 | return wxPoint( x, y); |
58 | } | |
59 | ||
46f573dc KO |
60 | bool shouldHandleSelector(SEL selector) |
61 | { | |
03647350 | 62 | if (selector == @selector(noop:) |
46f573dc KO |
63 | || selector == @selector(complete:) |
64 | || selector == @selector(deleteBackward:) | |
65 | || selector == @selector(deleteForward:) | |
66 | || selector == @selector(insertNewline:) | |
67 | || selector == @selector(insertTab:) | |
68 | || selector == @selector(keyDown:) | |
69 | || selector == @selector(keyUp:) | |
70 | || selector == @selector(scrollPageUp:) | |
71 | || selector == @selector(scrollPageDown:) | |
72 | || selector == @selector(scrollToBeginningOfDocument:) | |
73 | || selector == @selector(scrollToEndOfDocument:)) | |
74 | return false; | |
03647350 | 75 | |
46f573dc KO |
76 | return true; |
77 | ||
78 | } | |
79 | ||
dbeddfb9 | 80 | // |
e17ac396 | 81 | // wx category for NSWindow (our own and wrapped instances) |
dbeddfb9 SC |
82 | // |
83 | ||
e17ac396 SC |
84 | @interface NSWindow (wxNSWindowSupport) |
85 | ||
86 | - (wxNonOwnedWindowCocoaImpl*) WX_implementation; | |
87 | ||
88 | - (bool) WX_filterSendEvent:(NSEvent *) event; | |
89 | ||
90 | @end | |
91 | ||
92 | @implementation NSWindow (wxNSWindowSupport) | |
93 | ||
94 | - (wxNonOwnedWindowCocoaImpl*) WX_implementation | |
95 | { | |
96 | return (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self ); | |
97 | } | |
98 | ||
99 | // TODO in cocoa everything during a drag is sent to the NSWindow the mouse down occured, | |
100 | // this does not conform to the wx behaviour if the window is not captured, so try to resend | |
101 | // or capture all wx mouse event handling at the tlw as we did for carbon | |
102 | ||
103 | - (bool) WX_filterSendEvent:(NSEvent *) event | |
104 | { | |
105 | bool handled = false; | |
106 | if ( ([event type] >= NSLeftMouseDown) && ([event type] <= NSMouseExited) ) | |
107 | { | |
108 | wxWindow* cw = wxWindow::GetCapture(); | |
109 | if ( cw != NULL ) | |
110 | { | |
111 | ((wxWidgetCocoaImpl*)cw->GetPeer())->DoHandleMouseEvent( event); | |
112 | handled = true; | |
113 | } | |
114 | } | |
115 | return handled; | |
116 | } | |
117 | @end | |
118 | ||
119 | // | |
120 | // wx native implementation | |
121 | // | |
9130dfd7 | 122 | |
dbeddfb9 | 123 | @interface wxNSWindow : NSWindow |
dbeddfb9 | 124 | { |
dbeddfb9 SC |
125 | } |
126 | ||
e17ac396 | 127 | - (void) sendEvent:(NSEvent *)event; |
0bcac6c7 | 128 | - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen; |
9130dfd7 | 129 | - (void)noResponderFor: (SEL) selector; |
dbeddfb9 SC |
130 | @end |
131 | ||
132 | @implementation wxNSWindow | |
133 | ||
e17ac396 SC |
134 | - (void)sendEvent:(NSEvent *) event |
135 | { | |
136 | if ( ![self WX_filterSendEvent: event] ) | |
137 | [super sendEvent: event]; | |
138 | } | |
139 | ||
0bcac6c7 KO |
140 | // The default implementation always moves the window back onto the screen, |
141 | // even when the programmer explicitly wants to hide it. | |
142 | - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen | |
143 | { | |
219665bb | 144 | wxUnusedVar(screen); |
0bcac6c7 KO |
145 | return frameRect; |
146 | } | |
147 | ||
46f573dc KO |
148 | - (void)doCommandBySelector:(SEL)selector |
149 | { | |
03647350 | 150 | if (shouldHandleSelector(selector) && |
46f573dc KO |
151 | !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) ) |
152 | [super doCommandBySelector:selector]; | |
153 | } | |
154 | ||
155 | ||
9130dfd7 KO |
156 | // NB: if we don't do this, all key downs that get handled lead to a NSBeep |
157 | - (void)noResponderFor: (SEL) selector | |
158 | { | |
46f573dc | 159 | if (selector != @selector(keyDown:) && selector != @selector(keyUp:)) |
9130dfd7 | 160 | { |
20ede392 | 161 | [super noResponderFor:selector]; |
9130dfd7 KO |
162 | } |
163 | } | |
dbeddfb9 | 164 | |
2c3ce6c4 KO |
165 | // We need this for borderless windows, i.e. shaped windows or windows without |
166 | // a title bar. For more info, see: | |
167 | // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html | |
168 | - (BOOL)canBecomeKeyWindow | |
169 | { | |
170 | return YES; | |
171 | } | |
172 | ||
dbeddfb9 SC |
173 | @end |
174 | ||
bb839504 | 175 | @interface wxNSPanel : NSPanel |
dbeddfb9 SC |
176 | { |
177 | } | |
178 | ||
9130dfd7 | 179 | - (void)noResponderFor: (SEL) selector; |
e17ac396 | 180 | - (void)sendEvent:(NSEvent *)event; |
dbeddfb9 SC |
181 | @end |
182 | ||
03647350 | 183 | @implementation wxNSPanel |
dbeddfb9 | 184 | |
09a9eb20 KO |
185 | - (BOOL)canBecomeKeyWindow |
186 | { | |
187 | return YES; | |
188 | } | |
189 | ||
46f573dc KO |
190 | - (void)doCommandBySelector:(SEL)selector |
191 | { | |
192 | if (shouldHandleSelector(selector)) | |
193 | [super doCommandBySelector:selector]; | |
194 | } | |
195 | ||
196 | // NB: if we don't do this, it seems that all events that end here lead to a NSBeep | |
9130dfd7 KO |
197 | - (void)noResponderFor: (SEL) selector |
198 | { | |
46f573dc | 199 | if (selector != @selector(keyDown:) && selector != @selector(keyUp:)) |
9130dfd7 | 200 | { |
20ede392 | 201 | [super noResponderFor:selector]; |
9130dfd7 KO |
202 | } |
203 | } | |
204 | ||
e17ac396 SC |
205 | - (void)sendEvent:(NSEvent *) event |
206 | { | |
207 | if ( ![self WX_filterSendEvent: event] ) | |
208 | [super sendEvent: event]; | |
209 | } | |
210 | ||
dbeddfb9 SC |
211 | @end |
212 | ||
213 | ||
214 | // | |
215 | // controller | |
216 | // | |
217 | ||
c8fdb345 | 218 | @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>) |
dbeddfb9 SC |
219 | { |
220 | } | |
221 | ||
222 | - (void)windowDidResize:(NSNotification *)notification; | |
223 | - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; | |
09a9eb20 KO |
224 | - (void)windowDidResignKey:(NSNotification *)notification; |
225 | - (void)windowDidBecomeKey:(NSNotification *)notification; | |
dbeddfb9 SC |
226 | - (void)windowDidMove:(NSNotification *)notification; |
227 | - (BOOL)windowShouldClose:(id)window; | |
1232607d | 228 | - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame; |
dbeddfb9 SC |
229 | |
230 | @end | |
231 | ||
232 | @implementation wxNonOwnedWindowController | |
233 | ||
234 | - (id) init | |
235 | { | |
236 | [super init]; | |
237 | return self; | |
238 | } | |
239 | ||
240 | - (BOOL)windowShouldClose:(id)nwindow | |
241 | { | |
e17ac396 | 242 | wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation]; |
dbeddfb9 SC |
243 | if ( windowimpl ) |
244 | { | |
245 | wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer(); | |
246 | if ( wxpeer ) | |
247 | wxpeer->Close(); | |
248 | } | |
249 | return NO; | |
250 | } | |
251 | ||
e17ac396 | 252 | - (NSSize)windowWillResize:(NSWindow *)window |
dbeddfb9 SC |
253 | toSize:(NSSize)proposedFrameSize |
254 | { | |
e17ac396 | 255 | NSRect frame = [window frame]; |
5da125c7 | 256 | wxRect wxframe = wxFromNSRect( NULL, frame ); |
e490b0d2 VZ |
257 | wxframe.SetWidth( (int)proposedFrameSize.width ); |
258 | wxframe.SetHeight( (int)proposedFrameSize.height ); | |
e17ac396 SC |
259 | |
260 | wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation]; | |
5da125c7 SC |
261 | if ( windowimpl ) |
262 | { | |
263 | wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer(); | |
264 | if ( wxpeer ) | |
265 | { | |
266 | wxpeer->HandleResizing( 0, &wxframe ); | |
267 | NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight()); | |
268 | return newSize; | |
269 | } | |
270 | } | |
271 | ||
dbeddfb9 SC |
272 | return proposedFrameSize; |
273 | } | |
274 | ||
275 | - (void)windowDidResize:(NSNotification *)notification | |
276 | { | |
e17ac396 SC |
277 | NSWindow* window = (NSWindow*) [notification object]; |
278 | wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation]; | |
dbeddfb9 SC |
279 | if ( windowimpl ) |
280 | { | |
281 | wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer(); | |
282 | if ( wxpeer ) | |
283 | wxpeer->HandleResized(0); | |
284 | } | |
285 | } | |
286 | ||
287 | - (void)windowDidMove:(NSNotification *)notification | |
288 | { | |
289 | wxNSWindow* window = (wxNSWindow*) [notification object]; | |
e17ac396 | 290 | wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation]; |
dbeddfb9 SC |
291 | if ( windowimpl ) |
292 | { | |
293 | wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer(); | |
294 | if ( wxpeer ) | |
295 | wxpeer->HandleMoved(0); | |
296 | } | |
297 | } | |
298 | ||
09a9eb20 | 299 | - (void)windowDidBecomeKey:(NSNotification *)notification |
dbeddfb9 | 300 | { |
e17ac396 SC |
301 | NSWindow* window = (NSWindow*) [notification object]; |
302 | wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation]; | |
dbeddfb9 SC |
303 | if ( windowimpl ) |
304 | { | |
305 | wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer(); | |
306 | if ( wxpeer ) | |
307 | wxpeer->HandleActivated(0, true); | |
308 | } | |
309 | } | |
310 | ||
09a9eb20 | 311 | - (void)windowDidResignKey:(NSNotification *)notification |
dbeddfb9 | 312 | { |
e17ac396 SC |
313 | NSWindow* window = (NSWindow*) [notification object]; |
314 | wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation]; | |
dbeddfb9 SC |
315 | if ( windowimpl ) |
316 | { | |
317 | wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer(); | |
318 | if ( wxpeer ) | |
09a9eb20 | 319 | { |
dbeddfb9 | 320 | wxpeer->HandleActivated(0, false); |
03647350 VZ |
321 | // Needed for popup window since the firstResponder |
322 | // (focus in wx) doesn't change when this | |
09a9eb20 KO |
323 | // TLW becomes inactive. |
324 | wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId()); | |
325 | event.SetEventObject(wxpeer); | |
326 | wxpeer->HandleWindowEvent(event); | |
327 | } | |
dbeddfb9 SC |
328 | } |
329 | } | |
330 | ||
7cb2a241 SC |
331 | - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject |
332 | { | |
333 | wxUnusedVar(sender); | |
334 | ||
335 | if ([anObject isKindOfClass:[wxNSTextField class]]) | |
336 | { | |
337 | wxNSTextField* tf = (wxNSTextField*) anObject; | |
338 | wxNSTextFieldEditor* editor = [tf fieldEditor]; | |
339 | if ( editor == nil ) | |
340 | { | |
341 | editor = [[wxNSTextFieldEditor alloc] init]; | |
342 | [editor setFieldEditor:YES]; | |
343 | [tf setFieldEditor:editor]; | |
344 | } | |
345 | return editor; | |
346 | } | |
347 | ||
348 | return nil; | |
349 | } | |
350 | ||
1232607d KO |
351 | - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame |
352 | { | |
e17ac396 SC |
353 | wxUnusedVar(newFrame); |
354 | wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation]; | |
1232607d KO |
355 | if ( windowimpl ) |
356 | { | |
357 | wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer(); | |
358 | wxMaximizeEvent event(wxpeer->GetId()); | |
359 | event.SetEventObject(wxpeer); | |
360 | return !wxpeer->HandleWindowEvent(event); | |
361 | } | |
362 | return true; | |
363 | } | |
364 | ||
dbeddfb9 SC |
365 | @end |
366 | ||
33e90275 SC |
367 | IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl ) |
368 | ||
03647350 | 369 | wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) : |
33e90275 SC |
370 | wxNonOwnedWindowImpl(nonownedwnd) |
371 | { | |
372 | m_macWindow = NULL; | |
373 | m_macFullScreenData = NULL; | |
374 | } | |
03647350 VZ |
375 | |
376 | wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl() | |
33e90275 SC |
377 | { |
378 | m_macWindow = NULL; | |
379 | m_macFullScreenData = NULL; | |
380 | } | |
03647350 | 381 | |
33e90275 SC |
382 | wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl() |
383 | { | |
17e2694c SC |
384 | if ( !m_wxPeer->IsNativeWindowWrapper() ) |
385 | { | |
17e2694c SC |
386 | [m_macWindow setDelegate:nil]; |
387 | [m_macWindow release]; | |
388 | } | |
33e90275 SC |
389 | } |
390 | ||
0aaa6ace | 391 | void wxNonOwnedWindowCocoaImpl::WillBeDestroyed() |
33e90275 | 392 | { |
17e2694c SC |
393 | if ( !m_wxPeer->IsNativeWindowWrapper() ) |
394 | { | |
395 | [m_macWindow setDelegate:nil]; | |
396 | } | |
33e90275 SC |
397 | } |
398 | ||
20ede392 SC |
399 | void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size, |
400 | long style, long extraStyle, const wxString& WXUNUSED(name) ) | |
33e90275 | 401 | { |
dbeddfb9 | 402 | static wxNonOwnedWindowController* controller = NULL; |
03647350 | 403 | |
dbeddfb9 SC |
404 | if ( !controller ) |
405 | controller =[[wxNonOwnedWindowController alloc] init]; | |
406 | ||
407 | ||
33e90275 | 408 | int windowstyle = NSBorderlessWindowMask; |
03647350 VZ |
409 | |
410 | if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) || | |
09a9eb20 KO |
411 | GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG ) |
412 | { | |
dbeddfb9 | 413 | m_macWindow = [wxNSPanel alloc]; |
09a9eb20 | 414 | } |
33e90275 | 415 | else |
dbeddfb9 | 416 | m_macWindow = [wxNSWindow alloc]; |
03647350 | 417 | |
e912ebe3 | 418 | CGWindowLevel level = kCGNormalWindowLevel; |
03647350 | 419 | |
33e90275 SC |
420 | if ( style & wxFRAME_TOOL_WINDOW ) |
421 | { | |
aa960026 KO |
422 | windowstyle |= NSUtilityWindowMask; |
423 | if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) || | |
424 | ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) ) | |
425 | { | |
426 | windowstyle |= NSTitledWindowMask ; | |
427 | } | |
33e90275 SC |
428 | } |
429 | else if ( ( style & wxPOPUP_WINDOW ) ) | |
430 | { | |
431 | level = kCGPopUpMenuWindowLevel; | |
432 | /* | |
433 | if ( ( style & wxBORDER_NONE ) ) | |
434 | { | |
435 | wclass = kHelpWindowClass ; // has no border | |
436 | attr |= kWindowNoShadowAttribute; | |
437 | } | |
438 | else | |
439 | { | |
440 | wclass = kPlainWindowClass ; // has a single line border, it will have to do for now | |
441 | } | |
442 | */ | |
443 | } | |
444 | else if ( ( style & wxCAPTION ) ) | |
445 | { | |
446 | windowstyle |= NSTitledWindowMask ; | |
447 | } | |
448 | else if ( ( style & wxFRAME_DRAWER ) ) | |
449 | { | |
450 | /* | |
451 | wclass = kDrawerWindowClass; | |
452 | */ | |
453 | } | |
454 | else | |
455 | { | |
456 | // set these even if we have no title, otherwise the controls won't be visible | |
457 | if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) || | |
458 | ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) ) | |
459 | { | |
460 | windowstyle |= NSTitledWindowMask ; | |
461 | } | |
462 | /* | |
463 | else if ( ( style & wxNO_BORDER ) ) | |
464 | { | |
465 | wclass = kSimpleWindowClass ; | |
466 | } | |
467 | else | |
468 | { | |
469 | wclass = kPlainWindowClass ; | |
470 | } | |
471 | */ | |
472 | } | |
473 | ||
474 | if ( windowstyle & NSTitledWindowMask ) | |
475 | { | |
476 | if ( ( style & wxMINIMIZE_BOX ) ) | |
477 | windowstyle |= NSMiniaturizableWindowMask ; | |
478 | ||
479 | if ( ( style & wxMAXIMIZE_BOX ) ) | |
480 | windowstyle |= NSResizableWindowMask ; // TODO showing ZOOM ? | |
481 | ||
482 | if ( ( style & wxRESIZE_BORDER ) ) | |
483 | windowstyle |= NSResizableWindowMask ; | |
484 | ||
485 | if ( ( style & wxCLOSE_BOX) ) | |
486 | windowstyle |= NSClosableWindowMask ; | |
487 | } | |
488 | if ( extraStyle & wxFRAME_EX_METAL) | |
489 | windowstyle |= NSTexturedBackgroundWindowMask; | |
490 | ||
bb839504 KO |
491 | if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) ) |
492 | level = kCGFloatingWindowLevel; | |
493 | ||
33e90275 SC |
494 | if ( ( style & wxSTAY_ON_TOP ) ) |
495 | level = kCGUtilityWindowLevel; | |
03647350 | 496 | |
33e90275 | 497 | NSRect r = wxToNSRect( NULL, wxRect( pos, size) ); |
03647350 | 498 | |
01639b08 | 499 | r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle]; |
03647350 | 500 | |
33e90275 SC |
501 | [m_macWindow initWithContentRect:r |
502 | styleMask:windowstyle | |
503 | backing:NSBackingStoreBuffered | |
03647350 | 504 | defer:NO |
33e90275 | 505 | ]; |
03647350 | 506 | |
33e90275 | 507 | [m_macWindow setLevel:level]; |
dbeddfb9 SC |
508 | |
509 | [m_macWindow setDelegate:controller]; | |
03647350 | 510 | |
826da451 | 511 | [m_macWindow setAcceptsMouseMovedEvents: YES]; |
b61b8371 SC |
512 | |
513 | if ( ( style & wxFRAME_SHAPED) ) | |
514 | { | |
515 | [m_macWindow setOpaque:NO]; | |
516 | [m_macWindow setAlphaValue:1.0]; | |
517 | } | |
33e90275 SC |
518 | } |
519 | ||
17e2694c SC |
520 | void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow ) |
521 | { | |
522 | m_macWindow = nativeWindow; | |
523 | } | |
33e90275 SC |
524 | |
525 | WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const | |
526 | { | |
527 | return m_macWindow; | |
528 | } | |
529 | ||
530 | void wxNonOwnedWindowCocoaImpl::Raise() | |
531 | { | |
532 | [m_macWindow orderWindow:NSWindowAbove relativeTo:0]; | |
533 | } | |
03647350 | 534 | |
33e90275 SC |
535 | void wxNonOwnedWindowCocoaImpl::Lower() |
536 | { | |
537 | [m_macWindow orderWindow:NSWindowBelow relativeTo:0]; | |
538 | } | |
539 | ||
dbc7ceb9 KO |
540 | void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating() |
541 | { | |
a029e98a | 542 | [m_macWindow orderFront:nil]; |
eabe8426 | 543 | [[m_macWindow contentView] setNeedsDisplay: YES]; |
dbc7ceb9 KO |
544 | } |
545 | ||
33e90275 SC |
546 | bool wxNonOwnedWindowCocoaImpl::Show(bool show) |
547 | { | |
548 | if ( show ) | |
549 | { | |
1f83c631 SC |
550 | wxNonOwnedWindow* wxpeer = GetWXPeer(); |
551 | if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW)) | |
dbc7ceb9 | 552 | [m_macWindow makeKeyAndOrderFront:nil]; |
1f83c631 SC |
553 | else |
554 | [m_macWindow orderFront:nil]; | |
eabe8426 | 555 | [[m_macWindow contentView] setNeedsDisplay: YES]; |
33e90275 | 556 | } |
03647350 | 557 | else |
33e90275 SC |
558 | [m_macWindow orderOut:nil]; |
559 | return true; | |
560 | } | |
03647350 | 561 | |
ab9a0b84 VZ |
562 | bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show, |
563 | wxShowEffect effect, | |
564 | unsigned timeout) | |
33e90275 | 565 | { |
ab9a0b84 VZ |
566 | return wxWidgetCocoaImpl:: |
567 | ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout); | |
33e90275 SC |
568 | } |
569 | ||
570 | void wxNonOwnedWindowCocoaImpl::Update() | |
571 | { | |
572 | [m_macWindow displayIfNeeded]; | |
573 | } | |
574 | ||
575 | bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha) | |
576 | { | |
577 | [m_macWindow setAlphaValue:(CGFloat) alpha/255.0]; | |
578 | return true; | |
579 | } | |
580 | ||
20ede392 | 581 | bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& WXUNUSED(col) ) |
33e90275 SC |
582 | { |
583 | return true; | |
584 | } | |
585 | ||
586 | void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle ) | |
587 | { | |
588 | if ( m_macWindow ) | |
589 | { | |
590 | bool metal = exStyle & wxFRAME_EX_METAL ; | |
591 | int windowStyle = [ m_macWindow styleMask]; | |
592 | if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) ) | |
593 | { | |
9a83f860 | 594 | wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") ); |
33e90275 SC |
595 | } |
596 | else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) ) | |
597 | { | |
9a83f860 | 598 | wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") ); |
03647350 | 599 | } |
33e90275 SC |
600 | } |
601 | } | |
03647350 | 602 | |
b6dc21e7 KO |
603 | void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style ) |
604 | { | |
605 | if (m_macWindow) | |
606 | { | |
607 | CGWindowLevel level = kCGNormalWindowLevel; | |
608 | ||
609 | if (style & wxSTAY_ON_TOP) | |
610 | level = kCGUtilityWindowLevel; | |
611 | else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW )) | |
612 | level = kCGFloatingWindowLevel; | |
613 | ||
614 | [m_macWindow setLevel: level]; | |
615 | } | |
616 | } | |
617 | ||
eabe8426 | 618 | bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style) |
33e90275 | 619 | { |
eabe8426 KO |
620 | if ( style == wxBG_STYLE_TRANSPARENT ) |
621 | { | |
622 | [m_macWindow setOpaque:NO]; | |
623 | [m_macWindow setBackgroundColor:[NSColor clearColor]]; | |
624 | } | |
625 | ||
33e90275 SC |
626 | return true; |
627 | } | |
03647350 | 628 | |
33e90275 SC |
629 | bool wxNonOwnedWindowCocoaImpl::CanSetTransparent() |
630 | { | |
631 | return true; | |
632 | } | |
633 | ||
634 | void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height) | |
635 | { | |
636 | NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) ); | |
54f11060 SC |
637 | // do not trigger refreshes upon invisible and possible partly created objects |
638 | [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()]; | |
33e90275 SC |
639 | } |
640 | ||
641 | void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const | |
642 | { | |
643 | wxRect r = wxFromNSRect( NULL, [m_macWindow frame] ); | |
644 | x = r.GetLeft(); | |
645 | y = r.GetTop(); | |
646 | } | |
647 | ||
648 | void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const | |
649 | { | |
650 | NSRect rect = [m_macWindow frame]; | |
e490b0d2 VZ |
651 | width = (int)rect.size.width; |
652 | height = (int)rect.size.height; | |
33e90275 SC |
653 | } |
654 | ||
b0ec7fbb | 655 | void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const |
33e90275 SC |
656 | { |
657 | NSRect outer = NSMakeRect(100,100,100,100); | |
658 | NSRect content = [NSWindow contentRectForFrameRect:outer styleMask:[m_macWindow styleMask] ]; | |
659 | NSRect rect = [[m_macWindow contentView] frame]; | |
e490b0d2 VZ |
660 | left = (int)rect.origin.x; |
661 | top = (int)rect.origin.y; | |
662 | width = (int)rect.size.width; | |
663 | height = (int)rect.size.height; | |
33e90275 | 664 | } |
03647350 | 665 | |
20ede392 | 666 | bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region)) |
33e90275 | 667 | { |
eabe8426 KO |
668 | [m_macWindow setOpaque:NO]; |
669 | [m_macWindow setBackgroundColor:[NSColor clearColor]]; | |
670 | ||
671 | return true; | |
33e90275 SC |
672 | } |
673 | ||
03647350 | 674 | void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding ) |
33e90275 SC |
675 | { |
676 | [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()]; | |
677 | } | |
03647350 | 678 | |
33e90275 SC |
679 | bool wxNonOwnedWindowCocoaImpl::IsMaximized() const |
680 | { | |
cbe06760 VZ |
681 | if (([m_macWindow styleMask] & NSResizableWindowMask) != 0) |
682 | { | |
683 | return [m_macWindow isZoomed]; | |
684 | } | |
685 | else | |
686 | { | |
687 | NSRect rectScreen = [[NSScreen mainScreen] visibleFrame]; | |
688 | NSRect rectWindow = [m_macWindow frame]; | |
689 | return (rectScreen.origin.x == rectWindow.origin.x && | |
690 | rectScreen.origin.y == rectWindow.origin.y && | |
691 | rectScreen.size.width == rectWindow.size.width && | |
692 | rectScreen.size.height == rectWindow.size.height); | |
693 | } | |
33e90275 | 694 | } |
03647350 | 695 | |
33e90275 SC |
696 | bool wxNonOwnedWindowCocoaImpl::IsIconized() const |
697 | { | |
698 | return [m_macWindow isMiniaturized]; | |
699 | } | |
03647350 | 700 | |
33e90275 SC |
701 | void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize ) |
702 | { | |
703 | if ( iconize ) | |
704 | [m_macWindow miniaturize:nil]; | |
705 | else | |
706 | [m_macWindow deminiaturize:nil]; | |
707 | } | |
03647350 | 708 | |
20ede392 | 709 | void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize)) |
33e90275 SC |
710 | { |
711 | [m_macWindow zoom:nil]; | |
712 | } | |
03647350 | 713 | |
33e90275 SC |
714 | |
715 | // http://cocoadevcentral.com/articles/000028.php | |
716 | ||
717 | typedef struct | |
718 | { | |
719 | int m_formerLevel; | |
720 | NSRect m_formerFrame; | |
721 | } FullScreenData ; | |
722 | ||
723 | bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const | |
724 | { | |
725 | return m_macFullScreenData != NULL ; | |
726 | } | |
03647350 | 727 | |
20ede392 | 728 | bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style)) |
33e90275 SC |
729 | { |
730 | if ( show ) | |
731 | { | |
732 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; | |
733 | delete data ; | |
734 | data = new FullScreenData(); | |
735 | ||
736 | m_macFullScreenData = data ; | |
737 | data->m_formerLevel = [m_macWindow level]; | |
738 | data->m_formerFrame = [m_macWindow frame]; | |
739 | CGDisplayCapture( kCGDirectMainDisplay ); | |
740 | [m_macWindow setLevel:CGShieldingWindowLevel()]; | |
741 | [m_macWindow setFrame:[[NSScreen mainScreen] frame] display:YES]; | |
742 | } | |
743 | else if ( m_macFullScreenData != NULL ) | |
744 | { | |
745 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
746 | CGDisplayRelease( kCGDirectMainDisplay ); | |
747 | [m_macWindow setLevel:data->m_formerLevel]; | |
748 | [m_macWindow setFrame:data->m_formerFrame display:YES]; | |
749 | delete data ; | |
750 | m_macFullScreenData = NULL ; | |
751 | } | |
03647350 | 752 | |
33e90275 SC |
753 | return true; |
754 | } | |
755 | ||
32b8e701 | 756 | void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX) |
33e90275 | 757 | { |
98182acc | 758 | NSRequestUserAttentionType flagsOSX; |
32b8e701 VZ |
759 | switch ( flagsWX ) |
760 | { | |
761 | case wxUSER_ATTENTION_INFO: | |
762 | flagsOSX = NSInformationalRequest; | |
763 | break; | |
764 | ||
765 | case wxUSER_ATTENTION_ERROR: | |
766 | flagsOSX = NSCriticalRequest; | |
767 | break; | |
768 | ||
769 | default: | |
770 | wxFAIL_MSG( "invalid RequestUserAttention() flags" ); | |
771 | return; | |
772 | } | |
773 | ||
774 | [NSApp requestUserAttention:flagsOSX]; | |
33e90275 | 775 | } |
dbeddfb9 SC |
776 | |
777 | void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y ) | |
778 | { | |
779 | wxPoint p((x ? *x : 0), (y ? *y : 0) ); | |
dbeddfb9 | 780 | NSPoint nspt = wxToNSPoint( NULL, p ); |
54f11060 SC |
781 | nspt = [m_macWindow convertScreenToBase:nspt]; |
782 | nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil]; | |
783 | p = wxFromNSPoint([m_macWindow contentView], nspt); | |
dbeddfb9 | 784 | if ( x ) |
03647350 | 785 | *x = p.x; |
dbeddfb9 SC |
786 | if ( y ) |
787 | *y = p.y; | |
788 | } | |
789 | ||
790 | void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y ) | |
791 | { | |
54f11060 SC |
792 | wxPoint p((x ? *x : 0), (y ? *y : 0) ); |
793 | NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p ); | |
794 | nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil]; | |
795 | nspt = [m_macWindow convertBaseToScreen:nspt]; | |
796 | p = wxFromNSPoint( NULL, nspt); | |
dbeddfb9 SC |
797 | if ( x ) |
798 | *x = p.x; | |
799 | if ( y ) | |
800 | *y = p.y; | |
801 | } | |
802 | ||
dbc7ceb9 KO |
803 | bool wxNonOwnedWindowCocoaImpl::IsActive() |
804 | { | |
805 | return [m_macWindow isKeyWindow]; | |
806 | } | |
807 | ||
efb2fa41 KO |
808 | void wxNonOwnedWindowCocoaImpl::SetModified(bool modified) |
809 | { | |
810 | [m_macWindow setDocumentEdited:modified]; | |
811 | } | |
812 | ||
ebf7d5c4 | 813 | bool wxNonOwnedWindowCocoaImpl::IsModified() const |
efb2fa41 KO |
814 | { |
815 | return [m_macWindow isDocumentEdited]; | |
816 | } | |
817 | ||
17e2694c SC |
818 | wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow) |
819 | { | |
820 | wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer ); | |
821 | now->Create( parent, nativeWindow ); | |
822 | return now; | |
823 | } | |
824 | ||
dbeddfb9 SC |
825 | wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, |
826 | long style, long extraStyle, const wxString& name ) | |
827 | { | |
828 | wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer ); | |
829 | now->Create( parent, pos, size, style , extraStyle, name ); | |
830 | return now; | |
54f11060 | 831 | } |