+void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
+{
+ // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
+}
+
+void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
+{
+ if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
+ {
+ wxCFStringRef cf( title , m_wxPeer->GetFont().GetEncoding() );
+ [m_osxView setTitle:cf.AsNSString()];
+ }
+ else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
+ {
+ wxCFStringRef cf( title , m_wxPeer->GetFont().GetEncoding() );
+ [m_osxView setStringValue:cf.AsNSString()];
+ }
+}
+
+
+void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
+{
+ NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
+ p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
+ *pt = wxFromNSPoint( to->GetWXWidget(), p );
+}
+
+wxInt32 wxWidgetCocoaImpl::GetValue() const
+{
+ return [(NSControl*)m_osxView intValue];
+}
+
+void wxWidgetCocoaImpl::SetValue( wxInt32 v )
+{
+ if ( [m_osxView respondsToSelector:@selector(setIntValue:)] )
+ {
+ [m_osxView setIntValue:v];
+ }
+ else if ( [m_osxView respondsToSelector:@selector(setFloatValue:)] )
+ {
+ [m_osxView setFloatValue:(double)v];
+ }
+ else if ( [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
+ {
+ [m_osxView setDoubleValue:(double)v];
+ }
+}
+
+void wxWidgetCocoaImpl::SetMinimum( wxInt32 v )
+{
+ if ( [m_osxView respondsToSelector:@selector(setMinValue:)] )
+ {
+ [m_osxView setMinValue:(double)v];
+ }
+}
+
+void wxWidgetCocoaImpl::SetMaximum( wxInt32 v )
+{
+ if ( [m_osxView respondsToSelector:@selector(setMaxValue:)] )
+ {
+ [m_osxView setMaxValue:(double)v];
+ }
+}
+
+wxInt32 wxWidgetCocoaImpl::GetMinimum() const
+{
+ if ( [m_osxView respondsToSelector:@selector(getMinValue:)] )
+ {
+ return [m_osxView minValue];
+ }
+ return 0;
+}
+
+wxInt32 wxWidgetCocoaImpl::GetMaximum() const
+{
+ if ( [m_osxView respondsToSelector:@selector(getMaxValue:)] )
+ {
+ return [m_osxView maxValue];
+ }
+ return 0;
+}
+
+void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
+{
+ if ( [m_osxView respondsToSelector:@selector(setImage:)] )
+ {
+ [m_osxView setImage:bitmap.GetNSImage()];
+ }
+}
+
+void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& notebook)
+{
+ // implementation in subclass
+}
+
+void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
+{
+ r->x = r->y = r->width = r->height = 0;
+// if ( [m_osxView isKindOfClass:[NSControl class]] )
+ if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
+ {
+ NSRect former = [m_osxView frame];
+ [m_osxView sizeToFit];
+ NSRect best = [m_osxView frame];
+ [m_osxView setFrame:former];
+ r->width = best.size.width;
+ r->height = best.size.height;
+ }
+}
+
+bool wxWidgetCocoaImpl::IsEnabled() const
+{
+ if ( [m_osxView respondsToSelector:@selector(isEnabled) ] )
+ return [m_osxView isEnabled];
+ return true;
+}
+
+void wxWidgetCocoaImpl::Enable( bool enable )
+{
+ if ( [m_osxView respondsToSelector:@selector(setEnabled:) ] )
+ [m_osxView setEnabled:enable];
+}
+
+void wxWidgetCocoaImpl::PulseGauge()
+{
+}
+
+void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 val, wxInt32 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(_T("unexpected window variant"));
+ break ;
+ }
+ if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
+ [m_osxView setControlSize:size];
+}
+
+void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
+{
+ // TODO
+}
+
+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:)];
+ }
+
+ }
+}
+
+bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
+{
+ wxKeyEvent wxevent(wxEVT_KEY_DOWN);
+ SetupKeyEvent( wxevent, event, text );
+
+ return GetWXPeer()->OSXHandleKeyEvent(wxevent);
+}
+
+bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
+{
+ wxKeyEvent wxevent(wxEVT_KEY_DOWN);
+ SetupKeyEvent( wxevent, event );
+
+ bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
+
+ // this will fire higher level events, like insertText, to help
+ // us handle EVT_CHAR, etc.
+ if ([event type] == NSKeyDown)
+ {
+ m_lastKeyDownEvent = event;
+ [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
+ }
+ return result;
+}
+
+bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
+{
+ NSPoint clickLocation;
+ clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil];
+ wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
+ wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
+ SetupMouseEvent( wxevent , event ) ;
+ wxevent.m_x = pt.x;
+ wxevent.m_y = pt.y;
+
+ return GetWXPeer()->HandleWindowEvent(wxevent);
+}
+
+void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
+{
+ wxWindow* thisWindow = GetWXPeer();
+ if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
+ {
+ thisWindow->MacInvalidateBorders();
+ }
+
+ if ( receivedFocus )
+ {
+ wxLogTrace(_T("Focus"), _T("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);
+ // TODO how to find out the targetFocusWindow ?
+ // event.SetWindow(targetFocusWindow);
+ thisWindow->HandleWindowEvent(event) ;
+ }
+ else // !receivedFocuss
+ {
+#if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnKillFocus();
+#endif
+
+ wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
+
+ wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ // TODO how to find out the targetFocusWindow ?
+ // event.SetWindow(targetFocusWindow);
+ thisWindow->HandleWindowEvent(event) ;
+ }
+}
+
+void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor)
+{
+ 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];
+ }
+ [[m_osxView window] invalidateCursorRectsForView:m_osxView];
+}
+
+void wxWidgetCocoaImpl::CaptureMouse()
+{
+ [[m_osxView window] disableCursorRects];
+}
+
+void wxWidgetCocoaImpl::ReleaseMouse()
+{
+ [[m_osxView window] enableCursorRects];
+}
+
+void wxWidgetCocoaImpl::SetFlipped(bool flipped)
+{
+ m_isFlipped = flipped;
+}