]> git.saurik.com Git - wxWidgets.git/blob - src/osx/iphone/window.mm
A call to wxPopupWindow::Show shouldn't automatically cause the popup window to steal...
[wxWidgets.git] / src / osx / iphone / window.mm
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
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
23 #include <objc/runtime.h>
24
25 WXWidget wxWidgetImpl::FindFocus()
26 {
27 UIView* focusedView = nil;
28 UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
29 if ( keyWindow != nil )
30 {
31 /*
32 NSResponder* responder = [keyWindow firstResponder];
33 if ( [responder isKindOfClass:[NSTextView class]] &&
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
48 CGRect 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 }
58
59
60 @interface wxUIView(PossibleMethods)
61 - (void)setTitle:(NSString *)title forState:(UIControlState)state;
62
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
70 - (BOOL) becomeFirstResponder;
71 - (BOOL) resignFirstResponder;
72 @end
73
74 //
75 //
76 //
77
78 void 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
84 UInt32 button = 0; // no secondary button
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
179 + (void)initialize
180 {
181 static BOOL initialized = NO;
182 if (!initialized)
183 {
184 initialized = YES;
185 wxOSXIPhoneClassAddWXMethods( self );
186 }
187 }
188
189 @end // wxUIView
190
191 /*
192 - (void)drawRect: (CGRect) rect
193 {
194 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
195 if ( impl )
196 {
197 CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext();
198 CGContextSaveGState( context );
199 // draw background
200
201 CGContextSetFillColorWithColor( context, impl->GetWXPeer()->GetBackgroundColour().GetCGColor());
202 CGContextFillRect(context, rect );
203
204 impl->GetWXPeer()->MacSetCGContextRef( context );
205
206 impl->GetWXPeer()->GetUpdateRegion() =
207 wxRegion(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height) ;
208
209 wxPaintEvent event;
210 event.SetTimestamp(0); // todo
211 event.SetEventObject(impl->GetWXPeer());
212 impl->GetWXPeer()->HandleWindowEvent(event);
213
214 CGContextRestoreGState( context );
215 }
216
217 }
218
219 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
220 {
221 [self handleTouchEvent:touches withEvent:event];
222 }
223
224 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
225 {
226 [self handleTouchEvent:touches withEvent:event];
227 }
228
229 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
230 {
231 [self handleTouchEvent:touches withEvent:event];
232 }
233
234 -(void)handleTouchEvent:(NSSet *)touches withEvent:(UIEvent *)event
235 {
236 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
237 CGPoint clickLocation;
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;
245 wxevent.SetEventObject( impl->GetWXPeer() ) ;
246 wxevent.SetId( impl->GetWXPeer()->GetId() ) ;
247 impl->GetWXPeer()->HandleWindowEvent(wxevent);
248 }
249
250 */
251
252 void wxOSX_touchEvent(UIView* self, SEL _cmd, NSSet* touches, UIEvent *event )
253 {
254 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
255 if (impl == NULL)
256 return;
257
258 impl->touchEvent(touches, event, self, _cmd);
259 }
260
261 BOOL wxOSX_becomeFirstResponder(UIView* self, SEL _cmd)
262 {
263 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
264 if (impl == NULL)
265 return NO;
266
267 return impl->becomeFirstResponder(self, _cmd);
268 }
269
270 BOOL wxOSX_resignFirstResponder(UIView* self, SEL _cmd)
271 {
272 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
273 if (impl == NULL)
274 return NO;
275
276 return impl->resignFirstResponder(self, _cmd);
277 }
278
279 void wxOSX_drawRect(UIView* self, SEL _cmd, CGRect rect)
280 {
281 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( self );
282 if (impl == NULL)
283 return;
284
285 return impl->drawRect(&rect, self, _cmd);
286 }
287
288
289 void 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 }
298
299
300 IMPLEMENT_DYNAMIC_CLASS( wxWidgetIPhoneImpl , wxWidgetImpl )
301
302 wxWidgetIPhoneImpl::wxWidgetIPhoneImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
303 wxWidgetImpl( peer, isRootControl ), m_osxView(w)
304 {
305 }
306
307 wxWidgetIPhoneImpl::wxWidgetIPhoneImpl()
308 {
309 }
310
311 void wxWidgetIPhoneImpl::Init()
312 {
313 m_osxView = NULL;
314 }
315
316 wxWidgetIPhoneImpl::~wxWidgetIPhoneImpl()
317 {
318 RemoveAssociations( this );
319
320 if ( !IsRootControl() )
321 {
322 UIView *sv = [m_osxView superview];
323 if ( sv != nil )
324 [m_osxView removeFromSuperview];
325 }
326 [m_osxView release];
327 }
328
329 bool wxWidgetIPhoneImpl::IsVisible() const
330 {
331 UIView* view = m_osxView;
332 while ( view != nil && [view isHidden] == NO )
333 {
334 view = [view superview];
335 }
336 return view == nil;
337 }
338
339 void wxWidgetIPhoneImpl::SetVisibility( bool visible )
340 {
341 [m_osxView setHidden:(visible ? NO:YES)];
342 }
343
344 void wxWidgetIPhoneImpl::Raise()
345 {
346 [[m_osxView superview] bringSubviewToFront:m_osxView];
347 }
348
349 void wxWidgetIPhoneImpl::Lower()
350 {
351 [[m_osxView superview] sendSubviewToBack:m_osxView];
352 }
353
354 void wxWidgetIPhoneImpl::ScrollRect( const wxRect *rect, int dx, int dy )
355 {
356 SetNeedsDisplay() ;
357 }
358
359 void 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
365 void 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
372 void 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
379 void wxWidgetIPhoneImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
380 {
381 left = top = 0;
382 CGRect rect = [m_osxView bounds];
383 width = rect.size.width;
384 height = rect.size.height;
385 }
386
387 void 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
398 bool wxWidgetIPhoneImpl::GetNeedsDisplay() const
399 {
400 return false;
401 // return [m_osxView needsDisplay];
402 }
403
404 bool wxWidgetIPhoneImpl::CanFocus() const
405 {
406 return [m_osxView canBecomeFirstResponder] == YES;
407 // ? return [m_osxView isUserInteractionEnabled] == YES;
408 }
409
410 bool wxWidgetIPhoneImpl::HasFocus() const
411 {
412 return [m_osxView isFirstResponder] == YES;
413 }
414
415 bool wxWidgetIPhoneImpl::SetFocus()
416 {
417 // [m_osxView makeKeyWindow] ;
418 // TODO
419 return false;
420 }
421
422
423 void wxWidgetIPhoneImpl::RemoveFromParent()
424 {
425 [m_osxView removeFromSuperview];
426 }
427
428 void 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
435 void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
436 {
437 CGPoint p = CGPointMake( pt->x , pt->y );
438 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
439 pt->x = (int)p.x;
440 pt->y = (int)p.y;
441 }
442
443 void wxWidgetIPhoneImpl::SetBackgroundColour( const wxColour &col )
444 {
445 m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
446 }
447
448 void 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
463 void wxWidgetIPhoneImpl::SetCursor( const wxCursor & cursor )
464 {
465 }
466
467 void wxWidgetIPhoneImpl::CaptureMouse()
468 {
469 }
470
471 void wxWidgetIPhoneImpl::ReleaseMouse()
472 {
473 }
474
475 wxInt32 wxWidgetIPhoneImpl::GetValue() const
476 {
477 }
478
479 void wxWidgetIPhoneImpl::SetValue( wxInt32 v )
480 {
481 }
482
483 void wxWidgetIPhoneImpl::SetBitmap( const wxBitmap& bitmap )
484 {
485 }
486
487 wxBitmap wxWidgetIPhoneImpl::GetBitmap() const
488 {
489 wxBitmap bmp;
490 return bmp;
491 }
492
493 void wxWidgetIPhoneImpl::SetBitmapPosition( wxDirection dir )
494 {
495 }
496
497 void wxWidgetIPhoneImpl::SetupTabs( const wxNotebook &notebook )
498 {
499 }
500
501 void 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
516 bool wxWidgetIPhoneImpl::IsEnabled() const
517 {
518 }
519
520 void wxWidgetIPhoneImpl::Enable( bool enable )
521 {
522 }
523
524 void wxWidgetIPhoneImpl::SetMinimum( wxInt32 v )
525 {
526 }
527
528 void wxWidgetIPhoneImpl::SetMaximum( wxInt32 v )
529 {
530 }
531
532 wxInt32 wxWidgetIPhoneImpl::GetMinimum() const
533 {
534 }
535
536 wxInt32 wxWidgetIPhoneImpl::GetMaximum() const
537 {
538 }
539
540 void wxWidgetIPhoneImpl::PulseGauge()
541 {
542 }
543
544 void wxWidgetIPhoneImpl::SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
545 {
546 }
547
548 void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant )
549 {
550 }
551
552 void wxWidgetIPhoneImpl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack )
553 {
554 }
555
556 void 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
570 void 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 {
580 wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
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
602 wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
603
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
612 typedef void (*wxOSX_DrawRectHandlerPtr)(UIView* self, SEL _cmd, CGRect rect);
613 typedef BOOL (*wxOSX_FocusHandlerPtr)(UIView* self, SEL _cmd);
614
615 bool 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
619 UIView* otherView = FindFocus();
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
629 bool 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
634 UIView* otherView = FindFocus();
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
645 void wxWidgetIPhoneImpl::drawRect(CGRect* rect, WXWidget slf, void *WXUNUSED(_cmd))
646 {
647 CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext();
648 CGContextSaveGState( context );
649 // draw background
650
651 CGContextSetFillColorWithColor( context, GetWXPeer()->GetBackgroundColour().GetCGColor());
652 CGContextFillRect(context, *rect );
653
654 GetWXPeer()->MacSetCGContextRef( context );
655
656 GetWXPeer()->GetUpdateRegion() =
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 );
664
665 bool handled = wxpeer->MacDoRedraw( 0 );
666
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];
675 if ( superimpl != wxOSX_drawRect )
676 {
677 superimpl(slf, _cmd, *rect);
678 CGContextRestoreGState( context );
679 CGContextSaveGState( context );
680 }
681 }
682 wxpeer->MacPaintChildrenBorders();
683 wxpeer->MacSetCGContextRef( NULL );
684
685 CGContextRestoreGState( context );
686 }
687
688 void wxWidgetIPhoneImpl::touchEvent(NSSet* touches, UIEvent *event, WXWidget slf, void *WXUNUSED(_cmd))
689 {
690 bool inRecursion = false;
691 if ( inRecursion )
692 return;
693
694 UITouch *touch = [touches anyObject];
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 }
716 }
717
718 void wxWidgetIPhoneImpl::touchUpInsideAction(void* sender, WX_UIEvent evt, WXWidget slf, void* _cmd)
719 {
720 }
721
722 //
723 // Factory methods
724 //
725
726 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
727 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
728 long WXUNUSED(style), long WXUNUSED(extraStyle))
729 {
730 UIView* sv = (wxpeer->GetParent()->GetHandle() );
731
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;
738 wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v );
739 return c;
740 }
741