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" 
  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
) 
  84 #define wxMAC_DEBUG_REDRAW 0 
  85 #ifndef wxMAC_DEBUG_REDRAW 
  86 #define wxMAC_DEBUG_REDRAW 0 
  89 #define wxMAC_USE_THEME_BORDER 0 
  92 // =========================================================================== 
  94 // =========================================================================== 
  97 // ---------------------------------------------------------------------------- 
  98 // constructors and such 
  99 // ---------------------------------------------------------------------------- 
 101 void wxWindowMac::Init() 
 107     m_doubleClickAllowed 
= 0; 
 108     m_winCaptured 
= FALSE
; 
 110     m_isBeingDeleted 
= FALSE
; 
 113     m_mouseInWindow 
= FALSE
; 
 117     m_backgroundTransparent 
= FALSE
; 
 119     // as all windows are created with WS_VISIBLE style... 
 127     m_hScrollBar 
= NULL 
; 
 128     m_vScrollBar 
= NULL 
; 
 130     m_label 
= wxEmptyString
; 
 134 wxWindowMac::~wxWindowMac() 
 136     // deleting a window while it is shown invalidates the region 
 138         wxWindowMac
* iter 
= this ; 
 140             if ( iter
->IsTopLevel() ) 
 145             iter 
= iter
->GetParent() ; 
 150     m_isBeingDeleted 
= TRUE
; 
 152 #ifndef __WXUNIVERSAL__ 
 153     // VS: make sure there's no wxFrame with last focus set to us: 
 154     for ( wxWindow 
*win 
= GetParent(); win
; win 
= win
->GetParent() ) 
 156         wxFrame 
*frame 
= wxDynamicCast(win
, wxFrame
); 
 159             if ( frame
->GetLastFocus() == this ) 
 161                 frame
->SetLastFocus((wxWindow
*)NULL
); 
 166 #endif // __WXUNIVERSAL__ 
 168     if ( s_lastMouseWindow 
== this ) 
 170         s_lastMouseWindow 
= NULL 
; 
 173     wxFrame
* frame 
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame 
) ; 
 176         if ( frame
->GetLastFocus() == this ) 
 177                 frame
->SetLastFocus( NULL 
) ; 
 180     if ( gFocusWindow 
== this ) 
 182         gFocusWindow 
= NULL 
; 
 186         m_parent
->RemoveChild(this); 
 192 bool wxWindowMac::Create(wxWindowMac 
*parent
, wxWindowID id
, 
 196            const wxString
& name
) 
 198     wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") ); 
 200     if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) ) 
 203     parent
->AddChild(this); 
 207     AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
); 
 208     m_width 
= WidthDefault( size
.x 
); 
 209     m_height 
= HeightDefault( size
.y 
) ; 
 210 #ifndef __WXUNIVERSAL__ 
 211     // Don't give scrollbars to wxControls unless they ask for them 
 212     if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) || 
 213          (IsKindOf(CLASSINFO(wxControl
)) && ( style 
& wxHSCROLL 
|| style 
& wxVSCROLL
))) 
 215         MacCreateScrollBars( style 
) ; 
 221 void wxWindowMac::SetFocus() 
 223     if ( gFocusWindow 
== this ) 
 226     if ( AcceptsFocus() ) 
 232                 if ( gFocusWindow
->m_caret 
) 
 234                       gFocusWindow
->m_caret
->OnKillFocus(); 
 236             #endif // wxUSE_CARET 
 237       #ifndef __WXUNIVERSAL__ 
 238             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 239             if ( control 
&& control
->GetMacControl() ) 
 241                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNoPart 
) ; 
 242                 control
->MacRedrawControl() ; 
 245             wxFocusEvent 
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
); 
 246             event
.SetEventObject(gFocusWindow
); 
 247             gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ; 
 249         gFocusWindow 
= this ; 
 255                 m_caret
->OnSetFocus(); 
 257             #endif // wxUSE_CARET 
 258             // panel wants to track the window which was the last to have focus in it 
 259             wxChildFocusEvent 
eventFocus(this); 
 260             GetEventHandler()->ProcessEvent(eventFocus
); 
 262       #ifndef __WXUNIVERSAL__ 
 263             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 264             if ( control 
&& control
->GetMacControl() ) 
 266                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNextPart 
) ; 
 269             wxFocusEvent 
event(wxEVT_SET_FOCUS
, m_windowId
); 
 270             event
.SetEventObject(this); 
 271             GetEventHandler()->ProcessEvent(event
) ; 
 276 bool wxWindowMac::Enable(bool enable
) 
 278     if ( !wxWindowBase::Enable(enable
) ) 
 281     MacSuperEnabled( enable 
) ; 
 286 void wxWindowMac::DoCaptureMouse() 
 288     wxTheApp
->s_captureWindow 
= this ; 
 291 wxWindow
* wxWindowBase::GetCapture() 
 293     return wxTheApp
->s_captureWindow 
; 
 296 void wxWindowMac::DoReleaseMouse() 
 298     wxTheApp
->s_captureWindow 
= NULL 
; 
 301 #if    wxUSE_DRAG_AND_DROP 
 303 void wxWindowMac::SetDropTarget(wxDropTarget 
*pDropTarget
) 
 305   if ( m_dropTarget 
!= 0 ) { 
 309   m_dropTarget 
= pDropTarget
; 
 310   if ( m_dropTarget 
!= 0 ) 
 318 // Old style file-manager drag&drop 
 319 void wxWindowMac::DragAcceptFiles(bool accept
) 
 325 void wxWindowMac::DoGetSize(int *x
, int *y
) const 
 328      if(y
)   *y 
= m_height 
; 
 331 void wxWindowMac::DoGetPosition(int *x
, int *y
) const 
 337     if ( !IsTopLevel() && GetParent()) 
 339         wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
 348 bool wxWindowMac::DoPopupMenu(wxMenu 
*menu
, int x
, int y
) 
 350     menu
->SetInvokingWindow(this); 
 352     ClientToScreen( &x 
, &y 
) ; 
 354     ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ; 
 355     long menuResult 
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ; 
 356     if ( HiWord(menuResult
) != 0 ) 
 359         GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id 
) ; 
 361         wxCommandEvent 
event(wxEVT_COMMAND_MENU_SELECTED
, id 
); 
 362         event
.m_timeStamp 
=  TickCount() ; 
 363         event
.SetEventObject(this->GetEventHandler()); 
 365         GetEventHandler()->ProcessEvent(event
); 
 367     ::DeleteMenu( menu
->MacGetMenuId() ) ; 
 368     menu
->SetInvokingWindow(NULL
); 
 374 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const 
 376     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 378     Point       localwhere 
= {0,0} ; 
 380     if(x
)   localwhere
.h 
= * x 
; 
 381     if(y
)   localwhere
.v 
= * y 
; 
 385     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 386     ::GlobalToLocal( &localwhere 
) ; 
 389     if(x
)   *x 
= localwhere
.h 
; 
 390     if(y
)   *y 
= localwhere
.v 
; 
 392     MacRootWindowToWindow( x 
, y 
) ; 
 394             x 
-= MacGetLeftBorderSize() ; 
 396             y 
-= MacGetTopBorderSize() ; 
 399 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const 
 401     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 404             x 
+= MacGetLeftBorderSize() ; 
 406             y 
+= MacGetTopBorderSize() ; 
 408     MacWindowToRootWindow( x 
, y 
) ; 
 410     Point       localwhere 
= { 0,0 }; 
 411     if(x
)   localwhere
.h 
= * x 
; 
 412     if(y
)   localwhere
.v 
= * y 
; 
 416     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 418     ::LocalToGlobal( &localwhere 
) ; 
 420     if(x
)   *x 
= localwhere
.h 
; 
 421     if(y
)   *y 
= localwhere
.v 
; 
 424 void wxWindowMac::MacClientToRootWindow( int *x 
, int *y 
) const 
 426     wxPoint origin 
= GetClientAreaOrigin() ; 
 427     if(x
)   *x 
+= origin
.x 
; 
 428     if(y
)   *y 
+= origin
.y 
; 
 430     MacWindowToRootWindow( x 
, y 
) ; 
 433 void wxWindowMac::MacRootWindowToClient( int *x 
, int *y 
) const 
 435     wxPoint origin 
= GetClientAreaOrigin() ; 
 436     MacRootWindowToWindow( x 
, y 
) ; 
 437     if(x
)   *x 
-= origin
.x 
; 
 438     if(y
)   *y 
-= origin
.y 
; 
 441 void wxWindowMac::MacWindowToRootWindow( int *x 
, int *y 
) const 
 447         GetParent()->MacWindowToRootWindow( x 
, y 
) ; 
 451 void wxWindowMac::MacRootWindowToWindow( int *x 
, int *y 
) const 
 457         GetParent()->MacRootWindowToWindow( x 
, y 
) ; 
 461 bool wxWindowMac::SetCursor(const wxCursor
& cursor
) 
 463     if (m_cursor 
== cursor
) 
 466     if (wxNullCursor 
== cursor
) 
 468        if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR 
) ) 
 473        if ( ! wxWindowBase::SetCursor( cursor 
) ) 
 477   wxASSERT_MSG( m_cursor
.Ok(), 
 478                   wxT("cursor must be valid after call to the base version")); 
 481   wxWindowMac 
*mouseWin 
; 
 484   // Change the cursor NOW if we're within the correct window 
 486   if ( MacGetWindowFromPoint( wxPoint( pt
.h 
, pt
.v 
) , &mouseWin 
) ) 
 488     if ( mouseWin 
== this && !wxIsBusy() ) 
 490         m_cursor
.MacInstall() ; 
 498 // Get size *available for subwindows* i.e. excluding menu bar etc. 
 499 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const 
 505     ww 
-= MacGetLeftBorderSize(  )  + MacGetRightBorderSize(  ) ; 
 506     hh 
-= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ); 
 508   if ( (m_vScrollBar 
&& m_vScrollBar
->IsShown()) || (m_hScrollBar  
&& m_hScrollBar
->IsShown()) ) 
 515     MacClientToRootWindow( &x1 
, &y1 
) ; 
 516     MacClientToRootWindow( &w 
, &h 
) ; 
 518     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
 520     int totW 
= 10000 , totH 
= 10000; 
 523         if ( iter
->IsTopLevel() ) 
 525             totW 
= iter
->m_width 
; 
 526             totH 
= iter
->m_height 
; 
 530         iter 
= iter
->GetParent() ; 
 533     if (m_hScrollBar  
&& m_hScrollBar
->IsShown() ) 
 535         hh 
-= MAC_SCROLLBAR_SIZE
; 
 541     if (m_vScrollBar  
&& m_vScrollBar
->IsShown() ) 
 543         ww 
-= MAC_SCROLLBAR_SIZE
; 
 555 // ---------------------------------------------------------------------------- 
 557 // ---------------------------------------------------------------------------- 
 561 void wxWindowMac::DoSetToolTip(wxToolTip 
*tooltip
) 
 563     wxWindowBase::DoSetToolTip(tooltip
); 
 566         m_tooltip
->SetWindow(this); 
 569 #endif // wxUSE_TOOLTIPS 
 571 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
) 
 575     int former_w 
= m_width 
; 
 576     int former_h 
= m_height 
; 
 578   int actualWidth 
= width
; 
 579   int actualHeight 
= height
; 
 583     if ((m_minWidth 
!= -1) && (actualWidth 
< m_minWidth
)) 
 584         actualWidth 
= m_minWidth
; 
 585     if ((m_minHeight 
!= -1) && (actualHeight 
< m_minHeight
)) 
 586         actualHeight 
= m_minHeight
; 
 587     if ((m_maxWidth 
!= -1) && (actualWidth 
> m_maxWidth
)) 
 588         actualWidth 
= m_maxWidth
; 
 589     if ((m_maxHeight 
!= -1) && (actualHeight 
> m_maxHeight
)) 
 590         actualHeight 
= m_maxHeight
; 
 592     bool doMove 
= false ; 
 593     bool doResize 
= false ; 
 595     if ( actualX 
!= former_x 
|| actualY 
!= former_y 
) 
 599     if ( actualWidth 
!= former_w 
|| actualHeight 
!= former_h 
) 
 604     if ( doMove 
|| doResize 
) 
 606         // erase former position 
 608         bool partialRepaint 
= false ; 
 610         if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) ) 
 612             wxPoint 
oldPos( m_x 
, m_y 
) ;  
 613             wxPoint 
newPos( actualX 
, actualY 
) ; 
 614             MacWindowToRootWindow( &oldPos
.x 
, &oldPos
.y 
) ; 
 615             MacWindowToRootWindow( &newPos
.x 
, &newPos
.y 
) ; 
 616             if ( oldPos 
== newPos 
) 
 618                 partialRepaint 
= true ; 
 619                 RgnHandle oldRgn
,newRgn
,diffRgn 
; 
 623                 SetRectRgn(oldRgn 
, oldPos
.x 
, oldPos
.y 
, oldPos
.x 
+ m_width 
, oldPos
.y 
+ m_height 
) ; 
 624                 SetRectRgn(newRgn 
, newPos
.x 
, newPos
.y 
, newPos
.x 
+ actualWidth 
, newPos
.y 
+ actualHeight 
) ; 
 625                 DiffRgn( newRgn 
, oldRgn 
, diffRgn 
) ; 
 626                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 627                 DiffRgn( oldRgn 
, newRgn 
, diffRgn 
) ; 
 628                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 631                 DisposeRgn(diffRgn
) ; 
 635         if ( !partialRepaint 
) 
 640         m_width 
= actualWidth 
; 
 641         m_height 
= actualHeight 
; 
 643                 // update any low-level frame-relative positions 
 645                 MacUpdateDimensions() ; 
 646         // erase new position 
 648         if ( !partialRepaint 
) 
 651             wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified 
 653         MacRepositionScrollBars() ; 
 656             wxPoint 
point(m_x
, m_y
); 
 657             wxMoveEvent 
event(point
, m_windowId
); 
 658             event
.SetEventObject(this); 
 659             GetEventHandler()->ProcessEvent(event
) ; 
 663              MacRepositionScrollBars() ; 
 664              wxSize 
size(m_width
, m_height
); 
 665              wxSizeEvent 
event(size
, m_windowId
); 
 666              event
.SetEventObject(this); 
 667              GetEventHandler()->ProcessEvent(event
); 
 673 // set the size of the window: if the dimensions are positive, just use them, 
 674 // but if any of them is equal to -1, it means that we must find the value for 
 675 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in 
 676 // which case -1 is a valid value for x and y) 
 678 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate 
 679 // the width/height to best suit our contents, otherwise we reuse the current 
 681 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 683     // get the current size and position... 
 684     int currentX
, currentY
; 
 685     GetPosition(¤tX
, ¤tY
); 
 687     int currentW
,currentH
; 
 688     GetSize(¤tW
, ¤tH
); 
 690     // ... and don't do anything (avoiding flicker) if it's already ok 
 691     if ( x 
== currentX 
&& y 
== currentY 
&& 
 692          width 
== currentW 
&& height 
== currentH 
) 
 694         MacRepositionScrollBars() ; // we might have a real position shift 
 698     if ( x 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 700     if ( y 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 703     AdjustForParentClientOrigin(x
, y
, sizeFlags
); 
 708         if ( sizeFlags 
& wxSIZE_AUTO_WIDTH 
) 
 710             size 
= DoGetBestSize(); 
 715             // just take the current one 
 722         if ( sizeFlags 
& wxSIZE_AUTO_HEIGHT 
) 
 726                 size 
= DoGetBestSize(); 
 728             //else: already called DoGetBestSize() above 
 734             // just take the current one 
 739     DoMoveWindow(x
, y
, width
, height
); 
 742 // For implementation purposes - sometimes decorations make the client area 
 745 wxPoint 
wxWindowMac::GetClientAreaOrigin() const 
 747     return wxPoint(MacGetLeftBorderSize(  ) , MacGetTopBorderSize(  ) ); 
 750 void wxWindowMac::SetTitle(const wxString
& title
) 
 755 wxString 
wxWindowMac::GetTitle() const 
 760 bool wxWindowMac::Show(bool show
) 
 762     if ( !wxWindowBase::Show(show
) ) 
 766     WindowRef window = (WindowRef) MacGetRootWindow() ; 
 767     wxWindowMac* win = wxFindWinFromMacWindow( window ) ; 
 768     if ( win == NULL && win->m_isBeingDeleted ) 
 771     MacSuperShown( show 
) ; 
 776         if ( win && !win->m_isBeingDeleted ) 
 787 void wxWindowMac::MacSuperShown( bool show 
) 
 789     wxNode 
*node 
= GetChildren().First(); 
 792         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->Data(); 
 793         if ( child
->m_isShown 
) 
 794             child
->MacSuperShown( show 
) ; 
 799 void wxWindowMac::MacSuperEnabled( bool enabled 
) 
 803       // to be absolutely correct we'd have to invalidate (with eraseBkground 
 804       // because unter MacOSX the frames are drawn with an addXXX mode) 
 807     wxNode 
*node 
= GetChildren().First(); 
 810         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->Data(); 
 811         if ( child
->m_isShown 
) 
 812             child
->MacSuperEnabled( enabled 
) ; 
 817 bool wxWindowMac::MacIsReallyShown() const 
 819     if ( m_isShown 
&& (m_parent 
!= NULL
) ) { 
 820         return m_parent
->MacIsReallyShown(); 
 824     bool status = m_isShown ; 
 825     wxWindowMac * win = this ; 
 826     while ( status && win->m_parent != NULL ) 
 828         win = win->m_parent ; 
 829         status = win->m_isShown ; 
 835 int wxWindowMac::GetCharHeight() const 
 837     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 838     return dc
.GetCharHeight() ; 
 841 int wxWindowMac::GetCharWidth() const 
 843     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 844     return dc
.GetCharWidth() ; 
 847 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
, 
 848                            int *descent
, int *externalLeading
, const wxFont 
*theFont 
) const 
 850     const wxFont 
*fontToUse 
= theFont
; 
 854     wxClientDC 
dc( (wxWindowMac
*) this ) ; 
 856     dc
.GetTextExtent( string 
, &lx 
, &ly 
, &ld
, &le
, (wxFont 
*)fontToUse 
) ; 
 857     if ( externalLeading 
) 
 858         *externalLeading 
= le 
; 
 868  * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect 
 869  * we always intersect with the entire window, not only with the client area 
 872 void wxWindowMac::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 874     if ( MacGetTopLevelWindow() == NULL 
) 
 877     wxPoint client 
= GetClientAreaOrigin(); 
 880     int x2 
= m_width 
- client
.x
; 
 881     int y2 
= m_height 
- client
.y
; 
 883     if (IsKindOf( CLASSINFO(wxButton
))) 
 885         // buttons have an "aura" 
 892     Rect clientrect 
= { y1
, x1
, y2
, x2 
}; 
 896         Rect r 
= { rect
->y 
, rect
->x 
, rect
->y 
+ rect
->height 
, rect
->x 
+ rect
->width 
} ; 
 897         SectRect( &clientrect 
, &r 
, &clientrect 
) ; 
 900     if ( !EmptyRect( &clientrect 
) ) 
 902       int top 
= 0 , left 
= 0 ; 
 904       MacClientToRootWindow( &left 
, &top 
) ; 
 905       OffsetRect( &clientrect 
, left 
, top 
) ; 
 907       MacGetTopLevelWindow()->MacInvalidate( &clientrect 
, eraseBack 
) ; 
 911 #if wxUSE_CARET && WXWIN_COMPATIBILITY 
 912 // --------------------------------------------------------------------------- 
 913 // Caret manipulation 
 914 // --------------------------------------------------------------------------- 
 916 void wxWindowMac::CreateCaret(int w
, int h
) 
 918     SetCaret(new wxCaret(this, w
, h
)); 
 921 void wxWindowMac::CreateCaret(const wxBitmap 
*WXUNUSED(bitmap
)) 
 923     wxFAIL_MSG("not implemented"); 
 926 void wxWindowMac::ShowCaret(bool show
) 
 928     wxCHECK_RET( m_caret
, "no caret to show" ); 
 933 void wxWindowMac::DestroyCaret() 
 938 void wxWindowMac::SetCaretPos(int x
, int y
) 
 940     wxCHECK_RET( m_caret
, "no caret to move" ); 
 945 void wxWindowMac::GetCaretPos(int *x
, int *y
) const 
 947     wxCHECK_RET( m_caret
, "no caret to get position of" ); 
 949     m_caret
->GetPosition(x
, y
); 
 951 #endif // wxUSE_CARET 
 953 wxWindowMac 
*wxGetActiveWindow() 
 955     // actually this is a windows-only concept 
 959 // Coordinates relative to the window 
 960 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
) 
 962     // We really dont move the mouse programmatically under mac 
 965 const wxBrush
& wxWindowMac::MacGetBackgroundBrush() 
 967     if ( m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 969         m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground 
) ; 
 971     else if (  m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) ) 
 973         // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether 
 974         // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have 
 975         // either a non gray background color or a non control window 
 977             WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 979             wxWindowMac
* parent 
= GetParent() ; 
 982                 if ( parent
->MacGetRootWindow() != window 
) 
 984                     // we are in a different window on the mac system 
 990                     if ( parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) 
 991                       && parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 993                         // if we have any other colours in the hierarchy 
 994                         m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour 
) ; 
 997                     // if we have the normal colours in the hierarchy but another control etc. -> use it's background 
 998                     if ( parent
->IsKindOf( CLASSINFO( wxNotebook 
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl 
) )) 
1000                         Rect extent 
= { 0 , 0 , 0 , 0 } ; 
1003                         wxSize size 
= parent
->GetSize() ; 
1004                         parent
->MacClientToRootWindow( &x 
, &y 
) ; 
1008                         extent
.right 
= x 
+ size
.x 
; 
1009                         extent
.bottom 
= y 
+ size
.y 
; 
1010                         m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane 
, (WXRECTPTR
) &extent 
) ; // todo eventually change for inactive 
1014                 parent 
= parent
->GetParent() ; 
1018               m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive 
) ; // todo eventually change for inactive 
1023         m_macBackgroundBrush
.SetColour( m_backgroundColour 
) ; 
1026     return m_macBackgroundBrush 
; 
1030 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
) 
1032     event
.GetDC()->Clear() ; 
1035 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event 
) 
1037     wxWindowDC 
dc(this) ; 
1038     wxMacPortSetter 
helper(&dc
) ; 
1040     MacPaintBorders( dc
.m_macLocalOrigin
.x 
, dc
.m_macLocalOrigin
.y
) ; 
1043 int wxWindowMac::GetScrollPos(int orient
) const 
1045     if ( orient 
== wxHORIZONTAL 
) 
1048            return m_hScrollBar
->GetThumbPosition() ; 
1053            return m_vScrollBar
->GetThumbPosition() ; 
1058 // This now returns the whole range, not just the number 
1059 // of positions that we can scroll. 
1060 int wxWindowMac::GetScrollRange(int orient
) const 
1062     if ( orient 
== wxHORIZONTAL 
) 
1065            return m_hScrollBar
->GetRange() ; 
1070            return m_vScrollBar
->GetRange() ; 
1075 int wxWindowMac::GetScrollThumb(int orient
) const 
1077     if ( orient 
== wxHORIZONTAL 
) 
1080            return m_hScrollBar
->GetThumbSize() ; 
1085            return m_vScrollBar
->GetThumbSize() ; 
1090 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
) 
1092     if ( orient 
== wxHORIZONTAL 
) 
1095            m_hScrollBar
->SetThumbPosition( pos 
) ; 
1100            m_vScrollBar
->SetThumbPosition( pos 
) ; 
1104 void wxWindowMac::MacPaintBorders( int left 
, int top 
) 
1109     RGBColor white 
= { 0xFFFF, 0xFFFF , 0xFFFF } ; 
1110     RGBColor black 
= { 0x0000, 0x0000 , 0x0000 } ; 
1111     RGBColor face 
= { 0xDDDD, 0xDDDD , 0xDDDD } ; 
1112     RGBColor shadow 
= { 0x4444, 0x4444 , 0x4444 } ; 
1115     if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) ) 
1117 #if wxMAC_USE_THEME_BORDER 
1118           Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1121           GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; 
1122           InsetRect( &rect , border , border ); 
1123       DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; 
1126         DrawThemePrimaryGroup(&rect  
,IsEnabled() ? kThemeStateActive 
: kThemeStateInactive
) ; 
1128         bool sunken 
= HasFlag( wxSUNKEN_BORDER 
) ; 
1129         RGBForeColor( &face 
); 
1130         MoveTo( left 
+ 0 , top 
+ m_height 
- 2 ); 
1131         LineTo( left 
+ 0 , top 
+ 0 ); 
1132         LineTo( left 
+ m_width 
- 2 , top 
+ 0 ); 
1134         MoveTo( left 
+ 2 , top 
+ m_height 
- 3 ); 
1135         LineTo( left 
+ m_width 
- 3 , top 
+ m_height 
- 3 ); 
1136         LineTo( left 
+ m_width 
- 3 , top 
+ 2 ); 
1138         RGBForeColor( sunken 
? &face 
: &black 
); 
1139         MoveTo( left 
+ 0 , top 
+ m_height 
- 1 ); 
1140         LineTo( left 
+ m_width 
- 1 , top 
+ m_height 
- 1 ); 
1141         LineTo( left 
+ m_width 
- 1 , top 
+ 0 ); 
1143         RGBForeColor( sunken 
? &shadow 
: &white 
); 
1144         MoveTo( left 
+ 1 , top 
+ m_height 
- 3 ); 
1145         LineTo( left 
+ 1, top 
+ 1 ); 
1146         LineTo( left 
+ m_width 
- 3 , top 
+ 1 ); 
1148         RGBForeColor( sunken 
? &white 
: &shadow 
); 
1149         MoveTo( left 
+ 1 , top 
+ m_height 
- 2 ); 
1150         LineTo( left 
+ m_width 
- 2 , top 
+ m_height 
- 2 ); 
1151         LineTo( left 
+ m_width 
- 2 , top 
+ 1 ); 
1153         RGBForeColor( sunken 
? &black 
: &face 
); 
1154         MoveTo( left 
+ 2 , top 
+ m_height 
- 4 ); 
1155         LineTo( left 
+ 2 , top 
+ 2 ); 
1156         LineTo( left 
+ m_width 
- 4 , top 
+ 2 ); 
1159     else if (HasFlag(wxSIMPLE_BORDER
)) 
1161             Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1162         RGBForeColor( &black 
) ; 
1163         FrameRect( &rect 
) ; 
1167 void wxWindowMac::RemoveChild( wxWindowBase 
*child 
) 
1169     if ( child 
== m_hScrollBar 
) 
1170         m_hScrollBar 
= NULL 
; 
1171     if ( child 
== m_vScrollBar 
) 
1172         m_vScrollBar 
= NULL 
; 
1174     wxWindowBase::RemoveChild( child 
) ; 
1177 // New function that will replace some of the above. 
1178 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
, 
1179     int range
, bool refresh
) 
1181         if ( orient 
== wxHORIZONTAL 
) 
1185                 if ( range 
== 0 || thumbVisible 
>= range 
) 
1187                     if ( m_hScrollBar
->IsShown() ) 
1188                         m_hScrollBar
->Show(false) ; 
1192                     if ( !m_hScrollBar
->IsShown() ) 
1193                         m_hScrollBar
->Show(true) ; 
1194                     m_hScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1202                 if ( range 
== 0 || thumbVisible 
>= range 
) 
1204                     if ( m_vScrollBar
->IsShown() ) 
1205                         m_vScrollBar
->Show(false) ; 
1209                     if ( !m_vScrollBar
->IsShown() ) 
1210                         m_vScrollBar
->Show(true) ; 
1211                     m_vScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1215         MacRepositionScrollBars() ; 
1218 // Does a physical scroll 
1219 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
1221     wxClientDC 
dc(this) ; 
1222     wxMacPortSetter 
helper(&dc
) ; 
1225         int width 
, height 
; 
1226         GetClientSize( &width 
, &height 
) ; 
1228         Rect scrollrect 
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ; 
1229         RgnHandle updateRgn 
= NewRgn() ; 
1230         ClipRect( &scrollrect 
) ; 
1233             Rect r 
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y 
+ rect
->height
) , 
1234               dc
.XLOG2DEVMAC(rect
->x 
+ rect
->width
) } ; 
1235             SectRect( &scrollrect 
, &r 
, &scrollrect 
) ; 
1237         ScrollRect( &scrollrect 
, dx 
, dy 
, updateRgn 
) ; 
1238         InvalWindowRgn( (WindowRef
) MacGetRootWindow() ,  updateRgn 
) ; 
1239         DisposeRgn( updateRgn 
) ; 
1242     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1244         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1245         if (child 
== m_vScrollBar
) continue; 
1246         if (child 
== m_hScrollBar
) continue; 
1247         if (child
->IsTopLevel()) continue; 
1250         child
->GetPosition( &x
, &y 
); 
1252         child
->GetSize( &w
, &h 
); 
1253         child
->SetSize( x
+dx
, y
+dy
, w
, h 
); 
1258 void wxWindowMac::MacOnScroll(wxScrollEvent 
&event 
) 
1260     if ( event
.m_eventObject 
== m_vScrollBar 
|| event
.m_eventObject 
== m_hScrollBar 
) 
1262         wxScrollWinEvent wevent
; 
1263         wevent
.SetPosition(event
.GetPosition()); 
1264         wevent
.SetOrientation(event
.GetOrientation()); 
1265         wevent
.m_eventObject 
= this; 
1267         if (event
.m_eventType 
== wxEVT_SCROLL_TOP
) { 
1268             wevent
.m_eventType 
= wxEVT_SCROLLWIN_TOP
; 
1270         if (event
.m_eventType 
== wxEVT_SCROLL_BOTTOM
) { 
1271             wevent
.m_eventType 
= wxEVT_SCROLLWIN_BOTTOM
; 
1273         if (event
.m_eventType 
== wxEVT_SCROLL_LINEUP
) { 
1274             wevent
.m_eventType 
= wxEVT_SCROLLWIN_LINEUP
; 
1276         if (event
.m_eventType 
== wxEVT_SCROLL_LINEDOWN
) { 
1277             wevent
.m_eventType 
= wxEVT_SCROLLWIN_LINEDOWN
; 
1279         if (event
.m_eventType 
== wxEVT_SCROLL_PAGEUP
) { 
1280             wevent
.m_eventType 
= wxEVT_SCROLLWIN_PAGEUP
; 
1282         if (event
.m_eventType 
== wxEVT_SCROLL_PAGEDOWN
) { 
1283             wevent
.m_eventType 
= wxEVT_SCROLLWIN_PAGEDOWN
; 
1285         if (event
.m_eventType 
== wxEVT_SCROLL_THUMBTRACK
) { 
1286             wevent
.m_eventType 
= wxEVT_SCROLLWIN_THUMBTRACK
; 
1289         GetEventHandler()->ProcessEvent(wevent
); 
1293 // Get the window with the focus 
1294 wxWindowMac 
*wxWindowBase::FindFocus() 
1296     return gFocusWindow 
; 
1299 #if WXWIN_COMPATIBILITY 
1300 // If nothing defined for this, try the parent. 
1301 // E.g. we may be a button loaded from a resource, with no callback function 
1303 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
) 
1305     if ( GetEventHandler()->ProcessEvent(event
)  ) 
1308         m_parent
->GetEventHandler()->OnCommand(win
, event
); 
1310 #endif // WXWIN_COMPATIBILITY_2 
1312 #if WXWIN_COMPATIBILITY 
1313 wxObject
* wxWindowMac::GetChild(int number
) const 
1315     // Return a pointer to the Nth object in the Panel 
1316     wxNode 
*node 
= GetChildren().First(); 
1319         node 
= node
->Next(); 
1322         wxObject 
*obj 
= (wxObject 
*)node
->Data(); 
1328 #endif // WXWIN_COMPATIBILITY 
1330 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
) 
1332     // panel wants to track the window which was the last to have focus in it, 
1333     // so we want to set ourselves as the window which last had focus 
1335     // notice that it's also important to do it upwards the tree becaus 
1336     // otherwise when the top level panel gets focus, it won't set it back to 
1337     // us, but to some other sibling 
1339     // CS:don't know if this is still needed: 
1340     //wxChildFocusEvent eventFocus(this); 
1341     //(void)GetEventHandler()->ProcessEvent(eventFocus); 
1346 void wxWindowMac::Clear() 
1348     wxClientDC 
dc(this); 
1349     wxBrush 
brush(GetBackgroundColour(), wxSOLID
); 
1350     dc
.SetBackground(brush
); 
1354 // Setup background and foreground colours correctly 
1355 void wxWindowMac::SetupColours() 
1358         SetBackgroundColour(GetParent()->GetBackgroundColour()); 
1361 void wxWindowMac::OnIdle(wxIdleEvent
& event
) 
1364    // Check if we need to send a LEAVE event 
1365    if (m_mouseInWindow) 
1368        ::GetCursorPos(&pt); 
1369        if (::WindowFromPoint(pt) != (HWND) GetHWND()) 
1371            // Generate a LEAVE event 
1372            m_mouseInWindow = FALSE; 
1373            MSWOnMouseLeave(pt.x, pt.y, 0); 
1378     // This calls the UI-update mechanism (querying windows for 
1379     // menu/toolbar/control state information) 
1383 // Raise the window to the top of the Z order 
1384 void wxWindowMac::Raise() 
1388 // Lower the window to the bottom of the Z order 
1389 void wxWindowMac::Lower() 
1393 void wxWindowMac::DoSetClientSize(int width
, int height
) 
1395     if ( width 
!= -1 || height 
!= -1 ) 
1398         if ( width 
!= -1 && m_vScrollBar 
) 
1399             width 
+= MAC_SCROLLBAR_SIZE 
; 
1400         if ( height 
!= -1 && m_vScrollBar 
) 
1401             height 
+= MAC_SCROLLBAR_SIZE 
; 
1403         width 
+= MacGetLeftBorderSize(  ) + MacGetRightBorderSize( ) ; 
1404         height 
+= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ) ; 
1406         DoSetSize( -1 , -1 , width 
, height 
) ; 
1411 wxWindowMac
* wxWindowMac::s_lastMouseWindow 
= NULL 
; 
1413 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint 
&point 
, wxWindowMac
** outWin 
) 
1417       if ((point
.x 
< 0) || (point
.y 
< 0) || 
1418           (point
.x 
> (m_width
)) || (point
.y 
> (m_height
))) 
1423       if ((point
.x 
< m_x
) || (point
.y 
< m_y
) || 
1424           (point
.x 
> (m_x 
+ m_width
)) || (point
.y 
> (m_y 
+ m_height
))) 
1428     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1430     wxPoint 
newPoint( point 
) ; 
1432     if ( !IsTopLevel() ) 
1438     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1440         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1441         // added the m_isShown test --dmazzoni 
1442         if ( child
->MacGetRootWindow() == window 
&& child
->m_isShown 
) 
1444             if (child
->MacGetWindowFromPointSub(newPoint 
, outWin 
)) 
1453 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint 
&screenpoint 
, wxWindowMac
** outWin 
) 
1457     Point pt 
= { screenpoint
.y 
, screenpoint
.x 
} ; 
1458     if ( ::FindWindow( pt 
, &window 
) == 3 ) 
1461         wxWindowMac
* win 
= wxFindWinFromMacWindow( window 
) ; 
1464             // No, this yields the CLIENT are, we need the whole frame. RR. 
1465             // point = win->ScreenToClient( point ) ; 
1468             ::GetPort( &port 
) ; 
1469             ::SetPort( UMAGetWindowPort( window 
) ) ; 
1470             ::GlobalToLocal( &pt 
) ; 
1473             wxPoint 
point( pt
.h
, pt
.v 
) ; 
1475             return win
->MacGetWindowFromPointSub( point 
, outWin 
) ; 
1481 extern int wxBusyCursorCount 
; 
1482 static wxWindow 
*gs_lastWhich 
= NULL
; 
1484 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)  
1486     // first trigger a set cursor event 
1488     wxPoint clientorigin 
= GetClientAreaOrigin() ; 
1489     wxSize clientsize 
= GetClientSize() ; 
1491     if ( wxRect2DInt( clientorigin
.x 
, clientorigin
.y 
, clientsize
.x 
, clientsize
.y 
).Contains( wxPoint2DInt( pt 
) ) ) 
1493         wxSetCursorEvent 
event( pt
.x 
, pt
.y 
); 
1495         bool processedEvtSetCursor 
= GetEventHandler()->ProcessEvent(event
); 
1496         if ( processedEvtSetCursor 
&& event
.HasCursor() ) 
1498            cursor 
= event
.GetCursor() ; 
1503             // the test for processedEvtSetCursor is here to prevent using m_cursor 
1504             // if the user code caught EVT_SET_CURSOR() and returned nothing from 
1505             // it - this is a way to say that our cursor shouldn't be used for this 
1507             if ( !processedEvtSetCursor 
&& m_cursor
.Ok() ) 
1517                     cursor 
= *wxSTANDARD_CURSOR  
; 
1521             cursor
.MacInstall() ; 
1523     return cursor
.Ok() ; 
1526 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
) 
1528     if ((event
.m_x 
< m_x
) || (event
.m_y 
< m_y
) || 
1529         (event
.m_x 
> (m_x 
+ m_width
)) || (event
.m_y 
> (m_y 
+ m_height
))) 
1533     if ( IsKindOf( CLASSINFO ( wxStaticBox 
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */) 
1536     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1544     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1546         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1547         if ( child
->MacGetRootWindow() == window 
&& child
->IsShown() && child
->IsEnabled() ) 
1549             if (child
->MacDispatchMouseEvent(event
)) 
1554     wxWindow
* cursorTarget 
= this ; 
1555     wxPoint 
cursorPoint( x 
, y 
) ; 
1557     while( cursorTarget 
&& !cursorTarget
->MacSetupCursor( cursorPoint 
) ) 
1559         cursorTarget 
= cursorTarget
->GetParent() ; 
1561             cursorPoint 
+= cursorTarget
->GetPosition() ; 
1565     event
.SetEventObject( this ) ; 
1567     if ( event
.GetEventType() == wxEVT_LEFT_DOWN 
) 
1569         // set focus to this window 
1570         if (AcceptsFocus() && FindFocus()!=this) 
1575     if ( event
.GetEventType() == wxEVT_MOTION
 
1576             || event
.GetEventType() == wxEVT_ENTER_WINDOW
 
1577             || event
.GetEventType() == wxEVT_LEAVE_WINDOW 
) 
1578         wxToolTip::RelayEvent( this , event
); 
1579 #endif // wxUSE_TOOLTIPS 
1581     if (gs_lastWhich 
!= this) 
1583         gs_lastWhich 
= this; 
1585         // Double clicks must always occur on the same window 
1586         if (event
.GetEventType() == wxEVT_LEFT_DCLICK
) 
1587             event
.SetEventType( wxEVT_LEFT_DOWN 
); 
1588         if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) 
1589             event
.SetEventType( wxEVT_RIGHT_DOWN 
); 
1591         // Same for mouse up events 
1592         if (event
.GetEventType() == wxEVT_LEFT_UP
) 
1594         if (event
.GetEventType() == wxEVT_RIGHT_UP
) 
1598     GetEventHandler()->ProcessEvent( event 
) ; 
1603 wxString 
wxWindowMac::MacGetToolTipString( wxPoint 
&pt 
) 
1607         return m_tooltip
->GetTip() ; 
1612 void wxWindowMac::Update() 
1614     wxTopLevelWindowMac
* win 
= MacGetTopLevelWindow(  ) ; 
1617       win
->MacUpdate( 0 ) ; 
1618 #if TARGET_API_MAC_CARBON 
1619         if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) ) 
1621                 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL 
) ; 
1627 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const 
1629     wxTopLevelWindowMac
* win 
= NULL 
; 
1630     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1633         win 
= wxFindWinFromMacWindow( window 
) ; 
1638 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings 
) 
1640   RgnHandle visRgn 
= NewRgn() ; 
1641   RgnHandle tempRgn 
= NewRgn() ; 
1643   SetRectRgn( visRgn 
, 0 , 0 , m_width 
, m_height 
) ; 
1645   //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox 
1646   if ( IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1648     int borderTop 
= 14 ; 
1649     int borderOther 
= 4 ; 
1651     SetRectRgn( tempRgn 
, borderOther 
, borderTop 
, m_width 
- borderOther 
, m_height 
- borderOther 
) ; 
1652     DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1655   if ( !IsTopLevel() ) 
1657     wxWindow
* parent 
= GetParent() ; 
1660       wxSize size 
= parent
->GetSize() ; 
1663       parent
->MacWindowToRootWindow( &x
, &y 
) ; 
1664       MacRootWindowToWindow( &x 
, &y 
) ; 
1666       SetRectRgn( tempRgn 
,  
1667         x 
+ parent
->MacGetLeftBorderSize() , y 
+ parent
->MacGetTopBorderSize() ,  
1668         x 
+ size
.x 
- parent
->MacGetLeftBorderSize() - parent
->MacGetRightBorderSize(),  
1669         y 
+ size
.y 
- parent
->MacGetTopBorderSize() - parent
->MacGetBottomBorderSize()) ; 
1671       SectRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1672       if ( parent
->IsTopLevel() ) 
1674       parent 
= parent
->GetParent() ; 
1677   if ( respectChildrenAndSiblings 
) 
1679       if ( GetWindowStyle() & wxCLIP_CHILDREN 
) 
1681         for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1683             wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1685             if ( !child
->IsTopLevel() && child
->IsShown() ) 
1687                 SetRectRgn( tempRgn 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1688                 DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1693       if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() ) 
1695         bool thisWindowThrough 
= false ; 
1696         for (wxNode 
*node 
= GetParent()->GetChildren().First(); node
; node 
= node
->Next()) 
1698             wxWindowMac 
*sibling 
= (wxWindowMac
*)node
->Data(); 
1699             if ( sibling 
== this ) 
1701               thisWindowThrough 
= true ; 
1704             if( !thisWindowThrough 
) 
1709             if ( !sibling
->IsTopLevel() && sibling
->IsShown() ) 
1711                 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 
) ; 
1712                 DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1717   m_macVisibleRegion 
= visRgn 
; 
1718   DisposeRgn( visRgn 
) ; 
1719   DisposeRgn( tempRgn 
) ; 
1720   return m_macVisibleRegion 
; 
1723 void wxWindowMac::MacRedraw( WXHRGN updatergnr 
, long time
, bool erase
) 
1725     RgnHandle updatergn 
= (RgnHandle
) updatergnr 
; 
1726     // updatergn is always already clipped to our boundaries 
1727     // it is in window coordinates, not in client coordinates 
1729     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1732         // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates 
1733         RgnHandle ownUpdateRgn 
= NewRgn() ; 
1734         CopyRgn( updatergn 
, ownUpdateRgn 
) ; 
1736         SectRgn( ownUpdateRgn 
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn 
) ; 
1738         // newupdate is the update region in client coordinates 
1739         RgnHandle newupdate 
= NewRgn() ; 
1740         wxSize point 
= GetClientSize() ; 
1741         wxPoint origin 
= GetClientAreaOrigin() ; 
1742         SetRectRgn( newupdate 
, origin
.x 
, origin
.y 
, origin
.x 
+ point
.x 
, origin
.y
+point
.y 
) ; 
1743         SectRgn( newupdate 
, ownUpdateRgn 
, newupdate 
) ; 
1744         OffsetRgn( newupdate 
, -origin
.x 
, -origin
.y 
) ; 
1745         m_updateRegion 
= newupdate 
; 
1746         DisposeRgn( newupdate 
) ; // it's been cloned to m_updateRegion 
1748         if ( erase 
&& !EmptyRgn(ownUpdateRgn
) ) 
1750           wxWindowDC 
dc(this); 
1751           dc
.SetClippingRegion(wxRegion(ownUpdateRgn
)); 
1752           wxEraseEvent 
eevent( GetId(), &dc 
); 
1753           eevent
.SetEventObject( this ); 
1754           GetEventHandler()->ProcessEvent( eevent 
); 
1756           wxNcPaintEvent 
eventNc( GetId() ); 
1757           eventNc
.SetEventObject( this ); 
1758           GetEventHandler()->ProcessEvent( eventNc 
); 
1760         DisposeRgn( ownUpdateRgn 
) ; 
1761         if ( !m_updateRegion
.Empty() ) 
1764           event
.m_timeStamp 
= time 
; 
1765           event
.SetEventObject(this); 
1766           GetEventHandler()->ProcessEvent(event
); 
1770     // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively 
1772     RgnHandle childupdate 
= NewRgn() ; 
1773     for (wxNode 
*node 
= GetChildren().First(); node
; node 
= node
->Next()) 
1775         // calculate the update region for the child windows by intersecting the window rectangle with our own 
1776         // passed in update region and then offset it to be client-wise window coordinates again 
1777         wxWindowMac 
*child 
= (wxWindowMac
*)node
->Data(); 
1778         SetRectRgn( childupdate 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1779         SectRgn( childupdate 
, updatergn 
, childupdate 
) ; 
1780         OffsetRgn( childupdate 
, -child
->m_x 
, -child
->m_y 
) ; 
1781         if ( child
->MacGetRootWindow() == window 
&& child
->IsShown() && !EmptyRgn( childupdate 
) ) 
1783             // because dialogs may also be children 
1784             child
->MacRedraw( childupdate 
, time 
, erase 
) ; 
1787     DisposeRgn( childupdate 
) ; 
1788     // eventually a draw grow box here 
1792 WXHWND 
wxWindowMac::MacGetRootWindow() const 
1794     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1798         if ( iter
->IsTopLevel() ) 
1799             return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ; 
1801         iter 
= iter
->GetParent() ; 
1803     wxASSERT_MSG( 1 , "No valid mac root window" ) ; 
1807 void wxWindowMac::MacCreateScrollBars( long style 
) 
1809     wxASSERT_MSG( m_vScrollBar 
== NULL 
&& m_hScrollBar 
== NULL 
, "attempt to create window twice" ) ; 
1811     bool hasBoth 
= ( style 
& wxVSCROLL 
) && ( style 
& wxHSCROLL 
) ; 
1812     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1: 0 ; 
1814     GetClientSize( &width 
, &height 
) ; 
1816     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1817     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1818     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1819     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1821     m_vScrollBar 
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
, 
1822         vSize 
, wxVERTICAL
); 
1824     if ( style 
& wxVSCROLL 
) 
1830         m_vScrollBar
->Show(false) ; 
1832     m_hScrollBar 
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
, 
1833         hSize 
, wxHORIZONTAL
); 
1834     if ( style  
& wxHSCROLL 
) 
1839         m_hScrollBar
->Show(false) ; 
1842     // because the create does not take into account the client area origin 
1843     MacRepositionScrollBars() ; // we might have a real position shift 
1846 void wxWindowMac::MacRepositionScrollBars() 
1848     bool hasBoth 
= ( m_hScrollBar 
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar 
&& m_vScrollBar
->IsShown()) ; 
1849     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1 : 0 ; 
1851     // get real client area 
1853     int width 
= m_width 
; 
1854     int height 
= m_height 
; 
1856     width 
-= MacGetLeftBorderSize() + MacGetRightBorderSize(); 
1857     height 
-= MacGetTopBorderSize() + MacGetBottomBorderSize(); 
1859     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1860     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1861     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1862     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1869     MacClientToRootWindow( &x 
, &y 
) ; 
1870     MacClientToRootWindow( &w 
, &h 
) ; 
1872     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1874     int totW 
= 10000 , totH 
= 10000; 
1877         if ( iter
->IsTopLevel() ) 
1879             totW 
= iter
->m_width 
; 
1880             totH 
= iter
->m_height 
; 
1884         iter 
= iter
->GetParent() ; 
1912         m_vScrollBar
->SetSize( vPoint
.x 
, vPoint
.y
, vSize
.x
, vSize
.y 
, wxSIZE_ALLOW_MINUS_ONE
); 
1916         m_hScrollBar
->SetSize( hPoint
.x 
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
); 
1920 bool wxWindowMac::AcceptsFocus() const 
1922     return MacCanFocus() && wxWindowBase::AcceptsFocus(); 
1925 WXWidget 
wxWindowMac::MacGetContainerForEmbedding() 
1927     return GetParent()->MacGetContainerForEmbedding() ; 
1930 void wxWindowMac::MacSuperChangedPosition() 
1932     // only window-absolute structures have to be moved i.e. controls 
1934     wxNode 
*node 
= GetChildren().First(); 
1937         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->Data(); 
1938         child
->MacSuperChangedPosition() ; 
1939         node 
= node
->Next(); 
1943 void wxWindowMac::MacTopLevelWindowChangedPosition() 
1945     // only screen-absolute structures have to be moved i.e. glcanvas 
1947     wxNode 
*node 
= GetChildren().First(); 
1950         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->Data(); 
1951         child
->MacTopLevelWindowChangedPosition() ; 
1952         node 
= node
->Next(); 
1955 long wxWindowMac::MacGetLeftBorderSize( ) const 
1960     if (m_windowStyle 
& wxRAISED_BORDER 
|| m_windowStyle 
& wxSUNKEN_BORDER 
) 
1963 #if wxMAC_USE_THEME_BORDER 
1965           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
1970     else if (  m_windowStyle 
&wxDOUBLE_BORDER
) 
1973 #if wxMAC_USE_THEME_BORDER 
1975           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
1980     else if (m_windowStyle 
&wxSIMPLE_BORDER
) 
1987 long wxWindowMac::MacGetRightBorderSize( ) const 
1989     // they are all symmetric in mac themes 
1990     return MacGetLeftBorderSize() ; 
1993 long wxWindowMac::MacGetTopBorderSize( ) const 
1995     // they are all symmetric in mac themes 
1996     return MacGetLeftBorderSize() ; 
1999 long wxWindowMac::MacGetBottomBorderSize( ) const 
2001     // they are all symmetric in mac themes 
2002     return MacGetLeftBorderSize() ; 
2005 long wxWindowMac::MacRemoveBordersFromStyle( long style 
) 
2007     return style 
& ~( wxDOUBLE_BORDER 
| wxSUNKEN_BORDER 
| wxRAISED_BORDER 
| wxBORDER 
| wxSTATIC_BORDER 
) ; 
2010 // Find the wxWindowMac at the current mouse position, returning the mouse 
2012 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
) 
2014     pt 
= wxGetMousePosition(); 
2015     wxWindowMac
* found 
= wxFindWindowAtPoint(pt
); 
2019 // Get the current mouse position. 
2020 wxPoint 
wxGetMousePosition() 
2023     wxGetMousePosition(& x
, & y
); 
2024     return wxPoint(x
, y
);