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