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