]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/window.mm
Applied #10828 (Hourglass in wxDocManager::OnPreview)
[wxWidgets.git] / src / osx / cocoa / window.mm
CommitLineData
33e90275
SC
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
05cf95ed 14#ifndef WX_PRECOMP
f487501a 15 #include "wx/dcclient.h"
c583fa5a
SC
16 #include "wx/nonownedwnd.h"
17 #include "wx/log.h"
05cf95ed 18#endif
33e90275
SC
19
20#ifdef __WXMAC__
4dd9fdf8 21 #include "wx/osx/private.h"
33e90275
SC
22#endif
23
0c530e5a
SC
24#if wxUSE_CARET
25 #include "wx/caret.h"
26#endif
27
4dd9fdf8
SC
28#if wxUSE_DRAG_AND_DROP
29 #include "wx/dnd.h"
30#endif
31
32#include <objc/objc-runtime.h>
33
f06e0fea
SC
34// Get the window with the focus
35
7cb2a241 36NSView* GetViewFromResponder( NSResponder* responder )
f06e0fea 37{
7cb2a241
SC
38 NSView* view = nil;
39 if ( [responder isKindOfClass:[NSTextView class]] )
f06e0fea 40 {
7cb2a241
SC
41 NSView* delegate = [(NSTextView*)responder delegate];
42 if ( [delegate isKindOfClass:[NSTextField class] ] )
43 view = delegate;
f06e0fea 44 else
7cb2a241 45 view = (NSView*) responder;
f06e0fea 46 }
7cb2a241
SC
47 else
48 {
49 if ( [responder isKindOfClass:[NSView class]] )
50 view = (NSView*) responder;
51 }
52 return view;
53}
54
55NSView* GetFocusedViewInWindow( NSWindow* keyWindow )
56{
57 NSView* focusedView = nil;
58 if ( keyWindow != nil )
59 focusedView = GetViewFromResponder([keyWindow firstResponder]);
60
f06e0fea
SC
61 return focusedView;
62}
63
7cb2a241
SC
64WXWidget wxWidgetImpl::FindFocus()
65{
66 return GetFocusedViewInWindow( [[NSApplication sharedApplication] keyWindow] );
67}
68
dbeddfb9
SC
69NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
70{
71 int x, y, w, h ;
72
73 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
74 wxRect bounds(x,y,w,h);
75 NSView* sv = (window->GetParent()->GetHandle() );
76
77 return wxToNSRect( sv, bounds );
78}
33e90275
SC
79
80@interface wxNSView : NSView
81{
fc099495 82 NSTrackingRectTag rectTag;
33e90275
SC
83}
84
03647350 85// the tracking tag is needed to track mouse enter / exit events
fc099495
KO
86- (void) setTrackingTag: (NSTrackingRectTag)tag;
87- (NSTrackingRectTag) trackingTag;
33e90275
SC
88@end // wxNSView
89
03647350 90@interface NSView(PossibleMethods)
ffad7b0d
SC
91- (void)setTitle:(NSString *)aString;
92- (void)setStringValue:(NSString *)aString;
93- (void)setIntValue:(int)anInt;
94- (void)setFloatValue:(float)aFloat;
95- (void)setDoubleValue:(double)aDouble;
96
19c7ac3d
SC
97- (double)minValue;
98- (double)maxValue;
ffad7b0d
SC
99- (void)setMinValue:(double)aDouble;
100- (void)setMaxValue:(double)aDouble;
101
102- (void)sizeToFit;
103
104- (BOOL)isEnabled;
105- (void)setEnabled:(BOOL)flag;
106
107- (void)setImage:(NSImage *)image;
108- (void)setControlSize:(NSControlSize)size;
0c530e5a 109
6ac636dd
SC
110- (void)setFont:(NSFont *)fontObject;
111
0c530e5a 112- (id)contentView;
4dd9fdf8
SC
113
114- (void)setTarget:(id)anObject;
115- (void)setAction:(SEL)aSelector;
116- (void)setDoubleAction:(SEL)aSelector;
03647350 117@end
ffad7b0d 118
63a6419c 119long wxOSXTranslateCocoaKey( NSEvent* event )
524c47aa 120{
63a6419c
KO
121 long retval = 0;
122
123 if ([event type] != NSFlagsChanged)
03647350 124 {
63a6419c
KO
125 NSString* s = [event charactersIgnoringModifiers];
126 // backspace char reports as delete w/modifiers for some reason
127 if ([s length] == 1)
128 {
129 switch ( [s characterAtIndex:0] )
130 {
131 // backspace key
132 case 0x7F :
03647350 133 case 8 :
63a6419c
KO
134 retval = WXK_BACK;
135 break;
136 case NSUpArrowFunctionKey :
137 retval = WXK_UP;
138 break;
139 case NSDownArrowFunctionKey :
140 retval = WXK_DOWN;
141 break;
142 case NSLeftArrowFunctionKey :
143 retval = WXK_LEFT;
144 break;
145 case NSRightArrowFunctionKey :
146 retval = WXK_RIGHT;
147 break;
148 case NSInsertFunctionKey :
149 retval = WXK_INSERT;
150 break;
151 case NSDeleteFunctionKey :
152 retval = WXK_DELETE;
153 break;
154 case NSHomeFunctionKey :
155 retval = WXK_HOME;
156 break;
157 // case NSBeginFunctionKey :
158 // retval = WXK_BEGIN;
159 // break;
160 case NSEndFunctionKey :
161 retval = WXK_END;
162 break;
163 case NSPageUpFunctionKey :
164 retval = WXK_PAGEUP;
165 break;
166 case NSPageDownFunctionKey :
167 retval = WXK_PAGEDOWN;
168 break;
169 case NSHelpFunctionKey :
170 retval = WXK_HELP;
171 break;
172 default:
b480b80a
KO
173 int intchar = [s characterAtIndex: 0];
174 if ( intchar >= NSF1FunctionKey && intchar <= NSF24FunctionKey )
63a6419c
KO
175 retval = WXK_F1 + (intchar - NSF1FunctionKey );
176 break;
177 }
178 }
179 }
03647350 180
63a6419c
KO
181 // Some keys don't seem to have constants. The code mimics the approach
182 // taken by WebKit. See:
183 // http://trac.webkit.org/browser/trunk/WebCore/platform/mac/KeyEventMac.mm
184 switch( [event keyCode] )
524c47aa 185 {
63a6419c
KO
186 // command key
187 case 54:
188 case 55:
189 retval = WXK_COMMAND;
524c47aa 190 break;
63a6419c
KO
191 // caps locks key
192 case 57: // Capslock
193 retval = WXK_CAPITAL;
524c47aa 194 break;
63a6419c
KO
195 // shift key
196 case 56: // Left Shift
197 case 60: // Right Shift
198 retval = WXK_SHIFT;
524c47aa 199 break;
63a6419c
KO
200 // alt key
201 case 58: // Left Alt
202 case 61: // Right Alt
203 retval = WXK_ALT;
524c47aa 204 break;
63a6419c
KO
205 // ctrl key
206 case 59: // Left Ctrl
207 case 62: // Right Ctrl
208 retval = WXK_CONTROL;
524c47aa 209 break;
63a6419c 210 // clear key
03647350 211 case 71:
63a6419c 212 retval = WXK_CLEAR;
524c47aa 213 break;
63a6419c 214 // tab key
03647350 215 case 48:
63a6419c 216 retval = WXK_TAB;
524c47aa
SC
217 break;
218
4d61ae5f
SC
219 case 75: // /
220 retval = WXK_NUMPAD_DIVIDE;
03647350 221 break;
4d61ae5f
SC
222 case 67: // *
223 retval = WXK_NUMPAD_MULTIPLY;
224 break;
225 case 78: // -
226 retval = WXK_NUMPAD_SUBTRACT;
227 break;
228 case 69: // +
229 retval = WXK_NUMPAD_ADD;
230 break;
231 case 76: // Enter
232 retval = WXK_NUMPAD_ENTER;
233 break;
234 case 65: // .
235 retval = WXK_NUMPAD_DECIMAL;
236 break;
237 case 82: // 0
238 retval = WXK_NUMPAD0;
239 break;
240 case 83: // 1
241 retval = WXK_NUMPAD1;
242 break;
243 case 84: // 2
244 retval = WXK_NUMPAD2;
245 break;
246 case 85: // 3
247 retval = WXK_NUMPAD3;
248 break;
249 case 86: // 4
250 retval = WXK_NUMPAD4;
251 break;
252 case 87: // 5
253 retval = WXK_NUMPAD5;
254 break;
255 case 88: // 6
256 retval = WXK_NUMPAD6;
257 break;
258 case 89: // 7
259 retval = WXK_NUMPAD7;
260 break;
261 case 91: // 8
262 retval = WXK_NUMPAD8;
263 break;
264 case 92: // 9
265 retval = WXK_NUMPAD9;
266 break;
267 default:
268 //retval = [event keyCode];
524c47aa
SC
269 break;
270 }
271 return retval;
272}
273
f0e0116e 274void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charString = NULL )
524c47aa
SC
275{
276 UInt32 modifiers = [nsEvent modifierFlags] ;
fc39cf72 277 int eventType = [nsEvent type];
524c47aa
SC
278
279 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
280 wxevent.m_controlDown = modifiers & NSControlKeyMask;
281 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
282 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
03647350 283
19c7ac3d 284 wxevent.m_rawCode = [nsEvent keyCode];
524c47aa 285 wxevent.m_rawFlags = modifiers;
03647350 286
e490b0d2 287 wxevent.SetTimestamp( (int)([nsEvent timestamp] * 1000) ) ;
19c7ac3d
SC
288
289 wxString chars;
290 if ( eventType != NSFlagsChanged )
291 {
4d61ae5f 292 NSString* nschars = (wxevent.GetEventType() != wxEVT_CHAR) ? [nsEvent charactersIgnoringModifiers] : [nsEvent characters];
f0e0116e 293 if ( charString )
63a6419c
KO
294 {
295 // if charString is set, it did not come from key up / key down
296 wxevent.SetEventType( wxEVT_CHAR );
f66ecdc4 297 chars = wxCFStringRef::AsString(charString);
63a6419c
KO
298 }
299 else if ( nschars )
19c7ac3d 300 {
f66ecdc4 301 chars = wxCFStringRef::AsString(nschars);
19c7ac3d
SC
302 }
303 }
03647350 304
63a6419c
KO
305 int aunichar = chars.Length() > 0 ? chars[0] : 0;
306 long keyval = 0;
03647350 307
63a6419c 308 if (wxevent.GetEventType() != wxEVT_CHAR)
4d61ae5f 309 {
63a6419c 310 keyval = wxOSXTranslateCocoaKey(nsEvent) ;
4d61ae5f
SC
311 switch (eventType)
312 {
313 case NSKeyDown :
314 wxevent.SetEventType( wxEVT_KEY_DOWN ) ;
315 break;
316 case NSKeyUp :
317 wxevent.SetEventType( wxEVT_KEY_UP ) ;
318 break;
319 case NSFlagsChanged :
320 switch (keyval)
321 {
322 case WXK_CONTROL:
323 wxevent.SetEventType( wxevent.m_controlDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
324 break;
325 case WXK_SHIFT:
326 wxevent.SetEventType( wxevent.m_shiftDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
327 break;
328 case WXK_ALT:
329 wxevent.SetEventType( wxevent.m_altDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
330 break;
331 case WXK_COMMAND:
332 wxevent.SetEventType( wxevent.m_metaDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
333 break;
334 }
335 break;
336 default :
337 break ;
338 }
339 }
19c7ac3d 340
63a6419c
KO
341 if ( !keyval )
342 {
343 if ( wxevent.GetEventType() == wxEVT_KEY_UP || wxevent.GetEventType() == wxEVT_KEY_DOWN )
344 keyval = wxToupper( aunichar ) ;
345 else
346 keyval = aunichar;
347 }
03647350 348
19c7ac3d 349#if wxUSE_UNICODE
63a6419c 350 wxevent.m_uniChar = aunichar;
19c7ac3d
SC
351#endif
352 wxevent.m_keyCode = keyval;
524c47aa
SC
353}
354
54f11060
SC
355UInt32 g_lastButton = 0 ;
356bool g_lastButtonWasFakeRight = false ;
357
33e90275
SC
358void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
359{
4800ca79 360 int eventType = [nsEvent type];
33e90275
SC
361 UInt32 modifiers = [nsEvent modifierFlags] ;
362 wxPoint screenMouseLocation = wxFromNSPoint( NULL, [nsEvent locationInWindow]);
363
364 // these parameters are not given for all events
365 UInt32 button = [nsEvent buttonNumber];
4800ca79 366 UInt32 clickCount = 0;
33e90275
SC
367
368 wxevent.m_x = screenMouseLocation.x;
369 wxevent.m_y = screenMouseLocation.y;
370 wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
371 wxevent.m_controlDown = modifiers & NSControlKeyMask;
372 wxevent.m_altDown = modifiers & NSAlternateKeyMask;
373 wxevent.m_metaDown = modifiers & NSCommandKeyMask;
e490b0d2 374 wxevent.SetTimestamp( (int)([nsEvent timestamp] * 1000) ) ;
54f11060 375
03647350 376 UInt32 mouseChord = 0;
54f11060
SC
377
378 switch (eventType)
379 {
380 case NSLeftMouseDown :
381 case NSLeftMouseDragged :
382 mouseChord = 1U;
383 break;
384 case NSRightMouseDown :
385 case NSRightMouseDragged :
386 mouseChord = 2U;
387 break;
388 case NSOtherMouseDown :
389 case NSOtherMouseDragged :
390 mouseChord = 4U;
391 break;
392 }
393
33e90275
SC
394 // a control click is interpreted as a right click
395 bool thisButtonIsFakeRight = false ;
54f11060 396 if ( button == 0 && (modifiers & NSControlKeyMask) )
33e90275 397 {
54f11060 398 button = 1 ;
33e90275
SC
399 thisButtonIsFakeRight = true ;
400 }
401
402 // otherwise we report double clicks by connecting a left click with a ctrl-left click
403 if ( clickCount > 1 && button != g_lastButton )
404 clickCount = 1 ;
54f11060 405
33e90275
SC
406 // we must make sure that our synthetic 'right' button corresponds in
407 // mouse down, moved and mouse up, and does not deliver a right down and left up
54f11060 408 switch (eventType)
33e90275 409 {
54f11060
SC
410 case NSLeftMouseDown :
411 case NSRightMouseDown :
412 case NSOtherMouseDown :
413 g_lastButton = button ;
414 g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
415 break;
416 }
33e90275
SC
417
418 if ( button == 0 )
419 {
420 g_lastButton = 0 ;
421 g_lastButtonWasFakeRight = false ;
422 }
54f11060 423 else if ( g_lastButton == 1 && g_lastButtonWasFakeRight )
33e90275
SC
424 button = g_lastButton ;
425
426 // Adjust the chord mask to remove the primary button and add the
427 // secondary button. It is possible that the secondary button is
428 // already pressed, e.g. on a mouse connected to a laptop, but this
429 // possibility is ignored here:
430 if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
431 mouseChord = ((mouseChord & ~1U) | 2U);
432
433 if(mouseChord & 1U)
434 wxevent.m_leftDown = true ;
435 if(mouseChord & 2U)
436 wxevent.m_rightDown = true ;
437 if(mouseChord & 4U)
438 wxevent.m_middleDown = true ;
439
33e90275 440 // translate into wx types
33e90275
SC
441 switch (eventType)
442 {
443 case NSLeftMouseDown :
444 case NSRightMouseDown :
445 case NSOtherMouseDown :
08c1b134 446 clickCount = [nsEvent clickCount];
33e90275
SC
447 switch ( button )
448 {
449 case 0 :
450 wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
451 break ;
452
453 case 1 :
454 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
455 break ;
456
457 case 2 :
458 wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
459 break ;
460
461 default:
462 break ;
463 }
464 break ;
465
466 case NSLeftMouseUp :
467 case NSRightMouseUp :
468 case NSOtherMouseUp :
08c1b134 469 clickCount = [nsEvent clickCount];
33e90275
SC
470 switch ( button )
471 {
472 case 0 :
473 wxevent.SetEventType( wxEVT_LEFT_UP ) ;
474 break ;
475
476 case 1 :
477 wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
478 break ;
479
480 case 2 :
481 wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
482 break ;
483
484 default:
485 break ;
486 }
487 break ;
488
489 case NSScrollWheel :
490 {
491 wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
e32090ba 492 wxevent.m_wheelDelta = 10;
33e90275 493 wxevent.m_linesPerAction = 1;
8704e090
SC
494
495 if ( fabs([nsEvent deltaX]) > fabs([nsEvent deltaY]) )
4800ca79 496 {
33e90275 497 wxevent.m_wheelAxis = 1;
e490b0d2 498 wxevent.m_wheelRotation = (int)([nsEvent deltaX] * 10);
4800ca79
SC
499 }
500 else
501 {
e490b0d2 502 wxevent.m_wheelRotation = (int)([nsEvent deltaY] * 10);
4800ca79 503 }
33e90275
SC
504 }
505 break ;
506
507 case NSMouseEntered :
f1f15003
KO
508 wxevent.SetEventType( wxEVT_ENTER_WINDOW ) ;
509 break;
33e90275 510 case NSMouseExited :
f1f15003
KO
511 wxevent.SetEventType( wxEVT_LEAVE_WINDOW ) ;
512 break;
33e90275
SC
513 case NSLeftMouseDragged :
514 case NSRightMouseDragged :
515 case NSOtherMouseDragged :
516 case NSMouseMoved :
517 wxevent.SetEventType( wxEVT_MOTION ) ;
518 break;
519 default :
520 break ;
521 }
03647350 522
08c1b134 523 wxevent.m_clickCount = clickCount;
03647350 524
33e90275
SC
525}
526
527@implementation wxNSView
528
4dd9fdf8
SC
529+ (void)initialize
530{
531 static BOOL initialized = NO;
03647350 532 if (!initialized)
4dd9fdf8
SC
533 {
534 initialized = YES;
535 wxOSXCocoaClassAddWXMethods( self );
536 }
537}
538
fc099495
KO
539- (void) setTrackingTag: (NSTrackingRectTag)tag
540{
541 rectTag = tag;
542}
543
544- (NSTrackingRectTag) trackingTag
545{
546 return rectTag;
547}
548
4dd9fdf8
SC
549@end // wxNSView
550
551//
552// event handlers
553//
554
555#if wxUSE_DRAG_AND_DROP
556
557// see http://lists.apple.com/archives/Cocoa-dev/2005/Jul/msg01244.html
558// for details on the NSPasteboard -> PasteboardRef conversion
559
560NSDragOperation wxOSX_draggingEntered( id self, SEL _cmd, id <NSDraggingInfo>sender )
561{
562 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
563 if (impl == NULL)
564 return NSDragOperationNone;
03647350 565
4dd9fdf8
SC
566 return impl->draggingEntered(sender, self, _cmd);
567}
568
569void wxOSX_draggingExited( id self, SEL _cmd, id <NSDraggingInfo> sender )
570{
571 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
572 if (impl == NULL)
573 return ;
03647350 574
4dd9fdf8
SC
575 return impl->draggingExited(sender, self, _cmd);
576}
577
578NSDragOperation wxOSX_draggingUpdated( id self, SEL _cmd, id <NSDraggingInfo>sender )
579{
580 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
581 if (impl == NULL)
582 return NSDragOperationNone;
03647350 583
4dd9fdf8
SC
584 return impl->draggingUpdated(sender, self, _cmd);
585}
586
587BOOL wxOSX_performDragOperation( id self, SEL _cmd, id <NSDraggingInfo> sender )
588{
589 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
590 if (impl == NULL)
591 return NSDragOperationNone;
03647350 592
4dd9fdf8
SC
593 return impl->performDragOperation(sender, self, _cmd) ? YES:NO ;
594}
595
7cb2a241
SC
596#endif
597
03647350 598void wxOSX_mouseEvent(NSView* self, SEL _cmd, NSEvent *event)
4dd9fdf8
SC
599{
600 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
601 if (impl == NULL)
602 return;
03647350 603
4dd9fdf8
SC
604 impl->mouseEvent(event, self, _cmd);
605}
606
03647350 607void wxOSX_keyEvent(NSView* self, SEL _cmd, NSEvent *event)
4dd9fdf8
SC
608{
609 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
610 if (impl == NULL)
611 return;
03647350 612
4dd9fdf8
SC
613 impl->keyEvent(event, self, _cmd);
614}
615
03647350 616void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text)
f0e0116e
KO
617{
618 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
619 if (impl == NULL)
620 return;
03647350 621
f0e0116e
KO
622 impl->insertText(text, self, _cmd);
623}
624
03647350 625BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event)
4dd9fdf8
SC
626{
627 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
628 if (impl == NULL)
629 return NO;
03647350 630
4dd9fdf8
SC
631 return impl->performKeyEquivalent(event, self, _cmd);
632}
633
09a9eb20
KO
634BOOL wxOSX_acceptsFirstResponder(NSView* self, SEL _cmd)
635{
636 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
637 if (impl == NULL)
638 return NO;
03647350 639
09a9eb20
KO
640 return impl->acceptsFirstResponder(self, _cmd);
641}
642
4dd9fdf8
SC
643BOOL wxOSX_becomeFirstResponder(NSView* self, SEL _cmd)
644{
645 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
646 if (impl == NULL)
647 return NO;
03647350 648
4dd9fdf8
SC
649 return impl->becomeFirstResponder(self, _cmd);
650}
651
652BOOL wxOSX_resignFirstResponder(NSView* self, SEL _cmd)
653{
654 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
655 if (impl == NULL)
656 return NO;
03647350 657
4dd9fdf8
SC
658 return impl->resignFirstResponder(self, _cmd);
659}
660
661void wxOSX_resetCursorRects(NSView* self, SEL _cmd)
662{
663 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
664 if (impl == NULL)
665 return;
03647350 666
4dd9fdf8
SC
667 impl->resetCursorRects(self, _cmd);
668}
669
670BOOL wxOSX_isFlipped(NSView* self, SEL _cmd)
671{
672 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
673 if (impl == NULL)
674 return NO;
03647350 675
4dd9fdf8
SC
676 return impl->isFlipped(self, _cmd) ? YES:NO;
677}
678
679void wxOSX_drawRect(NSView* self, SEL _cmd, NSRect rect)
680{
681 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
682 if (impl == NULL)
683 return;
03647350 684
4dd9fdf8
SC
685 return impl->drawRect(&rect, self, _cmd);
686}
687
e32090ba 688void wxOSX_controlAction(NSView* self, SEL _cmd, id sender)
4dd9fdf8
SC
689{
690 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
691 if (impl == NULL)
692 return;
03647350 693
e32090ba 694 impl->controlAction(self, _cmd, sender);
4dd9fdf8
SC
695}
696
e32090ba 697void wxOSX_controlDoubleAction(NSView* self, SEL _cmd, id sender)
4dd9fdf8
SC
698{
699 wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
700 if (impl == NULL)
701 return;
03647350 702
e32090ba 703 impl->controlDoubleAction(self, _cmd, sender);
4dd9fdf8 704}
dbeddfb9 705
d8207702 706unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
33e90275 707{
4dd9fdf8
SC
708 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
709 NSPasteboard *pboard = [sender draggingPasteboard];
710 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
03647350 711
4dd9fdf8
SC
712 wxWindow* wxpeer = GetWXPeer();
713 if ( wxpeer == NULL )
714 return NSDragOperationNone;
03647350 715
4dd9fdf8
SC
716 wxDropTarget* target = wxpeer->GetDropTarget();
717 if ( target == NULL )
718 return NSDragOperationNone;
719
720 wxDragResult result = wxDragNone;
e6b3143a
SC
721 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
722 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
4dd9fdf8
SC
723
724 if ( sourceDragMask & NSDragOperationLink )
725 result = wxDragLink;
726 else if ( sourceDragMask & NSDragOperationCopy )
727 result = wxDragCopy;
728 else if ( sourceDragMask & NSDragOperationMove )
729 result = wxDragMove;
730
03647350 731 PasteboardRef pboardRef;
4dd9fdf8
SC
732 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
733 target->SetCurrentDragPasteboard(pboardRef);
734 result = target->OnEnter(pt.x, pt.y, result);
735 CFRelease(pboardRef);
03647350 736
4dd9fdf8
SC
737 NSDragOperation nsresult = NSDragOperationNone;
738 switch (result )
33e90275 739 {
4dd9fdf8
SC
740 case wxDragLink:
741 nsresult = NSDragOperationLink;
742 case wxDragMove:
743 nsresult = NSDragOperationMove;
744 case wxDragCopy:
745 nsresult = NSDragOperationCopy;
746 default :
747 break;
748 }
749 return nsresult;
750}
33e90275 751
d8207702 752void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
4dd9fdf8
SC
753{
754 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
755 NSPasteboard *pboard = [sender draggingPasteboard];
03647350 756
4dd9fdf8
SC
757 wxWindow* wxpeer = GetWXPeer();
758 if ( wxpeer == NULL )
759 return;
03647350 760
4dd9fdf8
SC
761 wxDropTarget* target = wxpeer->GetDropTarget();
762 if ( target == NULL )
763 return;
03647350
VZ
764
765 PasteboardRef pboardRef;
4dd9fdf8
SC
766 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
767 target->SetCurrentDragPasteboard(pboardRef);
768 target->OnLeave();
769 CFRelease(pboardRef);
770 }
771
d8207702 772unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
4dd9fdf8
SC
773{
774 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
775 NSPasteboard *pboard = [sender draggingPasteboard];
776 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
03647350 777
4dd9fdf8
SC
778 wxWindow* wxpeer = GetWXPeer();
779 if ( wxpeer == NULL )
780 return NSDragOperationNone;
03647350 781
4dd9fdf8
SC
782 wxDropTarget* target = wxpeer->GetDropTarget();
783 if ( target == NULL )
784 return NSDragOperationNone;
785
786 wxDragResult result = wxDragNone;
e6b3143a
SC
787 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
788 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
4dd9fdf8
SC
789
790 if ( sourceDragMask & NSDragOperationLink )
791 result = wxDragLink;
792 else if ( sourceDragMask & NSDragOperationCopy )
793 result = wxDragCopy;
794 else if ( sourceDragMask & NSDragOperationMove )
795 result = wxDragMove;
796
03647350 797 PasteboardRef pboardRef;
4dd9fdf8
SC
798 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
799 target->SetCurrentDragPasteboard(pboardRef);
800 result = target->OnDragOver(pt.x, pt.y, result);
801 CFRelease(pboardRef);
03647350 802
4dd9fdf8
SC
803 NSDragOperation nsresult = NSDragOperationNone;
804 switch (result )
805 {
806 case wxDragLink:
807 nsresult = NSDragOperationLink;
808 case wxDragMove:
809 nsresult = NSDragOperationMove;
810 case wxDragCopy:
811 nsresult = NSDragOperationCopy;
812 default :
813 break;
814 }
815 return nsresult;
816}
817
d8207702 818bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
4dd9fdf8
SC
819{
820 id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
dbeddfb9 821
4dd9fdf8
SC
822 NSPasteboard *pboard = [sender draggingPasteboard];
823 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
03647350 824
4dd9fdf8
SC
825 wxWindow* wxpeer = GetWXPeer();
826 wxDropTarget* target = wxpeer->GetDropTarget();
827 wxDragResult result = wxDragNone;
e6b3143a
SC
828 NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
829 wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
4dd9fdf8
SC
830
831 if ( sourceDragMask & NSDragOperationLink )
832 result = wxDragLink;
833 else if ( sourceDragMask & NSDragOperationCopy )
834 result = wxDragCopy;
835 else if ( sourceDragMask & NSDragOperationMove )
836 result = wxDragMove;
837
03647350 838 PasteboardRef pboardRef;
4dd9fdf8
SC
839 PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
840 target->SetCurrentDragPasteboard(pboardRef);
5646fba6
SC
841
842 if (target->OnDrop(pt.x, pt.y))
843 result = target->OnData(pt.x, pt.y, result);
844
4dd9fdf8 845 CFRelease(pboardRef);
03647350 846
4dd9fdf8
SC
847 return result != wxDragNone;
848}
849
63a6419c 850typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
4dd9fdf8
SC
851typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
852typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
853typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
854typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
11fed901 855typedef void (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
4dd9fdf8
SC
856
857void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
858{
859 if ( !DoHandleMouseEvent(event) )
860 {
2e498654
SC
861 // for plain NSView mouse events would propagate to parents otherwise
862 if (!m_wxPeer->MacIsUserPane())
863 {
864 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
865 superimpl(slf, (SEL)_cmd, event);
866 }
4dd9fdf8
SC
867 }
868}
869
870void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
871{
7cb2a241 872 if ( GetFocusedViewInWindow([slf window]) != slf || m_hasEditor || !DoHandleKeyEvent(event) )
4dd9fdf8
SC
873 {
874 wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
875 superimpl(slf, (SEL)_cmd, event);
876 }
877}
878
f0e0116e 879void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
4dd9fdf8 880{
7cb2a241 881 if ( m_lastKeyDownEvent==NULL || m_hasEditor || !DoHandleCharEvent(m_lastKeyDownEvent, text) )
4dd9fdf8 882 {
2e498654
SC
883 wxOSX_TextEventHandlerPtr superimpl = (wxOSX_TextEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
884 superimpl(slf, (SEL)_cmd, text);
4dd9fdf8 885 }
f0e0116e
KO
886 m_lastKeyDownEvent = NULL;
887}
4dd9fdf8 888
f0e0116e
KO
889
890bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
891{
892 wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
893 return superimpl(slf, (SEL)_cmd, event);
4dd9fdf8
SC
894}
895
09a9eb20
KO
896bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
897{
f06e0fea
SC
898 if ( m_wxPeer->MacIsUserPane() )
899 return m_wxPeer->AcceptsFocus();
900 else
901 {
902 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
903 return superimpl(slf, (SEL)_cmd);
904 }
09a9eb20
KO
905}
906
4dd9fdf8
SC
907bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
908{
909 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
b42865ce 910 // get the current focus before running becomeFirstResponder
03647350 911 NSView* otherView = FindFocus();
7cb2a241 912
b42865ce 913 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
4dd9fdf8
SC
914 BOOL r = superimpl(slf, (SEL)_cmd);
915 if ( r )
f06e0fea 916 {
b42865ce 917 DoNotifyFocusEvent( true, otherWindow );
f06e0fea 918 }
7cb2a241 919
4dd9fdf8
SC
920 return r;
921}
922
923bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
924{
925 wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
926 BOOL r = superimpl(slf, (SEL)_cmd);
b42865ce 927 // get the current focus after running resignFirstResponder
7cb2a241
SC
928 // note that this value isn't reliable, it might return the same view that
929 // is resigning
03647350 930 NSView* otherView = FindFocus();
b42865ce 931 wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
f06e0fea 932 // NSTextViews have an editor as true responder, therefore the might get the
7cb2a241
SC
933 // resign notification if their editor takes over, don't trigger any event then
934 if ( r && !m_hasEditor)
f06e0fea 935 {
b42865ce 936 DoNotifyFocusEvent( false, otherWindow );
f06e0fea 937 }
4dd9fdf8
SC
938 return r;
939}
940
941void wxWidgetCocoaImpl::resetCursorRects(WXWidget slf, void *_cmd)
942{
943 wxWindow* wxpeer = GetWXPeer();
944 if ( wxpeer )
945 {
946 NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();
947 if (cursor == NULL)
dbeddfb9 948 {
4dd9fdf8
SC
949 wxOSX_ResetCursorRectsHandlerPtr superimpl = (wxOSX_ResetCursorRectsHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
950 superimpl(slf, (SEL)_cmd);
dbeddfb9 951 }
4dd9fdf8 952 else
57c0a8ac 953 {
4dd9fdf8
SC
954 [slf addCursorRect: [slf bounds]
955 cursor: cursor];
57c0a8ac 956 }
4dd9fdf8
SC
957 }
958}
03647350 959
d8207702 960bool wxWidgetCocoaImpl::isFlipped(WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
4dd9fdf8
SC
961{
962 return m_isFlipped;
963}
33e90275 964
4dd9fdf8
SC
965
966#define OSX_DEBUG_DRAWING 0
967
d8207702 968void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
4dd9fdf8
SC
969{
970 CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
971 CGContextSaveGState( context );
03647350 972
4dd9fdf8
SC
973#if OSX_DEBUG_DRAWING
974 CGContextBeginPath( context );
975 CGContextMoveToPoint(context, 0, 0);
976 NSRect bounds = [self bounds];
977 CGContextAddLineToPoint(context, 10, 0);
978 CGContextMoveToPoint(context, 0, 0);
979 CGContextAddLineToPoint(context, 0, 10);
980 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
981 CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
982 CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
983 CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
984 CGContextClosePath( context );
985 CGContextStrokePath(context);
986#endif
987
988 if ( !m_isFlipped )
989 {
990 CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
991 CGContextScaleCTM( context, 1, -1 );
992 }
03647350 993
4dd9fdf8
SC
994 wxRegion updateRgn;
995 const NSRect *rects;
996 NSInteger count;
997
998 [slf getRectsBeingDrawn:&rects count:&count];
999 for ( int i = 0 ; i < count ; ++i )
1000 {
1001 updateRgn.Union(wxFromNSRect(slf, rects[i]) );
1002 }
1003
1004 wxWindow* wxpeer = GetWXPeer();
1005 wxpeer->GetUpdateRegion() = updateRgn;
1006 wxpeer->MacSetCGContextRef( context );
03647350 1007
09489833 1008 bool handled = wxpeer->MacDoRedraw( 0 );
03647350 1009
4dd9fdf8 1010 CGContextRestoreGState( context );
09489833
SC
1011
1012 CGContextSaveGState( context );
4dd9fdf8
SC
1013 if ( !handled )
1014 {
1015 // call super
1016 SEL _cmd = @selector(drawRect:);
1017 wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
1018 superimpl(slf, _cmd, *(NSRect*)rect);
09489833
SC
1019 CGContextRestoreGState( context );
1020 CGContextSaveGState( context );
33e90275 1021 }
09489833 1022 wxpeer->MacPaintChildrenBorders();
15fc716c 1023 wxpeer->MacSetCGContextRef( NULL );
09489833 1024 CGContextRestoreGState( context );
33e90275
SC
1025}
1026
d8207702 1027void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
4dd9fdf8
SC
1028{
1029 wxWindow* wxpeer = (wxWindow*) GetWXPeer();
1030 if ( wxpeer )
1031 wxpeer->OSXHandleClicked(0);
1032}
33e90275 1033
d8207702 1034void wxWidgetCocoaImpl::controlDoubleAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
524c47aa 1035{
524c47aa 1036}
33e90275 1037
03647350 1038//
4dd9fdf8
SC
1039
1040#if OBJC_API_VERSION >= 2
1041
1042#define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1043 class_addMethod(c, s, i, t );
1044
1045#else
1046
1047#define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
1048 { s, t, i },
1049
1050#endif
1051
1052void wxOSXCocoaClassAddWXMethods(Class c)
1053{
1054
1055#if OBJC_API_VERSION < 2
1056 static objc_method wxmethods[] =
1057 {
1058#endif
1059
1060 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1061 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1062 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
1063
1064 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1065 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1066 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
1067
1068 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseMoved:), (IMP) wxOSX_mouseEvent, "v@:@" )
1069
1070 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1071 wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1072 wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
1073
1074 wxOSX_CLASS_ADD_METHOD(c, @selector(scrollWheel:), (IMP) wxOSX_mouseEvent, "v@:@" )
1075 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
1076 wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
03647350 1077
4dd9fdf8
SC
1078 wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
1079 wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
1080 wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
03647350 1081
f0e0116e 1082 wxOSX_CLASS_ADD_METHOD(c, @selector(insertText:), (IMP) wxOSX_insertText, "v@:@" )
4dd9fdf8 1083
7cb2a241 1084 wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "c@:@" )
4dd9fdf8 1085
09a9eb20 1086 wxOSX_CLASS_ADD_METHOD(c, @selector(acceptsFirstResponder), (IMP) wxOSX_acceptsFirstResponder, "c@:" )
4dd9fdf8
SC
1087 wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
1088 wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
1089 wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
1090
1091 wxOSX_CLASS_ADD_METHOD(c, @selector(isFlipped), (IMP) wxOSX_isFlipped, "c@:" )
1092 wxOSX_CLASS_ADD_METHOD(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}" )
1093
e32090ba
SC
1094 wxOSX_CLASS_ADD_METHOD(c, @selector(controlAction:), (IMP) wxOSX_controlAction, "v@:@" )
1095 wxOSX_CLASS_ADD_METHOD(c, @selector(controlDoubleAction:), (IMP) wxOSX_controlDoubleAction, "v@:@" )
4dd9fdf8
SC
1096
1097#if wxUSE_DRAG_AND_DROP
1098 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingEntered:), (IMP) wxOSX_draggingEntered, "I@:@" )
1099 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingUpdated:), (IMP) wxOSX_draggingUpdated, "I@:@" )
1100 wxOSX_CLASS_ADD_METHOD(c, @selector(draggingExited:), (IMP) wxOSX_draggingExited, "v@:@" )
1101 wxOSX_CLASS_ADD_METHOD(c, @selector(performDragOperation:), (IMP) wxOSX_performDragOperation, "c@:@" )
03647350
VZ
1102#endif
1103
4dd9fdf8
SC
1104#if OBJC_API_VERSION < 2
1105 } ;
1106 static int method_count = WXSIZEOF( wxmethods );
1107 static objc_method_list *wxmethodlist = NULL;
1108 if ( wxmethodlist == NULL )
1109 {
1110 wxmethodlist = (objc_method_list*) malloc(sizeof(objc_method_list) + sizeof(wxmethods) );
1111 memcpy( &wxmethodlist->method_list[0], &wxmethods[0], sizeof(wxmethods) );
1112 wxmethodlist->method_count = method_count;
1113 wxmethodlist->obsolete = 0;
1114 }
1115 class_addMethods( c, wxmethodlist );
1116#endif
1117}
1118
1119//
1120// C++ implementation class
1121//
33e90275
SC
1122
1123IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
1124
1125wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
4dd9fdf8 1126 wxWidgetImpl( peer, isRootControl )
33e90275 1127{
4dd9fdf8
SC
1128 Init();
1129 m_osxView = w;
d94e9b62
VZ
1130
1131 // check if the user wants to create the control initially hidden
1132 if ( !peer->IsShown() )
1133 SetVisibility(false);
1134
9a038ddc
SC
1135 // gc aware handling
1136 if ( m_osxView )
1137 CFRetain(m_osxView);
1138 [m_osxView release];
33e90275
SC
1139}
1140
03647350 1141wxWidgetCocoaImpl::wxWidgetCocoaImpl()
33e90275 1142{
4dd9fdf8 1143 Init();
33e90275
SC
1144}
1145
1146void wxWidgetCocoaImpl::Init()
1147{
1148 m_osxView = NULL;
4dd9fdf8 1149 m_isFlipped = true;
f0e0116e 1150 m_lastKeyDownEvent = NULL;
7cb2a241 1151 m_hasEditor = false;
33e90275
SC
1152}
1153
1154wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
1155{
4dd9fdf8
SC
1156 RemoveAssociations( this );
1157
dbeddfb9
SC
1158 if ( !IsRootControl() )
1159 {
1160 NSView *sv = [m_osxView superview];
1161 if ( sv != nil )
1162 [m_osxView removeFromSuperview];
1163 }
9a038ddc
SC
1164 // gc aware handling
1165 if ( m_osxView )
1166 CFRelease(m_osxView);
33e90275 1167}
03647350
VZ
1168
1169bool wxWidgetCocoaImpl::IsVisible() const
33e90275
SC
1170{
1171 return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
1172}
1173
dbeddfb9
SC
1174void wxWidgetCocoaImpl::SetVisibility( bool visible )
1175{
1176 [m_osxView setHidden:(visible ? NO:YES)];
1177}
1178
33e90275
SC
1179void wxWidgetCocoaImpl::Raise()
1180{
11fed901 1181 // Not implemented
33e90275 1182}
03647350 1183
33e90275
SC
1184void wxWidgetCocoaImpl::Lower()
1185{
11fed901 1186 // Not implemented
33e90275
SC
1187}
1188
d8207702 1189void wxWidgetCocoaImpl::ScrollRect( const wxRect *WXUNUSED(rect), int WXUNUSED(dx), int WXUNUSED(dy) )
33e90275 1190{
54f11060
SC
1191#if 1
1192 SetNeedsDisplay() ;
1193#else
1194 // We should do something like this, but it wasn't working in 10.4.
1195 if (GetNeedsDisplay() )
1196 {
1197 SetNeedsDisplay() ;
1198 }
1199 NSRect r = wxToNSRect( [m_osxView superview], *rect );
1200 NSSize offset = NSMakeSize((float)dx, (float)dy);
1201 [m_osxView scrollRect:r by:offset];
1202#endif
33e90275
SC
1203}
1204
1205void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
1206{
0c530e5a 1207 wxWindowMac* parent = GetWXPeer()->GetParent();
03647350 1208 // under Cocoa we might have a contentView in the wxParent to which we have to
0c530e5a 1209 // adjust the coordinates
ea468399 1210 if (parent && [m_osxView superview] != parent->GetHandle() )
0c530e5a 1211 {
57c0a8ac
SC
1212 int cx = 0,cy = 0,cw = 0,ch = 0;
1213 if ( parent->GetPeer() )
1214 {
1215 parent->GetPeer()->GetContentArea(cx, cy, cw, ch);
1216 x -= cx;
1217 y -= cy;
1218 }
0c530e5a 1219 }
95fb3153 1220 [[m_osxView superview] setNeedsDisplayInRect:[m_osxView frame]];
33e90275
SC
1221 NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
1222 [m_osxView setFrame:r];
03647350
VZ
1223 [[m_osxView superview] setNeedsDisplayInRect:r];
1224
41af81ea 1225 if ([m_osxView respondsToSelector:@selector(trackingTag)] )
fc099495
KO
1226 {
1227 if ( [(wxNSView*)m_osxView trackingTag] )
1228 [m_osxView removeTrackingRect: [(wxNSView*)m_osxView trackingTag]];
03647350 1229
fc099495
KO
1230 [(wxNSView*)m_osxView setTrackingTag: [m_osxView addTrackingRect: [m_osxView bounds] owner: m_osxView userData: nil assumeInside: NO]];
1231 }
33e90275
SC
1232}
1233
1234void wxWidgetCocoaImpl::GetPosition( int &x, int &y ) const
1235{
1236 wxRect r = wxFromNSRect( [m_osxView superview], [m_osxView frame] );
1237 x = r.GetLeft();
1238 y = r.GetTop();
1239}
1240
1241void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
1242{
1243 NSRect rect = [m_osxView frame];
e490b0d2
VZ
1244 width = (int)rect.size.width;
1245 height = (int)rect.size.height;
33e90275
SC
1246}
1247
dbeddfb9 1248void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
33e90275 1249{
0c530e5a
SC
1250 if ( [m_osxView respondsToSelector:@selector(contentView) ] )
1251 {
1252 NSView* cv = [m_osxView contentView];
03647350 1253
0c530e5a
SC
1254 NSRect bounds = [m_osxView bounds];
1255 NSRect rect = [cv frame];
03647350 1256
e490b0d2
VZ
1257 int y = (int)rect.origin.y;
1258 int x = (int)rect.origin.x;
0c530e5a 1259 if ( ![ m_osxView isFlipped ] )
e490b0d2 1260 y = (int)(bounds.size.height - (rect.origin.y + rect.size.height));
0c530e5a
SC
1261 left = x;
1262 top = y;
e490b0d2
VZ
1263 width = (int)rect.size.width;
1264 height = (int)rect.size.height;
0c530e5a
SC
1265 }
1266 else
1267 {
1268 left = top = 0;
1269 GetSize( width, height );
1270 }
33e90275
SC
1271}
1272
1273void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
1274{
1275 if ( where )
1276 [m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )];
1277 else
1278 [m_osxView setNeedsDisplay:YES];
1279}
1280
1281bool wxWidgetCocoaImpl::GetNeedsDisplay() const
1282{
1283 return [m_osxView needsDisplay];
1284}
1285
dbeddfb9 1286bool wxWidgetCocoaImpl::CanFocus() const
33e90275 1287{
dbeddfb9 1288 return [m_osxView canBecomeKeyView] == YES;
33e90275
SC
1289}
1290
1291bool wxWidgetCocoaImpl::HasFocus() const
1292{
f06e0fea 1293 return ( FindFocus() == m_osxView );
33e90275
SC
1294}
1295
03647350 1296bool wxWidgetCocoaImpl::SetFocus()
33e90275 1297{
dbeddfb9
SC
1298 if ( [m_osxView canBecomeKeyView] == NO )
1299 return false;
03647350 1300
dbeddfb9 1301 [[m_osxView window] makeFirstResponder: m_osxView] ;
47e29847 1302 [[m_osxView window] makeKeyAndOrderFront:nil] ;
dbeddfb9 1303 return true;
33e90275
SC
1304}
1305
1306
1307void wxWidgetCocoaImpl::RemoveFromParent()
1308{
1309 [m_osxView removeFromSuperview];
1310}
1311
1312void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
1313{
1314 NSView* container = parent->GetWXWidget() ;
1315 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
1316 [container addSubview:m_osxView];
1317}
1318
dbeddfb9
SC
1319void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
1320{
1321 // m_osxView.backgroundColor = [[UIColor alloc] initWithCGColor:col.GetCGColor()];
1322}
1323
1324void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
1325{
1326 if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
1327 {
d8207702 1328 wxCFStringRef cf( title , encoding );
dbeddfb9
SC
1329 [m_osxView setTitle:cf.AsNSString()];
1330 }
e32090ba
SC
1331 else if ( [m_osxView respondsToSelector:@selector(setStringValue:) ] )
1332 {
d8207702 1333 wxCFStringRef cf( title , encoding );
e32090ba
SC
1334 [m_osxView setStringValue:cf.AsNSString()];
1335 }
dbeddfb9 1336}
03647350 1337
dbeddfb9
SC
1338
1339void wxWidgetImpl::Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to )
1340{
1341 NSPoint p = wxToNSPoint( from->GetWXWidget(), *pt );
03647350 1342 p = [from->GetWXWidget() convertPoint:p toView:to->GetWXWidget() ];
dbeddfb9
SC
1343 *pt = wxFromNSPoint( to->GetWXWidget(), p );
1344}
1345
03647350 1346wxInt32 wxWidgetCocoaImpl::GetValue() const
dbeddfb9
SC
1347{
1348 return [(NSControl*)m_osxView intValue];
1349}
1350
03647350 1351void wxWidgetCocoaImpl::SetValue( wxInt32 v )
dbeddfb9
SC
1352{
1353 if ( [m_osxView respondsToSelector:@selector(setIntValue:)] )
1354 {
1355 [m_osxView setIntValue:v];
1356 }
1357 else if ( [m_osxView respondsToSelector:@selector(setFloatValue:)] )
1358 {
1359 [m_osxView setFloatValue:(double)v];
1360 }
1361 else if ( [m_osxView respondsToSelector:@selector(setDoubleValue:)] )
1362 {
1363 [m_osxView setDoubleValue:(double)v];
1364 }
1365}
1366
03647350 1367void wxWidgetCocoaImpl::SetMinimum( wxInt32 v )
dbeddfb9
SC
1368{
1369 if ( [m_osxView respondsToSelector:@selector(setMinValue:)] )
1370 {
1371 [m_osxView setMinValue:(double)v];
1372 }
1373}
1374
03647350 1375void wxWidgetCocoaImpl::SetMaximum( wxInt32 v )
dbeddfb9
SC
1376{
1377 if ( [m_osxView respondsToSelector:@selector(setMaxValue:)] )
1378 {
1379 [m_osxView setMaxValue:(double)v];
1380 }
1381}
1382
03647350 1383wxInt32 wxWidgetCocoaImpl::GetMinimum() const
19c7ac3d
SC
1384{
1385 if ( [m_osxView respondsToSelector:@selector(getMinValue:)] )
1386 {
e490b0d2 1387 return (int)[m_osxView minValue];
19c7ac3d
SC
1388 }
1389 return 0;
1390}
1391
03647350 1392wxInt32 wxWidgetCocoaImpl::GetMaximum() const
19c7ac3d
SC
1393{
1394 if ( [m_osxView respondsToSelector:@selector(getMaxValue:)] )
1395 {
e490b0d2 1396 return (int)[m_osxView maxValue];
19c7ac3d
SC
1397 }
1398 return 0;
1399}
1400
e5d05b90
VZ
1401wxBitmap wxWidgetCocoaImpl::GetBitmap() const
1402{
1403 wxBitmap bmp;
1404
1405 // TODO: how to create a wxBitmap from NSImage?
1406#if 0
1407 if ( [m_osxView respondsToSelector:@selector(image:)] )
1408 bmp = [m_osxView image];
1409#endif
1410
1411 return bmp;
1412}
1413
dbeddfb9
SC
1414void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
1415{
1416 if ( [m_osxView respondsToSelector:@selector(setImage:)] )
1417 {
1418 [m_osxView setImage:bitmap.GetNSImage()];
1419 }
1420}
1421
e5d05b90
VZ
1422void wxWidgetCocoaImpl::SetBitmapPosition( wxDirection dir )
1423{
1424 if ( [m_osxView respondsToSelector:@selector(setImagePosition:)] )
1425 {
1426 NSCellImagePosition pos;
1427 switch ( dir )
1428 {
1429 case wxLEFT:
1430 pos = NSImageLeft;
1431 break;
1432
1433 case wxRIGHT:
1434 pos = NSImageRight;
1435 break;
1436
1437 case wxTOP:
1438 pos = NSImageAbove;
1439 break;
1440
1441 case wxBOTTOM:
1442 pos = NSImageBelow;
1443 break;
1444
1445 default:
1446 wxFAIL_MSG( "invalid image position" );
1447 pos = NSNoImage;
1448 }
1449
1450 [m_osxView setImagePosition:pos];
1451 }
1452}
1453
d8207702 1454void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& WXUNUSED(notebook))
dbeddfb9
SC
1455{
1456 // implementation in subclass
1457}
1458
1459void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
1460{
1461 r->x = r->y = r->width = r->height = 0;
09a9eb20 1462
dbeddfb9
SC
1463 if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
1464 {
1465 NSRect former = [m_osxView frame];
1466 [m_osxView sizeToFit];
1467 NSRect best = [m_osxView frame];
1468 [m_osxView setFrame:former];
e490b0d2
VZ
1469 r->width = (int)best.size.width;
1470 r->height = (int)best.size.height;
dbeddfb9
SC
1471 }
1472}
1473
1474bool wxWidgetCocoaImpl::IsEnabled() const
1475{
0f9b48d1
SC
1476 if ( [m_osxView respondsToSelector:@selector(isEnabled) ] )
1477 return [m_osxView isEnabled];
1478 return true;
dbeddfb9
SC
1479}
1480
1481void wxWidgetCocoaImpl::Enable( bool enable )
1482{
0f9b48d1
SC
1483 if ( [m_osxView respondsToSelector:@selector(setEnabled:) ] )
1484 [m_osxView setEnabled:enable];
dbeddfb9
SC
1485}
1486
1487void wxWidgetCocoaImpl::PulseGauge()
1488{
1489}
1490
d8207702 1491void wxWidgetCocoaImpl::SetScrollThumb( wxInt32 WXUNUSED(val), wxInt32 WXUNUSED(view) )
dbeddfb9
SC
1492{
1493}
33e90275 1494
03647350 1495void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
0f9b48d1
SC
1496{
1497 NSControlSize size = NSRegularControlSize;
03647350 1498
0f9b48d1
SC
1499 switch ( variant )
1500 {
1501 case wxWINDOW_VARIANT_NORMAL :
1502 size = NSRegularControlSize;
1503 break ;
1504
1505 case wxWINDOW_VARIANT_SMALL :
1506 size = NSSmallControlSize;
1507 break ;
1508
1509 case wxWINDOW_VARIANT_MINI :
1510 size = NSMiniControlSize;
1511 break ;
1512
1513 case wxWINDOW_VARIANT_LARGE :
1514 size = NSRegularControlSize;
1515 break ;
1516
1517 default:
9a83f860 1518 wxFAIL_MSG(wxT("unexpected window variant"));
0f9b48d1
SC
1519 break ;
1520 }
1521 if ( [m_osxView respondsToSelector:@selector(setControlSize:)] )
1522 [m_osxView setControlSize:size];
03647350
VZ
1523 else if ([m_osxView respondsToSelector:@selector(cell)])
1524 {
1525 id cell = [(id)m_osxView cell];
1526 if ([cell respondsToSelector:@selector(setControlSize:)])
1527 [cell setControlSize:size];
1528 }
0f9b48d1
SC
1529}
1530
09a9eb20 1531void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
1e181c7a 1532{
09a9eb20 1533 if ([m_osxView respondsToSelector:@selector(setFont:)])
aa6208d9 1534 [m_osxView setFont: font.OSXGetNSFont()];
1e181c7a
SC
1535}
1536
c4825ef7
SC
1537void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
1538{
4dd9fdf8
SC
1539 WXWidget c = control ? control : (WXWidget) m_osxView;
1540 wxWidgetImpl::Associate( c, this ) ;
1541 if ([c respondsToSelector:@selector(setAction:)])
1542 {
1543 [c setTarget: c];
e32090ba 1544 [c setAction: @selector(controlAction:)];
4dd9fdf8
SC
1545 if ([c respondsToSelector:@selector(setDoubleAction:)])
1546 {
e32090ba 1547 [c setDoubleAction: @selector(controlDoubleAction:)];
4dd9fdf8 1548 }
03647350 1549
4dd9fdf8 1550 }
c4825ef7
SC
1551}
1552
f0e0116e
KO
1553bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
1554{
4d61ae5f 1555 wxKeyEvent wxevent(wxEVT_CHAR);
f0e0116e 1556 SetupKeyEvent( wxevent, event, text );
03647350 1557 wxevent.SetEventObject(GetWXPeer());
f0e0116e
KO
1558
1559 return GetWXPeer()->OSXHandleKeyEvent(wxevent);
1560}
1561
ffad7b0d
SC
1562bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
1563{
1564 wxKeyEvent wxevent(wxEVT_KEY_DOWN);
1565 SetupKeyEvent( wxevent, event );
03647350 1566 wxevent.SetEventObject(GetWXPeer());
f0e0116e 1567 bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
19c7ac3d 1568
f0e0116e
KO
1569 // this will fire higher level events, like insertText, to help
1570 // us handle EVT_CHAR, etc.
7cb2a241 1571 if ( !m_hasEditor && [event type] == NSKeyDown)
f0e0116e
KO
1572 {
1573 m_lastKeyDownEvent = event;
4d61ae5f 1574 if ( !result )
7cb2a241
SC
1575 {
1576 if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
1577 [[(NSScrollView*)m_osxView documentView] interpretKeyEvents:[NSArray arrayWithObject:event]];
1578 else
1579 [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
1580 result = true;
1581 }
f0e0116e 1582 }
f0e0116e 1583 return result;
ffad7b0d
SC
1584}
1585
b466e85a 1586bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
4850cc8b 1587{
03647350
VZ
1588 NSPoint clickLocation;
1589 clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil];
4850cc8b
SC
1590 wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
1591 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
1592 SetupMouseEvent( wxevent , event ) ;
540f4445 1593 wxevent.SetEventObject(GetWXPeer());
4850cc8b
SC
1594 wxevent.m_x = pt.x;
1595 wxevent.m_y = pt.y;
b466e85a
SC
1596
1597 return GetWXPeer()->HandleWindowEvent(wxevent);
4850cc8b
SC
1598}
1599
b42865ce 1600void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
0c530e5a
SC
1601{
1602 wxWindow* thisWindow = GetWXPeer();
1603 if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
1604 {
1605 thisWindow->MacInvalidateBorders();
1606 }
1607
1608 if ( receivedFocus )
1609 {
9a83f860 1610 wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
0c530e5a
SC
1611 wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
1612 thisWindow->HandleWindowEvent(eventFocus);
1613
1614#if wxUSE_CARET
1615 if ( thisWindow->GetCaret() )
1616 thisWindow->GetCaret()->OnSetFocus();
1617#endif
1618
1619 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
1620 event.SetEventObject(thisWindow);
b42865ce
KO
1621 if (otherWindow)
1622 event.SetWindow(otherWindow->GetWXPeer());
0c530e5a
SC
1623 thisWindow->HandleWindowEvent(event) ;
1624 }
1625 else // !receivedFocuss
1626 {
1627#if wxUSE_CARET
1628 if ( thisWindow->GetCaret() )
1629 thisWindow->GetCaret()->OnKillFocus();
1630#endif
1631
9a83f860 1632 wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
03647350 1633
0c530e5a
SC
1634 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
1635 event.SetEventObject(thisWindow);
b42865ce
KO
1636 if (otherWindow)
1637 event.SetWindow(otherWindow->GetWXPeer());
0c530e5a
SC
1638 thisWindow->HandleWindowEvent(event) ;
1639 }
1640}
1641
54f11060
SC
1642void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor)
1643{
1644 NSPoint location = [NSEvent mouseLocation];
1645 location = [[m_osxView window] convertScreenToBase:location];
1646 NSPoint locationInView = [m_osxView convertPoint:location fromView:nil];
1647
1648 if( NSMouseInRect(locationInView, [m_osxView bounds], YES) )
1649 {
1650 [(NSCursor*)cursor.GetHCURSOR() set];
1651 }
1652 [[m_osxView window] invalidateCursorRectsForView:m_osxView];
1653}
1654
1655void wxWidgetCocoaImpl::CaptureMouse()
1656{
1657 [[m_osxView window] disableCursorRects];
1658}
1659
1660void wxWidgetCocoaImpl::ReleaseMouse()
1661{
1662 [[m_osxView window] enableCursorRects];
1663}
4850cc8b 1664
4dd9fdf8
SC
1665void wxWidgetCocoaImpl::SetFlipped(bool flipped)
1666{
1667 m_isFlipped = flipped;
1668}
1669
33e90275
SC
1670//
1671// Factory methods
1672//
1673
03647350 1674wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent),
d8207702
SC
1675 wxWindowID WXUNUSED(id), const wxPoint& pos, const wxSize& size,
1676 long WXUNUSED(style), long WXUNUSED(extraStyle))
33e90275 1677{
dbeddfb9 1678 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
33e90275 1679 wxNSView* v = [[wxNSView alloc] initWithFrame:r];
4dd9fdf8
SC
1680
1681 // temporary hook for dnd
1682 [v registerForDraggedTypes:[NSArray arrayWithObjects:
1683 NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
03647350 1684
33e90275 1685 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
33e90275
SC
1686 return c;
1687}
1688
03647350 1689wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
33e90275
SC
1690{
1691 NSWindow* tlw = now->GetWXWindow();
1692 wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
1693 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
7e06ee6d 1694 c->InstallEventHandler();
33e90275
SC
1695 [tlw setContentView:v];
1696 return c;
1697}