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;
208 retval = WXK_NUMPAD_DIVIDE;
211 retval = WXK_NUMPAD_MULTIPLY;
214 retval = WXK_NUMPAD_SUBTRACT;
217 retval = WXK_NUMPAD_ADD;
220 retval = WXK_NUMPAD_ENTER;
223 retval = WXK_NUMPAD_DECIMAL;
226 retval = WXK_NUMPAD0;
229 retval = WXK_NUMPAD1;
232 retval = WXK_NUMPAD2;
235 retval = WXK_NUMPAD3;
238 retval = WXK_NUMPAD4;
241 retval = WXK_NUMPAD5;
244 retval = WXK_NUMPAD6;
247 retval = WXK_NUMPAD7;
250 retval = WXK_NUMPAD8;
253 retval = WXK_NUMPAD9;
256 //retval = [event keyCode];
262 void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charString = NULL )
264 UInt32 modifiers = [nsEvent modifierFlags] ;
265 int eventType = [nsEvent type];
267 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
268 wxevent.m_controlDown = modifiers & NSControlKeyMask;
269 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
270 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
272 wxevent.m_rawCode = [nsEvent keyCode];
273 wxevent.m_rawFlags = modifiers;
275 wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
278 if ( eventType != NSFlagsChanged )
280 NSString* nschars = (wxevent.GetEventType() != wxEVT_CHAR) ? [nsEvent charactersIgnoringModifiers] : [nsEvent characters];
283 // if charString is set, it did not come from key up / key down
284 wxevent.SetEventType( wxEVT_CHAR );
285 wxCFStringRef cfchars((CFStringRef)[charString retain]);
286 chars = cfchars.AsString();
290 wxCFStringRef cfchars((CFStringRef)[nschars retain]);
291 chars = cfchars.AsString();
295 int aunichar = chars.Length() > 0 ? chars[0] : 0;
298 if (wxevent.GetEventType() != wxEVT_CHAR)
300 keyval = wxOSXTranslateCocoaKey(nsEvent) ;
304 wxevent.SetEventType( wxEVT_KEY_DOWN ) ;
307 wxevent.SetEventType( wxEVT_KEY_UP ) ;
309 case NSFlagsChanged :
313 wxevent.SetEventType( wxevent.m_controlDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
316 wxevent.SetEventType( wxevent.m_shiftDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
319 wxevent.SetEventType( wxevent.m_altDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
322 wxevent.SetEventType( wxevent.m_metaDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
333 if ( wxevent.GetEventType() == wxEVT_KEY_UP || wxevent.GetEventType() == wxEVT_KEY_DOWN )
334 keyval = wxToupper( aunichar ) ;
340 wxevent.m_uniChar = aunichar;
342 wxevent.m_keyCode = keyval;
345 UInt32 g_lastButton = 0 ;
346 bool g_lastButtonWasFakeRight = false ;
348 void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
350 int eventType = [nsEvent type];
351 UInt32 modifiers = [nsEvent modifierFlags] ;
352 wxPoint screenMouseLocation = wxFromNSPoint( NULL, [nsEvent locationInWindow]);
354 // these parameters are not given for all events
355 UInt32 button = [nsEvent buttonNumber];
356 UInt32 clickCount = 0;
358 wxevent.m_x = screenMouseLocation.x;
359 wxevent.m_y = screenMouseLocation.y;
360 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
361 wxevent.m_controlDown = modifiers & NSControlKeyMask;
362 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
363 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
364 wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
366 UInt32 mouseChord = 0;
370 case NSLeftMouseDown :
371 case NSLeftMouseDragged :
374 case NSRightMouseDown :
375 case NSRightMouseDragged :
378 case NSOtherMouseDown :
379 case NSOtherMouseDragged :
384 // a control click is interpreted as a right click
385 bool thisButtonIsFakeRight = false ;
386 if ( button == 0 && (modifiers & NSControlKeyMask) )
389 thisButtonIsFakeRight = true ;
392 // otherwise we report double clicks by connecting a left click with a ctrl-left click
393 if ( clickCount > 1 && button != g_lastButton )
396 // we must make sure that our synthetic 'right' button corresponds in
397 // mouse down, moved and mouse up, and does not deliver a right down and left up
400 case NSLeftMouseDown :
401 case NSRightMouseDown :
402 case NSOtherMouseDown :
403 g_lastButton = button ;
404 g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
411 g_lastButtonWasFakeRight = false ;
413 else if ( g_lastButton == 1 && g_lastButtonWasFakeRight )
414 button = g_lastButton ;
416 // Adjust the chord mask to remove the primary button and add the
417 // secondary button. It is possible that the secondary button is
418 // already pressed, e.g. on a mouse connected to a laptop, but this
419 // possibility is ignored here:
420 if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
421 mouseChord = ((mouseChord & ~1U) | 2U);
424 wxevent.m_leftDown = true ;
426 wxevent.m_rightDown = true ;
428 wxevent.m_middleDown = true ;
430 // translate into wx types
433 case NSLeftMouseDown :
434 case NSRightMouseDown :
435 case NSOtherMouseDown :
436 clickCount = [nsEvent clickCount];
440 wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
444 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
448 wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
457 case NSRightMouseUp :
458 case NSOtherMouseUp :
459 clickCount = [nsEvent clickCount];
463 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
467 wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
471 wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
481 wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
482 wxevent.m_wheelDelta = 10;
483 wxevent.m_linesPerAction = 1;
485 if ( fabs([nsEvent deltaX]) > fabs([nsEvent deltaY]) )
487 wxevent.m_wheelAxis = 1;
488 wxevent.m_wheelRotation = [nsEvent deltaX] * 10.0;
492 wxevent.m_wheelRotation = [nsEvent deltaY] * 10.0;
497 case NSMouseEntered :
498 wxevent.SetEventType( wxEVT_ENTER_WINDOW ) ;
501 wxevent.SetEventType( wxEVT_LEAVE_WINDOW ) ;
503 case NSLeftMouseDragged :
504 case NSRightMouseDragged :
505 case NSOtherMouseDragged :
507 wxevent.SetEventType( wxEVT_MOTION ) ;
513 wxevent.m_clickCount = clickCount;
517 @implementation wxNSView
521 static BOOL initialized = NO;
525 wxOSXCocoaClassAddWXMethods( self );
529 - (void) setTrackingTag: (NSTrackingRectTag)tag
534 - (NSTrackingRectTag) trackingTag
545 #if wxUSE_DRAG_AND_DROP
547 // see http://lists.apple.com/archives/Cocoa-dev/2005/Jul/msg01244.html
548 // for details on the NSPasteboard -> PasteboardRef conversion
550 NSDragOperation wxOSX_draggingEntered( id self, SEL _cmd, id <NSDraggingInfo>sender )
552 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
554 return NSDragOperationNone;
556 return impl->draggingEntered(sender, self, _cmd);
559 void wxOSX_draggingExited( id self, SEL _cmd, id <NSDraggingInfo> sender )
561 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
565 return impl->draggingExited(sender, self, _cmd);
568 NSDragOperation wxOSX_draggingUpdated( id self, SEL _cmd, id <NSDraggingInfo>sender )
570 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
572 return NSDragOperationNone;
574 return impl->draggingUpdated(sender, self, _cmd);
577 BOOL wxOSX_performDragOperation( id self, SEL _cmd, id <NSDraggingInfo> sender )
579 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
581 return NSDragOperationNone;
583 return impl->performDragOperation(sender, self, _cmd) ? YES:NO ;
586 void wxOSX_mouseEvent(NSView* self, SEL _cmd, NSEvent *event)
588 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
592 impl->mouseEvent(event, self, _cmd);
595 void wxOSX_keyEvent(NSView* self, SEL _cmd, NSEvent *event)
597 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
601 impl->keyEvent(event, self, _cmd);
604 void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text)
606 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
610 impl->insertText(text, self, _cmd);
613 BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event)
615 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
619 return impl->performKeyEquivalent(event, self, _cmd);
622 BOOL wxOSX_acceptsFirstResponder(NSView* self, SEL _cmd)
624 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
628 return impl->acceptsFirstResponder(self, _cmd);
631 BOOL wxOSX_becomeFirstResponder(NSView* self, SEL _cmd)
633 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
637 return impl->becomeFirstResponder(self, _cmd);
640 BOOL wxOSX_resignFirstResponder(NSView* self, SEL _cmd)
642 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
646 return impl->resignFirstResponder(self, _cmd);
649 void wxOSX_resetCursorRects(NSView* self, SEL _cmd)
651 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
655 impl->resetCursorRects(self, _cmd);
658 BOOL wxOSX_isFlipped(NSView* self, SEL _cmd)
660 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
664 return impl->isFlipped(self, _cmd) ? YES:NO;
667 void wxOSX_drawRect(NSView* self, SEL _cmd, NSRect rect)
669 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
673 return impl->drawRect(&rect, self, _cmd);
676 void wxOSX_controlAction(NSView* self, SEL _cmd, id sender)
678 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
682 impl->controlAction(self, _cmd, sender);
685 void wxOSX_controlDoubleAction(NSView* self, SEL _cmd, id sender)
687 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
691 impl->controlDoubleAction(self, _cmd, sender);
694 unsigned int wxWidgetCocoaImpl::draggingEntered(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->OnEnter(pt.x, pt.y, result);
722 CFRelease(pboardRef);
724 NSDragOperation nsresult = NSDragOperationNone;
728 nsresult = NSDragOperationLink;
730 nsresult = NSDragOperationMove;
732 nsresult = NSDragOperationCopy;
739 void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
741 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
742 NSPasteboard *pboard = [sender draggingPasteboard];
744 wxWindow* wxpeer = GetWXPeer();
745 if ( wxpeer == NULL )
748 wxDropTarget* target = wxpeer->GetDropTarget();
749 if ( target == NULL )
752 PasteboardRef pboardRef;
753 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
754 target->SetCurrentDragPasteboard(pboardRef);
756 CFRelease(pboardRef);
759 unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
761 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
762 NSPasteboard *pboard = [sender draggingPasteboard];
763 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
765 wxWindow* wxpeer = GetWXPeer();
766 if ( wxpeer == NULL )
767 return NSDragOperationNone;
769 wxDropTarget* target = wxpeer->GetDropTarget();
770 if ( target == NULL )
771 return NSDragOperationNone;
773 wxDragResult result = wxDragNone;
774 wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
776 if ( sourceDragMask & NSDragOperationLink )
778 else if ( sourceDragMask & NSDragOperationCopy )
780 else if ( sourceDragMask & NSDragOperationMove )
783 PasteboardRef pboardRef;
784 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
785 target->SetCurrentDragPasteboard(pboardRef);
786 result = target->OnDragOver(pt.x, pt.y, result);
787 CFRelease(pboardRef);
789 NSDragOperation nsresult = NSDragOperationNone;
793 nsresult = NSDragOperationLink;
795 nsresult = NSDragOperationMove;
797 nsresult = NSDragOperationCopy;
804 bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
806 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
808 NSPasteboard *pboard = [sender draggingPasteboard];
809 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
811 wxWindow* wxpeer = GetWXPeer();
812 wxDropTarget* target = wxpeer->GetDropTarget();
813 wxDragResult result = wxDragNone;
814 wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
816 if ( sourceDragMask & NSDragOperationLink )
818 else if ( sourceDragMask & NSDragOperationCopy )
820 else if ( sourceDragMask & NSDragOperationMove )
823 PasteboardRef pboardRef;
824 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
825 target->SetCurrentDragPasteboard(pboardRef);
826 result = target->OnData(pt.x, pt.y, result);
827 CFRelease(pboardRef);
829 return result != wxDragNone;
834 typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
835 typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
836 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
837 typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
838 typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
839 typedef BOOL (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
841 void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
843 if ( !DoHandleMouseEvent(event) )
845 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
846 superimpl(slf, (SEL)_cmd, event);
850 void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
852 if ( [[slf window] firstResponder] != slf || !DoHandleKeyEvent(event) )
854 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
855 superimpl(slf, (SEL)_cmd, event);
859 void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
861 if (m_lastKeyDownEvent && !DoHandleCharEvent(m_lastKeyDownEvent, text) )
863 wxOSX_TextEventHandlerPtr superimpl = (wxOSX_TextEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
864 superimpl(slf, (SEL)_cmd, text);
866 m_lastKeyDownEvent = NULL;
870 bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
872 wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
873 return superimpl(slf, (SEL)_cmd, event);
876 bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
878 if ( m_wxPeer->MacIsUserPane() )
879 return m_wxPeer->AcceptsFocus();
882 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
883 return superimpl(slf, (SEL)_cmd);
887 bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
889 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
890 // get the current focus before running becomeFirstResponder
891 NSView* otherView = FindFocus();
892 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
893 BOOL r = superimpl(slf, (SEL)_cmd);
896 DoNotifyFocusEvent( true, otherWindow );
901 bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
903 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
904 BOOL r = superimpl(slf, (SEL)_cmd);
905 // get the current focus after running resignFirstResponder
906 NSView* otherView = FindFocus();
907 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
908 // NSTextViews have an editor as true responder, therefore the might get the
909 // resign notification if their editor takes over, don't trigger any event hen
910 if ( r && otherWindow != this)
912 DoNotifyFocusEvent( false, otherWindow );
917 void wxWidgetCocoaImpl::resetCursorRects(WXWidget slf, void *_cmd)
919 wxWindow* wxpeer = GetWXPeer();
922 NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();
925 wxOSX_ResetCursorRectsHandlerPtr superimpl = (wxOSX_ResetCursorRectsHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
926 superimpl(slf, (SEL)_cmd);
930 [slf addCursorRect: [slf bounds]
936 bool wxWidgetCocoaImpl::isFlipped(WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
942 #define OSX_DEBUG_DRAWING 0
944 void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
946 CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
947 CGContextSaveGState( context );
949 #if OSX_DEBUG_DRAWING
950 CGContextBeginPath( context );
951 CGContextMoveToPoint(context, 0, 0);
952 NSRect bounds = [self bounds];
953 CGContextAddLineToPoint(context, 10, 0);
954 CGContextMoveToPoint(context, 0, 0);
955 CGContextAddLineToPoint(context, 0, 10);
956 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
957 CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
958 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
959 CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
960 CGContextClosePath( context );
961 CGContextStrokePath(context);
966 CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
967 CGContextScaleCTM( context, 1, -1 );
974 [slf getRectsBeingDrawn:&rects count:&count];
975 for ( int i = 0 ; i < count ; ++i )
977 updateRgn.Union(wxFromNSRect(slf, rects[i]) );
980 wxWindow* wxpeer = GetWXPeer();
981 wxpeer->GetUpdateRegion() = updateRgn;
982 wxpeer->MacSetCGContextRef( context );
984 bool handled = wxpeer->MacDoRedraw( 0 );
986 CGContextRestoreGState( context );
988 CGContextSaveGState( context );
992 SEL _cmd = @selector(drawRect:);
993 wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
994 superimpl(slf, _cmd, *(NSRect*)rect);
995 CGContextRestoreGState( context );
996 CGContextSaveGState( context );
998 wxpeer->MacPaintChildrenBorders();
999 wxpeer->MacSetCGContextRef( NULL );
1000 CGContextRestoreGState( context );
1003 void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
1005 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
1007 wxpeer->OSXHandleClicked(0);
1010 void wxWidgetCocoaImpl::controlDoubleAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
1016 #if OBJC_API_VERSION >= 2
1018 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1019 class_addMethod(c, s, i, t );
1023 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1028 void wxOSXCocoaClassAddWXMethods(Class c)
1031 #if OBJC_API_VERSION < 2
1032 static objc_method wxmethods[] =
1036 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1037 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1038 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1040 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1041 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1042 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1044 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseMoved:), (IMP) wxOSX_mouseEvent, "v@:@" )
1046 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1047 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1048 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1050 wxOSX_CLASS_ADD_METHOD(c, @selector(scrollWheel:), (IMP) wxOSX_mouseEvent, "v@:@" )
1051 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
1052 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
1054 wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
1055 wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
1056 wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
1058 wxOSX_CLASS_ADD_METHOD(c, @selector(insertText:), (IMP) wxOSX_insertText, "v@:@" )
1060 wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "v@:@" )
1062 wxOSX_CLASS_ADD_METHOD(c, @selector(acceptsFirstResponder), (IMP) wxOSX_acceptsFirstResponder, "c@:" )
1063 wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
1064 wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
1065 wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
1067 wxOSX_CLASS_ADD_METHOD(c, @selector(isFlipped), (IMP) wxOSX_isFlipped, "c@:" )
1068 wxOSX_CLASS_ADD_METHOD(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}" )
1070 wxOSX_CLASS_ADD_METHOD(c, @selector(controlAction:), (IMP) wxOSX_controlAction, "v@:@" )
1071 wxOSX_CLASS_ADD_METHOD(c, @selector(controlDoubleAction:), (IMP) wxOSX_controlDoubleAction, "v@:@" )
1073 #if wxUSE_DRAG_AND_DROP
1074 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingEntered:), (IMP) wxOSX_draggingEntered, "I@:@" )
1075 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingUpdated:), (IMP) wxOSX_draggingUpdated, "I@:@" )
1076 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingExited:), (IMP) wxOSX_draggingExited, "v@:@" )
1077 wxOSX_CLASS_ADD_METHOD(c, @selector(performDragOperation:), (IMP) wxOSX_performDragOperation, "c@:@" )
1080 #if OBJC_API_VERSION < 2
1082 static int method_count = WXSIZEOF( wxmethods );
1083 static objc_method_list *wxmethodlist = NULL;
1084 if ( wxmethodlist == NULL )
1086 wxmethodlist = (objc_method_list*) malloc(sizeof(objc_method_list) + sizeof(wxmethods) );
1087 memcpy( &wxmethodlist->method_list[0], &wxmethods[0], sizeof(wxmethods) );
1088 wxmethodlist->method_count = method_count;
1089 wxmethodlist->obsolete = 0;
1091 class_addMethods( c, wxmethodlist );
1096 // C++ implementation class
1099 IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
1101 wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
1102 wxWidgetImpl( peer, isRootControl )
1108 wxWidgetCocoaImpl::wxWidgetCocoaImpl()
1113 void wxWidgetCocoaImpl::Init()
1117 m_lastKeyDownEvent = NULL;
1120 wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
1122 RemoveAssociations( this );
1124 if ( !IsRootControl() )
1126 NSView *sv = [m_osxView superview];
1128 [m_osxView removeFromSuperview];
1130 [m_osxView release];
1133 bool wxWidgetCocoaImpl::IsVisible() const
1135 return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
1138 void wxWidgetCocoaImpl::SetVisibility( bool visible )
1140 [m_osxView setHidden:(visible ? NO:YES)];
1143 void wxWidgetCocoaImpl::Raise()
1147 void wxWidgetCocoaImpl::Lower()
1151 void wxWidgetCocoaImpl::ScrollRect( const wxRect *WXUNUSED(rect), int WXUNUSED(dx), int WXUNUSED(dy) )
1156 // We should do something like this, but it wasn't working in 10.4.
1157 if (GetNeedsDisplay() )
1161 NSRect r = wxToNSRect( [m_osxView superview], *rect );
1162 NSSize offset = NSMakeSize((float)dx, (float)dy);
1163 [m_osxView scrollRect:r by:offset];
1167 void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
1169 wxWindowMac* parent = GetWXPeer()->GetParent();
1170 // under Cocoa we might have a contentView in the wxParent to which we have to
1171 // adjust the coordinates
1172 if (parent && [m_osxView superview] != parent->GetHandle() )
1174 int cx = 0,cy = 0,cw = 0,ch = 0;
1175 if ( parent->GetPeer() )
1177 parent->GetPeer()->GetContentArea(cx, cy, cw, ch);
1182 [[m_osxView superview] setNeedsDisplayInRect:[m_osxView frame]];
1183 NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
1184 [m_osxView setFrame:r];
1185 [[m_osxView superview] setNeedsDisplayInRect:r];
1187 if ([m_osxView respondsToSelector:@selector(trackingTag)] )
1189 if ( [(wxNSView*)m_osxView trackingTag] )
1190 [m_osxView removeTrackingRect: [(wxNSView*)m_osxView trackingTag]];
1192 [(wxNSView*)m_osxView setTrackingTag: [m_osxView addTrackingRect: [m_osxView bounds] owner: m_osxView userData: nil assumeInside: NO]];
1196 void wxWidgetCocoaImpl::GetPosition( int &x, int &y ) const
1198 wxRect r = wxFromNSRect( [m_osxView superview], [m_osxView frame] );
1203 void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
1205 NSRect rect = [m_osxView frame];
1206 width = rect.size.width;
1207 height = rect.size.height;
1210 void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
1212 if ( [m_osxView respondsToSelector:@selector(contentView) ] )
1214 NSView* cv = [m_osxView contentView];
1216 NSRect bounds = [m_osxView bounds];
1217 NSRect rect = [cv frame];
1219 int y = rect.origin.y;
1220 int x = rect.origin.x;
1221 if ( ![ m_osxView isFlipped ] )
1222 y = bounds.size.height - (rect.origin.y + rect.size.height);
1225 width = rect.size.width;
1226 height = rect.size.height;
1231 GetSize( width, height );
1235 void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
1238 [m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )];
1240 [m_osxView setNeedsDisplay:YES];
1243 bool wxWidgetCocoaImpl::GetNeedsDisplay() const
1245 return [m_osxView needsDisplay];
1248 bool wxWidgetCocoaImpl::CanFocus() const
1250 return [m_osxView canBecomeKeyView] == YES;
1253 bool wxWidgetCocoaImpl::HasFocus() const
1255 return ( FindFocus() == m_osxView );
1258 bool wxWidgetCocoaImpl::SetFocus()
1260 if ( [m_osxView canBecomeKeyView] == NO )
1263 [[m_osxView window] makeFirstResponder: m_osxView] ;
1268 void wxWidgetCocoaImpl::RemoveFromParent()
1270 [m_osxView removeFromSuperview];
1273 void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
1275 NSView* container = parent->GetWXWidget() ;
1276 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
1277 [container addSubview:m_osxView];
1280 void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
1282 // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
1285 void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
1287 if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
1289 wxCFStringRef cf( title , encoding );
1290 [m_osxView setTitle:cf.AsNSString()];
1292 else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
1294 wxCFStringRef cf( title , encoding );
1295 [m_osxView setStringValue:cf.AsNSString()];
1300 void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
1302 NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
1303 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
1304 *pt = wxFromNSPoint( to->GetWXWidget(), p );
1307 wxInt32 wxWidgetCocoaImpl::GetValue() const
1309 return [(NSControl*)m_osxView intValue];
1312 void wxWidgetCocoaImpl::SetValue( wxInt32 v )
1314 if ( [m_osxView respondsToSelector:@selector(setIntValue:)] )
1316 [m_osxView setIntValue:v];
1318 else if ( [m_osxView respondsToSelector:@selector(setFloatValue:)] )
1320 [m_osxView setFloatValue:(double)v];
1322 else if ( [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
1324 [m_osxView setDoubleValue:(double)v];
1328 void wxWidgetCocoaImpl::SetMinimum( wxInt32 v )
1330 if ( [m_osxView respondsToSelector:@selector(setMinValue:)] )
1332 [m_osxView setMinValue:(double)v];
1336 void wxWidgetCocoaImpl::SetMaximum( wxInt32 v )
1338 if ( [m_osxView respondsToSelector:@selector(setMaxValue:)] )
1340 [m_osxView setMaxValue:(double)v];
1344 wxInt32 wxWidgetCocoaImpl::GetMinimum() const
1346 if ( [m_osxView respondsToSelector:@selector(getMinValue:)] )
1348 return [m_osxView minValue];
1353 wxInt32 wxWidgetCocoaImpl::GetMaximum() const
1355 if ( [m_osxView respondsToSelector:@selector(getMaxValue:)] )
1357 return [m_osxView maxValue];
1362 void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
1364 if ( [m_osxView respondsToSelector:@selector(setImage:)] )
1366 [m_osxView setImage:bitmap.GetNSImage()];
1370 void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& WXUNUSED(notebook))
1372 // implementation in subclass
1375 void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
1377 r->x = r->y = r->width = r->height = 0;
1379 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
1381 NSRect former = [m_osxView frame];
1382 [m_osxView sizeToFit];
1383 NSRect best = [m_osxView frame];
1384 [m_osxView setFrame:former];
1385 r->width = best.size.width;
1386 r->height = best.size.height;
1390 bool wxWidgetCocoaImpl::IsEnabled() const
1392 if ( [m_osxView respondsToSelector:@selector(isEnabled) ] )
1393 return [m_osxView isEnabled];
1397 void wxWidgetCocoaImpl::Enable( bool enable )
1399 if ( [m_osxView respondsToSelector:@selector(setEnabled:) ] )
1400 [m_osxView setEnabled:enable];
1403 void wxWidgetCocoaImpl::PulseGauge()
1407 void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 WXUNUSED(val), wxInt32 WXUNUSED(view) )
1411 void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
1413 NSControlSize size = NSRegularControlSize;
1417 case wxWINDOW_VARIANT_NORMAL :
1418 size = NSRegularControlSize;
1421 case wxWINDOW_VARIANT_SMALL :
1422 size = NSSmallControlSize;
1425 case wxWINDOW_VARIANT_MINI :
1426 size = NSMiniControlSize;
1429 case wxWINDOW_VARIANT_LARGE :
1430 size = NSRegularControlSize;
1434 wxFAIL_MSG(_T("unexpected window variant"));
1437 if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
1438 [m_osxView setControlSize:size];
1441 void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
1443 if ([m_osxView respondsToSelector:@selector(setFont:)])
1444 [m_osxView setFont: font.OSXGetNSFont()];
1447 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
1449 WXWidget c = control ? control : (WXWidget) m_osxView;
1450 wxWidgetImpl::Associate( c, this ) ;
1451 if ([c respondsToSelector:@selector(setAction:)])
1454 [c setAction: @selector(controlAction:)];
1455 if ([c respondsToSelector:@selector(setDoubleAction:)])
1457 [c setDoubleAction: @selector(controlDoubleAction:)];
1463 bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
1465 wxKeyEvent wxevent(wxEVT_CHAR);
1466 SetupKeyEvent( wxevent, event, text );
1467 wxevent.SetEventObject(GetWXPeer());
1469 return GetWXPeer()->OSXHandleKeyEvent(wxevent);
1472 bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
1474 wxKeyEvent wxevent(wxEVT_KEY_DOWN);
1475 SetupKeyEvent( wxevent, event );
1476 wxevent.SetEventObject(GetWXPeer());
1477 bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
1479 // this will fire higher level events, like insertText, to help
1480 // us handle EVT_CHAR, etc.
1481 if ([event type] == NSKeyDown)
1483 m_lastKeyDownEvent = event;
1485 [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
1490 bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
1492 NSPoint clickLocation;
1493 clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil];
1494 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
1495 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
1496 SetupMouseEvent( wxevent , event ) ;
1497 wxevent.SetEventObject(GetWXPeer());
1501 return GetWXPeer()->HandleWindowEvent(wxevent);
1504 void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
1506 wxWindow* thisWindow = GetWXPeer();
1507 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
1509 thisWindow->MacInvalidateBorders();
1512 if ( receivedFocus )
1514 wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
1515 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
1516 thisWindow->HandleWindowEvent(eventFocus);
1519 if ( thisWindow->GetCaret() )
1520 thisWindow->GetCaret()->OnSetFocus();
1523 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
1524 event.SetEventObject(thisWindow);
1526 event.SetWindow(otherWindow->GetWXPeer());
1527 thisWindow->HandleWindowEvent(event) ;
1529 else // !receivedFocuss
1532 if ( thisWindow->GetCaret() )
1533 thisWindow->GetCaret()->OnKillFocus();
1536 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
1538 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
1539 event.SetEventObject(thisWindow);
1541 event.SetWindow(otherWindow->GetWXPeer());
1542 thisWindow->HandleWindowEvent(event) ;
1546 void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor)
1548 NSPoint location = [NSEvent mouseLocation];
1549 location = [[m_osxView window] convertScreenToBase:location];
1550 NSPoint locationInView = [m_osxView convertPoint:location fromView:nil];
1552 if( NSMouseInRect(locationInView, [m_osxView bounds], YES) )
1554 [(NSCursor*)cursor.GetHCURSOR() set];
1556 [[m_osxView window] invalidateCursorRectsForView:m_osxView];
1559 void wxWidgetCocoaImpl::CaptureMouse()
1561 [[m_osxView window] disableCursorRects];
1564 void wxWidgetCocoaImpl::ReleaseMouse()
1566 [[m_osxView window] enableCursorRects];
1569 void wxWidgetCocoaImpl::SetFlipped(bool flipped)
1571 m_isFlipped = flipped;
1578 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
1579 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
1580 long WXUNUSED(style), long WXUNUSED(extraStyle))
1582 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
1583 wxNSView* v = [[wxNSView alloc] initWithFrame:r];
1585 // temporary hook for dnd
1586 [v registerForDraggedTypes:[NSArray arrayWithObjects:
1587 NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
1589 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
1593 wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
1595 NSWindow* tlw = now->GetWXWindow();
1596 wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
1597 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
1598 c->InstallEventHandler();
1599 [tlw setContentView:v];