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