X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a7f2b179fbc5b731987c34356e14b41cc257a90c..f7d32bb716ba2191d52cbf3ada5b3ff72103dfea:/src/osx/iphone/window.mm?ds=sidebyside diff --git a/src/osx/iphone/window.mm b/src/osx/iphone/window.mm index 28aa413c65..81d03166aa 100644 --- a/src/osx/iphone/window.mm +++ b/src/osx/iphone/window.mm @@ -30,7 +30,7 @@ WXWidget wxWidgetImpl::FindFocus() { /* NSResponder* responder = [keyWindow firstResponder]; - if ( [responder isKindOfClass:[NSTextView class]] && + if ( [responder isKindOfClass:[NSTextView class]] && [keyWindow fieldEditor:NO forObject:nil] != nil ) { focusedView = [(NSTextView*)responder delegate]; @@ -56,11 +56,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 +71,6 @@ CGRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const - (BOOL) resignFirstResponder; @end -@interface wxUIContentView : wxUIView -{ -} - -@end - -@interface wxUIContentViewController : UIViewController -{ -} - -@end - // // // @@ -98,7 +81,7 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent UITouch *touch = [touches anyObject]; // these parameters are not given for all events - UInt32 button = 0; // no secondary button + UInt32 button = 0; // no secondary button UInt32 clickCount = [touch tapCount]; UInt32 mouseChord = 0; // TODO does this exist for cocoa @@ -196,7 +179,7 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent + (void)initialize { static BOOL initialized = NO; - if (!initialized) + if (!initialized) { initialized = YES; wxOSXIPhoneClassAddWXMethods( self ); @@ -214,13 +197,13 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext(); CGContextSaveGState( context ); // draw background - + CGContextSetFillColorWithColor( context, impl->GetWXPeer()->GetBackgroundColour().GetCGColor()); CGContextFillRect(context, rect ); impl->GetWXPeer()->MacSetCGContextRef( context ); - impl->GetWXPeer()->GetUpdateRegion() = + impl->GetWXPeer()->GetUpdateRegion() = wxRegion(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height) ; wxPaintEvent event; @@ -233,25 +216,25 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent } -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self handleTouchEvent:touches withEvent:event]; } -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self handleTouchEvent:touches withEvent:event]; } -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self handleTouchEvent:touches withEvent:event]; } --(void)handleTouchEvent:(NSSet *)touches withEvent:(UIEvent *)event -{ +-(void)handleTouchEvent:(NSSet *)touches withEvent:(UIEvent *)event +{ wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); - CGPoint clickLocation; + CGPoint clickLocation; UITouch *touch = [touches anyObject]; clickLocation = [touch locationInView:self]; @@ -266,12 +249,12 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent */ -void wxOSX_touchEvent(UIView* self, SEL _cmd, NSSet* touches, UIEvent *event ) +void wxOSX_touchEvent(UIView* self, SEL _cmd, NSSet* touches, UIEvent *event ) { wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if (impl == NULL) return; - + impl->touchEvent(touches, event, self, _cmd); } @@ -280,7 +263,7 @@ BOOL wxOSX_becomeFirstResponder(UIView* self, SEL _cmd) wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if (impl == NULL) return NO; - + return impl->becomeFirstResponder(self, _cmd); } @@ -289,7 +272,7 @@ BOOL wxOSX_resignFirstResponder(UIView* self, SEL _cmd) wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if (impl == NULL) return NO; - + return impl->resignFirstResponder(self, _cmd); } @@ -298,7 +281,7 @@ void wxOSX_drawRect(UIView* self, SEL _cmd, CGRect rect) wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if (impl == NULL) return; - + return impl->drawRect(&rect, self, _cmd); } @@ -313,29 +296,6 @@ void wxOSXIPhoneClassAddWXMethods(Class c) class_addMethod(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_CGRect={_CGPoint=ff}{_CGSize=ff}}" ); } -@implementation wxUIContentView - -@end - -@implementation wxUIContentViewController - -- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation -{ - return YES; -} - -- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation -{ - 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]; -} - -@end - IMPLEMENT_DYNAMIC_CLASS( wxWidgetIPhoneImpl , wxWidgetImpl ) @@ -344,7 +304,7 @@ wxWidgetIPhoneImpl::wxWidgetIPhoneImpl( wxWindowMac* peer , WXWidget w, bool isR { } -wxWidgetIPhoneImpl::wxWidgetIPhoneImpl() +wxWidgetIPhoneImpl::wxWidgetIPhoneImpl() { } @@ -365,11 +325,15 @@ wxWidgetIPhoneImpl::~wxWidgetIPhoneImpl() } [m_osxView release]; } - -bool wxWidgetIPhoneImpl::IsVisible() const + +bool wxWidgetIPhoneImpl::IsVisible() const { - // TODO reflect Superviews state - return [m_osxView isHidden] == NO; + UIView* view = m_osxView; + while ( view != nil && [view isHidden] == NO ) + { + view = [view superview]; + } + return view == nil; } void wxWidgetIPhoneImpl::SetVisibility( bool visible ) @@ -381,7 +345,7 @@ void wxWidgetIPhoneImpl::Raise() { [[m_osxView superview] bringSubviewToFront:m_osxView]; } - + void wxWidgetIPhoneImpl::Lower() { [[m_osxView superview] sendSubviewToBack:m_osxView]; @@ -415,7 +379,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 ) @@ -446,7 +412,7 @@ bool wxWidgetIPhoneImpl::HasFocus() const return [m_osxView isFirstResponder] == YES; } -bool wxWidgetIPhoneImpl::SetFocus() +bool wxWidgetIPhoneImpl::SetFocus() { // [m_osxView makeKeyWindow] ; // TODO @@ -469,14 +435,14 @@ void wxWidgetIPhoneImpl::Embed( wxWidgetImpl *parent ) void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to ) { CGPoint p = CGPointMake( pt->x , pt->y ); - p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ]; + p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ]; pt->x = (int)p.x; pt->y = (int)p.y; } void wxWidgetIPhoneImpl::SetBackgroundColour( const wxColour &col ) { - // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()]; + m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()]; } void wxWidgetIPhoneImpl::SetLabel(const wxString& title, wxFontEncoding encoding) @@ -579,7 +545,7 @@ void wxWidgetIPhoneImpl::SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) { } -void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant ) +void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant ) { } @@ -611,7 +577,7 @@ void wxWidgetIPhoneImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* ot if ( receivedFocus ) { - wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast(thisWindow)); + wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast(thisWindow)); wxChildFocusEvent eventFocus((wxWindow*)thisWindow); thisWindow->HandleWindowEvent(eventFocus); @@ -633,8 +599,8 @@ void wxWidgetIPhoneImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* ot thisWindow->GetCaret()->OnKillFocus(); #endif - wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast(thisWindow)); - + wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast(thisWindow)); + wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); event.SetEventObject(thisWindow); if (otherWindow) @@ -650,7 +616,7 @@ 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(); + UIView* otherView = FindFocus(); wxWidgetImpl* otherWindow = FindFromWXWidget(otherView); BOOL r = superimpl(slf, (SEL)_cmd); if ( r ) @@ -665,7 +631,7 @@ 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(); + 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 @@ -681,13 +647,13 @@ 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() = + GetWXPeer()->GetUpdateRegion() = wxRegion(rect->origin.x,rect->origin.y,rect->size.width,rect->size.height) ; wxRegion updateRgn( wxFromNSRect( slf, *rect ) ); @@ -695,9 +661,9 @@ void wxWidgetIPhoneImpl::drawRect(CGRect* rect, WXWidget slf, void *WXUNUSED(_cm wxWindow* wxpeer = GetWXPeer(); wxpeer->GetUpdateRegion() = updateRgn; wxpeer->MacSetCGContextRef( context ); - + bool handled = wxpeer->MacDoRedraw( 0 ); - + CGContextRestoreGState( context ); CGContextSaveGState( context ); @@ -706,9 +672,12 @@ void wxWidgetIPhoneImpl::drawRect(CGRect* rect, WXWidget slf, void *WXUNUSED(_cm // call super SEL _cmd = @selector(drawRect:); wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd]; - superimpl(slf, _cmd, *rect); - CGContextRestoreGState( context ); - CGContextSaveGState( context ); + if ( superimpl != wxOSX_drawRect ) + { + superimpl(slf, _cmd, *rect); + CGContextRestoreGState( context ); + CGContextSaveGState( context ); + } } wxpeer->MacPaintChildrenBorders(); wxpeer->MacSetCGContextRef( NULL ); @@ -718,19 +687,32 @@ 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() ) ; - - GetWXPeer()->HandleWindowEvent(wxevent); + 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::touchUpInsideAction(void* sender, WX_UIEvent evt, WXWidget slf, void* _cmd) @@ -741,12 +723,12 @@ void wxWidgetIPhoneImpl::touchUpInsideAction(void* sender, WX_UIEvent evt, WXWid // Factory methods // -wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent), +wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent), wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size, long WXUNUSED(style), long WXUNUSED(extraStyle)) { UIView* sv = (wxpeer->GetParent()->GetHandle() ); - + CGRect r = CGRectMake( pos.x, pos.y, size.x, size.y) ; // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ; wxUIView* v = [[wxUIView alloc] initWithFrame:r]; @@ -757,37 +739,3 @@ wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WX 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; -} -