1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxWindowMac 
   8 // Copyright:   (c) AUTHOR 
   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" 
  44 #define wxWINDOW_HSCROLL 5998 
  45 #define wxWINDOW_VSCROLL 5997 
  46 #define MAC_SCROLLBAR_SIZE 16 
  48 #include "wx/mac/uma.h" 
  50 #if  wxUSE_DRAG_AND_DROP 
  56 extern wxList wxPendingDelete
; 
  57 wxWindowMac
* gFocusWindow 
= NULL 
; 
  59 #ifdef __WXUNIVERSAL__ 
  60     IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
) 
  62     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
) 
  63 #endif // __WXUNIVERSAL__/__WXMAC__ 
  65 #if !USE_SHARED_LIBRARY 
  67 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
) 
  68   EVT_NC_PAINT(wxWindowMac::OnNcPaint
) 
  69   EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
) 
  70   EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
) 
  71   EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
) 
  72   EVT_IDLE(wxWindowMac::OnIdle
) 
  73   EVT_SET_FOCUS(wxWindowMac::OnSetFocus
) 
  78 #define wxMAC_DEBUG_REDRAW 0 
  79 #ifndef wxMAC_DEBUG_REDRAW 
  80 #define wxMAC_DEBUG_REDRAW 0 
  83 #define wxMAC_USE_THEME_BORDER 0 
  86 // =========================================================================== 
  88 // =========================================================================== 
  91 // ---------------------------------------------------------------------------- 
  92 // constructors and such 
  93 // ---------------------------------------------------------------------------- 
  95 void wxWindowMac::Init() 
 101     m_doubleClickAllowed 
= 0; 
 102     m_winCaptured 
= FALSE
; 
 104     m_isBeingDeleted 
= FALSE
; 
 107     m_mouseInWindow 
= FALSE
; 
 111     m_backgroundTransparent 
= FALSE
; 
 113     // as all windows are created with WS_VISIBLE style... 
 121     m_hScrollBar 
= NULL 
; 
 122     m_vScrollBar 
= NULL 
; 
 124 #if  wxUSE_DRAG_AND_DROP 
 125   m_pDropTarget 
= NULL
; 
 130 wxWindowMac::~wxWindowMac() 
 132     // deleting a window while it is shown invalidates the region 
 134         wxWindowMac
* iter 
= this ; 
 136             if ( iter
->IsTopLevel() ) 
 141             iter 
= iter
->GetParent() ; 
 146     m_isBeingDeleted 
= TRUE
; 
 148     if ( s_lastMouseWindow 
== this ) 
 150         s_lastMouseWindow 
= NULL 
; 
 153     if ( gFocusWindow 
== this ) 
 155         gFocusWindow 
= NULL 
; 
 159         m_parent
->RemoveChild(this); 
 165 bool wxWindowMac::Create(wxWindowMac 
*parent
, wxWindowID id
, 
 169            const wxString
& name
) 
 171     wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") ); 
 173     if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) ) 
 176     parent
->AddChild(this); 
 180     AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
); 
 181     m_width 
= WidthDefault( size
.x 
); 
 182     m_height 
= HeightDefault( size
.y 
) ; 
 183 #ifndef __WXUNIVERSAL__ 
 184     if ( ! IsKindOf( CLASSINFO ( wxControl 
) ) && ! IsKindOf( CLASSINFO( wxStatusBar 
) ) ) 
 186         MacCreateScrollBars( style 
) ; 
 192 void wxWindowMac::SetFocus() 
 194     if ( gFocusWindow 
== this ) 
 197     if ( AcceptsFocus() ) 
 203                 if ( gFocusWindow
->m_caret 
) 
 205                       gFocusWindow
->m_caret
->OnKillFocus(); 
 207             #endif // wxUSE_CARET 
 208       #ifndef __WXUNIVERSAL__ 
 209             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 210             if ( control 
&& control
->GetMacControl() ) 
 212                 UMASetKeyboardFocus( gFocusWindow
->MacGetRootWindow() , control
->GetMacControl()  , kControlFocusNoPart 
) ; 
 213                 control
->MacRedrawControl() ; 
 216             wxFocusEvent 
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
); 
 217             event
.SetEventObject(gFocusWindow
); 
 218             gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ; 
 220         gFocusWindow 
= this ; 
 226                 m_caret
->OnSetFocus(); 
 228             #endif // wxUSE_CARET 
 229             // panel wants to track the window which was the last to have focus in it 
 230             wxChildFocusEvent 
eventFocus(this); 
 231             GetEventHandler()->ProcessEvent(eventFocus
); 
 233       #ifndef __WXUNIVERSAL__ 
 234             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 235             if ( control 
&& control
->GetMacControl() ) 
 237                 UMASetKeyboardFocus( gFocusWindow
->MacGetRootWindow() , control
->GetMacControl()  , kControlEditTextPart 
) ; 
 240             wxFocusEvent 
event(wxEVT_SET_FOCUS
, m_windowId
); 
 241             event
.SetEventObject(this); 
 242             GetEventHandler()->ProcessEvent(event
) ; 
 247 bool wxWindowMac::Enable(bool enable
) 
 249     if ( !wxWindowBase::Enable(enable
) ) 
 252     MacSuperEnabled( enable 
) ; 
 257 void wxWindowMac::CaptureMouse() 
 259     wxTheApp
->s_captureWindow 
= this ; 
 262 wxWindow
* wxWindowBase::GetCapture() 
 264     return wxTheApp
->s_captureWindow 
; 
 267 void wxWindowMac::ReleaseMouse() 
 269     wxTheApp
->s_captureWindow 
= NULL 
; 
 272 #if    wxUSE_DRAG_AND_DROP 
 274 void wxWindowMac::SetDropTarget(wxDropTarget 
*pDropTarget
) 
 276   if ( m_pDropTarget 
!= 0 ) { 
 277     delete m_pDropTarget
; 
 280   m_pDropTarget 
= pDropTarget
; 
 281   if ( m_pDropTarget 
!= 0 ) 
 289 // Old style file-manager drag&drop 
 290 void wxWindowMac::DragAcceptFiles(bool accept
) 
 296 void wxWindowMac::DoGetSize(int *x
, int *y
) const 
 299      if(y
)   *y 
= m_height 
; 
 302 void wxWindowMac::DoGetPosition(int *x
, int *y
) const 
 308     if ( !IsTopLevel() && GetParent()) 
 310         wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
 319 bool wxWindowMac::DoPopupMenu(wxMenu 
*menu
, int x
, int y
) 
 321     menu
->SetInvokingWindow(this); 
 323     ClientToScreen( &x 
, &y 
) ; 
 325     ::InsertMenu( menu
->GetHMenu() , -1 ) ; 
 326     long menuResult 
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ; 
 327     menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ; 
 328     ::DeleteMenu( menu
->MacGetMenuId() ) ; 
 329     menu
->SetInvokingWindow(NULL
); 
 335 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const 
 337     WindowRef window 
= MacGetRootWindow() ; 
 339     Point       localwhere 
= {0,0} ; 
 341     if(x
)   localwhere
.h 
= * x 
; 
 342     if(y
)   localwhere
.v 
= * y 
; 
 346     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 347     ::GlobalToLocal( &localwhere 
) ; 
 350     if(x
)   *x 
= localwhere
.h 
; 
 351     if(y
)   *y 
= localwhere
.v 
; 
 353     MacRootWindowToClient( x 
, y 
) ; 
 356 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const 
 358     WindowRef window 
= MacGetRootWindow() ; 
 360     MacClientToRootWindow( x 
, y 
) ; 
 362     Point       localwhere 
= { 0,0 }; 
 363     if(x
)   localwhere
.h 
= * x 
; 
 364     if(y
)   localwhere
.v 
= * y 
; 
 368     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 369     ::SetOrigin( 0 , 0 ) ; 
 370     ::LocalToGlobal( &localwhere 
) ; 
 372     if(x
)   *x 
= localwhere
.h 
; 
 373     if(y
)   *y 
= localwhere
.v 
; 
 376 void wxWindowMac::MacClientToRootWindow( int *x 
, int *y 
) const 
 378     wxPoint origin 
= GetClientAreaOrigin() ; 
 379     if(x
)   *x 
+= origin
.x 
; 
 380     if(y
)   *y 
+= origin
.y 
; 
 382     MacWindowToRootWindow( x 
, y 
) ; 
 385 void wxWindowMac::MacRootWindowToClient( int *x 
, int *y 
) const 
 387     wxPoint origin 
= GetClientAreaOrigin() ; 
 388     MacRootWindowToWindow( x 
, y 
) ; 
 389     if(x
)   *x 
-= origin
.x 
; 
 390     if(y
)   *y 
-= origin
.y 
; 
 393 void wxWindowMac::MacWindowToRootWindow( int *x 
, int *y 
) const 
 399         GetParent()->MacWindowToRootWindow( x 
, y 
) ; 
 403 void wxWindowMac::MacRootWindowToWindow( int *x 
, int *y 
) const 
 409         GetParent()->MacRootWindowToWindow( x 
, y 
) ; 
 413 bool wxWindowMac::SetCursor(const wxCursor
& cursor
) 
 415     if (m_cursor 
== cursor
) 
 418     if (wxNullCursor 
== cursor
) 
 420        if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR 
) ) 
 425        if ( ! wxWindowBase::SetCursor( cursor 
) ) 
 429   wxASSERT_MSG( m_cursor
.Ok(), 
 430                   wxT("cursor must be valid after call to the base version")); 
 433   wxWindowMac 
*mouseWin 
; 
 436   // Change the cursor NOW if we're within the correct window 
 438   if ( MacGetWindowFromPoint( wxPoint( pt
.h 
, pt
.v 
) , &mouseWin 
) ) 
 440     if ( mouseWin 
== this && !wxIsBusy() ) 
 442         m_cursor
.MacInstall() ; 
 450 // Get size *available for subwindows* i.e. excluding menu bar etc. 
 451 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const 
 457     ww 
-= MacGetLeftBorderSize(  )  + MacGetRightBorderSize(  ) ; 
 458     hh 
-= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ); 
 460   if ( (m_vScrollBar 
&& m_vScrollBar
->IsShown()) || (m_hScrollBar  
&& m_hScrollBar
->IsShown()) ) 
 467     MacClientToRootWindow( &x1 
, &y1 
) ; 
 468     MacClientToRootWindow( &w 
, &h 
) ; 
 470     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
 472     int totW 
= 10000 , totH 
= 10000; 
 475         if ( iter
->IsTopLevel() ) 
 477             totW 
= iter
->m_width 
; 
 478             totH 
= iter
->m_height 
; 
 482         iter 
= iter
->GetParent() ; 
 485     if (m_hScrollBar  
&& m_hScrollBar
->IsShown() ) 
 487         hh 
-= MAC_SCROLLBAR_SIZE
; 
 493     if (m_vScrollBar  
&& m_vScrollBar
->IsShown() ) 
 495         ww 
-= MAC_SCROLLBAR_SIZE
; 
 507 // ---------------------------------------------------------------------------- 
 509 // ---------------------------------------------------------------------------- 
 513 void wxWindowMac::DoSetToolTip(wxToolTip 
*tooltip
) 
 515     wxWindowBase::DoSetToolTip(tooltip
); 
 518         m_tooltip
->SetWindow(this); 
 521 #endif // wxUSE_TOOLTIPS 
 523 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
) 
 527     int former_w 
= m_width 
; 
 528     int former_h 
= m_height 
; 
 530   int actualWidth 
= width
; 
 531   int actualHeight 
= height
; 
 535     if ((m_minWidth 
!= -1) && (actualWidth 
< m_minWidth
))  
 536         actualWidth 
= m_minWidth
; 
 537     if ((m_minHeight 
!= -1) && (actualHeight 
< m_minHeight
))  
 538         actualHeight 
= m_minHeight
; 
 539     if ((m_maxWidth 
!= -1) && (actualWidth 
> m_maxWidth
))  
 540         actualWidth 
= m_maxWidth
; 
 541     if ((m_maxHeight 
!= -1) && (actualHeight 
> m_maxHeight
))  
 542         actualHeight 
= m_maxHeight
; 
 544     bool doMove 
= false ; 
 545     bool doResize 
= false ; 
 547     if ( actualX 
!= former_x 
|| actualY 
!= former_y 
) 
 551     if ( actualWidth 
!= former_w 
|| actualHeight 
!= former_h 
) 
 556     if ( doMove 
|| doResize 
) 
 558         // erase former position 
 559         wxMacDrawingHelper 
focus( this ) ; 
 562             Rect clientrect 
= { 0 , 0 , m_height 
, m_width 
} ; 
 563             // ClipRect( &clientrect ) ; 
 564             InvalWindowRect( MacGetRootWindow() , &clientrect 
) ; 
 569         m_width 
= actualWidth 
; 
 570         m_height 
= actualHeight 
; 
 571         // erase new position 
 574             wxMacDrawingHelper 
focus( this ) ; 
 577                 Rect clientrect 
= { 0 , 0 , m_height 
, m_width 
} ; 
 578                 // ClipRect( &clientrect ) ; 
 579                 InvalWindowRect( MacGetRootWindow() , &clientrect 
) ; 
 584             wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified 
 586         MacRepositionScrollBars() ; 
 589             wxPoint 
point(m_x
, m_y
); 
 590             wxMoveEvent 
event(point
, m_windowId
); 
 591             event
.SetEventObject(this); 
 592             GetEventHandler()->ProcessEvent(event
) ; 
 596              MacRepositionScrollBars() ; 
 597              wxSize 
size(m_width
, m_height
); 
 598              wxSizeEvent 
event(size
, m_windowId
); 
 599              event
.SetEventObject(this); 
 600              GetEventHandler()->ProcessEvent(event
); 
 606 // set the size of the window: if the dimensions are positive, just use them, 
 607 // but if any of them is equal to -1, it means that we must find the value for 
 608 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in 
 609 // which case -1 is a valid value for x and y) 
 611 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate 
 612 // the width/height to best suit our contents, otherwise we reuse the current 
 614 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 616     // get the current size and position... 
 617     int currentX
, currentY
; 
 618     GetPosition(¤tX
, ¤tY
); 
 620     int currentW
,currentH
; 
 621     GetSize(¤tW
, ¤tH
); 
 623     // ... and don't do anything (avoiding flicker) if it's already ok 
 624     if ( x 
== currentX 
&& y 
== currentY 
&& 
 625          width 
== currentW 
&& height 
== currentH 
) 
 627         MacRepositionScrollBars() ; // we might have a real position shift 
 631     if ( x 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 633     if ( y 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 636     AdjustForParentClientOrigin(x
, y
, sizeFlags
); 
 641         if ( sizeFlags 
& wxSIZE_AUTO_WIDTH 
) 
 643             size 
= DoGetBestSize(); 
 648             // just take the current one 
 655         if ( sizeFlags 
& wxSIZE_AUTO_HEIGHT 
) 
 659                 size 
= DoGetBestSize(); 
 661             //else: already called DoGetBestSize() above 
 667             // just take the current one 
 672     DoMoveWindow(x
, y
, width
, height
); 
 675 // For implementation purposes - sometimes decorations make the client area 
 678 wxPoint 
wxWindowMac::GetClientAreaOrigin() const 
 680     return wxPoint(MacGetLeftBorderSize(  ) , MacGetTopBorderSize(  ) ); 
 683 void wxWindow::SetTitle(const wxString
& title
) 
 688 wxString 
wxWindow::GetTitle() const 
 693 bool wxWindowMac::Show(bool show
) 
 695     if ( !wxWindowBase::Show(show
) ) 
 698     MacSuperShown( show 
) ; 
 701         WindowRef window 
= MacGetRootWindow() ; 
 702         wxWindowMac
* win 
= wxFindWinFromMacWindow( window 
) ; 
 703         if ( win 
&& !win
->m_isBeingDeleted 
) 
 714 void wxWindowMac::MacSuperShown( bool show 
)  
 716     wxNode 
*node 
= GetChildren().First(); 
 719         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->Data(); 
 720         if ( child
->m_isShown 
) 
 721             child
->MacSuperShown( show 
) ; 
 726 void wxWindowMac::MacSuperEnabled( bool enabled 
)  
 730       // to be absolutely correct we'd have to invalidate (with eraseBkground  
 731       // because unter MacOSX the frames are drawn with an addXXX mode) 
 734     wxNode 
*node 
= GetChildren().First(); 
 737         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->Data(); 
 738         if ( child
->m_isShown 
) 
 739             child
->MacSuperEnabled( enabled 
) ; 
 744 bool wxWindowMac::MacIsReallyShown() const  
 746     if ( m_isShown 
&& (m_parent 
!= NULL
) ) { 
 747         return m_parent
->MacIsReallyShown(); 
 751     bool status = m_isShown ; 
 752     wxWindowMac * win = this ; 
 753     while ( status && win->m_parent != NULL ) 
 755         win = win->m_parent ; 
 756         status = win->m_isShown ; 
 762 int wxWindowMac::GetCharHeight() const 
 764     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 765     return dc
.GetCharHeight() ; 
 768 int wxWindowMac::GetCharWidth() const 
 770     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 771     return dc
.GetCharWidth() ; 
 774 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
, 
 775                            int *descent
, int *externalLeading
, const wxFont 
*theFont 
) const 
 777     const wxFont 
*fontToUse 
= theFont
; 
 781     wxClientDC 
dc( (wxWindowMac
*) this ) ; 
 783     dc
.GetTextExtent( string 
, &lx 
, &ly 
, &ld
, &le
, (wxFont 
*)fontToUse 
) ; 
 784     if ( externalLeading 
) 
 785         *externalLeading 
= le 
; 
 795  * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect  
 796  * we always intersect with the entire window, not only with the client area 
 799 void wxWindowMac::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 801     if ( MacGetTopLevelWindow() == NULL 
) 
 805     client 
= GetClientAreaOrigin( ) ; 
 806     Rect clientrect 
= { -client
.y 
, -client
.x 
, m_height 
- client
.y 
, m_width 
- client
.x
} ; 
 809         Rect r 
= { rect
->y 
, rect
->x 
, rect
->y 
+ rect
->height 
, rect
->x 
+ rect
->width 
} ; 
 810         SectRect( &clientrect 
, &r 
, &clientrect 
) ;         
 812     if ( !EmptyRect( &clientrect 
) ) 
 814       int top 
= 0 , left 
= 0 ; 
 816       MacClientToRootWindow( &left 
, &top 
) ; 
 817       OffsetRect( &clientrect 
, left 
, top 
) ; 
 819       MacGetTopLevelWindow()->MacInvalidate( &clientrect 
, eraseBack 
) ; 
 823 #if wxUSE_CARET && WXWIN_COMPATIBILITY 
 824 // --------------------------------------------------------------------------- 
 825 // Caret manipulation 
 826 // --------------------------------------------------------------------------- 
 828 void wxWindowMac::CreateCaret(int w
, int h
) 
 830     SetCaret(new wxCaret(this, w
, h
)); 
 833 void wxWindowMac::CreateCaret(const wxBitmap 
*WXUNUSED(bitmap
)) 
 835     wxFAIL_MSG("not implemented"); 
 838 void wxWindowMac::ShowCaret(bool show
) 
 840     wxCHECK_RET( m_caret
, "no caret to show" ); 
 845 void wxWindowMac::DestroyCaret() 
 850 void wxWindowMac::SetCaretPos(int x
, int y
) 
 852     wxCHECK_RET( m_caret
, "no caret to move" ); 
 857 void wxWindowMac::GetCaretPos(int *x
, int *y
) const 
 859     wxCHECK_RET( m_caret
, "no caret to get position of" ); 
 861     m_caret
->GetPosition(x
, y
); 
 863 #endif // wxUSE_CARET 
 865 wxWindowMac 
*wxGetActiveWindow() 
 867     // actually this is a windows-only concept 
 871 // Coordinates relative to the window 
 872 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
) 
 874     // We really dont move the mouse programmatically under mac 
 877 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()  
 879     if ( m_backgroundColour 
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 881         m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground 
) ; 
 883     else if (  m_backgroundColour 
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE 
) ) 
 885         // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether 
 886         // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have 
 887         // either a non gray background color or a non control window 
 889             WindowRef window 
= MacGetRootWindow() ; 
 891             wxWindowMac
* parent 
= GetParent() ; 
 894                 if ( parent
->MacGetRootWindow() != window 
) 
 896                     // we are in a different window on the mac system 
 902                     if ( parent
->m_backgroundColour 
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE 
)  
 903                       && parent
->m_backgroundColour 
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 905                         // if we have any other colours in the hierarchy 
 906                         m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour 
) ; 
 909                     // if we have the normal colours in the hierarchy but another control etc. -> use it's background 
 910                     if ( parent
->IsKindOf( CLASSINFO( wxNotebook 
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl 
) )) 
 912                         m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane 
) ; // todo eventually change for inactive 
 916                 parent 
= parent
->GetParent() ; 
 920               m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive 
) ; // todo eventually change for inactive 
 925         m_macBackgroundBrush
.SetColour( m_backgroundColour 
) ; 
 928     return m_macBackgroundBrush 
; 
 932 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
) 
 934     event
.GetDC()->Clear() ; 
 937 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event 
) 
 939     wxMacDrawingHelper 
focus( this ) ; 
 946 int wxWindowMac::GetScrollPos(int orient
) const 
 948     if ( orient 
== wxHORIZONTAL 
) 
 951            return m_hScrollBar
->GetThumbPosition() ; 
 956            return m_vScrollBar
->GetThumbPosition() ; 
 961 // This now returns the whole range, not just the number 
 962 // of positions that we can scroll. 
 963 int wxWindowMac::GetScrollRange(int orient
) const 
 965     if ( orient 
== wxHORIZONTAL 
) 
 968            return m_hScrollBar
->GetRange() ; 
 973            return m_vScrollBar
->GetRange() ; 
 978 int wxWindowMac::GetScrollThumb(int orient
) const 
 980     if ( orient 
== wxHORIZONTAL 
) 
 983            return m_hScrollBar
->GetThumbSize() ; 
 988            return m_vScrollBar
->GetThumbSize() ; 
 993 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
) 
 995     if ( orient 
== wxHORIZONTAL 
) 
 998            m_hScrollBar
->SetThumbPosition( pos 
) ; 
1003            m_vScrollBar
->SetThumbPosition( pos 
) ; 
1007 void wxWindowMac::MacPaintBorders( )  
1012     RGBColor white 
= { 0xFFFF, 0xFFFF , 0xFFFF } ; 
1013     RGBColor black 
= { 0x0000, 0x0000 , 0x0000 } ; 
1014     RGBColor face 
= { 0xDDDD, 0xDDDD , 0xDDDD } ; 
1015     RGBColor shadow 
= { 0x4444, 0x4444 , 0x4444 } ; 
1018     if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) ) 
1020 #if wxMAC_USE_THEME_BORDER 
1021                   Rect rect 
= { 0 , 0 , m_height 
, m_width 
} ; 
1024                   GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; 
1025                   InsetRect( &rect , border , border ); 
1026       DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; 
1029         DrawThemePrimaryGroup(&rect  
,IsEnabled() ? kThemeStateActive 
: kThemeStateInactive
) ; 
1031         bool sunken 
= HasFlag( wxSUNKEN_BORDER 
) ; 
1032         RGBForeColor( &face 
); 
1033         MoveTo( 0 , m_height 
- 2 ); 
1035         LineTo( m_width 
- 2 , 0 ); 
1037         MoveTo( 2 , m_height 
- 3 ); 
1038         LineTo( m_width 
- 3 , m_height 
- 3 ); 
1039         LineTo( m_width 
- 3 , 2 ); 
1041         RGBForeColor( sunken 
? &face 
: &black 
); 
1042         MoveTo( 0 , m_height 
- 1 ); 
1043         LineTo( m_width 
- 1 , m_height 
- 1 ); 
1044         LineTo( m_width 
- 1 , 0 ); 
1046         RGBForeColor( sunken 
? &shadow 
: &white 
); 
1047         MoveTo( 1 , m_height 
- 3 ); 
1049         LineTo( m_width 
- 3 , 1 ); 
1051         RGBForeColor( sunken 
? &white 
: &shadow 
); 
1052         MoveTo( 1 , m_height 
- 2 ); 
1053         LineTo( m_width 
- 2 , m_height 
- 2 ); 
1054         LineTo( m_width 
- 2 , 1 ); 
1056         RGBForeColor( sunken 
? &black 
: &face 
); 
1057         MoveTo( 2 , m_height 
- 4 ); 
1059         LineTo( m_width 
- 4 , 2 ); 
1062     else if (HasFlag(wxSIMPLE_BORDER
)) 
1064         Rect rect 
= { 0 , 0 , m_height 
, m_width 
} ; 
1065         RGBForeColor( &black 
) ; 
1066         FrameRect( &rect 
) ; 
1070 // New function that will replace some of the above. 
1071 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
, 
1072     int range
, bool refresh
) 
1074         if ( orient 
== wxHORIZONTAL 
) 
1078                 if ( range 
== 0 || thumbVisible 
>= range 
) 
1080                     if ( m_hScrollBar
->IsShown() ) 
1081                         m_hScrollBar
->Show(false) ; 
1085                     if ( !m_hScrollBar
->IsShown() ) 
1086                         m_hScrollBar
->Show(true) ; 
1087                     m_hScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1095                 if ( range 
== 0 || thumbVisible 
>= range 
) 
1097                     if ( m_vScrollBar
->IsShown() ) 
1098                         m_vScrollBar
->Show(false) ; 
1102                     if ( !m_vScrollBar
->IsShown() ) 
1103                         m_vScrollBar
->Show(true) ; 
1104                     m_vScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1108         MacRepositionScrollBars() ; 
1111 // Does a physical scroll 
1112 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
1114     wxMacDrawingClientHelper 
focus( this ) ; 
1117         int width 
, height 
; 
1118         GetClientSize( &width 
, &height 
) ; 
1120         Rect scrollrect 
= { 0 , 0 , height 
, width 
} ; 
1122         RgnHandle updateRgn 
= NewRgn() ; 
1123         ClipRect( &scrollrect 
) ; 
1126             Rect r 
= { rect
->y 
, rect
->x 
, rect
->y 
+ rect
->height 
, rect
->x 
+ rect
->width 
} ; 
1127             SectRect( &scrollrect 
, &r 
, &scrollrect 
) ;         
1129         ScrollRect( &scrollrect 
, dx 
, dy 
, updateRgn 
) ; 
1130         InvalWindowRgn( MacGetRootWindow() ,  updateRgn 
) ; 
1131         DisposeRgn( updateRgn 
) ; 
1134     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1136         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1137         if (child 
== m_vScrollBar
) continue; 
1138         if (child 
== m_hScrollBar
) continue; 
1139         if (child
->IsTopLevel()) continue; 
1141         child
->GetPosition( &x
, &y 
); 
1143         child
->GetSize( &w
, &h 
); 
1144         child
->SetSize( x
+dx
, y
+dy
, w
, h 
); 
1149 void wxWindowMac::MacOnScroll(wxScrollEvent 
&event 
) 
1151     if ( event
.m_eventObject 
== m_vScrollBar 
|| event
.m_eventObject 
== m_hScrollBar 
) 
1153         wxScrollWinEvent wevent
; 
1154         wevent
.SetPosition(event
.GetPosition()); 
1155         wevent
.SetOrientation(event
.GetOrientation()); 
1156         wevent
.m_eventObject 
= this; 
1158         if (event
.m_eventType 
== wxEVT_SCROLL_TOP
) { 
1159             wevent
.m_eventType 
= wxEVT_SCROLLWIN_TOP
; 
1161         if (event
.m_eventType 
== wxEVT_SCROLL_BOTTOM
) { 
1162             wevent
.m_eventType 
= wxEVT_SCROLLWIN_BOTTOM
; 
1164         if (event
.m_eventType 
== wxEVT_SCROLL_LINEUP
) { 
1165             wevent
.m_eventType 
= wxEVT_SCROLLWIN_LINEUP
; 
1167         if (event
.m_eventType 
== wxEVT_SCROLL_LINEDOWN
) { 
1168             wevent
.m_eventType 
= wxEVT_SCROLLWIN_LINEDOWN
; 
1170         if (event
.m_eventType 
== wxEVT_SCROLL_PAGEUP
) { 
1171             wevent
.m_eventType 
= wxEVT_SCROLLWIN_PAGEUP
; 
1173         if (event
.m_eventType 
== wxEVT_SCROLL_PAGEDOWN
) { 
1174             wevent
.m_eventType 
= wxEVT_SCROLLWIN_PAGEDOWN
; 
1176         if (event
.m_eventType 
== wxEVT_SCROLL_THUMBTRACK
) { 
1177             wevent
.m_eventType 
= wxEVT_SCROLLWIN_THUMBTRACK
; 
1180         GetEventHandler()->ProcessEvent(wevent
); 
1184 // Get the window with the focus 
1185 wxWindowMac 
*wxWindowBase::FindFocus() 
1187     return gFocusWindow 
; 
1190 #if WXWIN_COMPATIBILITY 
1191 // If nothing defined for this, try the parent. 
1192 // E.g. we may be a button loaded from a resource, with no callback function 
1194 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
) 
1196     if ( GetEventHandler()->ProcessEvent(event
)  ) 
1199         m_parent
->GetEventHandler()->OnCommand(win
, event
); 
1201 #endif // WXWIN_COMPATIBILITY_2 
1203 #if WXWIN_COMPATIBILITY 
1204 wxObject
* wxWindowMac::GetChild(int number
) const 
1206     // Return a pointer to the Nth object in the Panel 
1207     wxNode 
*node 
= GetChildren().First(); 
1210         node 
= node
->Next(); 
1213         wxObject 
*obj 
= (wxObject 
*)node
->Data(); 
1219 #endif // WXWIN_COMPATIBILITY 
1221 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
) 
1223     // panel wants to track the window which was the last to have focus in it, 
1224     // so we want to set ourselves as the window which last had focus 
1226     // notice that it's also important to do it upwards the tree becaus 
1227     // otherwise when the top level panel gets focus, it won't set it back to 
1228     // us, but to some other sibling 
1230     // CS:don't know if this is still needed: 
1231     //wxChildFocusEvent eventFocus(this); 
1232     //(void)GetEventHandler()->ProcessEvent(eventFocus); 
1237 void wxWindowMac::Clear() 
1239     wxClientDC 
dc(this); 
1240     wxBrush 
brush(GetBackgroundColour(), wxSOLID
); 
1241     dc
.SetBackground(brush
); 
1245 // Setup background and foreground colours correctly 
1246 void wxWindowMac::SetupColours() 
1249         SetBackgroundColour(GetParent()->GetBackgroundColour()); 
1252 void wxWindowMac::OnIdle(wxIdleEvent
& event
) 
1255    // Check if we need to send a LEAVE event 
1256    if (m_mouseInWindow) 
1259        ::GetCursorPos(&pt); 
1260        if (::WindowFromPoint(pt) != (HWND) GetHWND()) 
1262            // Generate a LEAVE event 
1263            m_mouseInWindow = FALSE; 
1264            MSWOnMouseLeave(pt.x, pt.y, 0); 
1269     // This calls the UI-update mechanism (querying windows for 
1270     // menu/toolbar/control state information) 
1274 // Raise the window to the top of the Z order 
1275 void wxWindowMac::Raise() 
1279 // Lower the window to the bottom of the Z order 
1280 void wxWindowMac::Lower() 
1284 void wxWindowMac::DoSetClientSize(int width
, int height
) 
1286     if ( width 
!= -1 || height 
!= -1 ) 
1289         if ( width 
!= -1 && m_vScrollBar 
) 
1290             width 
+= MAC_SCROLLBAR_SIZE 
; 
1291         if ( height 
!= -1 && m_vScrollBar 
) 
1292             height 
+= MAC_SCROLLBAR_SIZE 
; 
1294         width 
+= MacGetLeftBorderSize(  ) + MacGetRightBorderSize( ) ; 
1295         height 
+= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ) ; 
1297         DoSetSize( -1 , -1 , width 
, height 
) ; 
1302 wxWindowMac
* wxWindowMac::s_lastMouseWindow 
= NULL 
; 
1304 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint 
&point 
, wxWindowMac
** outWin 
)  
1306     if ((point
.x 
< m_x
) || (point
.y 
< m_y
) || 
1307         (point
.x 
> (m_x 
+ m_width
)) || (point
.y 
> (m_y 
+ m_height
))) 
1310     WindowRef window 
= MacGetRootWindow() ; 
1312     wxPoint 
newPoint( point 
) ; 
1317     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1319         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1320         // added the m_isShown test --dmazzoni 
1321         if ( child
->MacGetRootWindow() == window 
&& child
->m_isShown 
) 
1323             if (child
->MacGetWindowFromPointSub(newPoint 
, outWin 
)) 
1332 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint 
&screenpoint 
, wxWindowMac
** outWin 
)  
1335     Point pt 
= { screenpoint
.y 
, screenpoint
.x 
} ; 
1336     if ( ::FindWindow( pt 
, &window 
) == 3 ) 
1338             wxPoint 
point( screenpoint 
) ; 
1339             wxWindowMac
* win 
= wxFindWinFromMacWindow( window 
) ; 
1342             win
->ScreenToClient( point 
) ; 
1343             return win
->MacGetWindowFromPointSub( point 
, outWin 
) ; 
1349 extern int wxBusyCursorCount 
; 
1351 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
) 
1353     if ((event
.m_x 
< m_x
) || (event
.m_y 
< m_y
) || 
1354         (event
.m_x 
> (m_x 
+ m_width
)) || (event
.m_y 
> (m_y 
+ m_height
))) 
1358     if ( IsKindOf( CLASSINFO ( wxStaticBox 
) ) ) 
1361     WindowRef window 
= MacGetRootWindow() ; 
1369     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1371         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1372         if ( child
->MacGetRootWindow() == window 
&& child
->IsShown() && child
->IsEnabled() ) 
1374             if (child
->MacDispatchMouseEvent(event
)) 
1382     if ( wxBusyCursorCount 
== 0 ) 
1384         m_cursor
.MacInstall() ; 
1387     if ( event
.GetEventType() == wxEVT_LEFT_DOWN 
) 
1389         // set focus to this window 
1390         if (AcceptsFocus() && FindFocus()!=this) 
1395     if ( event
.GetEventType() == wxEVT_MOTION 
 
1396             || event
.GetEventType() == wxEVT_ENTER_WINDOW
 
1397             || event
.GetEventType() == wxEVT_LEAVE_WINDOW 
) 
1398         wxToolTip::RelayEvent( this , event
); 
1399 #endif // wxUSE_TOOLTIPS 
1400     GetEventHandler()->ProcessEvent( event 
) ; 
1404 wxString 
wxWindowMac::MacGetToolTipString( wxPoint 
&pt 
) 
1408         return m_tooltip
->GetTip() ; 
1413 void wxWindowMac::Update() 
1415     wxTopLevelWindowMac
* win 
= MacGetTopLevelWindow(  ) ; 
1417       win
->MacUpdate( 0 ) ; 
1420 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const  
1422     wxTopLevelWindowMac
* win 
= NULL 
; 
1423     WindowRef window 
= MacGetRootWindow() ; 
1426         win 
= wxFindWinFromMacWindow( window 
) ; 
1431 const wxRegion
& wxWindowMac::MacGetVisibleRegion() 
1433   RgnHandle visRgn 
= NewRgn() ; 
1435   SetRectRgn( visRgn 
, 0 , 0 , m_width 
, m_height 
) ; 
1437   if ( GetWindowStyle() & wxCLIP_CHILDREN 
) 
1439     // subtract all children from updatergn 
1441     RgnHandle childarea 
= NewRgn() ; 
1442     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1444         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1446         if ( !child
->IsTopLevel() && child
->IsShown() ) 
1448             SetRectRgn( childarea 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1449             DiffRgn( visRgn 
, childarea 
, visRgn 
) ; 
1452     DisposeRgn( childarea 
) ; 
1455   if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() ) 
1457     RgnHandle siblingarea 
= NewRgn() ; 
1458     bool thisWindowThrough 
= false ; 
1459     for (wxNode 
*node 
= GetParent()->GetChildren().First(); node
; node 
= node
->Next()) 
1461         wxWindowMac 
*sibling 
= (wxWindowMac
*)node
->Data(); 
1462         if ( sibling 
== this ) 
1464           thisWindowThrough 
= true ; 
1467         if( !thisWindowThrough 
) 
1472         if ( !sibling
->IsTopLevel() && sibling
->IsShown() ) 
1474             SetRectRgn( siblingarea 
, 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 
) ; 
1475             DiffRgn( visRgn 
, siblingarea 
, visRgn 
) ; 
1478     DisposeRgn( siblingarea 
) ;      
1480   m_macVisibleRegion 
= visRgn 
; 
1481   DisposeRgn( visRgn 
) ; 
1482   return m_macVisibleRegion 
; 
1485 void wxWindowMac::MacRedraw( RgnHandle updatergn 
, long time
, bool erase
) 
1487     // updatergn is always already clipped to our boundaries 
1488     // it is in window coordinates, not in client coordinates 
1490     WindowRef window 
= MacGetRootWindow() ; 
1493         // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates 
1494         RgnHandle ownUpdateRgn 
= NewRgn() ; 
1495         CopyRgn( updatergn 
, ownUpdateRgn 
) ; 
1497         SectRgn( ownUpdateRgn 
, MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn 
) ; 
1499         // newupdate is the update region in client coordinates 
1500         RgnHandle newupdate 
= NewRgn() ; 
1501         wxSize point 
= GetClientSize() ; 
1502         wxPoint origin 
= GetClientAreaOrigin() ; 
1503         SetRectRgn( newupdate 
, origin
.x 
, origin
.y 
, origin
.x 
+ point
.x 
, origin
.y
+point
.y 
) ; 
1504         SectRgn( newupdate 
, ownUpdateRgn 
, newupdate 
) ; 
1505         OffsetRgn( newupdate 
, -origin
.x 
, -origin
.y 
) ; 
1506         m_updateRegion 
= newupdate 
; 
1507         DisposeRgn( newupdate 
) ; // it's been cloned to m_updateRegion 
1509         if ( erase 
&& !EmptyRgn(ownUpdateRgn
) ) 
1511           wxWindowDC 
dc(this); 
1512           dc
.SetClippingRegion(wxRegion(ownUpdateRgn
)); 
1513           wxEraseEvent 
eevent( GetId(), &dc 
); 
1514           eevent
.SetEventObject( this ); 
1515           GetEventHandler()->ProcessEvent( eevent 
); 
1517           wxNcPaintEvent 
eventNc( GetId() ); 
1518           eventNc
.SetEventObject( this ); 
1519           GetEventHandler()->ProcessEvent( eventNc 
); 
1521         DisposeRgn( ownUpdateRgn 
) ;  
1522         if ( !m_updateRegion
.Empty() ) 
1525           event
.m_timeStamp 
= time 
; 
1526           event
.SetEventObject(this); 
1527           GetEventHandler()->ProcessEvent(event
);  
1531     // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively 
1533     RgnHandle childupdate 
= NewRgn() ;             
1534     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1536         // calculate the update region for the child windows by intersecting the window rectangle with our own 
1537         // passed in update region and then offset it to be client-wise window coordinates again 
1538         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1539         SetRectRgn( childupdate 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1540         SectRgn( childupdate 
, updatergn 
, childupdate 
) ; 
1541         OffsetRgn( childupdate 
, -child
->m_x 
, -child
->m_y 
) ; 
1542         if ( child
->MacGetRootWindow() == window 
&& child
->IsShown() && !EmptyRgn( childupdate 
) ) 
1544             // because dialogs may also be children 
1545             child
->MacRedraw( childupdate 
, time 
, erase 
) ; 
1548     DisposeRgn( childupdate 
) ; 
1549     // eventually a draw grow box here 
1553 WindowRef 
wxWindowMac::MacGetRootWindow() const 
1555     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1559         if ( iter
->IsTopLevel() ) 
1560             return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ; 
1562         iter 
= iter
->GetParent() ; 
1564     wxASSERT_MSG( 1 , "No valid mac root window" ) ; 
1568 void wxWindowMac::MacCreateScrollBars( long style 
)  
1570     wxASSERT_MSG( m_vScrollBar 
== NULL 
&& m_hScrollBar 
== NULL 
, "attempt to create window twice" ) ; 
1572     bool hasBoth 
= ( style 
& wxVSCROLL 
) && ( style 
& wxHSCROLL 
) ; 
1573     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1: 0 ; 
1575     GetClientSize( &width 
, &height 
) ; 
1577     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1578     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1579     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1580     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1582     m_vScrollBar 
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,  
1583         vSize 
, wxVERTICAL
); 
1585     if ( style 
& wxVSCROLL 
) 
1591         m_vScrollBar
->Show(false) ; 
1593     m_hScrollBar 
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,  
1594         hSize 
, wxHORIZONTAL
); 
1595     if ( style  
& wxHSCROLL 
) 
1600         m_hScrollBar
->Show(false) ; 
1603     // because the create does not take into account the client area origin 
1604     MacRepositionScrollBars() ; // we might have a real position shift 
1607 void wxWindowMac::MacRepositionScrollBars() 
1609     bool hasBoth 
= ( m_hScrollBar 
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar 
&& m_vScrollBar
->IsShown()) ; 
1610     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1 : 0 ; 
1612     // get real client area 
1614     int width 
= m_width 
;  
1615     int height 
= m_height 
; 
1617     width 
-= MacGetLeftBorderSize() + MacGetRightBorderSize(); 
1618     height 
-= MacGetTopBorderSize() + MacGetBottomBorderSize(); 
1620     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1621     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1622     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1623     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1630     MacClientToRootWindow( &x 
, &y 
) ; 
1631     MacClientToRootWindow( &w 
, &h 
) ; 
1633     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1635     int totW 
= 10000 , totH 
= 10000; 
1638         if ( iter
->IsTopLevel() ) 
1640             totW 
= iter
->m_width 
; 
1641             totH 
= iter
->m_height 
; 
1645         iter 
= iter
->GetParent() ; 
1673         m_vScrollBar
->SetSize( vPoint
.x 
, vPoint
.y
, vSize
.x
, vSize
.y 
, wxSIZE_ALLOW_MINUS_ONE
); 
1677         m_hScrollBar
->SetSize( hPoint
.x 
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
); 
1681 bool wxWindowMac::AcceptsFocus() const 
1683     return MacCanFocus() && wxWindowBase::AcceptsFocus(); 
1686 ControlHandle 
wxWindowMac::MacGetContainerForEmbedding()  
1688     return GetParent()->MacGetContainerForEmbedding() ; 
1691 void wxWindowMac::MacSuperChangedPosition()  
1693     // only window-absolute structures have to be moved i.e. controls 
1695     wxNode 
*node 
= GetChildren().First(); 
1698         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->Data(); 
1699         child
->MacSuperChangedPosition() ; 
1700         node 
= node
->Next(); 
1704 void wxWindowMac::MacTopLevelWindowChangedPosition()  
1706     // only screen-absolute structures have to be moved i.e. glcanvas 
1708     wxNode 
*node 
= GetChildren().First(); 
1711         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->Data(); 
1712         child
->MacTopLevelWindowChangedPosition() ; 
1713         node 
= node
->Next(); 
1717 bool wxWindowMac::MacSetPortFocusParams( const Point 
& localOrigin
, const Rect 
& clipRect
, WindowRef window 
, wxWindowMac
* win 
)  
1719     if ( window 
== NULL 
) 
1725     ::GetPort(&currPort
); 
1726     port 
= UMAGetWindowPort( window
) ; 
1727     if (currPort 
!= port 
) 
1730 //  wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;  
1731     ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
); 
1735 bool wxWindowMac::MacSetPortDrawingParams( const Point 
& localOrigin
, const Rect 
& clipRect
, WindowRef window 
, wxWindowMac
* win 
)  
1737     if ( window 
== NULL 
) 
1742     ::GetPort(&currPort
); 
1743     port 
= UMAGetWindowPort( window
) ; 
1744     if (currPort 
!= port 
) 
1746 //  wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;  
1747     ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
); 
1748     ::ClipRect(&clipRect
); 
1751     ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ; 
1752     ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ; 
1753     Pattern whiteColor 
; 
1755     ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ; 
1756 //    ::SetThemeWindowBackground(  win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme ,  false ) ; 
1760 void wxWindowMac::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef 
*window  
, wxWindowMac
** rootwin
)  
1762     wxASSERT( GetParent() != NULL 
) ; 
1763     GetParent()->MacGetPortParams( localOrigin 
, clipRect 
, window
, rootwin
) ; 
1764     localOrigin
->h 
+= m_x
; 
1765     localOrigin
->v 
+= m_y
; 
1766     OffsetRect(clipRect
, -m_x
, -m_y
); 
1771     myClip
.right 
= m_width
; 
1772     myClip
.bottom 
= m_height
; 
1773     SectRect(clipRect
, &myClip
, clipRect
); 
1776 void wxWindowMac::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef 
*window 
, wxWindowMac
** rootwin 
)  
1778     wxASSERT( GetParent() != NULL 
) ; 
1780     GetParent()->MacDoGetPortClientParams( localOrigin 
, clipRect 
, window
, rootwin
) ; 
1782     localOrigin
->h 
+= m_x
; 
1783     localOrigin
->v 
+= m_y
; 
1784     OffsetRect(clipRect
, -m_x
, -m_y
); 
1789     myClip
.right 
= m_width 
;//width; 
1790     myClip
.bottom 
= m_height 
;// height; 
1791     SectRect(clipRect
, &myClip
, clipRect
); 
1794 void wxWindowMac::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef 
*window 
, wxWindowMac
** rootwin 
)  
1796     MacDoGetPortClientParams( localOrigin 
, clipRect 
, window 
, rootwin 
) ; 
1798     int width 
, height 
; 
1799     GetClientSize( &width 
, &height 
) ; 
1801     client 
= GetClientAreaOrigin( ) ; 
1803     localOrigin
->h 
+= client
.x
; 
1804     localOrigin
->v 
+= client
.y
; 
1805     OffsetRect(clipRect
, -client
.x
, -client
.y
); 
1810     myClip
.right 
= width
; 
1811     myClip
.bottom 
= height
; 
1812     SectRect(clipRect
, &myClip
, clipRect
); 
1815 long wxWindowMac::MacGetLeftBorderSize( ) const 
1820     if (m_windowStyle 
& wxRAISED_BORDER 
|| m_windowStyle 
& wxSUNKEN_BORDER 
) 
1823 #if wxMAC_USE_THEME_BORDER 
1825                   GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
1830     else if (  m_windowStyle 
&wxDOUBLE_BORDER
) 
1833 #if wxMAC_USE_THEME_BORDER 
1835                   GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
1840     else if (m_windowStyle 
&wxSIMPLE_BORDER
) 
1847 long wxWindowMac::MacGetRightBorderSize( ) const 
1849     // they are all symmetric in mac themes 
1850     return MacGetLeftBorderSize() ; 
1853 long wxWindowMac::MacGetTopBorderSize( ) const 
1855     // they are all symmetric in mac themes 
1856     return MacGetLeftBorderSize() ; 
1859 long wxWindowMac::MacGetBottomBorderSize( ) const 
1861     // they are all symmetric in mac themes 
1862     return MacGetLeftBorderSize() ; 
1865 long wxWindowMac::MacRemoveBordersFromStyle( long style 
)  
1867     return style 
& ~( wxDOUBLE_BORDER 
| wxSUNKEN_BORDER 
| wxRAISED_BORDER 
| wxBORDER 
| wxSTATIC_BORDER 
) ; 
1871 wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac 
* theWindow 
)  
1877     wxWindowMac 
*rootwin 
; 
1878     m_currentPort 
= NULL 
; 
1880     GetPort( &m_formerPort 
) ; 
1883         theWindow
->MacGetPortParams( &localOrigin 
, &clipRect 
, &window 
, &rootwin
) ; 
1884         m_currentPort 
= UMAGetWindowPort( window 
) ; 
1885         if ( m_formerPort 
!= m_currentPort 
) 
1886             SetPort( m_currentPort 
) ; 
1887         GetPenState( &m_savedPenState 
) ; 
1888         theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window 
, rootwin 
) ;  
1893 wxMacDrawingHelper::~wxMacDrawingHelper()  
1897         SetPort( m_currentPort 
) ; 
1898         SetPenState( &m_savedPenState 
) ; 
1899         SetOrigin( 0 , 0 ) ; 
1901         GetPortBounds( m_currentPort 
, &portRect 
) ; 
1902         ClipRect( &portRect 
) ; 
1905     if ( m_formerPort 
!= m_currentPort 
) 
1906         SetPort( m_formerPort 
) ; 
1909 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac 
* theWindow 
)  
1915     wxWindowMac 
*rootwin 
; 
1916     m_currentPort 
= NULL 
; 
1918     GetPort( &m_formerPort 
) ; 
1922         theWindow
->MacGetPortClientParams( &localOrigin 
, &clipRect 
, &window 
, &rootwin
) ; 
1923         m_currentPort 
= UMAGetWindowPort( window 
) ; 
1924         if ( m_formerPort 
!= m_currentPort 
) 
1925             SetPort( m_currentPort 
) ; 
1926         GetPenState( &m_savedPenState 
) ; 
1927         theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window 
, rootwin 
) ;  
1932 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()  
1936         SetPort( m_currentPort 
) ; 
1937         SetPenState( &m_savedPenState 
) ; 
1938         SetOrigin( 0 , 0 ) ; 
1940         GetPortBounds( m_currentPort 
, &portRect 
) ; 
1941         ClipRect( &portRect 
) ; 
1944     if ( m_formerPort 
!= m_currentPort 
) 
1945         SetPort( m_formerPort 
) ; 
1948 // Find the wxWindowMac at the current mouse position, returning the mouse 
1950 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
) 
1952     pt 
= wxGetMousePosition(); 
1953     wxWindowMac
* found 
= wxFindWindowAtPoint(pt
); 
1957 // Get the current mouse position. 
1958 wxPoint 
wxGetMousePosition() 
1961     wxGetMousePosition(& x
, & y
); 
1962     return wxPoint(x
, y
);