X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/de7cb655ae8436f02607fd71c85b7fd6483bce15..5a376169b1b6d476a2a149ddf68c0ecd9f8b6913:/src/osx/iphone/window.mm diff --git a/src/osx/iphone/window.mm b/src/osx/iphone/window.mm index 81d03166aa..d453aa8871 100644 --- a/src/osx/iphone/window.mm +++ b/src/osx/iphone/window.mm @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: // Created: 2008-06-20 -// RCS-ID: $Id: window.mm 48805 2007-09-19 14:52:25Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -20,6 +20,8 @@ #include "wx/log.h" #endif +#include "wx/textctrl.h" + #include WXWidget wxWidgetImpl::FindFocus() @@ -296,11 +298,39 @@ void wxOSXIPhoneClassAddWXMethods(Class c) class_addMethod(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_CGRect={_CGPoint=ff}{_CGSize=ff}}" ); } +// +// UIControl extensions +// + +@interface UIControl (wxUIControlActionSupport) + +- (void) WX_touchUpInsideAction:(id)sender event:(UIEvent*)event; +- (void) WX_valueChangedAction:(id)sender event:(UIEvent*)event; + +@end + +@implementation UIControl (wxUIControlActionSupport) + +- (void) WX_touchUpInsideAction:(id)sender event:(UIEvent*)event +{ + wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if (impl != NULL) + impl->controlAction(sender, UIControlEventTouchUpInside, event); +} + +- (void) WX_valueChangedAction:(id)sender event:(UIEvent*)event +{ + wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if (impl != NULL) + impl->controlAction(sender, UIControlEventValueChanged, event); +} + +@end IMPLEMENT_DYNAMIC_CLASS( wxWidgetIPhoneImpl , wxWidgetImpl ) -wxWidgetIPhoneImpl::wxWidgetIPhoneImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) : - wxWidgetImpl( peer, isRootControl ), m_osxView(w) +wxWidgetIPhoneImpl::wxWidgetIPhoneImpl( wxWindowMac* peer , WXWidget w, bool isRootControl, bool isUserPane ) : + wxWidgetImpl( peer, isRootControl, isUserPane ), m_osxView(w) { } @@ -362,6 +392,8 @@ void wxWidgetIPhoneImpl::Move(int x, int y, int width, int height) [m_osxView setFrame:r]; } + + void wxWidgetIPhoneImpl::GetPosition( int &x, int &y ) const { CGRect r = [m_osxView frame]; @@ -445,6 +477,18 @@ void wxWidgetIPhoneImpl::SetBackgroundColour( const wxColour &col ) 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:) ] ) @@ -452,11 +496,13 @@ void wxWidgetIPhoneImpl::SetLabel(const wxString& title, wxFontEncoding encoding 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 } @@ -549,6 +595,14 @@ 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 ) { } @@ -557,13 +611,12 @@ void wxWidgetIPhoneImpl::InstallEventHandler( WXWidget control ) { WXWidget c = control ? control : (WXWidget) m_osxView; wxWidgetImpl::Associate( c, this ) ; - - if ([c isKindOfClass:[UIControl class] ]) + + if ([c isKindOfClass:[UIControl class] ]) { UIControl* cc = (UIControl*) c; - /* - [cc addTarget:self action:@selector(touchUpInsideAction:event:) forControlEvents:UIControlEventTouchUpInside]; - */ + [cc addTarget:cc action:@selector(WX_touchUpInsideAction:event:) forControlEvents:UIControlEventTouchUpInside]; + [cc addTarget:cc action:@selector(WX_valueChangedAction:event:) forControlEvents:UIControlEventValueChanged]; } } @@ -647,10 +700,10 @@ void wxWidgetIPhoneImpl::drawRect(CGRect* rect, WXWidget slf, void *WXUNUSED(_cm CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext(); CGContextSaveGState( context ); // draw background - +/* CGContextSetFillColorWithColor( context, GetWXPeer()->GetBackgroundColour().GetCGColor()); CGContextFillRect(context, *rect ); - +*/ GetWXPeer()->MacSetCGContextRef( context ); GetWXPeer()->GetUpdateRegion() = @@ -715,8 +768,22 @@ void wxWidgetIPhoneImpl::touchEvent(NSSet* touches, UIEvent *event, WXWidget slf } } -void wxWidgetIPhoneImpl::touchUpInsideAction(void* sender, WX_UIEvent evt, WXWidget slf, void* _cmd) +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 ); + } } // @@ -735,7 +802,7 @@ wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WX sv.clipsToBounds = YES; sv.contentMode = UIViewContentModeRedraw; sv.clearsContextBeforeDrawing = NO; - wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v ); + wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v, false, true ); return c; }