1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/window.mm
3 // Purpose: widgets (non tlw) for cocoa
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: window.mm 48805 2007-09-19 14:52:25Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/dcclient.h"
16 #include "wx/nonownedwnd.h"
21 #include "wx/osx/private.h"
28 #if wxUSE_DRAG_AND_DROP
32 #include <objc/objc-runtime.h>
34 // Get the window with the focus
36 WXWidget wxWidgetImpl::FindFocus()
38 NSView* focusedView = nil;
39 NSWindow* keyWindow = [[NSApplication sharedApplication] keyWindow];
40 if ( keyWindow != nil )
42 NSResponder* responder = [keyWindow firstResponder];
43 if ( [responder isKindOfClass:[NSTextView class]] &&
44 [keyWindow fieldEditor:NO forObject:nil] != nil )
46 focusedView = [(NSTextView*)responder delegate];
50 if ( [responder isKindOfClass:[NSView class]] )
51 focusedView = (NSView*) responder;
57 NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
61 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
62 wxRect bounds(x,y,w,h);
63 NSView* sv = (window->GetParent()->GetHandle() );
65 return wxToNSRect( sv, bounds );
68 @interface wxNSView : NSView
70 NSTrackingRectTag rectTag;
73 // the tracking tag is needed to track mouse enter / exit events
74 - (void) setTrackingTag: (NSTrackingRectTag)tag;
75 - (NSTrackingRectTag) trackingTag;
78 @interface NSView(PossibleMethods)
79 - (void)setTitle:(NSString *)aString;
80 - (void)setStringValue:(NSString *)aString;
81 - (void)setIntValue:(int)anInt;
82 - (void)setFloatValue:(float)aFloat;
83 - (void)setDoubleValue:(double)aDouble;
87 - (void)setMinValue:(double)aDouble;
88 - (void)setMaxValue:(double)aDouble;
93 - (void)setEnabled:(BOOL)flag;
95 - (void)setImage:(NSImage *)image;
96 - (void)setControlSize:(NSControlSize)size;
98 - (void)setFont:(NSFont *)fontObject;
102 - (void)setTarget:(id)anObject;
103 - (void)setAction:(SEL)aSelector;
104 - (void)setDoubleAction:(SEL)aSelector;
107 long wxOSXTranslateCocoaKey( NSEvent* event )
111 if ([event type] != NSFlagsChanged)
113 NSString* s = [event charactersIgnoringModifiers];
114 // backspace char reports as delete w/modifiers for some reason
117 switch ( [s characterAtIndex:0] )
124 case NSUpArrowFunctionKey :
127 case NSDownArrowFunctionKey :
130 case NSLeftArrowFunctionKey :
133 case NSRightArrowFunctionKey :
136 case NSInsertFunctionKey :
139 case NSDeleteFunctionKey :
142 case NSHomeFunctionKey :
145 // case NSBeginFunctionKey :
146 // retval = WXK_BEGIN;
148 case NSEndFunctionKey :
151 case NSPageUpFunctionKey :
154 case NSPageDownFunctionKey :
155 retval = WXK_PAGEDOWN;
157 case NSHelpFunctionKey :
161 int intchar = [s characterAtIndex: 0];
162 if ( intchar >= NSF1FunctionKey && intchar <= NSF24FunctionKey )
163 retval = WXK_F1 + (intchar - NSF1FunctionKey );
169 // Some keys don't seem to have constants. The code mimics the approach
170 // taken by WebKit. See:
171 // http://trac.webkit.org/browser/trunk/WebCore/platform/mac/KeyEventMac.mm
172 switch( [event keyCode] )
177 retval = WXK_COMMAND;
181 retval = WXK_CAPITAL;
184 case 56: // Left Shift
185 case 60: // Right Shift
190 case 61: // Right Alt
194 case 59: // Left Ctrl
195 case 62: // Right Ctrl
196 retval = WXK_CONTROL;
213 void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charString = NULL )
215 UInt32 modifiers = [nsEvent modifierFlags] ;
216 int eventType = [nsEvent type];
218 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
219 wxevent.m_controlDown = modifiers & NSControlKeyMask;
220 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
221 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
223 wxevent.m_rawCode = [nsEvent keyCode];
224 wxevent.m_rawFlags = modifiers;
226 wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
230 wxevent.SetEventType( wxEVT_KEY_DOWN ) ;
233 wxevent.SetEventType( wxEVT_KEY_UP ) ;
235 case NSFlagsChanged :
236 // setup common code here
243 if ( eventType != NSFlagsChanged )
245 NSString* nschars = [nsEvent characters];
248 // if charString is set, it did not come from key up / key down
249 wxevent.SetEventType( wxEVT_CHAR );
250 wxCFStringRef cfchars((CFStringRef)[charString retain]);
251 chars = cfchars.AsString();
255 wxCFStringRef cfchars((CFStringRef)[nschars retain]);
256 chars = cfchars.AsString();
260 int aunichar = chars.Length() > 0 ? chars[0] : 0;
263 if (wxevent.GetEventType() != wxEVT_CHAR)
264 keyval = wxOSXTranslateCocoaKey(nsEvent) ;
268 if ( wxevent.GetEventType() == wxEVT_KEY_UP || wxevent.GetEventType() == wxEVT_KEY_DOWN )
269 keyval = wxToupper( aunichar ) ;
275 wxevent.m_uniChar = aunichar;
277 wxevent.m_keyCode = keyval;
280 UInt32 g_lastButton = 0 ;
281 bool g_lastButtonWasFakeRight = false ;
283 void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
285 int eventType = [nsEvent type];
286 UInt32 modifiers = [nsEvent modifierFlags] ;
287 wxPoint screenMouseLocation = wxFromNSPoint( NULL, [nsEvent locationInWindow]);
289 // these parameters are not given for all events
290 UInt32 button = [nsEvent buttonNumber];
291 UInt32 clickCount = 0;
293 wxevent.m_x = screenMouseLocation.x;
294 wxevent.m_y = screenMouseLocation.y;
295 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
296 wxevent.m_controlDown = modifiers & NSControlKeyMask;
297 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
298 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
299 wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
301 UInt32 mouseChord = 0;
305 case NSLeftMouseDown :
306 case NSLeftMouseDragged :
309 case NSRightMouseDown :
310 case NSRightMouseDragged :
313 case NSOtherMouseDown :
314 case NSOtherMouseDragged :
319 // a control click is interpreted as a right click
320 bool thisButtonIsFakeRight = false ;
321 if ( button == 0 && (modifiers & NSControlKeyMask) )
324 thisButtonIsFakeRight = true ;
327 // otherwise we report double clicks by connecting a left click with a ctrl-left click
328 if ( clickCount > 1 && button != g_lastButton )
331 // we must make sure that our synthetic 'right' button corresponds in
332 // mouse down, moved and mouse up, and does not deliver a right down and left up
335 case NSLeftMouseDown :
336 case NSRightMouseDown :
337 case NSOtherMouseDown :
338 g_lastButton = button ;
339 g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
346 g_lastButtonWasFakeRight = false ;
348 else if ( g_lastButton == 1 && g_lastButtonWasFakeRight )
349 button = g_lastButton ;
351 // Adjust the chord mask to remove the primary button and add the
352 // secondary button. It is possible that the secondary button is
353 // already pressed, e.g. on a mouse connected to a laptop, but this
354 // possibility is ignored here:
355 if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
356 mouseChord = ((mouseChord & ~1U) | 2U);
359 wxevent.m_leftDown = true ;
361 wxevent.m_rightDown = true ;
363 wxevent.m_middleDown = true ;
365 // translate into wx types
368 case NSLeftMouseDown :
369 case NSRightMouseDown :
370 case NSOtherMouseDown :
371 clickCount = [nsEvent clickCount];
375 wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
379 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
383 wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
392 case NSRightMouseUp :
393 case NSOtherMouseUp :
394 clickCount = [nsEvent clickCount];
398 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
402 wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
406 wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
416 wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
417 wxevent.m_wheelDelta = 10;
418 wxevent.m_linesPerAction = 1;
419 NSLog(@"deltaX %f, deltaY %f",[nsEvent deltaX], [nsEvent deltaY]);
420 if ( abs([nsEvent deltaX]) > abs([nsEvent deltaY]) )
422 wxevent.m_wheelAxis = 1;
423 wxevent.m_wheelRotation = [nsEvent deltaX] * 10.0;
427 wxevent.m_wheelRotation = [nsEvent deltaY] * 10.0;
432 case NSMouseEntered :
433 wxevent.SetEventType( wxEVT_ENTER_WINDOW ) ;
436 wxevent.SetEventType( wxEVT_LEAVE_WINDOW ) ;
438 case NSLeftMouseDragged :
439 case NSRightMouseDragged :
440 case NSOtherMouseDragged :
442 wxevent.SetEventType( wxEVT_MOTION ) ;
448 wxevent.m_clickCount = clickCount;
452 @implementation wxNSView
456 static BOOL initialized = NO;
460 wxOSXCocoaClassAddWXMethods( self );
464 - (void) setTrackingTag: (NSTrackingRectTag)tag
469 - (NSTrackingRectTag) trackingTag
480 #if wxUSE_DRAG_AND_DROP
482 // see http://lists.apple.com/archives/Cocoa-dev/2005/Jul/msg01244.html
483 // for details on the NSPasteboard -> PasteboardRef conversion
485 NSDragOperation wxOSX_draggingEntered( id self, SEL _cmd, id <NSDraggingInfo>sender )
487 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
489 return NSDragOperationNone;
491 return impl->draggingEntered(sender, self, _cmd);
494 void wxOSX_draggingExited( id self, SEL _cmd, id <NSDraggingInfo> sender )
496 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
500 return impl->draggingExited(sender, self, _cmd);
503 NSDragOperation wxOSX_draggingUpdated( id self, SEL _cmd, id <NSDraggingInfo>sender )
505 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
507 return NSDragOperationNone;
509 return impl->draggingUpdated(sender, self, _cmd);
512 BOOL wxOSX_performDragOperation( id self, SEL _cmd, id <NSDraggingInfo> sender )
514 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
516 return NSDragOperationNone;
518 return impl->performDragOperation(sender, self, _cmd) ? YES:NO ;
521 void wxOSX_mouseEvent(NSView* self, SEL _cmd, NSEvent *event)
523 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
527 impl->mouseEvent(event, self, _cmd);
530 void wxOSX_keyEvent(NSView* self, SEL _cmd, NSEvent *event)
532 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
536 impl->keyEvent(event, self, _cmd);
539 void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text)
541 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
545 impl->insertText(text, self, _cmd);
548 BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event)
550 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
554 return impl->performKeyEquivalent(event, self, _cmd);
557 BOOL wxOSX_acceptsFirstResponder(NSView* self, SEL _cmd)
559 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
563 return impl->acceptsFirstResponder(self, _cmd);
566 BOOL wxOSX_becomeFirstResponder(NSView* self, SEL _cmd)
568 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
572 return impl->becomeFirstResponder(self, _cmd);
575 BOOL wxOSX_resignFirstResponder(NSView* self, SEL _cmd)
577 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
581 return impl->resignFirstResponder(self, _cmd);
584 void wxOSX_resetCursorRects(NSView* self, SEL _cmd)
586 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
590 impl->resetCursorRects(self, _cmd);
593 BOOL wxOSX_isFlipped(NSView* self, SEL _cmd)
595 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
599 return impl->isFlipped(self, _cmd) ? YES:NO;
602 void wxOSX_drawRect(NSView* self, SEL _cmd, NSRect rect)
604 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
608 return impl->drawRect(&rect, self, _cmd);
611 void wxOSX_controlAction(NSView* self, SEL _cmd, id sender)
613 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
617 impl->controlAction(self, _cmd, sender);
620 void wxOSX_controlDoubleAction(NSView* self, SEL _cmd, id sender)
622 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
626 impl->controlDoubleAction(self, _cmd, sender);
629 unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
631 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
632 NSPasteboard *pboard = [sender draggingPasteboard];
633 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
635 wxWindow* wxpeer = GetWXPeer();
636 if ( wxpeer == NULL )
637 return NSDragOperationNone;
639 wxDropTarget* target = wxpeer->GetDropTarget();
640 if ( target == NULL )
641 return NSDragOperationNone;
643 wxDragResult result = wxDragNone;
644 wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
646 if ( sourceDragMask & NSDragOperationLink )
648 else if ( sourceDragMask & NSDragOperationCopy )
650 else if ( sourceDragMask & NSDragOperationMove )
653 PasteboardRef pboardRef;
654 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
655 target->SetCurrentDragPasteboard(pboardRef);
656 result = target->OnEnter(pt.x, pt.y, result);
657 CFRelease(pboardRef);
659 NSDragOperation nsresult = NSDragOperationNone;
663 nsresult = NSDragOperationLink;
665 nsresult = NSDragOperationMove;
667 nsresult = NSDragOperationCopy;
674 void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
676 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
677 NSPasteboard *pboard = [sender draggingPasteboard];
679 wxWindow* wxpeer = GetWXPeer();
680 if ( wxpeer == NULL )
683 wxDropTarget* target = wxpeer->GetDropTarget();
684 if ( target == NULL )
687 PasteboardRef pboardRef;
688 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
689 target->SetCurrentDragPasteboard(pboardRef);
691 CFRelease(pboardRef);
694 unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
696 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
697 NSPasteboard *pboard = [sender draggingPasteboard];
698 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
700 wxWindow* wxpeer = GetWXPeer();
701 if ( wxpeer == NULL )
702 return NSDragOperationNone;
704 wxDropTarget* target = wxpeer->GetDropTarget();
705 if ( target == NULL )
706 return NSDragOperationNone;
708 wxDragResult result = wxDragNone;
709 wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
711 if ( sourceDragMask & NSDragOperationLink )
713 else if ( sourceDragMask & NSDragOperationCopy )
715 else if ( sourceDragMask & NSDragOperationMove )
718 PasteboardRef pboardRef;
719 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
720 target->SetCurrentDragPasteboard(pboardRef);
721 result = target->OnDragOver(pt.x, pt.y, result);
722 CFRelease(pboardRef);
724 NSDragOperation nsresult = NSDragOperationNone;
728 nsresult = NSDragOperationLink;
730 nsresult = NSDragOperationMove;
732 nsresult = NSDragOperationCopy;
739 bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
741 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
743 NSPasteboard *pboard = [sender draggingPasteboard];
744 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
746 wxWindow* wxpeer = GetWXPeer();
747 wxDropTarget* target = wxpeer->GetDropTarget();
748 wxDragResult result = wxDragNone;
749 wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
751 if ( sourceDragMask & NSDragOperationLink )
753 else if ( sourceDragMask & NSDragOperationCopy )
755 else if ( sourceDragMask & NSDragOperationMove )
758 PasteboardRef pboardRef;
759 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
760 target->SetCurrentDragPasteboard(pboardRef);
761 result = target->OnData(pt.x, pt.y, result);
762 CFRelease(pboardRef);
764 return result != wxDragNone;
769 typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
770 typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
771 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
772 typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
773 typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
774 typedef BOOL (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
776 void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
778 if ( !DoHandleMouseEvent(event) )
780 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
781 superimpl(slf, (SEL)_cmd, event);
785 void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
787 if ( [[slf window] firstResponder] != slf || !DoHandleKeyEvent(event) )
789 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
790 superimpl(slf, (SEL)_cmd, event);
794 void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
796 if (m_lastKeyDownEvent && !DoHandleCharEvent(m_lastKeyDownEvent, text) )
798 wxOSX_TextEventHandlerPtr superimpl = (wxOSX_TextEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
799 superimpl(slf, (SEL)_cmd, text);
801 m_lastKeyDownEvent = NULL;
805 bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
807 wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
808 return superimpl(slf, (SEL)_cmd, event);
811 bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
813 if ( m_wxPeer->MacIsUserPane() )
814 return m_wxPeer->AcceptsFocus();
817 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
818 return superimpl(slf, (SEL)_cmd);
822 bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
824 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
825 // get the current focus before running becomeFirstResponder
826 NSView* otherView = FindFocus();
827 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
828 BOOL r = superimpl(slf, (SEL)_cmd);
831 DoNotifyFocusEvent( true, otherWindow );
836 bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
838 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
839 BOOL r = superimpl(slf, (SEL)_cmd);
840 // get the current focus after running resignFirstResponder
841 NSView* otherView = FindFocus();
842 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
843 // NSTextViews have an editor as true responder, therefore the might get the
844 // resign notification if their editor takes over, don't trigger any event hen
845 if ( r && otherWindow != this)
847 DoNotifyFocusEvent( false, otherWindow );
852 void wxWidgetCocoaImpl::resetCursorRects(WXWidget slf, void *_cmd)
854 wxWindow* wxpeer = GetWXPeer();
857 NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();
860 wxOSX_ResetCursorRectsHandlerPtr superimpl = (wxOSX_ResetCursorRectsHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
861 superimpl(slf, (SEL)_cmd);
865 [slf addCursorRect: [slf bounds]
871 bool wxWidgetCocoaImpl::isFlipped(WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
877 #define OSX_DEBUG_DRAWING 0
879 void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
881 CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
882 CGContextSaveGState( context );
884 #if OSX_DEBUG_DRAWING
885 CGContextBeginPath( context );
886 CGContextMoveToPoint(context, 0, 0);
887 NSRect bounds = [self bounds];
888 CGContextAddLineToPoint(context, 10, 0);
889 CGContextMoveToPoint(context, 0, 0);
890 CGContextAddLineToPoint(context, 0, 10);
891 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
892 CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
893 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
894 CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
895 CGContextClosePath( context );
896 CGContextStrokePath(context);
901 CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
902 CGContextScaleCTM( context, 1, -1 );
909 [slf getRectsBeingDrawn:&rects count:&count];
910 for ( int i = 0 ; i < count ; ++i )
912 updateRgn.Union(wxFromNSRect(slf, rects[i]) );
915 wxWindow* wxpeer = GetWXPeer();
916 wxpeer->GetUpdateRegion() = updateRgn;
917 wxpeer->MacSetCGContextRef( context );
919 bool handled = wxpeer->MacDoRedraw( 0 );
921 CGContextRestoreGState( context );
923 CGContextSaveGState( context );
927 SEL _cmd = @selector(drawRect:);
928 wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
929 superimpl(slf, _cmd, *(NSRect*)rect);
930 CGContextRestoreGState( context );
931 CGContextSaveGState( context );
933 wxpeer->MacPaintChildrenBorders();
934 wxpeer->MacSetCGContextRef( NULL );
935 CGContextRestoreGState( context );
938 void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
940 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
942 wxpeer->OSXHandleClicked(0);
945 void wxWidgetCocoaImpl::controlDoubleAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
951 #if OBJC_API_VERSION >= 2
953 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
954 class_addMethod(c, s, i, t );
958 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
963 void wxOSXCocoaClassAddWXMethods(Class c)
966 #if OBJC_API_VERSION < 2
967 static objc_method wxmethods[] =
971 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
972 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
973 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
975 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
976 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
977 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
979 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseMoved:), (IMP) wxOSX_mouseEvent, "v@:@" )
981 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
982 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
983 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
985 wxOSX_CLASS_ADD_METHOD(c, @selector(scrollWheel:), (IMP) wxOSX_mouseEvent, "v@:@" )
986 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
987 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
989 wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
990 wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
991 wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
993 wxOSX_CLASS_ADD_METHOD(c, @selector(insertText:), (IMP) wxOSX_insertText, "v@:@" )
995 wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "v@:@" )
997 wxOSX_CLASS_ADD_METHOD(c, @selector(acceptsFirstResponder), (IMP) wxOSX_acceptsFirstResponder, "c@:" )
998 wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
999 wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
1000 wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
1002 wxOSX_CLASS_ADD_METHOD(c, @selector(isFlipped), (IMP) wxOSX_isFlipped, "c@:" )
1003 wxOSX_CLASS_ADD_METHOD(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}" )
1005 wxOSX_CLASS_ADD_METHOD(c, @selector(controlAction:), (IMP) wxOSX_controlAction, "v@:@" )
1006 wxOSX_CLASS_ADD_METHOD(c, @selector(controlDoubleAction:), (IMP) wxOSX_controlDoubleAction, "v@:@" )
1008 #if wxUSE_DRAG_AND_DROP
1009 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingEntered:), (IMP) wxOSX_draggingEntered, "I@:@" )
1010 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingUpdated:), (IMP) wxOSX_draggingUpdated, "I@:@" )
1011 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingExited:), (IMP) wxOSX_draggingExited, "v@:@" )
1012 wxOSX_CLASS_ADD_METHOD(c, @selector(performDragOperation:), (IMP) wxOSX_performDragOperation, "c@:@" )
1015 #if OBJC_API_VERSION < 2
1017 static int method_count = WXSIZEOF( wxmethods );
1018 static objc_method_list *wxmethodlist = NULL;
1019 if ( wxmethodlist == NULL )
1021 wxmethodlist = (objc_method_list*) malloc(sizeof(objc_method_list) + sizeof(wxmethods) );
1022 memcpy( &wxmethodlist->method_list[0], &wxmethods[0], sizeof(wxmethods) );
1023 wxmethodlist->method_count = method_count;
1024 wxmethodlist->obsolete = 0;
1026 class_addMethods( c, wxmethodlist );
1031 // C++ implementation class
1034 IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
1036 wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
1037 wxWidgetImpl( peer, isRootControl )
1043 wxWidgetCocoaImpl::wxWidgetCocoaImpl()
1048 void wxWidgetCocoaImpl::Init()
1052 m_lastKeyDownEvent = NULL;
1055 wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
1057 RemoveAssociations( this );
1059 if ( !IsRootControl() )
1061 NSView *sv = [m_osxView superview];
1063 [m_osxView removeFromSuperview];
1065 [m_osxView release];
1068 bool wxWidgetCocoaImpl::IsVisible() const
1070 return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
1073 void wxWidgetCocoaImpl::SetVisibility( bool visible )
1075 [m_osxView setHidden:(visible ? NO:YES)];
1078 void wxWidgetCocoaImpl::Raise()
1082 void wxWidgetCocoaImpl::Lower()
1086 void wxWidgetCocoaImpl::ScrollRect( const wxRect *WXUNUSED(rect), int WXUNUSED(dx), int WXUNUSED(dy) )
1091 // We should do something like this, but it wasn't working in 10.4.
1092 if (GetNeedsDisplay() )
1096 NSRect r = wxToNSRect( [m_osxView superview], *rect );
1097 NSSize offset = NSMakeSize((float)dx, (float)dy);
1098 [m_osxView scrollRect:r by:offset];
1102 void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
1104 wxWindowMac* parent = GetWXPeer()->GetParent();
1105 // under Cocoa we might have a contentView in the wxParent to which we have to
1106 // adjust the coordinates
1107 if (parent && [m_osxView superview] != parent->GetHandle() )
1109 int cx = 0,cy = 0,cw = 0,ch = 0;
1110 if ( parent->GetPeer() )
1112 parent->GetPeer()->GetContentArea(cx, cy, cw, ch);
1117 [[m_osxView superview] setNeedsDisplayInRect:[m_osxView frame]];
1118 NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
1119 [m_osxView setFrame:r];
1120 [[m_osxView superview] setNeedsDisplayInRect:r];
1122 if ([m_osxView respondsToSelector:@selector(trackingTag)] )
1124 if ( [(wxNSView*)m_osxView trackingTag] )
1125 [m_osxView removeTrackingRect: [(wxNSView*)m_osxView trackingTag]];
1127 [(wxNSView*)m_osxView setTrackingTag: [m_osxView addTrackingRect: [m_osxView bounds] owner: m_osxView userData: nil assumeInside: NO]];
1131 void wxWidgetCocoaImpl::GetPosition( int &x, int &y ) const
1133 wxRect r = wxFromNSRect( [m_osxView superview], [m_osxView frame] );
1138 void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
1140 NSRect rect = [m_osxView frame];
1141 width = rect.size.width;
1142 height = rect.size.height;
1145 void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
1147 if ( [m_osxView respondsToSelector:@selector(contentView) ] )
1149 NSView* cv = [m_osxView contentView];
1151 NSRect bounds = [m_osxView bounds];
1152 NSRect rect = [cv frame];
1154 int y = rect.origin.y;
1155 int x = rect.origin.x;
1156 if ( ![ m_osxView isFlipped ] )
1157 y = bounds.size.height - (rect.origin.y + rect.size.height);
1160 width = rect.size.width;
1161 height = rect.size.height;
1166 GetSize( width, height );
1170 void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
1173 [m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )];
1175 [m_osxView setNeedsDisplay:YES];
1178 bool wxWidgetCocoaImpl::GetNeedsDisplay() const
1180 return [m_osxView needsDisplay];
1183 bool wxWidgetCocoaImpl::CanFocus() const
1185 return [m_osxView canBecomeKeyView] == YES;
1188 bool wxWidgetCocoaImpl::HasFocus() const
1190 return ( FindFocus() == m_osxView );
1193 bool wxWidgetCocoaImpl::SetFocus()
1195 if ( [m_osxView canBecomeKeyView] == NO )
1198 [[m_osxView window] makeFirstResponder: m_osxView] ;
1203 void wxWidgetCocoaImpl::RemoveFromParent()
1205 [m_osxView removeFromSuperview];
1208 void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
1210 NSView* container = parent->GetWXWidget() ;
1211 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
1212 [container addSubview:m_osxView];
1215 void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
1217 // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
1220 void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
1222 if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
1224 wxCFStringRef cf( title , encoding );
1225 [m_osxView setTitle:cf.AsNSString()];
1227 else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
1229 wxCFStringRef cf( title , encoding );
1230 [m_osxView setStringValue:cf.AsNSString()];
1235 void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
1237 NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
1238 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
1239 *pt = wxFromNSPoint( to->GetWXWidget(), p );
1242 wxInt32 wxWidgetCocoaImpl::GetValue() const
1244 return [(NSControl*)m_osxView intValue];
1247 void wxWidgetCocoaImpl::SetValue( wxInt32 v )
1249 if ( [m_osxView respondsToSelector:@selector(setIntValue:)] )
1251 [m_osxView setIntValue:v];
1253 else if ( [m_osxView respondsToSelector:@selector(setFloatValue:)] )
1255 [m_osxView setFloatValue:(double)v];
1257 else if ( [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
1259 [m_osxView setDoubleValue:(double)v];
1263 void wxWidgetCocoaImpl::SetMinimum( wxInt32 v )
1265 if ( [m_osxView respondsToSelector:@selector(setMinValue:)] )
1267 [m_osxView setMinValue:(double)v];
1271 void wxWidgetCocoaImpl::SetMaximum( wxInt32 v )
1273 if ( [m_osxView respondsToSelector:@selector(setMaxValue:)] )
1275 [m_osxView setMaxValue:(double)v];
1279 wxInt32 wxWidgetCocoaImpl::GetMinimum() const
1281 if ( [m_osxView respondsToSelector:@selector(getMinValue:)] )
1283 return [m_osxView minValue];
1288 wxInt32 wxWidgetCocoaImpl::GetMaximum() const
1290 if ( [m_osxView respondsToSelector:@selector(getMaxValue:)] )
1292 return [m_osxView maxValue];
1297 void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
1299 if ( [m_osxView respondsToSelector:@selector(setImage:)] )
1301 [m_osxView setImage:bitmap.GetNSImage()];
1305 void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& WXUNUSED(notebook))
1307 // implementation in subclass
1310 void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
1312 r->x = r->y = r->width = r->height = 0;
1314 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
1316 NSRect former = [m_osxView frame];
1317 [m_osxView sizeToFit];
1318 NSRect best = [m_osxView frame];
1319 [m_osxView setFrame:former];
1320 r->width = best.size.width;
1321 r->height = best.size.height;
1325 bool wxWidgetCocoaImpl::IsEnabled() const
1327 if ( [m_osxView respondsToSelector:@selector(isEnabled) ] )
1328 return [m_osxView isEnabled];
1332 void wxWidgetCocoaImpl::Enable( bool enable )
1334 if ( [m_osxView respondsToSelector:@selector(setEnabled:) ] )
1335 [m_osxView setEnabled:enable];
1338 void wxWidgetCocoaImpl::PulseGauge()
1342 void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 WXUNUSED(val), wxInt32 WXUNUSED(view) )
1346 void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
1348 NSControlSize size = NSRegularControlSize;
1352 case wxWINDOW_VARIANT_NORMAL :
1353 size = NSRegularControlSize;
1356 case wxWINDOW_VARIANT_SMALL :
1357 size = NSSmallControlSize;
1360 case wxWINDOW_VARIANT_MINI :
1361 size = NSMiniControlSize;
1364 case wxWINDOW_VARIANT_LARGE :
1365 size = NSRegularControlSize;
1369 wxFAIL_MSG(_T("unexpected window variant"));
1372 if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
1373 [m_osxView setControlSize:size];
1376 void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
1378 if ([m_osxView respondsToSelector:@selector(setFont:)])
1379 [m_osxView setFont: font.OSXGetNSFont()];
1382 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
1384 WXWidget c = control ? control : (WXWidget) m_osxView;
1385 wxWidgetImpl::Associate( c, this ) ;
1386 if ([c respondsToSelector:@selector(setAction:)])
1389 [c setAction: @selector(controlAction:)];
1390 if ([c respondsToSelector:@selector(setDoubleAction:)])
1392 [c setDoubleAction: @selector(controlDoubleAction:)];
1398 bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
1400 wxKeyEvent wxevent(wxEVT_KEY_DOWN);
1401 SetupKeyEvent( wxevent, event, text );
1402 wxevent.SetEventObject(GetWXPeer());
1404 return GetWXPeer()->OSXHandleKeyEvent(wxevent);
1407 bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
1409 wxKeyEvent wxevent(wxEVT_KEY_DOWN);
1410 SetupKeyEvent( wxevent, event );
1411 wxevent.SetEventObject(GetWXPeer());
1412 bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
1414 // this will fire higher level events, like insertText, to help
1415 // us handle EVT_CHAR, etc.
1416 if ([event type] == NSKeyDown)
1418 m_lastKeyDownEvent = event;
1419 [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
1424 bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
1426 NSPoint clickLocation;
1427 clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil];
1428 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
1429 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
1430 SetupMouseEvent( wxevent , event ) ;
1431 wxevent.SetEventObject(GetWXPeer());
1435 return GetWXPeer()->HandleWindowEvent(wxevent);
1438 void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
1440 wxWindow* thisWindow = GetWXPeer();
1441 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
1443 thisWindow->MacInvalidateBorders();
1446 if ( receivedFocus )
1448 wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
1449 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
1450 thisWindow->HandleWindowEvent(eventFocus);
1453 if ( thisWindow->GetCaret() )
1454 thisWindow->GetCaret()->OnSetFocus();
1457 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
1458 event.SetEventObject(thisWindow);
1460 event.SetWindow(otherWindow->GetWXPeer());
1461 thisWindow->HandleWindowEvent(event) ;
1463 else // !receivedFocuss
1466 if ( thisWindow->GetCaret() )
1467 thisWindow->GetCaret()->OnKillFocus();
1470 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
1472 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
1473 event.SetEventObject(thisWindow);
1475 event.SetWindow(otherWindow->GetWXPeer());
1476 thisWindow->HandleWindowEvent(event) ;
1480 void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor)
1482 NSPoint location = [NSEvent mouseLocation];
1483 location = [[m_osxView window] convertScreenToBase:location];
1484 NSPoint locationInView = [m_osxView convertPoint:location fromView:nil];
1486 if( NSMouseInRect(locationInView, [m_osxView bounds], YES) )
1488 [(NSCursor*)cursor.GetHCURSOR() set];
1490 [[m_osxView window] invalidateCursorRectsForView:m_osxView];
1493 void wxWidgetCocoaImpl::CaptureMouse()
1495 [[m_osxView window] disableCursorRects];
1498 void wxWidgetCocoaImpl::ReleaseMouse()
1500 [[m_osxView window] enableCursorRects];
1503 void wxWidgetCocoaImpl::SetFlipped(bool flipped)
1505 m_isFlipped = flipped;
1512 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
1513 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
1514 long WXUNUSED(style), long WXUNUSED(extraStyle))
1516 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
1517 wxNSView* v = [[wxNSView alloc] initWithFrame:r];
1519 // temporary hook for dnd
1520 [v registerForDraggedTypes:[NSArray arrayWithObjects:
1521 NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
1523 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
1527 wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
1529 NSWindow* tlw = now->GetWXWindow();
1530 wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
1531 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
1532 c->InstallEventHandler();
1533 [tlw setContentView:v];