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 NSView* GetViewFromResponder( NSResponder* responder )
39 if ( [responder isKindOfClass:[NSTextView class]] )
41 NSView* delegate = [(NSTextView*)responder delegate];
42 if ( [delegate isKindOfClass:[NSTextField class] ] )
45 view = (NSView*) responder;
49 if ( [responder isKindOfClass:[NSView class]] )
50 view = (NSView*) responder;
55 NSView* GetFocusedViewInWindow( NSWindow* keyWindow )
57 NSView* focusedView = nil;
58 if ( keyWindow != nil )
59 focusedView = GetViewFromResponder([keyWindow firstResponder]);
64 WXWidget wxWidgetImpl::FindFocus()
66 return GetFocusedViewInWindow( [[NSApplication sharedApplication] keyWindow] );
69 NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
73 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
74 wxRect bounds(x,y,w,h);
75 NSView* sv = (window->GetParent()->GetHandle() );
77 return wxToNSRect( sv, bounds );
80 @interface wxNSView : NSView
82 NSTrackingRectTag rectTag;
85 // the tracking tag is needed to track mouse enter / exit events
86 - (void) setTrackingTag: (NSTrackingRectTag)tag;
87 - (NSTrackingRectTag) trackingTag;
90 @interface NSView(PossibleMethods)
91 - (void)setTitle:(NSString *)aString;
92 - (void)setStringValue:(NSString *)aString;
93 - (void)setIntValue:(int)anInt;
94 - (void)setFloatValue:(float)aFloat;
95 - (void)setDoubleValue:(double)aDouble;
99 - (void)setMinValue:(double)aDouble;
100 - (void)setMaxValue:(double)aDouble;
105 - (void)setEnabled:(BOOL)flag;
107 - (void)setImage:(NSImage *)image;
108 - (void)setControlSize:(NSControlSize)size;
110 - (void)setFont:(NSFont *)fontObject;
114 - (void)setTarget:(id)anObject;
115 - (void)setAction:(SEL)aSelector;
116 - (void)setDoubleAction:(SEL)aSelector;
119 long wxOSXTranslateCocoaKey( NSEvent* event )
123 if ([event type] != NSFlagsChanged)
125 NSString* s = [event charactersIgnoringModifiers];
126 // backspace char reports as delete w/modifiers for some reason
129 switch ( [s characterAtIndex:0] )
136 case NSUpArrowFunctionKey :
139 case NSDownArrowFunctionKey :
142 case NSLeftArrowFunctionKey :
145 case NSRightArrowFunctionKey :
148 case NSInsertFunctionKey :
151 case NSDeleteFunctionKey :
154 case NSHomeFunctionKey :
157 // case NSBeginFunctionKey :
158 // retval = WXK_BEGIN;
160 case NSEndFunctionKey :
163 case NSPageUpFunctionKey :
166 case NSPageDownFunctionKey :
167 retval = WXK_PAGEDOWN;
169 case NSHelpFunctionKey :
173 int intchar = [s characterAtIndex: 0];
174 if ( intchar >= NSF1FunctionKey && intchar <= NSF24FunctionKey )
175 retval = WXK_F1 + (intchar - NSF1FunctionKey );
181 // Some keys don't seem to have constants. The code mimics the approach
182 // taken by WebKit. See:
183 // http://trac.webkit.org/browser/trunk/WebCore/platform/mac/KeyEventMac.mm
184 switch( [event keyCode] )
189 retval = WXK_COMMAND;
193 retval = WXK_CAPITAL;
196 case 56: // Left Shift
197 case 60: // Right Shift
202 case 61: // Right Alt
206 case 59: // Left Ctrl
207 case 62: // Right Ctrl
208 retval = WXK_CONTROL;
220 retval = WXK_NUMPAD_DIVIDE;
223 retval = WXK_NUMPAD_MULTIPLY;
226 retval = WXK_NUMPAD_SUBTRACT;
229 retval = WXK_NUMPAD_ADD;
232 retval = WXK_NUMPAD_ENTER;
235 retval = WXK_NUMPAD_DECIMAL;
238 retval = WXK_NUMPAD0;
241 retval = WXK_NUMPAD1;
244 retval = WXK_NUMPAD2;
247 retval = WXK_NUMPAD3;
250 retval = WXK_NUMPAD4;
253 retval = WXK_NUMPAD5;
256 retval = WXK_NUMPAD6;
259 retval = WXK_NUMPAD7;
262 retval = WXK_NUMPAD8;
265 retval = WXK_NUMPAD9;
268 //retval = [event keyCode];
274 void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charString = NULL )
276 UInt32 modifiers = [nsEvent modifierFlags] ;
277 int eventType = [nsEvent type];
279 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
280 wxevent.m_controlDown = modifiers & NSControlKeyMask;
281 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
282 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
284 wxevent.m_rawCode = [nsEvent keyCode];
285 wxevent.m_rawFlags = modifiers;
287 wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
290 if ( eventType != NSFlagsChanged )
292 NSString* nschars = (wxevent.GetEventType() != wxEVT_CHAR) ? [nsEvent charactersIgnoringModifiers] : [nsEvent characters];
295 // if charString is set, it did not come from key up / key down
296 wxevent.SetEventType( wxEVT_CHAR );
297 wxCFStringRef cfchars((CFStringRef)[charString retain]);
298 chars = cfchars.AsString();
302 wxCFStringRef cfchars((CFStringRef)[nschars retain]);
303 chars = cfchars.AsString();
307 int aunichar = chars.Length() > 0 ? chars[0] : 0;
310 if (wxevent.GetEventType() != wxEVT_CHAR)
312 keyval = wxOSXTranslateCocoaKey(nsEvent) ;
316 wxevent.SetEventType( wxEVT_KEY_DOWN ) ;
319 wxevent.SetEventType( wxEVT_KEY_UP ) ;
321 case NSFlagsChanged :
325 wxevent.SetEventType( wxevent.m_controlDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
328 wxevent.SetEventType( wxevent.m_shiftDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
331 wxevent.SetEventType( wxevent.m_altDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
334 wxevent.SetEventType( wxevent.m_metaDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
345 if ( wxevent.GetEventType() == wxEVT_KEY_UP || wxevent.GetEventType() == wxEVT_KEY_DOWN )
346 keyval = wxToupper( aunichar ) ;
352 wxevent.m_uniChar = aunichar;
354 wxevent.m_keyCode = keyval;
357 UInt32 g_lastButton = 0 ;
358 bool g_lastButtonWasFakeRight = false ;
360 void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
362 int eventType = [nsEvent type];
363 UInt32 modifiers = [nsEvent modifierFlags] ;
364 wxPoint screenMouseLocation = wxFromNSPoint( NULL, [nsEvent locationInWindow]);
366 // these parameters are not given for all events
367 UInt32 button = [nsEvent buttonNumber];
368 UInt32 clickCount = 0;
370 wxevent.m_x = screenMouseLocation.x;
371 wxevent.m_y = screenMouseLocation.y;
372 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
373 wxevent.m_controlDown = modifiers & NSControlKeyMask;
374 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
375 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
376 wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
378 UInt32 mouseChord = 0;
382 case NSLeftMouseDown :
383 case NSLeftMouseDragged :
386 case NSRightMouseDown :
387 case NSRightMouseDragged :
390 case NSOtherMouseDown :
391 case NSOtherMouseDragged :
396 // a control click is interpreted as a right click
397 bool thisButtonIsFakeRight = false ;
398 if ( button == 0 && (modifiers & NSControlKeyMask) )
401 thisButtonIsFakeRight = true ;
404 // otherwise we report double clicks by connecting a left click with a ctrl-left click
405 if ( clickCount > 1 && button != g_lastButton )
408 // we must make sure that our synthetic 'right' button corresponds in
409 // mouse down, moved and mouse up, and does not deliver a right down and left up
412 case NSLeftMouseDown :
413 case NSRightMouseDown :
414 case NSOtherMouseDown :
415 g_lastButton = button ;
416 g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
423 g_lastButtonWasFakeRight = false ;
425 else if ( g_lastButton == 1 && g_lastButtonWasFakeRight )
426 button = g_lastButton ;
428 // Adjust the chord mask to remove the primary button and add the
429 // secondary button. It is possible that the secondary button is
430 // already pressed, e.g. on a mouse connected to a laptop, but this
431 // possibility is ignored here:
432 if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
433 mouseChord = ((mouseChord & ~1U) | 2U);
436 wxevent.m_leftDown = true ;
438 wxevent.m_rightDown = true ;
440 wxevent.m_middleDown = true ;
442 // translate into wx types
445 case NSLeftMouseDown :
446 case NSRightMouseDown :
447 case NSOtherMouseDown :
448 clickCount = [nsEvent clickCount];
452 wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
456 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
460 wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
469 case NSRightMouseUp :
470 case NSOtherMouseUp :
471 clickCount = [nsEvent clickCount];
475 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
479 wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
483 wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
493 wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
494 wxevent.m_wheelDelta = 10;
495 wxevent.m_linesPerAction = 1;
497 if ( fabs([nsEvent deltaX]) > fabs([nsEvent deltaY]) )
499 wxevent.m_wheelAxis = 1;
500 wxevent.m_wheelRotation = [nsEvent deltaX] * 10.0;
504 wxevent.m_wheelRotation = [nsEvent deltaY] * 10.0;
509 case NSMouseEntered :
510 wxevent.SetEventType( wxEVT_ENTER_WINDOW ) ;
513 wxevent.SetEventType( wxEVT_LEAVE_WINDOW ) ;
515 case NSLeftMouseDragged :
516 case NSRightMouseDragged :
517 case NSOtherMouseDragged :
519 wxevent.SetEventType( wxEVT_MOTION ) ;
525 wxevent.m_clickCount = clickCount;
529 @implementation wxNSView
533 static BOOL initialized = NO;
537 wxOSXCocoaClassAddWXMethods( self );
541 - (void) setTrackingTag: (NSTrackingRectTag)tag
546 - (NSTrackingRectTag) trackingTag
557 #if wxUSE_DRAG_AND_DROP
559 // see http://lists.apple.com/archives/Cocoa-dev/2005/Jul/msg01244.html
560 // for details on the NSPasteboard -> PasteboardRef conversion
562 NSDragOperation wxOSX_draggingEntered( id self, SEL _cmd, id <NSDraggingInfo>sender )
564 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
566 return NSDragOperationNone;
568 return impl->draggingEntered(sender, self, _cmd);
571 void wxOSX_draggingExited( id self, SEL _cmd, id <NSDraggingInfo> sender )
573 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
577 return impl->draggingExited(sender, self, _cmd);
580 NSDragOperation wxOSX_draggingUpdated( id self, SEL _cmd, id <NSDraggingInfo>sender )
582 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
584 return NSDragOperationNone;
586 return impl->draggingUpdated(sender, self, _cmd);
589 BOOL wxOSX_performDragOperation( id self, SEL _cmd, id <NSDraggingInfo> sender )
591 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
593 return NSDragOperationNone;
595 return impl->performDragOperation(sender, self, _cmd) ? YES:NO ;
600 void wxOSX_mouseEvent(NSView* self, SEL _cmd, NSEvent *event)
602 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
606 impl->mouseEvent(event, self, _cmd);
609 void wxOSX_keyEvent(NSView* self, SEL _cmd, NSEvent *event)
611 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
615 impl->keyEvent(event, self, _cmd);
618 void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text)
620 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
624 impl->insertText(text, self, _cmd);
627 BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event)
629 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
633 return impl->performKeyEquivalent(event, self, _cmd);
636 BOOL wxOSX_acceptsFirstResponder(NSView* self, SEL _cmd)
638 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
642 return impl->acceptsFirstResponder(self, _cmd);
645 BOOL wxOSX_becomeFirstResponder(NSView* self, SEL _cmd)
647 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
651 return impl->becomeFirstResponder(self, _cmd);
654 BOOL wxOSX_resignFirstResponder(NSView* self, SEL _cmd)
656 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
660 return impl->resignFirstResponder(self, _cmd);
663 void wxOSX_resetCursorRects(NSView* self, SEL _cmd)
665 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
669 impl->resetCursorRects(self, _cmd);
672 BOOL wxOSX_isFlipped(NSView* self, SEL _cmd)
674 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
678 return impl->isFlipped(self, _cmd) ? YES:NO;
681 void wxOSX_drawRect(NSView* self, SEL _cmd, NSRect rect)
683 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
687 return impl->drawRect(&rect, self, _cmd);
690 void wxOSX_controlAction(NSView* self, SEL _cmd, id sender)
692 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
696 impl->controlAction(self, _cmd, sender);
699 void wxOSX_controlDoubleAction(NSView* self, SEL _cmd, id sender)
701 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
705 impl->controlDoubleAction(self, _cmd, sender);
708 unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
710 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
711 NSPasteboard *pboard = [sender draggingPasteboard];
712 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
714 wxWindow* wxpeer = GetWXPeer();
715 if ( wxpeer == NULL )
716 return NSDragOperationNone;
718 wxDropTarget* target = wxpeer->GetDropTarget();
719 if ( target == NULL )
720 return NSDragOperationNone;
722 wxDragResult result = wxDragNone;
723 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
724 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
726 if ( sourceDragMask & NSDragOperationLink )
728 else if ( sourceDragMask & NSDragOperationCopy )
730 else if ( sourceDragMask & NSDragOperationMove )
733 PasteboardRef pboardRef;
734 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
735 target->SetCurrentDragPasteboard(pboardRef);
736 result = target->OnEnter(pt.x, pt.y, result);
737 CFRelease(pboardRef);
739 NSDragOperation nsresult = NSDragOperationNone;
743 nsresult = NSDragOperationLink;
745 nsresult = NSDragOperationMove;
747 nsresult = NSDragOperationCopy;
754 void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
756 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
757 NSPasteboard *pboard = [sender draggingPasteboard];
759 wxWindow* wxpeer = GetWXPeer();
760 if ( wxpeer == NULL )
763 wxDropTarget* target = wxpeer->GetDropTarget();
764 if ( target == NULL )
767 PasteboardRef pboardRef;
768 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
769 target->SetCurrentDragPasteboard(pboardRef);
771 CFRelease(pboardRef);
774 unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
776 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
777 NSPasteboard *pboard = [sender draggingPasteboard];
778 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
780 wxWindow* wxpeer = GetWXPeer();
781 if ( wxpeer == NULL )
782 return NSDragOperationNone;
784 wxDropTarget* target = wxpeer->GetDropTarget();
785 if ( target == NULL )
786 return NSDragOperationNone;
788 wxDragResult result = wxDragNone;
789 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
790 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
792 if ( sourceDragMask & NSDragOperationLink )
794 else if ( sourceDragMask & NSDragOperationCopy )
796 else if ( sourceDragMask & NSDragOperationMove )
799 PasteboardRef pboardRef;
800 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
801 target->SetCurrentDragPasteboard(pboardRef);
802 result = target->OnDragOver(pt.x, pt.y, result);
803 CFRelease(pboardRef);
805 NSDragOperation nsresult = NSDragOperationNone;
809 nsresult = NSDragOperationLink;
811 nsresult = NSDragOperationMove;
813 nsresult = NSDragOperationCopy;
820 bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
822 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
824 NSPasteboard *pboard = [sender draggingPasteboard];
825 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
827 wxWindow* wxpeer = GetWXPeer();
828 wxDropTarget* target = wxpeer->GetDropTarget();
829 wxDragResult result = wxDragNone;
830 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
831 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
833 if ( sourceDragMask & NSDragOperationLink )
835 else if ( sourceDragMask & NSDragOperationCopy )
837 else if ( sourceDragMask & NSDragOperationMove )
840 PasteboardRef pboardRef;
841 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
842 target->SetCurrentDragPasteboard(pboardRef);
844 if (target->OnDrop(pt.x, pt.y))
845 result = target->OnData(pt.x, pt.y, result);
847 CFRelease(pboardRef);
849 return result != wxDragNone;
852 typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
853 typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
854 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
855 typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
856 typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
857 typedef BOOL (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
859 void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
861 if ( !DoHandleMouseEvent(event) )
863 // for plain NSView mouse events would propagate to parents otherwise
864 if (!m_wxPeer->MacIsUserPane())
866 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
867 superimpl(slf, (SEL)_cmd, event);
872 void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
874 if ( GetFocusedViewInWindow([slf window]) != slf || m_hasEditor || !DoHandleKeyEvent(event) )
876 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
877 superimpl(slf, (SEL)_cmd, event);
881 void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
883 if ( m_lastKeyDownEvent==NULL || m_hasEditor || !DoHandleCharEvent(m_lastKeyDownEvent, text) )
885 wxOSX_TextEventHandlerPtr superimpl = (wxOSX_TextEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
886 superimpl(slf, (SEL)_cmd, text);
888 m_lastKeyDownEvent = NULL;
892 bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
894 wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
895 return superimpl(slf, (SEL)_cmd, event);
898 bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
900 if ( m_wxPeer->MacIsUserPane() )
901 return m_wxPeer->AcceptsFocus();
904 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
905 return superimpl(slf, (SEL)_cmd);
909 bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
911 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
912 // get the current focus before running becomeFirstResponder
913 NSView* otherView = FindFocus();
915 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
916 BOOL r = superimpl(slf, (SEL)_cmd);
919 DoNotifyFocusEvent( true, otherWindow );
925 bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
927 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
928 BOOL r = superimpl(slf, (SEL)_cmd);
929 // get the current focus after running resignFirstResponder
930 // note that this value isn't reliable, it might return the same view that
932 NSView* otherView = FindFocus();
933 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
934 // NSTextViews have an editor as true responder, therefore the might get the
935 // resign notification if their editor takes over, don't trigger any event then
936 if ( r && !m_hasEditor)
938 DoNotifyFocusEvent( false, otherWindow );
943 void wxWidgetCocoaImpl::resetCursorRects(WXWidget slf, void *_cmd)
945 wxWindow* wxpeer = GetWXPeer();
948 NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();
951 wxOSX_ResetCursorRectsHandlerPtr superimpl = (wxOSX_ResetCursorRectsHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
952 superimpl(slf, (SEL)_cmd);
956 [slf addCursorRect: [slf bounds]
962 bool wxWidgetCocoaImpl::isFlipped(WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
968 #define OSX_DEBUG_DRAWING 0
970 void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
972 CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
973 CGContextSaveGState( context );
975 #if OSX_DEBUG_DRAWING
976 CGContextBeginPath( context );
977 CGContextMoveToPoint(context, 0, 0);
978 NSRect bounds = [self bounds];
979 CGContextAddLineToPoint(context, 10, 0);
980 CGContextMoveToPoint(context, 0, 0);
981 CGContextAddLineToPoint(context, 0, 10);
982 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
983 CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
984 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
985 CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
986 CGContextClosePath( context );
987 CGContextStrokePath(context);
992 CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
993 CGContextScaleCTM( context, 1, -1 );
1000 [slf getRectsBeingDrawn:&rects count:&count];
1001 for ( int i = 0 ; i < count ; ++i )
1003 updateRgn.Union(wxFromNSRect(slf, rects[i]) );
1006 wxWindow* wxpeer = GetWXPeer();
1007 wxpeer->GetUpdateRegion() = updateRgn;
1008 wxpeer->MacSetCGContextRef( context );
1010 bool handled = wxpeer->MacDoRedraw( 0 );
1012 CGContextRestoreGState( context );
1014 CGContextSaveGState( context );
1018 SEL _cmd = @selector(drawRect:);
1019 wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
1020 superimpl(slf, _cmd, *(NSRect*)rect);
1021 CGContextRestoreGState( context );
1022 CGContextSaveGState( context );
1024 wxpeer->MacPaintChildrenBorders();
1025 wxpeer->MacSetCGContextRef( NULL );
1026 CGContextRestoreGState( context );
1029 void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
1031 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
1033 wxpeer->OSXHandleClicked(0);
1036 void wxWidgetCocoaImpl::controlDoubleAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
1042 #if OBJC_API_VERSION >= 2
1044 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1045 class_addMethod(c, s, i, t );
1049 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1054 void wxOSXCocoaClassAddWXMethods(Class c)
1057 #if OBJC_API_VERSION < 2
1058 static objc_method wxmethods[] =
1062 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1063 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1064 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1066 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1067 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1068 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1070 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseMoved:), (IMP) wxOSX_mouseEvent, "v@:@" )
1072 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1073 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1074 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1076 wxOSX_CLASS_ADD_METHOD(c, @selector(scrollWheel:), (IMP) wxOSX_mouseEvent, "v@:@" )
1077 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
1078 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
1080 wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
1081 wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
1082 wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
1084 wxOSX_CLASS_ADD_METHOD(c, @selector(insertText:), (IMP) wxOSX_insertText, "v@:@" )
1086 wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "c@:@" )
1088 wxOSX_CLASS_ADD_METHOD(c, @selector(acceptsFirstResponder), (IMP) wxOSX_acceptsFirstResponder, "c@:" )
1089 wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
1090 wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
1091 wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
1093 wxOSX_CLASS_ADD_METHOD(c, @selector(isFlipped), (IMP) wxOSX_isFlipped, "c@:" )
1094 wxOSX_CLASS_ADD_METHOD(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}" )
1096 wxOSX_CLASS_ADD_METHOD(c, @selector(controlAction:), (IMP) wxOSX_controlAction, "v@:@" )
1097 wxOSX_CLASS_ADD_METHOD(c, @selector(controlDoubleAction:), (IMP) wxOSX_controlDoubleAction, "v@:@" )
1099 #if wxUSE_DRAG_AND_DROP
1100 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingEntered:), (IMP) wxOSX_draggingEntered, "I@:@" )
1101 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingUpdated:), (IMP) wxOSX_draggingUpdated, "I@:@" )
1102 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingExited:), (IMP) wxOSX_draggingExited, "v@:@" )
1103 wxOSX_CLASS_ADD_METHOD(c, @selector(performDragOperation:), (IMP) wxOSX_performDragOperation, "c@:@" )
1106 #if OBJC_API_VERSION < 2
1108 static int method_count = WXSIZEOF( wxmethods );
1109 static objc_method_list *wxmethodlist = NULL;
1110 if ( wxmethodlist == NULL )
1112 wxmethodlist = (objc_method_list*) malloc(sizeof(objc_method_list) + sizeof(wxmethods) );
1113 memcpy( &wxmethodlist->method_list[0], &wxmethods[0], sizeof(wxmethods) );
1114 wxmethodlist->method_count = method_count;
1115 wxmethodlist->obsolete = 0;
1117 class_addMethods( c, wxmethodlist );
1122 // C++ implementation class
1125 IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
1127 wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
1128 wxWidgetImpl( peer, isRootControl )
1134 wxWidgetCocoaImpl::wxWidgetCocoaImpl()
1139 void wxWidgetCocoaImpl::Init()
1143 m_lastKeyDownEvent = NULL;
1144 m_hasEditor = false;
1147 wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
1149 RemoveAssociations( this );
1151 if ( !IsRootControl() )
1153 NSView *sv = [m_osxView superview];
1155 [m_osxView removeFromSuperview];
1157 [m_osxView release];
1160 bool wxWidgetCocoaImpl::IsVisible() const
1162 return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
1165 void wxWidgetCocoaImpl::SetVisibility( bool visible )
1167 [m_osxView setHidden:(visible ? NO:YES)];
1170 void wxWidgetCocoaImpl::Raise()
1174 void wxWidgetCocoaImpl::Lower()
1178 void wxWidgetCocoaImpl::ScrollRect( const wxRect *WXUNUSED(rect), int WXUNUSED(dx), int WXUNUSED(dy) )
1183 // We should do something like this, but it wasn't working in 10.4.
1184 if (GetNeedsDisplay() )
1188 NSRect r = wxToNSRect( [m_osxView superview], *rect );
1189 NSSize offset = NSMakeSize((float)dx, (float)dy);
1190 [m_osxView scrollRect:r by:offset];
1194 void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
1196 wxWindowMac* parent = GetWXPeer()->GetParent();
1197 // under Cocoa we might have a contentView in the wxParent to which we have to
1198 // adjust the coordinates
1199 if (parent && [m_osxView superview] != parent->GetHandle() )
1201 int cx = 0,cy = 0,cw = 0,ch = 0;
1202 if ( parent->GetPeer() )
1204 parent->GetPeer()->GetContentArea(cx, cy, cw, ch);
1209 [[m_osxView superview] setNeedsDisplayInRect:[m_osxView frame]];
1210 NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
1211 [m_osxView setFrame:r];
1212 [[m_osxView superview] setNeedsDisplayInRect:r];
1214 if ([m_osxView respondsToSelector:@selector(trackingTag)] )
1216 if ( [(wxNSView*)m_osxView trackingTag] )
1217 [m_osxView removeTrackingRect: [(wxNSView*)m_osxView trackingTag]];
1219 [(wxNSView*)m_osxView setTrackingTag: [m_osxView addTrackingRect: [m_osxView bounds] owner: m_osxView userData: nil assumeInside: NO]];
1223 void wxWidgetCocoaImpl::GetPosition( int &x, int &y ) const
1225 wxRect r = wxFromNSRect( [m_osxView superview], [m_osxView frame] );
1230 void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
1232 NSRect rect = [m_osxView frame];
1233 width = rect.size.width;
1234 height = rect.size.height;
1237 void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
1239 if ( [m_osxView respondsToSelector:@selector(contentView) ] )
1241 NSView* cv = [m_osxView contentView];
1243 NSRect bounds = [m_osxView bounds];
1244 NSRect rect = [cv frame];
1246 int y = rect.origin.y;
1247 int x = rect.origin.x;
1248 if ( ![ m_osxView isFlipped ] )
1249 y = bounds.size.height - (rect.origin.y + rect.size.height);
1252 width = rect.size.width;
1253 height = rect.size.height;
1258 GetSize( width, height );
1262 void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
1265 [m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )];
1267 [m_osxView setNeedsDisplay:YES];
1270 bool wxWidgetCocoaImpl::GetNeedsDisplay() const
1272 return [m_osxView needsDisplay];
1275 bool wxWidgetCocoaImpl::CanFocus() const
1277 return [m_osxView canBecomeKeyView] == YES;
1280 bool wxWidgetCocoaImpl::HasFocus() const
1282 return ( FindFocus() == m_osxView );
1285 bool wxWidgetCocoaImpl::SetFocus()
1287 if ( [m_osxView canBecomeKeyView] == NO )
1290 [[m_osxView window] makeFirstResponder: m_osxView] ;
1291 [[m_osxView window] makeKeyAndOrderFront:nil] ;
1296 void wxWidgetCocoaImpl::RemoveFromParent()
1298 [m_osxView removeFromSuperview];
1301 void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
1303 NSView* container = parent->GetWXWidget() ;
1304 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
1305 [container addSubview:m_osxView];
1308 void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
1310 // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
1313 void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
1315 if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
1317 wxCFStringRef cf( title , encoding );
1318 [m_osxView setTitle:cf.AsNSString()];
1320 else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
1322 wxCFStringRef cf( title , encoding );
1323 [m_osxView setStringValue:cf.AsNSString()];
1328 void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
1330 NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
1331 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
1332 *pt = wxFromNSPoint( to->GetWXWidget(), p );
1335 wxInt32 wxWidgetCocoaImpl::GetValue() const
1337 return [(NSControl*)m_osxView intValue];
1340 void wxWidgetCocoaImpl::SetValue( wxInt32 v )
1342 if ( [m_osxView respondsToSelector:@selector(setIntValue:)] )
1344 [m_osxView setIntValue:v];
1346 else if ( [m_osxView respondsToSelector:@selector(setFloatValue:)] )
1348 [m_osxView setFloatValue:(double)v];
1350 else if ( [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
1352 [m_osxView setDoubleValue:(double)v];
1356 void wxWidgetCocoaImpl::SetMinimum( wxInt32 v )
1358 if ( [m_osxView respondsToSelector:@selector(setMinValue:)] )
1360 [m_osxView setMinValue:(double)v];
1364 void wxWidgetCocoaImpl::SetMaximum( wxInt32 v )
1366 if ( [m_osxView respondsToSelector:@selector(setMaxValue:)] )
1368 [m_osxView setMaxValue:(double)v];
1372 wxInt32 wxWidgetCocoaImpl::GetMinimum() const
1374 if ( [m_osxView respondsToSelector:@selector(getMinValue:)] )
1376 return [m_osxView minValue];
1381 wxInt32 wxWidgetCocoaImpl::GetMaximum() const
1383 if ( [m_osxView respondsToSelector:@selector(getMaxValue:)] )
1385 return [m_osxView maxValue];
1390 void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
1392 if ( [m_osxView respondsToSelector:@selector(setImage:)] )
1394 [m_osxView setImage:bitmap.GetNSImage()];
1398 void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& WXUNUSED(notebook))
1400 // implementation in subclass
1403 void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
1405 r->x = r->y = r->width = r->height = 0;
1407 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
1409 NSRect former = [m_osxView frame];
1410 [m_osxView sizeToFit];
1411 NSRect best = [m_osxView frame];
1412 [m_osxView setFrame:former];
1413 r->width = best.size.width;
1414 r->height = best.size.height;
1418 bool wxWidgetCocoaImpl::IsEnabled() const
1420 if ( [m_osxView respondsToSelector:@selector(isEnabled) ] )
1421 return [m_osxView isEnabled];
1425 void wxWidgetCocoaImpl::Enable( bool enable )
1427 if ( [m_osxView respondsToSelector:@selector(setEnabled:) ] )
1428 [m_osxView setEnabled:enable];
1431 void wxWidgetCocoaImpl::PulseGauge()
1435 void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 WXUNUSED(val), wxInt32 WXUNUSED(view) )
1439 void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
1441 NSControlSize size = NSRegularControlSize;
1445 case wxWINDOW_VARIANT_NORMAL :
1446 size = NSRegularControlSize;
1449 case wxWINDOW_VARIANT_SMALL :
1450 size = NSSmallControlSize;
1453 case wxWINDOW_VARIANT_MINI :
1454 size = NSMiniControlSize;
1457 case wxWINDOW_VARIANT_LARGE :
1458 size = NSRegularControlSize;
1462 wxFAIL_MSG(_T("unexpected window variant"));
1465 if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
1466 [m_osxView setControlSize:size];
1469 void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
1471 if ([m_osxView respondsToSelector:@selector(setFont:)])
1472 [m_osxView setFont: font.OSXGetNSFont()];
1475 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
1477 WXWidget c = control ? control : (WXWidget) m_osxView;
1478 wxWidgetImpl::Associate( c, this ) ;
1479 if ([c respondsToSelector:@selector(setAction:)])
1482 [c setAction: @selector(controlAction:)];
1483 if ([c respondsToSelector:@selector(setDoubleAction:)])
1485 [c setDoubleAction: @selector(controlDoubleAction:)];
1491 bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
1493 wxKeyEvent wxevent(wxEVT_CHAR);
1494 SetupKeyEvent( wxevent, event, text );
1495 wxevent.SetEventObject(GetWXPeer());
1497 return GetWXPeer()->OSXHandleKeyEvent(wxevent);
1500 bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
1502 wxKeyEvent wxevent(wxEVT_KEY_DOWN);
1503 SetupKeyEvent( wxevent, event );
1504 wxevent.SetEventObject(GetWXPeer());
1505 bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
1507 // this will fire higher level events, like insertText, to help
1508 // us handle EVT_CHAR, etc.
1509 if ( !m_hasEditor && [event type] == NSKeyDown)
1511 m_lastKeyDownEvent = event;
1514 if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
1515 [[(NSScrollView*)m_osxView documentView] interpretKeyEvents:[NSArray arrayWithObject:event]];
1517 [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
1524 bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
1526 NSPoint clickLocation;
1527 clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil];
1528 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
1529 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
1530 SetupMouseEvent( wxevent , event ) ;
1531 wxevent.SetEventObject(GetWXPeer());
1535 return GetWXPeer()->HandleWindowEvent(wxevent);
1538 void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
1540 wxWindow* thisWindow = GetWXPeer();
1541 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
1543 thisWindow->MacInvalidateBorders();
1546 if ( receivedFocus )
1548 wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
1549 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
1550 thisWindow->HandleWindowEvent(eventFocus);
1553 if ( thisWindow->GetCaret() )
1554 thisWindow->GetCaret()->OnSetFocus();
1557 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
1558 event.SetEventObject(thisWindow);
1560 event.SetWindow(otherWindow->GetWXPeer());
1561 thisWindow->HandleWindowEvent(event) ;
1563 else // !receivedFocuss
1566 if ( thisWindow->GetCaret() )
1567 thisWindow->GetCaret()->OnKillFocus();
1570 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
1572 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
1573 event.SetEventObject(thisWindow);
1575 event.SetWindow(otherWindow->GetWXPeer());
1576 thisWindow->HandleWindowEvent(event) ;
1580 void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor)
1582 NSPoint location = [NSEvent mouseLocation];
1583 location = [[m_osxView window] convertScreenToBase:location];
1584 NSPoint locationInView = [m_osxView convertPoint:location fromView:nil];
1586 if( NSMouseInRect(locationInView, [m_osxView bounds], YES) )
1588 [(NSCursor*)cursor.GetHCURSOR() set];
1590 [[m_osxView window] invalidateCursorRectsForView:m_osxView];
1593 void wxWidgetCocoaImpl::CaptureMouse()
1595 [[m_osxView window] disableCursorRects];
1598 void wxWidgetCocoaImpl::ReleaseMouse()
1600 [[m_osxView window] enableCursorRects];
1603 void wxWidgetCocoaImpl::SetFlipped(bool flipped)
1605 m_isFlipped = flipped;
1612 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
1613 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
1614 long WXUNUSED(style), long WXUNUSED(extraStyle))
1616 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
1617 wxNSView* v = [[wxNSView alloc] initWithFrame:r];
1619 // temporary hook for dnd
1620 [v registerForDraggedTypes:[NSArray arrayWithObjects:
1621 NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
1623 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
1627 wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
1629 NSWindow* tlw = now->GetWXWindow();
1630 wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
1631 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
1632 c->InstallEventHandler();
1633 [tlw setContentView:v];