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