+void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 WXUNUSED(val), wxInt32 WXUNUSED(view) )
+{
+}
+
+void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
+{
+ NSControlSize size = NSRegularControlSize;
+
+ switch ( variant )
+ {
+ case wxWINDOW_VARIANT_NORMAL :
+ size = NSRegularControlSize;
+ break ;
+
+ case wxWINDOW_VARIANT_SMALL :
+ size = NSSmallControlSize;
+ break ;
+
+ case wxWINDOW_VARIANT_MINI :
+ size = NSMiniControlSize;
+ break ;
+
+ case wxWINDOW_VARIANT_LARGE :
+ size = NSRegularControlSize;
+ break ;
+
+ default:
+ wxFAIL_MSG(wxT("unexpected window variant"));
+ break ;
+ }
+ if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
+ [m_osxView setControlSize:size];
+ else if ([m_osxView respondsToSelector:@selector(cell)])
+ {
+ id cell = [(id)m_osxView cell];
+ if ([cell respondsToSelector:@selector(setControlSize:)])
+ [cell setControlSize:size];
+ }
+
+ // we need to propagate this to inner views as well
+ if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
+ {
+ NSView* targetView = [(NSScrollView*) m_osxView documentView];
+
+ if ( [targetView respondsToSelector:@selector(setControlSize:)] )
+ [targetView setControlSize:size];
+ else if ([targetView respondsToSelector:@selector(cell)])
+ {
+ id cell = [(id)targetView cell];
+ if ([cell respondsToSelector:@selector(setControlSize:)])
+ [cell setControlSize:size];
+ }
+ }
+}
+
+void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&col, long, bool)
+{
+ NSView* targetView = m_osxView;
+ if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
+ targetView = [(NSScrollView*) m_osxView documentView];
+
+ if ([targetView respondsToSelector:@selector(setFont:)])
+ [targetView setFont: font.OSXGetNSFont()];
+ if ([targetView respondsToSelector:@selector(setTextColor:)])
+ [targetView setTextColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0)
+ green:(CGFloat) (col.Green() / 255.0)
+ blue:(CGFloat) (col.Blue() / 255.0)
+ alpha:(CGFloat) (col.Alpha() / 255.0)]];
+}
+
+void wxWidgetCocoaImpl::SetToolTip(wxToolTip* tooltip)
+{
+ if ( tooltip )
+ {
+ wxCFStringRef cf( tooltip->GetTip() , m_wxPeer->GetFont().GetEncoding() );
+ [m_osxView setToolTip: cf.AsNSString()];
+ }
+ else
+ {
+ [m_osxView setToolTip:nil];
+ }
+}
+
+void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
+{
+ WXWidget c = control ? control : (WXWidget) m_osxView;
+ wxWidgetImpl::Associate( c, this ) ;
+ if ([c respondsToSelector:@selector(setAction:)])
+ {
+ [c setTarget: c];
+ [c setAction: @selector(controlAction:)];
+ if ([c respondsToSelector:@selector(setDoubleAction:)])
+ {
+ [c setDoubleAction: @selector(controlDoubleAction:)];
+ }
+
+ }
+ NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited|NSTrackingCursorUpdate|NSTrackingMouseMoved|NSTrackingActiveAlways|NSTrackingInVisibleRect;
+ NSTrackingArea* area = [[NSTrackingArea alloc] initWithRect: NSZeroRect options: options owner: m_osxView userInfo: nil];
+ [m_osxView addTrackingArea: area];
+ [area release];
+ }
+
+bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
+{
+ wxKeyEvent wxevent(wxEVT_CHAR);
+ SetupKeyEvent( wxevent, event, text );
+
+ return GetWXPeer()->OSXHandleKeyEvent(wxevent);
+}
+
+bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
+{
+ wxKeyEvent wxevent(wxEVT_KEY_DOWN);
+ SetupKeyEvent( wxevent, event );
+
+ // Generate wxEVT_CHAR_HOOK before sending any other events but only when
+ // the key is pressed, not when it's released (the type of wxevent is
+ // changed by SetupKeyEvent() so it can be wxEVT_KEY_UP too by now).
+ if ( wxevent.GetEventType() == wxEVT_KEY_DOWN )
+ {
+ wxKeyEvent eventHook(wxEVT_CHAR_HOOK, wxevent);
+ if ( GetWXPeer()->OSXHandleKeyEvent(eventHook)
+ && !eventHook.IsNextEventAllowed() )
+ return true;
+ }
+
+ bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
+
+ // this will fire higher level events, like insertText, to help
+ // us handle EVT_CHAR, etc.
+
+ if ( !result )
+ {
+ if ( [event type] == NSKeyDown)
+ {
+ long keycode = wxOSXTranslateCocoaKey( event, wxEVT_CHAR );
+
+ if ( (keycode > 0 && keycode < WXK_SPACE) || keycode == WXK_DELETE || keycode >= WXK_START )
+ {
+ // eventually we could setup a doCommandBySelector catcher and retransform this into the wx key chars
+ wxKeyEvent wxevent2(wxevent) ;
+ wxevent2.SetEventType(wxEVT_CHAR);
+ SetupKeyEvent( wxevent2, event );
+ wxevent2.m_keyCode = keycode;
+ result = GetWXPeer()->OSXHandleKeyEvent(wxevent2);
+ }
+ else if (wxevent.CmdDown())
+ {
+ wxKeyEvent wxevent2(wxevent) ;
+ wxevent2.SetEventType(wxEVT_CHAR);
+ SetupKeyEvent( wxevent2, event );
+ result = GetWXPeer()->OSXHandleKeyEvent(wxevent2);
+ }
+ else
+ {
+ if ( IsUserPane() && !wxevent.CmdDown() )
+ {
+ if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
+ [[(NSScrollView*)m_osxView documentView] interpretKeyEvents:[NSArray arrayWithObject:event]];
+ else
+ [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
+ result = true;
+ }
+ }
+ }
+ }
+
+ return result;
+}
+
+bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
+{
+ wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
+ SetupMouseEvent(wxevent , event) ;
+ return GetWXPeer()->HandleWindowEvent(wxevent);
+}
+
+void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
+{
+ wxWindow* thisWindow = GetWXPeer();
+ if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
+ {
+ thisWindow->MacInvalidateBorders();
+ }
+
+ if ( receivedFocus )
+ {
+ wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
+ wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
+ thisWindow->HandleWindowEvent(eventFocus);
+
+#if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnSetFocus();
+#endif
+
+ wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ if (otherWindow)
+ event.SetWindow(otherWindow->GetWXPeer());
+ thisWindow->HandleWindowEvent(event) ;
+ }
+ else // !receivedFocuss
+ {
+#if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnKillFocus();
+#endif
+
+ wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
+
+ wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ if (otherWindow)
+ event.SetWindow(otherWindow->GetWXPeer());
+ thisWindow->HandleWindowEvent(event) ;
+ }
+}
+
+void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor)
+{
+ if ( !wxIsBusy() )
+ {
+ NSPoint location = [NSEvent mouseLocation];
+ location = [[m_osxView window] convertScreenToBase:location];
+ NSPoint locationInView = [m_osxView convertPoint:location fromView:nil];
+
+ if( NSMouseInRect(locationInView, [m_osxView bounds], YES) )
+ {
+ [(NSCursor*)cursor.GetHCURSOR() set];
+ }
+ }
+}
+
+void wxWidgetCocoaImpl::CaptureMouse()
+{
+ // TODO remove if we don't get into problems with cursor settings
+ // [[m_osxView window] disableCursorRects];
+}
+
+void wxWidgetCocoaImpl::ReleaseMouse()