+ m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
+}
+
+bool wxWidgetIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
+{
+ if ( style == wxBG_STYLE_PAINT )
+ [m_osxView setOpaque: YES ];
+ else
+ {
+ [m_osxView setOpaque: NO ];
+ m_osxView.backgroundColor = [UIColor clearColor];
+ }
+ return true;
+}
+
+void wxWidgetIPhoneImpl::SetLabel(const wxString& title, wxFontEncoding encoding)
+{
+ if ( [m_osxView respondsToSelector:@selector(setTitle:forState:) ] )
+ {
+ wxCFStringRef cf( title , encoding );
+ [m_osxView setTitle:cf.AsNSString() forState:UIControlStateNormal ];
+ }
+#if 0 // nonpublic API problems
+ else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
+ {
+ wxCFStringRef cf( title , encoding );
+ [m_osxView setStringValue:cf.AsNSString()];
+ }
+#endif
+}
+
+
+void wxWidgetIPhoneImpl::SetCursor( const wxCursor & cursor )
+{
+}
+
+void wxWidgetIPhoneImpl::CaptureMouse()
+{
+}
+
+void wxWidgetIPhoneImpl::ReleaseMouse()
+{
+}
+
+wxInt32 wxWidgetIPhoneImpl::GetValue() const
+{
+}
+
+void wxWidgetIPhoneImpl::SetValue( wxInt32 v )
+{
+}
+
+void wxWidgetIPhoneImpl::SetBitmap( const wxBitmap& bitmap )
+{
+}
+
+wxBitmap wxWidgetIPhoneImpl::GetBitmap() const
+{
+ wxBitmap bmp;
+ return bmp;
+}
+
+void wxWidgetIPhoneImpl::SetBitmapPosition( wxDirection dir )
+{
+}
+
+void wxWidgetIPhoneImpl::SetupTabs( const wxNotebook ¬ebook )
+{
+}
+
+void wxWidgetIPhoneImpl::GetBestRect( wxRect *r ) const
+{
+ r->x = r->y = r->width = r->height = 0;
+
+ if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
+ {
+ CGRect former = [m_osxView frame];
+ [m_osxView sizeToFit];
+ CGRect best = [m_osxView frame];
+ [m_osxView setFrame:former];
+ r->width = best.size.width;
+ r->height = best.size.height;
+ }
+}
+
+bool wxWidgetIPhoneImpl::IsEnabled() const
+{
+}
+
+void wxWidgetIPhoneImpl::Enable( bool enable )
+{
+}
+
+void wxWidgetIPhoneImpl::SetMinimum( wxInt32 v )
+{
+}
+
+void wxWidgetIPhoneImpl::SetMaximum( wxInt32 v )
+{
+}
+
+wxInt32 wxWidgetIPhoneImpl::GetMinimum() const
+{
+}
+
+wxInt32 wxWidgetIPhoneImpl::GetMaximum() const
+{
+}
+
+void wxWidgetIPhoneImpl::PulseGauge()
+{
+}
+
+void wxWidgetIPhoneImpl::SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
+{
+}
+
+void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant )
+{
+}
+
+float wxWidgetIPhoneImpl::GetContentScaleFactor() const
+{
+ if ( [m_osxView respondsToSelector:@selector(contentScaleFactor) ])
+ return [m_osxView contentScaleFactor];
+ else
+ return 1.0;
+}
+
+void wxWidgetIPhoneImpl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack )
+{
+}
+
+void wxWidgetIPhoneImpl::InstallEventHandler( WXWidget control )
+{
+ WXWidget c = control ? control : (WXWidget) m_osxView;
+ wxWidgetImpl::Associate( c, this ) ;
+
+ if ([c isKindOfClass:[UIControl class] ])
+ {
+ UIControl* cc = (UIControl*) c;
+ [cc addTarget:cc action:@selector(WX_touchUpInsideAction:event:) forControlEvents:UIControlEventTouchUpInside];
+ [cc addTarget:cc action:@selector(WX_valueChangedAction:event:) forControlEvents:UIControlEventValueChanged];
+ }
+}
+
+void wxWidgetIPhoneImpl::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) ;
+ }
+}
+
+typedef void (*wxOSX_DrawRectHandlerPtr)(UIView* self, SEL _cmd, CGRect rect);
+typedef BOOL (*wxOSX_FocusHandlerPtr)(UIView* self, SEL _cmd);
+
+bool wxWidgetIPhoneImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
+{
+ wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+ // get the current focus before running becomeFirstResponder
+ UIView* otherView = FindFocus();
+ wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
+ BOOL r = superimpl(slf, (SEL)_cmd);
+ if ( r )
+ {
+ DoNotifyFocusEvent( true, otherWindow );
+ }
+ return r;
+}
+
+bool wxWidgetIPhoneImpl::resignFirstResponder(WXWidget slf, void *_cmd)
+{
+ wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+ BOOL r = superimpl(slf, (SEL)_cmd);
+ // get the current focus after running resignFirstResponder
+ UIView* otherView = FindFocus();
+ wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
+ // NSTextViews have an editor as true responder, therefore the might get the
+ // resign notification if their editor takes over, don't trigger any event hen
+ if ( r && otherWindow != this)
+ {
+ DoNotifyFocusEvent( false, otherWindow );
+ }
+ return r;
+}
+
+void wxWidgetIPhoneImpl::drawRect(CGRect* rect, WXWidget slf, void *WXUNUSED(_cmd))
+{
+ CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext();
+ CGContextSaveGState( context );
+ // draw background
+/*
+ CGContextSetFillColorWithColor( context, GetWXPeer()->GetBackgroundColour().GetCGColor());
+ CGContextFillRect(context, *rect );
+*/
+ GetWXPeer()->MacSetCGContextRef( context );
+
+ GetWXPeer()->GetUpdateRegion() =
+ wxRegion(rect->origin.x,rect->origin.y,rect->size.width,rect->size.height) ;
+
+ wxRegion updateRgn( wxFromNSRect( slf, *rect ) );
+
+ wxWindow* wxpeer = GetWXPeer();
+ wxpeer->GetUpdateRegion() = updateRgn;
+ wxpeer->MacSetCGContextRef( context );
+
+ bool handled = wxpeer->MacDoRedraw( 0 );
+
+ CGContextRestoreGState( context );
+
+ CGContextSaveGState( context );
+ if ( !handled )
+ {
+ // call super
+ SEL _cmd = @selector(drawRect:);
+ wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
+ if ( superimpl != wxOSX_drawRect )
+ {
+ superimpl(slf, _cmd, *rect);
+ CGContextRestoreGState( context );
+ CGContextSaveGState( context );
+ }
+ }
+ wxpeer->MacPaintChildrenBorders();
+ wxpeer->MacSetCGContextRef( NULL );
+
+ CGContextRestoreGState( context );
+}
+
+void wxWidgetIPhoneImpl::touchEvent(NSSet* touches, UIEvent *event, WXWidget slf, void *WXUNUSED(_cmd))
+{
+ bool inRecursion = false;
+ if ( inRecursion )
+ return;
+
+ UITouch *touch = [touches anyObject];
+ CGPoint clickLocation;
+ if ( [touch view] != slf && IsRootControl() )
+ {
+ NSLog(@"self is %@ and touch view is %@",slf,[touch view]);
+ inRecursion = true;
+ inRecursion = false;
+ }
+ else
+ {
+ clickLocation = [touch locationInView:slf];
+ wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
+
+ wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
+ SetupMouseEvent( wxevent , touches, event ) ;
+ wxevent.m_x = pt.x;
+ wxevent.m_y = pt.y;
+ wxevent.SetEventObject( GetWXPeer() ) ;
+ //?wxevent.SetId( GetWXPeer()->GetId() ) ;
+
+ GetWXPeer()->HandleWindowEvent(wxevent);
+ }
+}
+
+void wxWidgetIPhoneImpl::controlAction(void* sender, wxUint32 controlEvent, WX_UIEvent rawEvent)
+{
+ if ( controlEvent == UIControlEventTouchUpInside )
+ GetWXPeer()->OSXHandleClicked(0);
+}
+
+void wxWidgetIPhoneImpl::controlTextDidChange()
+{
+ wxTextCtrl* wxpeer = wxDynamicCast((wxWindow*)GetWXPeer(),wxTextCtrl);
+ if ( wxpeer )
+ {
+ wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
+ event.SetEventObject( wxpeer );
+ event.SetString( wxpeer->GetValue() );
+ wxpeer->HandleWindowEvent( event );
+ }