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 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
710 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
712 if ( sourceDragMask & NSDragOperationLink )
714 else if ( sourceDragMask & NSDragOperationCopy )
716 else if ( sourceDragMask & NSDragOperationMove )
719 PasteboardRef pboardRef;
720 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
721 target->SetCurrentDragPasteboard(pboardRef);
722 result = target->OnEnter(pt.x, pt.y, result);
723 CFRelease(pboardRef);
725 NSDragOperation nsresult = NSDragOperationNone;
729 nsresult = NSDragOperationLink;
731 nsresult = NSDragOperationMove;
733 nsresult = NSDragOperationCopy;
740 void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
742 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
743 NSPasteboard *pboard = [sender draggingPasteboard];
745 wxWindow* wxpeer = GetWXPeer();
746 if ( wxpeer == NULL )
749 wxDropTarget* target = wxpeer->GetDropTarget();
750 if ( target == NULL )
753 PasteboardRef pboardRef;
754 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
755 target->SetCurrentDragPasteboard(pboardRef);
757 CFRelease(pboardRef);
760 unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
762 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
763 NSPasteboard *pboard = [sender draggingPasteboard];
764 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
766 wxWindow* wxpeer = GetWXPeer();
767 if ( wxpeer == NULL )
768 return NSDragOperationNone;
770 wxDropTarget* target = wxpeer->GetDropTarget();
771 if ( target == NULL )
772 return NSDragOperationNone;
774 wxDragResult result = wxDragNone;
775 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
776 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
778 if ( sourceDragMask & NSDragOperationLink )
780 else if ( sourceDragMask & NSDragOperationCopy )
782 else if ( sourceDragMask & NSDragOperationMove )
785 PasteboardRef pboardRef;
786 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
787 target->SetCurrentDragPasteboard(pboardRef);
788 result = target->OnDragOver(pt.x, pt.y, result);
789 CFRelease(pboardRef);
791 NSDragOperation nsresult = NSDragOperationNone;
795 nsresult = NSDragOperationLink;
797 nsresult = NSDragOperationMove;
799 nsresult = NSDragOperationCopy;
806 bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
808 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
810 NSPasteboard *pboard = [sender draggingPasteboard];
811 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
813 wxWindow* wxpeer = GetWXPeer();
814 wxDropTarget* target = wxpeer->GetDropTarget();
815 wxDragResult result = wxDragNone;
816 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
817 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
819 if ( sourceDragMask & NSDragOperationLink )
821 else if ( sourceDragMask & NSDragOperationCopy )
823 else if ( sourceDragMask & NSDragOperationMove )
826 PasteboardRef pboardRef;
827 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
828 target->SetCurrentDragPasteboard(pboardRef);
830 if (target->OnDrop(pt.x, pt.y))
831 result = target->OnData(pt.x, pt.y, result);
833 CFRelease(pboardRef);
835 return result != wxDragNone;
840 typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
841 typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
842 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
843 typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
844 typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
845 typedef BOOL (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
847 void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
849 if ( !DoHandleMouseEvent(event) )
851 // for plain NSView mouse events would propagate to parents otherwise
852 if (!m_wxPeer->MacIsUserPane())
854 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
855 superimpl(slf, (SEL)_cmd, event);
860 void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
862 if ( [[slf window] firstResponder] != slf || !DoHandleKeyEvent(event) )
864 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
865 superimpl(slf, (SEL)_cmd, event);
869 void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
871 if (m_lastKeyDownEvent && !DoHandleCharEvent(m_lastKeyDownEvent, text) )
873 wxOSX_TextEventHandlerPtr superimpl = (wxOSX_TextEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
874 superimpl(slf, (SEL)_cmd, text);
876 m_lastKeyDownEvent = NULL;
880 bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
882 wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
883 return superimpl(slf, (SEL)_cmd, event);
886 bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
888 if ( m_wxPeer->MacIsUserPane() )
889 return m_wxPeer->AcceptsFocus();
892 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
893 return superimpl(slf, (SEL)_cmd);
897 bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
899 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
900 // get the current focus before running becomeFirstResponder
901 NSView* otherView = FindFocus();
902 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
903 BOOL r = superimpl(slf, (SEL)_cmd);
906 DoNotifyFocusEvent( true, otherWindow );
911 bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
913 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
914 BOOL r = superimpl(slf, (SEL)_cmd);
915 // get the current focus after running resignFirstResponder
916 NSView* otherView = FindFocus();
917 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
918 // NSTextViews have an editor as true responder, therefore the might get the
919 // resign notification if their editor takes over, don't trigger any event hen
920 if ( r && otherWindow != this)
922 DoNotifyFocusEvent( false, otherWindow );
927 void wxWidgetCocoaImpl::resetCursorRects(WXWidget slf, void *_cmd)
929 wxWindow* wxpeer = GetWXPeer();
932 NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();
935 wxOSX_ResetCursorRectsHandlerPtr superimpl = (wxOSX_ResetCursorRectsHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
936 superimpl(slf, (SEL)_cmd);
940 [slf addCursorRect: [slf bounds]
946 bool wxWidgetCocoaImpl::isFlipped(WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
952 #define OSX_DEBUG_DRAWING 0
954 void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
956 CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
957 CGContextSaveGState( context );
959 #if OSX_DEBUG_DRAWING
960 CGContextBeginPath( context );
961 CGContextMoveToPoint(context, 0, 0);
962 NSRect bounds = [self bounds];
963 CGContextAddLineToPoint(context, 10, 0);
964 CGContextMoveToPoint(context, 0, 0);
965 CGContextAddLineToPoint(context, 0, 10);
966 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
967 CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
968 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
969 CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
970 CGContextClosePath( context );
971 CGContextStrokePath(context);
976 CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
977 CGContextScaleCTM( context, 1, -1 );
984 [slf getRectsBeingDrawn:&rects count:&count];
985 for ( int i = 0 ; i < count ; ++i )
987 updateRgn.Union(wxFromNSRect(slf, rects[i]) );
990 wxWindow* wxpeer = GetWXPeer();
991 wxpeer->GetUpdateRegion() = updateRgn;
992 wxpeer->MacSetCGContextRef( context );
994 bool handled = wxpeer->MacDoRedraw( 0 );
996 CGContextRestoreGState( context );
998 CGContextSaveGState( context );
1002 SEL _cmd = @selector(drawRect:);
1003 wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
1004 superimpl(slf, _cmd, *(NSRect*)rect);
1005 CGContextRestoreGState( context );
1006 CGContextSaveGState( context );
1008 wxpeer->MacPaintChildrenBorders();
1009 wxpeer->MacSetCGContextRef( NULL );
1010 CGContextRestoreGState( context );
1013 void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
1015 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
1017 wxpeer->OSXHandleClicked(0);
1020 void wxWidgetCocoaImpl::controlDoubleAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
1026 #if OBJC_API_VERSION >= 2
1028 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1029 class_addMethod(c, s, i, t );
1033 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1038 void wxOSXCocoaClassAddWXMethods(Class c)
1041 #if OBJC_API_VERSION < 2
1042 static objc_method wxmethods[] =
1046 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1047 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1048 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1050 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1051 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1052 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1054 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseMoved:), (IMP) wxOSX_mouseEvent, "v@:@" )
1056 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1057 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1058 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1060 wxOSX_CLASS_ADD_METHOD(c, @selector(scrollWheel:), (IMP) wxOSX_mouseEvent, "v@:@" )
1061 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
1062 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
1064 wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
1065 wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
1066 wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
1068 wxOSX_CLASS_ADD_METHOD(c, @selector(insertText:), (IMP) wxOSX_insertText, "v@:@" )
1070 wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "v@:@" )
1072 wxOSX_CLASS_ADD_METHOD(c, @selector(acceptsFirstResponder), (IMP) wxOSX_acceptsFirstResponder, "c@:" )
1073 wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
1074 wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
1075 wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
1077 wxOSX_CLASS_ADD_METHOD(c, @selector(isFlipped), (IMP) wxOSX_isFlipped, "c@:" )
1078 wxOSX_CLASS_ADD_METHOD(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}" )
1080 wxOSX_CLASS_ADD_METHOD(c, @selector(controlAction:), (IMP) wxOSX_controlAction, "v@:@" )
1081 wxOSX_CLASS_ADD_METHOD(c, @selector(controlDoubleAction:), (IMP) wxOSX_controlDoubleAction, "v@:@" )
1083 #if wxUSE_DRAG_AND_DROP
1084 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingEntered:), (IMP) wxOSX_draggingEntered, "I@:@" )
1085 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingUpdated:), (IMP) wxOSX_draggingUpdated, "I@:@" )
1086 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingExited:), (IMP) wxOSX_draggingExited, "v@:@" )
1087 wxOSX_CLASS_ADD_METHOD(c, @selector(performDragOperation:), (IMP) wxOSX_performDragOperation, "c@:@" )
1090 #if OBJC_API_VERSION < 2
1092 static int method_count = WXSIZEOF( wxmethods );
1093 static objc_method_list *wxmethodlist = NULL;
1094 if ( wxmethodlist == NULL )
1096 wxmethodlist = (objc_method_list*) malloc(sizeof(objc_method_list) + sizeof(wxmethods) );
1097 memcpy( &wxmethodlist->method_list[0], &wxmethods[0], sizeof(wxmethods) );
1098 wxmethodlist->method_count = method_count;
1099 wxmethodlist->obsolete = 0;
1101 class_addMethods( c, wxmethodlist );
1106 // C++ implementation class
1109 IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
1111 wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
1112 wxWidgetImpl( peer, isRootControl )
1118 wxWidgetCocoaImpl::wxWidgetCocoaImpl()
1123 void wxWidgetCocoaImpl::Init()
1127 m_lastKeyDownEvent = NULL;
1130 wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
1132 RemoveAssociations( this );
1134 if ( !IsRootControl() )
1136 NSView *sv = [m_osxView superview];
1138 [m_osxView removeFromSuperview];
1140 [m_osxView release];
1143 bool wxWidgetCocoaImpl::IsVisible() const
1145 return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
1148 void wxWidgetCocoaImpl::SetVisibility( bool visible )
1150 [m_osxView setHidden:(visible ? NO:YES)];
1153 void wxWidgetCocoaImpl::Raise()
1157 void wxWidgetCocoaImpl::Lower()
1161 void wxWidgetCocoaImpl::ScrollRect( const wxRect *WXUNUSED(rect), int WXUNUSED(dx), int WXUNUSED(dy) )
1166 // We should do something like this, but it wasn't working in 10.4.
1167 if (GetNeedsDisplay() )
1171 NSRect r = wxToNSRect( [m_osxView superview], *rect );
1172 NSSize offset = NSMakeSize((float)dx, (float)dy);
1173 [m_osxView scrollRect:r by:offset];
1177 void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
1179 wxWindowMac* parent = GetWXPeer()->GetParent();
1180 // under Cocoa we might have a contentView in the wxParent to which we have to
1181 // adjust the coordinates
1182 if (parent && [m_osxView superview] != parent->GetHandle() )
1184 int cx = 0,cy = 0,cw = 0,ch = 0;
1185 if ( parent->GetPeer() )
1187 parent->GetPeer()->GetContentArea(cx, cy, cw, ch);
1192 [[m_osxView superview] setNeedsDisplayInRect:[m_osxView frame]];
1193 NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
1194 [m_osxView setFrame:r];
1195 [[m_osxView superview] setNeedsDisplayInRect:r];
1197 if ([m_osxView respondsToSelector:@selector(trackingTag)] )
1199 if ( [(wxNSView*)m_osxView trackingTag] )
1200 [m_osxView removeTrackingRect: [(wxNSView*)m_osxView trackingTag]];
1202 [(wxNSView*)m_osxView setTrackingTag: [m_osxView addTrackingRect: [m_osxView bounds] owner: m_osxView userData: nil assumeInside: NO]];
1206 void wxWidgetCocoaImpl::GetPosition( int &x, int &y ) const
1208 wxRect r = wxFromNSRect( [m_osxView superview], [m_osxView frame] );
1213 void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
1215 NSRect rect = [m_osxView frame];
1216 width = rect.size.width;
1217 height = rect.size.height;
1220 void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
1222 if ( [m_osxView respondsToSelector:@selector(contentView) ] )
1224 NSView* cv = [m_osxView contentView];
1226 NSRect bounds = [m_osxView bounds];
1227 NSRect rect = [cv frame];
1229 int y = rect.origin.y;
1230 int x = rect.origin.x;
1231 if ( ![ m_osxView isFlipped ] )
1232 y = bounds.size.height - (rect.origin.y + rect.size.height);
1235 width = rect.size.width;
1236 height = rect.size.height;
1241 GetSize( width, height );
1245 void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
1248 [m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )];
1250 [m_osxView setNeedsDisplay:YES];
1253 bool wxWidgetCocoaImpl::GetNeedsDisplay() const
1255 return [m_osxView needsDisplay];
1258 bool wxWidgetCocoaImpl::CanFocus() const
1260 return [m_osxView canBecomeKeyView] == YES;
1263 bool wxWidgetCocoaImpl::HasFocus() const
1265 return ( FindFocus() == m_osxView );
1268 bool wxWidgetCocoaImpl::SetFocus()
1270 if ( [m_osxView canBecomeKeyView] == NO )
1273 [[m_osxView window] makeFirstResponder: m_osxView] ;
1278 void wxWidgetCocoaImpl::RemoveFromParent()
1280 [m_osxView removeFromSuperview];
1283 void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
1285 NSView* container = parent->GetWXWidget() ;
1286 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
1287 [container addSubview:m_osxView];
1290 void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
1292 // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
1295 void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
1297 if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
1299 wxCFStringRef cf( title , encoding );
1300 [m_osxView setTitle:cf.AsNSString()];
1302 else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
1304 wxCFStringRef cf( title , encoding );
1305 [m_osxView setStringValue:cf.AsNSString()];
1310 void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
1312 NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
1313 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
1314 *pt = wxFromNSPoint( to->GetWXWidget(), p );
1317 wxInt32 wxWidgetCocoaImpl::GetValue() const
1319 return [(NSControl*)m_osxView intValue];
1322 void wxWidgetCocoaImpl::SetValue( wxInt32 v )
1324 if ( [m_osxView respondsToSelector:@selector(setIntValue:)] )
1326 [m_osxView setIntValue:v];
1328 else if ( [m_osxView respondsToSelector:@selector(setFloatValue:)] )
1330 [m_osxView setFloatValue:(double)v];
1332 else if ( [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
1334 [m_osxView setDoubleValue:(double)v];
1338 void wxWidgetCocoaImpl::SetMinimum( wxInt32 v )
1340 if ( [m_osxView respondsToSelector:@selector(setMinValue:)] )
1342 [m_osxView setMinValue:(double)v];
1346 void wxWidgetCocoaImpl::SetMaximum( wxInt32 v )
1348 if ( [m_osxView respondsToSelector:@selector(setMaxValue:)] )
1350 [m_osxView setMaxValue:(double)v];
1354 wxInt32 wxWidgetCocoaImpl::GetMinimum() const
1356 if ( [m_osxView respondsToSelector:@selector(getMinValue:)] )
1358 return [m_osxView minValue];
1363 wxInt32 wxWidgetCocoaImpl::GetMaximum() const
1365 if ( [m_osxView respondsToSelector:@selector(getMaxValue:)] )
1367 return [m_osxView maxValue];
1372 void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
1374 if ( [m_osxView respondsToSelector:@selector(setImage:)] )
1376 [m_osxView setImage:bitmap.GetNSImage()];
1380 void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& WXUNUSED(notebook))
1382 // implementation in subclass
1385 void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
1387 r->x = r->y = r->width = r->height = 0;
1389 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
1391 NSRect former = [m_osxView frame];
1392 [m_osxView sizeToFit];
1393 NSRect best = [m_osxView frame];
1394 [m_osxView setFrame:former];
1395 r->width = best.size.width;
1396 r->height = best.size.height;
1400 bool wxWidgetCocoaImpl::IsEnabled() const
1402 if ( [m_osxView respondsToSelector:@selector(isEnabled) ] )
1403 return [m_osxView isEnabled];
1407 void wxWidgetCocoaImpl::Enable( bool enable )
1409 if ( [m_osxView respondsToSelector:@selector(setEnabled:) ] )
1410 [m_osxView setEnabled:enable];
1413 void wxWidgetCocoaImpl::PulseGauge()
1417 void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 WXUNUSED(val), wxInt32 WXUNUSED(view) )
1421 void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
1423 NSControlSize size = NSRegularControlSize;
1427 case wxWINDOW_VARIANT_NORMAL :
1428 size = NSRegularControlSize;
1431 case wxWINDOW_VARIANT_SMALL :
1432 size = NSSmallControlSize;
1435 case wxWINDOW_VARIANT_MINI :
1436 size = NSMiniControlSize;
1439 case wxWINDOW_VARIANT_LARGE :
1440 size = NSRegularControlSize;
1444 wxFAIL_MSG(_T("unexpected window variant"));
1447 if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
1448 [m_osxView setControlSize:size];
1451 void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
1453 if ([m_osxView respondsToSelector:@selector(setFont:)])
1454 [m_osxView setFont: font.OSXGetNSFont()];
1457 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
1459 WXWidget c = control ? control : (WXWidget) m_osxView;
1460 wxWidgetImpl::Associate( c, this ) ;
1461 if ([c respondsToSelector:@selector(setAction:)])
1464 [c setAction: @selector(controlAction:)];
1465 if ([c respondsToSelector:@selector(setDoubleAction:)])
1467 [c setDoubleAction: @selector(controlDoubleAction:)];
1473 bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
1475 wxKeyEvent wxevent(wxEVT_CHAR);
1476 SetupKeyEvent( wxevent, event, text );
1477 wxevent.SetEventObject(GetWXPeer());
1479 return GetWXPeer()->OSXHandleKeyEvent(wxevent);
1482 bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
1484 wxKeyEvent wxevent(wxEVT_KEY_DOWN);
1485 SetupKeyEvent( wxevent, event );
1486 wxevent.SetEventObject(GetWXPeer());
1487 bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
1489 // this will fire higher level events, like insertText, to help
1490 // us handle EVT_CHAR, etc.
1491 if ([event type] == NSKeyDown)
1493 m_lastKeyDownEvent = event;
1495 [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
1500 bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
1502 NSPoint clickLocation;
1503 clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil];
1504 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
1505 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
1506 SetupMouseEvent( wxevent , event ) ;
1507 wxevent.SetEventObject(GetWXPeer());
1511 return GetWXPeer()->HandleWindowEvent(wxevent);
1514 void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
1516 wxWindow* thisWindow = GetWXPeer();
1517 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
1519 thisWindow->MacInvalidateBorders();
1522 if ( receivedFocus )
1524 wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
1525 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
1526 thisWindow->HandleWindowEvent(eventFocus);
1529 if ( thisWindow->GetCaret() )
1530 thisWindow->GetCaret()->OnSetFocus();
1533 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
1534 event.SetEventObject(thisWindow);
1536 event.SetWindow(otherWindow->GetWXPeer());
1537 thisWindow->HandleWindowEvent(event) ;
1539 else // !receivedFocuss
1542 if ( thisWindow->GetCaret() )
1543 thisWindow->GetCaret()->OnKillFocus();
1546 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
1548 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
1549 event.SetEventObject(thisWindow);
1551 event.SetWindow(otherWindow->GetWXPeer());
1552 thisWindow->HandleWindowEvent(event) ;
1556 void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor)
1558 NSPoint location = [NSEvent mouseLocation];
1559 location = [[m_osxView window] convertScreenToBase:location];
1560 NSPoint locationInView = [m_osxView convertPoint:location fromView:nil];
1562 if( NSMouseInRect(locationInView, [m_osxView bounds], YES) )
1564 [(NSCursor*)cursor.GetHCURSOR() set];
1566 [[m_osxView window] invalidateCursorRectsForView:m_osxView];
1569 void wxWidgetCocoaImpl::CaptureMouse()
1571 [[m_osxView window] disableCursorRects];
1574 void wxWidgetCocoaImpl::ReleaseMouse()
1576 [[m_osxView window] enableCursorRects];
1579 void wxWidgetCocoaImpl::SetFlipped(bool flipped)
1581 m_isFlipped = flipped;
1588 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
1589 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
1590 long WXUNUSED(style), long WXUNUSED(extraStyle))
1592 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
1593 wxNSView* v = [[wxNSView alloc] initWithFrame:r];
1595 // temporary hook for dnd
1596 [v registerForDraggedTypes:[NSArray arrayWithObjects:
1597 NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
1599 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
1603 wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
1605 NSWindow* tlw = now->GetWXWindow();
1606 wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
1607 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
1608 c->InstallEventHandler();
1609 [tlw setContentView:v];