]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/window.mm
fixing controls with content areas, correcting radiobox layout
[wxWidgets.git] / src / osx / cocoa / window.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/window.mm
3 // Purpose: widgets (non tlw) for cocoa
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 #ifndef WX_PRECOMP
15 #include "wx/nonownedwnd.h"
16 #endif
17
18 #ifdef __WXMAC__
19 #include "wx/osx/private.h"
20 #endif
21
22 #if wxUSE_CARET
23 #include "wx/caret.h"
24 #endif
25
26 NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
27 {
28 int x, y, w, h ;
29
30 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
31 wxRect bounds(x,y,w,h);
32 NSView* sv = (window->GetParent()->GetHandle() );
33
34 return wxToNSRect( sv, bounds );
35 }
36
37 @interface wxNSView : NSView
38 {
39 WXCOCOAIMPL_COMMON_MEMBERS
40 }
41
42 - (void)drawRect: (NSRect) rect;
43
44 WXCOCOAIMPL_COMMON_INTERFACE
45
46 - (BOOL) canBecomeKeyView;
47
48 @end // wxNSView
49
50 @interface NSView(PossibleMethods)
51 - (void)setImplementation:(wxWidgetCocoaImpl *)theImplementation;
52 - (void)setTitle:(NSString *)aString;
53 - (void)setStringValue:(NSString *)aString;
54 - (void)setIntValue:(int)anInt;
55 - (void)setFloatValue:(float)aFloat;
56 - (void)setDoubleValue:(double)aDouble;
57
58 - (void)setMinValue:(double)aDouble;
59 - (void)setMaxValue:(double)aDouble;
60
61 - (void)sizeToFit;
62
63 - (BOOL)isEnabled;
64 - (void)setEnabled:(BOOL)flag;
65
66 - (void)setImage:(NSImage *)image;
67 - (void)setControlSize:(NSControlSize)size;
68
69 - (id)contentView;
70 @end
71
72 long wxOSXTranslateCocoaKey(unsigned short code, int unichar )
73 {
74 long retval = code;
75 switch( unichar )
76 {
77 case NSUpArrowFunctionKey :
78 retval = WXK_UP;
79 break;
80 case NSDownArrowFunctionKey :
81 retval = WXK_DOWN;
82 break;
83 case NSLeftArrowFunctionKey :
84 retval = WXK_LEFT;
85 break;
86 case NSRightArrowFunctionKey :
87 retval = WXK_RIGHT;
88 break;
89 case NSInsertFunctionKey :
90 retval = WXK_INSERT;
91 break;
92 case NSDeleteFunctionKey :
93 retval = WXK_DELETE;
94 break;
95 case NSHomeFunctionKey :
96 retval = WXK_HOME;
97 break;
98 // case NSBeginFunctionKey :
99 // retval = WXK_BEGIN;
100 // break;
101 case NSEndFunctionKey :
102 retval = WXK_END;
103 break;
104 case NSPageUpFunctionKey :
105 retval = WXK_PAGEUP;
106 break;
107 case NSPageDownFunctionKey :
108 retval = WXK_PAGEDOWN;
109 break;
110 case NSHelpFunctionKey :
111 retval = WXK_HELP;
112 break;
113
114 default :
115 if ( unichar >= NSF1FunctionKey && unichar >= NSF24FunctionKey )
116 retval = WXK_F1 + (unichar - NSF1FunctionKey );
117 break;
118 }
119 return retval;
120 }
121
122 void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent )
123 {
124 UInt32 modifiers = [nsEvent modifierFlags] ;
125 int eventType = [nsEvent type];
126
127 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
128 wxevent.m_controlDown = modifiers & NSControlKeyMask;
129 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
130 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
131
132 wxString chars;
133 if ( eventType != NSFlagsChanged )
134 {
135 NSString* nschars = [nsEvent characters];
136 if ( nschars )
137 {
138 wxCFStringRef cfchars((CFStringRef)[nschars retain]);
139 chars = cfchars.AsString();
140 }
141 }
142
143 int unichar = chars.Length() > 0 ? chars[0] : 0;
144
145 #if wxUSE_UNICODE
146 wxevent.m_uniChar = unichar;
147 #endif
148 wxevent.m_keyCode = wxOSXTranslateCocoaKey( [nsEvent keyCode], unichar ) ;
149 // wxevent.m_rawCode = keymessage;
150 wxevent.m_rawFlags = modifiers;
151
152 wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
153 switch (eventType)
154 {
155 case NSKeyDown :
156 wxevent.SetEventType( wxEVT_KEY_DOWN ) ;
157 break;
158 case NSKeyUp :
159 wxevent.SetEventType( wxEVT_KEY_UP ) ;
160 break;
161 case NSFlagsChanged :
162 // setup common code here
163 break;
164 default :
165 break ;
166 }
167 }
168
169 void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
170 {
171 UInt32 modifiers = [nsEvent modifierFlags] ;
172 wxPoint screenMouseLocation = wxFromNSPoint( NULL, [nsEvent locationInWindow]);
173
174 // these parameters are not given for all events
175 UInt32 button = [nsEvent buttonNumber];
176 UInt32 clickCount = [nsEvent clickCount];
177
178 wxevent.m_x = screenMouseLocation.x;
179 wxevent.m_y = screenMouseLocation.y;
180 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
181 wxevent.m_controlDown = modifiers & NSControlKeyMask;
182 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
183 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
184 wxevent.m_clickCount = clickCount;
185 wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
186 /*
187 UInt32 mouseChord = 0; // TODO does this exist for cocoa
188 // a control click is interpreted as a right click
189 bool thisButtonIsFakeRight = false ;
190 if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
191 {
192 button = kEventMouseButtonSecondary ;
193 thisButtonIsFakeRight = true ;
194 }
195
196 // otherwise we report double clicks by connecting a left click with a ctrl-left click
197 if ( clickCount > 1 && button != g_lastButton )
198 clickCount = 1 ;
199 // we must make sure that our synthetic 'right' button corresponds in
200 // mouse down, moved and mouse up, and does not deliver a right down and left up
201
202 if ( cEvent.GetKind() == kEventMouseDown )
203 {
204 g_lastButton = button ;
205 g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
206 }
207
208 if ( button == 0 )
209 {
210 g_lastButton = 0 ;
211 g_lastButtonWasFakeRight = false ;
212 }
213 else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight )
214 button = g_lastButton ;
215
216 // Adjust the chord mask to remove the primary button and add the
217 // secondary button. It is possible that the secondary button is
218 // already pressed, e.g. on a mouse connected to a laptop, but this
219 // possibility is ignored here:
220 if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
221 mouseChord = ((mouseChord & ~1U) | 2U);
222
223 if(mouseChord & 1U)
224 wxevent.m_leftDown = true ;
225 if(mouseChord & 2U)
226 wxevent.m_rightDown = true ;
227 if(mouseChord & 4U)
228 wxevent.m_middleDown = true ;
229
230 */
231 // translate into wx types
232 int eventType = [nsEvent type];
233 switch (eventType)
234 {
235 case NSLeftMouseDown :
236 case NSRightMouseDown :
237 case NSOtherMouseDown :
238 switch ( button )
239 {
240 case 0 :
241 wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
242 break ;
243
244 case 1 :
245 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
246 break ;
247
248 case 2 :
249 wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
250 break ;
251
252 default:
253 break ;
254 }
255 break ;
256
257 case NSLeftMouseUp :
258 case NSRightMouseUp :
259 case NSOtherMouseUp :
260 switch ( button )
261 {
262 case 0 :
263 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
264 break ;
265
266 case 1 :
267 wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
268 break ;
269
270 case 2 :
271 wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
272 break ;
273
274 default:
275 break ;
276 }
277 break ;
278
279 case NSScrollWheel :
280 {
281 wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
282 /*
283 EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
284 SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeSInt32) ;
285 */
286 wxevent.m_wheelRotation = 10; // delta;
287 wxevent.m_wheelDelta = 1;
288 wxevent.m_linesPerAction = 1;
289 if ( 0 /* axis == kEventMouseWheelAxisX*/ )
290 wxevent.m_wheelAxis = 1;
291 }
292 break ;
293
294 case NSMouseEntered :
295 case NSMouseExited :
296 case NSLeftMouseDragged :
297 case NSRightMouseDragged :
298 case NSOtherMouseDragged :
299 case NSMouseMoved :
300 wxevent.SetEventType( wxEVT_MOTION ) ;
301 break;
302 default :
303 break ;
304 }
305 }
306
307 @implementation wxNSView
308
309 #define OSX_DEBUG_DRAWING 0
310
311 - (void)drawRect: (NSRect) rect
312 {
313 if ( impl )
314 {
315 CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
316 CGContextSaveGState( context );
317 #if OSX_DEBUG_DRAWING
318 CGContextBeginPath( context );
319 CGContextMoveToPoint(context, 0, 0);
320 NSRect bounds = [self bounds];
321 CGContextAddLineToPoint(context, 10, 0);
322 CGContextMoveToPoint(context, 0, 0);
323 CGContextAddLineToPoint(context, 0, 10);
324 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
325 CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
326 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
327 CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
328 CGContextClosePath( context );
329 CGContextStrokePath(context);
330 #endif
331
332 if ( [ self isFlipped ] == NO )
333 {
334 CGContextTranslateCTM( context, 0, [self bounds].size.height );
335 CGContextScaleCTM( context, 1, -1 );
336 }
337
338 wxRegion updateRgn;
339 const NSRect *rects;
340 NSInteger count;
341
342 [self getRectsBeingDrawn:&rects count:&count];
343 for ( int i = 0 ; i < count ; ++i )
344 {
345 updateRgn.Union(wxFromNSRect(self, rects[i]) );
346 }
347
348 wxWindow* wxpeer = impl->GetWXPeer();
349 wxpeer->GetUpdateRegion() = updateRgn;
350 wxpeer->MacSetCGContextRef( context );
351
352 wxPaintEvent event;
353 event.SetTimestamp(0); // todo
354 event.SetEventObject(wxpeer);
355 wxpeer->HandleWindowEvent(event);
356
357 CGContextRestoreGState( context );
358 }
359 }
360
361 WXCOCOAIMPL_COMMON_IMPLEMENTATION
362
363 - (BOOL) canBecomeKeyView
364 {
365 return YES;
366 }
367
368 @end // wxNSView
369
370 IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
371
372 wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
373 wxWidgetImpl( peer, isRootControl ), m_osxView(w)
374 {
375 }
376
377 wxWidgetCocoaImpl::wxWidgetCocoaImpl()
378 {
379 }
380
381 void wxWidgetCocoaImpl::Init()
382 {
383 m_osxView = NULL;
384 }
385
386 wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
387 {
388 if ( [m_osxView respondsToSelector:@selector(setImplementation:) ] )
389 [m_osxView setImplementation:NULL];
390 if ( !IsRootControl() )
391 {
392 NSView *sv = [m_osxView superview];
393 if ( sv != nil )
394 [m_osxView removeFromSuperview];
395 }
396 [m_osxView release];
397 }
398
399 bool wxWidgetCocoaImpl::IsVisible() const
400 {
401 return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
402 }
403
404 void wxWidgetCocoaImpl::SetVisibility( bool visible )
405 {
406 [m_osxView setHidden:(visible ? NO:YES)];
407 }
408
409 void wxWidgetCocoaImpl::Raise()
410 {
411 }
412
413 void wxWidgetCocoaImpl::Lower()
414 {
415 }
416
417 void wxWidgetCocoaImpl::ScrollRect( const wxRect *rect, int dx, int dy )
418 {
419 }
420
421 void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
422 {
423 wxWindowMac* parent = GetWXPeer()->GetParent();
424 // under Cocoa we might have a contentView in the wxParent to which we have to
425 // adjust the coordinates
426 if (parent)
427 {
428 wxPoint pt(parent->GetClientAreaOrigin());
429 x -= pt.x;
430 y -= pt.y;
431 }
432 NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
433 [m_osxView setFrame:r];
434 }
435
436 void wxWidgetCocoaImpl::GetPosition( int &x, int &y ) const
437 {
438 wxRect r = wxFromNSRect( [m_osxView superview], [m_osxView frame] );
439 x = r.GetLeft();
440 y = r.GetTop();
441 }
442
443 void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
444 {
445 NSRect rect = [m_osxView frame];
446 width = rect.size.width;
447 height = rect.size.height;
448 }
449
450 void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
451 {
452 if ( [m_osxView respondsToSelector:@selector(contentView) ] )
453 {
454 NSView* cv = [m_osxView contentView];
455
456 NSRect bounds = [m_osxView bounds];
457 NSRect rect = [cv frame];
458
459 int y = rect.origin.y;
460 int x = rect.origin.x;
461 if ( ![ m_osxView isFlipped ] )
462 y = bounds.size.height - (rect.origin.y + rect.size.height);
463 left = x;
464 top = y;
465 width = rect.size.width;
466 height = rect.size.height;
467 }
468 else
469 {
470 left = top = 0;
471 GetSize( width, height );
472 }
473 }
474
475 void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
476 {
477 if ( where )
478 [m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )];
479 else
480 [m_osxView setNeedsDisplay:YES];
481 }
482
483 bool wxWidgetCocoaImpl::GetNeedsDisplay() const
484 {
485 return [m_osxView needsDisplay];
486 }
487
488 bool wxWidgetCocoaImpl::CanFocus() const
489 {
490 return [m_osxView canBecomeKeyView] == YES;
491 }
492
493 bool wxWidgetCocoaImpl::HasFocus() const
494 {
495 return ( [[m_osxView window] firstResponder] == m_osxView );
496 }
497
498 bool wxWidgetCocoaImpl::SetFocus()
499 {
500 if ( [m_osxView canBecomeKeyView] == NO )
501 return false;
502
503 [[m_osxView window] makeFirstResponder: m_osxView] ;
504 return true;
505 }
506
507
508 void wxWidgetCocoaImpl::RemoveFromParent()
509 {
510 [m_osxView removeFromSuperview];
511 }
512
513 void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
514 {
515 NSView* container = parent->GetWXWidget() ;
516 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
517 [container addSubview:m_osxView];
518 }
519
520 void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
521 {
522 // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
523 }
524
525 void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
526 {
527 if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
528 {
529 wxCFStringRef cf( title , m_wxPeer->GetFont().GetEncoding() );
530 [m_osxView setTitle:cf.AsNSString()];
531 }
532 }
533
534
535 void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
536 {
537 NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
538 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
539 *pt = wxFromNSPoint( to->GetWXWidget(), p );
540 }
541
542 wxInt32 wxWidgetCocoaImpl::GetValue() const
543 {
544 return [(NSControl*)m_osxView intValue];
545 }
546
547 void wxWidgetCocoaImpl::SetValue( wxInt32 v )
548 {
549 if ( [m_osxView respondsToSelector:@selector(setIntValue:)] )
550 {
551 [m_osxView setIntValue:v];
552 }
553 else if ( [m_osxView respondsToSelector:@selector(setFloatValue:)] )
554 {
555 [m_osxView setFloatValue:(double)v];
556 }
557 else if ( [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
558 {
559 [m_osxView setDoubleValue:(double)v];
560 }
561 }
562
563 void wxWidgetCocoaImpl::SetMinimum( wxInt32 v )
564 {
565 if ( [m_osxView respondsToSelector:@selector(setMinValue:)] )
566 {
567 [m_osxView setMinValue:(double)v];
568 }
569 }
570
571 void wxWidgetCocoaImpl::SetMaximum( wxInt32 v )
572 {
573 if ( [m_osxView respondsToSelector:@selector(setMaxValue:)] )
574 {
575 [m_osxView setMaxValue:(double)v];
576 }
577 }
578
579 void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
580 {
581 if ( [m_osxView respondsToSelector:@selector(setImage:)] )
582 {
583 [m_osxView setImage:bitmap.GetNSImage()];
584 }
585 }
586
587 void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& notebook)
588 {
589 // implementation in subclass
590 }
591
592 void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
593 {
594 r->x = r->y = r->width = r->height = 0;
595 // if ( [m_osxView isKindOfClass:[NSControl class]] )
596 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
597 {
598 NSRect former = [m_osxView frame];
599 [m_osxView sizeToFit];
600 NSRect best = [m_osxView frame];
601 [m_osxView setFrame:former];
602 r->width = best.size.width;
603 r->height = best.size.height;
604 }
605 }
606
607 bool wxWidgetCocoaImpl::IsEnabled() const
608 {
609 if ( [m_osxView respondsToSelector:@selector(isEnabled) ] )
610 return [m_osxView isEnabled];
611 return true;
612 }
613
614 void wxWidgetCocoaImpl::Enable( bool enable )
615 {
616 if ( [m_osxView respondsToSelector:@selector(setEnabled:) ] )
617 [m_osxView setEnabled:enable];
618 }
619
620 void wxWidgetCocoaImpl::PulseGauge()
621 {
622 }
623
624 void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 val, wxInt32 view )
625 {
626 }
627
628 void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
629 {
630 NSControlSize size = NSRegularControlSize;
631
632 switch ( variant )
633 {
634 case wxWINDOW_VARIANT_NORMAL :
635 size = NSRegularControlSize;
636 break ;
637
638 case wxWINDOW_VARIANT_SMALL :
639 size = NSSmallControlSize;
640 break ;
641
642 case wxWINDOW_VARIANT_MINI :
643 size = NSMiniControlSize;
644 break ;
645
646 case wxWINDOW_VARIANT_LARGE :
647 size = NSRegularControlSize;
648 break ;
649
650 default:
651 wxFAIL_MSG(_T("unexpected window variant"));
652 break ;
653 }
654 if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
655 [m_osxView setControlSize:size];
656 }
657
658 void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
659 {
660 // TODO
661 }
662
663 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
664 {
665 }
666
667 bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
668 {
669 wxKeyEvent wxevent(wxEVT_KEY_DOWN);
670 SetupKeyEvent( wxevent, event );
671 return GetWXPeer()->HandleWindowEvent(wxevent);
672 }
673
674 bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
675 {
676 NSPoint clickLocation;
677 clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil];
678 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
679 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
680 SetupMouseEvent( wxevent , event ) ;
681 wxevent.m_x = pt.x;
682 wxevent.m_y = pt.y;
683
684 return GetWXPeer()->HandleWindowEvent(wxevent);
685 }
686
687 void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
688 {
689 wxWindow* thisWindow = GetWXPeer();
690 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
691 {
692 thisWindow->MacInvalidateBorders();
693 }
694
695 if ( receivedFocus )
696 {
697 wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
698 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
699 thisWindow->HandleWindowEvent(eventFocus);
700
701 #if wxUSE_CARET
702 if ( thisWindow->GetCaret() )
703 thisWindow->GetCaret()->OnSetFocus();
704 #endif
705
706 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
707 event.SetEventObject(thisWindow);
708 // TODO how to find out the targetFocusWindow ?
709 // event.SetWindow(targetFocusWindow);
710 thisWindow->HandleWindowEvent(event) ;
711 }
712 else // !receivedFocuss
713 {
714 #if wxUSE_CARET
715 if ( thisWindow->GetCaret() )
716 thisWindow->GetCaret()->OnKillFocus();
717 #endif
718
719 wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
720
721 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
722 event.SetEventObject(thisWindow);
723 // TODO how to find out the targetFocusWindow ?
724 // event.SetWindow(targetFocusWindow);
725 thisWindow->HandleWindowEvent(event) ;
726 }
727 }
728
729
730 //
731 // Factory methods
732 //
733
734 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
735 long style, long extraStyle)
736 {
737 NSView* sv = (wxpeer->GetParent()->GetHandle() );
738
739 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
740 wxNSView* v = [[wxNSView alloc] initWithFrame:r];
741 [sv addSubview:v];
742 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
743 [v setImplementation:c];
744 return c;
745 }
746
747 wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
748 {
749 NSWindow* tlw = now->GetWXWindow();
750 wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
751 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
752 [v setImplementation:c];
753 [tlw setContentView:v];
754 return c;
755 }