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