]> git.saurik.com Git - wxWidgets.git/blob - src/osx/iphone/window.mm
committing current iphone state
[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 void wxWidgetIPhoneImpl::SetupTabs( const wxNotebook &notebook )
523 {
524 }
525
526 void wxWidgetIPhoneImpl::GetBestRect( wxRect *r ) const
527 {
528 r->x = r->y = r->width = r->height = 0;
529
530 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
531 {
532 CGRect former = [m_osxView frame];
533 [m_osxView sizeToFit];
534 CGRect best = [m_osxView frame];
535 [m_osxView setFrame:former];
536 r->width = best.size.width;
537 r->height = best.size.height;
538 }
539 }
540
541 bool wxWidgetIPhoneImpl::IsEnabled() const
542 {
543 }
544
545 void wxWidgetIPhoneImpl::Enable( bool enable )
546 {
547 }
548
549 void wxWidgetIPhoneImpl::SetMinimum( wxInt32 v )
550 {
551 }
552
553 void wxWidgetIPhoneImpl::SetMaximum( wxInt32 v )
554 {
555 }
556
557 wxInt32 wxWidgetIPhoneImpl::GetMinimum() const
558 {
559 }
560
561 wxInt32 wxWidgetIPhoneImpl::GetMaximum() const
562 {
563 }
564
565 void wxWidgetIPhoneImpl::PulseGauge()
566 {
567 }
568
569 void wxWidgetIPhoneImpl::SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
570 {
571 }
572
573 void wxWidgetIPhoneImpl::SetControlSize( wxWindowVariant variant )
574 {
575 }
576
577 void wxWidgetIPhoneImpl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack )
578 {
579 }
580
581 void wxWidgetIPhoneImpl::InstallEventHandler( WXWidget control )
582 {
583 WXWidget c = control ? control : (WXWidget) m_osxView;
584 wxWidgetImpl::Associate( c, this ) ;
585
586 if ([c isKindOfClass:[UIControl class] ])
587 {
588 UIControl* cc = (UIControl*) c;
589 /*
590 [cc addTarget:self action:@selector(touchUpInsideAction:event:) forControlEvents:UIControlEventTouchUpInside];
591 */
592 }
593 }
594
595 void wxWidgetIPhoneImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
596 {
597 wxWindow* thisWindow = GetWXPeer();
598 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
599 {
600 thisWindow->MacInvalidateBorders();
601 }
602
603 if ( receivedFocus )
604 {
605 wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
606 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
607 thisWindow->HandleWindowEvent(eventFocus);
608
609 #if wxUSE_CARET
610 if ( thisWindow->GetCaret() )
611 thisWindow->GetCaret()->OnSetFocus();
612 #endif
613
614 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
615 event.SetEventObject(thisWindow);
616 if (otherWindow)
617 event.SetWindow(otherWindow->GetWXPeer());
618 thisWindow->HandleWindowEvent(event) ;
619 }
620 else // !receivedFocuss
621 {
622 #if wxUSE_CARET
623 if ( thisWindow->GetCaret() )
624 thisWindow->GetCaret()->OnKillFocus();
625 #endif
626
627 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
628
629 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
630 event.SetEventObject(thisWindow);
631 if (otherWindow)
632 event.SetWindow(otherWindow->GetWXPeer());
633 thisWindow->HandleWindowEvent(event) ;
634 }
635 }
636
637 typedef void (*wxOSX_DrawRectHandlerPtr)(UIView* self, SEL _cmd, CGRect rect);
638 typedef BOOL (*wxOSX_FocusHandlerPtr)(UIView* self, SEL _cmd);
639
640 bool wxWidgetIPhoneImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
641 {
642 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
643 // get the current focus before running becomeFirstResponder
644 UIView* otherView = FindFocus();
645 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
646 BOOL r = superimpl(slf, (SEL)_cmd);
647 if ( r )
648 {
649 DoNotifyFocusEvent( true, otherWindow );
650 }
651 return r;
652 }
653
654 bool wxWidgetIPhoneImpl::resignFirstResponder(WXWidget slf, void *_cmd)
655 {
656 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
657 BOOL r = superimpl(slf, (SEL)_cmd);
658 // get the current focus after running resignFirstResponder
659 UIView* otherView = FindFocus();
660 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
661 // NSTextViews have an editor as true responder, therefore the might get the
662 // resign notification if their editor takes over, don't trigger any event hen
663 if ( r && otherWindow != this)
664 {
665 DoNotifyFocusEvent( false, otherWindow );
666 }
667 return r;
668 }
669
670 void wxWidgetIPhoneImpl::drawRect(CGRect* rect, WXWidget slf, void *WXUNUSED(_cmd))
671 {
672 CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext();
673 CGContextSaveGState( context );
674 // draw background
675
676 CGContextSetFillColorWithColor( context, GetWXPeer()->GetBackgroundColour().GetCGColor());
677 CGContextFillRect(context, *rect );
678
679 GetWXPeer()->MacSetCGContextRef( context );
680
681 GetWXPeer()->GetUpdateRegion() =
682 wxRegion(rect->origin.x,rect->origin.y,rect->size.width,rect->size.height) ;
683
684 wxRegion updateRgn( wxFromNSRect( slf, *rect ) );
685
686 wxWindow* wxpeer = GetWXPeer();
687 wxpeer->GetUpdateRegion() = updateRgn;
688 wxpeer->MacSetCGContextRef( context );
689
690 bool handled = wxpeer->MacDoRedraw( 0 );
691
692 CGContextRestoreGState( context );
693
694 CGContextSaveGState( context );
695 if ( !handled )
696 {
697 // call super
698 SEL _cmd = @selector(drawRect:);
699 wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
700 superimpl(slf, _cmd, *rect);
701 CGContextRestoreGState( context );
702 CGContextSaveGState( context );
703 }
704 wxpeer->MacPaintChildrenBorders();
705 wxpeer->MacSetCGContextRef( NULL );
706
707 CGContextRestoreGState( context );
708 }
709
710 void wxWidgetIPhoneImpl::touchEvent(NSSet* touches, UIEvent *event, WXWidget slf, void *WXUNUSED(_cmd))
711 {
712 CGPoint clickLocation;
713 UITouch *touch = [touches anyObject];
714 clickLocation = [touch locationInView:slf];
715 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
716
717 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
718 SetupMouseEvent( wxevent , touches, event ) ;
719 wxevent.m_x = pt.x;
720 wxevent.m_y = pt.y;
721 wxevent.SetEventObject( GetWXPeer() ) ;
722 //?wxevent.SetId( GetWXPeer()->GetId() ) ;
723
724 GetWXPeer()->HandleWindowEvent(wxevent);
725 }
726
727 void wxWidgetIPhoneImpl::touchUpInsideAction(void* sender, WX_UIEvent evt, WXWidget slf, void* _cmd)
728 {
729 }
730
731 //
732 // Factory methods
733 //
734
735 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
736 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
737 long WXUNUSED(style), long WXUNUSED(extraStyle))
738 {
739 UIView* sv = (wxpeer->GetParent()->GetHandle() );
740
741 CGRect r = CGRectMake( pos.x, pos.y, size.x, size.y) ;
742 // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
743 wxUIView* v = [[wxUIView alloc] initWithFrame:r];
744 sv.clipsToBounds = YES;
745 sv.contentMode = UIViewContentModeRedraw;
746 sv.clearsContextBeforeDrawing = NO;
747 wxWidgetIPhoneImpl* c = new wxWidgetIPhoneImpl( wxpeer, v );
748 return c;
749 }
750
751 wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
752 {
753 UIWindow* toplevelwindow = now->GetWXWindow();
754
755 wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:[toplevelwindow bounds]];
756 contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
757 wxUIContentViewController* controller = [[wxUIContentViewController alloc] init];
758 controller.view = contentview;
759 /*
760 UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
761 // left orientation not yet implemented !
762 if (orientation == UIInterfaceOrientationLandscapeRight )
763 {
764 CGAffineTransform transform = v.transform;
765
766 // Use the status bar frame to determine the center point of the window's content area.
767 CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
768 CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
769 CGPoint center = CGPointMake(bounds.size.height / 2.0, bounds.size.width / 2.0);
770
771 // Set the center point of the view to the center point of the window's content area.
772 v.center = center;
773
774 // Rotate the view 90 degrees around its new center point.
775 transform = CGAffineTransformRotate(transform, ( M_PI / 2.0));
776 v.transform = transform;
777 }
778 */
779 wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true );
780 impl->InstallEventHandler();
781 [toplevelwindow addSubview:contentview];
782 return impl;
783 }
784