X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8996460cb98aadf153a61d749b009e436dbb0fd7..9e9574fe45b176ee74bba8fad7574cf9906145d1:/src/osx/iphone/window.mm?ds=sidebyside diff --git a/src/osx/iphone/window.mm b/src/osx/iphone/window.mm index 2858e3ccc3..b4b8c4ac36 100644 --- a/src/osx/iphone/window.mm +++ b/src/osx/iphone/window.mm @@ -4,7 +4,6 @@ // Author: Stefan Csomor // Modified by: // Created: 2008-06-20 -// RCS-ID: $Id: window.mm 48805 2007-09-19 14:52:25Z SC $ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -20,6 +19,8 @@ #include "wx/log.h" #endif +#include "wx/textctrl.h" + #include WXWidget wxWidgetImpl::FindFocus() @@ -56,11 +57,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 +72,6 @@ CGRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const - (BOOL) resignFirstResponder; @end -@interface wxUIContentView : wxUIView -{ -} - -@end - -@interface wxUIContentViewController : UIViewController -{ -} - -@end - // // // @@ -313,34 +297,39 @@ 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 { - 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]; -// CGRect cv = [[self.view superview] frame]; -// CGRect bounds = CGRectMake( 0,0,fr.size.width, fr.size.height); -// [[self.view superview] setFrame: fr ]; -// [self.view setFrame: bounds]; -// [self.view setNeedsDisplayInRect:bounds]; + 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) { } @@ -372,8 +361,6 @@ bool wxWidgetIPhoneImpl::IsVisible() const while ( view != nil && [view isHidden] == NO ) { view = [view superview]; - if (view != nil && [view isHidden]) - NSLog(@"visible test failed for %@",view); } return view == nil; } @@ -404,6 +391,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]; @@ -421,7 +410,9 @@ void wxWidgetIPhoneImpl::GetSize( int &width, int &height ) const void wxWidgetIPhoneImpl::GetContentArea( int&left, int &top, int &width, int &height ) const { left = top = 0; - GetSize( width, height ); + CGRect rect = [m_osxView bounds]; + width = rect.size.width; + height = rect.size.height; } void wxWidgetIPhoneImpl::SetNeedsDisplay( const wxRect* where ) @@ -482,7 +473,19 @@ 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) +{ + 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) @@ -492,11 +495,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 } @@ -555,10 +560,22 @@ void wxWidgetIPhoneImpl::GetBestRect( wxRect *r ) const bool wxWidgetIPhoneImpl::IsEnabled() const { + UIView* targetView = m_osxView; + // TODO add support for documentViews + + if ( [targetView respondsToSelector:@selector(isEnabled) ] ) + return [targetView isEnabled]; + + return true; } void wxWidgetIPhoneImpl::Enable( bool enable ) { + UIView* targetView = m_osxView; + // TODO add support for documentViews + + if ( [targetView respondsToSelector:@selector(setEnabled:) ] ) + [targetView setEnabled:enable]; } void wxWidgetIPhoneImpl::SetMinimum( wxInt32 v ) @@ -571,10 +588,12 @@ void wxWidgetIPhoneImpl::SetMaximum( wxInt32 v ) wxInt32 wxWidgetIPhoneImpl::GetMinimum() const { + return 0; } wxInt32 wxWidgetIPhoneImpl::GetMaximum() const { + return 0; } void wxWidgetIPhoneImpl::PulseGauge() @@ -589,6 +608,14 @@ void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant ) { } +double 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 ) { } @@ -597,13 +624,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]; } } @@ -687,10 +713,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() = @@ -727,23 +753,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_TEXT, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + event.SetString( wxpeer->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } } // @@ -762,41 +815,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; } -wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) -{ - UIWindow* toplevelwindow = now->GetWXWindow(); - - wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:[toplevelwindow bounds]]; - contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - wxUIContentViewController* controller = [[wxUIContentViewController alloc] init]; - controller.view = contentview; - /* - UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; - // left orientation not yet implemented ! - if (orientation == UIInterfaceOrientationLandscapeRight ) - { - CGAffineTransform transform = v.transform; - - // Use the status bar frame to determine the center point of the window's content area. - CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; - CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x); - CGPoint center = CGPointMake(bounds.size.height / 2.0, bounds.size.width / 2.0); - - // Set the center point of the view to the center point of the window's content area. - v.center = center; - - // Rotate the view 90 degrees around its new center point. - transform = CGAffineTransformRotate(transform, ( M_PI / 2.0)); - v.transform = transform; - } - */ - wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true ); - impl->InstallEventHandler(); - [toplevelwindow addSubview:contentview]; - return impl; -} -