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