1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxWindowMac 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "window.h" 
  18 #include "wx/window.h" 
  20 #include "wx/dcclient.h" 
  24 #include "wx/layout.h" 
  25 #include "wx/dialog.h" 
  26 #include "wx/listbox.h" 
  27 #include "wx/scrolbar.h" 
  28 #include "wx/statbox.h" 
  29 #include "wx/button.h" 
  30 #include "wx/settings.h" 
  31 #include "wx/msgdlg.h" 
  33 #include "wx/notebook.h" 
  34 #include "wx/tabctrl.h" 
  35 #include "wx/tooltip.h" 
  36 #include "wx/statusbr.h" 
  37 #include "wx/menuitem.h" 
  38 #include "wx/spinctrl.h" 
  40 #include "wx/geometry.h" 
  46 #define wxWINDOW_HSCROLL 5998 
  47 #define wxWINDOW_VSCROLL 5997 
  48 #define MAC_SCROLLBAR_SIZE 16 
  50 #include "wx/mac/uma.h" 
  53 #include <ToolUtils.h> 
  56 #if  wxUSE_DRAG_AND_DROP 
  62 extern wxList wxPendingDelete
; 
  63 wxWindowMac
* gFocusWindow 
= NULL 
; 
  65 #ifdef __WXUNIVERSAL__ 
  66     IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
) 
  68     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
) 
  69 #endif // __WXUNIVERSAL__/__WXMAC__ 
  71 #if !USE_SHARED_LIBRARY 
  73 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
) 
  74   EVT_NC_PAINT(wxWindowMac::OnNcPaint
) 
  75   EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
) 
  76   EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
) 
  77   EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
) 
  78   EVT_IDLE(wxWindowMac::OnIdle
) 
  79   EVT_SET_FOCUS(wxWindowMac::OnSetFocus
) 
  80   EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
) 
  85 #define wxMAC_DEBUG_REDRAW 0 
  86 #ifndef wxMAC_DEBUG_REDRAW 
  87 #define wxMAC_DEBUG_REDRAW 0 
  90 #define wxMAC_USE_THEME_BORDER 0 
  93 // =========================================================================== 
  95 // =========================================================================== 
  98 // ---------------------------------------------------------------------------- 
  99 // constructors and such 
 100 // ---------------------------------------------------------------------------- 
 102 void wxWindowMac::Init() 
 107     m_isBeingDeleted 
= FALSE
; 
 108     m_backgroundTransparent 
= FALSE
; 
 110     // as all windows are created with WS_VISIBLE style... 
 118     m_hScrollBar 
= NULL 
; 
 119     m_vScrollBar 
= NULL 
; 
 121     m_label 
= wxEmptyString
; 
 125 wxWindowMac::~wxWindowMac() 
 129     // deleting a window while it is shown invalidates the region 
 131         wxWindowMac
* iter 
= this ; 
 133             if ( iter
->IsTopLevel() ) 
 138             iter 
= iter
->GetParent() ; 
 143     m_isBeingDeleted 
= TRUE
; 
 145 #ifndef __WXUNIVERSAL__ 
 146     // VS: make sure there's no wxFrame with last focus set to us: 
 147     for ( wxWindow 
*win 
= GetParent(); win
; win 
= win
->GetParent() ) 
 149         wxFrame 
*frame 
= wxDynamicCast(win
, wxFrame
); 
 152             if ( frame
->GetLastFocus() == this ) 
 154                 frame
->SetLastFocus((wxWindow
*)NULL
); 
 159 #endif // __WXUNIVERSAL__ 
 161     if ( s_lastMouseWindow 
== this ) 
 163         s_lastMouseWindow 
= NULL 
; 
 166     wxFrame
* frame 
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame 
) ; 
 169         if ( frame
->GetLastFocus() == this ) 
 170             frame
->SetLastFocus( NULL 
) ; 
 173     if ( gFocusWindow 
== this ) 
 175         gFocusWindow 
= NULL 
; 
 178         // CS: copied from MSW : 
 179     // VS: destroy children first and _then_ detach *this from its parent. 
 180     //     If we'd do it the other way around, children wouldn't be able 
 181     //     find their parent frame (see above). 
 185         m_parent
->RemoveChild(this); 
 187     // delete our drop target if we've got one 
 188 #if wxUSE_DRAG_AND_DROP 
 189     if ( m_dropTarget 
!= NULL 
) 
 194 #endif // wxUSE_DRAG_AND_DROP 
 198 bool wxWindowMac::Create(wxWindowMac 
*parent
, wxWindowID id
, 
 202            const wxString
& name
) 
 204     wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") ); 
 207     // wxGTK doesn't allow to create controls with static box as the parent so 
 208     // this will result in a crash when the program is ported to wxGTK - warn 
 211     // the correct solution is to create the controls as siblings of the 
 213     wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
), 
 214                   _T("wxStaticBox can't be used as a window parent!") ); 
 215 #endif // wxUSE_STATBOX 
 217     if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) ) 
 220     parent
->AddChild(this); 
 224     AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
); 
 225     m_width 
= WidthDefault( size
.x 
); 
 226     m_height 
= HeightDefault( size
.y 
) ; 
 227 #ifndef __WXUNIVERSAL__ 
 228     // Don't give scrollbars to wxControls unless they ask for them 
 229     if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) || 
 230          (IsKindOf(CLASSINFO(wxControl
)) && ( style 
& wxHSCROLL 
|| style 
& wxVSCROLL
))) 
 232         MacCreateScrollBars( style 
) ; 
 238 void wxWindowMac::SetFocus() 
 240     if ( gFocusWindow 
== this ) 
 243     if ( AcceptsFocus() ) 
 249                 if ( gFocusWindow
->m_caret 
) 
 251                       gFocusWindow
->m_caret
->OnKillFocus(); 
 253 #endif // wxUSE_CARET 
 254 #ifndef __WXUNIVERSAL__ 
 255             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 256             if ( control 
&& control
->GetMacControl() ) 
 258                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNoPart 
) ; 
 259                 control
->MacRedrawControl() ; 
 262             // Without testing the window id, for some reason 
 263             // a kill focus event can still be sent to 
 264             // the control just being focussed. 
 265             int thisId 
= this->m_windowId
; 
 266             int gFocusWindowId 
= gFocusWindow
->m_windowId
; 
 267             if (gFocusWindowId 
!= thisId
) 
 269                 wxFocusEvent 
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
); 
 270                 event
.SetEventObject(gFocusWindow
); 
 271                 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ; 
 274         gFocusWindow 
= this ; 
 280                 m_caret
->OnSetFocus(); 
 282             #endif // wxUSE_CARET 
 283             // panel wants to track the window which was the last to have focus in it 
 284             wxChildFocusEvent 
eventFocus(this); 
 285             GetEventHandler()->ProcessEvent(eventFocus
); 
 287       #ifndef __WXUNIVERSAL__ 
 288             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 289             if ( control 
&& control
->GetMacControl() ) 
 291                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNextPart 
) ; 
 294             wxFocusEvent 
event(wxEVT_SET_FOCUS
, m_windowId
); 
 295             event
.SetEventObject(this); 
 296             GetEventHandler()->ProcessEvent(event
) ; 
 301 bool wxWindowMac::Enable(bool enable
) 
 303     if ( !wxWindowBase::Enable(enable
) ) 
 306     MacSuperEnabled( enable 
) ; 
 311 void wxWindowMac::DoCaptureMouse() 
 313     wxTheApp
->s_captureWindow 
= this ; 
 316 wxWindow
* wxWindowBase::GetCapture() 
 318     return wxTheApp
->s_captureWindow 
; 
 321 void wxWindowMac::DoReleaseMouse() 
 323     wxTheApp
->s_captureWindow 
= NULL 
; 
 326 #if    wxUSE_DRAG_AND_DROP 
 328 void wxWindowMac::SetDropTarget(wxDropTarget 
*pDropTarget
) 
 330     if ( m_dropTarget 
!= 0 ) { 
 334     m_dropTarget 
= pDropTarget
; 
 335     if ( m_dropTarget 
!= 0 ) 
 343 // Old style file-manager drag&drop 
 344 void wxWindowMac::DragAcceptFiles(bool accept
) 
 350 void wxWindowMac::DoGetSize(int *x
, int *y
) const 
 353      if(y
)   *y 
= m_height 
; 
 356 void wxWindowMac::DoGetPosition(int *x
, int *y
) const 
 362     if ( !IsTopLevel() && GetParent()) 
 364         wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
 373 bool wxWindowMac::DoPopupMenu(wxMenu 
*menu
, int x
, int y
) 
 375     menu
->SetInvokingWindow(this); 
 377     ClientToScreen( &x 
, &y 
) ; 
 379     menu
->MacBeforeDisplay( true ) ; 
 380     long menuResult 
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ; 
 381     if ( HiWord(menuResult
) != 0 ) 
 384         GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id 
) ; 
 385         wxMenuItem
* item 
= NULL 
; 
 387         item 
= menu
->FindItem(id
, &realmenu
) ; 
 388         if (item
->IsCheckable()) 
 390             item
->Check( !item
->IsChecked() ) ; 
 392         menu
->SendEvent( id 
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ; 
 394     menu
->MacAfterDisplay( true ) ; 
 396     menu
->SetInvokingWindow(NULL
); 
 402 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const 
 404     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 406     Point       localwhere 
= {0,0} ; 
 408     if(x
)   localwhere
.h 
= * x 
; 
 409     if(y
)   localwhere
.v 
= * y 
; 
 413     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 414     ::GlobalToLocal( &localwhere 
) ; 
 417     if(x
)   *x 
= localwhere
.h 
; 
 418     if(y
)   *y 
= localwhere
.v 
; 
 420     MacRootWindowToWindow( x 
, y 
) ; 
 422         *x 
-= MacGetLeftBorderSize() ; 
 424         *y 
-= MacGetTopBorderSize() ; 
 427 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const 
 429     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 432         *x 
+= MacGetLeftBorderSize() ; 
 434         *y 
+= MacGetTopBorderSize() ; 
 436     MacWindowToRootWindow( x 
, y 
) ; 
 438     Point       localwhere 
= { 0,0 }; 
 439     if(x
)   localwhere
.h 
= * x 
; 
 440     if(y
)   localwhere
.v 
= * y 
; 
 444     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 446     ::LocalToGlobal( &localwhere 
) ; 
 448     if(x
)   *x 
= localwhere
.h 
; 
 449     if(y
)   *y 
= localwhere
.v 
; 
 452 void wxWindowMac::MacClientToRootWindow( int *x 
, int *y 
) const 
 454     wxPoint origin 
= GetClientAreaOrigin() ; 
 455     if(x
)   *x 
+= origin
.x 
; 
 456     if(y
)   *y 
+= origin
.y 
; 
 458     MacWindowToRootWindow( x 
, y 
) ; 
 461 void wxWindowMac::MacRootWindowToClient( int *x 
, int *y 
) const 
 463     wxPoint origin 
= GetClientAreaOrigin() ; 
 464     MacRootWindowToWindow( x 
, y 
) ; 
 465     if(x
)   *x 
-= origin
.x 
; 
 466     if(y
)   *y 
-= origin
.y 
; 
 469 void wxWindowMac::MacWindowToRootWindow( int *x 
, int *y 
) const 
 475         GetParent()->MacWindowToRootWindow( x 
, y 
) ; 
 479 void wxWindowMac::MacRootWindowToWindow( int *x 
, int *y 
) const 
 485         GetParent()->MacRootWindowToWindow( x 
, y 
) ; 
 489 bool wxWindowMac::SetCursor(const wxCursor
& cursor
) 
 491     if (m_cursor 
== cursor
) 
 494     if (wxNullCursor 
== cursor
) 
 496         if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR 
) ) 
 501         if ( ! wxWindowBase::SetCursor( cursor 
) ) 
 505     wxASSERT_MSG( m_cursor
.Ok(), 
 506         wxT("cursor must be valid after call to the base version")); 
 509     wxWindowMac 
*mouseWin 
; 
 512     // Change the cursor NOW if we're within the correct window 
 514     if ( MacGetWindowFromPoint( wxPoint( pt
.h 
, pt
.v 
) , &mouseWin 
) ) 
 516         if ( mouseWin 
== this && !wxIsBusy() ) 
 518             m_cursor
.MacInstall() ; 
 526 // Get size *available for subwindows* i.e. excluding menu bar etc. 
 527 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const 
 533     ww 
-= MacGetLeftBorderSize(  )  + MacGetRightBorderSize(  ) ; 
 534     hh 
-= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ); 
 536     if ( (m_vScrollBar 
&& m_vScrollBar
->IsShown()) || (m_hScrollBar  
&& m_hScrollBar
->IsShown()) ) 
 543         MacClientToRootWindow( &x1 
, &y1 
) ; 
 544         MacClientToRootWindow( &w 
, &h 
) ; 
 546         wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
 548         int totW 
= 10000 , totH 
= 10000; 
 551             if ( iter
->IsTopLevel() ) 
 553                 totW 
= iter
->m_width 
; 
 554                 totH 
= iter
->m_height 
; 
 558             iter 
= iter
->GetParent() ; 
 561         if (m_hScrollBar  
&& m_hScrollBar
->IsShown() ) 
 563             hh 
-= MAC_SCROLLBAR_SIZE
; 
 569         if (m_vScrollBar  
&& m_vScrollBar
->IsShown() ) 
 571             ww 
-= MAC_SCROLLBAR_SIZE
; 
 583 // ---------------------------------------------------------------------------- 
 585 // ---------------------------------------------------------------------------- 
 589 void wxWindowMac::DoSetToolTip(wxToolTip 
*tooltip
) 
 591     wxWindowBase::DoSetToolTip(tooltip
); 
 594         m_tooltip
->SetWindow(this); 
 597 #endif // wxUSE_TOOLTIPS 
 599 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
) 
 603     int former_w 
= m_width 
; 
 604     int former_h 
= m_height 
; 
 606     int actualWidth 
= width
; 
 607     int actualHeight 
= height
; 
 611     if ((m_minWidth 
!= -1) && (actualWidth 
< m_minWidth
)) 
 612         actualWidth 
= m_minWidth
; 
 613     if ((m_minHeight 
!= -1) && (actualHeight 
< m_minHeight
)) 
 614         actualHeight 
= m_minHeight
; 
 615     if ((m_maxWidth 
!= -1) && (actualWidth 
> m_maxWidth
)) 
 616         actualWidth 
= m_maxWidth
; 
 617     if ((m_maxHeight 
!= -1) && (actualHeight 
> m_maxHeight
)) 
 618         actualHeight 
= m_maxHeight
; 
 620     bool doMove 
= false ; 
 621     bool doResize 
= false ; 
 623     if ( actualX 
!= former_x 
|| actualY 
!= former_y 
) 
 627     if ( actualWidth 
!= former_w 
|| actualHeight 
!= former_h 
) 
 632     if ( doMove 
|| doResize 
) 
 634         // erase former position 
 636         bool partialRepaint 
= false ; 
 638         if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) ) 
 640             wxPoint 
oldPos( m_x 
, m_y 
) ; 
 641             wxPoint 
newPos( actualX 
, actualY 
) ; 
 642             MacWindowToRootWindow( &oldPos
.x 
, &oldPos
.y 
) ; 
 643             MacWindowToRootWindow( &newPos
.x 
, &newPos
.y 
) ; 
 644             if ( oldPos 
== newPos 
) 
 646                 partialRepaint 
= true ; 
 647                 RgnHandle oldRgn
,newRgn
,diffRgn 
; 
 651                 SetRectRgn(oldRgn 
, oldPos
.x 
, oldPos
.y 
, oldPos
.x 
+ m_width 
, oldPos
.y 
+ m_height 
) ; 
 652                 SetRectRgn(newRgn 
, newPos
.x 
, newPos
.y 
, newPos
.x 
+ actualWidth 
, newPos
.y 
+ actualHeight 
) ; 
 653                 DiffRgn( newRgn 
, oldRgn 
, diffRgn 
) ; 
 654                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 655                 DiffRgn( oldRgn 
, newRgn 
, diffRgn 
) ; 
 656                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 659                 DisposeRgn(diffRgn
) ; 
 663         if ( !partialRepaint 
) 
 668         m_width 
= actualWidth 
; 
 669         m_height 
= actualHeight 
; 
 671         // update any low-level frame-relative positions 
 673         MacUpdateDimensions() ; 
 674         // erase new position 
 676         if ( !partialRepaint 
) 
 679             wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified 
 681         MacRepositionScrollBars() ; 
 684             wxPoint 
point(m_x
, m_y
); 
 685             wxMoveEvent 
event(point
, m_windowId
); 
 686             event
.SetEventObject(this); 
 687             GetEventHandler()->ProcessEvent(event
) ; 
 691             MacRepositionScrollBars() ; 
 692             wxSize 
size(m_width
, m_height
); 
 693             wxSizeEvent 
event(size
, m_windowId
); 
 694             event
.SetEventObject(this); 
 695             GetEventHandler()->ProcessEvent(event
); 
 701 // set the size of the window: if the dimensions are positive, just use them, 
 702 // but if any of them is equal to -1, it means that we must find the value for 
 703 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in 
 704 // which case -1 is a valid value for x and y) 
 706 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate 
 707 // the width/height to best suit our contents, otherwise we reuse the current 
 709 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 711     // get the current size and position... 
 712     int currentX
, currentY
; 
 713     GetPosition(¤tX
, ¤tY
); 
 715     int currentW
,currentH
; 
 716     GetSize(¤tW
, ¤tH
); 
 718     // ... and don't do anything (avoiding flicker) if it's already ok 
 719     if ( x 
== currentX 
&& y 
== currentY 
&& 
 720         width 
== currentW 
&& height 
== currentH 
) 
 722         MacRepositionScrollBars() ; // we might have a real position shift 
 726     if ( x 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 728     if ( y 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 731     AdjustForParentClientOrigin(x
, y
, sizeFlags
); 
 736         if ( sizeFlags 
& wxSIZE_AUTO_WIDTH 
) 
 738             size 
= DoGetBestSize(); 
 743             // just take the current one 
 750         if ( sizeFlags 
& wxSIZE_AUTO_HEIGHT 
) 
 754                 size 
= DoGetBestSize(); 
 756             //else: already called DoGetBestSize() above 
 762             // just take the current one 
 767     DoMoveWindow(x
, y
, width
, height
); 
 770 // For implementation purposes - sometimes decorations make the client area 
 773 wxPoint 
wxWindowMac::GetClientAreaOrigin() const 
 775     return wxPoint(MacGetLeftBorderSize(  ) , MacGetTopBorderSize(  ) ); 
 778 void wxWindowMac::SetTitle(const wxString
& title
) 
 783 wxString 
wxWindowMac::GetTitle() const 
 788 bool wxWindowMac::Show(bool show
) 
 790     if ( !wxWindowBase::Show(show
) ) 
 793     MacSuperShown( show 
) ; 
 799 void wxWindowMac::MacSuperShown( bool show 
) 
 801     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
 804         wxWindowMac 
*child 
= node
->GetData(); 
 805         if ( child
->m_isShown 
) 
 806             child
->MacSuperShown( show 
) ; 
 807         node 
= node
->GetNext(); 
 811 void wxWindowMac::MacSuperEnabled( bool enabled 
) 
 815       // to be absolutely correct we'd have to invalidate (with eraseBkground 
 816       // because unter MacOSX the frames are drawn with an addXXX mode) 
 819     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
 822         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->GetData(); 
 823         if ( child
->m_isShown 
) 
 824             child
->MacSuperEnabled( enabled 
) ; 
 825         node 
= node
->GetNext(); 
 829 bool wxWindowMac::MacIsReallyShown() const 
 831     if ( m_isShown 
&& (m_parent 
!= NULL
) ) { 
 832         return m_parent
->MacIsReallyShown(); 
 836     bool status = m_isShown ; 
 837     wxWindowMac * win = this ; 
 838     while ( status && win->m_parent != NULL ) 
 840         win = win->m_parent ; 
 841         status = win->m_isShown ; 
 847 int wxWindowMac::GetCharHeight() const 
 849     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 850     return dc
.GetCharHeight() ; 
 853 int wxWindowMac::GetCharWidth() const 
 855     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 856     return dc
.GetCharWidth() ; 
 859 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
, 
 860                            int *descent
, int *externalLeading
, const wxFont 
*theFont 
) const 
 862     const wxFont 
*fontToUse 
= theFont
; 
 866     wxClientDC 
dc( (wxWindowMac
*) this ) ; 
 868     dc
.GetTextExtent( string 
, &lx 
, &ly 
, &ld
, &le
, (wxFont 
*)fontToUse 
) ; 
 869     if ( externalLeading 
) 
 870         *externalLeading 
= le 
; 
 880  * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect 
 881  * we always intersect with the entire window, not only with the client area 
 884 void wxWindowMac::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 886     if ( MacGetTopLevelWindow() == NULL 
) 
 889     if ( !MacIsReallyShown() ) 
 892      wxPoint client 
= GetClientAreaOrigin(); 
 895     int x2 
= m_width 
- client
.x
; 
 896     int y2 
= m_height 
- client
.y
; 
 898     if (IsKindOf( CLASSINFO(wxButton
))) 
 900         // buttons have an "aura" 
 907     Rect clientrect 
= { y1
, x1
, y2
, x2 
}; 
 911         Rect r 
= { rect
->y 
, rect
->x 
, rect
->y 
+ rect
->height 
, rect
->x 
+ rect
->width 
} ; 
 912         SectRect( &clientrect 
, &r 
, &clientrect 
) ; 
 915     if ( !EmptyRect( &clientrect 
) ) 
 917       int top 
= 0 , left 
= 0 ; 
 919       MacClientToRootWindow( &left 
, &top 
) ; 
 920       OffsetRect( &clientrect 
, left 
, top 
) ; 
 922       MacGetTopLevelWindow()->MacInvalidate( &clientrect 
, eraseBack 
) ; 
 926 #if wxUSE_CARET && WXWIN_COMPATIBILITY 
 927 // --------------------------------------------------------------------------- 
 928 // Caret manipulation 
 929 // --------------------------------------------------------------------------- 
 931 void wxWindowMac::CreateCaret(int w
, int h
) 
 933     SetCaret(new wxCaret(this, w
, h
)); 
 936 void wxWindowMac::CreateCaret(const wxBitmap 
*WXUNUSED(bitmap
)) 
 938     wxFAIL_MSG("not implemented"); 
 941 void wxWindowMac::ShowCaret(bool show
) 
 943     wxCHECK_RET( m_caret
, "no caret to show" ); 
 948 void wxWindowMac::DestroyCaret() 
 953 void wxWindowMac::SetCaretPos(int x
, int y
) 
 955     wxCHECK_RET( m_caret
, "no caret to move" ); 
 960 void wxWindowMac::GetCaretPos(int *x
, int *y
) const 
 962     wxCHECK_RET( m_caret
, "no caret to get position of" ); 
 964     m_caret
->GetPosition(x
, y
); 
 966 #endif // wxUSE_CARET 
 968 wxWindowMac 
*wxGetActiveWindow() 
 970     // actually this is a windows-only concept 
 974 // Coordinates relative to the window 
 975 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
) 
 977     // We really don't move the mouse programmatically under Mac. 
 980 const wxBrush
& wxWindowMac::MacGetBackgroundBrush() 
 982     if ( m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 984         m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground 
) ; 
 986     else if (  m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) ) 
 988         // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether 
 989         // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have 
 990         // either a non gray background color or a non control window 
 992         WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 994         wxWindowMac
* parent 
= GetParent() ; 
 997             if ( parent
->MacGetRootWindow() != window 
) 
 999                 // we are in a different window on the mac system 
1005                 if ( parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) 
1006                     && parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
1008                     // if we have any other colours in the hierarchy 
1009                     m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour 
) ; 
1012                 // if we have the normal colours in the hierarchy but another control etc. -> use it's background 
1013                 if ( parent
->IsKindOf( CLASSINFO( wxNotebook 
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl 
) )) 
1015                     Rect extent 
= { 0 , 0 , 0 , 0 } ; 
1018                     wxSize size 
= parent
->GetSize() ; 
1019                     parent
->MacClientToRootWindow( &x 
, &y 
) ; 
1023                     extent
.right 
= x 
+ size
.x 
; 
1024                     extent
.bottom 
= y 
+ size
.y 
; 
1025                     m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane 
, (WXRECTPTR
) &extent 
) ; // todo eventually change for inactive 
1029             parent 
= parent
->GetParent() ; 
1033             m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive 
) ; // todo eventually change for inactive 
1038         m_macBackgroundBrush
.SetColour( m_backgroundColour 
) ; 
1041     return m_macBackgroundBrush 
; 
1044 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
) 
1046     event
.GetDC()->Clear() ; 
1049 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event 
) 
1051     wxWindowDC 
dc(this) ; 
1052     wxMacPortSetter 
helper(&dc
) ; 
1054     MacPaintBorders( dc
.m_macLocalOrigin
.x 
, dc
.m_macLocalOrigin
.y
) ; 
1057 int wxWindowMac::GetScrollPos(int orient
) const 
1059     if ( orient 
== wxHORIZONTAL 
) 
1062            return m_hScrollBar
->GetThumbPosition() ; 
1067            return m_vScrollBar
->GetThumbPosition() ; 
1072 // This now returns the whole range, not just the number 
1073 // of positions that we can scroll. 
1074 int wxWindowMac::GetScrollRange(int orient
) const 
1076     if ( orient 
== wxHORIZONTAL 
) 
1079            return m_hScrollBar
->GetRange() ; 
1084            return m_vScrollBar
->GetRange() ; 
1089 int wxWindowMac::GetScrollThumb(int orient
) const 
1091     if ( orient 
== wxHORIZONTAL 
) 
1094            return m_hScrollBar
->GetThumbSize() ; 
1099            return m_vScrollBar
->GetThumbSize() ; 
1104 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
) 
1106     if ( orient 
== wxHORIZONTAL 
) 
1109            m_hScrollBar
->SetThumbPosition( pos 
) ; 
1114            m_vScrollBar
->SetThumbPosition( pos 
) ; 
1118 void wxWindowMac::MacPaintBorders( int left 
, int top 
) 
1123     RGBColor white 
= { 0xFFFF, 0xFFFF , 0xFFFF } ; 
1124     RGBColor black 
= { 0x0000, 0x0000 , 0x0000 } ; 
1125     RGBColor face 
= { 0xDDDD, 0xDDDD , 0xDDDD } ; 
1126     RGBColor shadow 
= { 0x4444, 0x4444 , 0x4444 } ; 
1129     if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) ) 
1131 #if wxMAC_USE_THEME_BORDER 
1132           Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1135           GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; 
1136           InsetRect( &rect , border , border ); 
1137       DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; 
1140         DrawThemePrimaryGroup(&rect  
,IsEnabled() ? kThemeStateActive 
: kThemeStateInactive
) ; 
1142         bool sunken 
= HasFlag( wxSUNKEN_BORDER 
) ; 
1143         RGBForeColor( &face 
); 
1144         MoveTo( left 
+ 0 , top 
+ m_height 
- 2 ); 
1145         LineTo( left 
+ 0 , top 
+ 0 ); 
1146         LineTo( left 
+ m_width 
- 2 , top 
+ 0 ); 
1148         MoveTo( left 
+ 2 , top 
+ m_height 
- 3 ); 
1149         LineTo( left 
+ m_width 
- 3 , top 
+ m_height 
- 3 ); 
1150         LineTo( left 
+ m_width 
- 3 , top 
+ 2 ); 
1152         RGBForeColor( sunken 
? &face 
: &black 
); 
1153         MoveTo( left 
+ 0 , top 
+ m_height 
- 1 ); 
1154         LineTo( left 
+ m_width 
- 1 , top 
+ m_height 
- 1 ); 
1155         LineTo( left 
+ m_width 
- 1 , top 
+ 0 ); 
1157         RGBForeColor( sunken 
? &shadow 
: &white 
); 
1158         MoveTo( left 
+ 1 , top 
+ m_height 
- 3 ); 
1159         LineTo( left 
+ 1, top 
+ 1 ); 
1160         LineTo( left 
+ m_width 
- 3 , top 
+ 1 ); 
1162         RGBForeColor( sunken 
? &white 
: &shadow 
); 
1163         MoveTo( left 
+ 1 , top 
+ m_height 
- 2 ); 
1164         LineTo( left 
+ m_width 
- 2 , top 
+ m_height 
- 2 ); 
1165         LineTo( left 
+ m_width 
- 2 , top 
+ 1 ); 
1167         RGBForeColor( sunken 
? &black 
: &face 
); 
1168         MoveTo( left 
+ 2 , top 
+ m_height 
- 4 ); 
1169         LineTo( left 
+ 2 , top 
+ 2 ); 
1170         LineTo( left 
+ m_width 
- 4 , top 
+ 2 ); 
1173     else if (HasFlag(wxSIMPLE_BORDER
)) 
1175             Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1176         RGBForeColor( &black 
) ; 
1177         FrameRect( &rect 
) ; 
1181 void wxWindowMac::RemoveChild( wxWindowBase 
*child 
) 
1183     if ( child 
== m_hScrollBar 
) 
1184         m_hScrollBar 
= NULL 
; 
1185     if ( child 
== m_vScrollBar 
) 
1186         m_vScrollBar 
= NULL 
; 
1188     wxWindowBase::RemoveChild( child 
) ; 
1191 // New function that will replace some of the above. 
1192 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
, 
1193     int range
, bool refresh
) 
1195     if ( orient 
== wxHORIZONTAL 
) 
1199             if ( range 
== 0 || thumbVisible 
>= range 
) 
1201                 if ( m_hScrollBar
->IsShown() ) 
1202                     m_hScrollBar
->Show(false) ; 
1206                 if ( !m_hScrollBar
->IsShown() ) 
1207                     m_hScrollBar
->Show(true) ; 
1208                 m_hScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1216             if ( range 
== 0 || thumbVisible 
>= range 
) 
1218                 if ( m_vScrollBar
->IsShown() ) 
1219                     m_vScrollBar
->Show(false) ; 
1223                 if ( !m_vScrollBar
->IsShown() ) 
1224                     m_vScrollBar
->Show(true) ; 
1225                 m_vScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1229     MacRepositionScrollBars() ; 
1232 // Does a physical scroll 
1233 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
1235     wxClientDC 
dc(this) ; 
1236     wxMacPortSetter 
helper(&dc
) ; 
1239         int width 
, height 
; 
1240         GetClientSize( &width 
, &height 
) ; 
1242         Rect scrollrect 
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ; 
1243         RgnHandle updateRgn 
= NewRgn() ; 
1244         ClipRect( &scrollrect 
) ; 
1247             Rect r 
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y 
+ rect
->height
) , 
1248                 dc
.XLOG2DEVMAC(rect
->x 
+ rect
->width
) } ; 
1249             SectRect( &scrollrect 
, &r 
, &scrollrect 
) ; 
1251         ScrollRect( &scrollrect 
, dx 
, dy 
, updateRgn 
) ; 
1252         InvalWindowRgn( (WindowRef
) MacGetRootWindow() ,  updateRgn 
) ; 
1253         DisposeRgn( updateRgn 
) ; 
1256     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1258         wxWindowMac 
*child 
= node
->GetData(); 
1259         if (child 
== m_vScrollBar
) continue; 
1260         if (child 
== m_hScrollBar
) continue; 
1261         if (child
->IsTopLevel()) continue; 
1264         child
->GetPosition( &x
, &y 
); 
1266         child
->GetSize( &w
, &h 
); 
1267         child
->SetSize( x
+dx
, y
+dy
, w
, h 
); 
1272 void wxWindowMac::MacOnScroll(wxScrollEvent 
&event 
) 
1274     if ( event
.m_eventObject 
== m_vScrollBar 
|| event
.m_eventObject 
== m_hScrollBar 
) 
1276         wxScrollWinEvent wevent
; 
1277         wevent
.SetPosition(event
.GetPosition()); 
1278         wevent
.SetOrientation(event
.GetOrientation()); 
1279         wevent
.m_eventObject 
= this; 
1281         if (event
.m_eventType 
== wxEVT_SCROLL_TOP
) 
1282             wevent
.m_eventType 
= wxEVT_SCROLLWIN_TOP
; 
1283         else if (event
.m_eventType 
== wxEVT_SCROLL_BOTTOM
) 
1284             wevent
.m_eventType 
= wxEVT_SCROLLWIN_BOTTOM
; 
1285         else if (event
.m_eventType 
== wxEVT_SCROLL_LINEUP
) 
1286             wevent
.m_eventType 
= wxEVT_SCROLLWIN_LINEUP
; 
1287         else if (event
.m_eventType 
== wxEVT_SCROLL_LINEDOWN
) 
1288             wevent
.m_eventType 
= wxEVT_SCROLLWIN_LINEDOWN
; 
1289         else if (event
.m_eventType 
== wxEVT_SCROLL_PAGEUP
) 
1290             wevent
.m_eventType 
= wxEVT_SCROLLWIN_PAGEUP
; 
1291         else if (event
.m_eventType 
== wxEVT_SCROLL_PAGEDOWN
) 
1292             wevent
.m_eventType 
= wxEVT_SCROLLWIN_PAGEDOWN
; 
1293         else if (event
.m_eventType 
== wxEVT_SCROLL_THUMBTRACK
) 
1294             wevent
.m_eventType 
= wxEVT_SCROLLWIN_THUMBTRACK
; 
1295         else if (event
.m_eventType 
== wxEVT_SCROLL_THUMBRELEASE
) 
1296             wevent
.m_eventType 
= wxEVT_SCROLLWIN_THUMBRELEASE
; 
1298         GetEventHandler()->ProcessEvent(wevent
); 
1302 // Get the window with the focus 
1303 wxWindowMac 
*wxWindowBase::FindFocus() 
1305     return gFocusWindow 
; 
1308 #if WXWIN_COMPATIBILITY 
1309 // If nothing defined for this, try the parent. 
1310 // E.g. we may be a button loaded from a resource, with no callback function 
1312 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
) 
1314     if ( GetEventHandler()->ProcessEvent(event
)  ) 
1317         m_parent
->GetEventHandler()->OnCommand(win
, event
); 
1319 #endif // WXWIN_COMPATIBILITY_2 
1321 #if WXWIN_COMPATIBILITY 
1322 wxObject
* wxWindowMac::GetChild(int number
) const 
1324     // Return a pointer to the Nth object in the Panel 
1325     wxNode 
*node 
= GetChildren().GetFirst(); 
1328         node 
= node
->GetNext(); 
1331         wxObject 
*obj 
= (wxObject 
*)node
->GetData(); 
1337 #endif // WXWIN_COMPATIBILITY 
1339 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
) 
1341     // panel wants to track the window which was the last to have focus in it, 
1342     // so we want to set ourselves as the window which last had focus 
1344     // notice that it's also important to do it upwards the tree becaus 
1345     // otherwise when the top level panel gets focus, it won't set it back to 
1346     // us, but to some other sibling 
1348     // CS:don't know if this is still needed: 
1349     //wxChildFocusEvent eventFocus(this); 
1350     //(void)GetEventHandler()->ProcessEvent(eventFocus); 
1355 void wxWindowMac::Clear() 
1357     wxClientDC 
dc(this); 
1358     wxBrush 
brush(GetBackgroundColour(), wxSOLID
); 
1359     dc
.SetBackground(brush
); 
1363 // Setup background and foreground colours correctly 
1364 void wxWindowMac::SetupColours() 
1367         SetBackgroundColour(GetParent()->GetBackgroundColour()); 
1370 void wxWindowMac::OnIdle(wxIdleEvent
& event
) 
1372     // This calls the UI-update mechanism (querying windows for 
1373     // menu/toolbar/control state information) 
1374     if (wxUpdateUIEvent::CanUpdate()) 
1378 // Raise the window to the top of the Z order 
1379 void wxWindowMac::Raise() 
1383 // Lower the window to the bottom of the Z order 
1384 void wxWindowMac::Lower() 
1388 void wxWindowMac::DoSetClientSize(int width
, int height
) 
1390     if ( width 
!= -1 || height 
!= -1 ) 
1393         if ( width 
!= -1 && m_vScrollBar 
) 
1394             width 
+= MAC_SCROLLBAR_SIZE 
; 
1395         if ( height 
!= -1 && m_vScrollBar 
) 
1396             height 
+= MAC_SCROLLBAR_SIZE 
; 
1398         width 
+= MacGetLeftBorderSize(  ) + MacGetRightBorderSize( ) ; 
1399         height 
+= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ) ; 
1401         DoSetSize( -1 , -1 , width 
, height 
) ; 
1406 wxWindowMac
* wxWindowMac::s_lastMouseWindow 
= NULL 
; 
1408 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint 
&point 
, wxWindowMac
** outWin 
) 
1412         if ((point
.x 
< 0) || (point
.y 
< 0) || 
1413             (point
.x 
> (m_width
)) || (point
.y 
> (m_height
))) 
1418         if ((point
.x 
< m_x
) || (point
.y 
< m_y
) || 
1419             (point
.x 
> (m_x 
+ m_width
)) || (point
.y 
> (m_y 
+ m_height
))) 
1423     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1425     wxPoint 
newPoint( point 
) ; 
1427     if ( !IsTopLevel() ) 
1433     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1435         wxWindowMac 
*child 
= node
->GetData(); 
1436         // added the m_isShown test --dmazzoni 
1437         if ( child
->MacGetRootWindow() == window 
&& child
->m_isShown 
) 
1439             if (child
->MacGetWindowFromPointSub(newPoint 
, outWin 
)) 
1448 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint 
&screenpoint 
, wxWindowMac
** outWin 
) 
1452     Point pt 
= { screenpoint
.y 
, screenpoint
.x 
} ; 
1453     if ( ::FindWindow( pt 
, &window 
) == 3 ) 
1456         wxWindowMac
* win 
= wxFindWinFromMacWindow( window 
) ; 
1459             // No, this yields the CLIENT are, we need the whole frame. RR. 
1460             // point = win->ScreenToClient( point ) ; 
1463             ::GetPort( &port 
) ; 
1464             ::SetPort( UMAGetWindowPort( window 
) ) ; 
1465             ::GlobalToLocal( &pt 
) ; 
1468             wxPoint 
point( pt
.h
, pt
.v 
) ; 
1470             return win
->MacGetWindowFromPointSub( point 
, outWin 
) ; 
1476 static wxWindow 
*gs_lastWhich 
= NULL
; 
1478 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
) 
1480     // first trigger a set cursor event 
1482     wxPoint clientorigin 
= GetClientAreaOrigin() ; 
1483     wxSize clientsize 
= GetClientSize() ; 
1485     if ( wxRect2DInt( clientorigin
.x 
, clientorigin
.y 
, clientsize
.x 
, clientsize
.y 
).Contains( wxPoint2DInt( pt 
) ) ) 
1487         wxSetCursorEvent 
event( pt
.x 
, pt
.y 
); 
1489         bool processedEvtSetCursor 
= GetEventHandler()->ProcessEvent(event
); 
1490         if ( processedEvtSetCursor 
&& event
.HasCursor() ) 
1492             cursor 
= event
.GetCursor() ; 
1497             // the test for processedEvtSetCursor is here to prevent using m_cursor 
1498             // if the user code caught EVT_SET_CURSOR() and returned nothing from 
1499             // it - this is a way to say that our cursor shouldn't be used for this 
1501             if ( !processedEvtSetCursor 
&& m_cursor
.Ok() ) 
1511                     cursor 
= *wxSTANDARD_CURSOR  
; 
1515             cursor
.MacInstall() ; 
1517     return cursor
.Ok() ; 
1520 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
) 
1522     if ((event
.m_x 
< m_x
) || (event
.m_y 
< m_y
) || 
1523         (event
.m_x 
> (m_x 
+ m_width
)) || (event
.m_y 
> (m_y 
+ m_height
))) 
1527     if ( IsKindOf( CLASSINFO ( wxStaticBox 
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */) 
1530     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1538     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1540         wxWindowMac 
*child 
= node
->GetData(); 
1541         if ( child
->MacGetRootWindow() == window 
&& child
->IsShown() && child
->IsEnabled() ) 
1543             if (child
->MacDispatchMouseEvent(event
)) 
1548     wxWindow
* cursorTarget 
= this ; 
1549     wxPoint 
cursorPoint( x 
, y 
) ; 
1551     while( cursorTarget 
&& !cursorTarget
->MacSetupCursor( cursorPoint 
) ) 
1553         cursorTarget 
= cursorTarget
->GetParent() ; 
1555             cursorPoint 
+= cursorTarget
->GetPosition() ; 
1559     event
.SetEventObject( this ) ; 
1561     if ( event
.GetEventType() == wxEVT_LEFT_DOWN 
) 
1563         // set focus to this window 
1564         if (AcceptsFocus() && FindFocus()!=this) 
1569     if ( event
.GetEventType() == wxEVT_MOTION
 
1570         || event
.GetEventType() == wxEVT_ENTER_WINDOW
 
1571         || event
.GetEventType() == wxEVT_LEAVE_WINDOW 
) 
1572         wxToolTip::RelayEvent( this , event
); 
1573 #endif // wxUSE_TOOLTIPS 
1575     if (gs_lastWhich 
!= this) 
1577         gs_lastWhich 
= this; 
1579         // Double clicks must always occur on the same window 
1580         if (event
.GetEventType() == wxEVT_LEFT_DCLICK
) 
1581             event
.SetEventType( wxEVT_LEFT_DOWN 
); 
1582         if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) 
1583             event
.SetEventType( wxEVT_RIGHT_DOWN 
); 
1585         // Same for mouse up events 
1586         if (event
.GetEventType() == wxEVT_LEFT_UP
) 
1588         if (event
.GetEventType() == wxEVT_RIGHT_UP
) 
1592     GetEventHandler()->ProcessEvent( event 
) ; 
1597 wxString 
wxWindowMac::MacGetToolTipString( wxPoint 
&pt 
) 
1601         return m_tooltip
->GetTip() ; 
1603     return wxEmptyString 
; 
1606 void wxWindowMac::Update() 
1608     wxTopLevelWindowMac
* win 
= MacGetTopLevelWindow(  ) ; 
1611       win
->MacUpdate( 0 ) ; 
1612 #if TARGET_API_MAC_CARBON 
1613         if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) ) 
1615                 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL 
) ; 
1621 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const 
1623     wxTopLevelWindowMac
* win 
= NULL 
; 
1624     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1627         win 
= wxFindWinFromMacWindow( window 
) ; 
1632 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings 
) 
1634     RgnHandle visRgn 
= NewRgn() ; 
1635     RgnHandle tempRgn 
= NewRgn() ; 
1636     RgnHandle tempStaticBoxRgn 
= NewRgn() ; 
1638     SetRectRgn( visRgn 
, 0 , 0 , m_width 
, m_height 
) ; 
1640     //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox 
1641     if ( IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1643         int borderTop 
= 14 ; 
1644         int borderOther 
= 4 ; 
1646         SetRectRgn( tempStaticBoxRgn 
, borderOther 
, borderTop 
, m_width 
- borderOther 
, m_height 
- borderOther 
) ; 
1647         DiffRgn( visRgn 
, tempStaticBoxRgn 
, visRgn 
) ; 
1650     if ( !IsTopLevel() ) 
1652         wxWindow
* parent 
= GetParent() ; 
1655             wxSize size 
= parent
->GetSize() ; 
1658             parent
->MacWindowToRootWindow( &x
, &y 
) ; 
1659             MacRootWindowToWindow( &x 
, &y 
) ; 
1661             SetRectRgn( tempRgn 
, 
1662                 x 
+ parent
->MacGetLeftBorderSize() , y 
+ parent
->MacGetTopBorderSize() , 
1663                 x 
+ size
.x 
- parent
->MacGetRightBorderSize(), 
1664                 y 
+ size
.y 
- parent
->MacGetBottomBorderSize()) ; 
1666             SectRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1667             if ( parent
->IsTopLevel() ) 
1669             parent 
= parent
->GetParent() ; 
1672     if ( respectChildrenAndSiblings 
) 
1674         if ( GetWindowStyle() & wxCLIP_CHILDREN 
) 
1676             for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1678                 wxWindowMac 
*child 
= node
->GetData(); 
1680                 if ( !child
->IsTopLevel() && child
->IsShown() ) 
1682                     SetRectRgn( tempRgn 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1683                     if ( child
->IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1685                         int borderTop 
= 14 ; 
1686                         int borderOther 
= 4 ; 
1688                         SetRectRgn( tempStaticBoxRgn 
, child
->m_x 
+ borderOther 
, child
->m_y 
+ borderTop 
, child
->m_x 
+ child
->m_width 
- borderOther 
, child
->m_y 
+ child
->m_height 
- borderOther 
) ; 
1689                         DiffRgn( tempRgn 
, tempStaticBoxRgn 
, tempRgn 
) ; 
1691                     DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1696         if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() ) 
1698             bool thisWindowThrough 
= false ; 
1699             for (wxWindowListNode 
*node 
= GetParent()->GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1701                 wxWindowMac 
*sibling 
= node
->GetData(); 
1702                 if ( sibling 
== this ) 
1704                     thisWindowThrough 
= true ; 
1707                 if( !thisWindowThrough 
) 
1712                 if ( !sibling
->IsTopLevel() && sibling
->IsShown() ) 
1714                     SetRectRgn( tempRgn 
, sibling
->m_x 
- m_x 
, sibling
->m_y 
- m_y 
, sibling
->m_x 
+ sibling
->m_width 
- m_x 
,  sibling
->m_y 
+ sibling
->m_height 
- m_y 
) ; 
1715                     if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1717                         int borderTop 
= 14 ; 
1718                         int borderOther 
= 4 ; 
1720                         SetRectRgn( tempStaticBoxRgn 
, sibling
->m_x 
- m_x 
+ borderOther 
, sibling
->m_y 
- m_y 
+ borderTop 
, sibling
->m_x 
+ sibling
->m_width 
- m_x 
- borderOther 
, sibling
->m_y 
+ sibling
->m_height 
- m_y 
- borderOther 
) ; 
1721                         DiffRgn( tempRgn 
, tempStaticBoxRgn 
, tempRgn 
) ; 
1723                     DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1728     m_macVisibleRegion 
= visRgn 
; 
1729     DisposeRgn( visRgn 
) ; 
1730     DisposeRgn( tempRgn 
) ; 
1731     DisposeRgn( tempStaticBoxRgn 
) ; 
1732     return m_macVisibleRegion 
; 
1735 void wxWindowMac::MacRedraw( WXHRGN updatergnr 
, long time
, bool erase
) 
1737     RgnHandle updatergn 
= (RgnHandle
) updatergnr 
; 
1738     // updatergn is always already clipped to our boundaries 
1739     // it is in window coordinates, not in client coordinates 
1741     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1744         // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates 
1745         RgnHandle ownUpdateRgn 
= NewRgn() ; 
1746         CopyRgn( updatergn 
, ownUpdateRgn 
) ; 
1748         SectRgn( ownUpdateRgn 
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn 
) ; 
1750         // newupdate is the update region in client coordinates 
1751         RgnHandle newupdate 
= NewRgn() ; 
1752         wxSize point 
= GetClientSize() ; 
1753         wxPoint origin 
= GetClientAreaOrigin() ; 
1754         SetRectRgn( newupdate 
, origin
.x 
, origin
.y 
, origin
.x 
+ point
.x 
, origin
.y
+point
.y 
) ; 
1755         SectRgn( newupdate 
, ownUpdateRgn 
, newupdate 
) ; 
1756         OffsetRgn( newupdate 
, -origin
.x 
, -origin
.y 
) ; 
1757         m_updateRegion 
= newupdate 
; 
1758         DisposeRgn( newupdate 
) ; // it's been cloned to m_updateRegion 
1760         if ( erase 
&& !EmptyRgn(ownUpdateRgn
) ) 
1762             wxWindowDC 
dc(this); 
1763             if (!EmptyRgn(ownUpdateRgn
)) 
1764                 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
)); 
1765             wxEraseEvent 
eevent( GetId(), &dc 
); 
1766             eevent
.SetEventObject( this ); 
1767             GetEventHandler()->ProcessEvent( eevent 
); 
1769             wxNcPaintEvent 
eventNc( GetId() ); 
1770             eventNc
.SetEventObject( this ); 
1771             GetEventHandler()->ProcessEvent( eventNc 
); 
1773         DisposeRgn( ownUpdateRgn 
) ; 
1774         if ( !m_updateRegion
.Empty() ) 
1777             event
.m_timeStamp 
= time 
; 
1778             event
.SetEventObject(this); 
1779             GetEventHandler()->ProcessEvent(event
); 
1783     // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively 
1785     RgnHandle childupdate 
= NewRgn() ; 
1786     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1788         // calculate the update region for the child windows by intersecting the window rectangle with our own 
1789         // passed in update region and then offset it to be client-wise window coordinates again 
1790         wxWindowMac 
*child 
= node
->GetData(); 
1791         SetRectRgn( childupdate 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1792         SectRgn( childupdate 
, updatergn 
, childupdate 
) ; 
1793         OffsetRgn( childupdate 
, -child
->m_x 
, -child
->m_y 
) ; 
1794         if ( child
->MacGetRootWindow() == window 
&& child
->IsShown() && !EmptyRgn( childupdate 
) ) 
1796             // because dialogs may also be children 
1797             child
->MacRedraw( childupdate 
, time 
, erase 
) ; 
1800     DisposeRgn( childupdate 
) ; 
1801     // eventually a draw grow box here 
1805 WXHWND 
wxWindowMac::MacGetRootWindow() const 
1807     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1811         if ( iter
->IsTopLevel() ) 
1812             return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ; 
1814         iter 
= iter
->GetParent() ; 
1816     wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; 
1820 void wxWindowMac::MacCreateScrollBars( long style 
) 
1822     wxASSERT_MSG( m_vScrollBar 
== NULL 
&& m_hScrollBar 
== NULL 
, wxT("attempt to create window twice") ) ; 
1824     bool hasBoth 
= ( style 
& wxVSCROLL 
) && ( style 
& wxHSCROLL 
) ; 
1825     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1: 0 ; 
1827     GetClientSize( &width 
, &height 
) ; 
1829     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1830     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1831     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1832     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1834     m_vScrollBar 
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
, 
1835         vSize 
, wxVERTICAL
); 
1837     if ( style 
& wxVSCROLL 
) 
1843         m_vScrollBar
->Show(false) ; 
1845     m_hScrollBar 
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
, 
1846         hSize 
, wxHORIZONTAL
); 
1847     if ( style  
& wxHSCROLL 
) 
1852         m_hScrollBar
->Show(false) ; 
1855     // because the create does not take into account the client area origin 
1856     MacRepositionScrollBars() ; // we might have a real position shift 
1859 void wxWindowMac::MacRepositionScrollBars() 
1861     bool hasBoth 
= ( m_hScrollBar 
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar 
&& m_vScrollBar
->IsShown()) ; 
1862     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1 : 0 ; 
1864     // get real client area 
1866     int width 
= m_width 
; 
1867     int height 
= m_height 
; 
1869     width 
-= MacGetLeftBorderSize() + MacGetRightBorderSize(); 
1870     height 
-= MacGetTopBorderSize() + MacGetBottomBorderSize(); 
1872     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1873     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1874     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1875     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1882     MacClientToRootWindow( &x 
, &y 
) ; 
1883     MacClientToRootWindow( &w 
, &h 
) ; 
1885     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1887     int totW 
= 10000 , totH 
= 10000; 
1890         if ( iter
->IsTopLevel() ) 
1892             totW 
= iter
->m_width 
; 
1893             totH 
= iter
->m_height 
; 
1897         iter 
= iter
->GetParent() ; 
1925         m_vScrollBar
->SetSize( vPoint
.x 
, vPoint
.y
, vSize
.x
, vSize
.y 
, wxSIZE_ALLOW_MINUS_ONE
); 
1929         m_hScrollBar
->SetSize( hPoint
.x 
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
); 
1933 bool wxWindowMac::AcceptsFocus() const 
1935     return MacCanFocus() && wxWindowBase::AcceptsFocus(); 
1938 WXWidget 
wxWindowMac::MacGetContainerForEmbedding() 
1940     return GetParent()->MacGetContainerForEmbedding() ; 
1943 void wxWindowMac::MacSuperChangedPosition() 
1945     // only window-absolute structures have to be moved i.e. controls 
1947     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
1950         wxWindowMac 
*child 
= node
->GetData(); 
1951         child
->MacSuperChangedPosition() ; 
1952         node 
= node
->GetNext(); 
1956 void wxWindowMac::MacTopLevelWindowChangedPosition() 
1958     // only screen-absolute structures have to be moved i.e. glcanvas 
1960     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
1963         wxWindowMac 
*child 
= node
->GetData(); 
1964         child
->MacTopLevelWindowChangedPosition() ; 
1965         node 
= node
->GetNext(); 
1968 long wxWindowMac::MacGetLeftBorderSize( ) const 
1973     if (m_windowStyle 
& wxRAISED_BORDER 
|| m_windowStyle 
& wxSUNKEN_BORDER 
) 
1976 #if wxMAC_USE_THEME_BORDER 
1978           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
1983     else if (  m_windowStyle 
&wxDOUBLE_BORDER
) 
1986 #if wxMAC_USE_THEME_BORDER 
1988           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
1993     else if (m_windowStyle 
&wxSIMPLE_BORDER
) 
2000 long wxWindowMac::MacGetRightBorderSize( ) const 
2002     // they are all symmetric in mac themes 
2003     return MacGetLeftBorderSize() ; 
2006 long wxWindowMac::MacGetTopBorderSize( ) const 
2008     // they are all symmetric in mac themes 
2009     return MacGetLeftBorderSize() ; 
2012 long wxWindowMac::MacGetBottomBorderSize( ) const 
2014     // they are all symmetric in mac themes 
2015     return MacGetLeftBorderSize() ; 
2018 long wxWindowMac::MacRemoveBordersFromStyle( long style 
) 
2020     return style 
& ~( wxDOUBLE_BORDER 
| wxSUNKEN_BORDER 
| wxRAISED_BORDER 
| wxBORDER 
| wxSTATIC_BORDER 
) ; 
2023 // Find the wxWindowMac at the current mouse position, returning the mouse 
2025 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
) 
2027     pt 
= wxGetMousePosition(); 
2028     wxWindowMac
* found 
= wxFindWindowAtPoint(pt
); 
2032 // Get the current mouse position. 
2033 wxPoint 
wxGetMousePosition() 
2036     wxGetMousePosition(& x
, & y
); 
2037     return wxPoint(x
, y
); 
2040 void wxWindowMac::OnMouseEvent( wxMouseEvent 
&event 
) 
2042         if ( event
.GetEventType() == wxEVT_RIGHT_DOWN 
) 
2044                 // copied from wxGTK : CS 
2045         // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN 
2048         // (a) it's a command event and so is propagated to the parent 
2049         // (b) under MSW it can be generated from kbd too 
2050         // (c) it uses screen coords (because of (a)) 
2051         wxContextMenuEvent 
evtCtx(wxEVT_CONTEXT_MENU
, 
2053                                   this->ClientToScreen(event
.GetPosition())); 
2054         if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )