1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/window.cpp 
   3 // Purpose:     wxWindowMac 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  15 #include "wx/window.h" 
  17 #include "wx/dcclient.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" 
  29 #include "wx/tooltip.h" 
  30 #include "wx/statusbr.h" 
  31 #include "wx/menuitem.h" 
  32 #include "wx/spinctrl.h" 
  34 #include "wx/geometry.h" 
  35 #include "wx/textctrl.h" 
  37 #include "wx/toolbar.h" 
  44 #define MAC_SCROLLBAR_SIZE 15 
  45 #define MAC_SMALL_SCROLLBAR_SIZE 11 
  47 #include "wx/mac/uma.h" 
  51 #include <ToolUtils.h> 
  53 #include <MacTextEditor.h> 
  56 #if TARGET_API_MAC_OSX 
  58     #include <HIToolbox/HIView.h> 
  62 #if  wxUSE_DRAG_AND_DROP 
  68 extern wxList wxPendingDelete
; 
  70 #ifdef __WXUNIVERSAL__ 
  71     IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
) 
  73     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
) 
  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
) 
  82     EVT_SET_FOCUS(wxWindowMac::OnSetFocus
) 
  83     EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
) 
  84     EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
) 
  87 #define wxMAC_DEBUG_REDRAW 0 
  88 #ifndef wxMAC_DEBUG_REDRAW 
  89 #define wxMAC_DEBUG_REDRAW 0 
  92 #define wxMAC_USE_THEME_BORDER 1 
  94 // --------------------------------------------------------------------------- 
  95 // Utility Routines to move between different coordinate systems 
  96 // --------------------------------------------------------------------------- 
  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) 
 113 // originating from native control 
 117 void wxMacNativeToWindow( const wxWindow
* window 
, RgnHandle handle 
) 
 119     OffsetRgn( handle 
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ; 
 122 void wxMacNativeToWindow( const wxWindow
* window 
, Rect 
*rect 
) 
 124     OffsetRect( rect 
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ; 
 128 // directed towards native control 
 131 void wxMacWindowToNative( const wxWindow
* window 
, RgnHandle handle 
) 
 133     OffsetRgn( handle 
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ); 
 136 void wxMacWindowToNative( const wxWindow
* window 
, Rect 
*rect 
) 
 138     OffsetRect( rect 
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ; 
 141 // --------------------------------------------------------------------------- 
 143 // --------------------------------------------------------------------------- 
 145 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ; 
 146 pascal OSStatus 
wxMacSetupControlBackground( ControlRef iControl 
, SInt16 iMessage 
, SInt16 iDepth 
, Boolean iIsColor 
) ; 
 148 #if TARGET_API_MAC_OSX 
 150 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3 
 153     kEventControlVisibilityChanged 
= 157 
 159 static const EventTypeSpec eventList
[] = 
 161     { kEventClassControl 
, kEventControlHit 
} , 
 163 #if TARGET_API_MAC_OSX 
 164     { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent 
} , 
 165     { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea 
} , 
 167     { kEventClassControl 
, kEventControlDraw 
} , 
 168     { kEventClassControl 
, kEventControlVisibilityChanged 
} , 
 169     { kEventClassControl 
, kEventControlEnabledStateChanged 
} , 
 170     { kEventClassControl 
, kEventControlHiliteChanged 
} , 
 171     { kEventClassControl 
, kEventControlSetFocusPart 
} , 
 173     { kEventClassService 
, kEventServiceGetTypes 
}, 
 174     { kEventClassService 
, kEventServiceCopy 
}, 
 175     { kEventClassService 
, kEventServicePaste 
}, 
 177 //    { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only 
 178 //    { kEventClassControl , kEventControlBoundsChanged } , 
 182 static pascal OSStatus 
wxMacWindowControlEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 184     OSStatus result 
= eventNotHandledErr 
; 
 186     wxMacCarbonEvent 
cEvent( event 
) ; 
 188     ControlRef controlRef 
; 
 189     wxWindowMac
* thisWindow 
= (wxWindowMac
*) data 
; 
 191     cEvent
.GetParameter( kEventParamDirectObject 
, &controlRef 
) ; 
 193     switch ( GetEventKind( event 
) ) 
 195 #if TARGET_API_MAC_OSX 
 196         case kEventControlDraw 
: 
 198                 RgnHandle updateRgn 
= NULL 
; 
 199                 RgnHandle allocatedRgn 
= NULL 
; 
 200                 wxRegion visRegion 
= thisWindow
->MacGetVisibleRegion() ; 
 203                 if ( ! thisWindow
->GetPeer()->IsCompositing() ) 
 205                     if ( thisWindow
->GetPeer()->IsRootControl() ) 
 206                         thisWindow
->GetPeer()->GetRect( &controlBounds 
) ; 
 208                         GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds 
) ; 
 211                 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr 
) 
 213                     updateRgn 
= (RgnHandle
) visRegion
.GetWXHRGN() ; 
 217                     if ( ! thisWindow
->GetPeer()->IsCompositing() ) 
 219                         allocatedRgn 
= NewRgn() ; 
 220                         CopyRgn( updateRgn 
, allocatedRgn 
) ; 
 221                         OffsetRgn( allocatedRgn 
, -controlBounds
.left 
, -controlBounds
.top 
) ; 
 223                         // hide the given region by the new region that must be shifted 
 224                         wxMacNativeToWindow( thisWindow 
, allocatedRgn 
) ; 
 225                         updateRgn 
= allocatedRgn 
; 
 229                         if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 ) 
 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 
) ; 
 235                             // hide the given region by the new region that must be shifted 
 236                             wxMacNativeToWindow( thisWindow 
, allocatedRgn 
) ; 
 237                             updateRgn 
= allocatedRgn 
; 
 243                 GetRegionBounds( updateRgn 
, &rgnBounds 
) ; 
 245 #if wxMAC_DEBUG_REDRAW 
 246                 if ( thisWindow
->MacIsUserPane() ) 
 248                     static float color 
= 0.5 ; 
 251                     CGContextRef cgContext 
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ; 
 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 
); 
 269 #if wxMAC_USE_CORE_GRAPHICS 
 270                     bool created 
= false ; 
 271                     CGContextRef cgContext 
= NULL 
; 
 272                     if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr 
) 
 274                         wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ; 
 276                         // this parameter is not provided on non-composited windows 
 279                         // rest of the code expects this to be already transformed and clipped for local 
 280                         CGrafPtr port 
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ; 
 282                         GetPortBounds( port 
, &bounds 
) ; 
 283                         CreateCGContextForPort( port 
, &cgContext 
) ; 
 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 
) ; 
 291                         CGContextTranslateCTM( cgContext 
, 0 , bounds
.bottom 
- bounds
.top 
) ; 
 292                         CGContextScaleCTM( cgContext 
, 1 , -1 ) ; 
 294                         CGContextTranslateCTM( cgContext 
, controlBounds
.left 
, controlBounds
.top 
) ; 
 297                         CGContextSetRGBFillColor( cgContext 
, 1.0 , 1.0 , 1.0 , 1.0 ) ; 
 298                         CGContextFillRect( cgContext 
, 
 300                                 controlBounds
.right 
- controlBounds
.left 
, 
 301                                 controlBounds
.bottom 
- controlBounds
.top 
) ); 
 305                     thisWindow
->MacSetCGContextRef( cgContext 
) ; 
 308                         wxMacCGContextStateSaver 
sg( cgContext 
) ; 
 310                         if ( thisWindow
->MacDoRedraw( updateRgn 
, cEvent
.GetTicks() ) ) 
 313 #if wxMAC_USE_CORE_GRAPHICS 
 314                         thisWindow
->MacSetCGContextRef( NULL 
) ; 
 318                         CGContextRelease( cgContext 
) ; 
 323                     DisposeRgn( allocatedRgn 
) ; 
 327         case kEventControlVisibilityChanged 
: 
 328             thisWindow
->MacVisibilityChanged() ; 
 331         case kEventControlEnabledStateChanged 
: 
 332             thisWindow
->MacEnabledStateChanged() ; 
 335         case kEventControlHiliteChanged 
: 
 336             thisWindow
->MacHiliteChanged() ; 
 340         // we emulate this event under Carbon CFM 
 341         case kEventControlSetFocusPart 
: 
 343                 Boolean focusEverything 
= false ; 
 344                 ControlPartCode controlPart 
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart 
, typeControlPartCode 
); 
 347                 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything 
, &focusEverything 
) == noErr 
) 
 352                 if ( controlPart 
== kControlFocusNoPart 
) 
 355                     if ( thisWindow
->GetCaret() ) 
 356                         thisWindow
->GetCaret()->OnKillFocus(); 
 359                     static bool inKillFocusEvent 
= false ; 
 361                     if ( !inKillFocusEvent 
) 
 363                         inKillFocusEvent 
= true ; 
 364                         wxFocusEvent 
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId()); 
 365                         event
.SetEventObject(thisWindow
); 
 366                         thisWindow
->GetEventHandler()->ProcessEvent(event
) ; 
 367                         inKillFocusEvent 
= false ; 
 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
); 
 377                     if ( thisWindow
->GetCaret() ) 
 378                         thisWindow
->GetCaret()->OnSetFocus(); 
 381                     wxFocusEvent 
event(wxEVT_SET_FOCUS
, thisWindow
->GetId()); 
 382                     event
.SetEventObject(thisWindow
); 
 383                     thisWindow
->GetEventHandler()->ProcessEvent(event
) ; 
 386                 if ( thisWindow
->MacIsUserPane() ) 
 391         case kEventControlHit 
: 
 392             result 
= thisWindow
->MacControlHit( handler 
, event 
) ; 
 402 static pascal OSStatus 
wxMacWindowServiceEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 404     OSStatus result 
= eventNotHandledErr 
; 
 406     wxMacCarbonEvent 
cEvent( event 
) ; 
 408     ControlRef controlRef 
; 
 409     wxWindowMac
* thisWindow 
= (wxWindowMac
*) data 
; 
 410     wxTextCtrl
* textCtrl 
= wxDynamicCast( thisWindow 
, wxTextCtrl 
) ; 
 411     cEvent
.GetParameter( kEventParamDirectObject 
, &controlRef 
) ; 
 413     switch ( GetEventKind( event 
) ) 
 415         case kEventServiceGetTypes 
: 
 419                 textCtrl
->GetSelection( &from 
, &to 
) ; 
 421                 CFMutableArrayRef copyTypes 
= 0 , pasteTypes 
= 0; 
 423                     copyTypes 
= cEvent
.GetParameter
< CFMutableArrayRef 
>( kEventParamServiceCopyTypes 
, typeCFMutableArrayRef 
) ; 
 424                 if ( textCtrl
->IsEditable() ) 
 425                     pasteTypes 
= cEvent
.GetParameter
< CFMutableArrayRef 
>( kEventParamServicePasteTypes 
, typeCFMutableArrayRef 
) ; 
 427                 static const OSType textDataTypes
[] = { kTXNTextData 
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */  }; 
 428                 for ( size_t i 
= 0 ; i 
< WXSIZEOF(textDataTypes
) ; ++i 
) 
 430                     CFStringRef typestring 
= CreateTypeStringWithOSType(textDataTypes
[i
]); 
 434                             CFArrayAppendValue(copyTypes
, typestring
) ; 
 436                             CFArrayAppendValue(pasteTypes
, typestring
) ; 
 438                         CFRelease( typestring 
) ; 
 446         case kEventServiceCopy 
: 
 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() ) ) ; 
 461         case kEventServicePaste 
: 
 464                 ScrapRef scrapRef 
= cEvent
.GetParameter
< ScrapRef 
> ( kEventParamScrapRef 
, typeScrapRef 
) ; 
 465                 Size textSize
, pastedSize 
; 
 466                 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ; 
 468                 char *content 
= new char[textSize
] ; 
 469                 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content 
); 
 470                 content
[textSize 
- 1] = 0 ; 
 473                 textCtrl
->WriteText( wxString( content 
, wxConvLocal 
) ); 
 475                 textCtrl
->WriteText( wxString( content 
) ) ; 
 490 pascal OSStatus 
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 492     OSStatus result 
= eventNotHandledErr 
; 
 493     wxWindowMac
* focus 
= (wxWindowMac
*) data 
; 
 495     wchar_t* uniChars 
= NULL 
; 
 496     UInt32 when 
= EventTimeToTicks( GetEventTime( event 
) ) ; 
 499     UInt32 dataSize 
= 0 ; 
 502     if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL 
) == noErr 
) 
 504         numChars 
= dataSize 
/ sizeof( UniChar
) ; 
 507         if ( dataSize 
> sizeof(buf
) ) 
 508             charBuf 
= new UniChar
[ numChars 
] ; 
 512         uniChars 
= new wchar_t[ numChars 
] ; 
 513         GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize 
, NULL 
, charBuf 
) ; 
 514 #if SIZEOF_WCHAR_T == 2 
 516         memcpy( uniChars 
, charBuf 
, dataSize 
) ; 
 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 
) ; 
 524     switch ( GetEventKind( event 
) ) 
 526         case kEventTextInputUpdateActiveInputArea 
: 
 528                 // An IME input event may return several characters, but we need to send one char at a time to 
 530                 for (int pos
=0 ; pos 
< numChars 
; pos
++) 
 533                     WXEVENTREF formerEvent 
= wxTheApp
->MacGetCurrentEvent() ; 
 534                     WXEVENTHANDLERCALLREF formerHandler 
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ; 
 535                     wxTheApp
->MacSetCurrentEvent( event 
, handler 
) ; 
 537                     UInt32 message 
= (0  << 8) + ((char)uniChars
[pos
] ); 
 538                     if ( wxTheApp
->MacSendCharEvent( 
 539                                                     focus 
, message 
, 0 , when 
, 0 , 0 , uniChars
[pos
] ) ) 
 544                     wxTheApp
->MacSetCurrentEvent( formerEvent 
, formerHandler 
) ; 
 548         case kEventTextInputUnicodeForKeyEvent 
: 
 550                 UInt32 keyCode
, modifiers 
; 
 553                 unsigned char charCode 
; 
 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 
); 
 561                 UInt32 message 
= (keyCode 
<< 8) + charCode
; 
 562                 // this is only called when no default handler has jumped in, e.g. a wxControl on a floater window does not 
 563                 // get its own kEventTextInputUnicodeForKeyEvent, so we reroute the event back to the control 
 565                 // NOTE to Stefan: Is this still needed? Shouldn't we be calling SendToEventTarget rather than 
 566                 // HandleControlKey? (which, IIRC, is not Unicode friendly?) TODO :: MEMORY LEAK IN uniChar etc. 
 568                 wxControl* control = wxDynamicCast( focus , wxControl ) ; 
 571                     ControlRef macControl = (ControlRef) control->GetHandle() ; 
 574                         ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; 
 580                 // An IME input event may return several characters, but we need to send one char at a time to 
 582                 for (int pos
=0 ; pos 
< numChars 
; pos
++) 
 585                     WXEVENTREF formerEvent 
= wxTheApp
->MacGetCurrentEvent() ; 
 586                     WXEVENTHANDLERCALLREF formerHandler 
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ; 
 587                     wxTheApp
->MacSetCurrentEvent( event 
, handler 
) ; 
 589                     if ( wxTheApp
->MacSendCharEvent( 
 590                         focus 
, message 
, modifiers 
, when 
, point
.h 
, point
.v 
, uniChars
[pos
] ) ) 
 595                     wxTheApp
->MacSetCurrentEvent( formerEvent 
, formerHandler 
) ; 
 604     if ( charBuf 
!= buf 
) 
 611 pascal OSStatus 
wxMacWindowEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 613     EventRef formerEvent 
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ; 
 614     EventHandlerCallRef formerEventHandlerCallRef 
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ; 
 615     wxTheApp
->MacSetCurrentEvent( event 
, handler 
) ; 
 616     OSStatus result 
= eventNotHandledErr 
; 
 618     switch ( GetEventClass( event 
) ) 
 620         case kEventClassControl 
: 
 621             result 
= wxMacWindowControlEventHandler( handler
, event
, data 
) ; 
 624         case kEventClassService 
: 
 625             result 
= wxMacWindowServiceEventHandler( handler
, event 
, data 
) ; 
 628         case kEventClassTextInput 
: 
 629             result 
= wxMacUnicodeTextEventHandler( handler 
, event 
, data 
) ; 
 635     wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef 
) ; 
 640 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler 
) 
 642 #if !TARGET_API_MAC_OSX 
 644 // --------------------------------------------------------------------------- 
 645 // UserPane events for non OSX builds 
 646 // --------------------------------------------------------------------------- 
 648 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
) 
 650     wxWindow 
* win 
= wxFindControlFromMacControl(control
) ; 
 652         win
->MacControlUserPaneDrawProc(part
) ; 
 654 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP 
, wxMacControlUserPaneDrawProc 
) ; 
 656 static pascal ControlPartCode 
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
) 
 658     wxWindow 
* win 
= wxFindControlFromMacControl(control
) ; 
 660         return win
->MacControlUserPaneHitTestProc(where
.h 
, where
.v
) ; 
 662         return kControlNoPart 
; 
 664 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP 
, wxMacControlUserPaneHitTestProc 
) ; 
 666 static pascal ControlPartCode 
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
) 
 668     wxWindow 
* win 
= wxFindControlFromMacControl(control
) ; 
 670         return win
->MacControlUserPaneTrackingProc( startPt
.h 
, startPt
.v 
, (void*) actionProc
) ; 
 672         return kControlNoPart 
; 
 674 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP 
, wxMacControlUserPaneTrackingProc 
) ; 
 676 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
) 
 678     wxWindow 
* win 
= wxFindControlFromMacControl(control
) ; 
 680         win
->MacControlUserPaneIdleProc() ; 
 682 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP 
, wxMacControlUserPaneIdleProc 
) ; 
 684 static pascal ControlPartCode 
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) 
 686     wxWindow 
* win 
= wxFindControlFromMacControl(control
) ; 
 688         return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ; 
 690         return kControlNoPart 
; 
 692 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP 
, wxMacControlUserPaneKeyDownProc 
) ; 
 694 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
) 
 696     wxWindow 
* win 
= wxFindControlFromMacControl(control
) ; 
 698         win
->MacControlUserPaneActivateProc(activating
) ; 
 700 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP 
, wxMacControlUserPaneActivateProc 
) ; 
 702 static pascal ControlPartCode 
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
) 
 704     wxWindow 
* win 
= wxFindControlFromMacControl(control
) ; 
 706         return win
->MacControlUserPaneFocusProc(action
) ; 
 708         return kControlNoPart 
; 
 710 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP 
, wxMacControlUserPaneFocusProc 
) ; 
 712 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
) 
 714     wxWindow 
* win 
= wxFindControlFromMacControl(control
) ; 
 716         win
->MacControlUserPaneBackgroundProc(info
) ; 
 718 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP 
, wxMacControlUserPaneBackgroundProc 
) ; 
 720 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
) 
 723     RgnHandle rgn 
= NewRgn() ; 
 725     MacWindowToRootWindow( &x
, &y 
) ; 
 726     OffsetRgn( rgn 
, -x 
, -y 
) ; 
 727     wxMacWindowStateSaver 
sv( this ) ; 
 728     SectRgn( rgn 
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn 
) ; 
 729     MacDoRedraw( rgn 
, 0 ) ; 
 733 wxInt16 
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) 
 735     return kControlNoPart 
; 
 738 wxInt16 
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) 
 740     return kControlNoPart 
; 
 743 void wxWindowMac::MacControlUserPaneIdleProc() 
 747 wxInt16 
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) 
 749     return kControlNoPart 
; 
 752 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
) 
 756 wxInt16 
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
) 
 758     if ( AcceptsFocus() ) 
 761         return kControlNoPart 
; 
 764 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
) 
 770 // --------------------------------------------------------------------------- 
 771 // Scrollbar Tracking for all 
 772 // --------------------------------------------------------------------------- 
 774 pascal void wxMacLiveScrollbarActionProc( ControlRef control 
, ControlPartCode partCode 
) ; 
 775 pascal void wxMacLiveScrollbarActionProc( ControlRef control 
, ControlPartCode partCode 
) 
 779         wxWindow
*  wx 
= wxFindControlFromMacControl( control 
) ; 
 781             wx
->MacHandleControlClick( (WXWidget
) control 
, partCode 
, true /* stillDown */ ) ; 
 784 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP 
, wxMacLiveScrollbarActionProc 
) ; 
 786 // =========================================================================== 
 788 // =========================================================================== 
 790 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
); 
 792 static MacControlMap wxWinMacControlList
; 
 794 wxWindow 
*wxFindControlFromMacControl(ControlRef inControl 
) 
 796     MacControlMap::iterator node 
= wxWinMacControlList
.find(inControl
); 
 798     return (node 
== wxWinMacControlList
.end()) ? NULL 
: node
->second
; 
 801 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow 
*control
) 
 803     // adding NULL ControlRef is (first) surely a result of an error and 
 804     // (secondly) breaks native event processing 
 805     wxCHECK_RET( inControl 
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") ); 
 807     wxWinMacControlList
[inControl
] = control
; 
 810 void wxRemoveMacControlAssociation(wxWindow 
*control
) 
 812    // iterate over all the elements in the class 
 813     // is the iterator stable ? as we might have two associations pointing to the same wxWindow 
 814     // we should go on... 
 820         MacControlMap::iterator it
; 
 821         for ( it 
= wxWinMacControlList
.begin(); it 
!= wxWinMacControlList
.end(); ++it 
) 
 823             if ( it
->second 
== control 
) 
 825                 wxWinMacControlList
.erase(it
); 
 833 // ---------------------------------------------------------------------------- 
 834  // constructors and such 
 835 // ---------------------------------------------------------------------------- 
 837 wxWindowMac::wxWindowMac() 
 842 wxWindowMac::wxWindowMac(wxWindowMac 
*parent
, 
 847             const wxString
& name 
) 
 850     Create(parent
, id
, pos
, size
, style
, name
); 
 853 void wxWindowMac::Init() 
 858 #if WXWIN_COMPATIBILITY_2_4 
 859     m_backgroundTransparent 
= false; 
 862 #if wxMAC_USE_CORE_GRAPHICS 
 863     m_cgContextRef 
= NULL 
; 
 866     // as all windows are created with WS_VISIBLE style... 
 869     m_hScrollBar 
= NULL 
; 
 870     m_vScrollBar 
= NULL 
; 
 871     m_macBackgroundBrush 
= wxNullBrush 
; 
 873     m_macIsUserPane 
= true; 
 874     m_clipChildren 
= false ; 
 875     m_cachedClippedRectValid 
= false ; 
 877     // we need a valid font for the encodings 
 878     wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
)); 
 882 wxWindowMac::~wxWindowMac() 
 886     m_isBeingDeleted 
= true; 
 888     MacInvalidateBorders() ; 
 890 #ifndef __WXUNIVERSAL__ 
 891     // VS: make sure there's no wxFrame with last focus set to us: 
 892     for ( wxWindow 
*win 
= GetParent(); win
; win 
= win
->GetParent() ) 
 894         wxFrame 
*frame 
= wxDynamicCast(win
, wxFrame
); 
 897             if ( frame
->GetLastFocus() == this ) 
 898                 frame
->SetLastFocus((wxWindow
*)NULL
); 
 902 #endif // __WXUNIVERSAL__ 
 904     // destroy children before destroying this window itself 
 907     // wxRemoveMacControlAssociation( this ) ; 
 908     // If we delete an item, we should initialize the parent panel, 
 909     // because it could now be invalid. 
 910     wxWindow 
*parent 
= GetParent() ; 
 913         if (parent
->GetDefaultItem() == (wxButton
*) this) 
 914             parent
->SetDefaultItem(NULL
); 
 917     if ( m_peer 
&& m_peer
->Ok() ) 
 919         // in case the callback might be called during destruction 
 920         wxRemoveMacControlAssociation( this) ; 
 921         ::RemoveEventHandler( (EventHandlerRef 
) m_macControlEventHandler 
) ; 
 922         // we currently are not using this hook 
 923         // ::SetControlColorProc( *m_peer , NULL ) ; 
 927     if ( g_MacLastWindow 
== this ) 
 928         g_MacLastWindow 
= NULL 
; 
 930     wxFrame
* frame 
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame 
) ; 
 933         if ( frame
->GetLastFocus() == this ) 
 934             frame
->SetLastFocus( NULL 
) ; 
 937     // delete our drop target if we've got one 
 938 #if wxUSE_DRAG_AND_DROP 
 939     if ( m_dropTarget 
!= NULL 
) 
 949 WXWidget 
wxWindowMac::GetHandle() const 
 951     return (WXWidget
) m_peer
->GetControlRef() ; 
 954 void wxWindowMac::MacInstallEventHandler( WXWidget control 
) 
 956     wxAssociateControlWithMacControl( (ControlRef
) control 
, this ) ; 
 957     InstallControlEventHandler( (ControlRef
)control 
, GetwxMacWindowEventHandlerUPP(), 
 958         GetEventTypeCount(eventList
), eventList
, this, 
 959         (EventHandlerRef 
*)&m_macControlEventHandler
); 
 961 #if !TARGET_API_MAC_OSX 
 962     if ( (ControlRef
) control 
== m_peer
->GetControlRef() ) 
 964         m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ; 
 965         m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ; 
 966         m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ; 
 967         m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ; 
 968         m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ; 
 969         m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ; 
 970         m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ; 
 971         m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ; 
 977 bool wxWindowMac::Create(wxWindowMac 
*parent
, 
 982     const wxString
& name
) 
 984     wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") ); 
 986     if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) ) 
 989     m_windowVariant 
= parent
->GetWindowVariant() ; 
 991     if ( m_macIsUserPane 
) 
 993         Rect bounds 
= wxMacGetBoundsForControl( this , pos 
, size 
) ; 
 996             | kControlSupportsEmbedding
 
 997             | kControlSupportsLiveFeedback
 
 998             | kControlGetsFocusOnClick
 
 999 //            | kControlHasSpecialBackground 
1000 //            | kControlSupportsCalcBestRect 
1001             | kControlHandlesTracking
 
1002             | kControlSupportsFocus
 
1003             | kControlWantsActivate
 
1004             | kControlWantsIdle 
; 
1006         m_peer 
= new wxMacControl(this) ; 
1007         OSStatus err 
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features 
, m_peer
->GetControlRefAddr() ); 
1008         verify_noerr( err 
); 
1010         MacPostControlCreate(pos
, size
) ; 
1013 #ifndef __WXUNIVERSAL__ 
1014     // Don't give scrollbars to wxControls unless they ask for them 
1015     if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) 
1016          || (IsKindOf(CLASSINFO(wxControl
)) && ((style 
& wxHSCROLL
) || (style 
& wxVSCROLL
)))) 
1018         MacCreateScrollBars( style 
) ; 
1022     wxWindowCreateEvent 
event(this); 
1023     GetEventHandler()->AddPendingEvent(event
); 
1028 void wxWindowMac::MacChildAdded() 
1031         m_vScrollBar
->Raise() ; 
1033         m_hScrollBar
->Raise() ; 
1036 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) 
1038     wxASSERT_MSG( m_peer 
!= NULL 
&& m_peer
->Ok() , wxT("No valid mac control") ) ; 
1040     m_peer
->SetReference( (long)this ) ; 
1041     GetParent()->AddChild( this ); 
1043     MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ); 
1045     ControlRef container 
= (ControlRef
) GetParent()->GetHandle() ; 
1046     wxASSERT_MSG( container 
!= NULL 
, wxT("No valid mac container control") ) ; 
1047     ::EmbedControl( m_peer
->GetControlRef() , container 
) ; 
1048     GetParent()->MacChildAdded() ; 
1050     // adjust font, controlsize etc 
1051     DoSetWindowVariant( m_windowVariant 
) ; 
1053     m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ; 
1055     if (!m_macIsUserPane
) 
1056         SetInitialBestSize(size
); 
1058     SetCursor( *wxSTANDARD_CURSOR 
) ; 
1061 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant 
) 
1063     // Don't assert, in case we set the window variant before 
1064     // the window is created 
1065     // wxASSERT( m_peer->Ok() ) ; 
1067     m_windowVariant 
= variant 
; 
1069     if (m_peer 
== NULL 
|| !m_peer
->Ok()) 
1073     ThemeFontID themeFont 
= kThemeSystemFont 
; 
1075     // we will get that from the settings later 
1076     // and make this NORMAL later, but first 
1077     // we have a few calculations that we must fix 
1081         case wxWINDOW_VARIANT_NORMAL 
: 
1082             size 
= kControlSizeNormal
; 
1083             themeFont 
= kThemeSystemFont 
; 
1086         case wxWINDOW_VARIANT_SMALL 
: 
1087             size 
= kControlSizeSmall
; 
1088             themeFont 
= kThemeSmallSystemFont 
; 
1091         case wxWINDOW_VARIANT_MINI 
: 
1092            if (UMAGetSystemVersion() >= 0x1030 ) 
1094                 // not always defined in the headers 
1100                 size 
= kControlSizeSmall
; 
1101                 themeFont 
= kThemeSmallSystemFont 
; 
1105         case wxWINDOW_VARIANT_LARGE 
: 
1106             size 
= kControlSizeLarge
; 
1107             themeFont 
= kThemeSystemFont 
; 
1111             wxFAIL_MSG(_T("unexpected window variant")); 
1115     m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size 
) ; 
1118     font
.MacCreateThemeFont( themeFont 
) ; 
1122 void wxWindowMac::MacUpdateControlFont() 
1124     m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; 
1128 bool wxWindowMac::SetFont(const wxFont
& font
) 
1130     bool retval 
= wxWindowBase::SetFont( font 
); 
1132     MacUpdateControlFont() ; 
1137 bool wxWindowMac::SetForegroundColour(const wxColour
& col 
) 
1139     bool retval 
= wxWindowBase::SetForegroundColour( col 
); 
1142         MacUpdateControlFont(); 
1147 bool wxWindowMac::SetBackgroundColour(const wxColour
& col 
) 
1149     if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol 
) 
1153     wxColour 
newCol(GetBackgroundColour()); 
1155     if ( newCol 
== wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE 
) ) 
1156         brush
.MacSetTheme( kThemeBrushDocumentWindowBackground 
) ; 
1157     else if ( newCol 
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE 
) ) 
1158         brush
.MacSetTheme( kThemeBrushDialogBackgroundActive 
) ; 
1160         brush
.SetColour( newCol 
) ; 
1162     MacSetBackgroundBrush( brush 
) ; 
1163     MacUpdateControlFont() ; 
1168 void wxWindowMac::MacSetBackgroundBrush( const wxBrush 
&brush 
) 
1170     m_macBackgroundBrush 
= brush 
; 
1171     m_peer
->SetBackground( brush 
) ; 
1174 bool wxWindowMac::MacCanFocus() const 
1176     // there is currently no way to determine whether the window is running in full keyboard 
1177     // access mode, therefore we cannot rely on these features, yet the only other way would be 
1178     // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems 
1179     // in event handlers... 
1180     UInt32 features 
= 0 ; 
1181     m_peer
->GetFeatures( &features 
) ; 
1183     return features 
& ( kControlSupportsFocus 
| kControlGetsFocusOnClick 
) ; 
1186 void wxWindowMac::SetFocus() 
1188     if ( !AcceptsFocus() ) 
1191     wxWindow
* former 
= FindFocus() ; 
1192     if ( former 
== this ) 
1195     // as we cannot rely on the control features to find out whether we are in full keyboard mode, 
1196     // we can only leave in case of an error 
1197     OSStatus err 
= m_peer
->SetFocus( kControlFocusNextPart 
) ; 
1198     if ( err 
== errCouldntSetFocus 
) 
1201     SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() ); 
1203 #if !TARGET_API_MAC_OSX 
1204     // emulate carbon events when running under CarbonLib where they are not natively available 
1207         EventRef evRef 
= NULL 
; 
1209         err 
= MacCreateEvent( 
1210             NULL 
, kEventClassControl 
, kEventControlSetFocusPart 
, TicksToEventTime( TickCount() ) , 
1211             kEventAttributeUserEvent 
, &evRef 
); 
1212         verify_noerr( err 
); 
1214         wxMacCarbonEvent 
cEvent( evRef 
) ; 
1215         cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject 
, (ControlRef
) former
->GetHandle() ) ; 
1216         cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart 
, typeControlPartCode 
, kControlFocusNoPart 
) ; 
1218         wxMacWindowEventHandler( NULL 
, evRef 
, former 
) ; 
1219         ReleaseEvent( evRef 
) ; 
1222     // send new focus event 
1224         EventRef evRef 
= NULL 
; 
1226         err 
= MacCreateEvent( 
1227             NULL 
, kEventClassControl 
, kEventControlSetFocusPart 
, TicksToEventTime( TickCount() ) , 
1228             kEventAttributeUserEvent 
, &evRef 
); 
1229         verify_noerr( err 
); 
1231         wxMacCarbonEvent 
cEvent( evRef 
) ; 
1232         cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject 
, (ControlRef
) GetHandle() ) ; 
1233         cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart 
, typeControlPartCode 
, kControlFocusNextPart 
) ; 
1235         wxMacWindowEventHandler( NULL 
, evRef 
, this ) ; 
1236         ReleaseEvent( evRef 
) ; 
1241 void wxWindowMac::DoCaptureMouse() 
1243     wxApp::s_captureWindow 
= this ; 
1246 wxWindow
* wxWindowBase::GetCapture() 
1248     return wxApp::s_captureWindow 
; 
1251 void wxWindowMac::DoReleaseMouse() 
1253     wxApp::s_captureWindow 
= NULL 
; 
1256 #if wxUSE_DRAG_AND_DROP 
1258 void wxWindowMac::SetDropTarget(wxDropTarget 
*pDropTarget
) 
1260     if ( m_dropTarget 
!= NULL 
) 
1261         delete m_dropTarget
; 
1263     m_dropTarget 
= pDropTarget
; 
1264     if ( m_dropTarget 
!= NULL 
) 
1272 // Old style file-manager drag&drop 
1273 void wxWindowMac::DragAcceptFiles(bool accept
) 
1278 // Returns the size of the native control. In the case of the toplevel window 
1279 // this is the content area root control 
1281 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
, 
1282                                            int& w
, int& h
) const 
1284     wxFAIL_MSG( wxT("Not currently supported") ) ; 
1287 // From a wx position / size calculate the appropriate size of the native control 
1289 bool wxWindowMac::MacGetBoundsForControl( 
1293     int& w
, int& h 
, bool adjustOrigin 
) const 
1295     bool isCompositing 
= MacGetTopLevelWindow()->MacUsesCompositing() ; 
1297     // the desired size, minus the border pixels gives the correct size of the control 
1302     // TODO: the default calls may be used as soon as PostCreateControl Is moved here 
1303     w 
= wxMax(size
.x
, 0) ; // WidthDefault( size.x ); 
1304     h 
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ; 
1306     if ( !isCompositing 
) 
1307         GetParent()->MacWindowToRootWindow( &x 
, &y 
) ; 
1309     x 
+= MacGetLeftBorderSize() ; 
1310     y 
+= MacGetTopBorderSize() ; 
1311     w 
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ; 
1312     h 
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ; 
1315         AdjustForParentClientOrigin( x 
, y 
) ; 
1317     // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border 
1318     if ( !GetParent()->IsTopLevel() ) 
1320         x 
-= GetParent()->MacGetLeftBorderSize() ; 
1321         y 
-= GetParent()->MacGetTopBorderSize() ; 
1327 // Get window size (not client size) 
1328 void wxWindowMac::DoGetSize(int *x
, int *y
) const 
1331     m_peer
->GetRect( &bounds 
) ; 
1334        *x 
= bounds
.right 
- bounds
.left 
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ; 
1336        *y 
= bounds
.bottom 
- bounds
.top 
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ; 
1339 // get the position of the bounds of this window in client coordinates of its parent 
1340 void wxWindowMac::DoGetPosition(int *x
, int *y
) const 
1343     m_peer
->GetRect( &bounds 
) ; 
1345     int x1 
= bounds
.left 
; 
1346     int y1 
= bounds
.top 
; 
1348     // get the wx window position from the native one 
1349     x1 
-= MacGetLeftBorderSize() ; 
1350     y1 
-= MacGetTopBorderSize() ; 
1352     if ( !IsTopLevel() ) 
1354         wxWindow 
*parent 
= GetParent(); 
1357             // we must first adjust it to be in window coordinates of the parent, 
1358             // as otherwise it gets lost by the ClientAreaOrigin fix 
1359             x1 
+= parent
->MacGetLeftBorderSize() ; 
1360             y1 
+= parent
->MacGetTopBorderSize() ; 
1362             // and now to client coordinates 
1363             wxPoint 
pt(parent
->GetClientAreaOrigin()); 
1375 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const 
1377     WindowRef window 
= (WindowRef
) MacGetTopLevelWindowRef() ; 
1378     wxCHECK_RET( window 
, wxT("TopLevel Window missing") ) ; 
1380     Point localwhere 
= { 0, 0 } ; 
1387     QDGlobalToLocalPoint( GetWindowPort( window 
) , &localwhere 
) ; 
1394     MacRootWindowToWindow( x 
, y 
) ; 
1396     wxPoint origin 
= GetClientAreaOrigin() ; 
1403 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const 
1405     WindowRef window 
= (WindowRef
) MacGetTopLevelWindowRef() ; 
1406     wxCHECK_RET( window 
, wxT("TopLevel window missing") ) ; 
1408     wxPoint origin 
= GetClientAreaOrigin() ; 
1414     MacWindowToRootWindow( x 
, y 
) ; 
1416     Point localwhere 
= { 0, 0 }; 
1422     QDLocalToGlobalPoint( GetWindowPort( window 
) , &localwhere 
) ; 
1430 void wxWindowMac::MacClientToRootWindow( int *x 
, int *y 
) const 
1432     wxPoint origin 
= GetClientAreaOrigin() ; 
1438     MacWindowToRootWindow( x 
, y 
) ; 
1441 void wxWindowMac::MacRootWindowToClient( int *x 
, int *y 
) const 
1443     MacRootWindowToWindow( x 
, y 
) ; 
1445     wxPoint origin 
= GetClientAreaOrigin() ; 
1452 void wxWindowMac::MacWindowToRootWindow( int *x 
, int *y 
) const 
1461     if ( !IsTopLevel() ) 
1463         wxTopLevelWindowMac
* top 
= MacGetTopLevelWindow(); 
1466             pt
.x 
-= MacGetLeftBorderSize() ; 
1467             pt
.y 
-= MacGetTopBorderSize() ; 
1468             wxMacControl::Convert( &pt 
, m_peer 
, top
->m_peer 
) ; 
1478 void wxWindowMac::MacWindowToRootWindow( short *x 
, short *y 
) const 
1487     MacWindowToRootWindow( &x1 
, &y1 
) ; 
1495 void wxWindowMac::MacRootWindowToWindow( int *x 
, int *y 
) const 
1504     if ( !IsTopLevel() ) 
1506         wxTopLevelWindowMac
* top 
= MacGetTopLevelWindow(); 
1509             wxMacControl::Convert( &pt 
, top
->m_peer 
, m_peer 
) ; 
1510             pt
.x 
+= MacGetLeftBorderSize() ; 
1511             pt
.y 
+= MacGetTopBorderSize() ; 
1521 void wxWindowMac::MacRootWindowToWindow( short *x 
, short *y 
) const 
1530     MacRootWindowToWindow( &x1 
, &y1 
) ; 
1538 void wxWindowMac::MacGetContentAreaInset( int &left 
, int &top 
, int &right 
, int &bottom 
) 
1540     RgnHandle rgn 
= NewRgn() ; 
1542     if ( m_peer
->GetRegion( kControlContentMetaPart 
, rgn 
) == noErr 
) 
1544         Rect structure
, content 
; 
1546         GetRegionBounds( rgn 
, &content 
) ; 
1547         m_peer
->GetRect( &structure 
) ; 
1548         OffsetRect( &structure
, -structure
.left 
, -structure
.top 
) ; 
1550         left 
= content
.left 
- structure
.left 
; 
1551         top 
= content
.top 
- structure
.top 
; 
1552         right 
= structure
.right 
- content
.right 
; 
1553         bottom 
= structure
.bottom 
- content
.bottom 
; 
1557         left 
= top 
= right 
= bottom 
= 0 ; 
1563 wxSize 
wxWindowMac::DoGetSizeFromClientSize( const wxSize 
& size 
)  const 
1565     wxSize sizeTotal 
= size
; 
1567     RgnHandle rgn 
= NewRgn() ; 
1568     if ( m_peer
->GetRegion( kControlContentMetaPart 
, rgn 
) == noErr 
) 
1570         Rect content
, structure 
; 
1571         GetRegionBounds( rgn 
, &content 
) ; 
1572         m_peer
->GetRect( &structure 
) ; 
1574         // structure is in parent coordinates, but we only need width and height, so it's ok 
1576         sizeTotal
.x 
+= (structure
.right 
- structure
.left
) - (content
.right 
- content
.left
) ; 
1577         sizeTotal
.y 
+= (structure
.bottom 
- structure
.top
) - (content
.bottom 
- content
.top
) ; 
1582     sizeTotal
.x 
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ; 
1583     sizeTotal
.y 
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ; 
1588 // Get size *available for subwindows* i.e. excluding menu bar etc. 
1589 void wxWindowMac::DoGetClientSize( int *x
, int *y 
) const 
1593     RgnHandle rgn 
= NewRgn() ; 
1595     if ( m_peer
->GetRegion( kControlContentMetaPart 
, rgn 
) == noErr 
) 
1596         GetRegionBounds( rgn 
, &content 
) ; 
1598         m_peer
->GetRect( &content 
) ; 
1601     ww 
= content
.right 
- content
.left 
; 
1602     hh 
= content
.bottom 
- content
.top 
; 
1604     if (m_hScrollBar  
&& m_hScrollBar
->IsShown() ) 
1605         hh 
-= m_hScrollBar
->GetSize().y 
; 
1607     if (m_vScrollBar  
&& m_vScrollBar
->IsShown() ) 
1608         ww 
-= m_vScrollBar
->GetSize().x 
; 
1616 bool wxWindowMac::SetCursor(const wxCursor
& cursor
) 
1618     if (m_cursor 
== cursor
) 
1621     if (wxNullCursor 
== cursor
) 
1623         if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR 
) ) 
1628         if ( ! wxWindowBase::SetCursor( cursor 
) ) 
1632     wxASSERT_MSG( m_cursor
.Ok(), 
1633         wxT("cursor must be valid after call to the base version")); 
1635     wxWindowMac 
*mouseWin 
= 0 ; 
1637         wxTopLevelWindowMac 
*tlw 
= MacGetTopLevelWindow() ; 
1638         WindowRef window 
= (WindowRef
) ( tlw 
? tlw
->MacGetWindowRef() : 0 ) ; 
1640         Boolean swapped 
= QDSwapPort( GetWindowPort( window 
) , &savePort 
) ; 
1642         // TODO: If we ever get a GetCurrentEvent... replacement 
1643         // for the mouse position, use it... 
1646         ControlPartCode part 
; 
1647         ControlRef control 
; 
1650         control 
= wxMacFindControlUnderMouse( tlw 
, pt 
, window 
, &part 
) ; 
1652             mouseWin 
= wxFindControlFromMacControl( control 
) ; 
1655             QDSwapPort( savePort 
, NULL 
) ; 
1658     if ( mouseWin 
== this && !wxIsBusy() ) 
1659         m_cursor
.MacInstall() ; 
1665 bool wxWindowMac::DoPopupMenu(wxMenu 
*menu
, int x
, int y
) 
1667     menu
->SetInvokingWindow(this); 
1670     if ( x 
== -1 && y 
== -1 ) 
1672         wxPoint mouse 
= wxGetMousePosition(); 
1678         ClientToScreen( &x 
, &y 
) ; 
1681     menu
->MacBeforeDisplay( true ) ; 
1682     long menuResult 
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ; 
1683     if ( HiWord(menuResult
) != 0 ) 
1686         GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id 
) ; 
1687         wxMenuItem
* item 
= NULL 
; 
1689         item 
= menu
->FindItem( id
, &realmenu 
) ; 
1690         if (item
->IsCheckable()) 
1691             item
->Check( !item
->IsChecked() ) ; 
1693         menu
->SendEvent( id 
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ; 
1696     menu
->MacAfterDisplay( true ) ; 
1697     menu
->SetInvokingWindow( NULL 
); 
1703 // ---------------------------------------------------------------------------- 
1705 // ---------------------------------------------------------------------------- 
1709 void wxWindowMac::DoSetToolTip(wxToolTip 
*tooltip
) 
1711     wxWindowBase::DoSetToolTip(tooltip
); 
1714         m_tooltip
->SetWindow(this); 
1719 void wxWindowMac::MacInvalidateBorders() 
1721     if ( m_peer 
== NULL 
) 
1724     bool vis 
= MacIsReallyShown() ; 
1728     int outerBorder 
= MacGetLeftBorderSize() ; 
1729     if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ) 
1732     if ( outerBorder 
== 0 ) 
1735     // now we know that we have something to do at all 
1737     // as the borders are drawn on the parent we have to properly invalidate all these areas 
1738     RgnHandle updateInner 
, updateOuter
; 
1741     // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon 
1742     updateInner 
= NewRgn() ; 
1743     updateOuter 
= NewRgn() ; 
1745     m_peer
->GetRect( &rect 
) ; 
1746     RectRgn( updateInner
, &rect 
) ; 
1747     InsetRect( &rect 
, -outerBorder 
, -outerBorder 
) ; 
1748     RectRgn( updateOuter
, &rect 
) ; 
1749     DiffRgn( updateOuter
, updateInner 
, updateOuter 
) ; 
1751 #ifdef __WXMAC_OSX__ 
1752     GetParent()->m_peer
->SetNeedsDisplay( updateOuter 
) ; 
1754     WindowRef tlw 
= (WindowRef
) MacGetTopLevelWindowRef() ; 
1756         InvalWindowRgn( tlw 
, updateOuter 
) ; 
1759     DisposeRgn( updateOuter 
) ; 
1760     DisposeRgn( updateInner 
) ; 
1763 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
) 
1765     // this is never called for a toplevel window, so we know we have a parent 
1766     int former_x 
, former_y 
, former_w
, former_h 
; 
1768     // Get true coordinates of former position 
1769     DoGetPosition( &former_x 
, &former_y 
) ; 
1770     DoGetSize( &former_w 
, &former_h 
) ; 
1772     wxWindow 
*parent 
= GetParent(); 
1775         wxPoint 
pt(parent
->GetClientAreaOrigin()); 
1780     int actualWidth 
= width 
; 
1781     int actualHeight 
= height 
; 
1785     if ((m_minWidth 
!= -1) && (actualWidth 
< m_minWidth
)) 
1786         actualWidth 
= m_minWidth
; 
1787     if ((m_minHeight 
!= -1) && (actualHeight 
< m_minHeight
)) 
1788         actualHeight 
= m_minHeight
; 
1789     if ((m_maxWidth 
!= -1) && (actualWidth 
> m_maxWidth
)) 
1790         actualWidth 
= m_maxWidth
; 
1791     if ((m_maxHeight 
!= -1) && (actualHeight 
> m_maxHeight
)) 
1792         actualHeight 
= m_maxHeight
; 
1794     bool doMove 
= false, doResize 
= false ; 
1796     if ( actualX 
!= former_x 
|| actualY 
!= former_y 
) 
1799     if ( actualWidth 
!= former_w 
|| actualHeight 
!= former_h 
) 
1802     if ( doMove 
|| doResize 
) 
1804         // as the borders are drawn outside the native control, we adjust now 
1806         wxRect 
bounds( wxPoint( actualX 
+ MacGetLeftBorderSize() ,actualY 
+ MacGetTopBorderSize() ), 
1807             wxSize( actualWidth 
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) , 
1808                 actualHeight 
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ; 
1811         wxMacRectToNative( &bounds 
, &r 
) ; 
1813         if ( !GetParent()->IsTopLevel() ) 
1814             wxMacWindowToNative( GetParent() , &r 
) ; 
1816         MacInvalidateBorders() ; 
1818         m_cachedClippedRectValid 
= false ; 
1819         m_peer
->SetRect( &r 
) ; 
1821         wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified 
1823         MacInvalidateBorders() ; 
1825         MacRepositionScrollBars() ; 
1828             wxPoint 
point(actualX
, actualY
); 
1829             wxMoveEvent 
event(point
, m_windowId
); 
1830             event
.SetEventObject(this); 
1831             GetEventHandler()->ProcessEvent(event
) ; 
1836             MacRepositionScrollBars() ; 
1837             wxSize 
size(actualWidth
, actualHeight
); 
1838             wxSizeEvent 
event(size
, m_windowId
); 
1839             event
.SetEventObject(this); 
1840             GetEventHandler()->ProcessEvent(event
); 
1845 wxSize 
wxWindowMac::DoGetBestSize() const 
1847     if ( m_macIsUserPane 
|| IsTopLevel() ) 
1848         return wxWindowBase::DoGetBestSize() ; 
1850     Rect    bestsize 
= { 0 , 0 , 0 , 0 } ; 
1851     int bestWidth
, bestHeight 
; 
1853     m_peer
->GetBestRect( &bestsize 
) ; 
1854     if ( EmptyRect( &bestsize 
) ) 
1859         bestsize
.bottom 
= 16 ; 
1861         if ( IsKindOf( CLASSINFO( wxScrollBar 
) ) ) 
1863             bestsize
.bottom 
= 16 ; 
1866         else if ( IsKindOf( CLASSINFO( wxSpinButton 
) ) ) 
1868             bestsize
.bottom 
= 24 ; 
1873             // return wxWindowBase::DoGetBestSize() ; 
1877     bestWidth 
= bestsize
.right 
- bestsize
.left 
; 
1878     bestHeight 
= bestsize
.bottom 
- bestsize
.top 
; 
1879     if ( bestHeight 
< 10 ) 
1882     return wxSize(bestWidth
, bestHeight
); 
1885 // set the size of the window: if the dimensions are positive, just use them, 
1886 // but if any of them is equal to -1, it means that we must find the value for 
1887 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in 
1888 // which case -1 is a valid value for x and y) 
1890 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate 
1891 // the width/height to best suit our contents, otherwise we reuse the current 
1893 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
1895     // get the current size and position... 
1896     int currentX
, currentY
; 
1897     int currentW
, currentH
; 
1899     GetPosition(¤tX
, ¤tY
); 
1900     GetSize(¤tW
, ¤tH
); 
1902     // ... and don't do anything (avoiding flicker) if it's already ok 
1903     if ( x 
== currentX 
&& y 
== currentY 
&& 
1904         width 
== currentW 
&& height 
== currentH 
&& ( height 
!= -1 && width 
!= -1 ) ) 
1907         MacRepositionScrollBars() ; // we might have a real position shift 
1912     if ( !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
1914         if ( x 
== wxDefaultCoord 
) 
1916         if ( y 
== wxDefaultCoord 
) 
1920     AdjustForParentClientOrigin( x
, y
, sizeFlags 
); 
1922     wxSize size 
= wxDefaultSize
; 
1923     if ( width 
== wxDefaultCoord 
) 
1925         if ( sizeFlags 
& wxSIZE_AUTO_WIDTH 
) 
1927             size 
= DoGetBestSize(); 
1932             // just take the current one 
1937     if ( height 
== wxDefaultCoord 
) 
1939         if ( sizeFlags 
& wxSIZE_AUTO_HEIGHT 
) 
1941             if ( size
.x 
== wxDefaultCoord 
) 
1942                 size 
= DoGetBestSize(); 
1943             // else: already called DoGetBestSize() above 
1949             // just take the current one 
1954     DoMoveWindow( x
, y
, width
, height 
); 
1957 wxPoint 
wxWindowMac::GetClientAreaOrigin() const 
1959     RgnHandle rgn 
= NewRgn() ; 
1961     if ( m_peer
->GetRegion( kControlContentMetaPart 
, rgn 
) == noErr 
) 
1963         GetRegionBounds( rgn 
, &content 
) ; 
1973     return wxPoint( content
.left 
+ MacGetLeftBorderSize() , content
.top 
+ MacGetTopBorderSize() ); 
1976 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
) 
1978     if ( clientheight 
!= wxDefaultCoord 
|| clientheight 
!= wxDefaultCoord 
) 
1980         int currentclientwidth 
, currentclientheight 
; 
1981         int currentwidth 
, currentheight 
; 
1983         GetClientSize( ¤tclientwidth 
, ¤tclientheight 
) ; 
1984         GetSize( ¤twidth 
, ¤theight 
) ; 
1986         DoSetSize( wxDefaultCoord 
, wxDefaultCoord 
, currentwidth 
+ clientwidth 
- currentclientwidth 
, 
1987             currentheight 
+ clientheight 
- currentclientheight 
, wxSIZE_USE_EXISTING 
) ; 
1991 void wxWindowMac::SetLabel(const wxString
& title
) 
1993     m_label 
= wxStripMenuCodes(title
) ; 
1995     if ( m_peer 
&& m_peer
->Ok() ) 
1996         m_peer
->SetLabel( m_label 
) ; 
2001 wxString 
wxWindowMac::GetLabel() const 
2006 bool wxWindowMac::Show(bool show
) 
2008     bool former 
= MacIsReallyShown() ; 
2009     if ( !wxWindowBase::Show(show
) ) 
2012     // TODO: use visibilityChanged Carbon Event for OSX 
2014         m_peer
->SetVisibility( show 
, true ) ; 
2016     if ( former 
!= MacIsReallyShown() ) 
2017         MacPropagateVisibilityChanged() ; 
2022 bool wxWindowMac::Enable(bool enable
) 
2024     wxASSERT( m_peer
->Ok() ) ; 
2025     bool former 
= MacIsReallyEnabled() ; 
2026     if ( !wxWindowBase::Enable(enable
) ) 
2029     m_peer
->Enable( enable 
) ; 
2031     if ( former 
!= MacIsReallyEnabled() ) 
2032         MacPropagateEnabledStateChanged() ; 
2038 // status change propagations (will be not necessary for OSX later ) 
2041 void wxWindowMac::MacPropagateVisibilityChanged() 
2043 #if !TARGET_API_MAC_OSX 
2044     MacVisibilityChanged() ; 
2047     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
2050         child 
= node
->GetData(); 
2051         if ( child
->IsShown() ) 
2052             child
->MacPropagateVisibilityChanged() ; 
2054         node 
= node
->GetNext(); 
2059 void wxWindowMac::MacPropagateEnabledStateChanged() 
2061 #if !TARGET_API_MAC_OSX 
2062     MacEnabledStateChanged() ; 
2065     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
2068         child 
= node
->GetData(); 
2069         if ( child
->IsEnabled() ) 
2070             child
->MacPropagateEnabledStateChanged() ; 
2072         node 
= node
->GetNext(); 
2077 void wxWindowMac::MacPropagateHiliteChanged() 
2079 #if !TARGET_API_MAC_OSX 
2080     MacHiliteChanged() ; 
2083     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
2086         child 
= node
->GetData(); 
2087         if (child 
/* && child->IsEnabled() */) 
2088             child
->MacPropagateHiliteChanged() ; 
2090         node 
= node
->GetNext(); 
2096 // status change notifications 
2099 void wxWindowMac::MacVisibilityChanged() 
2103 void wxWindowMac::MacHiliteChanged() 
2107 void wxWindowMac::MacEnabledStateChanged() 
2112 // status queries on the inherited window's state 
2115 bool wxWindowMac::MacIsReallyShown() 
2117     // only under OSX the visibility of the TLW is taken into account 
2118     if ( m_isBeingDeleted 
) 
2121 #if TARGET_API_MAC_OSX 
2122     if ( m_peer 
&& m_peer
->Ok() ) 
2123         return m_peer
->IsVisible(); 
2126     wxWindow
* win 
= this ; 
2127     while ( win
->IsShown() ) 
2129         if ( win
->IsTopLevel() ) 
2132         win 
= win
->GetParent() ; 
2140 bool wxWindowMac::MacIsReallyEnabled() 
2142     return m_peer
->IsEnabled() ; 
2145 bool wxWindowMac::MacIsReallyHilited() 
2147     return m_peer
->IsActive(); 
2150 void wxWindowMac::MacFlashInvalidAreas() 
2152 #if TARGET_API_MAC_OSX 
2153     HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ; 
2157 int wxWindowMac::GetCharHeight() const 
2159     wxClientDC 
dc( (wxWindowMac
*)this ) ; 
2161     return dc
.GetCharHeight() ; 
2164 int wxWindowMac::GetCharWidth() const 
2166     wxClientDC 
dc( (wxWindowMac
*)this ) ; 
2168     return dc
.GetCharWidth() ; 
2171 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
, 
2172                            int *descent
, int *externalLeading
, const wxFont 
*theFont 
) const 
2174     const wxFont 
*fontToUse 
= theFont
; 
2176         fontToUse 
= &m_font
; 
2178     wxClientDC 
dc( (wxWindowMac
*) this ) ; 
2180     dc
.GetTextExtent( string 
, &lx 
, &ly 
, &ld
, &le
, (wxFont 
*)fontToUse 
) ; 
2181     if ( externalLeading 
) 
2182         *externalLeading 
= le 
; 
2192  * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect 
2193  * we always intersect with the entire window, not only with the client area 
2196 void wxWindowMac::Refresh(bool eraseBack
, const wxRect 
*rect
) 
2198     if ( m_peer 
== NULL 
) 
2201     if ( !MacIsReallyShown() ) 
2208         wxMacRectToNative( rect 
, &r 
) ; 
2209         m_peer
->SetNeedsDisplay( &r 
) ; 
2213         m_peer
->SetNeedsDisplay() ; 
2217 void wxWindowMac::Freeze() 
2219 #if TARGET_API_MAC_OSX 
2220     if ( !m_frozenness
++ ) 
2222         if ( m_peer 
&& m_peer
->Ok() ) 
2223             m_peer
->SetDrawingEnabled( false ) ; 
2228 void wxWindowMac::Thaw() 
2230 #if TARGET_API_MAC_OSX 
2231     wxASSERT_MSG( m_frozenness 
> 0, wxT("Thaw() without matching Freeze()") ); 
2233     if ( !--m_frozenness 
) 
2235         if ( m_peer 
&& m_peer
->Ok() ) 
2237             m_peer
->SetDrawingEnabled( true ) ; 
2238             m_peer
->InvalidateWithChildren() ; 
2244 wxWindowMac 
*wxGetActiveWindow() 
2246     // actually this is a windows-only concept 
2250 // Coordinates relative to the window 
2251 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
) 
2253     // We really don't move the mouse programmatically under Mac. 
2256 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
) 
2258     if ( MacGetTopLevelWindow() == NULL 
) 
2261 #if TARGET_API_MAC_OSX 
2262     if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT 
) ) 
2269         event
.GetDC()->Clear() ; 
2273 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event 
) 
2278 int wxWindowMac::GetScrollPos(int orient
) const 
2280     if ( orient 
== wxHORIZONTAL 
) 
2283            return m_hScrollBar
->GetThumbPosition() ; 
2288            return m_vScrollBar
->GetThumbPosition() ; 
2294 // This now returns the whole range, not just the number 
2295 // of positions that we can scroll. 
2296 int wxWindowMac::GetScrollRange(int orient
) const 
2298     if ( orient 
== wxHORIZONTAL 
) 
2301            return m_hScrollBar
->GetRange() ; 
2306            return m_vScrollBar
->GetRange() ; 
2312 int wxWindowMac::GetScrollThumb(int orient
) const 
2314     if ( orient 
== wxHORIZONTAL 
) 
2317            return m_hScrollBar
->GetThumbSize() ; 
2322            return m_vScrollBar
->GetThumbSize() ; 
2328 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
) 
2330     if ( orient 
== wxHORIZONTAL 
) 
2333            m_hScrollBar
->SetThumbPosition( pos 
) ; 
2338            m_vScrollBar
->SetThumbPosition( pos 
) ; 
2343 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef 
2344 // our own window origin is at leftOrigin/rightOrigin 
2347 void wxWindowMac::MacPaintBorders( int leftOrigin 
, int rightOrigin 
) 
2353     bool hasFocus 
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ; 
2354     bool hasBothScrollbars 
= (m_hScrollBar 
&& m_hScrollBar
->IsShown()) && (m_vScrollBar 
&& m_vScrollBar
->IsShown()) ; 
2356     // back to the surrounding frame rectangle 
2357     m_peer
->GetRect( &rect 
) ; 
2358     InsetRect( &rect
, -1 , -1 ) ; 
2360 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 
2361     if ( UMAGetSystemVersion() >= 0x1030 ) 
2363         CGRect cgrect 
= CGRectMake( rect
.left 
, rect
.top 
, rect
.right 
- rect
.left 
, 
2364             rect
.bottom 
- rect
.top 
) ; 
2366         HIThemeFrameDrawInfo info 
; 
2367         memset( &info
, 0 , sizeof(info
) ) ; 
2371         info
.state 
= IsEnabled() ? kThemeStateActive 
: kThemeStateInactive 
; 
2372         info
.isFocused 
= hasFocus 
; 
2374         CGContextRef cgContext 
= (CGContextRef
) GetParent()->MacGetCGContextRef() ; 
2375         wxASSERT( cgContext 
) ; 
2377         if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) ) 
2379             info
.kind 
= kHIThemeFrameTextFieldSquare 
; 
2380             HIThemeDrawFrame( &cgrect 
, &info 
, cgContext 
, kHIThemeOrientationNormal 
) ; 
2382         else if ( HasFlag(wxSIMPLE_BORDER
) ) 
2384             info
.kind 
= kHIThemeFrameListBox 
; 
2385             HIThemeDrawFrame( &cgrect 
, &info 
, cgContext 
, kHIThemeOrientationNormal 
) ; 
2387         else if ( hasFocus 
) 
2389             HIThemeDrawFocusRect( &cgrect 
, true , cgContext 
, kHIThemeOrientationNormal 
) ; 
2392         m_peer
->GetRect( &rect 
) ; 
2393         if ( hasBothScrollbars 
) 
2395             int size 
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL 
? 16 : 12 ; 
2396             CGRect cgrect 
= CGRectMake( rect
.right 
- size 
, rect
.bottom 
- size 
, size 
, size 
) ; 
2397             CGPoint cgpoint 
= CGPointMake( rect
.right 
- size 
, rect
.bottom 
- size 
) ; 
2398             HIThemeGrowBoxDrawInfo info 
; 
2399             memset( &info
, 0, sizeof(info
) ) ; 
2401             info
.state 
= IsEnabled() ? kThemeStateActive 
: kThemeStateInactive 
; 
2402             info
.kind 
= kHIThemeGrowBoxKindNone 
; 
2403             info
.size 
= kHIThemeGrowBoxSizeNormal 
; 
2404             info
.direction 
= kThemeGrowRight 
| kThemeGrowDown 
; 
2405             HIThemeDrawGrowBox( &cgpoint 
, &info 
, cgContext 
, kHIThemeOrientationNormal 
) ; 
2411         wxTopLevelWindowMac
* top 
= MacGetTopLevelWindow(); 
2415             wxMacControl::Convert( &pt 
, GetParent()->m_peer 
, top
->m_peer 
) ; 
2416             OffsetRect( &rect 
, pt
.x 
, pt
.y 
) ; 
2419         if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) ) 
2420             DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive 
: kThemeStateInactive 
) ; 
2421         else if ( HasFlag(wxSIMPLE_BORDER
) ) 
2422             DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive 
: kThemeStateInactive 
) ; 
2425             DrawThemeFocusRect( &rect 
, true ) ; 
2427         if ( hasBothScrollbars 
) 
2429             // GetThemeStandaloneGrowBoxBounds 
2430             // DrawThemeStandaloneNoGrowBox 
2435 void wxWindowMac::RemoveChild( wxWindowBase 
*child 
) 
2437     if ( child 
== m_hScrollBar 
) 
2438         m_hScrollBar 
= NULL 
; 
2439     if ( child 
== m_vScrollBar 
) 
2440         m_vScrollBar 
= NULL 
; 
2442     wxWindowBase::RemoveChild( child 
) ; 
2445 // New function that will replace some of the above. 
2446 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
, 
2447     int range
, bool refresh
) 
2451     if ( orient 
== wxHORIZONTAL 
) 
2455             showScroller 
= ((range 
!= 0) && (range 
> thumbVisible
)); 
2456             if ( m_hScrollBar
->IsShown() != showScroller 
) 
2457                 m_hScrollBar
->Show( showScroller 
) ; 
2459             m_hScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
2466             showScroller 
= ((range 
!= 0) && (range 
> thumbVisible
)); 
2467             if ( m_vScrollBar
->IsShown() != showScroller 
) 
2468                 m_vScrollBar
->Show( showScroller 
) ; 
2470             m_vScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
2474     MacRepositionScrollBars() ; 
2477 // Does a physical scroll 
2478 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
2480     if ( dx 
== 0 && dy 
== 0 ) 
2483     int width 
, height 
; 
2484     GetClientSize( &width 
, &height 
) ; 
2486 #if TARGET_API_MAC_OSX 
2487     if ( true /* m_peer->IsCompositing() */ ) 
2489         // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control 
2490         // area is scrolled, this does not occur if width and height are 2 pixels less, 
2491         // TODO: write optimal workaround 
2492         wxRect 
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width 
, height 
) ; 
2494             scrollrect
.Intersect( *rect 
) ; 
2496         if ( m_peer
->GetNeedsDisplay() ) 
2498             // because HIViewScrollRect does not scroll the already invalidated area we have two options: 
2499             // either immediate redraw or full invalidate 
2501             // is the better overall solution, as it does not slow down scrolling 
2502             m_peer
->SetNeedsDisplay() ; 
2504             // this would be the preferred version for fast drawing controls 
2506 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 
2507             if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() ) 
2508                 HIViewRender(m_peer
->GetControlRef()) ; 
2515         // as the native control might be not a 0/0 wx window coordinates, we have to offset 
2516         scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; 
2517         m_peer
->ScrollRect( &scrollrect 
, dx 
, dy 
) ; 
2519         // becuase HIViewScrollRect does not scroll the already invalidated area we have two options 
2520         // either immediate redraw or full invalidate 
2522         // is the better overall solution, as it does not slow down scrolling 
2523         m_peer
->SetNeedsDisplay() ; 
2525         // this would be the preferred version for fast drawing controls 
2527 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 
2528             if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() ) 
2529                 HIViewRender(m_peer
->GetControlRef()) ; 
2543         RgnHandle updateRgn 
= NewRgn() ; 
2546             wxClientDC 
dc(this) ; 
2547             wxMacPortSetter 
helper(&dc
) ; 
2549             m_peer
->GetRectInWindowCoords( &scrollrect 
) ; 
2550             //scrollrect.top += MacGetTopBorderSize() ; 
2551             //scrollrect.left += MacGetLeftBorderSize() ; 
2552             scrollrect
.bottom 
= scrollrect
.top 
+ height 
; 
2553             scrollrect
.right 
= scrollrect
.left 
+ width 
; 
2557                 Rect r 
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y 
+ rect
->height
) , 
2558                     dc
.XLOG2DEVMAC(rect
->x 
+ rect
->width
) } ; 
2559                 SectRect( &scrollrect 
, &r 
, &scrollrect 
) ; 
2562             ScrollRect( &scrollrect 
, dx 
, dy 
, updateRgn 
) ; 
2564             // now scroll the former update region as well and add the new update region 
2565             WindowRef rootWindow 
= (WindowRef
) MacGetTopLevelWindowRef() ; 
2566             RgnHandle formerUpdateRgn 
= NewRgn() ; 
2567             RgnHandle scrollRgn 
= NewRgn() ; 
2568             RectRgn( scrollRgn 
, &scrollrect 
) ; 
2569             GetWindowUpdateRgn( rootWindow 
, formerUpdateRgn 
) ; 
2571             LocalToGlobal( &pt 
) ; 
2572             OffsetRgn( formerUpdateRgn 
, -pt
.h 
, -pt
.v 
) ; 
2573             SectRgn( formerUpdateRgn 
, scrollRgn 
, formerUpdateRgn 
) ; 
2575             if ( !EmptyRgn( formerUpdateRgn 
) ) 
2577                 MacOffsetRgn( formerUpdateRgn 
, dx 
, dy 
) ; 
2578                 SectRgn( formerUpdateRgn 
, scrollRgn 
, formerUpdateRgn 
) ; 
2579                 InvalWindowRgn( rootWindow
, formerUpdateRgn 
) ; 
2582             InvalWindowRgn(rootWindow
, updateRgn 
) ; 
2583             DisposeRgn( updateRgn 
) ; 
2584             DisposeRgn( formerUpdateRgn 
) ; 
2585             DisposeRgn( scrollRgn 
) ; 
2593     for (wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
2595         child 
= node
->GetData(); 
2598         if (child 
== m_vScrollBar
) 
2600         if (child 
== m_hScrollBar
) 
2602         if (child
->IsTopLevel()) 
2605         child
->GetPosition( &x
, &y 
); 
2606         child
->GetSize( &w
, &h 
); 
2609             wxRect 
rc( x
, y
, w
, h 
); 
2610             if (rect
->Intersects( rc 
)) 
2611                 child
->SetSize( x 
+ dx
, y 
+ dy
, w
, h 
); 
2615             child
->SetSize( x 
+ dx
, y 
+ dy
, w
, h 
); 
2620 void wxWindowMac::MacOnScroll( wxScrollEvent 
&event 
) 
2622     if ( event
.GetEventObject() == m_vScrollBar 
|| event
.GetEventObject() == m_hScrollBar 
) 
2624         wxScrollWinEvent wevent
; 
2625         wevent
.SetPosition(event
.GetPosition()); 
2626         wevent
.SetOrientation(event
.GetOrientation()); 
2627         wevent
.SetEventObject(this); 
2629         if (event
.GetEventType() == wxEVT_SCROLL_TOP
) 
2630             wevent
.SetEventType( wxEVT_SCROLLWIN_TOP 
); 
2631         else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
) 
2632             wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM 
); 
2633         else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
) 
2634             wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP 
); 
2635         else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
) 
2636             wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN 
); 
2637         else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
) 
2638             wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP 
); 
2639         else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
) 
2640             wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN 
); 
2641         else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) 
2642             wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK 
); 
2643         else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
) 
2644             wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE 
); 
2646         GetEventHandler()->ProcessEvent(wevent
); 
2650 // Get the window with the focus 
2651 wxWindowMac 
*wxWindowBase::DoFindFocus() 
2653     ControlRef control 
; 
2654     GetKeyboardFocus( GetUserFocusWindow() , &control 
) ; 
2655     return wxFindControlFromMacControl( control 
) ; 
2658 void wxWindowMac::OnSetFocus( wxFocusEvent
& event 
) 
2660     // panel wants to track the window which was the last to have focus in it, 
2661     // so we want to set ourselves as the window which last had focus 
2663     // notice that it's also important to do it upwards the tree because 
2664     // otherwise when the top level panel gets focus, it won't set it back to 
2665     // us, but to some other sibling 
2667     // CS: don't know if this is still needed: 
2668     //wxChildFocusEvent eventFocus(this); 
2669     //(void)GetEventHandler()->ProcessEvent(eventFocus); 
2671     if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() ) 
2673 #if wxMAC_USE_CORE_GRAPHICS 
2674         GetParent()->Refresh() ; 
2676         wxMacWindowStateSaver 
sv( this ) ; 
2679         m_peer
->GetRect( &rect 
) ; 
2680         // auf den umgebenden Rahmen zur\9fck 
2681         InsetRect( &rect
, -1 , -1 ) ; 
2683         wxTopLevelWindowMac
* top 
= MacGetTopLevelWindow(); 
2687             wxMacControl::Convert( &pt 
, GetParent()->m_peer 
, top
->m_peer 
) ; 
2689             rect
.right 
+= pt
.x 
; 
2691             rect
.bottom 
+= pt
.y 
; 
2694         bool bIsFocusEvent 
= (event
.GetEventType() == wxEVT_SET_FOCUS
); 
2695         DrawThemeFocusRect( &rect 
, bIsFocusEvent 
) ; 
2696         if ( !bIsFocusEvent 
) 
2698             // as this erases part of the frame we have to redraw borders 
2699             // and because our z-ordering is not always correct (staticboxes) 
2700             // we have to invalidate things, we cannot simple redraw 
2701             MacInvalidateBorders() ; 
2709 void wxWindowMac::OnInternalIdle() 
2711     // This calls the UI-update mechanism (querying windows for 
2712     // menu/toolbar/control state information) 
2713     if (wxUpdateUIEvent::CanUpdate(this)) 
2714         UpdateWindowUI(wxUPDATE_UI_FROMIDLE
); 
2717 // Raise the window to the top of the Z order 
2718 void wxWindowMac::Raise() 
2720     m_peer
->SetZOrder( true , NULL 
) ; 
2723 // Lower the window to the bottom of the Z order 
2724 void wxWindowMac::Lower() 
2726     m_peer
->SetZOrder( false , NULL 
) ; 
2729 // static wxWindow *gs_lastWhich = NULL; 
2731 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt 
) 
2733     // first trigger a set cursor event 
2735     wxPoint clientorigin 
= GetClientAreaOrigin() ; 
2736     wxSize clientsize 
= GetClientSize() ; 
2738     if ( wxRect2DInt( clientorigin
.x 
, clientorigin
.y 
, clientsize
.x 
, clientsize
.y 
).Contains( wxPoint2DInt( pt 
) ) ) 
2740         wxSetCursorEvent 
event( pt
.x 
, pt
.y 
); 
2742         bool processedEvtSetCursor 
= GetEventHandler()->ProcessEvent(event
); 
2743         if ( processedEvtSetCursor 
&& event
.HasCursor() ) 
2745             cursor 
= event
.GetCursor() ; 
2749             // the test for processedEvtSetCursor is here to prevent using m_cursor 
2750             // if the user code caught EVT_SET_CURSOR() and returned nothing from 
2751             // it - this is a way to say that our cursor shouldn't be used for this 
2753             if ( !processedEvtSetCursor 
&& m_cursor
.Ok() ) 
2756             if ( !wxIsBusy() && !GetParent() ) 
2757                 cursor 
= *wxSTANDARD_CURSOR 
; 
2761             cursor
.MacInstall() ; 
2764     return cursor
.Ok() ; 
2767 wxString 
wxWindowMac::MacGetToolTipString( wxPoint 
&pt 
) 
2771         return m_tooltip
->GetTip() ; 
2774     return wxEmptyString 
; 
2777 void wxWindowMac::ClearBackground() 
2783 void wxWindowMac::Update() 
2785 #if TARGET_API_MAC_OSX 
2786     MacGetTopLevelWindow()->MacPerformUpdates() ; 
2788     ::Draw1Control( m_peer
->GetControlRef() ) ; 
2792 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const 
2794     wxTopLevelWindowMac
* win 
= NULL 
; 
2795     WindowRef window 
= (WindowRef
) MacGetTopLevelWindowRef() ; 
2797         win 
= wxFindWinFromMacWindow( window 
) ; 
2802 const wxRect
& wxWindowMac::MacGetClippedClientRect() const 
2804     MacUpdateClippedRects() ; 
2806     return m_cachedClippedClientRect 
; 
2809 const wxRect
& wxWindowMac::MacGetClippedRect() const 
2811     MacUpdateClippedRects() ; 
2813     return m_cachedClippedRect 
; 
2816 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const 
2818     MacUpdateClippedRects() ; 
2820     return m_cachedClippedRectWithOuterStructure 
; 
2823 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures 
) 
2825     static wxRegion emptyrgn 
; 
2827     if ( !m_isBeingDeleted 
&& MacIsReallyShown() /*m_peer->IsVisible() */ ) 
2829         MacUpdateClippedRects() ; 
2830         if ( includeOuterStructures 
) 
2831             return m_cachedClippedRegionWithOuterStructure 
; 
2833             return m_cachedClippedRegion 
; 
2841 void wxWindowMac::MacUpdateClippedRects() const 
2843     if ( m_cachedClippedRectValid 
) 
2846     // includeOuterStructures is true if we try to draw somthing like a focus ring etc. 
2847     // also a window dc uses this, in this case we only clip in the hierarchy for hard 
2848     // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having 
2849     // to add focus borders everywhere 
2851     Rect r
, rIncludingOuterStructures 
; 
2853     m_peer
->GetRect( &r 
) ; 
2854     r
.left 
-= MacGetLeftBorderSize() ; 
2855     r
.top 
-= MacGetTopBorderSize() ; 
2856     r
.bottom 
+= MacGetBottomBorderSize() ; 
2857     r
.right 
+= MacGetRightBorderSize() ; 
2864     rIncludingOuterStructures 
= r 
; 
2865     InsetRect( &rIncludingOuterStructures 
, -4 , -4 ) ; 
2867     wxRect cl 
= GetClientRect() ; 
2868     Rect rClient 
= { cl
.y 
, cl
.x 
, cl
.y 
+ cl
.height 
, cl
.x 
+ cl
.width 
} ; 
2872     const wxWindow
* child 
= this ; 
2873     const wxWindow
* parent 
= NULL 
; 
2875     while ( !child
->IsTopLevel() && ( parent 
= child
->GetParent() ) != NULL 
) 
2877         if ( parent
->MacIsChildOfClientArea(child
) ) 
2879             size 
= parent
->GetClientSize() ; 
2880             wxPoint origin 
= parent
->GetClientAreaOrigin() ; 
2886             // this will be true for scrollbars, toolbars etc. 
2887             size 
= parent
->GetSize() ; 
2888             y 
= parent
->MacGetTopBorderSize() ; 
2889             x 
= parent
->MacGetLeftBorderSize() ; 
2890             size
.x 
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ; 
2891             size
.y 
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ; 
2894         parent
->MacWindowToRootWindow( &x
, &y 
) ; 
2895         MacRootWindowToWindow( &x 
, &y 
) ; 
2897         Rect rparent 
= { y 
, x 
, y 
+ size
.y 
, x 
+ size
.x 
} ; 
2899         // the wxwindow and client rects will always be clipped 
2900         SectRect( &r 
, &rparent 
, &r 
) ; 
2901         SectRect( &rClient 
, &rparent 
, &rClient 
) ; 
2903         // the structure only at 'hard' borders 
2904         if ( parent
->MacClipChildren() || 
2905             ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) ) 
2907             SectRect( &rIncludingOuterStructures 
, &rparent 
, &rIncludingOuterStructures 
) ; 
2913     m_cachedClippedRect 
= wxRect( r
.left 
, r
.top 
, r
.right 
- r
.left 
, r
.bottom 
- r
.top 
) ; 
2914     m_cachedClippedClientRect 
= wxRect( rClient
.left 
, rClient
.top 
, 
2915         rClient
.right 
- rClient
.left 
, rClient
.bottom 
- rClient
.top 
) ; 
2916     m_cachedClippedRectWithOuterStructure 
= wxRect( 
2917         rIncludingOuterStructures
.left 
, rIncludingOuterStructures
.top 
, 
2918         rIncludingOuterStructures
.right 
- rIncludingOuterStructures
.left 
, 
2919         rIncludingOuterStructures
.bottom 
- rIncludingOuterStructures
.top 
) ; 
2921     m_cachedClippedRegionWithOuterStructure 
= wxRegion( m_cachedClippedRectWithOuterStructure 
) ; 
2922     m_cachedClippedRegion 
= wxRegion( m_cachedClippedRect 
) ; 
2923     m_cachedClippedClientRegion 
= wxRegion( m_cachedClippedClientRect 
) ; 
2925     m_cachedClippedRectValid 
= true ; 
2929     This function must not change the updatergn ! 
2931 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr 
, long time 
) 
2933     bool handled 
= false ; 
2935     RgnHandle updatergn 
= (RgnHandle
) updatergnr 
; 
2936     GetRegionBounds( updatergn 
, &updatebounds 
) ; 
2938     // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ; 
2940     if ( !EmptyRgn(updatergn
) ) 
2942         RgnHandle newupdate 
= NewRgn() ; 
2943         wxSize point 
= GetClientSize() ; 
2944         wxPoint origin 
= GetClientAreaOrigin() ; 
2945         SetRectRgn( newupdate 
, origin
.x 
, origin
.y 
, origin
.x 
+ point
.x 
, origin
.y 
+ point
.y 
) ; 
2946         SectRgn( newupdate 
, updatergn 
, newupdate 
) ; 
2948         // first send an erase event to the entire update area 
2950             // for the toplevel window this really is the entire area 
2951             // for all the others only their client area, otherwise they 
2952             // might be drawing with full alpha and eg put blue into 
2953             // the grow-box area of a scrolled window (scroll sample) 
2954             wxDC
* dc 
= new wxWindowDC(this); 
2956                 dc
->SetClippingRegion(wxRegion(updatergn
)); 
2958                 dc
->SetClippingRegion(wxRegion(newupdate
)); 
2960             wxEraseEvent 
eevent( GetId(), dc 
); 
2961             eevent
.SetEventObject( this ); 
2962             GetEventHandler()->ProcessEvent( eevent 
); 
2966         // calculate a client-origin version of the update rgn and set m_updateRegion to that 
2967         OffsetRgn( newupdate 
, -origin
.x 
, -origin
.y 
) ; 
2968         m_updateRegion 
= newupdate 
; 
2969         DisposeRgn( newupdate 
) ; 
2971         if ( !m_updateRegion
.Empty() ) 
2973             // paint the window itself 
2976             event
.SetTimestamp(time
); 
2977             event
.SetEventObject(this); 
2978             GetEventHandler()->ProcessEvent(event
); 
2982         // now we cannot rely on having its borders drawn by a window itself, as it does not 
2983         // get the updateRgn wide enough to always do so, so we do it from the parent 
2984         // this would also be the place to draw any custom backgrounds for native controls 
2985         // in Composited windowing 
2986         wxPoint clientOrigin 
= GetClientAreaOrigin() ; 
2990         for (wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
2992             child 
= node
->GetData(); 
2995             if (child 
== m_vScrollBar
) 
2997             if (child 
== m_hScrollBar
) 
2999             if (child
->IsTopLevel()) 
3001             if (!child
->IsShown()) 
3004             // only draw those in the update region (add a safety margin of 10 pixels for shadow effects 
3006             child
->GetPosition( &x
, &y 
); 
3007             child
->GetSize( &w
, &h 
); 
3008             Rect childRect 
= { y 
, x 
, y 
+ h 
, x 
+ w 
} ; 
3009             OffsetRect( &childRect 
, clientOrigin
.x 
, clientOrigin
.y 
) ; 
3010             InsetRect( &childRect 
, -10 , -10) ; 
3012             if ( RectInRgn( &childRect 
, updatergn 
) ) 
3014                 // paint custom borders 
3015                 wxNcPaintEvent 
eventNc( child
->GetId() ); 
3016                 eventNc
.SetEventObject( child 
); 
3017                 if ( !child
->GetEventHandler()->ProcessEvent( eventNc 
) ) 
3019 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 
3020                     if ( UMAGetSystemVersion() >= 0x1030 ) 
3022                         child
->MacPaintBorders(0, 0) ; 
3027                         wxWindowDC 
dc(this) ; 
3028                         dc
.SetClippingRegion(wxRegion(updatergn
)); 
3029                         wxMacPortSetter 
helper(&dc
) ; 
3030                         child
->MacPaintBorders(0, 0) ; 
3041 WXWindow 
wxWindowMac::MacGetTopLevelWindowRef() const 
3043     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
3047         if ( iter
->IsTopLevel() ) 
3048             return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ; 
3050         iter 
= iter
->GetParent() ; 
3053     wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; 
3058 void wxWindowMac::MacCreateScrollBars( long style 
) 
3060     wxASSERT_MSG( m_vScrollBar 
== NULL 
&& m_hScrollBar 
== NULL 
, wxT("attempt to create window twice") ) ; 
3062     if ( style 
& ( wxVSCROLL 
| wxHSCROLL 
) ) 
3064         bool hasBoth 
= ( style 
& wxVSCROLL 
) && ( style 
& wxHSCROLL 
) ; 
3065         int scrlsize 
= MAC_SCROLLBAR_SIZE 
; 
3066         wxWindowVariant variant 
= wxWINDOW_VARIANT_NORMAL 
; 
3067         if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL 
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI 
) 
3069             scrlsize 
= MAC_SMALL_SCROLLBAR_SIZE 
; 
3070             variant 
= wxWINDOW_VARIANT_SMALL 
; 
3073         int adjust 
= hasBoth 
? scrlsize 
- 1: 0 ; 
3075         GetClientSize( &width 
, &height 
) ; 
3077         wxPoint 
vPoint(width 
- scrlsize
, 0) ; 
3078         wxSize 
vSize(scrlsize
, height 
- adjust
) ; 
3079         wxPoint 
hPoint(0, height 
- scrlsize
) ; 
3080         wxSize 
hSize(width 
- adjust
, scrlsize
) ; 
3082         if ( style 
& wxVSCROLL 
) 
3083             m_vScrollBar 
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize 
, wxVERTICAL
); 
3085         if ( style  
& wxHSCROLL 
) 
3086             m_hScrollBar 
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize 
, wxHORIZONTAL
); 
3089     // because the create does not take into account the client area origin 
3090     // we might have a real position shift 
3091     MacRepositionScrollBars() ; 
3094 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child 
) const 
3096     bool result 
= ((child 
== NULL
) || ((child 
!= m_hScrollBar
) && (child 
!= m_vScrollBar
))); 
3101 void wxWindowMac::MacRepositionScrollBars() 
3103     if ( !m_hScrollBar 
&& !m_vScrollBar 
) 
3106     bool hasBoth 
= (m_hScrollBar 
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar 
&& m_vScrollBar
->IsShown()) ; 
3107     int scrlsize 
= m_hScrollBar 
? m_hScrollBar
->GetSize().y 
: ( m_vScrollBar 
? m_vScrollBar
->GetSize().x 
: MAC_SCROLLBAR_SIZE 
) ; 
3108     int adjust 
= hasBoth 
? scrlsize 
- 1 : 0 ; 
3110     // get real client area 
3112     GetSize( &width 
, &height 
); 
3114     width 
-= MacGetLeftBorderSize() + MacGetRightBorderSize(); 
3115     height 
-= MacGetTopBorderSize() + MacGetBottomBorderSize(); 
3117     wxPoint 
vPoint( width 
- scrlsize
, 0 ) ; 
3118     wxSize 
vSize( scrlsize
, height 
- adjust 
) ; 
3119     wxPoint 
hPoint( 0 , height 
- scrlsize 
) ; 
3120     wxSize 
hSize( width 
- adjust
, scrlsize 
) ; 
3123     int x 
= 0, y 
= 0, w
, h 
; 
3124     GetSize( &w 
, &h 
) ; 
3126     MacClientToRootWindow( &x 
, &y 
) ; 
3127     MacClientToRootWindow( &w 
, &h 
) ; 
3129     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
3131     int totW 
= 10000 , totH 
= 10000; 
3134         if ( iter
->IsTopLevel() ) 
3136             iter
->GetSize( &totW 
, &totH 
) ; 
3140         iter 
= iter
->GetParent() ; 
3154     if ( w 
- x 
>= totW 
) 
3159     if ( h 
- y 
>= totH 
) 
3167         m_vScrollBar
->SetSize( vPoint
.x 
, vPoint
.y
, vSize
.x
, vSize
.y 
, wxSIZE_ALLOW_MINUS_ONE 
); 
3169         m_hScrollBar
->SetSize( hPoint
.x 
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE 
); 
3172 bool wxWindowMac::AcceptsFocus() const 
3174     return MacCanFocus() && wxWindowBase::AcceptsFocus(); 
3177 void wxWindowMac::MacSuperChangedPosition() 
3179     // only window-absolute structures have to be moved i.e. controls 
3181     m_cachedClippedRectValid 
= false ; 
3184     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
3187         child 
= node
->GetData(); 
3188         child
->MacSuperChangedPosition() ; 
3190         node 
= node
->GetNext(); 
3194 void wxWindowMac::MacTopLevelWindowChangedPosition() 
3196     // only screen-absolute structures have to be moved i.e. glcanvas 
3199     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
3202         child 
= node
->GetData(); 
3203         child
->MacTopLevelWindowChangedPosition() ; 
3205         node 
= node
->GetNext(); 
3209 long wxWindowMac::MacGetLeftBorderSize() const 
3216     if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
)) 
3218         // this metric is only the 'outset' outside the simple frame rect 
3219         GetThemeMetric( kThemeMetricEditTextFrameOutset 
, &border 
) ; 
3222     else if (HasFlag(wxSIMPLE_BORDER
)) 
3224         // this metric is only the 'outset' outside the simple frame rect 
3225         GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
3232 long wxWindowMac::MacGetRightBorderSize() const 
3234     // they are all symmetric in mac themes 
3235     return MacGetLeftBorderSize() ; 
3238 long wxWindowMac::MacGetTopBorderSize() const 
3240     // they are all symmetric in mac themes 
3241     return MacGetLeftBorderSize() ; 
3244 long wxWindowMac::MacGetBottomBorderSize() const 
3246     // they are all symmetric in mac themes 
3247     return MacGetLeftBorderSize() ; 
3250 long wxWindowMac::MacRemoveBordersFromStyle( long style 
) 
3252     return style 
& ~wxBORDER_MASK 
; 
3255 // Find the wxWindowMac at the current mouse position, returning the mouse 
3257 wxWindowMac 
* wxFindWindowAtPointer( wxPoint
& pt 
) 
3259     pt 
= wxGetMousePosition(); 
3260     wxWindowMac
* found 
= wxFindWindowAtPoint(pt
); 
3265 // Get the current mouse position. 
3266 wxPoint 
wxGetMousePosition() 
3270     wxGetMousePosition( &x
, &y 
); 
3272     return wxPoint(x
, y
); 
3275 void wxWindowMac::OnMouseEvent( wxMouseEvent 
&event 
) 
3277     if ( event
.GetEventType() == wxEVT_RIGHT_DOWN 
) 
3279         // copied from wxGTK : CS 
3280         // VZ: shouldn't we move this to base class then? 
3282         // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN 
3285         // (a) it's a command event and so is propagated to the parent 
3286         // (b) under MSW it can be generated from kbd too 
3287         // (c) it uses screen coords (because of (a)) 
3288         wxContextMenuEvent 
evtCtx(wxEVT_CONTEXT_MENU
, 
3290                                   this->ClientToScreen(event
.GetPosition())); 
3291         if ( ! GetEventHandler()->ProcessEvent(evtCtx
) ) 
3300 void wxWindowMac::OnPaint( wxPaintEvent 
& event 
) 
3302     if ( wxTheApp
->MacGetCurrentEvent() != NULL 
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL 
) 
3303         CallNextEventHandler( 
3304             (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , 
3305             (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ; 
3308 void wxWindowMac::MacHandleControlClick( WXWidget control 
, wxInt16 controlpart 
, bool WXUNUSED( mouseStillDown 
) ) 
3312 Rect 
wxMacGetBoundsForControl( wxWindow
* window 
, const wxPoint
& pos 
, const wxSize 
&size 
, bool adjustForOrigin 
) 
3316     window
->MacGetBoundsForControl( pos 
, size 
, x 
, y
, w
, h 
, adjustForOrigin 
) ; 
3317     Rect bounds 
= { y
, x
, y 
+ h
, x 
+ w 
}; 
3322 wxInt32 
wxWindowMac::MacControlHit(WXEVENTHANDLERREF 
WXUNUSED(handler
) , WXEVENTREF 
WXUNUSED(event
) ) 
3324     return eventNotHandledErr 
; 
3327 bool wxWindowMac::Reparent(wxWindowBase 
*newParentBase
) 
3329     wxWindowMac 
*newParent 
= (wxWindowMac 
*)newParentBase
; 
3330     if ( !wxWindowBase::Reparent(newParent
) ) 
3333     // copied from MacPostControlCreate 
3334     ControlRef container 
= (ControlRef
) GetParent()->GetHandle() ; 
3336     wxASSERT_MSG( container 
!= NULL 
, wxT("No valid mac container control") ) ; 
3338     ::EmbedControl( m_peer
->GetControlRef() , container 
) ;