]> git.saurik.com Git - wxWidgets.git/blame - src/osx/iphone/window.mm
'Set to Unspecified' -> 'Set Value to Unspecified'
[wxWidgets.git] / src / osx / iphone / window.mm
CommitLineData
c16b2153
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/iphone/window.mm
3// Purpose: widgets (non tlw) for iphone
4// Author: Stefan Csomor
5// Modified by:
6// Created: 2008-06-20
7// RCS-ID: $Id: window.mm 48805 2007-09-19 14:52:25Z SC $
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/osx/private.h"
15
d3929256
SC
16#ifndef WX_PRECOMP
17 #include "wx/nonownedwnd.h"
18 #include "wx/frame.h"
19 #include "wx/event.h"
20 #include "wx/log.h"
21#endif
22
a7f2b179 23#include <objc/runtime.h>
d3929256
SC
24
25WXWidget wxWidgetImpl::FindFocus()
26{
27 UIView* focusedView = nil;
28 UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
29 if ( keyWindow != nil )
30 {
31 /*
32 NSResponder* responder = [keyWindow firstResponder];
03647350 33 if ( [responder isKindOfClass:[NSTextView class]] &&
d3929256
SC
34 [keyWindow fieldEditor:NO forObject:nil] != nil )
35 {
36 focusedView = [(NSTextView*)responder delegate];
37 }
38 else
39 {
40 if ( [responder isKindOfClass:[NSView class]] )
41 focusedView = (NSView*) responder;
42 }
43 */
44 }
45 return focusedView;
46}
47
48CGRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
49{
50 int x, y, w, h ;
51
52 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
53 wxRect bounds(x,y,w,h);
54 UIView* sv = (window->GetParent()->GetHandle() );
55
56 return wxToNSRect( sv, bounds );
57}
c16b2153 58
d3929256
SC
59
60@interface wxUIView(PossibleMethods)
61- (void)setTitle:(NSString *)title forState:(UIControlState)state;
62
c16b2153
SC
63- (void)drawRect: (CGRect) rect;
64
65- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
66- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
67- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
68- (void)handleTouchEvent:(NSSet *)touches withEvent:(UIEvent *)event;
69
c16b2153
SC
70- (BOOL) becomeFirstResponder;
71- (BOOL) resignFirstResponder;
d3929256 72@end
c16b2153 73
c16b2153
SC
74//
75//
76//
77
78void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent )
79{
80 UInt32 modifiers = 0 ;
81 UITouch *touch = [touches anyObject];
82
83 // these parameters are not given for all events
03647350 84 UInt32 button = 0; // no secondary button
c16b2153
SC
85 UInt32 clickCount = [touch tapCount];
86 UInt32 mouseChord = 0; // TODO does this exist for cocoa
87
88 // will be overridden
89 wxevent.m_x = 0;
90 wxevent.m_y = 0;
91 wxevent.m_shiftDown = 0;
92 wxevent.m_controlDown = 0;
93 wxevent.m_altDown = 0;
94 wxevent.m_metaDown = 0;
95 wxevent.m_clickCount = clickCount;
96 wxevent.SetTimestamp( [touch timestamp] ) ;
97/*
98 // a control click is interpreted as a right click
99 bool thisButtonIsFakeRight = false ;
100 if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
101 {
102 button = kEventMouseButtonSecondary ;
103 thisButtonIsFakeRight = true ;
104 }
105
106 // otherwise we report double clicks by connecting a left click with a ctrl-left click
107 if ( clickCount > 1 && button != g_lastButton )
108 clickCount = 1 ;
109 // we must make sure that our synthetic 'right' button corresponds in
110 // mouse down, moved and mouse up, and does not deliver a right down and left up
111
112 if ( cEvent.GetKind() == kEventMouseDown )
113 {
114 g_lastButton = button ;
115 g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
116 }
117
118 if ( button == 0 )
119 {
120 g_lastButton = 0 ;
121 g_lastButtonWasFakeRight = false ;
122 }
123 else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight )
124 button = g_lastButton ;
125
126 // Adjust the chord mask to remove the primary button and add the
127 // secondary button. It is possible that the secondary button is
128 // already pressed, e.g. on a mouse connected to a laptop, but this
129 // possibility is ignored here:
130 if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
131 mouseChord = ((mouseChord & ~1U) | 2U);
132
133 if(mouseChord & 1U)
134 wxevent.m_leftDown = true ;
135 if(mouseChord & 2U)
136 wxevent.m_rightDown = true ;
137 if(mouseChord & 4U)
138 wxevent.m_middleDown = true ;
139
140*/
141 // translate into wx types
142 int eventType = [touch phase];
143 switch (eventType)
144 {
145 case UITouchPhaseBegan :
146 switch ( button )
147 {
148 case 0 :
149 wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
150 break ;
151
152 default:
153 break ;
154 }
155 break ;
156
157 case UITouchPhaseEnded :
158 switch ( button )
159 {
160 case 0 :
161 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
162 break ;
163
164 default:
165 break ;
166 }
167 break ;
168
169 case UITouchPhaseMoved :
170 wxevent.SetEventType( wxEVT_MOTION ) ;
171 break;
172 default :
173 break ;
174 }
175}
176
177@implementation wxUIView
178
d3929256 179+ (void)initialize
c16b2153 180{
d3929256 181 static BOOL initialized = NO;
03647350 182 if (!initialized)
c16b2153 183 {
d3929256
SC
184 initialized = YES;
185 wxOSXIPhoneClassAddWXMethods( self );
c16b2153 186 }
c16b2153
SC
187}
188
d3929256 189@end // wxUIView
c16b2153 190
d3929256 191/*
c16b2153
SC
192- (void)drawRect: (CGRect) rect
193{
d3929256
SC
194 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
195 if ( impl )
c16b2153
SC
196 {
197 CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext();
198 CGContextSaveGState( context );
199 // draw background
03647350 200
d3929256 201 CGContextSetFillColorWithColor( context, impl->GetWXPeer()->GetBackgroundColour().GetCGColor());
c16b2153
SC
202 CGContextFillRect(context, rect );
203
d3929256 204 impl->GetWXPeer()->MacSetCGContextRef( context );
c16b2153 205
03647350 206 impl->GetWXPeer()->GetUpdateRegion() =
c16b2153
SC
207 wxRegion(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height) ;
208
209 wxPaintEvent event;
210 event.SetTimestamp(0); // todo
d3929256
SC
211 event.SetEventObject(impl->GetWXPeer());
212 impl->GetWXPeer()->HandleWindowEvent(event);
c16b2153
SC
213
214 CGContextRestoreGState( context );
215 }
216
217}
218
03647350 219- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
c16b2153
SC
220{
221 [self handleTouchEvent:touches withEvent:event];
222}
223
03647350 224- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
c16b2153
SC
225{
226 [self handleTouchEvent:touches withEvent:event];
227}
228
03647350 229- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
c16b2153
SC
230{
231 [self handleTouchEvent:touches withEvent:event];
232}
233
03647350
VZ
234-(void)handleTouchEvent:(NSSet *)touches withEvent:(UIEvent *)event
235{
d3929256 236 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
03647350 237 CGPoint clickLocation;
c16b2153
SC
238 UITouch *touch = [touches anyObject];
239 clickLocation = [touch locationInView:self];
240
241 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
242 SetupMouseEvent( wxevent , touches, event ) ;
243 wxevent.m_x = clickLocation.x;
244 wxevent.m_y = clickLocation.y;
d3929256
SC
245 wxevent.SetEventObject( impl->GetWXPeer() ) ;
246 wxevent.SetId( impl->GetWXPeer()->GetId() ) ;
247 impl->GetWXPeer()->HandleWindowEvent(wxevent);
c16b2153
SC
248}
249
d3929256 250*/
c16b2153 251
03647350 252void wxOSX_touchEvent(UIView* self, SEL _cmd, NSSet* touches, UIEvent *event )
c16b2153 253{
d3929256
SC
254 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
255 if (impl == NULL)
256 return;
03647350 257
d3929256 258 impl->touchEvent(touches, event, self, _cmd);
c16b2153
SC
259}
260
d3929256 261BOOL wxOSX_becomeFirstResponder(UIView* self, SEL _cmd)
c16b2153 262{
d3929256
SC
263 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
264 if (impl == NULL)
265 return NO;
03647350 266
d3929256 267 return impl->becomeFirstResponder(self, _cmd);
c16b2153
SC
268}
269
d3929256 270BOOL wxOSX_resignFirstResponder(UIView* self, SEL _cmd)
c16b2153 271{
d3929256
SC
272 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
273 if (impl == NULL)
274 return NO;
03647350 275
d3929256 276 return impl->resignFirstResponder(self, _cmd);
c16b2153
SC
277}
278
d3929256 279void wxOSX_drawRect(UIView* self, SEL _cmd, CGRect rect)
c16b2153 280{
d3929256
SC
281 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
282 if (impl == NULL)
283 return;
03647350 284
d3929256 285 return impl->drawRect(&rect, self, _cmd);
c16b2153
SC
286}
287
288
d3929256
SC
289void wxOSXIPhoneClassAddWXMethods(Class c)
290{
291 class_addMethod(c, @selector(touchesBegan:withEvent:), (IMP) wxOSX_touchEvent, "v@:@@");
292 class_addMethod(c, @selector(touchesMoved:withEvent:), (IMP) wxOSX_touchEvent, "v@:@@");
293 class_addMethod(c, @selector(touchesEnded:withEvent:), (IMP) wxOSX_touchEvent, "v@:@@");
294 class_addMethod(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" );
295 class_addMethod(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" );
296 class_addMethod(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_CGRect={_CGPoint=ff}{_CGSize=ff}}" );
297}
c16b2153 298
c16b2153
SC
299
300IMPLEMENT_DYNAMIC_CLASS( wxWidgetIPhoneImpl , wxWidgetImpl )
301
302wxWidgetIPhoneImpl::wxWidgetIPhoneImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
303 wxWidgetImpl( peer, isRootControl ), m_osxView(w)
304{
305}
306
03647350 307wxWidgetIPhoneImpl::wxWidgetIPhoneImpl()
c16b2153
SC
308{
309}
310
311void wxWidgetIPhoneImpl::Init()
312{
313 m_osxView = NULL;
314}
315
316wxWidgetIPhoneImpl::~wxWidgetIPhoneImpl()
317{
d3929256
SC
318 RemoveAssociations( this );
319
320 if ( !IsRootControl() )
321 {
322 UIView *sv = [m_osxView superview];
323 if ( sv != nil )
324 [m_osxView removeFromSuperview];
325 }
c16b2153
SC
326 [m_osxView release];
327}
03647350
VZ
328
329bool wxWidgetIPhoneImpl::IsVisible() const
c16b2153 330{
8996460c
SC
331 UIView* view = m_osxView;
332 while ( view != nil && [view isHidden] == NO )
333 {
334 view = [view superview];
8996460c
SC
335 }
336 return view == nil;
c16b2153
SC
337}
338
339void wxWidgetIPhoneImpl::SetVisibility( bool visible )
340{
341 [m_osxView setHidden:(visible ? NO:YES)];
342}
343
344void wxWidgetIPhoneImpl::Raise()
345{
346 [[m_osxView superview] bringSubviewToFront:m_osxView];
347}
03647350 348
c16b2153
SC
349void wxWidgetIPhoneImpl::Lower()
350{
351 [[m_osxView superview] sendSubviewToBack:m_osxView];
352}
353
354void wxWidgetIPhoneImpl::ScrollRect( const wxRect *rect, int dx, int dy )
355{
d3929256 356 SetNeedsDisplay() ;
c16b2153
SC
357}
358
359void wxWidgetIPhoneImpl::Move(int x, int y, int width, int height)
360{
361 CGRect r = CGRectMake( x, y, width, height) ;
362 [m_osxView setFrame:r];
363}
364
365void wxWidgetIPhoneImpl::GetPosition( int &x, int &y ) const
366{
367 CGRect r = [m_osxView frame];
368 x = r.origin.x;
369 y = r.origin.y;
370}
371
372void wxWidgetIPhoneImpl::GetSize( int &width, int &height ) const
373{
374 CGRect rect = [m_osxView frame];
375 width = rect.size.width;
376 height = rect.size.height;
377}
378
379void wxWidgetIPhoneImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
380{
381 left = top = 0;
65536c92
SC
382 CGRect rect = [m_osxView bounds];
383 width = rect.size.width;
384 height = rect.size.height;
c16b2153
SC
385}
386
387void wxWidgetIPhoneImpl::SetNeedsDisplay( const wxRect* where )
388{
389 if ( where )
390 {
391 CGRect r = CGRectMake( where->x, where->y, where->width, where->height) ;
392 [m_osxView setNeedsDisplayInRect:r];
393 }
394 else
395 [m_osxView setNeedsDisplay];
396}
397
398bool wxWidgetIPhoneImpl::GetNeedsDisplay() const
399{
400 return false;
401// return [m_osxView needsDisplay];
402}
403
404bool wxWidgetIPhoneImpl::CanFocus() const
405{
406 return [m_osxView canBecomeFirstResponder] == YES;
407 // ? return [m_osxView isUserInteractionEnabled] == YES;
408}
409
410bool wxWidgetIPhoneImpl::HasFocus() const
411{
412 return [m_osxView isFirstResponder] == YES;
413}
414
03647350 415bool wxWidgetIPhoneImpl::SetFocus()
c16b2153
SC
416{
417// [m_osxView makeKeyWindow] ;
418// TODO
419 return false;
420}
421
422
423void wxWidgetIPhoneImpl::RemoveFromParent()
424{
425 [m_osxView removeFromSuperview];
426}
427
428void wxWidgetIPhoneImpl::Embed( wxWidgetImpl *parent )
429{
430 UIView* container = parent->GetWXWidget() ;
431 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
432 [container addSubview:m_osxView];
433}
434
435void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
436{
437 CGPoint p = CGPointMake( pt->x , pt->y );
03647350 438 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
c16b2153
SC
439 pt->x = (int)p.x;
440 pt->y = (int)p.y;
441}
442
443void wxWidgetIPhoneImpl::SetBackgroundColour( const wxColour &col )
444{
de7cb655 445 m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
c16b2153
SC
446}
447
d3929256
SC
448void wxWidgetIPhoneImpl::SetLabel(const wxString& title, wxFontEncoding encoding)
449{
450 if ( [m_osxView respondsToSelector:@selector(setTitle:forState:) ] )
451 {
452 wxCFStringRef cf( title , encoding );
453 [m_osxView setTitle:cf.AsNSString() forState:UIControlStateNormal ];
454 }
455 else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
456 {
457 wxCFStringRef cf( title , encoding );
458 [m_osxView setStringValue:cf.AsNSString()];
459 }
460}
461
462
463void wxWidgetIPhoneImpl::SetCursor( const wxCursor & cursor )
464{
465}
466
467void wxWidgetIPhoneImpl::CaptureMouse()
468{
469}
470
471void wxWidgetIPhoneImpl::ReleaseMouse()
472{
473}
474
475wxInt32 wxWidgetIPhoneImpl::GetValue() const
476{
477}
478
479void wxWidgetIPhoneImpl::SetValue( wxInt32 v )
480{
481}
482
483void wxWidgetIPhoneImpl::SetBitmap( const wxBitmap& bitmap )
484{
485}
486
9e55f38d
SC
487wxBitmap wxWidgetIPhoneImpl::GetBitmap() const
488{
489 wxBitmap bmp;
490 return bmp;
491}
492
493void wxWidgetIPhoneImpl::SetBitmapPosition( wxDirection dir )
494{
495}
496
d3929256
SC
497void wxWidgetIPhoneImpl::SetupTabs( const wxNotebook &notebook )
498{
499}
500
501void wxWidgetIPhoneImpl::GetBestRect( wxRect *r ) const
502{
503 r->x = r->y = r->width = r->height = 0;
504
505 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
506 {
507 CGRect former = [m_osxView frame];
508 [m_osxView sizeToFit];
509 CGRect best = [m_osxView frame];
510 [m_osxView setFrame:former];
511 r->width = best.size.width;
512 r->height = best.size.height;
513 }
514}
515
516bool wxWidgetIPhoneImpl::IsEnabled() const
517{
518}
519
520void wxWidgetIPhoneImpl::Enable( bool enable )
521{
522}
523
524void wxWidgetIPhoneImpl::SetMinimum( wxInt32 v )
525{
526}
527
528void wxWidgetIPhoneImpl::SetMaximum( wxInt32 v )
529{
530}
531
532wxInt32 wxWidgetIPhoneImpl::GetMinimum() const
533{
534}
535
536wxInt32 wxWidgetIPhoneImpl::GetMaximum() const
537{
538}
539
540void wxWidgetIPhoneImpl::PulseGauge()
541{
542}
543
544void wxWidgetIPhoneImpl::SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
545{
546}
547
03647350 548void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant )
d3929256
SC
549{
550}
551
552void wxWidgetIPhoneImpl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack )
553{
554}
555
556void wxWidgetIPhoneImpl::InstallEventHandler( WXWidget control )
557{
558 WXWidget c = control ? control : (WXWidget) m_osxView;
559 wxWidgetImpl::Associate( c, this ) ;
560
561 if ([c isKindOfClass:[UIControl class] ])
562 {
563 UIControl* cc = (UIControl*) c;
564 /*
565 [cc addTarget:self action:@selector(touchUpInsideAction:event:) forControlEvents:UIControlEventTouchUpInside];
566 */
567 }
568}
569
570void wxWidgetIPhoneImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
571{
572 wxWindow* thisWindow = GetWXPeer();
573 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
574 {
575 thisWindow->MacInvalidateBorders();
576 }
577
578 if ( receivedFocus )
579 {
9a83f860 580 wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
d3929256
SC
581 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
582 thisWindow->HandleWindowEvent(eventFocus);
583
584#if wxUSE_CARET
585 if ( thisWindow->GetCaret() )
586 thisWindow->GetCaret()->OnSetFocus();
587#endif
588
589 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
590 event.SetEventObject(thisWindow);
591 if (otherWindow)
592 event.SetWindow(otherWindow->GetWXPeer());
593 thisWindow->HandleWindowEvent(event) ;
594 }
595 else // !receivedFocuss
596 {
597#if wxUSE_CARET
598 if ( thisWindow->GetCaret() )
599 thisWindow->GetCaret()->OnKillFocus();
600#endif
601
9a83f860 602 wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
03647350 603
d3929256
SC
604 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
605 event.SetEventObject(thisWindow);
606 if (otherWindow)
607 event.SetWindow(otherWindow->GetWXPeer());
608 thisWindow->HandleWindowEvent(event) ;
609 }
610}
611
612typedef void (*wxOSX_DrawRectHandlerPtr)(UIView* self, SEL _cmd, CGRect rect);
613typedef BOOL (*wxOSX_FocusHandlerPtr)(UIView* self, SEL _cmd);
614
615bool wxWidgetIPhoneImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
616{
617 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
618 // get the current focus before running becomeFirstResponder
03647350 619 UIView* otherView = FindFocus();
d3929256
SC
620 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
621 BOOL r = superimpl(slf, (SEL)_cmd);
622 if ( r )
623 {
624 DoNotifyFocusEvent( true, otherWindow );
625 }
626 return r;
627}
628
629bool wxWidgetIPhoneImpl::resignFirstResponder(WXWidget slf, void *_cmd)
630{
631 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
632 BOOL r = superimpl(slf, (SEL)_cmd);
633 // get the current focus after running resignFirstResponder
03647350 634 UIView* otherView = FindFocus();
d3929256
SC
635 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
636 // NSTextViews have an editor as true responder, therefore the might get the
637 // resign notification if their editor takes over, don't trigger any event hen
638 if ( r && otherWindow != this)
639 {
640 DoNotifyFocusEvent( false, otherWindow );
641 }
642 return r;
643}
644
645void wxWidgetIPhoneImpl::drawRect(CGRect* rect, WXWidget slf, void *WXUNUSED(_cmd))
646{
647 CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext();
648 CGContextSaveGState( context );
649 // draw background
03647350 650
d3929256
SC
651 CGContextSetFillColorWithColor( context, GetWXPeer()->GetBackgroundColour().GetCGColor());
652 CGContextFillRect(context, *rect );
653
654 GetWXPeer()->MacSetCGContextRef( context );
655
03647350 656 GetWXPeer()->GetUpdateRegion() =
d3929256
SC
657 wxRegion(rect->origin.x,rect->origin.y,rect->size.width,rect->size.height) ;
658
659 wxRegion updateRgn( wxFromNSRect( slf, *rect ) );
660
661 wxWindow* wxpeer = GetWXPeer();
662 wxpeer->GetUpdateRegion() = updateRgn;
663 wxpeer->MacSetCGContextRef( context );
03647350 664
d3929256 665 bool handled = wxpeer->MacDoRedraw( 0 );
03647350 666
d3929256
SC
667 CGContextRestoreGState( context );
668
669 CGContextSaveGState( context );
670 if ( !handled )
671 {
672 // call super
673 SEL _cmd = @selector(drawRect:);
674 wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
8996460c
SC
675 if ( superimpl != wxOSX_drawRect )
676 {
677 superimpl(slf, _cmd, *rect);
678 CGContextRestoreGState( context );
679 CGContextSaveGState( context );
680 }
d3929256
SC
681 }
682 wxpeer->MacPaintChildrenBorders();
683 wxpeer->MacSetCGContextRef( NULL );
684
685 CGContextRestoreGState( context );
686}
687
688void wxWidgetIPhoneImpl::touchEvent(NSSet* touches, UIEvent *event, WXWidget slf, void *WXUNUSED(_cmd))
689{
de7cb655
SC
690 bool inRecursion = false;
691 if ( inRecursion )
692 return;
693
d3929256 694 UITouch *touch = [touches anyObject];
de7cb655
SC
695 CGPoint clickLocation;
696 if ( [touch view] != slf && IsRootControl() )
697 {
698 NSLog(@"self is %@ and touch view is %@",slf,[touch view]);
699 inRecursion = true;
700 inRecursion = false;
701 }
702 else
703 {
704 clickLocation = [touch locationInView:slf];
705 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
706
707 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
708 SetupMouseEvent( wxevent , touches, event ) ;
709 wxevent.m_x = pt.x;
710 wxevent.m_y = pt.y;
711 wxevent.SetEventObject( GetWXPeer() ) ;
712 //?wxevent.SetId( GetWXPeer()->GetId() ) ;
713
714 GetWXPeer()->HandleWindowEvent(wxevent);
715 }
d3929256
SC
716}
717
718void wxWidgetIPhoneImpl::touchUpInsideAction(void* sender, WX_UIEvent evt, WXWidget slf, void* _cmd)
719{
720}
721
c16b2153
SC
722//
723// Factory methods
724//
725
03647350 726wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
d3929256
SC
727 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
728 long WXUNUSED(style), long WXUNUSED(extraStyle))
c16b2153
SC
729{
730 UIView* sv = (wxpeer->GetParent()->GetHandle() );
03647350 731
c16b2153
SC
732 CGRect r = CGRectMake( pos.x, pos.y, size.x, size.y) ;
733 // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
734 wxUIView* v = [[wxUIView alloc] initWithFrame:r];
735 sv.clipsToBounds = YES;
736 sv.contentMode = UIViewContentModeRedraw;
737 sv.clearsContextBeforeDrawing = NO;
c16b2153 738 wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v );
c16b2153
SC
739 return c;
740}
741