X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/65536c9221c62262cca9b76431bc1fdaf4886a3b..6f3f38980f10a935f3b47dbf0d3b4643e96a4be2:/src/osx/iphone/window.mm?ds=sidebyside diff --git a/src/osx/iphone/window.mm b/src/osx/iphone/window.mm index c6cce21b50..6fbf4b9b4c 100644 --- a/src/osx/iphone/window.mm +++ b/src/osx/iphone/window.mm @@ -20,6 +20,8 @@ #include "wx/log.h" #endif +#include "wx/textctrl.h" + #include WXWidget wxWidgetImpl::FindFocus() @@ -56,11 +58,6 @@ CGRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const return wxToNSRect( sv, bounds ); } -@interface wxUIView : UIView -{ -} - -@end // wxUIView @interface wxUIView(PossibleMethods) - (void)setTitle:(NSString *)title forState:(UIControlState)state; @@ -76,18 +73,6 @@ CGRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const - (BOOL) resignFirstResponder; @end -@interface wxUIContentView : wxUIView -{ -} - -@end - -@interface wxUIContentViewController : UIViewController -{ -} - -@end - // // // @@ -313,34 +298,35 @@ void wxOSXIPhoneClassAddWXMethods(Class c) class_addMethod(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_CGRect={_CGPoint=ff}{_CGSize=ff}}" ); } -@implementation wxUIContentView +// +// UIControl extensions +// + +@interface UIControl (wxUIControlActionSupport) + +- (void) WX_touchUpInsideAction:(id)sender event:(UIEvent*)event; +- (void) WX_valueChangedAction:(id)sender event:(UIEvent*)event; @end -@implementation wxUIContentViewController +@implementation UIControl (wxUIControlActionSupport) -- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation +- (void) WX_touchUpInsideAction:(id)sender event:(UIEvent*)event { - wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] ); - wxNonOwnedWindow* now = dynamic_cast (impl->GetWXPeer()); - - // TODO: determine NO or YES based on min size requirements (whether it fits on the new orientation) - - return YES; + wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if (impl != NULL) + impl->controlAction(sender, UIControlEventTouchUpInside, event); } -- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation +- (void) WX_valueChangedAction:(id)sender event:(UIEvent*)event { - CGRect fr = [self.view frame]; - wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] ); - wxNonOwnedWindow* now = dynamic_cast (impl->GetWXPeer()); - - now->HandleResized(0); + 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 ) : @@ -486,7 +472,12 @@ void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to void wxWidgetIPhoneImpl::SetBackgroundColour( const wxColour &col ) { - // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()]; + m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()]; +} + +bool wxWidgetIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style) +{ + [m_osxView setOpaque: (style == wxBG_STYLE_PAINT) ]; } void wxWidgetIPhoneImpl::SetLabel(const wxString& title, wxFontEncoding encoding) @@ -601,13 +592,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]; } } @@ -731,23 +721,50 @@ void wxWidgetIPhoneImpl::drawRect(CGRect* rect, WXWidget slf, void *WXUNUSED(_cm void wxWidgetIPhoneImpl::touchEvent(NSSet* touches, UIEvent *event, WXWidget slf, void *WXUNUSED(_cmd)) { - CGPoint clickLocation; + bool inRecursion = false; + if ( inRecursion ) + return; + UITouch *touch = [touches anyObject]; - 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() ) ; + 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); + } +} - GetWXPeer()->HandleWindowEvent(wxevent); +void wxWidgetIPhoneImpl::controlAction(void* sender, wxUint32 controlEvent, WX_UIEvent rawEvent) +{ + if ( controlEvent == UIControlEventTouchUpInside ) + GetWXPeer()->OSXHandleClicked(0); } -void wxWidgetIPhoneImpl::touchUpInsideAction(void* sender, WX_UIEvent evt, WXWidget slf, void* _cmd) +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 ); + } } // @@ -770,27 +787,3 @@ wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WX return c; } -wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) -{ - UIWindow* toplevelwindow = now->GetWXWindow(); - CGRect frame = [toplevelwindow bounds]; - CGRect appframe = [[UIScreen mainScreen] applicationFrame]; - - if ( now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE ) - { - double offset = appframe.origin.y; - frame.origin.y += offset; - frame.size.height -= offset; - } - - wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:frame]; - contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - wxUIContentViewController* controller = [[wxUIContentViewController alloc] init]; - controller.view = contentview; - - wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true ); - impl->InstallEventHandler(); - [toplevelwindow addSubview:contentview]; - return impl; -} -