#include "wx/log.h"
#endif
-#include <objc/objc-runtime.h>
+#include "wx/textctrl.h"
+#include <objc/runtime.h>
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];
return wxToNSRect( sv, bounds );
}
-@interface wxUIView : UIView
-{
-}
-
-@end // wxUIView
@interface wxUIView(PossibleMethods)
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
- (BOOL) resignFirstResponder;
@end
-@interface wxUIContentView : wxUIView
-{
-}
-
-@end
-
-@interface wxUIContentViewController : UIViewController
-{
-}
-
-@end
-
//
//
//
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
+ (void)initialize
{
static BOOL initialized = NO;
- if (!initialized)
+ if (!initialized)
{
initialized = YES;
wxOSXIPhoneClassAddWXMethods( self );
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;
}
-- (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];
*/
-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);
}
wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NO;
-
+
return impl->becomeFirstResponder(self, _cmd);
}
wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NO;
-
+
return impl->resignFirstResponder(self, _cmd);
}
wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return;
-
+
return impl->drawRect(&rect, self, _cmd);
}
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 ) :
{
}
-wxWidgetIPhoneImpl::wxWidgetIPhoneImpl()
+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 )
{
[[m_osxView superview] bringSubviewToFront:m_osxView];
}
-
+
void wxWidgetIPhoneImpl::Lower()
{
[[m_osxView superview] sendSubviewToBack:m_osxView];
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 )
return [m_osxView isFirstResponder] == YES;
}
-bool wxWidgetIPhoneImpl::SetFocus()
+bool wxWidgetIPhoneImpl::SetFocus()
{
// [m_osxView makeKeyWindow] ;
// TODO
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()];
+}
+
+bool wxWidgetIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
+{
+ [m_osxView setOpaque: (style == wxBG_STYLE_PAINT) ];
}
void wxWidgetIPhoneImpl::SetLabel(const wxString& title, wxFontEncoding encoding)
{
}
-void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant )
+void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant )
{
}
{
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];
}
}
if ( receivedFocus )
{
- wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
+ wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
thisWindow->HandleWindowEvent(eventFocus);
thisWindow->GetCaret()->OnKillFocus();
#endif
- wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
-
+ wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
+
wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
event.SetEventObject(thisWindow);
if (otherWindow)
{
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 )
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
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 ) );
wxWindow* wxpeer = GetWXPeer();
wxpeer->GetUpdateRegion() = updateRgn;
wxpeer->MacSetCGContextRef( context );
-
+
bool handled = wxpeer->MacDoRedraw( 0 );
-
+
CGContextRestoreGState( context );
CGContextSaveGState( context );
// 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 );
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 );
+ }
}
//
// 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];
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;
-}
-