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