removing unnecessary code
[wxWidgets.git] / src / mac / carbon / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/menu.h"
15 #include "wx/window.h"
16 #include "wx/dc.h"
17 #include "wx/dcclient.h"
18 #include "wx/utils.h"
19 #include "wx/app.h"
20 #include "wx/panel.h"
21 #include "wx/layout.h"
22 #include "wx/dialog.h"
23 #include "wx/scrolbar.h"
24 #include "wx/statbox.h"
25 #include "wx/button.h"
26 #include "wx/settings.h"
27 #include "wx/msgdlg.h"
28 #include "wx/frame.h"
29 #include "wx/tooltip.h"
30 #include "wx/statusbr.h"
31 #include "wx/menuitem.h"
32 #include "wx/spinctrl.h"
33 #include "wx/log.h"
34 #include "wx/geometry.h"
35 #include "wx/textctrl.h"
36
37 #include "wx/toolbar.h"
38 #include "wx/dc.h"
39
40 #if wxUSE_CARET
41 #include "wx/caret.h"
42 #endif
43
44 #define MAC_SCROLLBAR_SIZE 15
45 #define MAC_SMALL_SCROLLBAR_SIZE 11
46
47 #include "wx/mac/uma.h"
48
49 #ifndef __DARWIN__
50 #include <Windows.h>
51 #include <ToolUtils.h>
52 #include <Scrap.h>
53 #include <MacTextEditor.h>
54 #endif
55
56 #if TARGET_API_MAC_OSX
57 #ifndef __HIVIEW__
58 #include <HIToolbox/HIView.h>
59 #endif
60 #endif
61
62 #if wxUSE_DRAG_AND_DROP
63 #include "wx/dnd.h"
64 #endif
65
66 #include <string.h>
67
68 extern wxList wxPendingDelete;
69
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
72 #else
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
74 #endif
75
76 BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
77 EVT_NC_PAINT(wxWindowMac::OnNcPaint)
78 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
79 #if TARGET_API_MAC_OSX
80 EVT_PAINT(wxWindowMac::OnPaint)
81 #endif
82 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
83 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
85 END_EVENT_TABLE()
86
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
90 #endif
91
92 #define wxMAC_USE_THEME_BORDER 1
93
94 // ---------------------------------------------------------------------------
95 // Utility Routines to move between different coordinate systems
96 // ---------------------------------------------------------------------------
97
98 /*
99 * Right now we have the following setup :
100 * a border that is not part of the native control is always outside the
101 * control's border (otherwise we loose all native intelligence, future ways
102 * may be to have a second embedding control responsible for drawing borders
103 * and backgrounds eventually)
104 * so all this border calculations have to be taken into account when calling
105 * native methods or getting native oriented data
106 * so we have three coordinate systems here
107 * wx client coordinates
108 * wx window coordinates (including window frames)
109 * native coordinates
110 */
111
112 //
113 // originating from native control
114 //
115
116
117 void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle )
118 {
119 OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
120 }
121
122 void wxMacNativeToWindow( const wxWindow* window , Rect *rect )
123 {
124 OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
125 }
126
127 //
128 // directed towards native control
129 //
130
131 void wxMacWindowToNative( const wxWindow* window , RgnHandle handle )
132 {
133 OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
134 }
135
136 void wxMacWindowToNative( const wxWindow* window , Rect *rect )
137 {
138 OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ;
139 }
140
141 // ---------------------------------------------------------------------------
142 // Carbon Events
143 // ---------------------------------------------------------------------------
144
145 extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
146 pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ;
147
148 #if TARGET_API_MAC_OSX
149
150 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
151 enum
152 {
153 kEventControlVisibilityChanged = 157
154 };
155 #endif
156
157 #endif
158
159 static const EventTypeSpec eventList[] =
160 {
161 { kEventClassControl , kEventControlHit } ,
162
163 #if TARGET_API_MAC_OSX
164 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
165 { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
166
167 { kEventClassControl , kEventControlDraw } ,
168 { kEventClassControl , kEventControlVisibilityChanged } ,
169 { kEventClassControl , kEventControlEnabledStateChanged } ,
170 { kEventClassControl , kEventControlHiliteChanged } ,
171 { kEventClassControl , kEventControlSetFocusPart } ,
172
173 { kEventClassService , kEventServiceGetTypes },
174 { kEventClassService , kEventServiceCopy },
175 { kEventClassService , kEventServicePaste },
176
177 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
178 // { kEventClassControl , kEventControlBoundsChanged } ,
179 #endif
180 } ;
181
182 static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
183 {
184 OSStatus result = eventNotHandledErr ;
185
186 wxMacCarbonEvent cEvent( event ) ;
187
188 ControlRef controlRef ;
189 wxWindowMac* thisWindow = (wxWindowMac*) data ;
190
191 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
192
193 switch ( GetEventKind( event ) )
194 {
195 #if TARGET_API_MAC_OSX
196 case kEventControlDraw :
197 {
198 RgnHandle updateRgn = NULL ;
199 RgnHandle allocatedRgn = NULL ;
200 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
201 Rect controlBounds ;
202
203 if ( ! thisWindow->GetPeer()->IsCompositing() )
204 {
205 if ( thisWindow->GetPeer()->IsRootControl() )
206 thisWindow->GetPeer()->GetRect( &controlBounds ) ;
207 else
208 GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ;
209 }
210
211 if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
212 {
213 updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
214 }
215 else
216 {
217 if ( ! thisWindow->GetPeer()->IsCompositing() )
218 {
219 allocatedRgn = NewRgn() ;
220 CopyRgn( updateRgn , allocatedRgn ) ;
221 OffsetRgn( allocatedRgn , -controlBounds.left , -controlBounds.top ) ;
222
223 // hide the given region by the new region that must be shifted
224 wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
225 updateRgn = allocatedRgn ;
226 }
227 else
228 {
229 if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
230 {
231 // as this update region is in native window locals we must adapt it to wx window local
232 allocatedRgn = NewRgn() ;
233 CopyRgn( updateRgn , allocatedRgn ) ;
234
235 // hide the given region by the new region that must be shifted
236 wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
237 updateRgn = allocatedRgn ;
238 }
239 }
240 }
241
242 Rect rgnBounds ;
243 GetRegionBounds( updateRgn , &rgnBounds ) ;
244
245 #if wxMAC_DEBUG_REDRAW
246 if ( thisWindow->MacIsUserPane() )
247 {
248 static float color = 0.5 ;
249 static channel = 0 ;
250 HIRect bounds;
251 CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
252
253 HIViewGetBounds( controlRef, &bounds );
254 CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 ,
255 channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 );
256 CGContextFillRect( cgContext, bounds );
257 color += 0.1 ;
258 if ( color > 0.9 )
259 {
260 color = 0.5 ;
261 channel++ ;
262 if ( channel == 3 )
263 channel = 0 ;
264 }
265 }
266 #endif
267
268 {
269 #if wxMAC_USE_CORE_GRAPHICS
270 bool created = false ;
271 CGContextRef cgContext = NULL ;
272 if ( cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) != noErr )
273 {
274 wxASSERT( thisWindow->GetPeer()->IsCompositing() == false ) ;
275
276 // this parameter is not provided on non-composited windows
277 created = true ;
278
279 // rest of the code expects this to be already transformed and clipped for local
280 CGrafPtr port = GetWindowPort( (WindowRef) thisWindow->MacGetTopLevelWindowRef() ) ;
281 Rect bounds ;
282 GetPortBounds( port , &bounds ) ;
283 CreateCGContextForPort( port , &cgContext ) ;
284
285 wxMacWindowToNative( thisWindow , updateRgn ) ;
286 OffsetRgn( updateRgn , controlBounds.left , controlBounds.top ) ;
287 ClipCGContextToRegion( cgContext , &bounds , updateRgn ) ;
288 wxMacNativeToWindow( thisWindow , updateRgn ) ;
289 OffsetRgn( updateRgn , -controlBounds.left , -controlBounds.top ) ;
290
291 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
292 CGContextScaleCTM( cgContext , 1 , -1 ) ;
293
294 CGContextTranslateCTM( cgContext , controlBounds.left , controlBounds.top ) ;
295
296 #if 0
297 CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
298 CGContextFillRect( cgContext ,
299 CGRectMake( 0 , 0 ,
300 controlBounds.right - controlBounds.left ,
301 controlBounds.bottom - controlBounds.top ) );
302 #endif
303 }
304
305 thisWindow->MacSetCGContextRef( cgContext ) ;
306
307 {
308 wxMacCGContextStateSaver sg( cgContext ) ;
309 #endif
310 if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
311 result = noErr ;
312
313 #if wxMAC_USE_CORE_GRAPHICS
314 thisWindow->MacSetCGContextRef( NULL ) ;
315 }
316
317 if ( created )
318 CGContextRelease( cgContext ) ;
319 #endif
320 }
321
322 if ( allocatedRgn )
323 DisposeRgn( allocatedRgn ) ;
324 }
325 break ;
326
327 case kEventControlVisibilityChanged :
328 thisWindow->MacVisibilityChanged() ;
329 break ;
330
331 case kEventControlEnabledStateChanged :
332 thisWindow->MacEnabledStateChanged() ;
333 break ;
334
335 case kEventControlHiliteChanged :
336 thisWindow->MacHiliteChanged() ;
337 break ;
338 #endif
339
340 // we emulate this event under Carbon CFM
341 case kEventControlSetFocusPart :
342 {
343 Boolean focusEverything = false ;
344 ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
345
346 #ifdef __WXMAC_OSX__
347 if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
348 {
349 }
350 #endif
351
352 if ( controlPart == kControlFocusNoPart )
353 {
354 #if wxUSE_CARET
355 if ( thisWindow->GetCaret() )
356 thisWindow->GetCaret()->OnKillFocus();
357 #endif
358
359 static bool inKillFocusEvent = false ;
360
361 if ( !inKillFocusEvent )
362 {
363 inKillFocusEvent = true ;
364 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
365 event.SetEventObject(thisWindow);
366 thisWindow->GetEventHandler()->ProcessEvent(event) ;
367 inKillFocusEvent = false ;
368 }
369 }
370 else
371 {
372 // panel wants to track the window which was the last to have focus in it
373 wxChildFocusEvent eventFocus(thisWindow);
374 thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
375
376 #if wxUSE_CARET
377 if ( thisWindow->GetCaret() )
378 thisWindow->GetCaret()->OnSetFocus();
379 #endif
380
381 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
382 event.SetEventObject(thisWindow);
383 thisWindow->GetEventHandler()->ProcessEvent(event) ;
384 }
385
386 if ( thisWindow->MacIsUserPane() )
387 result = noErr ;
388 }
389 break ;
390
391 case kEventControlHit :
392 result = thisWindow->MacControlHit( handler , event ) ;
393 break ;
394
395 default :
396 break ;
397 }
398
399 return result ;
400 }
401
402 static pascal OSStatus wxMacWindowServiceEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
403 {
404 OSStatus result = eventNotHandledErr ;
405
406 wxMacCarbonEvent cEvent( event ) ;
407
408 ControlRef controlRef ;
409 wxWindowMac* thisWindow = (wxWindowMac*) data ;
410 wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ;
411 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
412
413 switch ( GetEventKind( event ) )
414 {
415 case kEventServiceGetTypes :
416 if ( textCtrl )
417 {
418 long from, to ;
419 textCtrl->GetSelection( &from , &to ) ;
420
421 CFMutableArrayRef copyTypes = 0 , pasteTypes = 0;
422 if ( from != to )
423 copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ;
424 if ( textCtrl->IsEditable() )
425 pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ;
426
427 static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
428 for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i )
429 {
430 CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]);
431 if ( typestring )
432 {
433 if ( copyTypes )
434 CFArrayAppendValue(copyTypes, typestring) ;
435 if ( pasteTypes )
436 CFArrayAppendValue(pasteTypes, typestring) ;
437
438 CFRelease( typestring ) ;
439 }
440 }
441
442 result = noErr ;
443 }
444 break ;
445
446 case kEventServiceCopy :
447 if ( textCtrl )
448 {
449 long from, to ;
450
451 textCtrl->GetSelection( &from , &to ) ;
452 wxString val = textCtrl->GetValue() ;
453 val = val.Mid( from , to - from ) ;
454 ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
455 verify_noerr( ClearScrap( &scrapRef ) ) ;
456 verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.length() , val.c_str() ) ) ;
457 result = noErr ;
458 }
459 break ;
460
461 case kEventServicePaste :
462 if ( textCtrl )
463 {
464 ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
465 Size textSize, pastedSize ;
466 verify_noerr( GetScrapFlavorSize(scrapRef, kTXNTextData, &textSize) ) ;
467 textSize++ ;
468 char *content = new char[textSize] ;
469 GetScrapFlavorData(scrapRef, kTXNTextData, &pastedSize, content );
470 content[textSize - 1] = 0 ;
471
472 #if wxUSE_UNICODE
473 textCtrl->WriteText( wxString( content , wxConvLocal ) );
474 #else
475 textCtrl->WriteText( wxString( content ) ) ;
476 #endif
477
478 delete[] content ;
479 result = noErr ;
480 }
481 break ;
482
483 default:
484 break ;
485 }
486
487 return result ;
488 }
489
490 pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
491 {
492 OSStatus result = eventNotHandledErr ;
493 wxWindowMac* focus = (wxWindowMac*) data ;
494
495 wchar_t* uniChars = NULL ;
496 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
497
498 UniChar* charBuf;
499 UInt32 dataSize = 0 ;
500 int numChars = 0 ;
501 UniChar buf[2] ;
502 if ( GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr )
503 {
504 numChars = dataSize / sizeof( UniChar) ;
505 charBuf = buf ;
506
507 if ( dataSize > sizeof(buf) )
508 charBuf = new UniChar[ numChars ] ;
509 else
510 charBuf = buf ;
511
512 uniChars = new wchar_t[ numChars ] ;
513 GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
514 #if SIZEOF_WCHAR_T == 2
515 uniChars = charBuf ;
516 memcpy( uniChars , charBuf , dataSize ) ;
517 #else
518 // the resulting string will never have more chars than the utf16 version, so this is safe
519 wxMBConvUTF16 converter ;
520 numChars = converter.MB2WC( uniChars , (const char*)charBuf , numChars ) ;
521 #endif
522 }
523
524 switch ( GetEventKind( event ) )
525 {
526 case kEventTextInputUpdateActiveInputArea :
527 {
528 // An IME input event may return several characters, but we need to send one char at a time to
529 // EVT_CHAR
530 for (int pos=0 ; pos < numChars ; pos++)
531 {
532
533 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
534 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
535 wxTheApp->MacSetCurrentEvent( event , handler ) ;
536
537 UInt32 message = (0 << 8) + ((char)uniChars[pos] );
538 if ( wxTheApp->MacSendCharEvent(
539 focus , message , 0 , when , 0 , 0 , uniChars[pos] ) )
540 {
541 result = noErr ;
542 }
543
544 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
545 }
546 }
547 break ;
548 case kEventTextInputUnicodeForKeyEvent :
549 {
550 UInt32 keyCode, modifiers ;
551 Point point ;
552 EventRef rawEvent ;
553 unsigned char charCode ;
554
555 GetEventParameter( event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, sizeof(rawEvent), NULL, &rawEvent ) ;
556 GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode );
557 GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
558 GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers );
559 GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point );
560
561 UInt32 message = (keyCode << 8) + charCode;
562
563 // An IME input event may return several characters, but we need to send one char at a time to
564 // EVT_CHAR
565 for (int pos=0 ; pos < numChars ; pos++)
566 {
567
568 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
569 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
570 wxTheApp->MacSetCurrentEvent( event , handler ) ;
571
572 if ( wxTheApp->MacSendCharEvent(
573 focus , message , modifiers , when , point.h , point.v , uniChars[pos] ) )
574 {
575 result = noErr ;
576 }
577
578 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
579 }
580 }
581 break;
582 default:
583 break ;
584 }
585
586 delete[] uniChars ;
587 if ( charBuf != buf )
588 delete[] charBuf ;
589
590 return result ;
591
592 }
593
594 pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
595 {
596 EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
597 EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
598 wxTheApp->MacSetCurrentEvent( event , handler ) ;
599 OSStatus result = eventNotHandledErr ;
600
601 switch ( GetEventClass( event ) )
602 {
603 case kEventClassControl :
604 result = wxMacWindowControlEventHandler( handler, event, data ) ;
605 break ;
606
607 case kEventClassService :
608 result = wxMacWindowServiceEventHandler( handler, event , data ) ;
609 break ;
610
611 case kEventClassTextInput :
612 result = wxMacUnicodeTextEventHandler( handler , event , data ) ;
613 break ;
614 default :
615 break ;
616 }
617
618 wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
619
620 return result ;
621 }
622
623 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
624
625 #if !TARGET_API_MAC_OSX
626
627 // ---------------------------------------------------------------------------
628 // UserPane events for non OSX builds
629 // ---------------------------------------------------------------------------
630
631 static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
632 {
633 wxWindow * win = wxFindControlFromMacControl(control) ;
634 if ( win )
635 win->MacControlUserPaneDrawProc(part) ;
636 }
637 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP , wxMacControlUserPaneDrawProc ) ;
638
639 static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
640 {
641 wxWindow * win = wxFindControlFromMacControl(control) ;
642 if ( win )
643 return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
644 else
645 return kControlNoPart ;
646 }
647 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP , wxMacControlUserPaneHitTestProc ) ;
648
649 static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
650 {
651 wxWindow * win = wxFindControlFromMacControl(control) ;
652 if ( win )
653 return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
654 else
655 return kControlNoPart ;
656 }
657 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP , wxMacControlUserPaneTrackingProc ) ;
658
659 static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
660 {
661 wxWindow * win = wxFindControlFromMacControl(control) ;
662 if ( win )
663 win->MacControlUserPaneIdleProc() ;
664 }
665 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP , wxMacControlUserPaneIdleProc ) ;
666
667 static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
668 {
669 wxWindow * win = wxFindControlFromMacControl(control) ;
670 if ( win )
671 return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
672 else
673 return kControlNoPart ;
674 }
675 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP , wxMacControlUserPaneKeyDownProc ) ;
676
677 static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
678 {
679 wxWindow * win = wxFindControlFromMacControl(control) ;
680 if ( win )
681 win->MacControlUserPaneActivateProc(activating) ;
682 }
683 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP , wxMacControlUserPaneActivateProc ) ;
684
685 static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
686 {
687 wxWindow * win = wxFindControlFromMacControl(control) ;
688 if ( win )
689 return win->MacControlUserPaneFocusProc(action) ;
690 else
691 return kControlNoPart ;
692 }
693 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP , wxMacControlUserPaneFocusProc ) ;
694
695 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
696 {
697 wxWindow * win = wxFindControlFromMacControl(control) ;
698 if ( win )
699 win->MacControlUserPaneBackgroundProc(info) ;
700 }
701 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP , wxMacControlUserPaneBackgroundProc ) ;
702
703 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part)
704 {
705 int x = 0 , y = 0;
706 RgnHandle rgn = NewRgn() ;
707 GetClip( rgn ) ;
708 MacWindowToRootWindow( &x, &y ) ;
709 OffsetRgn( rgn , -x , -y ) ;
710 wxMacWindowStateSaver sv( this ) ;
711 SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ;
712 MacDoRedraw( rgn , 0 ) ;
713 DisposeRgn( rgn ) ;
714 }
715
716 wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
717 {
718 return kControlNoPart ;
719 }
720
721 wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
722 {
723 return kControlNoPart ;
724 }
725
726 void wxWindowMac::MacControlUserPaneIdleProc()
727 {
728 }
729
730 wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
731 {
732 return kControlNoPart ;
733 }
734
735 void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
736 {
737 }
738
739 wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
740 {
741 if ( AcceptsFocus() )
742 return 1 ;
743 else
744 return kControlNoPart ;
745 }
746
747 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
748 {
749 }
750
751 #endif
752
753 // ---------------------------------------------------------------------------
754 // Scrollbar Tracking for all
755 // ---------------------------------------------------------------------------
756
757 pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ;
758 pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode )
759 {
760 if ( partCode != 0)
761 {
762 wxWindow* wx = wxFindControlFromMacControl( control ) ;
763 if ( wx )
764 wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
765 }
766 }
767 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ;
768
769 // ===========================================================================
770 // implementation
771 // ===========================================================================
772
773 WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap);
774
775 static MacControlMap wxWinMacControlList;
776
777 wxWindow *wxFindControlFromMacControl(ControlRef inControl )
778 {
779 MacControlMap::iterator node = wxWinMacControlList.find(inControl);
780
781 return (node == wxWinMacControlList.end()) ? NULL : node->second;
782 }
783
784 void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
785 {
786 // adding NULL ControlRef is (first) surely a result of an error and
787 // (secondly) breaks native event processing
788 wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
789
790 wxWinMacControlList[inControl] = control;
791 }
792
793 void wxRemoveMacControlAssociation(wxWindow *control)
794 {
795 // iterate over all the elements in the class
796 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
797 // we should go on...
798
799 bool found = true ;
800 while ( found )
801 {
802 found = false ;
803 MacControlMap::iterator it;
804 for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
805 {
806 if ( it->second == control )
807 {
808 wxWinMacControlList.erase(it);
809 found = true ;
810 break;
811 }
812 }
813 }
814 }
815
816 // ----------------------------------------------------------------------------
817 // constructors and such
818 // ----------------------------------------------------------------------------
819
820 wxWindowMac::wxWindowMac()
821 {
822 Init();
823 }
824
825 wxWindowMac::wxWindowMac(wxWindowMac *parent,
826 wxWindowID id,
827 const wxPoint& pos ,
828 const wxSize& size ,
829 long style ,
830 const wxString& name )
831 {
832 Init();
833 Create(parent, id, pos, size, style, name);
834 }
835
836 void wxWindowMac::Init()
837 {
838 m_peer = NULL ;
839 m_frozenness = 0 ;
840
841 #if WXWIN_COMPATIBILITY_2_4
842 m_backgroundTransparent = false;
843 #endif
844
845 #if wxMAC_USE_CORE_GRAPHICS
846 m_cgContextRef = NULL ;
847 #endif
848
849 // as all windows are created with WS_VISIBLE style...
850 m_isShown = true;
851
852 m_hScrollBar = NULL ;
853 m_vScrollBar = NULL ;
854 m_macBackgroundBrush = wxNullBrush ;
855
856 m_macIsUserPane = true;
857 m_clipChildren = false ;
858 m_cachedClippedRectValid = false ;
859
860 // we need a valid font for the encodings
861 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
862 }
863
864 // Destructor
865 wxWindowMac::~wxWindowMac()
866 {
867 SendDestroyEvent();
868
869 m_isBeingDeleted = true;
870
871 MacInvalidateBorders() ;
872
873 #ifndef __WXUNIVERSAL__
874 // VS: make sure there's no wxFrame with last focus set to us:
875 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
876 {
877 wxFrame *frame = wxDynamicCast(win, wxFrame);
878 if ( frame )
879 {
880 if ( frame->GetLastFocus() == this )
881 frame->SetLastFocus((wxWindow*)NULL);
882 break;
883 }
884 }
885 #endif // __WXUNIVERSAL__
886
887 // destroy children before destroying this window itself
888 DestroyChildren();
889
890 // wxRemoveMacControlAssociation( this ) ;
891 // If we delete an item, we should initialize the parent panel,
892 // because it could now be invalid.
893 wxWindow *parent = GetParent() ;
894 if ( parent )
895 {
896 if (parent->GetDefaultItem() == (wxButton*) this)
897 parent->SetDefaultItem(NULL);
898 }
899
900 if ( m_peer && m_peer->Ok() )
901 {
902 // in case the callback might be called during destruction
903 wxRemoveMacControlAssociation( this) ;
904 ::RemoveEventHandler( (EventHandlerRef ) m_macControlEventHandler ) ;
905 // we currently are not using this hook
906 // ::SetControlColorProc( *m_peer , NULL ) ;
907 m_peer->Dispose() ;
908 }
909
910 if ( g_MacLastWindow == this )
911 g_MacLastWindow = NULL ;
912
913 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
914 if ( frame )
915 {
916 if ( frame->GetLastFocus() == this )
917 frame->SetLastFocus( NULL ) ;
918 }
919
920 // delete our drop target if we've got one
921 #if wxUSE_DRAG_AND_DROP
922 if ( m_dropTarget != NULL )
923 {
924 delete m_dropTarget;
925 m_dropTarget = NULL;
926 }
927 #endif
928
929 delete m_peer ;
930 }
931
932 WXWidget wxWindowMac::GetHandle() const
933 {
934 return (WXWidget) m_peer->GetControlRef() ;
935 }
936
937 void wxWindowMac::MacInstallEventHandler( WXWidget control )
938 {
939 wxAssociateControlWithMacControl( (ControlRef) control , this ) ;
940 InstallControlEventHandler( (ControlRef)control , GetwxMacWindowEventHandlerUPP(),
941 GetEventTypeCount(eventList), eventList, this,
942 (EventHandlerRef *)&m_macControlEventHandler);
943
944 #if !TARGET_API_MAC_OSX
945 if ( (ControlRef) control == m_peer->GetControlRef() )
946 {
947 m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl, kControlUserPaneDrawProcTag, GetwxMacControlUserPaneDrawProc()) ;
948 m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl, kControlUserPaneHitTestProcTag, GetwxMacControlUserPaneHitTestProc()) ;
949 m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl, kControlUserPaneTrackingProcTag, GetwxMacControlUserPaneTrackingProc()) ;
950 m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl, kControlUserPaneIdleProcTag, GetwxMacControlUserPaneIdleProc()) ;
951 m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl, kControlUserPaneKeyDownProcTag, GetwxMacControlUserPaneKeyDownProc()) ;
952 m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl, kControlUserPaneActivateProcTag, GetwxMacControlUserPaneActivateProc()) ;
953 m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl, kControlUserPaneFocusProcTag, GetwxMacControlUserPaneFocusProc()) ;
954 m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl, kControlUserPaneBackgroundProcTag, GetwxMacControlUserPaneBackgroundProc()) ;
955 }
956 #endif
957 }
958
959 // Constructor
960 bool wxWindowMac::Create(wxWindowMac *parent,
961 wxWindowID id,
962 const wxPoint& pos,
963 const wxSize& size,
964 long style,
965 const wxString& name)
966 {
967 wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") );
968
969 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
970 return false;
971
972 m_windowVariant = parent->GetWindowVariant() ;
973
974 if ( m_macIsUserPane )
975 {
976 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
977
978 UInt32 features = 0
979 | kControlSupportsEmbedding
980 | kControlSupportsLiveFeedback
981 | kControlGetsFocusOnClick
982 // | kControlHasSpecialBackground
983 // | kControlSupportsCalcBestRect
984 | kControlHandlesTracking
985 | kControlSupportsFocus
986 | kControlWantsActivate
987 | kControlWantsIdle ;
988
989 m_peer = new wxMacControl(this) ;
990 OSStatus err =::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
991 verify_noerr( err );
992
993 MacPostControlCreate(pos, size) ;
994 }
995
996 #ifndef __WXUNIVERSAL__
997 // Don't give scrollbars to wxControls unless they ask for them
998 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar)))
999 || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL))))
1000 {
1001 MacCreateScrollBars( style ) ;
1002 }
1003 #endif
1004
1005 wxWindowCreateEvent event(this);
1006 GetEventHandler()->AddPendingEvent(event);
1007
1008 return true;
1009 }
1010
1011 void wxWindowMac::MacChildAdded()
1012 {
1013 if ( m_vScrollBar )
1014 m_vScrollBar->Raise() ;
1015 if ( m_hScrollBar )
1016 m_hScrollBar->Raise() ;
1017 }
1018
1019 void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
1020 {
1021 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
1022
1023 m_peer->SetReference( (long)this ) ;
1024 GetParent()->AddChild( this );
1025
1026 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() );
1027
1028 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
1029 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
1030 ::EmbedControl( m_peer->GetControlRef() , container ) ;
1031 GetParent()->MacChildAdded() ;
1032
1033 // adjust font, controlsize etc
1034 DoSetWindowVariant( m_windowVariant ) ;
1035
1036 m_peer->SetLabel( wxStripMenuCodes(m_label) ) ;
1037
1038 if (!m_macIsUserPane)
1039 SetInitialBestSize(size);
1040
1041 SetCursor( *wxSTANDARD_CURSOR ) ;
1042 }
1043
1044 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
1045 {
1046 // Don't assert, in case we set the window variant before
1047 // the window is created
1048 // wxASSERT( m_peer->Ok() ) ;
1049
1050 m_windowVariant = variant ;
1051
1052 if (m_peer == NULL || !m_peer->Ok())
1053 return;
1054
1055 ControlSize size ;
1056 ThemeFontID themeFont = kThemeSystemFont ;
1057
1058 // we will get that from the settings later
1059 // and make this NORMAL later, but first
1060 // we have a few calculations that we must fix
1061
1062 switch ( variant )
1063 {
1064 case wxWINDOW_VARIANT_NORMAL :
1065 size = kControlSizeNormal;
1066 themeFont = kThemeSystemFont ;
1067 break ;
1068
1069 case wxWINDOW_VARIANT_SMALL :
1070 size = kControlSizeSmall;
1071 themeFont = kThemeSmallSystemFont ;
1072 break ;
1073
1074 case wxWINDOW_VARIANT_MINI :
1075 if (UMAGetSystemVersion() >= 0x1030 )
1076 {
1077 // not always defined in the headers
1078 size = 3 ;
1079 themeFont = 109 ;
1080 }
1081 else
1082 {
1083 size = kControlSizeSmall;
1084 themeFont = kThemeSmallSystemFont ;
1085 }
1086 break ;
1087
1088 case wxWINDOW_VARIANT_LARGE :
1089 size = kControlSizeLarge;
1090 themeFont = kThemeSystemFont ;
1091 break ;
1092
1093 default:
1094 wxFAIL_MSG(_T("unexpected window variant"));
1095 break ;
1096 }
1097
1098 m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
1099
1100 wxFont font ;
1101 font.MacCreateThemeFont( themeFont ) ;
1102 SetFont( font ) ;
1103 }
1104
1105 void wxWindowMac::MacUpdateControlFont()
1106 {
1107 m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1108 Refresh() ;
1109 }
1110
1111 bool wxWindowMac::SetFont(const wxFont& font)
1112 {
1113 bool retval = wxWindowBase::SetFont( font );
1114
1115 MacUpdateControlFont() ;
1116
1117 return retval;
1118 }
1119
1120 bool wxWindowMac::SetForegroundColour(const wxColour& col )
1121 {
1122 bool retval = wxWindowBase::SetForegroundColour( col );
1123
1124 if (retval)
1125 MacUpdateControlFont();
1126
1127 return retval;
1128 }
1129
1130 bool wxWindowMac::SetBackgroundColour(const wxColour& col )
1131 {
1132 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
1133 return false ;
1134
1135 wxBrush brush ;
1136 wxColour newCol(GetBackgroundColour());
1137
1138 if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE ) )
1139 brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
1140 else if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) )
1141 brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
1142 else
1143 brush.SetColour( newCol ) ;
1144
1145 MacSetBackgroundBrush( brush ) ;
1146 MacUpdateControlFont() ;
1147
1148 return true ;
1149 }
1150
1151 void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
1152 {
1153 m_macBackgroundBrush = brush ;
1154 m_peer->SetBackground( brush ) ;
1155 }
1156
1157 bool wxWindowMac::MacCanFocus() const
1158 {
1159 // there is currently no way to determine whether the window is running in full keyboard
1160 // access mode, therefore we cannot rely on these features, yet the only other way would be
1161 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1162 // in event handlers...
1163 UInt32 features = 0 ;
1164 m_peer->GetFeatures( &features ) ;
1165
1166 return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
1167 }
1168
1169 void wxWindowMac::SetFocus()
1170 {
1171 if ( !AcceptsFocus() )
1172 return ;
1173
1174 wxWindow* former = FindFocus() ;
1175 if ( former == this )
1176 return ;
1177
1178 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1179 // we can only leave in case of an error
1180 OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
1181 if ( err == errCouldntSetFocus )
1182 return ;
1183
1184 SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() );
1185
1186 #if !TARGET_API_MAC_OSX
1187 // emulate carbon events when running under CarbonLib where they are not natively available
1188 if ( former )
1189 {
1190 EventRef evRef = NULL ;
1191
1192 err = MacCreateEvent(
1193 NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) ,
1194 kEventAttributeUserEvent , &evRef );
1195 verify_noerr( err );
1196
1197 wxMacCarbonEvent cEvent( evRef ) ;
1198 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
1199 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
1200
1201 wxMacWindowEventHandler( NULL , evRef , former ) ;
1202 ReleaseEvent( evRef ) ;
1203 }
1204
1205 // send new focus event
1206 {
1207 EventRef evRef = NULL ;
1208
1209 err = MacCreateEvent(
1210 NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) ,
1211 kEventAttributeUserEvent , &evRef );
1212 verify_noerr( err );
1213
1214 wxMacCarbonEvent cEvent( evRef ) ;
1215 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
1216 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
1217
1218 wxMacWindowEventHandler( NULL , evRef , this ) ;
1219 ReleaseEvent( evRef ) ;
1220 }
1221 #endif
1222 }
1223
1224 void wxWindowMac::DoCaptureMouse()
1225 {
1226 wxApp::s_captureWindow = this ;
1227 }
1228
1229 wxWindow* wxWindowBase::GetCapture()
1230 {
1231 return wxApp::s_captureWindow ;
1232 }
1233
1234 void wxWindowMac::DoReleaseMouse()
1235 {
1236 wxApp::s_captureWindow = NULL ;
1237 }
1238
1239 #if wxUSE_DRAG_AND_DROP
1240
1241 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
1242 {
1243 if ( m_dropTarget != NULL )
1244 delete m_dropTarget;
1245
1246 m_dropTarget = pDropTarget;
1247 if ( m_dropTarget != NULL )
1248 {
1249 // TODO:
1250 }
1251 }
1252
1253 #endif
1254
1255 // Old style file-manager drag&drop
1256 void wxWindowMac::DragAcceptFiles(bool accept)
1257 {
1258 // TODO:
1259 }
1260
1261 // Returns the size of the native control. In the case of the toplevel window
1262 // this is the content area root control
1263
1264 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
1265 int& w, int& h) const
1266 {
1267 wxFAIL_MSG( wxT("Not currently supported") ) ;
1268 }
1269
1270 // From a wx position / size calculate the appropriate size of the native control
1271
1272 bool wxWindowMac::MacGetBoundsForControl(
1273 const wxPoint& pos,
1274 const wxSize& size,
1275 int& x, int& y,
1276 int& w, int& h , bool adjustOrigin ) const
1277 {
1278 bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ;
1279
1280 // the desired size, minus the border pixels gives the correct size of the control
1281
1282 x = (int)pos.x;
1283 y = (int)pos.y;
1284
1285 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1286 w = wxMax(size.x, 0) ; // WidthDefault( size.x );
1287 h = wxMax(size.y, 0) ; // HeightDefault( size.y ) ;
1288
1289 if ( !isCompositing )
1290 GetParent()->MacWindowToRootWindow( &x , &y ) ;
1291
1292 x += MacGetLeftBorderSize() ;
1293 y += MacGetTopBorderSize() ;
1294 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1295 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1296
1297 if ( adjustOrigin )
1298 AdjustForParentClientOrigin( x , y ) ;
1299
1300 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1301 if ( !GetParent()->IsTopLevel() )
1302 {
1303 x -= GetParent()->MacGetLeftBorderSize() ;
1304 y -= GetParent()->MacGetTopBorderSize() ;
1305 }
1306
1307 return true ;
1308 }
1309
1310 // Get window size (not client size)
1311 void wxWindowMac::DoGetSize(int *x, int *y) const
1312 {
1313 Rect bounds ;
1314 m_peer->GetRect( &bounds ) ;
1315
1316 if (x)
1317 *x = bounds.right - bounds.left + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1318 if (y)
1319 *y = bounds.bottom - bounds.top + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1320 }
1321
1322 // get the position of the bounds of this window in client coordinates of its parent
1323 void wxWindowMac::DoGetPosition(int *x, int *y) const
1324 {
1325 Rect bounds ;
1326 m_peer->GetRect( &bounds ) ;
1327
1328 int x1 = bounds.left ;
1329 int y1 = bounds.top ;
1330
1331 // get the wx window position from the native one
1332 x1 -= MacGetLeftBorderSize() ;
1333 y1 -= MacGetTopBorderSize() ;
1334
1335 if ( !IsTopLevel() )
1336 {
1337 wxWindow *parent = GetParent();
1338 if ( parent )
1339 {
1340 // we must first adjust it to be in window coordinates of the parent,
1341 // as otherwise it gets lost by the ClientAreaOrigin fix
1342 x1 += parent->MacGetLeftBorderSize() ;
1343 y1 += parent->MacGetTopBorderSize() ;
1344
1345 // and now to client coordinates
1346 wxPoint pt(parent->GetClientAreaOrigin());
1347 x1 -= pt.x ;
1348 y1 -= pt.y ;
1349 }
1350 }
1351
1352 if (x)
1353 *x = x1 ;
1354 if (y)
1355 *y = y1 ;
1356 }
1357
1358 void wxWindowMac::DoScreenToClient(int *x, int *y) const
1359 {
1360 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1361 wxCHECK_RET( window , wxT("TopLevel Window missing") ) ;
1362
1363 Point localwhere = { 0, 0 } ;
1364
1365 if (x)
1366 localwhere.h = *x ;
1367 if (y)
1368 localwhere.v = *y ;
1369
1370 QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ;
1371
1372 if (x)
1373 *x = localwhere.h ;
1374 if (y)
1375 *y = localwhere.v ;
1376
1377 MacRootWindowToWindow( x , y ) ;
1378
1379 wxPoint origin = GetClientAreaOrigin() ;
1380 if (x)
1381 *x -= origin.x ;
1382 if (y)
1383 *y -= origin.y ;
1384 }
1385
1386 void wxWindowMac::DoClientToScreen(int *x, int *y) const
1387 {
1388 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1389 wxCHECK_RET( window , wxT("TopLevel window missing") ) ;
1390
1391 wxPoint origin = GetClientAreaOrigin() ;
1392 if (x)
1393 *x += origin.x ;
1394 if (y)
1395 *y += origin.y ;
1396
1397 MacWindowToRootWindow( x , y ) ;
1398
1399 Point localwhere = { 0, 0 };
1400 if (x)
1401 localwhere.h = *x ;
1402 if (y)
1403 localwhere.v = *y ;
1404
1405 QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ;
1406
1407 if (x)
1408 *x = localwhere.h ;
1409 if (y)
1410 *y = localwhere.v ;
1411 }
1412
1413 void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
1414 {
1415 wxPoint origin = GetClientAreaOrigin() ;
1416 if (x)
1417 *x += origin.x ;
1418 if (y)
1419 *y += origin.y ;
1420
1421 MacWindowToRootWindow( x , y ) ;
1422 }
1423
1424 void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1425 {
1426 MacRootWindowToWindow( x , y ) ;
1427
1428 wxPoint origin = GetClientAreaOrigin() ;
1429 if (x)
1430 *x -= origin.x ;
1431 if (y)
1432 *y -= origin.y ;
1433 }
1434
1435 void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1436 {
1437 wxPoint pt ;
1438
1439 if (x)
1440 pt.x = *x ;
1441 if (y)
1442 pt.y = *y ;
1443
1444 if ( !IsTopLevel() )
1445 {
1446 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1447 if (top)
1448 {
1449 pt.x -= MacGetLeftBorderSize() ;
1450 pt.y -= MacGetTopBorderSize() ;
1451 wxMacControl::Convert( &pt , m_peer , top->m_peer ) ;
1452 }
1453 }
1454
1455 if (x)
1456 *x = (int) pt.x ;
1457 if (y)
1458 *y = (int) pt.y ;
1459 }
1460
1461 void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1462 {
1463 int x1 , y1 ;
1464
1465 if (x)
1466 x1 = *x ;
1467 if (y)
1468 y1 = *y ;
1469
1470 MacWindowToRootWindow( &x1 , &y1 ) ;
1471
1472 if (x)
1473 *x = x1 ;
1474 if (y)
1475 *y = y1 ;
1476 }
1477
1478 void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
1479 {
1480 wxPoint pt ;
1481
1482 if (x)
1483 pt.x = *x ;
1484 if (y)
1485 pt.y = *y ;
1486
1487 if ( !IsTopLevel() )
1488 {
1489 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1490 if (top)
1491 {
1492 wxMacControl::Convert( &pt , top->m_peer , m_peer ) ;
1493 pt.x += MacGetLeftBorderSize() ;
1494 pt.y += MacGetTopBorderSize() ;
1495 }
1496 }
1497
1498 if (x)
1499 *x = (int) pt.x ;
1500 if (y)
1501 *y = (int) pt.y ;
1502 }
1503
1504 void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
1505 {
1506 int x1 , y1 ;
1507
1508 if (x)
1509 x1 = *x ;
1510 if (y)
1511 y1 = *y ;
1512
1513 MacRootWindowToWindow( &x1 , &y1 ) ;
1514
1515 if (x)
1516 *x = x1 ;
1517 if (y)
1518 *y = y1 ;
1519 }
1520
1521 void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1522 {
1523 RgnHandle rgn = NewRgn() ;
1524
1525 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1526 {
1527 Rect structure, content ;
1528
1529 GetRegionBounds( rgn , &content ) ;
1530 m_peer->GetRect( &structure ) ;
1531 OffsetRect( &structure, -structure.left , -structure.top ) ;
1532
1533 left = content.left - structure.left ;
1534 top = content.top - structure.top ;
1535 right = structure.right - content.right ;
1536 bottom = structure.bottom - content.bottom ;
1537 }
1538 else
1539 {
1540 left = top = right = bottom = 0 ;
1541 }
1542
1543 DisposeRgn( rgn ) ;
1544 }
1545
1546 wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1547 {
1548 wxSize sizeTotal = size;
1549
1550 RgnHandle rgn = NewRgn() ;
1551 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1552 {
1553 Rect content, structure ;
1554 GetRegionBounds( rgn , &content ) ;
1555 m_peer->GetRect( &structure ) ;
1556
1557 // structure is in parent coordinates, but we only need width and height, so it's ok
1558
1559 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1560 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top) ;
1561 }
1562
1563 DisposeRgn( rgn ) ;
1564
1565 sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1566 sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1567
1568 return sizeTotal;
1569 }
1570
1571 // Get size *available for subwindows* i.e. excluding menu bar etc.
1572 void wxWindowMac::DoGetClientSize( int *x, int *y ) const
1573 {
1574 int ww, hh;
1575
1576 RgnHandle rgn = NewRgn() ;
1577 Rect content ;
1578 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1579 GetRegionBounds( rgn , &content ) ;
1580 else
1581 m_peer->GetRect( &content ) ;
1582 DisposeRgn( rgn ) ;
1583
1584 ww = content.right - content.left ;
1585 hh = content.bottom - content.top ;
1586
1587 if (m_hScrollBar && m_hScrollBar->IsShown() )
1588 hh -= m_hScrollBar->GetSize().y ;
1589
1590 if (m_vScrollBar && m_vScrollBar->IsShown() )
1591 ww -= m_vScrollBar->GetSize().x ;
1592
1593 if (x)
1594 *x = ww;
1595 if (y)
1596 *y = hh;
1597 }
1598
1599 bool wxWindowMac::SetCursor(const wxCursor& cursor)
1600 {
1601 if (m_cursor == cursor)
1602 return false;
1603
1604 if (wxNullCursor == cursor)
1605 {
1606 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1607 return false ;
1608 }
1609 else
1610 {
1611 if ( ! wxWindowBase::SetCursor( cursor ) )
1612 return false ;
1613 }
1614
1615 wxASSERT_MSG( m_cursor.Ok(),
1616 wxT("cursor must be valid after call to the base version"));
1617
1618 wxWindowMac *mouseWin = 0 ;
1619 {
1620 wxTopLevelWindowMac *tlw = MacGetTopLevelWindow() ;
1621 WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ;
1622 CGrafPtr savePort ;
1623 Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
1624
1625 // TODO: If we ever get a GetCurrentEvent... replacement
1626 // for the mouse position, use it...
1627
1628 Point pt ;
1629 ControlPartCode part ;
1630 ControlRef control ;
1631
1632 GetMouse( &pt ) ;
1633 control = wxMacFindControlUnderMouse( tlw , pt , window , &part ) ;
1634 if ( control )
1635 mouseWin = wxFindControlFromMacControl( control ) ;
1636
1637 if ( swapped )
1638 QDSwapPort( savePort , NULL ) ;
1639 }
1640
1641 if ( mouseWin == this && !wxIsBusy() )
1642 m_cursor.MacInstall() ;
1643
1644 return true ;
1645 }
1646
1647 #if wxUSE_MENUS
1648 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1649 {
1650 menu->SetInvokingWindow(this);
1651 menu->UpdateUI();
1652
1653 if ( x == -1 && y == -1 )
1654 {
1655 wxPoint mouse = wxGetMousePosition();
1656 x = mouse.x;
1657 y = mouse.y;
1658 }
1659 else
1660 {
1661 ClientToScreen( &x , &y ) ;
1662 }
1663
1664 menu->MacBeforeDisplay( true ) ;
1665 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ;
1666 if ( HiWord(menuResult) != 0 )
1667 {
1668 MenuCommand id ;
1669 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1670 wxMenuItem* item = NULL ;
1671 wxMenu* realmenu ;
1672 item = menu->FindItem( id, &realmenu ) ;
1673 if (item->IsCheckable())
1674 item->Check( !item->IsChecked() ) ;
1675
1676 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1677 }
1678
1679 menu->MacAfterDisplay( true ) ;
1680 menu->SetInvokingWindow( NULL );
1681
1682 return true;
1683 }
1684 #endif
1685
1686 // ----------------------------------------------------------------------------
1687 // tooltips
1688 // ----------------------------------------------------------------------------
1689
1690 #if wxUSE_TOOLTIPS
1691
1692 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
1693 {
1694 wxWindowBase::DoSetToolTip(tooltip);
1695
1696 if ( m_tooltip )
1697 m_tooltip->SetWindow(this);
1698 }
1699
1700 #endif
1701
1702 void wxWindowMac::MacInvalidateBorders()
1703 {
1704 if ( m_peer == NULL )
1705 return ;
1706
1707 bool vis = MacIsReallyShown() ;
1708 if ( !vis )
1709 return ;
1710
1711 int outerBorder = MacGetLeftBorderSize() ;
1712 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
1713 outerBorder += 4 ;
1714
1715 if ( outerBorder == 0 )
1716 return ;
1717
1718 // now we know that we have something to do at all
1719
1720 // as the borders are drawn on the parent we have to properly invalidate all these areas
1721 RgnHandle updateInner , updateOuter;
1722 Rect rect ;
1723
1724 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1725 updateInner = NewRgn() ;
1726 updateOuter = NewRgn() ;
1727
1728 m_peer->GetRect( &rect ) ;
1729 RectRgn( updateInner, &rect ) ;
1730 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1731 RectRgn( updateOuter, &rect ) ;
1732 DiffRgn( updateOuter, updateInner , updateOuter ) ;
1733
1734 #ifdef __WXMAC_OSX__
1735 GetParent()->m_peer->SetNeedsDisplay( updateOuter ) ;
1736 #else
1737 WindowRef tlw = (WindowRef) MacGetTopLevelWindowRef() ;
1738 if ( tlw )
1739 InvalWindowRgn( tlw , updateOuter ) ;
1740 #endif
1741
1742 DisposeRgn( updateOuter ) ;
1743 DisposeRgn( updateInner ) ;
1744 }
1745
1746 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
1747 {
1748 // this is never called for a toplevel window, so we know we have a parent
1749 int former_x , former_y , former_w, former_h ;
1750
1751 // Get true coordinates of former position
1752 DoGetPosition( &former_x , &former_y ) ;
1753 DoGetSize( &former_w , &former_h ) ;
1754
1755 wxWindow *parent = GetParent();
1756 if ( parent )
1757 {
1758 wxPoint pt(parent->GetClientAreaOrigin());
1759 former_x += pt.x ;
1760 former_y += pt.y ;
1761 }
1762
1763 int actualWidth = width ;
1764 int actualHeight = height ;
1765 int actualX = x;
1766 int actualY = y;
1767
1768 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1769 actualWidth = m_minWidth;
1770 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1771 actualHeight = m_minHeight;
1772 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1773 actualWidth = m_maxWidth;
1774 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1775 actualHeight = m_maxHeight;
1776
1777 bool doMove = false, doResize = false ;
1778
1779 if ( actualX != former_x || actualY != former_y )
1780 doMove = true ;
1781
1782 if ( actualWidth != former_w || actualHeight != former_h )
1783 doResize = true ;
1784
1785 if ( doMove || doResize )
1786 {
1787 // as the borders are drawn outside the native control, we adjust now
1788
1789 wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ),
1790 wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1791 actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1792
1793 Rect r ;
1794 wxMacRectToNative( &bounds , &r ) ;
1795
1796 if ( !GetParent()->IsTopLevel() )
1797 wxMacWindowToNative( GetParent() , &r ) ;
1798
1799 MacInvalidateBorders() ;
1800
1801 m_cachedClippedRectValid = false ;
1802 m_peer->SetRect( &r ) ;
1803
1804 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1805
1806 MacInvalidateBorders() ;
1807
1808 MacRepositionScrollBars() ;
1809 if ( doMove )
1810 {
1811 wxPoint point(actualX, actualY);
1812 wxMoveEvent event(point, m_windowId);
1813 event.SetEventObject(this);
1814 GetEventHandler()->ProcessEvent(event) ;
1815 }
1816
1817 if ( doResize )
1818 {
1819 MacRepositionScrollBars() ;
1820 wxSize size(actualWidth, actualHeight);
1821 wxSizeEvent event(size, m_windowId);
1822 event.SetEventObject(this);
1823 GetEventHandler()->ProcessEvent(event);
1824 }
1825 }
1826 }
1827
1828 wxSize wxWindowMac::DoGetBestSize() const
1829 {
1830 if ( m_macIsUserPane || IsTopLevel() )
1831 return wxWindowBase::DoGetBestSize() ;
1832
1833 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1834 int bestWidth, bestHeight ;
1835
1836 m_peer->GetBestRect( &bestsize ) ;
1837 if ( EmptyRect( &bestsize ) )
1838 {
1839 bestsize.left =
1840 bestsize.top = 0 ;
1841 bestsize.right =
1842 bestsize.bottom = 16 ;
1843
1844 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1845 {
1846 bestsize.bottom = 16 ;
1847 }
1848 #if wxUSE_SPINBTN
1849 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1850 {
1851 bestsize.bottom = 24 ;
1852 }
1853 #endif
1854 else
1855 {
1856 // return wxWindowBase::DoGetBestSize() ;
1857 }
1858 }
1859
1860 bestWidth = bestsize.right - bestsize.left ;
1861 bestHeight = bestsize.bottom - bestsize.top ;
1862 if ( bestHeight < 10 )
1863 bestHeight = 13 ;
1864
1865 return wxSize(bestWidth, bestHeight);
1866 }
1867
1868 // set the size of the window: if the dimensions are positive, just use them,
1869 // but if any of them is equal to -1, it means that we must find the value for
1870 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1871 // which case -1 is a valid value for x and y)
1872 //
1873 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1874 // the width/height to best suit our contents, otherwise we reuse the current
1875 // width/height
1876 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1877 {
1878 // get the current size and position...
1879 int currentX, currentY;
1880 int currentW, currentH;
1881
1882 GetPosition(&currentX, &currentY);
1883 GetSize(&currentW, &currentH);
1884
1885 // ... and don't do anything (avoiding flicker) if it's already ok
1886 if ( x == currentX && y == currentY &&
1887 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1888 {
1889 // TODO: REMOVE
1890 MacRepositionScrollBars() ; // we might have a real position shift
1891
1892 return;
1893 }
1894
1895 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1896 {
1897 if ( x == wxDefaultCoord )
1898 x = currentX;
1899 if ( y == wxDefaultCoord )
1900 y = currentY;
1901 }
1902
1903 AdjustForParentClientOrigin( x, y, sizeFlags );
1904
1905 wxSize size = wxDefaultSize;
1906 if ( width == wxDefaultCoord )
1907 {
1908 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1909 {
1910 size = DoGetBestSize();
1911 width = size.x;
1912 }
1913 else
1914 {
1915 // just take the current one
1916 width = currentW;
1917 }
1918 }
1919
1920 if ( height == wxDefaultCoord )
1921 {
1922 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1923 {
1924 if ( size.x == wxDefaultCoord )
1925 size = DoGetBestSize();
1926 // else: already called DoGetBestSize() above
1927
1928 height = size.y;
1929 }
1930 else
1931 {
1932 // just take the current one
1933 height = currentH;
1934 }
1935 }
1936
1937 DoMoveWindow( x, y, width, height );
1938 }
1939
1940 wxPoint wxWindowMac::GetClientAreaOrigin() const
1941 {
1942 RgnHandle rgn = NewRgn() ;
1943 Rect content ;
1944 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1945 {
1946 GetRegionBounds( rgn , &content ) ;
1947 }
1948 else
1949 {
1950 content.left =
1951 content.top = 0 ;
1952 }
1953
1954 DisposeRgn( rgn ) ;
1955
1956 return wxPoint( content.left + MacGetLeftBorderSize() , content.top + MacGetTopBorderSize() );
1957 }
1958
1959 void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1960 {
1961 if ( clientheight != wxDefaultCoord || clientheight != wxDefaultCoord )
1962 {
1963 int currentclientwidth , currentclientheight ;
1964 int currentwidth , currentheight ;
1965
1966 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1967 GetSize( &currentwidth , &currentheight ) ;
1968
1969 DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
1970 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1971 }
1972 }
1973
1974 void wxWindowMac::SetLabel(const wxString& title)
1975 {
1976 m_label = wxStripMenuCodes(title) ;
1977
1978 if ( m_peer && m_peer->Ok() )
1979 m_peer->SetLabel( m_label ) ;
1980
1981 Refresh() ;
1982 }
1983
1984 wxString wxWindowMac::GetLabel() const
1985 {
1986 return m_label ;
1987 }
1988
1989 bool wxWindowMac::Show(bool show)
1990 {
1991 bool former = MacIsReallyShown() ;
1992 if ( !wxWindowBase::Show(show) )
1993 return false;
1994
1995 // TODO: use visibilityChanged Carbon Event for OSX
1996 if ( m_peer )
1997 m_peer->SetVisibility( show , true ) ;
1998
1999 if ( former != MacIsReallyShown() )
2000 MacPropagateVisibilityChanged() ;
2001
2002 return true;
2003 }
2004
2005 bool wxWindowMac::Enable(bool enable)
2006 {
2007 wxASSERT( m_peer->Ok() ) ;
2008 bool former = MacIsReallyEnabled() ;
2009 if ( !wxWindowBase::Enable(enable) )
2010 return false;
2011
2012 m_peer->Enable( enable ) ;
2013
2014 if ( former != MacIsReallyEnabled() )
2015 MacPropagateEnabledStateChanged() ;
2016
2017 return true;
2018 }
2019
2020 //
2021 // status change propagations (will be not necessary for OSX later )
2022 //
2023
2024 void wxWindowMac::MacPropagateVisibilityChanged()
2025 {
2026 #if !TARGET_API_MAC_OSX
2027 MacVisibilityChanged() ;
2028
2029 wxWindowMac *child;
2030 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2031 while ( node )
2032 {
2033 child = node->GetData();
2034 if ( child->IsShown() )
2035 child->MacPropagateVisibilityChanged() ;
2036
2037 node = node->GetNext();
2038 }
2039 #endif
2040 }
2041
2042 void wxWindowMac::MacPropagateEnabledStateChanged()
2043 {
2044 #if !TARGET_API_MAC_OSX
2045 MacEnabledStateChanged() ;
2046
2047 wxWindowMac *child;
2048 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2049 while ( node )
2050 {
2051 child = node->GetData();
2052 if ( child->IsEnabled() )
2053 child->MacPropagateEnabledStateChanged() ;
2054
2055 node = node->GetNext();
2056 }
2057 #endif
2058 }
2059
2060 void wxWindowMac::MacPropagateHiliteChanged()
2061 {
2062 #if !TARGET_API_MAC_OSX
2063 MacHiliteChanged() ;
2064
2065 wxWindowMac *child;
2066 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2067 while ( node )
2068 {
2069 child = node->GetData();
2070 if (child /* && child->IsEnabled() */)
2071 child->MacPropagateHiliteChanged() ;
2072
2073 node = node->GetNext();
2074 }
2075 #endif
2076 }
2077
2078 //
2079 // status change notifications
2080 //
2081
2082 void wxWindowMac::MacVisibilityChanged()
2083 {
2084 }
2085
2086 void wxWindowMac::MacHiliteChanged()
2087 {
2088 }
2089
2090 void wxWindowMac::MacEnabledStateChanged()
2091 {
2092 }
2093
2094 //
2095 // status queries on the inherited window's state
2096 //
2097
2098 bool wxWindowMac::MacIsReallyShown()
2099 {
2100 // only under OSX the visibility of the TLW is taken into account
2101 if ( m_isBeingDeleted )
2102 return false ;
2103
2104 #if TARGET_API_MAC_OSX
2105 if ( m_peer && m_peer->Ok() )
2106 return m_peer->IsVisible();
2107 #endif
2108
2109 wxWindow* win = this ;
2110 while ( win->IsShown() )
2111 {
2112 if ( win->IsTopLevel() )
2113 return true ;
2114
2115 win = win->GetParent() ;
2116 if ( win == NULL )
2117 return true ;
2118 }
2119
2120 return false ;
2121 }
2122
2123 bool wxWindowMac::MacIsReallyEnabled()
2124 {
2125 return m_peer->IsEnabled() ;
2126 }
2127
2128 bool wxWindowMac::MacIsReallyHilited()
2129 {
2130 return m_peer->IsActive();
2131 }
2132
2133 void wxWindowMac::MacFlashInvalidAreas()
2134 {
2135 #if TARGET_API_MAC_OSX
2136 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
2137 #endif
2138 }
2139
2140 int wxWindowMac::GetCharHeight() const
2141 {
2142 wxClientDC dc( (wxWindowMac*)this ) ;
2143
2144 return dc.GetCharHeight() ;
2145 }
2146
2147 int wxWindowMac::GetCharWidth() const
2148 {
2149 wxClientDC dc( (wxWindowMac*)this ) ;
2150
2151 return dc.GetCharWidth() ;
2152 }
2153
2154 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
2155 int *descent, int *externalLeading, const wxFont *theFont ) const
2156 {
2157 const wxFont *fontToUse = theFont;
2158 if ( !fontToUse )
2159 fontToUse = &m_font;
2160
2161 wxClientDC dc( (wxWindowMac*) this ) ;
2162 long lx,ly,ld,le ;
2163 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2164 if ( externalLeading )
2165 *externalLeading = le ;
2166 if ( descent )
2167 *descent = ld ;
2168 if ( x )
2169 *x = lx ;
2170 if ( y )
2171 *y = ly ;
2172 }
2173
2174 /*
2175 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2176 * we always intersect with the entire window, not only with the client area
2177 */
2178
2179 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
2180 {
2181 if ( m_peer == NULL )
2182 return ;
2183
2184 if ( !MacIsReallyShown() )
2185 return ;
2186
2187 if ( rect )
2188 {
2189 Rect r ;
2190
2191 wxMacRectToNative( rect , &r ) ;
2192 m_peer->SetNeedsDisplay( &r ) ;
2193 }
2194 else
2195 {
2196 m_peer->SetNeedsDisplay() ;
2197 }
2198 }
2199
2200 void wxWindowMac::Freeze()
2201 {
2202 #if TARGET_API_MAC_OSX
2203 if ( !m_frozenness++ )
2204 {
2205 if ( m_peer && m_peer->Ok() )
2206 m_peer->SetDrawingEnabled( false ) ;
2207 }
2208 #endif
2209 }
2210
2211 void wxWindowMac::Thaw()
2212 {
2213 #if TARGET_API_MAC_OSX
2214 wxASSERT_MSG( m_frozenness > 0, wxT("Thaw() without matching Freeze()") );
2215
2216 if ( !--m_frozenness )
2217 {
2218 if ( m_peer && m_peer->Ok() )
2219 {
2220 m_peer->SetDrawingEnabled( true ) ;
2221 m_peer->InvalidateWithChildren() ;
2222 }
2223 }
2224 #endif
2225 }
2226
2227 wxWindowMac *wxGetActiveWindow()
2228 {
2229 // actually this is a windows-only concept
2230 return NULL;
2231 }
2232
2233 // Coordinates relative to the window
2234 void wxWindowMac::WarpPointer(int x_pos, int y_pos)
2235 {
2236 // We really don't move the mouse programmatically under Mac.
2237 }
2238
2239 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
2240 {
2241 if ( MacGetTopLevelWindow() == NULL )
2242 return ;
2243
2244 #if TARGET_API_MAC_OSX
2245 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) )
2246 {
2247 event.Skip() ;
2248 }
2249 else
2250 #endif
2251 {
2252 event.GetDC()->Clear() ;
2253 }
2254 }
2255
2256 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2257 {
2258 event.Skip() ;
2259 }
2260
2261 int wxWindowMac::GetScrollPos(int orient) const
2262 {
2263 if ( orient == wxHORIZONTAL )
2264 {
2265 if ( m_hScrollBar )
2266 return m_hScrollBar->GetThumbPosition() ;
2267 }
2268 else
2269 {
2270 if ( m_vScrollBar )
2271 return m_vScrollBar->GetThumbPosition() ;
2272 }
2273
2274 return 0;
2275 }
2276
2277 // This now returns the whole range, not just the number
2278 // of positions that we can scroll.
2279 int wxWindowMac::GetScrollRange(int orient) const
2280 {
2281 if ( orient == wxHORIZONTAL )
2282 {
2283 if ( m_hScrollBar )
2284 return m_hScrollBar->GetRange() ;
2285 }
2286 else
2287 {
2288 if ( m_vScrollBar )
2289 return m_vScrollBar->GetRange() ;
2290 }
2291
2292 return 0;
2293 }
2294
2295 int wxWindowMac::GetScrollThumb(int orient) const
2296 {
2297 if ( orient == wxHORIZONTAL )
2298 {
2299 if ( m_hScrollBar )
2300 return m_hScrollBar->GetThumbSize() ;
2301 }
2302 else
2303 {
2304 if ( m_vScrollBar )
2305 return m_vScrollBar->GetThumbSize() ;
2306 }
2307
2308 return 0;
2309 }
2310
2311 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
2312 {
2313 if ( orient == wxHORIZONTAL )
2314 {
2315 if ( m_hScrollBar )
2316 m_hScrollBar->SetThumbPosition( pos ) ;
2317 }
2318 else
2319 {
2320 if ( m_vScrollBar )
2321 m_vScrollBar->SetThumbPosition( pos ) ;
2322 }
2323 }
2324
2325 //
2326 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2327 // our own window origin is at leftOrigin/rightOrigin
2328 //
2329
2330 void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
2331 {
2332 if ( IsTopLevel() )
2333 return ;
2334
2335 Rect rect ;
2336 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
2337 bool hasBothScrollbars = (m_hScrollBar && m_hScrollBar->IsShown()) && (m_vScrollBar && m_vScrollBar->IsShown()) ;
2338
2339 // back to the surrounding frame rectangle
2340 m_peer->GetRect( &rect ) ;
2341 InsetRect( &rect, -1 , -1 ) ;
2342
2343 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2344 if ( UMAGetSystemVersion() >= 0x1030 )
2345 {
2346 CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
2347 rect.bottom - rect.top ) ;
2348
2349 HIThemeFrameDrawInfo info ;
2350 memset( &info, 0 , sizeof(info) ) ;
2351
2352 info.version = 0 ;
2353 info.kind = 0 ;
2354 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2355 info.isFocused = hasFocus ;
2356
2357 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
2358 wxASSERT( cgContext ) ;
2359
2360 if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2361 {
2362 info.kind = kHIThemeFrameTextFieldSquare ;
2363 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2364 }
2365 else if ( HasFlag(wxSIMPLE_BORDER) )
2366 {
2367 info.kind = kHIThemeFrameListBox ;
2368 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2369 }
2370 else if ( hasFocus )
2371 {
2372 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
2373 }
2374
2375 m_peer->GetRect( &rect ) ;
2376 if ( hasBothScrollbars )
2377 {
2378 int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
2379 CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
2380 CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
2381 HIThemeGrowBoxDrawInfo info ;
2382 memset( &info, 0, sizeof(info) ) ;
2383 info.version = 0 ;
2384 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2385 info.kind = kHIThemeGrowBoxKindNone ;
2386 info.size = kHIThemeGrowBoxSizeNormal ;
2387 info.direction = kThemeGrowRight | kThemeGrowDown ;
2388 HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
2389 }
2390 }
2391 else
2392 #endif
2393 {
2394 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2395 if ( top )
2396 {
2397 wxPoint pt(0, 0) ;
2398 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
2399 OffsetRect( &rect , pt.x , pt.y ) ;
2400 }
2401
2402 if ( HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2403 DrawThemeEditTextFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
2404 else if ( HasFlag(wxSIMPLE_BORDER) )
2405 DrawThemeListBoxFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
2406
2407 if ( hasFocus )
2408 DrawThemeFocusRect( &rect , true ) ;
2409
2410 if ( hasBothScrollbars )
2411 {
2412 // GetThemeStandaloneGrowBoxBounds
2413 // DrawThemeStandaloneNoGrowBox
2414 }
2415 }
2416 }
2417
2418 void wxWindowMac::RemoveChild( wxWindowBase *child )
2419 {
2420 if ( child == m_hScrollBar )
2421 m_hScrollBar = NULL ;
2422 if ( child == m_vScrollBar )
2423 m_vScrollBar = NULL ;
2424
2425 wxWindowBase::RemoveChild( child ) ;
2426 }
2427
2428 // New function that will replace some of the above.
2429 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2430 int range, bool refresh)
2431 {
2432 bool showScroller;
2433
2434 if ( orient == wxHORIZONTAL )
2435 {
2436 if ( m_hScrollBar )
2437 {
2438 showScroller = ((range != 0) && (range > thumbVisible));
2439 if ( m_hScrollBar->IsShown() != showScroller )
2440 m_hScrollBar->Show( showScroller ) ;
2441
2442 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2443 }
2444 }
2445 else
2446 {
2447 if ( m_vScrollBar )
2448 {
2449 showScroller = ((range != 0) && (range > thumbVisible));
2450 if ( m_vScrollBar->IsShown() != showScroller )
2451 m_vScrollBar->Show( showScroller ) ;
2452
2453 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2454 }
2455 }
2456
2457 MacRepositionScrollBars() ;
2458 }
2459
2460 // Does a physical scroll
2461 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2462 {
2463 if ( dx == 0 && dy == 0 )
2464 return ;
2465
2466 int width , height ;
2467 GetClientSize( &width , &height ) ;
2468
2469 #if TARGET_API_MAC_OSX
2470 if ( true /* m_peer->IsCompositing() */ )
2471 {
2472 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2473 // area is scrolled, this does not occur if width and height are 2 pixels less,
2474 // TODO: write optimal workaround
2475 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
2476 if ( rect )
2477 scrollrect.Intersect( *rect ) ;
2478
2479 if ( m_peer->GetNeedsDisplay() )
2480 {
2481 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2482 // either immediate redraw or full invalidate
2483 #if 1
2484 // is the better overall solution, as it does not slow down scrolling
2485 m_peer->SetNeedsDisplay() ;
2486 #else
2487 // this would be the preferred version for fast drawing controls
2488
2489 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2490 if ( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() )
2491 HIViewRender(m_peer->GetControlRef()) ;
2492 else
2493 #endif
2494 Update() ;
2495 #endif
2496 }
2497
2498 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2499 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2500 m_peer->ScrollRect( &scrollrect , dx , dy ) ;
2501
2502 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2503 // either immediate redraw or full invalidate
2504 #if 0
2505 // is the better overall solution, as it does not slow down scrolling
2506 m_peer->SetNeedsDisplay() ;
2507 #else
2508 // this would be the preferred version for fast drawing controls
2509
2510 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2511 if ( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() )
2512 HIViewRender(m_peer->GetControlRef()) ;
2513 else
2514 #endif
2515 Update() ;
2516 #endif
2517 }
2518 else
2519 #endif
2520 {
2521 wxPoint pos;
2522 pos.x =
2523 pos.y = 0;
2524
2525 Rect scrollrect;
2526 RgnHandle updateRgn = NewRgn() ;
2527
2528 {
2529 wxClientDC dc(this) ;
2530 wxMacPortSetter helper(&dc) ;
2531
2532 m_peer->GetRectInWindowCoords( &scrollrect ) ;
2533 //scrollrect.top += MacGetTopBorderSize() ;
2534 //scrollrect.left += MacGetLeftBorderSize() ;
2535 scrollrect.bottom = scrollrect.top + height ;
2536 scrollrect.right = scrollrect.left + width ;
2537
2538 if ( rect )
2539 {
2540 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2541 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2542 SectRect( &scrollrect , &r , &scrollrect ) ;
2543 }
2544
2545 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2546
2547 // now scroll the former update region as well and add the new update region
2548 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2549 RgnHandle formerUpdateRgn = NewRgn() ;
2550 RgnHandle scrollRgn = NewRgn() ;
2551 RectRgn( scrollRgn , &scrollrect ) ;
2552 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2553 Point pt = {0, 0} ;
2554 LocalToGlobal( &pt ) ;
2555 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2556 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2557
2558 if ( !EmptyRgn( formerUpdateRgn ) )
2559 {
2560 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2561 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2562 InvalWindowRgn( rootWindow, formerUpdateRgn ) ;
2563 }
2564
2565 InvalWindowRgn(rootWindow, updateRgn ) ;
2566 DisposeRgn( updateRgn ) ;
2567 DisposeRgn( formerUpdateRgn ) ;
2568 DisposeRgn( scrollRgn ) ;
2569 }
2570
2571 Update() ;
2572 }
2573
2574 wxWindowMac *child;
2575 int x, y, w, h;
2576 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2577 {
2578 child = node->GetData();
2579 if (child == NULL)
2580 continue;
2581 if (child == m_vScrollBar)
2582 continue;
2583 if (child == m_hScrollBar)
2584 continue;
2585 if (child->IsTopLevel())
2586 continue;
2587
2588 child->GetPosition( &x, &y );
2589 child->GetSize( &w, &h );
2590 if (rect)
2591 {
2592 wxRect rc( x, y, w, h );
2593 if (rect->Intersects( rc ))
2594 child->SetSize( x + dx, y + dy, w, h );
2595 }
2596 else
2597 {
2598 child->SetSize( x + dx, y + dy, w, h );
2599 }
2600 }
2601 }
2602
2603 void wxWindowMac::MacOnScroll( wxScrollEvent &event )
2604 {
2605 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
2606 {
2607 wxScrollWinEvent wevent;
2608 wevent.SetPosition(event.GetPosition());
2609 wevent.SetOrientation(event.GetOrientation());
2610 wevent.SetEventObject(this);
2611
2612 if (event.GetEventType() == wxEVT_SCROLL_TOP)
2613 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
2614 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
2615 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
2616 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
2617 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
2618 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
2619 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
2620 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
2621 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
2622 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
2623 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
2624 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
2625 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
2626 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
2627 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
2628
2629 GetEventHandler()->ProcessEvent(wevent);
2630 }
2631 }
2632
2633 // Get the window with the focus
2634 wxWindowMac *wxWindowBase::DoFindFocus()
2635 {
2636 ControlRef control ;
2637 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2638 return wxFindControlFromMacControl( control ) ;
2639 }
2640
2641 void wxWindowMac::OnSetFocus( wxFocusEvent& event )
2642 {
2643 // panel wants to track the window which was the last to have focus in it,
2644 // so we want to set ourselves as the window which last had focus
2645 //
2646 // notice that it's also important to do it upwards the tree because
2647 // otherwise when the top level panel gets focus, it won't set it back to
2648 // us, but to some other sibling
2649
2650 // CS: don't know if this is still needed:
2651 //wxChildFocusEvent eventFocus(this);
2652 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2653
2654 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2655 {
2656 #if wxMAC_USE_CORE_GRAPHICS
2657 GetParent()->Refresh() ;
2658 #else
2659 wxMacWindowStateSaver sv( this ) ;
2660 Rect rect ;
2661
2662 m_peer->GetRect( &rect ) ;
2663 // auf den umgebenden Rahmen zur\9fck
2664 InsetRect( &rect, -1 , -1 ) ;
2665
2666 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2667 if ( top )
2668 {
2669 wxPoint pt(0, 0) ;
2670 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
2671 rect.left += pt.x ;
2672 rect.right += pt.x ;
2673 rect.top += pt.y ;
2674 rect.bottom += pt.y ;
2675 }
2676
2677 bool bIsFocusEvent = (event.GetEventType() == wxEVT_SET_FOCUS);
2678 DrawThemeFocusRect( &rect , bIsFocusEvent ) ;
2679 if ( !bIsFocusEvent )
2680 {
2681 // as this erases part of the frame we have to redraw borders
2682 // and because our z-ordering is not always correct (staticboxes)
2683 // we have to invalidate things, we cannot simple redraw
2684 MacInvalidateBorders() ;
2685 }
2686 #endif
2687 }
2688
2689 event.Skip();
2690 }
2691
2692 void wxWindowMac::OnInternalIdle()
2693 {
2694 // This calls the UI-update mechanism (querying windows for
2695 // menu/toolbar/control state information)
2696 if (wxUpdateUIEvent::CanUpdate(this))
2697 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2698 }
2699
2700 // Raise the window to the top of the Z order
2701 void wxWindowMac::Raise()
2702 {
2703 m_peer->SetZOrder( true , NULL ) ;
2704 }
2705
2706 // Lower the window to the bottom of the Z order
2707 void wxWindowMac::Lower()
2708 {
2709 m_peer->SetZOrder( false , NULL ) ;
2710 }
2711
2712 // static wxWindow *gs_lastWhich = NULL;
2713
2714 bool wxWindowMac::MacSetupCursor( const wxPoint& pt )
2715 {
2716 // first trigger a set cursor event
2717
2718 wxPoint clientorigin = GetClientAreaOrigin() ;
2719 wxSize clientsize = GetClientSize() ;
2720 wxCursor cursor ;
2721 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2722 {
2723 wxSetCursorEvent event( pt.x , pt.y );
2724
2725 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2726 if ( processedEvtSetCursor && event.HasCursor() )
2727 {
2728 cursor = event.GetCursor() ;
2729 }
2730 else
2731 {
2732 // the test for processedEvtSetCursor is here to prevent using m_cursor
2733 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2734 // it - this is a way to say that our cursor shouldn't be used for this
2735 // point
2736 if ( !processedEvtSetCursor && m_cursor.Ok() )
2737 cursor = m_cursor ;
2738
2739 if ( !wxIsBusy() && !GetParent() )
2740 cursor = *wxSTANDARD_CURSOR ;
2741 }
2742
2743 if ( cursor.Ok() )
2744 cursor.MacInstall() ;
2745 }
2746
2747 return cursor.Ok() ;
2748 }
2749
2750 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2751 {
2752 #if wxUSE_TOOLTIPS
2753 if ( m_tooltip )
2754 return m_tooltip->GetTip() ;
2755 #endif
2756
2757 return wxEmptyString ;
2758 }
2759
2760 void wxWindowMac::ClearBackground()
2761 {
2762 Refresh() ;
2763 Update() ;
2764 }
2765
2766 void wxWindowMac::Update()
2767 {
2768 #if TARGET_API_MAC_OSX
2769 MacGetTopLevelWindow()->MacPerformUpdates() ;
2770 #else
2771 ::Draw1Control( m_peer->GetControlRef() ) ;
2772 #endif
2773 }
2774
2775 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2776 {
2777 wxTopLevelWindowMac* win = NULL ;
2778 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2779 if ( window )
2780 win = wxFindWinFromMacWindow( window ) ;
2781
2782 return win ;
2783 }
2784
2785 const wxRect& wxWindowMac::MacGetClippedClientRect() const
2786 {
2787 MacUpdateClippedRects() ;
2788
2789 return m_cachedClippedClientRect ;
2790 }
2791
2792 const wxRect& wxWindowMac::MacGetClippedRect() const
2793 {
2794 MacUpdateClippedRects() ;
2795
2796 return m_cachedClippedRect ;
2797 }
2798
2799 const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2800 {
2801 MacUpdateClippedRects() ;
2802
2803 return m_cachedClippedRectWithOuterStructure ;
2804 }
2805
2806 const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2807 {
2808 static wxRegion emptyrgn ;
2809
2810 if ( !m_isBeingDeleted && MacIsReallyShown() /*m_peer->IsVisible() */ )
2811 {
2812 MacUpdateClippedRects() ;
2813 if ( includeOuterStructures )
2814 return m_cachedClippedRegionWithOuterStructure ;
2815 else
2816 return m_cachedClippedRegion ;
2817 }
2818 else
2819 {
2820 return emptyrgn ;
2821 }
2822 }
2823
2824 void wxWindowMac::MacUpdateClippedRects() const
2825 {
2826 if ( m_cachedClippedRectValid )
2827 return ;
2828
2829 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2830 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2831 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2832 // to add focus borders everywhere
2833
2834 Rect r, rIncludingOuterStructures ;
2835
2836 m_peer->GetRect( &r ) ;
2837 r.left -= MacGetLeftBorderSize() ;
2838 r.top -= MacGetTopBorderSize() ;
2839 r.bottom += MacGetBottomBorderSize() ;
2840 r.right += MacGetRightBorderSize() ;
2841
2842 r.right -= r.left ;
2843 r.bottom -= r.top ;
2844 r.left = 0 ;
2845 r.top = 0 ;
2846
2847 rIncludingOuterStructures = r ;
2848 InsetRect( &rIncludingOuterStructures , -4 , -4 ) ;
2849
2850 wxRect cl = GetClientRect() ;
2851 Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ;
2852
2853 int x , y ;
2854 wxSize size ;
2855 const wxWindow* child = this ;
2856 const wxWindow* parent = NULL ;
2857
2858 while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL )
2859 {
2860 if ( parent->MacIsChildOfClientArea(child) )
2861 {
2862 size = parent->GetClientSize() ;
2863 wxPoint origin = parent->GetClientAreaOrigin() ;
2864 x = origin.x ;
2865 y = origin.y ;
2866 }
2867 else
2868 {
2869 // this will be true for scrollbars, toolbars etc.
2870 size = parent->GetSize() ;
2871 y = parent->MacGetTopBorderSize() ;
2872 x = parent->MacGetLeftBorderSize() ;
2873 size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ;
2874 size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ;
2875 }
2876
2877 parent->MacWindowToRootWindow( &x, &y ) ;
2878 MacRootWindowToWindow( &x , &y ) ;
2879
2880 Rect rparent = { y , x , y + size.y , x + size.x } ;
2881
2882 // the wxwindow and client rects will always be clipped
2883 SectRect( &r , &rparent , &r ) ;
2884 SectRect( &rClient , &rparent , &rClient ) ;
2885
2886 // the structure only at 'hard' borders
2887 if ( parent->MacClipChildren() ||
2888 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) )
2889 {
2890 SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ;
2891 }
2892
2893 child = parent ;
2894 }
2895
2896 m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ;
2897 m_cachedClippedClientRect = wxRect( rClient.left , rClient.top ,
2898 rClient.right - rClient.left , rClient.bottom - rClient.top ) ;
2899 m_cachedClippedRectWithOuterStructure = wxRect(
2900 rIncludingOuterStructures.left , rIncludingOuterStructures.top ,
2901 rIncludingOuterStructures.right - rIncludingOuterStructures.left ,
2902 rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ;
2903
2904 m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ;
2905 m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ;
2906 m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ;
2907
2908 m_cachedClippedRectValid = true ;
2909 }
2910
2911 /*
2912 This function must not change the updatergn !
2913 */
2914 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2915 {
2916 bool handled = false ;
2917 Rect updatebounds ;
2918 RgnHandle updatergn = (RgnHandle) updatergnr ;
2919 GetRegionBounds( updatergn , &updatebounds ) ;
2920
2921 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2922
2923 if ( !EmptyRgn(updatergn) )
2924 {
2925 RgnHandle newupdate = NewRgn() ;
2926 wxSize point = GetClientSize() ;
2927 wxPoint origin = GetClientAreaOrigin() ;
2928 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y + point.y ) ;
2929 SectRgn( newupdate , updatergn , newupdate ) ;
2930
2931 // first send an erase event to the entire update area
2932 {
2933 // for the toplevel window this really is the entire area
2934 // for all the others only their client area, otherwise they
2935 // might be drawing with full alpha and eg put blue into
2936 // the grow-box area of a scrolled window (scroll sample)
2937 wxDC* dc = new wxWindowDC(this);
2938 if ( IsTopLevel() )
2939 dc->SetClippingRegion(wxRegion(updatergn));
2940 else
2941 dc->SetClippingRegion(wxRegion(newupdate));
2942
2943 wxEraseEvent eevent( GetId(), dc );
2944 eevent.SetEventObject( this );
2945 GetEventHandler()->ProcessEvent( eevent );
2946 delete dc ;
2947 }
2948
2949 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2950 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2951 m_updateRegion = newupdate ;
2952 DisposeRgn( newupdate ) ;
2953
2954 if ( !m_updateRegion.Empty() )
2955 {
2956 // paint the window itself
2957
2958 wxPaintEvent event;
2959 event.SetTimestamp(time);
2960 event.SetEventObject(this);
2961 GetEventHandler()->ProcessEvent(event);
2962 handled = true ;
2963 }
2964
2965 // now we cannot rely on having its borders drawn by a window itself, as it does not
2966 // get the updateRgn wide enough to always do so, so we do it from the parent
2967 // this would also be the place to draw any custom backgrounds for native controls
2968 // in Composited windowing
2969 wxPoint clientOrigin = GetClientAreaOrigin() ;
2970
2971 wxWindowMac *child;
2972 int x, y, w, h;
2973 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2974 {
2975 child = node->GetData();
2976 if (child == NULL)
2977 continue;
2978 if (child == m_vScrollBar)
2979 continue;
2980 if (child == m_hScrollBar)
2981 continue;
2982 if (child->IsTopLevel())
2983 continue;
2984 if (!child->IsShown())
2985 continue;
2986
2987 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2988
2989 child->GetPosition( &x, &y );
2990 child->GetSize( &w, &h );
2991 Rect childRect = { y , x , y + h , x + w } ;
2992 OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ;
2993 InsetRect( &childRect , -10 , -10) ;
2994
2995 if ( RectInRgn( &childRect , updatergn ) )
2996 {
2997 // paint custom borders
2998 wxNcPaintEvent eventNc( child->GetId() );
2999 eventNc.SetEventObject( child );
3000 if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
3001 {
3002 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3003 if ( UMAGetSystemVersion() >= 0x1030 )
3004 {
3005 child->MacPaintBorders(0, 0) ;
3006 }
3007 else
3008 #endif
3009 {
3010 wxWindowDC dc(this) ;
3011 dc.SetClippingRegion(wxRegion(updatergn));
3012 wxMacPortSetter helper(&dc) ;
3013 child->MacPaintBorders(0, 0) ;
3014 }
3015 }
3016 }
3017 }
3018 }
3019
3020 return handled ;
3021 }
3022
3023
3024 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
3025 {
3026 wxWindowMac *iter = (wxWindowMac*)this ;
3027
3028 while ( iter )
3029 {
3030 if ( iter->IsTopLevel() )
3031 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
3032
3033 iter = iter->GetParent() ;
3034 }
3035
3036 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3037
3038 return NULL ;
3039 }
3040
3041 void wxWindowMac::MacCreateScrollBars( long style )
3042 {
3043 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
3044
3045 if ( style & ( wxVSCROLL | wxHSCROLL ) )
3046 {
3047 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
3048 int scrlsize = MAC_SCROLLBAR_SIZE ;
3049 wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ;
3050 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
3051 {
3052 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
3053 variant = wxWINDOW_VARIANT_SMALL ;
3054 }
3055
3056 int adjust = hasBoth ? scrlsize - 1: 0 ;
3057 int width, height ;
3058 GetClientSize( &width , &height ) ;
3059
3060 wxPoint vPoint(width - scrlsize, 0) ;
3061 wxSize vSize(scrlsize, height - adjust) ;
3062 wxPoint hPoint(0, height - scrlsize) ;
3063 wxSize hSize(width - adjust, scrlsize) ;
3064
3065 if ( style & wxVSCROLL )
3066 m_vScrollBar = new wxScrollBar(this, wxID_ANY, vPoint, vSize , wxVERTICAL);
3067
3068 if ( style & wxHSCROLL )
3069 m_hScrollBar = new wxScrollBar(this, wxID_ANY, hPoint, hSize , wxHORIZONTAL);
3070 }
3071
3072 // because the create does not take into account the client area origin
3073 // we might have a real position shift
3074 MacRepositionScrollBars() ;
3075 }
3076
3077 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const
3078 {
3079 bool result = ((child == NULL) || ((child != m_hScrollBar) && (child != m_vScrollBar)));
3080
3081 return result ;
3082 }
3083
3084 void wxWindowMac::MacRepositionScrollBars()
3085 {
3086 if ( !m_hScrollBar && !m_vScrollBar )
3087 return ;
3088
3089 bool hasBoth = (m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
3090 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
3091 int adjust = hasBoth ? scrlsize - 1 : 0 ;
3092
3093 // get real client area
3094 int width, height ;
3095 GetSize( &width , &height );
3096
3097 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
3098 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
3099
3100 wxPoint vPoint( width - scrlsize, 0 ) ;
3101 wxSize vSize( scrlsize, height - adjust ) ;
3102 wxPoint hPoint( 0 , height - scrlsize ) ;
3103 wxSize hSize( width - adjust, scrlsize ) ;
3104
3105 #if 0
3106 int x = 0, y = 0, w, h ;
3107 GetSize( &w , &h ) ;
3108
3109 MacClientToRootWindow( &x , &y ) ;
3110 MacClientToRootWindow( &w , &h ) ;
3111
3112 wxWindowMac *iter = (wxWindowMac*)this ;
3113
3114 int totW = 10000 , totH = 10000;
3115 while ( iter )
3116 {
3117 if ( iter->IsTopLevel() )
3118 {
3119 iter->GetSize( &totW , &totH ) ;
3120 break ;
3121 }
3122
3123 iter = iter->GetParent() ;
3124 }
3125
3126 if ( x == 0 )
3127 {
3128 hPoint.x = -1 ;
3129 hSize.x += 1 ;
3130 }
3131 if ( y == 0 )
3132 {
3133 vPoint.y = -1 ;
3134 vSize.y += 1 ;
3135 }
3136
3137 if ( w - x >= totW )
3138 {
3139 hSize.x += 1 ;
3140 vPoint.x += 1 ;
3141 }
3142 if ( h - y >= totH )
3143 {
3144 vSize.y += 1 ;
3145 hPoint.y += 1 ;
3146 }
3147 #endif
3148
3149 if ( m_vScrollBar )
3150 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE );
3151 if ( m_hScrollBar )
3152 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE );
3153 }
3154
3155 bool wxWindowMac::AcceptsFocus() const
3156 {
3157 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3158 }
3159
3160 void wxWindowMac::MacSuperChangedPosition()
3161 {
3162 // only window-absolute structures have to be moved i.e. controls
3163
3164 m_cachedClippedRectValid = false ;
3165
3166 wxWindowMac *child;
3167 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3168 while ( node )
3169 {
3170 child = node->GetData();
3171 child->MacSuperChangedPosition() ;
3172
3173 node = node->GetNext();
3174 }
3175 }
3176
3177 void wxWindowMac::MacTopLevelWindowChangedPosition()
3178 {
3179 // only screen-absolute structures have to be moved i.e. glcanvas
3180
3181 wxWindowMac *child;
3182 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3183 while ( node )
3184 {
3185 child = node->GetData();
3186 child->MacTopLevelWindowChangedPosition() ;
3187
3188 node = node->GetNext();
3189 }
3190 }
3191
3192 long wxWindowMac::MacGetLeftBorderSize() const
3193 {
3194 if ( IsTopLevel() )
3195 return 0 ;
3196
3197 SInt32 border = 0 ;
3198
3199 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER))
3200 {
3201 // this metric is only the 'outset' outside the simple frame rect
3202 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
3203 border += 1 ;
3204 }
3205 else if (HasFlag(wxSIMPLE_BORDER))
3206 {
3207 // this metric is only the 'outset' outside the simple frame rect
3208 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
3209 border += 1 ;
3210 }
3211
3212 return border ;
3213 }
3214
3215 long wxWindowMac::MacGetRightBorderSize() const
3216 {
3217 // they are all symmetric in mac themes
3218 return MacGetLeftBorderSize() ;
3219 }
3220
3221 long wxWindowMac::MacGetTopBorderSize() const
3222 {
3223 // they are all symmetric in mac themes
3224 return MacGetLeftBorderSize() ;
3225 }
3226
3227 long wxWindowMac::MacGetBottomBorderSize() const
3228 {
3229 // they are all symmetric in mac themes
3230 return MacGetLeftBorderSize() ;
3231 }
3232
3233 long wxWindowMac::MacRemoveBordersFromStyle( long style )
3234 {
3235 return style & ~wxBORDER_MASK ;
3236 }
3237
3238 // Find the wxWindowMac at the current mouse position, returning the mouse
3239 // position.
3240 wxWindowMac * wxFindWindowAtPointer( wxPoint& pt )
3241 {
3242 pt = wxGetMousePosition();
3243 wxWindowMac* found = wxFindWindowAtPoint(pt);
3244
3245 return found;
3246 }
3247
3248 // Get the current mouse position.
3249 wxPoint wxGetMousePosition()
3250 {
3251 int x, y;
3252
3253 wxGetMousePosition( &x, &y );
3254
3255 return wxPoint(x, y);
3256 }
3257
3258 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
3259 {
3260 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
3261 {
3262 // copied from wxGTK : CS
3263 // VZ: shouldn't we move this to base class then?
3264
3265 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3266 // except that:
3267 //
3268 // (a) it's a command event and so is propagated to the parent
3269 // (b) under MSW it can be generated from kbd too
3270 // (c) it uses screen coords (because of (a))
3271 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
3272 this->GetId(),
3273 this->ClientToScreen(event.GetPosition()));
3274 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
3275 event.Skip() ;
3276 }
3277 else
3278 {
3279 event.Skip() ;
3280 }
3281 }
3282
3283 void wxWindowMac::OnPaint( wxPaintEvent & event )
3284 {
3285 if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
3286 CallNextEventHandler(
3287 (EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() ,
3288 (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
3289 }
3290
3291 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
3292 {
3293 }
3294
3295 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
3296 {
3297 int x, y, w, h ;
3298
3299 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
3300 Rect bounds = { y, x, y + h, x + w };
3301
3302 return bounds ;
3303 }
3304
3305 wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
3306 {
3307 return eventNotHandledErr ;
3308 }
3309
3310 bool wxWindowMac::Reparent(wxWindowBase *newParentBase)
3311 {
3312 wxWindowMac *newParent = (wxWindowMac *)newParentBase;
3313 if ( !wxWindowBase::Reparent(newParent) )
3314 return false;
3315
3316 // copied from MacPostControlCreate
3317 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
3318
3319 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
3320
3321 ::EmbedControl( m_peer->GetControlRef() , container ) ;
3322
3323 return true;
3324 }