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 wxWidgetCocoaImpl::SetupKeyEvent(wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charString)
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( (int)([nsEvent timestamp] * 1000) ) ;
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 chars = wxCFStringRef::AsString(charString);
301 chars = wxCFStringRef::AsString(nschars);
305 int aunichar = chars.Length() > 0 ? chars[0] : 0;
308 if (wxevent.GetEventType() != wxEVT_CHAR)
310 keyval = wxOSXTranslateCocoaKey(nsEvent) ;
314 wxevent.SetEventType( wxEVT_KEY_DOWN ) ;
317 wxevent.SetEventType( wxEVT_KEY_UP ) ;
319 case NSFlagsChanged :
323 wxevent.SetEventType( wxevent.m_controlDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
326 wxevent.SetEventType( wxevent.m_shiftDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
329 wxevent.SetEventType( wxevent.m_altDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
332 wxevent.SetEventType( wxevent.m_metaDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
343 if ( wxevent.GetEventType() == wxEVT_KEY_UP || wxevent.GetEventType() == wxEVT_KEY_DOWN )
344 keyval = wxToupper( aunichar ) ;
350 wxevent.m_uniChar = aunichar;
352 wxevent.m_keyCode = keyval;
354 wxWindowMac* peer = GetWXPeer();
357 wxevent.SetEventObject(peer);
358 wxevent.SetId(peer->GetId()) ;
362 UInt32 g_lastButton = 0 ;
363 bool g_lastButtonWasFakeRight = false ;
365 void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
367 int eventType = [nsEvent type];
368 UInt32 modifiers = [nsEvent modifierFlags] ;
369 wxPoint screenMouseLocation = wxFromNSPoint( NULL, [nsEvent locationInWindow]);
371 // these parameters are not given for all events
372 UInt32 button = [nsEvent buttonNumber];
373 UInt32 clickCount = 0;
375 wxevent.m_x = screenMouseLocation.x;
376 wxevent.m_y = screenMouseLocation.y;
377 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
378 wxevent.m_controlDown = modifiers & NSControlKeyMask;
379 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
380 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
381 wxevent.SetTimestamp( (int)([nsEvent timestamp] * 1000) ) ;
383 UInt32 mouseChord = 0;
387 case NSLeftMouseDown :
388 case NSLeftMouseDragged :
391 case NSRightMouseDown :
392 case NSRightMouseDragged :
395 case NSOtherMouseDown :
396 case NSOtherMouseDragged :
401 // a control click is interpreted as a right click
402 bool thisButtonIsFakeRight = false ;
403 if ( button == 0 && (modifiers & NSControlKeyMask) )
406 thisButtonIsFakeRight = true ;
409 // otherwise we report double clicks by connecting a left click with a ctrl-left click
410 if ( clickCount > 1 && button != g_lastButton )
413 // we must make sure that our synthetic 'right' button corresponds in
414 // mouse down, moved and mouse up, and does not deliver a right down and left up
417 case NSLeftMouseDown :
418 case NSRightMouseDown :
419 case NSOtherMouseDown :
420 g_lastButton = button ;
421 g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
428 g_lastButtonWasFakeRight = false ;
430 else if ( g_lastButton == 1 && g_lastButtonWasFakeRight )
431 button = g_lastButton ;
433 // Adjust the chord mask to remove the primary button and add the
434 // secondary button. It is possible that the secondary button is
435 // already pressed, e.g. on a mouse connected to a laptop, but this
436 // possibility is ignored here:
437 if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
438 mouseChord = ((mouseChord & ~1U) | 2U);
441 wxevent.m_leftDown = true ;
443 wxevent.m_rightDown = true ;
445 wxevent.m_middleDown = true ;
447 // translate into wx types
450 case NSLeftMouseDown :
451 case NSRightMouseDown :
452 case NSOtherMouseDown :
453 clickCount = [nsEvent clickCount];
457 wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
461 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
465 wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
474 case NSRightMouseUp :
475 case NSOtherMouseUp :
476 clickCount = [nsEvent clickCount];
480 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
484 wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
488 wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
498 wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
499 wxevent.m_wheelDelta = 10;
500 wxevent.m_linesPerAction = 1;
502 if ( fabs([nsEvent deltaX]) > fabs([nsEvent deltaY]) )
504 wxevent.m_wheelAxis = 1;
505 wxevent.m_wheelRotation = (int)([nsEvent deltaX] * 10);
509 wxevent.m_wheelRotation = (int)([nsEvent deltaY] * 10);
514 case NSMouseEntered :
515 wxevent.SetEventType( wxEVT_ENTER_WINDOW ) ;
518 wxevent.SetEventType( wxEVT_LEAVE_WINDOW ) ;
520 case NSLeftMouseDragged :
521 case NSRightMouseDragged :
522 case NSOtherMouseDragged :
524 wxevent.SetEventType( wxEVT_MOTION ) ;
530 wxevent.m_clickCount = clickCount;
531 wxWindowMac* peer = GetWXPeer();
534 wxevent.SetEventObject(peer);
535 wxevent.SetId(peer->GetId()) ;
539 @implementation wxNSView
543 static BOOL initialized = NO;
547 wxOSXCocoaClassAddWXMethods( self );
551 - (void) setTrackingTag: (NSTrackingRectTag)tag
556 - (NSTrackingRectTag) trackingTag
567 #if wxUSE_DRAG_AND_DROP
569 // see http://lists.apple.com/archives/Cocoa-dev/2005/Jul/msg01244.html
570 // for details on the NSPasteboard -> PasteboardRef conversion
572 NSDragOperation wxOSX_draggingEntered( id self, SEL _cmd, id <NSDraggingInfo>sender )
574 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
576 return NSDragOperationNone;
578 return impl->draggingEntered(sender, self, _cmd);
581 void wxOSX_draggingExited( id self, SEL _cmd, id <NSDraggingInfo> sender )
583 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
587 return impl->draggingExited(sender, self, _cmd);
590 NSDragOperation wxOSX_draggingUpdated( id self, SEL _cmd, id <NSDraggingInfo>sender )
592 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
594 return NSDragOperationNone;
596 return impl->draggingUpdated(sender, self, _cmd);
599 BOOL wxOSX_performDragOperation( id self, SEL _cmd, id <NSDraggingInfo> sender )
601 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
603 return NSDragOperationNone;
605 return impl->performDragOperation(sender, self, _cmd) ? YES:NO ;
610 void wxOSX_mouseEvent(NSView* self, SEL _cmd, NSEvent *event)
612 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
616 impl->mouseEvent(event, self, _cmd);
619 void wxOSX_keyEvent(NSView* self, SEL _cmd, NSEvent *event)
621 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
625 impl->keyEvent(event, self, _cmd);
628 void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text)
630 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
634 impl->insertText(text, self, _cmd);
637 BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event)
639 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
643 return impl->performKeyEquivalent(event, self, _cmd);
646 BOOL wxOSX_acceptsFirstResponder(NSView* self, SEL _cmd)
648 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
652 return impl->acceptsFirstResponder(self, _cmd);
655 BOOL wxOSX_becomeFirstResponder(NSView* self, SEL _cmd)
657 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
661 return impl->becomeFirstResponder(self, _cmd);
664 BOOL wxOSX_resignFirstResponder(NSView* self, SEL _cmd)
666 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
670 return impl->resignFirstResponder(self, _cmd);
673 void wxOSX_resetCursorRects(NSView* self, SEL _cmd)
675 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
679 impl->resetCursorRects(self, _cmd);
682 BOOL wxOSX_isFlipped(NSView* self, SEL _cmd)
684 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
688 return impl->isFlipped(self, _cmd) ? YES:NO;
691 void wxOSX_drawRect(NSView* self, SEL _cmd, NSRect rect)
693 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
697 return impl->drawRect(&rect, self, _cmd);
700 void wxOSX_controlAction(NSView* self, SEL _cmd, id sender)
702 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
706 impl->controlAction(self, _cmd, sender);
709 void wxOSX_controlDoubleAction(NSView* self, SEL _cmd, id sender)
711 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
715 impl->controlDoubleAction(self, _cmd, sender);
718 unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
720 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
721 NSPasteboard *pboard = [sender draggingPasteboard];
722 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
724 wxWindow* wxpeer = GetWXPeer();
725 if ( wxpeer == NULL )
726 return NSDragOperationNone;
728 wxDropTarget* target = wxpeer->GetDropTarget();
729 if ( target == NULL )
730 return NSDragOperationNone;
732 wxDragResult result = wxDragNone;
733 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
734 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
736 if ( sourceDragMask & NSDragOperationLink )
738 else if ( sourceDragMask & NSDragOperationCopy )
740 else if ( sourceDragMask & NSDragOperationMove )
743 PasteboardRef pboardRef;
744 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
745 target->SetCurrentDragPasteboard(pboardRef);
746 result = target->OnEnter(pt.x, pt.y, result);
747 CFRelease(pboardRef);
749 NSDragOperation nsresult = NSDragOperationNone;
753 nsresult = NSDragOperationLink;
755 nsresult = NSDragOperationMove;
757 nsresult = NSDragOperationCopy;
764 void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
766 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
767 NSPasteboard *pboard = [sender draggingPasteboard];
769 wxWindow* wxpeer = GetWXPeer();
770 if ( wxpeer == NULL )
773 wxDropTarget* target = wxpeer->GetDropTarget();
774 if ( target == NULL )
777 PasteboardRef pboardRef;
778 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
779 target->SetCurrentDragPasteboard(pboardRef);
781 CFRelease(pboardRef);
784 unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
786 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
787 NSPasteboard *pboard = [sender draggingPasteboard];
788 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
790 wxWindow* wxpeer = GetWXPeer();
791 if ( wxpeer == NULL )
792 return NSDragOperationNone;
794 wxDropTarget* target = wxpeer->GetDropTarget();
795 if ( target == NULL )
796 return NSDragOperationNone;
798 wxDragResult result = wxDragNone;
799 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
800 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
802 if ( sourceDragMask & NSDragOperationLink )
804 else if ( sourceDragMask & NSDragOperationCopy )
806 else if ( sourceDragMask & NSDragOperationMove )
809 PasteboardRef pboardRef;
810 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
811 target->SetCurrentDragPasteboard(pboardRef);
812 result = target->OnDragOver(pt.x, pt.y, result);
813 CFRelease(pboardRef);
815 NSDragOperation nsresult = NSDragOperationNone;
819 nsresult = NSDragOperationLink;
821 nsresult = NSDragOperationMove;
823 nsresult = NSDragOperationCopy;
830 bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
832 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
834 NSPasteboard *pboard = [sender draggingPasteboard];
835 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
837 wxWindow* wxpeer = GetWXPeer();
838 wxDropTarget* target = wxpeer->GetDropTarget();
839 wxDragResult result = wxDragNone;
840 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
841 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
843 if ( sourceDragMask & NSDragOperationLink )
845 else if ( sourceDragMask & NSDragOperationCopy )
847 else if ( sourceDragMask & NSDragOperationMove )
850 PasteboardRef pboardRef;
851 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
852 target->SetCurrentDragPasteboard(pboardRef);
854 if (target->OnDrop(pt.x, pt.y))
855 result = target->OnData(pt.x, pt.y, result);
857 CFRelease(pboardRef);
859 return result != wxDragNone;
862 typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
863 typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
864 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
865 typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
866 typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
867 typedef void (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
869 void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
871 if ( !DoHandleMouseEvent(event) )
873 // for plain NSView mouse events would propagate to parents otherwise
874 if (!m_wxPeer->MacIsUserPane())
876 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
877 superimpl(slf, (SEL)_cmd, event);
882 void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
884 if ( GetFocusedViewInWindow([slf window]) != slf || m_hasEditor || !DoHandleKeyEvent(event) )
886 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
887 superimpl(slf, (SEL)_cmd, event);
891 void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
893 if ( m_lastKeyDownEvent==NULL || m_hasEditor || !DoHandleCharEvent(m_lastKeyDownEvent, text) )
895 wxOSX_TextEventHandlerPtr superimpl = (wxOSX_TextEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
896 superimpl(slf, (SEL)_cmd, text);
898 m_lastKeyDownEvent = NULL;
902 bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
904 wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
905 return superimpl(slf, (SEL)_cmd, event);
908 bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
910 if ( m_wxPeer->MacIsUserPane() )
911 return m_wxPeer->AcceptsFocus();
914 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
915 return superimpl(slf, (SEL)_cmd);
919 bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
921 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
922 // get the current focus before running becomeFirstResponder
923 NSView* otherView = FindFocus();
925 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
926 BOOL r = superimpl(slf, (SEL)_cmd);
929 DoNotifyFocusEvent( true, otherWindow );
935 bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
937 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
938 BOOL r = superimpl(slf, (SEL)_cmd);
939 // get the current focus after running resignFirstResponder
940 // note that this value isn't reliable, it might return the same view that
942 NSView* otherView = FindFocus();
943 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
944 // NSTextViews have an editor as true responder, therefore the might get the
945 // resign notification if their editor takes over, don't trigger any event then
946 if ( r && !m_hasEditor)
948 DoNotifyFocusEvent( false, otherWindow );
953 void wxWidgetCocoaImpl::resetCursorRects(WXWidget slf, void *_cmd)
955 wxWindow* wxpeer = GetWXPeer();
958 NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();
961 wxOSX_ResetCursorRectsHandlerPtr superimpl = (wxOSX_ResetCursorRectsHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
962 superimpl(slf, (SEL)_cmd);
966 [slf addCursorRect: [slf bounds]
972 bool wxWidgetCocoaImpl::isFlipped(WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
978 #define OSX_DEBUG_DRAWING 0
980 void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
982 CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
983 CGContextSaveGState( context );
985 #if OSX_DEBUG_DRAWING
986 CGContextBeginPath( context );
987 CGContextMoveToPoint(context, 0, 0);
988 NSRect bounds = [self bounds];
989 CGContextAddLineToPoint(context, 10, 0);
990 CGContextMoveToPoint(context, 0, 0);
991 CGContextAddLineToPoint(context, 0, 10);
992 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
993 CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
994 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
995 CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
996 CGContextClosePath( context );
997 CGContextStrokePath(context);
1002 CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
1003 CGContextScaleCTM( context, 1, -1 );
1007 const NSRect *rects;
1010 [slf getRectsBeingDrawn:&rects count:&count];
1011 for ( int i = 0 ; i < count ; ++i )
1013 updateRgn.Union(wxFromNSRect(slf, rects[i]) );
1016 wxWindow* wxpeer = GetWXPeer();
1017 wxpeer->GetUpdateRegion() = updateRgn;
1018 wxpeer->MacSetCGContextRef( context );
1020 bool handled = wxpeer->MacDoRedraw( 0 );
1022 CGContextRestoreGState( context );
1024 CGContextSaveGState( context );
1028 SEL _cmd = @selector(drawRect:);
1029 wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
1030 superimpl(slf, _cmd, *(NSRect*)rect);
1031 CGContextRestoreGState( context );
1032 CGContextSaveGState( context );
1034 wxpeer->MacPaintChildrenBorders();
1035 wxpeer->MacSetCGContextRef( NULL );
1036 CGContextRestoreGState( context );
1039 void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
1041 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
1043 wxpeer->OSXHandleClicked(0);
1046 void wxWidgetCocoaImpl::controlDoubleAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
1052 #if OBJC_API_VERSION >= 2
1054 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1055 class_addMethod(c, s, i, t );
1059 #define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1064 void wxOSXCocoaClassAddWXMethods(Class c)
1067 #if OBJC_API_VERSION < 2
1068 static objc_method wxmethods[] =
1072 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1073 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1074 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1076 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1077 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1078 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1080 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseMoved:), (IMP) wxOSX_mouseEvent, "v@:@" )
1082 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1083 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1084 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1086 wxOSX_CLASS_ADD_METHOD(c, @selector(scrollWheel:), (IMP) wxOSX_mouseEvent, "v@:@" )
1087 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
1088 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
1090 wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
1091 wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
1092 wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
1094 wxOSX_CLASS_ADD_METHOD(c, @selector(insertText:), (IMP) wxOSX_insertText, "v@:@" )
1096 wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "c@:@" )
1098 wxOSX_CLASS_ADD_METHOD(c, @selector(acceptsFirstResponder), (IMP) wxOSX_acceptsFirstResponder, "c@:" )
1099 wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
1100 wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
1101 wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
1103 wxOSX_CLASS_ADD_METHOD(c, @selector(isFlipped), (IMP) wxOSX_isFlipped, "c@:" )
1104 wxOSX_CLASS_ADD_METHOD(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}" )
1106 wxOSX_CLASS_ADD_METHOD(c, @selector(controlAction:), (IMP) wxOSX_controlAction, "v@:@" )
1107 wxOSX_CLASS_ADD_METHOD(c, @selector(controlDoubleAction:), (IMP) wxOSX_controlDoubleAction, "v@:@" )
1109 #if wxUSE_DRAG_AND_DROP
1110 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingEntered:), (IMP) wxOSX_draggingEntered, "I@:@" )
1111 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingUpdated:), (IMP) wxOSX_draggingUpdated, "I@:@" )
1112 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingExited:), (IMP) wxOSX_draggingExited, "v@:@" )
1113 wxOSX_CLASS_ADD_METHOD(c, @selector(performDragOperation:), (IMP) wxOSX_performDragOperation, "c@:@" )
1116 #if OBJC_API_VERSION < 2
1118 static int method_count = WXSIZEOF( wxmethods );
1119 static objc_method_list *wxmethodlist = NULL;
1120 if ( wxmethodlist == NULL )
1122 wxmethodlist = (objc_method_list*) malloc(sizeof(objc_method_list) + sizeof(wxmethods) );
1123 memcpy( &wxmethodlist->method_list[0], &wxmethods[0], sizeof(wxmethods) );
1124 wxmethodlist->method_count = method_count;
1125 wxmethodlist->obsolete = 0;
1127 class_addMethods( c, wxmethodlist );
1132 // C++ implementation class
1135 IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
1137 wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
1138 wxWidgetImpl( peer, isRootControl )
1143 // check if the user wants to create the control initially hidden
1144 if ( !peer->IsShown() )
1145 SetVisibility(false);
1147 // gc aware handling
1149 CFRetain(m_osxView);
1150 [m_osxView release];
1153 wxWidgetCocoaImpl::wxWidgetCocoaImpl()
1158 void wxWidgetCocoaImpl::Init()
1162 m_lastKeyDownEvent = NULL;
1163 m_hasEditor = false;
1166 wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
1168 RemoveAssociations( this );
1170 if ( !IsRootControl() )
1172 NSView *sv = [m_osxView superview];
1174 [m_osxView removeFromSuperview];
1176 // gc aware handling
1178 CFRelease(m_osxView);
1181 bool wxWidgetCocoaImpl::IsVisible() const
1183 return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
1186 void wxWidgetCocoaImpl::SetVisibility( bool visible )
1188 [m_osxView setHidden:(visible ? NO:YES)];
1191 void wxWidgetCocoaImpl::Raise()
1196 void wxWidgetCocoaImpl::Lower()
1201 void wxWidgetCocoaImpl::ScrollRect( const wxRect *WXUNUSED(rect), int WXUNUSED(dx), int WXUNUSED(dy) )
1206 // We should do something like this, but it wasn't working in 10.4.
1207 if (GetNeedsDisplay() )
1211 NSRect r = wxToNSRect( [m_osxView superview], *rect );
1212 NSSize offset = NSMakeSize((float)dx, (float)dy);
1213 [m_osxView scrollRect:r by:offset];
1217 void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
1219 wxWindowMac* parent = GetWXPeer()->GetParent();
1220 // under Cocoa we might have a contentView in the wxParent to which we have to
1221 // adjust the coordinates
1222 if (parent && [m_osxView superview] != parent->GetHandle() )
1224 int cx = 0,cy = 0,cw = 0,ch = 0;
1225 if ( parent->GetPeer() )
1227 parent->GetPeer()->GetContentArea(cx, cy, cw, ch);
1232 [[m_osxView superview] setNeedsDisplayInRect:[m_osxView frame]];
1233 NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
1234 [m_osxView setFrame:r];
1235 [[m_osxView superview] setNeedsDisplayInRect:r];
1237 if ([m_osxView respondsToSelector:@selector(trackingTag)] )
1239 if ( [(wxNSView*)m_osxView trackingTag] )
1240 [m_osxView removeTrackingRect: [(wxNSView*)m_osxView trackingTag]];
1242 [(wxNSView*)m_osxView setTrackingTag: [m_osxView addTrackingRect: [m_osxView bounds] owner: m_osxView userData: nil assumeInside: NO]];
1246 void wxWidgetCocoaImpl::GetPosition( int &x, int &y ) const
1248 wxRect r = wxFromNSRect( [m_osxView superview], [m_osxView frame] );
1253 void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
1255 NSRect rect = [m_osxView frame];
1256 width = (int)rect.size.width;
1257 height = (int)rect.size.height;
1260 void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
1262 if ( [m_osxView respondsToSelector:@selector(contentView) ] )
1264 NSView* cv = [m_osxView contentView];
1266 NSRect bounds = [m_osxView bounds];
1267 NSRect rect = [cv frame];
1269 int y = (int)rect.origin.y;
1270 int x = (int)rect.origin.x;
1271 if ( ![ m_osxView isFlipped ] )
1272 y = (int)(bounds.size.height - (rect.origin.y + rect.size.height));
1275 width = (int)rect.size.width;
1276 height = (int)rect.size.height;
1281 GetSize( width, height );
1285 void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
1288 [m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )];
1290 [m_osxView setNeedsDisplay:YES];
1293 bool wxWidgetCocoaImpl::GetNeedsDisplay() const
1295 return [m_osxView needsDisplay];
1298 bool wxWidgetCocoaImpl::CanFocus() const
1300 return [m_osxView canBecomeKeyView] == YES;
1303 bool wxWidgetCocoaImpl::HasFocus() const
1305 return ( FindFocus() == m_osxView );
1308 bool wxWidgetCocoaImpl::SetFocus()
1310 if ( [m_osxView canBecomeKeyView] == NO )
1313 [[m_osxView window] makeFirstResponder: m_osxView] ;
1314 [[m_osxView window] makeKeyAndOrderFront:nil] ;
1319 void wxWidgetCocoaImpl::RemoveFromParent()
1321 [m_osxView removeFromSuperview];
1324 void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
1326 NSView* container = parent->GetWXWidget() ;
1327 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
1328 [container addSubview:m_osxView];
1331 void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
1333 // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
1336 void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
1338 if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
1340 wxCFStringRef cf( title , encoding );
1341 [m_osxView setTitle:cf.AsNSString()];
1343 else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
1345 wxCFStringRef cf( title , encoding );
1346 [m_osxView setStringValue:cf.AsNSString()];
1351 void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
1353 NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
1354 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
1355 *pt = wxFromNSPoint( to->GetWXWidget(), p );
1358 wxInt32 wxWidgetCocoaImpl::GetValue() const
1360 return [(NSControl*)m_osxView intValue];
1363 void wxWidgetCocoaImpl::SetValue( wxInt32 v )
1365 if ( [m_osxView respondsToSelector:@selector(setIntValue:)] )
1367 [m_osxView setIntValue:v];
1369 else if ( [m_osxView respondsToSelector:@selector(setFloatValue:)] )
1371 [m_osxView setFloatValue:(double)v];
1373 else if ( [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
1375 [m_osxView setDoubleValue:(double)v];
1379 void wxWidgetCocoaImpl::SetMinimum( wxInt32 v )
1381 if ( [m_osxView respondsToSelector:@selector(setMinValue:)] )
1383 [m_osxView setMinValue:(double)v];
1387 void wxWidgetCocoaImpl::SetMaximum( wxInt32 v )
1389 if ( [m_osxView respondsToSelector:@selector(setMaxValue:)] )
1391 [m_osxView setMaxValue:(double)v];
1395 wxInt32 wxWidgetCocoaImpl::GetMinimum() const
1397 if ( [m_osxView respondsToSelector:@selector(getMinValue:)] )
1399 return (int)[m_osxView minValue];
1404 wxInt32 wxWidgetCocoaImpl::GetMaximum() const
1406 if ( [m_osxView respondsToSelector:@selector(getMaxValue:)] )
1408 return (int)[m_osxView maxValue];
1413 wxBitmap wxWidgetCocoaImpl::GetBitmap() const
1417 // TODO: how to create a wxBitmap from NSImage?
1419 if ( [m_osxView respondsToSelector:@selector(image:)] )
1420 bmp = [m_osxView image];
1426 void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
1428 if ( [m_osxView respondsToSelector:@selector(setImage:)] )
1430 [m_osxView setImage:bitmap.GetNSImage()];
1434 void wxWidgetCocoaImpl::SetBitmapPosition( wxDirection dir )
1436 if ( [m_osxView respondsToSelector:@selector(setImagePosition:)] )
1438 NSCellImagePosition pos;
1458 wxFAIL_MSG( "invalid image position" );
1462 [m_osxView setImagePosition:pos];
1466 void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& WXUNUSED(notebook))
1468 // implementation in subclass
1471 void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
1473 r->x = r->y = r->width = r->height = 0;
1475 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
1477 NSRect former = [m_osxView frame];
1478 [m_osxView sizeToFit];
1479 NSRect best = [m_osxView frame];
1480 [m_osxView setFrame:former];
1481 r->width = (int)best.size.width;
1482 r->height = (int)best.size.height;
1486 bool wxWidgetCocoaImpl::IsEnabled() const
1488 if ( [m_osxView respondsToSelector:@selector(isEnabled) ] )
1489 return [m_osxView isEnabled];
1493 void wxWidgetCocoaImpl::Enable( bool enable )
1495 if ( [m_osxView respondsToSelector:@selector(setEnabled:) ] )
1496 [m_osxView setEnabled:enable];
1499 void wxWidgetCocoaImpl::PulseGauge()
1503 void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 WXUNUSED(val), wxInt32 WXUNUSED(view) )
1507 void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
1509 NSControlSize size = NSRegularControlSize;
1513 case wxWINDOW_VARIANT_NORMAL :
1514 size = NSRegularControlSize;
1517 case wxWINDOW_VARIANT_SMALL :
1518 size = NSSmallControlSize;
1521 case wxWINDOW_VARIANT_MINI :
1522 size = NSMiniControlSize;
1525 case wxWINDOW_VARIANT_LARGE :
1526 size = NSRegularControlSize;
1530 wxFAIL_MSG(wxT("unexpected window variant"));
1533 if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
1534 [m_osxView setControlSize:size];
1535 else if ([m_osxView respondsToSelector:@selector(cell)])
1537 id cell = [(id)m_osxView cell];
1538 if ([cell respondsToSelector:@selector(setControlSize:)])
1539 [cell setControlSize:size];
1543 void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
1545 if ([m_osxView respondsToSelector:@selector(setFont:)])
1546 [m_osxView setFont: font.OSXGetNSFont()];
1549 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
1551 WXWidget c = control ? control : (WXWidget) m_osxView;
1552 wxWidgetImpl::Associate( c, this ) ;
1553 if ([c respondsToSelector:@selector(setAction:)])
1556 [c setAction: @selector(controlAction:)];
1557 if ([c respondsToSelector:@selector(setDoubleAction:)])
1559 [c setDoubleAction: @selector(controlDoubleAction:)];
1565 bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
1567 wxKeyEvent wxevent(wxEVT_CHAR);
1568 SetupKeyEvent( wxevent, event, text );
1570 return GetWXPeer()->OSXHandleKeyEvent(wxevent);
1573 bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
1575 wxKeyEvent wxevent(wxEVT_KEY_DOWN);
1576 SetupKeyEvent( wxevent, event );
1577 bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
1579 // this will fire higher level events, like insertText, to help
1580 // us handle EVT_CHAR, etc.
1581 if ( !m_hasEditor && [event type] == NSKeyDown)
1583 m_lastKeyDownEvent = event;
1586 if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
1587 [[(NSScrollView*)m_osxView documentView] interpretKeyEvents:[NSArray arrayWithObject:event]];
1589 [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
1596 bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
1598 NSPoint clickLocation;
1599 clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil];
1600 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
1601 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
1602 SetupMouseEvent(wxevent , event) ;
1606 return GetWXPeer()->HandleWindowEvent(wxevent);
1609 void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
1611 wxWindow* thisWindow = GetWXPeer();
1612 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
1614 thisWindow->MacInvalidateBorders();
1617 if ( receivedFocus )
1619 wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
1620 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
1621 thisWindow->HandleWindowEvent(eventFocus);
1624 if ( thisWindow->GetCaret() )
1625 thisWindow->GetCaret()->OnSetFocus();
1628 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
1629 event.SetEventObject(thisWindow);
1631 event.SetWindow(otherWindow->GetWXPeer());
1632 thisWindow->HandleWindowEvent(event) ;
1634 else // !receivedFocuss
1637 if ( thisWindow->GetCaret() )
1638 thisWindow->GetCaret()->OnKillFocus();
1641 wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
1643 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
1644 event.SetEventObject(thisWindow);
1646 event.SetWindow(otherWindow->GetWXPeer());
1647 thisWindow->HandleWindowEvent(event) ;
1651 void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor)
1653 NSPoint location = [NSEvent mouseLocation];
1654 location = [[m_osxView window] convertScreenToBase:location];
1655 NSPoint locationInView = [m_osxView convertPoint:location fromView:nil];
1657 if( NSMouseInRect(locationInView, [m_osxView bounds], YES) )
1659 [(NSCursor*)cursor.GetHCURSOR() set];
1661 [[m_osxView window] invalidateCursorRectsForView:m_osxView];
1664 void wxWidgetCocoaImpl::CaptureMouse()
1666 [[m_osxView window] disableCursorRects];
1669 void wxWidgetCocoaImpl::ReleaseMouse()
1671 [[m_osxView window] enableCursorRects];
1674 void wxWidgetCocoaImpl::SetFlipped(bool flipped)
1676 m_isFlipped = flipped;
1683 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
1684 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
1685 long WXUNUSED(style), long WXUNUSED(extraStyle))
1687 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
1688 wxNSView* v = [[wxNSView alloc] initWithFrame:r];
1690 // temporary hook for dnd
1691 [v registerForDraggedTypes:[NSArray arrayWithObjects:
1692 NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
1694 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
1698 wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
1700 NSWindow* tlw = now->GetWXWindow();
1701 wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
1702 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
1703 c->InstallEventHandler();
1704 [tlw setContentView:v];