converting menu ids and safeguarding against missing menu items
[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 macid;
1669 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid );
1670 int id = wxMacCommandToId( macid );
1671 wxMenuItem* item = NULL ;
1672 wxMenu* realmenu ;
1673 item = menu->FindItem( id, &realmenu ) ;
1674 if ( item )
1675 {
1676 if (item->IsCheckable())
1677 item->Check( !item->IsChecked() ) ;
1678
1679 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1680 }
1681 }
1682
1683 menu->MacAfterDisplay( true ) ;
1684 menu->SetInvokingWindow( NULL );
1685
1686 return true;
1687 }
1688 #endif
1689
1690 // ----------------------------------------------------------------------------
1691 // tooltips
1692 // ----------------------------------------------------------------------------
1693
1694 #if wxUSE_TOOLTIPS
1695
1696 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
1697 {
1698 wxWindowBase::DoSetToolTip(tooltip);
1699
1700 if ( m_tooltip )
1701 m_tooltip->SetWindow(this);
1702 }
1703
1704 #endif
1705
1706 void wxWindowMac::MacInvalidateBorders()
1707 {
1708 if ( m_peer == NULL )
1709 return ;
1710
1711 bool vis = MacIsReallyShown() ;
1712 if ( !vis )
1713 return ;
1714
1715 int outerBorder = MacGetLeftBorderSize() ;
1716 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
1717 outerBorder += 4 ;
1718
1719 if ( outerBorder == 0 )
1720 return ;
1721
1722 // now we know that we have something to do at all
1723
1724 // as the borders are drawn on the parent we have to properly invalidate all these areas
1725 RgnHandle updateInner , updateOuter;
1726 Rect rect ;
1727
1728 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1729 updateInner = NewRgn() ;
1730 updateOuter = NewRgn() ;
1731
1732 m_peer->GetRect( &rect ) ;
1733 RectRgn( updateInner, &rect ) ;
1734 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1735 RectRgn( updateOuter, &rect ) ;
1736 DiffRgn( updateOuter, updateInner , updateOuter ) ;
1737
1738 #ifdef __WXMAC_OSX__
1739 GetParent()->m_peer->SetNeedsDisplay( updateOuter ) ;
1740 #else
1741 WindowRef tlw = (WindowRef) MacGetTopLevelWindowRef() ;
1742 if ( tlw )
1743 InvalWindowRgn( tlw , updateOuter ) ;
1744 #endif
1745
1746 DisposeRgn( updateOuter ) ;
1747 DisposeRgn( updateInner ) ;
1748 }
1749
1750 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
1751 {
1752 // this is never called for a toplevel window, so we know we have a parent
1753 int former_x , former_y , former_w, former_h ;
1754
1755 // Get true coordinates of former position
1756 DoGetPosition( &former_x , &former_y ) ;
1757 DoGetSize( &former_w , &former_h ) ;
1758
1759 wxWindow *parent = GetParent();
1760 if ( parent )
1761 {
1762 wxPoint pt(parent->GetClientAreaOrigin());
1763 former_x += pt.x ;
1764 former_y += pt.y ;
1765 }
1766
1767 int actualWidth = width ;
1768 int actualHeight = height ;
1769 int actualX = x;
1770 int actualY = y;
1771
1772 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1773 actualWidth = m_minWidth;
1774 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1775 actualHeight = m_minHeight;
1776 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1777 actualWidth = m_maxWidth;
1778 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1779 actualHeight = m_maxHeight;
1780
1781 bool doMove = false, doResize = false ;
1782
1783 if ( actualX != former_x || actualY != former_y )
1784 doMove = true ;
1785
1786 if ( actualWidth != former_w || actualHeight != former_h )
1787 doResize = true ;
1788
1789 if ( doMove || doResize )
1790 {
1791 // as the borders are drawn outside the native control, we adjust now
1792
1793 wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ),
1794 wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1795 actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1796
1797 Rect r ;
1798 wxMacRectToNative( &bounds , &r ) ;
1799
1800 if ( !GetParent()->IsTopLevel() )
1801 wxMacWindowToNative( GetParent() , &r ) ;
1802
1803 MacInvalidateBorders() ;
1804
1805 m_cachedClippedRectValid = false ;
1806 m_peer->SetRect( &r ) ;
1807
1808 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1809
1810 MacInvalidateBorders() ;
1811
1812 MacRepositionScrollBars() ;
1813 if ( doMove )
1814 {
1815 wxPoint point(actualX, actualY);
1816 wxMoveEvent event(point, m_windowId);
1817 event.SetEventObject(this);
1818 GetEventHandler()->ProcessEvent(event) ;
1819 }
1820
1821 if ( doResize )
1822 {
1823 MacRepositionScrollBars() ;
1824 wxSize size(actualWidth, actualHeight);
1825 wxSizeEvent event(size, m_windowId);
1826 event.SetEventObject(this);
1827 GetEventHandler()->ProcessEvent(event);
1828 }
1829 }
1830 }
1831
1832 wxSize wxWindowMac::DoGetBestSize() const
1833 {
1834 if ( m_macIsUserPane || IsTopLevel() )
1835 return wxWindowBase::DoGetBestSize() ;
1836
1837 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1838 int bestWidth, bestHeight ;
1839
1840 m_peer->GetBestRect( &bestsize ) ;
1841 if ( EmptyRect( &bestsize ) )
1842 {
1843 bestsize.left =
1844 bestsize.top = 0 ;
1845 bestsize.right =
1846 bestsize.bottom = 16 ;
1847
1848 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1849 {
1850 bestsize.bottom = 16 ;
1851 }
1852 #if wxUSE_SPINBTN
1853 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1854 {
1855 bestsize.bottom = 24 ;
1856 }
1857 #endif
1858 else
1859 {
1860 // return wxWindowBase::DoGetBestSize() ;
1861 }
1862 }
1863
1864 bestWidth = bestsize.right - bestsize.left ;
1865 bestHeight = bestsize.bottom - bestsize.top ;
1866 if ( bestHeight < 10 )
1867 bestHeight = 13 ;
1868
1869 return wxSize(bestWidth, bestHeight);
1870 }
1871
1872 // set the size of the window: if the dimensions are positive, just use them,
1873 // but if any of them is equal to -1, it means that we must find the value for
1874 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1875 // which case -1 is a valid value for x and y)
1876 //
1877 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1878 // the width/height to best suit our contents, otherwise we reuse the current
1879 // width/height
1880 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1881 {
1882 // get the current size and position...
1883 int currentX, currentY;
1884 int currentW, currentH;
1885
1886 GetPosition(&currentX, &currentY);
1887 GetSize(&currentW, &currentH);
1888
1889 // ... and don't do anything (avoiding flicker) if it's already ok
1890 if ( x == currentX && y == currentY &&
1891 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1892 {
1893 // TODO: REMOVE
1894 MacRepositionScrollBars() ; // we might have a real position shift
1895
1896 return;
1897 }
1898
1899 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1900 {
1901 if ( x == wxDefaultCoord )
1902 x = currentX;
1903 if ( y == wxDefaultCoord )
1904 y = currentY;
1905 }
1906
1907 AdjustForParentClientOrigin( x, y, sizeFlags );
1908
1909 wxSize size = wxDefaultSize;
1910 if ( width == wxDefaultCoord )
1911 {
1912 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1913 {
1914 size = DoGetBestSize();
1915 width = size.x;
1916 }
1917 else
1918 {
1919 // just take the current one
1920 width = currentW;
1921 }
1922 }
1923
1924 if ( height == wxDefaultCoord )
1925 {
1926 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1927 {
1928 if ( size.x == wxDefaultCoord )
1929 size = DoGetBestSize();
1930 // else: already called DoGetBestSize() above
1931
1932 height = size.y;
1933 }
1934 else
1935 {
1936 // just take the current one
1937 height = currentH;
1938 }
1939 }
1940
1941 DoMoveWindow( x, y, width, height );
1942 }
1943
1944 wxPoint wxWindowMac::GetClientAreaOrigin() const
1945 {
1946 RgnHandle rgn = NewRgn() ;
1947 Rect content ;
1948 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1949 {
1950 GetRegionBounds( rgn , &content ) ;
1951 }
1952 else
1953 {
1954 content.left =
1955 content.top = 0 ;
1956 }
1957
1958 DisposeRgn( rgn ) ;
1959
1960 return wxPoint( content.left + MacGetLeftBorderSize() , content.top + MacGetTopBorderSize() );
1961 }
1962
1963 void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1964 {
1965 if ( clientheight != wxDefaultCoord || clientheight != wxDefaultCoord )
1966 {
1967 int currentclientwidth , currentclientheight ;
1968 int currentwidth , currentheight ;
1969
1970 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1971 GetSize( &currentwidth , &currentheight ) ;
1972
1973 DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
1974 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1975 }
1976 }
1977
1978 void wxWindowMac::SetLabel(const wxString& title)
1979 {
1980 m_label = wxStripMenuCodes(title) ;
1981
1982 if ( m_peer && m_peer->Ok() )
1983 m_peer->SetLabel( m_label ) ;
1984
1985 Refresh() ;
1986 }
1987
1988 wxString wxWindowMac::GetLabel() const
1989 {
1990 return m_label ;
1991 }
1992
1993 bool wxWindowMac::Show(bool show)
1994 {
1995 bool former = MacIsReallyShown() ;
1996 if ( !wxWindowBase::Show(show) )
1997 return false;
1998
1999 // TODO: use visibilityChanged Carbon Event for OSX
2000 if ( m_peer )
2001 m_peer->SetVisibility( show , true ) ;
2002
2003 if ( former != MacIsReallyShown() )
2004 MacPropagateVisibilityChanged() ;
2005
2006 return true;
2007 }
2008
2009 bool wxWindowMac::Enable(bool enable)
2010 {
2011 wxASSERT( m_peer->Ok() ) ;
2012 bool former = MacIsReallyEnabled() ;
2013 if ( !wxWindowBase::Enable(enable) )
2014 return false;
2015
2016 m_peer->Enable( enable ) ;
2017
2018 if ( former != MacIsReallyEnabled() )
2019 MacPropagateEnabledStateChanged() ;
2020
2021 return true;
2022 }
2023
2024 //
2025 // status change propagations (will be not necessary for OSX later )
2026 //
2027
2028 void wxWindowMac::MacPropagateVisibilityChanged()
2029 {
2030 #if !TARGET_API_MAC_OSX
2031 MacVisibilityChanged() ;
2032
2033 wxWindowMac *child;
2034 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2035 while ( node )
2036 {
2037 child = node->GetData();
2038 if ( child->IsShown() )
2039 child->MacPropagateVisibilityChanged() ;
2040
2041 node = node->GetNext();
2042 }
2043 #endif
2044 }
2045
2046 void wxWindowMac::MacPropagateEnabledStateChanged()
2047 {
2048 #if !TARGET_API_MAC_OSX
2049 MacEnabledStateChanged() ;
2050
2051 wxWindowMac *child;
2052 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2053 while ( node )
2054 {
2055 child = node->GetData();
2056 if ( child->IsEnabled() )
2057 child->MacPropagateEnabledStateChanged() ;
2058
2059 node = node->GetNext();
2060 }
2061 #endif
2062 }
2063
2064 void wxWindowMac::MacPropagateHiliteChanged()
2065 {
2066 #if !TARGET_API_MAC_OSX
2067 MacHiliteChanged() ;
2068
2069 wxWindowMac *child;
2070 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2071 while ( node )
2072 {
2073 child = node->GetData();
2074 if (child /* && child->IsEnabled() */)
2075 child->MacPropagateHiliteChanged() ;
2076
2077 node = node->GetNext();
2078 }
2079 #endif
2080 }
2081
2082 //
2083 // status change notifications
2084 //
2085
2086 void wxWindowMac::MacVisibilityChanged()
2087 {
2088 }
2089
2090 void wxWindowMac::MacHiliteChanged()
2091 {
2092 }
2093
2094 void wxWindowMac::MacEnabledStateChanged()
2095 {
2096 }
2097
2098 //
2099 // status queries on the inherited window's state
2100 //
2101
2102 bool wxWindowMac::MacIsReallyShown()
2103 {
2104 // only under OSX the visibility of the TLW is taken into account
2105 if ( m_isBeingDeleted )
2106 return false ;
2107
2108 #if TARGET_API_MAC_OSX
2109 if ( m_peer && m_peer->Ok() )
2110 return m_peer->IsVisible();
2111 #endif
2112
2113 wxWindow* win = this ;
2114 while ( win->IsShown() )
2115 {
2116 if ( win->IsTopLevel() )
2117 return true ;
2118
2119 win = win->GetParent() ;
2120 if ( win == NULL )
2121 return true ;
2122 }
2123
2124 return false ;
2125 }
2126
2127 bool wxWindowMac::MacIsReallyEnabled()
2128 {
2129 return m_peer->IsEnabled() ;
2130 }
2131
2132 bool wxWindowMac::MacIsReallyHilited()
2133 {
2134 return m_peer->IsActive();
2135 }
2136
2137 void wxWindowMac::MacFlashInvalidAreas()
2138 {
2139 #if TARGET_API_MAC_OSX
2140 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
2141 #endif
2142 }
2143
2144 int wxWindowMac::GetCharHeight() const
2145 {
2146 wxClientDC dc( (wxWindowMac*)this ) ;
2147
2148 return dc.GetCharHeight() ;
2149 }
2150
2151 int wxWindowMac::GetCharWidth() const
2152 {
2153 wxClientDC dc( (wxWindowMac*)this ) ;
2154
2155 return dc.GetCharWidth() ;
2156 }
2157
2158 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
2159 int *descent, int *externalLeading, const wxFont *theFont ) const
2160 {
2161 const wxFont *fontToUse = theFont;
2162 if ( !fontToUse )
2163 fontToUse = &m_font;
2164
2165 wxClientDC dc( (wxWindowMac*) this ) ;
2166 long lx,ly,ld,le ;
2167 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2168 if ( externalLeading )
2169 *externalLeading = le ;
2170 if ( descent )
2171 *descent = ld ;
2172 if ( x )
2173 *x = lx ;
2174 if ( y )
2175 *y = ly ;
2176 }
2177
2178 /*
2179 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2180 * we always intersect with the entire window, not only with the client area
2181 */
2182
2183 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
2184 {
2185 if ( m_peer == NULL )
2186 return ;
2187
2188 if ( !MacIsReallyShown() )
2189 return ;
2190
2191 if ( rect )
2192 {
2193 Rect r ;
2194
2195 wxMacRectToNative( rect , &r ) ;
2196 m_peer->SetNeedsDisplay( &r ) ;
2197 }
2198 else
2199 {
2200 m_peer->SetNeedsDisplay() ;
2201 }
2202 }
2203
2204 void wxWindowMac::Freeze()
2205 {
2206 #if TARGET_API_MAC_OSX
2207 if ( !m_frozenness++ )
2208 {
2209 if ( m_peer && m_peer->Ok() )
2210 m_peer->SetDrawingEnabled( false ) ;
2211 }
2212 #endif
2213 }
2214
2215 void wxWindowMac::Thaw()
2216 {
2217 #if TARGET_API_MAC_OSX
2218 wxASSERT_MSG( m_frozenness > 0, wxT("Thaw() without matching Freeze()") );
2219
2220 if ( !--m_frozenness )
2221 {
2222 if ( m_peer && m_peer->Ok() )
2223 {
2224 m_peer->SetDrawingEnabled( true ) ;
2225 m_peer->InvalidateWithChildren() ;
2226 }
2227 }
2228 #endif
2229 }
2230
2231 wxWindowMac *wxGetActiveWindow()
2232 {
2233 // actually this is a windows-only concept
2234 return NULL;
2235 }
2236
2237 // Coordinates relative to the window
2238 void wxWindowMac::WarpPointer(int x_pos, int y_pos)
2239 {
2240 // We really don't move the mouse programmatically under Mac.
2241 }
2242
2243 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
2244 {
2245 if ( MacGetTopLevelWindow() == NULL )
2246 return ;
2247
2248 #if TARGET_API_MAC_OSX
2249 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) )
2250 {
2251 event.Skip() ;
2252 }
2253 else
2254 #endif
2255 {
2256 event.GetDC()->Clear() ;
2257 }
2258 }
2259
2260 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2261 {
2262 event.Skip() ;
2263 }
2264
2265 int wxWindowMac::GetScrollPos(int orient) const
2266 {
2267 if ( orient == wxHORIZONTAL )
2268 {
2269 if ( m_hScrollBar )
2270 return m_hScrollBar->GetThumbPosition() ;
2271 }
2272 else
2273 {
2274 if ( m_vScrollBar )
2275 return m_vScrollBar->GetThumbPosition() ;
2276 }
2277
2278 return 0;
2279 }
2280
2281 // This now returns the whole range, not just the number
2282 // of positions that we can scroll.
2283 int wxWindowMac::GetScrollRange(int orient) const
2284 {
2285 if ( orient == wxHORIZONTAL )
2286 {
2287 if ( m_hScrollBar )
2288 return m_hScrollBar->GetRange() ;
2289 }
2290 else
2291 {
2292 if ( m_vScrollBar )
2293 return m_vScrollBar->GetRange() ;
2294 }
2295
2296 return 0;
2297 }
2298
2299 int wxWindowMac::GetScrollThumb(int orient) const
2300 {
2301 if ( orient == wxHORIZONTAL )
2302 {
2303 if ( m_hScrollBar )
2304 return m_hScrollBar->GetThumbSize() ;
2305 }
2306 else
2307 {
2308 if ( m_vScrollBar )
2309 return m_vScrollBar->GetThumbSize() ;
2310 }
2311
2312 return 0;
2313 }
2314
2315 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
2316 {
2317 if ( orient == wxHORIZONTAL )
2318 {
2319 if ( m_hScrollBar )
2320 m_hScrollBar->SetThumbPosition( pos ) ;
2321 }
2322 else
2323 {
2324 if ( m_vScrollBar )
2325 m_vScrollBar->SetThumbPosition( pos ) ;
2326 }
2327 }
2328
2329 //
2330 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2331 // our own window origin is at leftOrigin/rightOrigin
2332 //
2333
2334 void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
2335 {
2336 if ( IsTopLevel() )
2337 return ;
2338
2339 Rect rect ;
2340 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
2341 bool hasBothScrollbars = (m_hScrollBar && m_hScrollBar->IsShown()) && (m_vScrollBar && m_vScrollBar->IsShown()) ;
2342
2343 // back to the surrounding frame rectangle
2344 m_peer->GetRect( &rect ) ;
2345 InsetRect( &rect, -1 , -1 ) ;
2346
2347 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2348 if ( UMAGetSystemVersion() >= 0x1030 )
2349 {
2350 CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
2351 rect.bottom - rect.top ) ;
2352
2353 HIThemeFrameDrawInfo info ;
2354 memset( &info, 0 , sizeof(info) ) ;
2355
2356 info.version = 0 ;
2357 info.kind = 0 ;
2358 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2359 info.isFocused = hasFocus ;
2360
2361 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
2362 wxASSERT( cgContext ) ;
2363
2364 if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2365 {
2366 info.kind = kHIThemeFrameTextFieldSquare ;
2367 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2368 }
2369 else if ( HasFlag(wxSIMPLE_BORDER) )
2370 {
2371 info.kind = kHIThemeFrameListBox ;
2372 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2373 }
2374 else if ( hasFocus )
2375 {
2376 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
2377 }
2378
2379 m_peer->GetRect( &rect ) ;
2380 if ( hasBothScrollbars )
2381 {
2382 int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
2383 CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
2384 CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
2385 HIThemeGrowBoxDrawInfo info ;
2386 memset( &info, 0, sizeof(info) ) ;
2387 info.version = 0 ;
2388 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2389 info.kind = kHIThemeGrowBoxKindNone ;
2390 info.size = kHIThemeGrowBoxSizeNormal ;
2391 info.direction = kThemeGrowRight | kThemeGrowDown ;
2392 HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
2393 }
2394 }
2395 else
2396 #endif
2397 {
2398 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2399 if ( top )
2400 {
2401 wxPoint pt(0, 0) ;
2402 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
2403 OffsetRect( &rect , pt.x , pt.y ) ;
2404 }
2405
2406 if ( HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2407 DrawThemeEditTextFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
2408 else if ( HasFlag(wxSIMPLE_BORDER) )
2409 DrawThemeListBoxFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
2410
2411 if ( hasFocus )
2412 DrawThemeFocusRect( &rect , true ) ;
2413
2414 if ( hasBothScrollbars )
2415 {
2416 // GetThemeStandaloneGrowBoxBounds
2417 // DrawThemeStandaloneNoGrowBox
2418 }
2419 }
2420 }
2421
2422 void wxWindowMac::RemoveChild( wxWindowBase *child )
2423 {
2424 if ( child == m_hScrollBar )
2425 m_hScrollBar = NULL ;
2426 if ( child == m_vScrollBar )
2427 m_vScrollBar = NULL ;
2428
2429 wxWindowBase::RemoveChild( child ) ;
2430 }
2431
2432 // New function that will replace some of the above.
2433 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2434 int range, bool refresh)
2435 {
2436 bool showScroller;
2437
2438 if ( orient == wxHORIZONTAL )
2439 {
2440 if ( m_hScrollBar )
2441 {
2442 showScroller = ((range != 0) && (range > thumbVisible));
2443 if ( m_hScrollBar->IsShown() != showScroller )
2444 m_hScrollBar->Show( showScroller ) ;
2445
2446 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2447 }
2448 }
2449 else
2450 {
2451 if ( m_vScrollBar )
2452 {
2453 showScroller = ((range != 0) && (range > thumbVisible));
2454 if ( m_vScrollBar->IsShown() != showScroller )
2455 m_vScrollBar->Show( showScroller ) ;
2456
2457 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2458 }
2459 }
2460
2461 MacRepositionScrollBars() ;
2462 }
2463
2464 // Does a physical scroll
2465 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2466 {
2467 if ( dx == 0 && dy == 0 )
2468 return ;
2469
2470 int width , height ;
2471 GetClientSize( &width , &height ) ;
2472
2473 #if TARGET_API_MAC_OSX
2474 if ( true /* m_peer->IsCompositing() */ )
2475 {
2476 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2477 // area is scrolled, this does not occur if width and height are 2 pixels less,
2478 // TODO: write optimal workaround
2479 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
2480 if ( rect )
2481 scrollrect.Intersect( *rect ) ;
2482
2483 if ( m_peer->GetNeedsDisplay() )
2484 {
2485 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2486 // either immediate redraw or full invalidate
2487 #if 1
2488 // is the better overall solution, as it does not slow down scrolling
2489 m_peer->SetNeedsDisplay() ;
2490 #else
2491 // this would be the preferred version for fast drawing controls
2492
2493 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2494 if ( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() )
2495 HIViewRender(m_peer->GetControlRef()) ;
2496 else
2497 #endif
2498 Update() ;
2499 #endif
2500 }
2501
2502 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2503 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2504 m_peer->ScrollRect( &scrollrect , dx , dy ) ;
2505
2506 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2507 // either immediate redraw or full invalidate
2508 #if 0
2509 // is the better overall solution, as it does not slow down scrolling
2510 m_peer->SetNeedsDisplay() ;
2511 #else
2512 // this would be the preferred version for fast drawing controls
2513
2514 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2515 if ( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() )
2516 HIViewRender(m_peer->GetControlRef()) ;
2517 else
2518 #endif
2519 Update() ;
2520 #endif
2521 }
2522 else
2523 #endif
2524 {
2525 wxPoint pos;
2526 pos.x =
2527 pos.y = 0;
2528
2529 Rect scrollrect;
2530 RgnHandle updateRgn = NewRgn() ;
2531
2532 {
2533 wxClientDC dc(this) ;
2534 wxMacPortSetter helper(&dc) ;
2535
2536 m_peer->GetRectInWindowCoords( &scrollrect ) ;
2537 //scrollrect.top += MacGetTopBorderSize() ;
2538 //scrollrect.left += MacGetLeftBorderSize() ;
2539 scrollrect.bottom = scrollrect.top + height ;
2540 scrollrect.right = scrollrect.left + width ;
2541
2542 if ( rect )
2543 {
2544 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2545 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2546 SectRect( &scrollrect , &r , &scrollrect ) ;
2547 }
2548
2549 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2550
2551 // now scroll the former update region as well and add the new update region
2552 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2553 RgnHandle formerUpdateRgn = NewRgn() ;
2554 RgnHandle scrollRgn = NewRgn() ;
2555 RectRgn( scrollRgn , &scrollrect ) ;
2556 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2557 Point pt = {0, 0} ;
2558 LocalToGlobal( &pt ) ;
2559 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2560 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2561
2562 if ( !EmptyRgn( formerUpdateRgn ) )
2563 {
2564 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2565 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2566 InvalWindowRgn( rootWindow, formerUpdateRgn ) ;
2567 }
2568
2569 InvalWindowRgn(rootWindow, updateRgn ) ;
2570 DisposeRgn( updateRgn ) ;
2571 DisposeRgn( formerUpdateRgn ) ;
2572 DisposeRgn( scrollRgn ) ;
2573 }
2574
2575 Update() ;
2576 }
2577
2578 wxWindowMac *child;
2579 int x, y, w, h;
2580 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2581 {
2582 child = node->GetData();
2583 if (child == NULL)
2584 continue;
2585 if (child == m_vScrollBar)
2586 continue;
2587 if (child == m_hScrollBar)
2588 continue;
2589 if (child->IsTopLevel())
2590 continue;
2591
2592 child->GetPosition( &x, &y );
2593 child->GetSize( &w, &h );
2594 if (rect)
2595 {
2596 wxRect rc( x, y, w, h );
2597 if (rect->Intersects( rc ))
2598 child->SetSize( x + dx, y + dy, w, h );
2599 }
2600 else
2601 {
2602 child->SetSize( x + dx, y + dy, w, h );
2603 }
2604 }
2605 }
2606
2607 void wxWindowMac::MacOnScroll( wxScrollEvent &event )
2608 {
2609 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
2610 {
2611 wxScrollWinEvent wevent;
2612 wevent.SetPosition(event.GetPosition());
2613 wevent.SetOrientation(event.GetOrientation());
2614 wevent.SetEventObject(this);
2615
2616 if (event.GetEventType() == wxEVT_SCROLL_TOP)
2617 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
2618 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
2619 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
2620 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
2621 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
2622 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
2623 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
2624 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
2625 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
2626 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
2627 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
2628 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
2629 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
2630 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
2631 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
2632
2633 GetEventHandler()->ProcessEvent(wevent);
2634 }
2635 }
2636
2637 // Get the window with the focus
2638 wxWindowMac *wxWindowBase::DoFindFocus()
2639 {
2640 ControlRef control ;
2641 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2642 return wxFindControlFromMacControl( control ) ;
2643 }
2644
2645 void wxWindowMac::OnSetFocus( wxFocusEvent& event )
2646 {
2647 // panel wants to track the window which was the last to have focus in it,
2648 // so we want to set ourselves as the window which last had focus
2649 //
2650 // notice that it's also important to do it upwards the tree because
2651 // otherwise when the top level panel gets focus, it won't set it back to
2652 // us, but to some other sibling
2653
2654 // CS: don't know if this is still needed:
2655 //wxChildFocusEvent eventFocus(this);
2656 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2657
2658 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2659 {
2660 #if wxMAC_USE_CORE_GRAPHICS
2661 GetParent()->Refresh() ;
2662 #else
2663 wxMacWindowStateSaver sv( this ) ;
2664 Rect rect ;
2665
2666 m_peer->GetRect( &rect ) ;
2667 // auf den umgebenden Rahmen zur\9fck
2668 InsetRect( &rect, -1 , -1 ) ;
2669
2670 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2671 if ( top )
2672 {
2673 wxPoint pt(0, 0) ;
2674 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
2675 rect.left += pt.x ;
2676 rect.right += pt.x ;
2677 rect.top += pt.y ;
2678 rect.bottom += pt.y ;
2679 }
2680
2681 bool bIsFocusEvent = (event.GetEventType() == wxEVT_SET_FOCUS);
2682 DrawThemeFocusRect( &rect , bIsFocusEvent ) ;
2683 if ( !bIsFocusEvent )
2684 {
2685 // as this erases part of the frame we have to redraw borders
2686 // and because our z-ordering is not always correct (staticboxes)
2687 // we have to invalidate things, we cannot simple redraw
2688 MacInvalidateBorders() ;
2689 }
2690 #endif
2691 }
2692
2693 event.Skip();
2694 }
2695
2696 void wxWindowMac::OnInternalIdle()
2697 {
2698 // This calls the UI-update mechanism (querying windows for
2699 // menu/toolbar/control state information)
2700 if (wxUpdateUIEvent::CanUpdate(this))
2701 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2702 }
2703
2704 // Raise the window to the top of the Z order
2705 void wxWindowMac::Raise()
2706 {
2707 m_peer->SetZOrder( true , NULL ) ;
2708 }
2709
2710 // Lower the window to the bottom of the Z order
2711 void wxWindowMac::Lower()
2712 {
2713 m_peer->SetZOrder( false , NULL ) ;
2714 }
2715
2716 // static wxWindow *gs_lastWhich = NULL;
2717
2718 bool wxWindowMac::MacSetupCursor( const wxPoint& pt )
2719 {
2720 // first trigger a set cursor event
2721
2722 wxPoint clientorigin = GetClientAreaOrigin() ;
2723 wxSize clientsize = GetClientSize() ;
2724 wxCursor cursor ;
2725 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2726 {
2727 wxSetCursorEvent event( pt.x , pt.y );
2728
2729 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2730 if ( processedEvtSetCursor && event.HasCursor() )
2731 {
2732 cursor = event.GetCursor() ;
2733 }
2734 else
2735 {
2736 // the test for processedEvtSetCursor is here to prevent using m_cursor
2737 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2738 // it - this is a way to say that our cursor shouldn't be used for this
2739 // point
2740 if ( !processedEvtSetCursor && m_cursor.Ok() )
2741 cursor = m_cursor ;
2742
2743 if ( !wxIsBusy() && !GetParent() )
2744 cursor = *wxSTANDARD_CURSOR ;
2745 }
2746
2747 if ( cursor.Ok() )
2748 cursor.MacInstall() ;
2749 }
2750
2751 return cursor.Ok() ;
2752 }
2753
2754 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2755 {
2756 #if wxUSE_TOOLTIPS
2757 if ( m_tooltip )
2758 return m_tooltip->GetTip() ;
2759 #endif
2760
2761 return wxEmptyString ;
2762 }
2763
2764 void wxWindowMac::ClearBackground()
2765 {
2766 Refresh() ;
2767 Update() ;
2768 }
2769
2770 void wxWindowMac::Update()
2771 {
2772 #if TARGET_API_MAC_OSX
2773 MacGetTopLevelWindow()->MacPerformUpdates() ;
2774 #else
2775 ::Draw1Control( m_peer->GetControlRef() ) ;
2776 #endif
2777 }
2778
2779 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2780 {
2781 wxTopLevelWindowMac* win = NULL ;
2782 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2783 if ( window )
2784 win = wxFindWinFromMacWindow( window ) ;
2785
2786 return win ;
2787 }
2788
2789 const wxRect& wxWindowMac::MacGetClippedClientRect() const
2790 {
2791 MacUpdateClippedRects() ;
2792
2793 return m_cachedClippedClientRect ;
2794 }
2795
2796 const wxRect& wxWindowMac::MacGetClippedRect() const
2797 {
2798 MacUpdateClippedRects() ;
2799
2800 return m_cachedClippedRect ;
2801 }
2802
2803 const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2804 {
2805 MacUpdateClippedRects() ;
2806
2807 return m_cachedClippedRectWithOuterStructure ;
2808 }
2809
2810 const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2811 {
2812 static wxRegion emptyrgn ;
2813
2814 if ( !m_isBeingDeleted && MacIsReallyShown() /*m_peer->IsVisible() */ )
2815 {
2816 MacUpdateClippedRects() ;
2817 if ( includeOuterStructures )
2818 return m_cachedClippedRegionWithOuterStructure ;
2819 else
2820 return m_cachedClippedRegion ;
2821 }
2822 else
2823 {
2824 return emptyrgn ;
2825 }
2826 }
2827
2828 void wxWindowMac::MacUpdateClippedRects() const
2829 {
2830 if ( m_cachedClippedRectValid )
2831 return ;
2832
2833 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2834 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2835 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2836 // to add focus borders everywhere
2837
2838 Rect r, rIncludingOuterStructures ;
2839
2840 m_peer->GetRect( &r ) ;
2841 r.left -= MacGetLeftBorderSize() ;
2842 r.top -= MacGetTopBorderSize() ;
2843 r.bottom += MacGetBottomBorderSize() ;
2844 r.right += MacGetRightBorderSize() ;
2845
2846 r.right -= r.left ;
2847 r.bottom -= r.top ;
2848 r.left = 0 ;
2849 r.top = 0 ;
2850
2851 rIncludingOuterStructures = r ;
2852 InsetRect( &rIncludingOuterStructures , -4 , -4 ) ;
2853
2854 wxRect cl = GetClientRect() ;
2855 Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ;
2856
2857 int x , y ;
2858 wxSize size ;
2859 const wxWindow* child = this ;
2860 const wxWindow* parent = NULL ;
2861
2862 while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL )
2863 {
2864 if ( parent->MacIsChildOfClientArea(child) )
2865 {
2866 size = parent->GetClientSize() ;
2867 wxPoint origin = parent->GetClientAreaOrigin() ;
2868 x = origin.x ;
2869 y = origin.y ;
2870 }
2871 else
2872 {
2873 // this will be true for scrollbars, toolbars etc.
2874 size = parent->GetSize() ;
2875 y = parent->MacGetTopBorderSize() ;
2876 x = parent->MacGetLeftBorderSize() ;
2877 size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ;
2878 size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ;
2879 }
2880
2881 parent->MacWindowToRootWindow( &x, &y ) ;
2882 MacRootWindowToWindow( &x , &y ) ;
2883
2884 Rect rparent = { y , x , y + size.y , x + size.x } ;
2885
2886 // the wxwindow and client rects will always be clipped
2887 SectRect( &r , &rparent , &r ) ;
2888 SectRect( &rClient , &rparent , &rClient ) ;
2889
2890 // the structure only at 'hard' borders
2891 if ( parent->MacClipChildren() ||
2892 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) )
2893 {
2894 SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ;
2895 }
2896
2897 child = parent ;
2898 }
2899
2900 m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ;
2901 m_cachedClippedClientRect = wxRect( rClient.left , rClient.top ,
2902 rClient.right - rClient.left , rClient.bottom - rClient.top ) ;
2903 m_cachedClippedRectWithOuterStructure = wxRect(
2904 rIncludingOuterStructures.left , rIncludingOuterStructures.top ,
2905 rIncludingOuterStructures.right - rIncludingOuterStructures.left ,
2906 rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ;
2907
2908 m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ;
2909 m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ;
2910 m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ;
2911
2912 m_cachedClippedRectValid = true ;
2913 }
2914
2915 /*
2916 This function must not change the updatergn !
2917 */
2918 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2919 {
2920 bool handled = false ;
2921 Rect updatebounds ;
2922 RgnHandle updatergn = (RgnHandle) updatergnr ;
2923 GetRegionBounds( updatergn , &updatebounds ) ;
2924
2925 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2926
2927 if ( !EmptyRgn(updatergn) )
2928 {
2929 RgnHandle newupdate = NewRgn() ;
2930 wxSize point = GetClientSize() ;
2931 wxPoint origin = GetClientAreaOrigin() ;
2932 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y + point.y ) ;
2933 SectRgn( newupdate , updatergn , newupdate ) ;
2934
2935 // first send an erase event to the entire update area
2936 {
2937 // for the toplevel window this really is the entire area
2938 // for all the others only their client area, otherwise they
2939 // might be drawing with full alpha and eg put blue into
2940 // the grow-box area of a scrolled window (scroll sample)
2941 wxDC* dc = new wxWindowDC(this);
2942 if ( IsTopLevel() )
2943 dc->SetClippingRegion(wxRegion(updatergn));
2944 else
2945 dc->SetClippingRegion(wxRegion(newupdate));
2946
2947 wxEraseEvent eevent( GetId(), dc );
2948 eevent.SetEventObject( this );
2949 GetEventHandler()->ProcessEvent( eevent );
2950 delete dc ;
2951 }
2952
2953 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2954 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2955 m_updateRegion = newupdate ;
2956 DisposeRgn( newupdate ) ;
2957
2958 if ( !m_updateRegion.Empty() )
2959 {
2960 // paint the window itself
2961
2962 wxPaintEvent event;
2963 event.SetTimestamp(time);
2964 event.SetEventObject(this);
2965 GetEventHandler()->ProcessEvent(event);
2966 handled = true ;
2967 }
2968
2969 // now we cannot rely on having its borders drawn by a window itself, as it does not
2970 // get the updateRgn wide enough to always do so, so we do it from the parent
2971 // this would also be the place to draw any custom backgrounds for native controls
2972 // in Composited windowing
2973 wxPoint clientOrigin = GetClientAreaOrigin() ;
2974
2975 wxWindowMac *child;
2976 int x, y, w, h;
2977 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2978 {
2979 child = node->GetData();
2980 if (child == NULL)
2981 continue;
2982 if (child == m_vScrollBar)
2983 continue;
2984 if (child == m_hScrollBar)
2985 continue;
2986 if (child->IsTopLevel())
2987 continue;
2988 if (!child->IsShown())
2989 continue;
2990
2991 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2992
2993 child->GetPosition( &x, &y );
2994 child->GetSize( &w, &h );
2995 Rect childRect = { y , x , y + h , x + w } ;
2996 OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ;
2997 InsetRect( &childRect , -10 , -10) ;
2998
2999 if ( RectInRgn( &childRect , updatergn ) )
3000 {
3001 // paint custom borders
3002 wxNcPaintEvent eventNc( child->GetId() );
3003 eventNc.SetEventObject( child );
3004 if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
3005 {
3006 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3007 if ( UMAGetSystemVersion() >= 0x1030 )
3008 {
3009 child->MacPaintBorders(0, 0) ;
3010 }
3011 else
3012 #endif
3013 {
3014 wxWindowDC dc(this) ;
3015 dc.SetClippingRegion(wxRegion(updatergn));
3016 wxMacPortSetter helper(&dc) ;
3017 child->MacPaintBorders(0, 0) ;
3018 }
3019 }
3020 }
3021 }
3022 }
3023
3024 return handled ;
3025 }
3026
3027
3028 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
3029 {
3030 wxWindowMac *iter = (wxWindowMac*)this ;
3031
3032 while ( iter )
3033 {
3034 if ( iter->IsTopLevel() )
3035 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
3036
3037 iter = iter->GetParent() ;
3038 }
3039
3040 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3041
3042 return NULL ;
3043 }
3044
3045 void wxWindowMac::MacCreateScrollBars( long style )
3046 {
3047 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
3048
3049 if ( style & ( wxVSCROLL | wxHSCROLL ) )
3050 {
3051 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
3052 int scrlsize = MAC_SCROLLBAR_SIZE ;
3053 wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ;
3054 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
3055 {
3056 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
3057 variant = wxWINDOW_VARIANT_SMALL ;
3058 }
3059
3060 int adjust = hasBoth ? scrlsize - 1: 0 ;
3061 int width, height ;
3062 GetClientSize( &width , &height ) ;
3063
3064 wxPoint vPoint(width - scrlsize, 0) ;
3065 wxSize vSize(scrlsize, height - adjust) ;
3066 wxPoint hPoint(0, height - scrlsize) ;
3067 wxSize hSize(width - adjust, scrlsize) ;
3068
3069 if ( style & wxVSCROLL )
3070 m_vScrollBar = new wxScrollBar(this, wxID_ANY, vPoint, vSize , wxVERTICAL);
3071
3072 if ( style & wxHSCROLL )
3073 m_hScrollBar = new wxScrollBar(this, wxID_ANY, hPoint, hSize , wxHORIZONTAL);
3074 }
3075
3076 // because the create does not take into account the client area origin
3077 // we might have a real position shift
3078 MacRepositionScrollBars() ;
3079 }
3080
3081 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const
3082 {
3083 bool result = ((child == NULL) || ((child != m_hScrollBar) && (child != m_vScrollBar)));
3084
3085 return result ;
3086 }
3087
3088 void wxWindowMac::MacRepositionScrollBars()
3089 {
3090 if ( !m_hScrollBar && !m_vScrollBar )
3091 return ;
3092
3093 bool hasBoth = (m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
3094 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
3095 int adjust = hasBoth ? scrlsize - 1 : 0 ;
3096
3097 // get real client area
3098 int width, height ;
3099 GetSize( &width , &height );
3100
3101 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
3102 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
3103
3104 wxPoint vPoint( width - scrlsize, 0 ) ;
3105 wxSize vSize( scrlsize, height - adjust ) ;
3106 wxPoint hPoint( 0 , height - scrlsize ) ;
3107 wxSize hSize( width - adjust, scrlsize ) ;
3108
3109 #if 0
3110 int x = 0, y = 0, w, h ;
3111 GetSize( &w , &h ) ;
3112
3113 MacClientToRootWindow( &x , &y ) ;
3114 MacClientToRootWindow( &w , &h ) ;
3115
3116 wxWindowMac *iter = (wxWindowMac*)this ;
3117
3118 int totW = 10000 , totH = 10000;
3119 while ( iter )
3120 {
3121 if ( iter->IsTopLevel() )
3122 {
3123 iter->GetSize( &totW , &totH ) ;
3124 break ;
3125 }
3126
3127 iter = iter->GetParent() ;
3128 }
3129
3130 if ( x == 0 )
3131 {
3132 hPoint.x = -1 ;
3133 hSize.x += 1 ;
3134 }
3135 if ( y == 0 )
3136 {
3137 vPoint.y = -1 ;
3138 vSize.y += 1 ;
3139 }
3140
3141 if ( w - x >= totW )
3142 {
3143 hSize.x += 1 ;
3144 vPoint.x += 1 ;
3145 }
3146 if ( h - y >= totH )
3147 {
3148 vSize.y += 1 ;
3149 hPoint.y += 1 ;
3150 }
3151 #endif
3152
3153 if ( m_vScrollBar )
3154 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE );
3155 if ( m_hScrollBar )
3156 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE );
3157 }
3158
3159 bool wxWindowMac::AcceptsFocus() const
3160 {
3161 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3162 }
3163
3164 void wxWindowMac::MacSuperChangedPosition()
3165 {
3166 // only window-absolute structures have to be moved i.e. controls
3167
3168 m_cachedClippedRectValid = false ;
3169
3170 wxWindowMac *child;
3171 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3172 while ( node )
3173 {
3174 child = node->GetData();
3175 child->MacSuperChangedPosition() ;
3176
3177 node = node->GetNext();
3178 }
3179 }
3180
3181 void wxWindowMac::MacTopLevelWindowChangedPosition()
3182 {
3183 // only screen-absolute structures have to be moved i.e. glcanvas
3184
3185 wxWindowMac *child;
3186 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3187 while ( node )
3188 {
3189 child = node->GetData();
3190 child->MacTopLevelWindowChangedPosition() ;
3191
3192 node = node->GetNext();
3193 }
3194 }
3195
3196 long wxWindowMac::MacGetLeftBorderSize() const
3197 {
3198 if ( IsTopLevel() )
3199 return 0 ;
3200
3201 SInt32 border = 0 ;
3202
3203 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER))
3204 {
3205 // this metric is only the 'outset' outside the simple frame rect
3206 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
3207 border += 1 ;
3208 }
3209 else if (HasFlag(wxSIMPLE_BORDER))
3210 {
3211 // this metric is only the 'outset' outside the simple frame rect
3212 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
3213 border += 1 ;
3214 }
3215
3216 return border ;
3217 }
3218
3219 long wxWindowMac::MacGetRightBorderSize() const
3220 {
3221 // they are all symmetric in mac themes
3222 return MacGetLeftBorderSize() ;
3223 }
3224
3225 long wxWindowMac::MacGetTopBorderSize() const
3226 {
3227 // they are all symmetric in mac themes
3228 return MacGetLeftBorderSize() ;
3229 }
3230
3231 long wxWindowMac::MacGetBottomBorderSize() const
3232 {
3233 // they are all symmetric in mac themes
3234 return MacGetLeftBorderSize() ;
3235 }
3236
3237 long wxWindowMac::MacRemoveBordersFromStyle( long style )
3238 {
3239 return style & ~wxBORDER_MASK ;
3240 }
3241
3242 // Find the wxWindowMac at the current mouse position, returning the mouse
3243 // position.
3244 wxWindowMac * wxFindWindowAtPointer( wxPoint& pt )
3245 {
3246 pt = wxGetMousePosition();
3247 wxWindowMac* found = wxFindWindowAtPoint(pt);
3248
3249 return found;
3250 }
3251
3252 // Get the current mouse position.
3253 wxPoint wxGetMousePosition()
3254 {
3255 int x, y;
3256
3257 wxGetMousePosition( &x, &y );
3258
3259 return wxPoint(x, y);
3260 }
3261
3262 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
3263 {
3264 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
3265 {
3266 // copied from wxGTK : CS
3267 // VZ: shouldn't we move this to base class then?
3268
3269 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3270 // except that:
3271 //
3272 // (a) it's a command event and so is propagated to the parent
3273 // (b) under MSW it can be generated from kbd too
3274 // (c) it uses screen coords (because of (a))
3275 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
3276 this->GetId(),
3277 this->ClientToScreen(event.GetPosition()));
3278 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
3279 event.Skip() ;
3280 }
3281 else
3282 {
3283 event.Skip() ;
3284 }
3285 }
3286
3287 void wxWindowMac::OnPaint( wxPaintEvent & event )
3288 {
3289 if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
3290 CallNextEventHandler(
3291 (EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() ,
3292 (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
3293 }
3294
3295 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
3296 {
3297 }
3298
3299 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
3300 {
3301 int x, y, w, h ;
3302
3303 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
3304 Rect bounds = { y, x, y + h, x + w };
3305
3306 return bounds ;
3307 }
3308
3309 wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
3310 {
3311 return eventNotHandledErr ;
3312 }
3313
3314 bool wxWindowMac::Reparent(wxWindowBase *newParentBase)
3315 {
3316 wxWindowMac *newParent = (wxWindowMac *)newParentBase;
3317 if ( !wxWindowBase::Reparent(newParent) )
3318 return false;
3319
3320 // copied from MacPostControlCreate
3321 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
3322
3323 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
3324
3325 ::EmbedControl( m_peer->GetControlRef() , container ) ;
3326
3327 return true;
3328 }