1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxWindowMac 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "window.h" 
  18 #include "wx/window.h" 
  20 #include "wx/dcclient.h" 
  24 #include "wx/layout.h" 
  25 #include "wx/dialog.h" 
  26 #include "wx/listbox.h" 
  27 #include "wx/scrolbar.h" 
  28 #include "wx/statbox.h" 
  29 #include "wx/button.h" 
  30 #include "wx/settings.h" 
  31 #include "wx/msgdlg.h" 
  33 #include "wx/notebook.h" 
  34 #include "wx/tabctrl.h" 
  35 #include "wx/tooltip.h" 
  36 #include "wx/statusbr.h" 
  37 #include "wx/menuitem.h" 
  38 #include "wx/spinctrl.h" 
  40 #include "wx/geometry.h" 
  46 #define wxWINDOW_HSCROLL 5998 
  47 #define wxWINDOW_VSCROLL 5997 
  48 #define MAC_SCROLLBAR_SIZE 16 
  50 #include "wx/mac/uma.h" 
  53 #include <ToolUtils.h> 
  56 #if  wxUSE_DRAG_AND_DROP 
  62 extern wxList wxPendingDelete
; 
  63 wxWindowMac
* gFocusWindow 
= NULL 
; 
  65 #ifdef __WXUNIVERSAL__ 
  66     IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
) 
  68     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
) 
  69 #endif // __WXUNIVERSAL__/__WXMAC__ 
  71 #if !USE_SHARED_LIBRARY 
  73 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
) 
  74   EVT_NC_PAINT(wxWindowMac::OnNcPaint
) 
  75   EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
) 
  76   EVT_SET_FOCUS(wxWindowMac::OnSetFocus
) 
  77   EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
) 
  82 #define wxMAC_DEBUG_REDRAW 0 
  83 #ifndef wxMAC_DEBUG_REDRAW 
  84 #define wxMAC_DEBUG_REDRAW 0 
  87 #define wxMAC_USE_THEME_BORDER 0 
  90 // =========================================================================== 
  92 // =========================================================================== 
  95 // ---------------------------------------------------------------------------- 
  96 // constructors and such 
  97 // ---------------------------------------------------------------------------- 
  99 void wxWindowMac::Init() 
 101     m_backgroundTransparent 
= FALSE
; 
 103     // as all windows are created with WS_VISIBLE style... 
 111     m_hScrollBar 
= NULL 
; 
 112     m_vScrollBar 
= NULL 
; 
 116 wxWindowMac::~wxWindowMac() 
 120     // deleting a window while it is shown invalidates the region 
 122         wxWindowMac
* iter 
= this ; 
 124             if ( iter
->IsTopLevel() ) 
 129             iter 
= iter
->GetParent() ; 
 134     m_isBeingDeleted 
= TRUE
; 
 136 #ifndef __WXUNIVERSAL__ 
 137     // VS: make sure there's no wxFrame with last focus set to us: 
 138     for ( wxWindow 
*win 
= GetParent(); win
; win 
= win
->GetParent() ) 
 140         wxFrame 
*frame 
= wxDynamicCast(win
, wxFrame
); 
 143             if ( frame
->GetLastFocus() == this ) 
 145                 frame
->SetLastFocus((wxWindow
*)NULL
); 
 150 #endif // __WXUNIVERSAL__ 
 152     if ( s_lastMouseWindow 
== this ) 
 154         s_lastMouseWindow 
= NULL 
; 
 157     wxFrame
* frame 
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame 
) ; 
 160         if ( frame
->GetLastFocus() == this ) 
 161             frame
->SetLastFocus( NULL 
) ; 
 164     if ( gFocusWindow 
== this ) 
 166         gFocusWindow 
= NULL 
; 
 171     // delete our drop target if we've got one 
 172 #if wxUSE_DRAG_AND_DROP 
 173     if ( m_dropTarget 
!= NULL 
) 
 178 #endif // wxUSE_DRAG_AND_DROP 
 182 bool wxWindowMac::Create(wxWindowMac 
*parent
, wxWindowID id
, 
 186            const wxString
& name
) 
 188     wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") ); 
 191     // wxGTK doesn't allow to create controls with static box as the parent so 
 192     // this will result in a crash when the program is ported to wxGTK - warn 
 195     // the correct solution is to create the controls as siblings of the 
 197     wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
), 
 198                   _T("wxStaticBox can't be used as a window parent!") ); 
 199 #endif // wxUSE_STATBOX 
 201     if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) ) 
 204     parent
->AddChild(this); 
 208     AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
); 
 209     m_width 
= WidthDefault( size
.x 
); 
 210     m_height 
= HeightDefault( size
.y 
) ; 
 211 #ifndef __WXUNIVERSAL__ 
 212     // Don't give scrollbars to wxControls unless they ask for them 
 213     if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) || 
 214          (IsKindOf(CLASSINFO(wxControl
)) && ( style 
& wxHSCROLL 
|| style 
& wxVSCROLL
))) 
 216         MacCreateScrollBars( style 
) ; 
 220     wxWindowCreateEvent 
event(this); 
 221     GetEventHandler()->AddPendingEvent(event
); 
 226 void wxWindowMac::SetFocus() 
 228     if ( gFocusWindow 
== this ) 
 231     if ( AcceptsFocus() ) 
 237                 if ( gFocusWindow
->m_caret 
) 
 239                       gFocusWindow
->m_caret
->OnKillFocus(); 
 241 #endif // wxUSE_CARET 
 242 #ifndef __WXUNIVERSAL__ 
 243             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 244             if ( control 
&& control
->GetMacControl() ) 
 246                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNoPart 
) ; 
 247                 control
->MacRedrawControl() ; 
 250             // Without testing the window id, for some reason 
 251             // a kill focus event can still be sent to 
 252             // the control just being focussed. 
 253             int thisId 
= this->m_windowId
; 
 254             int gFocusWindowId 
= gFocusWindow
->m_windowId
; 
 255             if (gFocusWindowId 
!= thisId
) 
 257                 wxFocusEvent 
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
); 
 258                 event
.SetEventObject(gFocusWindow
); 
 259                 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ; 
 262         gFocusWindow 
= this ; 
 268                 m_caret
->OnSetFocus(); 
 270             #endif // wxUSE_CARET 
 271             // panel wants to track the window which was the last to have focus in it 
 272             wxChildFocusEvent 
eventFocus(this); 
 273             GetEventHandler()->ProcessEvent(eventFocus
); 
 275       #ifndef __WXUNIVERSAL__ 
 276             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 277             if ( control 
&& control
->GetMacControl() ) 
 279                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNextPart 
) ; 
 282             wxFocusEvent 
event(wxEVT_SET_FOCUS
, m_windowId
); 
 283             event
.SetEventObject(this); 
 284             GetEventHandler()->ProcessEvent(event
) ; 
 289 bool wxWindowMac::Enable(bool enable
) 
 291     if ( !wxWindowBase::Enable(enable
) ) 
 294     MacSuperEnabled( enable 
) ; 
 299 void wxWindowMac::DoCaptureMouse() 
 301     wxTheApp
->s_captureWindow 
= this ; 
 304 wxWindow
* wxWindowBase::GetCapture() 
 306     return wxTheApp
->s_captureWindow 
; 
 309 void wxWindowMac::DoReleaseMouse() 
 311     wxTheApp
->s_captureWindow 
= NULL 
; 
 314 #if    wxUSE_DRAG_AND_DROP 
 316 void wxWindowMac::SetDropTarget(wxDropTarget 
*pDropTarget
) 
 318     if ( m_dropTarget 
!= 0 ) { 
 322     m_dropTarget 
= pDropTarget
; 
 323     if ( m_dropTarget 
!= 0 ) 
 331 // Old style file-manager drag&drop 
 332 void wxWindowMac::DragAcceptFiles(bool accept
) 
 338 void wxWindowMac::DoGetSize(int *x
, int *y
) const 
 341      if(y
)   *y 
= m_height 
; 
 344 void wxWindowMac::DoGetPosition(int *x
, int *y
) const 
 350     if ( !IsTopLevel() && GetParent()) 
 352         wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
 361 bool wxWindowMac::DoPopupMenu(wxMenu 
*menu
, int x
, int y
) 
 363     menu
->SetInvokingWindow(this); 
 366     if ( x 
== -1 && y 
== -1 ) 
 368         wxPoint mouse 
= wxGetMousePosition(); 
 369         x 
= mouse
.x
; y 
= mouse
.y
; 
 373         ClientToScreen( &x 
, &y 
) ; 
 376     menu
->MacBeforeDisplay( true ) ; 
 377     long menuResult 
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ; 
 378     if ( HiWord(menuResult
) != 0 ) 
 381         GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id 
) ; 
 382         wxMenuItem
* item 
= NULL 
; 
 384         item 
= menu
->FindItem(id
, &realmenu
) ; 
 385         if (item
->IsCheckable()) 
 387             item
->Check( !item
->IsChecked() ) ; 
 389         menu
->SendEvent( id 
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ; 
 391     menu
->MacAfterDisplay( true ) ; 
 393     menu
->SetInvokingWindow(NULL
); 
 399 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const 
 401     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 403     Point       localwhere 
= {0,0} ; 
 405     if(x
)   localwhere
.h 
= * x 
; 
 406     if(y
)   localwhere
.v 
= * y 
; 
 410     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 411     ::GlobalToLocal( &localwhere 
) ; 
 414     if(x
)   *x 
= localwhere
.h 
; 
 415     if(y
)   *y 
= localwhere
.v 
; 
 417     MacRootWindowToWindow( x 
, y 
) ; 
 419         *x 
-= MacGetLeftBorderSize() ; 
 421         *y 
-= MacGetTopBorderSize() ; 
 424 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const 
 426     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 429         *x 
+= MacGetLeftBorderSize() ; 
 431         *y 
+= MacGetTopBorderSize() ; 
 433     MacWindowToRootWindow( x 
, y 
) ; 
 435     Point       localwhere 
= { 0,0 }; 
 436     if(x
)   localwhere
.h 
= * x 
; 
 437     if(y
)   localwhere
.v 
= * y 
; 
 441     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 443     ::LocalToGlobal( &localwhere 
) ; 
 445     if(x
)   *x 
= localwhere
.h 
; 
 446     if(y
)   *y 
= localwhere
.v 
; 
 449 void wxWindowMac::MacClientToRootWindow( int *x 
, int *y 
) const 
 451     wxPoint origin 
= GetClientAreaOrigin() ; 
 452     if(x
)   *x 
+= origin
.x 
; 
 453     if(y
)   *y 
+= origin
.y 
; 
 455     MacWindowToRootWindow( x 
, y 
) ; 
 458 void wxWindowMac::MacRootWindowToClient( int *x 
, int *y 
) const 
 460     wxPoint origin 
= GetClientAreaOrigin() ; 
 461     MacRootWindowToWindow( x 
, y 
) ; 
 462     if(x
)   *x 
-= origin
.x 
; 
 463     if(y
)   *y 
-= origin
.y 
; 
 466 void wxWindowMac::MacWindowToRootWindow( int *x 
, int *y 
) const 
 472         GetParent()->MacWindowToRootWindow( x 
, y 
) ; 
 476 void wxWindowMac::MacRootWindowToWindow( int *x 
, int *y 
) const 
 482         GetParent()->MacRootWindowToWindow( x 
, y 
) ; 
 486 bool wxWindowMac::SetCursor(const wxCursor
& cursor
) 
 488     if (m_cursor 
== cursor
) 
 491     if (wxNullCursor 
== cursor
) 
 493         if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR 
) ) 
 498         if ( ! wxWindowBase::SetCursor( cursor 
) ) 
 502     wxASSERT_MSG( m_cursor
.Ok(), 
 503         wxT("cursor must be valid after call to the base version")); 
 506     wxWindowMac 
*mouseWin 
; 
 509     // Change the cursor NOW if we're within the correct window 
 511     if ( MacGetWindowFromPoint( wxPoint( pt
.h 
, pt
.v 
) , &mouseWin 
) ) 
 513         if ( mouseWin 
== this && !wxIsBusy() ) 
 515             m_cursor
.MacInstall() ; 
 523 // Get size *available for subwindows* i.e. excluding menu bar etc. 
 524 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const 
 530     ww 
-= MacGetLeftBorderSize(  )  + MacGetRightBorderSize(  ) ; 
 531     hh 
-= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ); 
 533     if ( (m_vScrollBar 
&& m_vScrollBar
->IsShown()) || (m_hScrollBar  
&& m_hScrollBar
->IsShown()) ) 
 540         MacClientToRootWindow( &x1 
, &y1 
) ; 
 541         MacClientToRootWindow( &w 
, &h 
) ; 
 543         wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
 545         int totW 
= 10000 , totH 
= 10000; 
 548             if ( iter
->IsTopLevel() ) 
 550                 totW 
= iter
->m_width 
; 
 551                 totH 
= iter
->m_height 
; 
 555             iter 
= iter
->GetParent() ; 
 558         if (m_hScrollBar  
&& m_hScrollBar
->IsShown() ) 
 560             hh 
-= MAC_SCROLLBAR_SIZE
; 
 566         if (m_vScrollBar  
&& m_vScrollBar
->IsShown() ) 
 568             ww 
-= MAC_SCROLLBAR_SIZE
; 
 580 // ---------------------------------------------------------------------------- 
 582 // ---------------------------------------------------------------------------- 
 586 void wxWindowMac::DoSetToolTip(wxToolTip 
*tooltip
) 
 588     wxWindowBase::DoSetToolTip(tooltip
); 
 591         m_tooltip
->SetWindow(this); 
 594 #endif // wxUSE_TOOLTIPS 
 596 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
) 
 600     int former_w 
= m_width 
; 
 601     int former_h 
= m_height 
; 
 603     int actualWidth 
= width
; 
 604     int actualHeight 
= height
; 
 608     if ((m_minWidth 
!= -1) && (actualWidth 
< m_minWidth
)) 
 609         actualWidth 
= m_minWidth
; 
 610     if ((m_minHeight 
!= -1) && (actualHeight 
< m_minHeight
)) 
 611         actualHeight 
= m_minHeight
; 
 612     if ((m_maxWidth 
!= -1) && (actualWidth 
> m_maxWidth
)) 
 613         actualWidth 
= m_maxWidth
; 
 614     if ((m_maxHeight 
!= -1) && (actualHeight 
> m_maxHeight
)) 
 615         actualHeight 
= m_maxHeight
; 
 617     bool doMove 
= false ; 
 618     bool doResize 
= false ; 
 620     if ( actualX 
!= former_x 
|| actualY 
!= former_y 
) 
 624     if ( actualWidth 
!= former_w 
|| actualHeight 
!= former_h 
) 
 629     if ( doMove 
|| doResize 
) 
 631         // erase former position 
 633         bool partialRepaint 
= false ; 
 635         if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) ) 
 637             wxPoint 
oldPos( m_x 
, m_y 
) ; 
 638             wxPoint 
newPos( actualX 
, actualY 
) ; 
 639             MacWindowToRootWindow( &oldPos
.x 
, &oldPos
.y 
) ; 
 640             MacWindowToRootWindow( &newPos
.x 
, &newPos
.y 
) ; 
 641             if ( oldPos 
== newPos 
) 
 643                 partialRepaint 
= true ; 
 644                 RgnHandle oldRgn
,newRgn
,diffRgn 
; 
 649                 // invalidate the differences between the old and the new area 
 651                 SetRectRgn(oldRgn 
, oldPos
.x 
, oldPos
.y 
, oldPos
.x 
+ m_width 
, oldPos
.y 
+ m_height 
) ; 
 652                 SetRectRgn(newRgn 
, newPos
.x 
, newPos
.y 
, newPos
.x 
+ actualWidth 
, newPos
.y 
+ actualHeight 
) ; 
 653                 DiffRgn( newRgn 
, oldRgn 
, diffRgn 
) ; 
 654                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 655                 DiffRgn( oldRgn 
, newRgn 
, diffRgn 
) ; 
 656                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 658                 // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really 
 659                 // changing pixels... 
 661                 if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 ||  
 662                         MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 ) 
 664                         RgnHandle innerOldRgn
, innerNewRgn 
; 
 665                         innerOldRgn 
= NewRgn() ; 
 666                         innerNewRgn 
= NewRgn() ; 
 668                         SetRectRgn(innerOldRgn 
, oldPos
.x 
+ MacGetLeftBorderSize()  , oldPos
.y 
+ MacGetTopBorderSize() ,  
 669                                 oldPos
.x 
+ m_width 
- MacGetRightBorderSize() , oldPos
.y 
+ m_height 
- MacGetBottomBorderSize() ) ; 
 670                     DiffRgn( oldRgn 
, innerOldRgn 
, diffRgn 
) ; 
 671                         InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 673                         SetRectRgn(innerNewRgn 
, newPos
.x 
+ MacGetLeftBorderSize()  , newPos
.y 
+ MacGetTopBorderSize() ,  
 674                                 newPos
.x 
+ actualWidth 
- MacGetRightBorderSize() , newPos
.y 
+ actualHeight 
- MacGetBottomBorderSize() ) ; 
 675                     DiffRgn( newRgn 
, innerNewRgn 
, diffRgn 
) ; 
 676                         InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 678                         DisposeRgn( innerOldRgn 
) ; 
 679                         DisposeRgn( innerNewRgn 
) ; 
 684                 DisposeRgn(diffRgn
) ; 
 688         if ( !partialRepaint 
) 
 693         m_width 
= actualWidth 
; 
 694         m_height 
= actualHeight 
; 
 696         // update any low-level frame-relative positions 
 698         MacUpdateDimensions() ; 
 699         // erase new position 
 701         if ( !partialRepaint 
) 
 704             wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified 
 706         MacRepositionScrollBars() ; 
 709             wxPoint 
point(m_x
, m_y
); 
 710             wxMoveEvent 
event(point
, m_windowId
); 
 711             event
.SetEventObject(this); 
 712             GetEventHandler()->ProcessEvent(event
) ; 
 716             MacRepositionScrollBars() ; 
 717             wxSize 
size(m_width
, m_height
); 
 718             wxSizeEvent 
event(size
, m_windowId
); 
 719             event
.SetEventObject(this); 
 720             GetEventHandler()->ProcessEvent(event
); 
 726 // set the size of the window: if the dimensions are positive, just use them, 
 727 // but if any of them is equal to -1, it means that we must find the value for 
 728 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in 
 729 // which case -1 is a valid value for x and y) 
 731 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate 
 732 // the width/height to best suit our contents, otherwise we reuse the current 
 734 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 736     // get the current size and position... 
 737     int currentX
, currentY
; 
 738     GetPosition(¤tX
, ¤tY
); 
 740     int currentW
,currentH
; 
 741     GetSize(¤tW
, ¤tH
); 
 743     // ... and don't do anything (avoiding flicker) if it's already ok 
 744     if ( x 
== currentX 
&& y 
== currentY 
&& 
 745         width 
== currentW 
&& height 
== currentH 
) 
 747         MacRepositionScrollBars() ; // we might have a real position shift 
 751     if ( x 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 753     if ( y 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 756     AdjustForParentClientOrigin(x
, y
, sizeFlags
); 
 761         if ( sizeFlags 
& wxSIZE_AUTO_WIDTH 
) 
 763             size 
= DoGetBestSize(); 
 768             // just take the current one 
 775         if ( sizeFlags 
& wxSIZE_AUTO_HEIGHT 
) 
 779                 size 
= DoGetBestSize(); 
 781             //else: already called DoGetBestSize() above 
 787             // just take the current one 
 792     DoMoveWindow(x
, y
, width
, height
); 
 795 // For implementation purposes - sometimes decorations make the client area 
 798 wxPoint 
wxWindowMac::GetClientAreaOrigin() const 
 800     return wxPoint(MacGetLeftBorderSize(  ) , MacGetTopBorderSize(  ) ); 
 803 void wxWindowMac::SetTitle(const wxString
& title
) 
 808 wxString 
wxWindowMac::GetTitle() const 
 813 bool wxWindowMac::Show(bool show
) 
 815     if ( !wxWindowBase::Show(show
) ) 
 818     MacSuperShown( show 
) ; 
 824 void wxWindowMac::MacSuperShown( bool show 
) 
 826     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
 829         wxWindowMac 
*child 
= node
->GetData(); 
 830         if ( child
->m_isShown 
) 
 831             child
->MacSuperShown( show 
) ; 
 832         node 
= node
->GetNext(); 
 836 void wxWindowMac::MacSuperEnabled( bool enabled 
) 
 840       // to be absolutely correct we'd have to invalidate (with eraseBkground 
 841       // because unter MacOSX the frames are drawn with an addXXX mode) 
 844     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
 847         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->GetData(); 
 848         if ( child
->m_isShown 
) 
 849             child
->MacSuperEnabled( enabled 
) ; 
 850         node 
= node
->GetNext(); 
 854 bool wxWindowMac::MacIsReallyShown() const 
 856     if ( m_isShown 
&& (m_parent 
!= NULL 
&& !IsTopLevel() ) ) { 
 857         return m_parent
->MacIsReallyShown(); 
 861     bool status = m_isShown ; 
 862     wxWindowMac * win = this ; 
 863     while ( status && win->m_parent != NULL ) 
 865         win = win->m_parent ; 
 866         status = win->m_isShown ; 
 872 int wxWindowMac::GetCharHeight() const 
 874     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 875     return dc
.GetCharHeight() ; 
 878 int wxWindowMac::GetCharWidth() const 
 880     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 881     return dc
.GetCharWidth() ; 
 884 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
, 
 885                            int *descent
, int *externalLeading
, const wxFont 
*theFont 
) const 
 887     const wxFont 
*fontToUse 
= theFont
; 
 891     wxClientDC 
dc( (wxWindowMac
*) this ) ; 
 893     dc
.GetTextExtent( string 
, &lx 
, &ly 
, &ld
, &le
, (wxFont 
*)fontToUse 
) ; 
 894     if ( externalLeading 
) 
 895         *externalLeading 
= le 
; 
 905  * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect 
 906  * we always intersect with the entire window, not only with the client area 
 909 void wxWindowMac::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 911     if ( MacGetTopLevelWindow() == NULL 
) 
 914     if ( !MacIsReallyShown() ) 
 917      wxPoint client 
= GetClientAreaOrigin(); 
 920     int x2 
= m_width 
- client
.x
; 
 921     int y2 
= m_height 
- client
.y
; 
 923     if (IsKindOf( CLASSINFO(wxButton
))) 
 925         // buttons have an "aura" 
 932     Rect clientrect 
= { y1
, x1
, y2
, x2 
}; 
 936         Rect r 
= { rect
->y 
, rect
->x 
, rect
->y 
+ rect
->height 
, rect
->x 
+ rect
->width 
} ; 
 937         SectRect( &clientrect 
, &r 
, &clientrect 
) ; 
 940     if ( !EmptyRect( &clientrect 
) ) 
 942       int top 
= 0 , left 
= 0 ; 
 944       MacClientToRootWindow( &left 
, &top 
) ; 
 945       OffsetRect( &clientrect 
, left 
, top 
) ; 
 947       MacGetTopLevelWindow()->MacInvalidate( &clientrect 
, eraseBack 
) ; 
 951 wxWindowMac 
*wxGetActiveWindow() 
 953     // actually this is a windows-only concept 
 957 // Coordinates relative to the window 
 958 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
) 
 960     // We really don't move the mouse programmatically under Mac. 
 963 const wxBrush
& wxWindowMac::MacGetBackgroundBrush() 
 965     if ( m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 967         m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground 
) ; 
 969     else if (  m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) ) 
 971         // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether 
 972         // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have 
 973         // either a non gray background color or a non control window 
 975         WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 977         wxWindowMac
* parent 
= GetParent() ; 
 980             if ( parent
->MacGetRootWindow() != (WXWindow
) window 
) 
 982                 // we are in a different window on the mac system 
 988                 if ( parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) 
 989                     && parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 991                     // if we have any other colours in the hierarchy 
 992                     m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour 
) ; 
 995                 // if we have the normal colours in the hierarchy but another control etc. -> use it's background 
 996                 if ( parent
->IsKindOf( CLASSINFO( wxNotebook 
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl 
) )) 
 998                     Rect extent 
= { 0 , 0 , 0 , 0 } ; 
1001                     wxSize size 
= parent
->GetSize() ; 
1002                     parent
->MacClientToRootWindow( &x 
, &y 
) ; 
1006                     extent
.right 
= x 
+ size
.x 
; 
1007                     extent
.bottom 
= y 
+ size
.y 
; 
1008                     m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane 
, (WXRECTPTR
) &extent 
) ; // todo eventually change for inactive 
1012             parent 
= parent
->GetParent() ; 
1016             m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive 
) ; // todo eventually change for inactive 
1021         m_macBackgroundBrush
.SetColour( m_backgroundColour 
) ; 
1024     return m_macBackgroundBrush 
; 
1027 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
) 
1029     event
.GetDC()->Clear() ; 
1032 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event 
) 
1034     wxWindowDC 
dc(this) ; 
1035     wxMacPortSetter 
helper(&dc
) ; 
1037     MacPaintBorders( dc
.m_macLocalOrigin
.x 
, dc
.m_macLocalOrigin
.y
) ; 
1040 int wxWindowMac::GetScrollPos(int orient
) const 
1042     if ( orient 
== wxHORIZONTAL 
) 
1045            return m_hScrollBar
->GetThumbPosition() ; 
1050            return m_vScrollBar
->GetThumbPosition() ; 
1055 // This now returns the whole range, not just the number 
1056 // of positions that we can scroll. 
1057 int wxWindowMac::GetScrollRange(int orient
) const 
1059     if ( orient 
== wxHORIZONTAL 
) 
1062            return m_hScrollBar
->GetRange() ; 
1067            return m_vScrollBar
->GetRange() ; 
1072 int wxWindowMac::GetScrollThumb(int orient
) const 
1074     if ( orient 
== wxHORIZONTAL 
) 
1077            return m_hScrollBar
->GetThumbSize() ; 
1082            return m_vScrollBar
->GetThumbSize() ; 
1087 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
) 
1089     if ( orient 
== wxHORIZONTAL 
) 
1092            m_hScrollBar
->SetThumbPosition( pos 
) ; 
1097            m_vScrollBar
->SetThumbPosition( pos 
) ; 
1101 void wxWindowMac::MacPaintBorders( int left 
, int top 
) 
1107     wxGetOsVersion( &major
, &minor 
); 
1109     RGBColor white 
= { 0xFFFF, 0xFFFF , 0xFFFF } ; 
1110     RGBColor face 
= { 0xDDDD, 0xDDDD , 0xDDDD } ; 
1112     RGBColor darkShadow 
= { 0x0000, 0x0000 , 0x0000 } ; 
1113     RGBColor lightShadow 
= { 0x4444, 0x4444 , 0x4444 } ; 
1114     // OS X has lighter border edges than classic: 
1117         darkShadow
.red          
= 0x8E8E; 
1118         darkShadow
.green        
= 0x8E8E; 
1119         darkShadow
.blue         
= 0x8E8E; 
1120         lightShadow
.red         
= 0xBDBD; 
1121         lightShadow
.green       
= 0xBDBD; 
1122         lightShadow
.blue        
= 0xBDBD; 
1127     if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) ) 
1129 #if wxMAC_USE_THEME_BORDER 
1130         Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1133         GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; 
1134         InsetRect( &rect , border , border ); 
1135         DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; 
1138         DrawThemePrimaryGroup(&rect  
,IsEnabled() ? kThemeStateActive 
: kThemeStateInactive
) ; 
1140         bool sunken 
= HasFlag( wxSUNKEN_BORDER 
) ; 
1141         RGBForeColor( &face 
); 
1142         MoveTo( left 
+ 0 , top 
+ m_height 
- 2 ); 
1143         LineTo( left 
+ 0 , top 
+ 0 ); 
1144         LineTo( left 
+ m_width 
- 2 , top 
+ 0 ); 
1146         MoveTo( left 
+ 2 , top 
+ m_height 
- 3 ); 
1147         LineTo( left 
+ m_width 
- 3 , top 
+ m_height 
- 3 ); 
1148         LineTo( left 
+ m_width 
- 3 , top 
+ 2 ); 
1150         RGBForeColor( sunken 
? &face 
: &darkShadow 
); 
1151         MoveTo( left 
+ 0 , top 
+ m_height 
- 1 ); 
1152         LineTo( left 
+ m_width 
- 1 , top 
+ m_height 
- 1 ); 
1153         LineTo( left 
+ m_width 
- 1 , top 
+ 0 ); 
1155         RGBForeColor( sunken 
? &lightShadow 
: &white 
); 
1156         MoveTo( left 
+ 1 , top 
+ m_height 
- 3 ); 
1157         LineTo( left 
+ 1, top 
+ 1 ); 
1158         LineTo( left 
+ m_width 
- 3 , top 
+ 1 ); 
1160         RGBForeColor( sunken 
? &white 
: &lightShadow 
); 
1161         MoveTo( left 
+ 1 , top 
+ m_height 
- 2 ); 
1162         LineTo( left 
+ m_width 
- 2 , top 
+ m_height 
- 2 ); 
1163         LineTo( left 
+ m_width 
- 2 , top 
+ 1 ); 
1165         RGBForeColor( sunken 
? &darkShadow 
: &face 
); 
1166         MoveTo( left 
+ 2 , top 
+ m_height 
- 4 ); 
1167         LineTo( left 
+ 2 , top 
+ 2 ); 
1168         LineTo( left 
+ m_width 
- 4 , top 
+ 2 ); 
1171     else if (HasFlag(wxSIMPLE_BORDER
)) 
1173         Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1174         RGBForeColor( &darkShadow 
) ; 
1175         FrameRect( &rect 
) ; 
1179 void wxWindowMac::RemoveChild( wxWindowBase 
*child 
) 
1181     if ( child 
== m_hScrollBar 
) 
1182         m_hScrollBar 
= NULL 
; 
1183     if ( child 
== m_vScrollBar 
) 
1184         m_vScrollBar 
= NULL 
; 
1186     wxWindowBase::RemoveChild( child 
) ; 
1189 // New function that will replace some of the above. 
1190 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
, 
1191     int range
, bool refresh
) 
1193     if ( orient 
== wxHORIZONTAL 
) 
1197             if ( range 
== 0 || thumbVisible 
>= range 
) 
1199                 if ( m_hScrollBar
->IsShown() ) 
1200                     m_hScrollBar
->Show(false) ; 
1204                 if ( !m_hScrollBar
->IsShown() ) 
1205                     m_hScrollBar
->Show(true) ; 
1206                 m_hScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1214             if ( range 
== 0 || thumbVisible 
>= range 
) 
1216                 if ( m_vScrollBar
->IsShown() ) 
1217                     m_vScrollBar
->Show(false) ; 
1221                 if ( !m_vScrollBar
->IsShown() ) 
1222                     m_vScrollBar
->Show(true) ; 
1223                 m_vScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1227     MacRepositionScrollBars() ; 
1230 // Does a physical scroll 
1231 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
1233     if( dx 
== 0 && dy 
==0 ) 
1238         wxClientDC 
dc(this) ; 
1239         wxMacPortSetter 
helper(&dc
) ; 
1241         int width 
, height 
; 
1242         GetClientSize( &width 
, &height 
) ; 
1244         Rect scrollrect 
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ; 
1245         RgnHandle updateRgn 
= NewRgn() ; 
1246         ClipRect( &scrollrect 
) ; 
1249             Rect r 
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y 
+ rect
->height
) , 
1250                 dc
.XLOG2DEVMAC(rect
->x 
+ rect
->width
) } ; 
1251             SectRect( &scrollrect 
, &r 
, &scrollrect 
) ; 
1253         ScrollRect( &scrollrect 
, dx 
, dy 
, updateRgn 
) ; 
1254         // we also have to scroll the update rgn in this rectangle  
1255         // in order not to loose updates 
1256         WindowRef rootWindow 
= (WindowRef
) MacGetRootWindow() ; 
1257         RgnHandle formerUpdateRgn 
= NewRgn() ; 
1258         RgnHandle scrollRgn 
= NewRgn() ; 
1259         RectRgn( scrollRgn 
, &scrollrect 
) ; 
1260         GetWindowUpdateRgn( rootWindow 
, formerUpdateRgn 
) ; 
1262         LocalToGlobal( &pt 
) ; 
1263         OffsetRgn( formerUpdateRgn 
, -pt
.h 
, -pt
.v 
) ; 
1264         SectRgn( formerUpdateRgn 
, scrollRgn 
, formerUpdateRgn 
) ; 
1265         if ( !EmptyRgn( formerUpdateRgn 
) ) 
1267             MacOffsetRgn( formerUpdateRgn 
, dx 
, dy 
) ; 
1268             SectRgn( formerUpdateRgn 
, scrollRgn 
, formerUpdateRgn 
) ; 
1269             InvalWindowRgn(rootWindow  
,  formerUpdateRgn 
) ; 
1271         InvalWindowRgn(rootWindow  
,  updateRgn 
) ; 
1272         DisposeRgn( updateRgn 
) ; 
1273         DisposeRgn( formerUpdateRgn 
) ; 
1274         DisposeRgn( scrollRgn 
) ; 
1277     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1279         wxWindowMac 
*child 
= node
->GetData(); 
1280         if (child 
== m_vScrollBar
) continue; 
1281         if (child 
== m_hScrollBar
) continue; 
1282         if (child
->IsTopLevel()) continue; 
1285         child
->GetPosition( &x
, &y 
); 
1287         child
->GetSize( &w
, &h 
); 
1291             if (rect
->Intersects(rc
)) 
1292                 child
->SetSize( x
+dx
, y
+dy
, w
, h 
); 
1296             child
->SetSize( x
+dx
, y
+dy
, w
, h 
);          
1304 void wxWindowMac::MacOnScroll(wxScrollEvent 
&event 
) 
1306     if ( event
.GetEventObject() == m_vScrollBar 
|| event
.GetEventObject() == m_hScrollBar 
) 
1308         wxScrollWinEvent wevent
; 
1309         wevent
.SetPosition(event
.GetPosition()); 
1310         wevent
.SetOrientation(event
.GetOrientation()); 
1311         wevent
.SetEventObject(this); 
1313         if (event
.GetEventType() == wxEVT_SCROLL_TOP
) 
1314             wevent
.SetEventType( wxEVT_SCROLLWIN_TOP 
); 
1315         else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
) 
1316             wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM 
); 
1317         else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
) 
1318             wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP 
); 
1319         else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
) 
1320             wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN 
); 
1321         else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
) 
1322             wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP 
); 
1323         else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
) 
1324             wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN 
); 
1325         else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) 
1326             wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK 
); 
1327         else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
) 
1328             wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE 
); 
1330         GetEventHandler()->ProcessEvent(wevent
); 
1334 // Get the window with the focus 
1335 wxWindowMac 
*wxWindowBase::DoFindFocus() 
1337     return gFocusWindow 
; 
1340 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
) 
1342     // panel wants to track the window which was the last to have focus in it, 
1343     // so we want to set ourselves as the window which last had focus 
1345     // notice that it's also important to do it upwards the tree becaus 
1346     // otherwise when the top level panel gets focus, it won't set it back to 
1347     // us, but to some other sibling 
1349     // CS:don't know if this is still needed: 
1350     //wxChildFocusEvent eventFocus(this); 
1351     //(void)GetEventHandler()->ProcessEvent(eventFocus); 
1356 // Setup background and foreground colours correctly 
1357 void wxWindowMac::SetupColours() 
1360         SetBackgroundColour(GetParent()->GetBackgroundColour()); 
1363 void wxWindowMac::OnInternalIdle() 
1365     // This calls the UI-update mechanism (querying windows for 
1366     // menu/toolbar/control state information) 
1367     if (wxUpdateUIEvent::CanUpdate(this)) 
1368         UpdateWindowUI(wxUPDATE_UI_FROMIDLE
); 
1371 // Raise the window to the top of the Z order 
1372 void wxWindowMac::Raise() 
1376 // Lower the window to the bottom of the Z order 
1377 void wxWindowMac::Lower() 
1381 void wxWindowMac::DoSetClientSize(int width
, int height
) 
1383     if ( width 
!= -1 || height 
!= -1 ) 
1386         if ( width 
!= -1 && m_vScrollBar 
) 
1387             width 
+= MAC_SCROLLBAR_SIZE 
; 
1388         if ( height 
!= -1 && m_vScrollBar 
) 
1389             height 
+= MAC_SCROLLBAR_SIZE 
; 
1391         width 
+= MacGetLeftBorderSize(  ) + MacGetRightBorderSize( ) ; 
1392         height 
+= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ) ; 
1394         DoSetSize( -1 , -1 , width 
, height 
) ; 
1399 wxWindowMac
* wxWindowMac::s_lastMouseWindow 
= NULL 
; 
1401 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint 
&point 
, wxWindowMac
** outWin 
) 
1405         if ((point
.x 
< 0) || (point
.y 
< 0) || 
1406             (point
.x 
> (m_width
)) || (point
.y 
> (m_height
))) 
1411         if ((point
.x 
< m_x
) || (point
.y 
< m_y
) || 
1412             (point
.x 
> (m_x 
+ m_width
)) || (point
.y 
> (m_y 
+ m_height
))) 
1416     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1418     wxPoint 
newPoint( point 
) ; 
1420     if ( !IsTopLevel() ) 
1426     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1428         wxWindowMac 
*child 
= node
->GetData(); 
1429         // added the m_isShown test --dmazzoni 
1430         if ( child
->MacGetRootWindow() == (WXWindow
) window 
&& child
->m_isShown 
) 
1432             if (child
->MacGetWindowFromPointSub(newPoint 
, outWin 
)) 
1441 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint 
&screenpoint 
, wxWindowMac
** outWin 
) 
1445     Point pt 
= { screenpoint
.y 
, screenpoint
.x 
} ; 
1446     if ( ::FindWindow( pt 
, &window 
) == 3 ) 
1449         wxWindowMac
* win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
1452             // No, this yields the CLIENT are, we need the whole frame. RR. 
1453             // point = win->ScreenToClient( point ) ; 
1456             ::GetPort( &port 
) ; 
1457             ::SetPort( UMAGetWindowPort( window 
) ) ; 
1458             ::GlobalToLocal( &pt 
) ; 
1461             wxPoint 
point( pt
.h
, pt
.v 
) ; 
1463             return win
->MacGetWindowFromPointSub( point 
, outWin 
) ; 
1469 static wxWindow 
*gs_lastWhich 
= NULL
; 
1471 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
) 
1473     // first trigger a set cursor event 
1475     wxPoint clientorigin 
= GetClientAreaOrigin() ; 
1476     wxSize clientsize 
= GetClientSize() ; 
1478     if ( wxRect2DInt( clientorigin
.x 
, clientorigin
.y 
, clientsize
.x 
, clientsize
.y 
).Contains( wxPoint2DInt( pt 
) ) ) 
1480         wxSetCursorEvent 
event( pt
.x 
, pt
.y 
); 
1482         bool processedEvtSetCursor 
= GetEventHandler()->ProcessEvent(event
); 
1483         if ( processedEvtSetCursor 
&& event
.HasCursor() ) 
1485             cursor 
= event
.GetCursor() ; 
1490             // the test for processedEvtSetCursor is here to prevent using m_cursor 
1491             // if the user code caught EVT_SET_CURSOR() and returned nothing from 
1492             // it - this is a way to say that our cursor shouldn't be used for this 
1494             if ( !processedEvtSetCursor 
&& m_cursor
.Ok() ) 
1504                     cursor 
= *wxSTANDARD_CURSOR  
; 
1508             cursor
.MacInstall() ; 
1510     return cursor
.Ok() ; 
1513 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
) 
1515     if ((event
.m_x 
< m_x
) || (event
.m_y 
< m_y
) || 
1516         (event
.m_x 
> (m_x 
+ m_width
)) || (event
.m_y 
> (m_y 
+ m_height
))) 
1520     if ( IsKindOf( CLASSINFO ( wxStaticBox 
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */) 
1523     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1531     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1533         wxWindowMac 
*child 
= node
->GetData(); 
1534         if ( child
->MacGetRootWindow() == (WXWindow
) window 
&& child
->IsShown() && child
->IsEnabled() ) 
1536             if (child
->MacDispatchMouseEvent(event
)) 
1541     wxWindow
* cursorTarget 
= this ; 
1542     wxPoint 
cursorPoint( x 
, y 
) ; 
1544     while( cursorTarget 
&& !cursorTarget
->MacSetupCursor( cursorPoint 
) ) 
1546         cursorTarget 
= cursorTarget
->GetParent() ; 
1548             cursorPoint 
+= cursorTarget
->GetPosition() ; 
1552     event
.SetEventObject( this ) ; 
1554     if ( event
.GetEventType() == wxEVT_LEFT_DOWN 
) 
1556         // set focus to this window 
1557         if (AcceptsFocus() && FindFocus()!=this) 
1562     if ( event
.GetEventType() == wxEVT_MOTION
 
1563         || event
.GetEventType() == wxEVT_ENTER_WINDOW
 
1564         || event
.GetEventType() == wxEVT_LEAVE_WINDOW 
) 
1565         wxToolTip::RelayEvent( this , event
); 
1566 #endif // wxUSE_TOOLTIPS 
1568     if (gs_lastWhich 
!= this) 
1570         gs_lastWhich 
= this; 
1572         // Double clicks must always occur on the same window 
1573         if (event
.GetEventType() == wxEVT_LEFT_DCLICK
) 
1574             event
.SetEventType( wxEVT_LEFT_DOWN 
); 
1575         if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) 
1576             event
.SetEventType( wxEVT_RIGHT_DOWN 
); 
1578         // Same for mouse up events 
1579         if (event
.GetEventType() == wxEVT_LEFT_UP
) 
1581         if (event
.GetEventType() == wxEVT_RIGHT_UP
) 
1585     GetEventHandler()->ProcessEvent( event 
) ; 
1590 wxString 
wxWindowMac::MacGetToolTipString( wxPoint 
&pt 
) 
1594         return m_tooltip
->GetTip() ; 
1596     return wxEmptyString 
; 
1599 void wxWindowMac::Update() 
1601     wxRegion visRgn 
= MacGetVisibleRegion( false ) ; 
1602     int top 
= 0 , left 
= 0 ; 
1603     MacWindowToRootWindow( &left 
, &top 
) ; 
1604     WindowRef rootWindow 
= (WindowRef
) MacGetRootWindow() ; 
1605     RgnHandle updateRgn 
= NewRgn() ;     
1606     // getting the update region in macos local coordinates 
1607     GetWindowUpdateRgn( rootWindow 
, updateRgn 
) ; 
1609     ::GetPort( &port 
) ; 
1610     ::SetPort( UMAGetWindowPort( rootWindow 
) ) ; 
1612     LocalToGlobal( &pt 
) ; 
1614     OffsetRgn( updateRgn 
, -pt
.h 
, -pt
.v 
) ; 
1615     // translate to window local coordinates 
1616     OffsetRgn( updateRgn 
, -left 
, -top 
) ; 
1617     SectRgn( updateRgn 
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn 
) ; 
1618     MacRedraw( updateRgn 
, 0 , true ) ; 
1619     // for flushing and validating we need macos-local coordinates again 
1620     OffsetRgn( updateRgn 
, left 
, top 
) ; 
1621 #if TARGET_API_MAC_CARBON 
1622     if ( QDIsPortBuffered( GetWindowPort( rootWindow 
) ) ) 
1624         QDFlushPortBuffer( GetWindowPort( rootWindow 
) , updateRgn 
) ; 
1627     ValidWindowRgn( rootWindow 
, updateRgn 
) ; 
1628     DisposeRgn( updateRgn 
) ; 
1631 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const 
1633     wxTopLevelWindowMac
* win 
= NULL 
; 
1634     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1637         win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
1642 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings 
) 
1644     RgnHandle visRgn 
= NewRgn() ; 
1645     RgnHandle tempRgn 
= NewRgn() ; 
1646     RgnHandle tempStaticBoxRgn 
= NewRgn() ; 
1648     if ( MacIsReallyShown() ) 
1650         SetRectRgn( visRgn 
, 0 , 0 , m_width 
, m_height 
) ; 
1652         //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox 
1653         if ( IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1655             int borderTop 
= 14 ; 
1656             int borderOther 
= 4 ; 
1657             if ( UMAGetSystemVersion() >= 0x1030 ) 
1660             SetRectRgn( tempStaticBoxRgn 
, borderOther 
, borderTop 
, m_width 
- borderOther 
, m_height 
- borderOther 
) ; 
1661             DiffRgn( visRgn 
, tempStaticBoxRgn 
, visRgn 
) ; 
1664         if ( !IsTopLevel() ) 
1666             wxWindow
* parent 
= GetParent() ; 
1669                 wxSize size 
= parent
->GetSize() ; 
1672                 parent
->MacWindowToRootWindow( &x
, &y 
) ; 
1673                 MacRootWindowToWindow( &x 
, &y 
) ; 
1675                 SetRectRgn( tempRgn 
, 
1676                     x 
+ parent
->MacGetLeftBorderSize() , y 
+ parent
->MacGetTopBorderSize() , 
1677                     x 
+ size
.x 
- parent
->MacGetRightBorderSize(), 
1678                     y 
+ size
.y 
- parent
->MacGetBottomBorderSize()) ; 
1680                 SectRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1681                 if ( parent
->IsTopLevel() ) 
1683                 parent 
= parent
->GetParent() ; 
1686         if ( respectChildrenAndSiblings 
) 
1688             if ( GetWindowStyle() & wxCLIP_CHILDREN 
) 
1690                 for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1692                     wxWindowMac 
*child 
= node
->GetData(); 
1694                     if ( !child
->IsTopLevel() && child
->IsShown() ) 
1696                         SetRectRgn( tempRgn 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1697                         if ( child
->IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1699                             int borderTop 
= 14 ; 
1700                             int borderOther 
= 4 ; 
1701                             if ( UMAGetSystemVersion() >= 0x1030 ) 
1704                             SetRectRgn( tempStaticBoxRgn 
, child
->m_x 
+ borderOther 
, child
->m_y 
+ borderTop 
, child
->m_x 
+ child
->m_width 
- borderOther 
, child
->m_y 
+ child
->m_height 
- borderOther 
) ; 
1705                             DiffRgn( tempRgn 
, tempStaticBoxRgn 
, tempRgn 
) ; 
1707                         DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1712             if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() ) 
1714                 bool thisWindowThrough 
= false ; 
1715                 for (wxWindowListNode 
*node 
= GetParent()->GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1717                     wxWindowMac 
*sibling 
= node
->GetData(); 
1718                     if ( sibling 
== this ) 
1720                         thisWindowThrough 
= true ; 
1723                     if( !thisWindowThrough 
) 
1728                     if ( !sibling
->IsTopLevel() && sibling
->IsShown() ) 
1730                         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 
) ; 
1731                         if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1733                             int borderTop 
= 14 ; 
1734                             int borderOther 
= 4 ; 
1735                             if ( UMAGetSystemVersion() >= 0x1030 ) 
1738                             SetRectRgn( tempStaticBoxRgn 
, sibling
->m_x 
- m_x 
+ borderOther 
, sibling
->m_y 
- m_y 
+ borderTop 
, sibling
->m_x 
+ sibling
->m_width 
- m_x 
- borderOther 
, sibling
->m_y 
+ sibling
->m_height 
- m_y 
- borderOther 
) ; 
1739                             DiffRgn( tempRgn 
, tempStaticBoxRgn 
, tempRgn 
) ; 
1741                         DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1747     m_macVisibleRegion 
= visRgn 
; 
1748     DisposeRgn( visRgn 
) ; 
1749     DisposeRgn( tempRgn 
) ; 
1750     DisposeRgn( tempStaticBoxRgn 
) ; 
1751     return m_macVisibleRegion 
; 
1754 void wxWindowMac::MacRedraw( WXHRGN updatergnr 
, long time
, bool erase
) 
1756     RgnHandle updatergn 
= (RgnHandle
) updatergnr 
; 
1757     // updatergn is always already clipped to our boundaries 
1758     // it is in window coordinates, not in client coordinates 
1760     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1763         // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates 
1764         RgnHandle ownUpdateRgn 
= NewRgn() ; 
1765         CopyRgn( updatergn 
, ownUpdateRgn 
) ; 
1767         SectRgn( ownUpdateRgn 
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn 
) ; 
1769         // newupdate is the update region in client coordinates 
1770         RgnHandle newupdate 
= NewRgn() ; 
1771         wxSize point 
= GetClientSize() ; 
1772         wxPoint origin 
= GetClientAreaOrigin() ; 
1773         SetRectRgn( newupdate 
, origin
.x 
, origin
.y 
, origin
.x 
+ point
.x 
, origin
.y
+point
.y 
) ; 
1774         SectRgn( newupdate 
, ownUpdateRgn 
, newupdate 
) ; 
1775         OffsetRgn( newupdate 
, -origin
.x 
, -origin
.y 
) ; 
1776         m_updateRegion 
= newupdate 
; 
1777         DisposeRgn( newupdate 
) ; // it's been cloned to m_updateRegion 
1779         if ( erase 
&& !EmptyRgn(ownUpdateRgn
) ) 
1781             wxWindowDC 
dc(this); 
1782             if (!EmptyRgn(ownUpdateRgn
)) 
1783                 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
)); 
1784             wxEraseEvent 
eevent( GetId(), &dc 
); 
1785             eevent
.SetEventObject( this ); 
1786             GetEventHandler()->ProcessEvent( eevent 
); 
1788             wxNcPaintEvent 
eventNc( GetId() ); 
1789             eventNc
.SetEventObject( this ); 
1790             GetEventHandler()->ProcessEvent( eventNc 
); 
1792         DisposeRgn( ownUpdateRgn 
) ; 
1793         if ( !m_updateRegion
.Empty() ) 
1795             wxWindowList hiddenWindows 
; 
1796             for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1798                 wxControl 
*child 
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl 
) ; 
1800                 if ( child 
&& child
->MacGetRootWindow() == (WXWindow
) window 
&& child
->IsShown() && child
->GetMacControl() ) 
1802                     SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ; 
1803                     hiddenWindows
.Append( child 
) ; 
1808             event
.SetTimestamp(time
); 
1809             event
.SetEventObject(this); 
1810             GetEventHandler()->ProcessEvent(event
); 
1812             for (wxWindowListNode 
*node 
= hiddenWindows
.GetFirst(); node
; node 
= node
->GetNext()) 
1814                 wxControl 
*child 
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl 
) ; 
1816                 if ( child 
&& child
->GetMacControl() ) 
1818                     SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ; 
1824     // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively 
1826     RgnHandle childupdate 
= NewRgn() ; 
1827     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1829         // calculate the update region for the child windows by intersecting the window rectangle with our own 
1830         // passed in update region and then offset it to be client-wise window coordinates again 
1831         wxWindowMac 
*child 
= node
->GetData(); 
1832         SetRectRgn( childupdate 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1833         SectRgn( childupdate 
, updatergn 
, childupdate 
) ; 
1834         OffsetRgn( childupdate 
, -child
->m_x 
, -child
->m_y 
) ; 
1835         if ( child
->MacGetRootWindow() == (WXWindow
) window 
&& child
->IsShown() && !EmptyRgn( childupdate 
) ) 
1837             // because dialogs may also be children 
1838             child
->MacRedraw( childupdate 
, time 
, erase 
) ; 
1841     DisposeRgn( childupdate 
) ; 
1842     // eventually a draw grow box here 
1846 WXWindow 
wxWindowMac::MacGetRootWindow() const 
1848     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1852         if ( iter
->IsTopLevel() ) 
1853             return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ; 
1855         iter 
= iter
->GetParent() ; 
1857     wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; 
1861 void wxWindowMac::MacCreateScrollBars( long style 
) 
1863     wxASSERT_MSG( m_vScrollBar 
== NULL 
&& m_hScrollBar 
== NULL 
, wxT("attempt to create window twice") ) ; 
1865     bool hasBoth 
= ( style 
& wxVSCROLL 
) && ( style 
& wxHSCROLL 
) ; 
1866     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1: 0 ; 
1868     GetClientSize( &width 
, &height 
) ; 
1870     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1871     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1872     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1873     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1875     m_vScrollBar 
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
, 
1876         vSize 
, wxVERTICAL
); 
1878     if ( style 
& wxVSCROLL 
) 
1884         m_vScrollBar
->Show(false) ; 
1886     m_hScrollBar 
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
, 
1887         hSize 
, wxHORIZONTAL
); 
1888     if ( style  
& wxHSCROLL 
) 
1893         m_hScrollBar
->Show(false) ; 
1896     // because the create does not take into account the client area origin 
1897     MacRepositionScrollBars() ; // we might have a real position shift 
1900 void wxWindowMac::MacRepositionScrollBars() 
1902     bool hasBoth 
= ( m_hScrollBar 
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar 
&& m_vScrollBar
->IsShown()) ; 
1903     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1 : 0 ; 
1905     // get real client area 
1907     int width 
= m_width 
; 
1908     int height 
= m_height 
; 
1910     width 
-= MacGetLeftBorderSize() + MacGetRightBorderSize(); 
1911     height 
-= MacGetTopBorderSize() + MacGetBottomBorderSize(); 
1913     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1914     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1915     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1916     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1923     MacClientToRootWindow( &x 
, &y 
) ; 
1924     MacClientToRootWindow( &w 
, &h 
) ; 
1926     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1928     int totW 
= 10000 , totH 
= 10000; 
1931         if ( iter
->IsTopLevel() ) 
1933             totW 
= iter
->m_width 
; 
1934             totH 
= iter
->m_height 
; 
1938         iter 
= iter
->GetParent() ; 
1966         m_vScrollBar
->SetSize( vPoint
.x 
, vPoint
.y
, vSize
.x
, vSize
.y 
, wxSIZE_ALLOW_MINUS_ONE
); 
1970         m_hScrollBar
->SetSize( hPoint
.x 
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
); 
1974 bool wxWindowMac::AcceptsFocus() const 
1976     return MacCanFocus() && wxWindowBase::AcceptsFocus(); 
1979 WXWidget 
wxWindowMac::MacGetContainerForEmbedding() 
1981     return GetParent()->MacGetContainerForEmbedding() ; 
1984 void wxWindowMac::MacSuperChangedPosition() 
1986     // only window-absolute structures have to be moved i.e. controls 
1988     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
1991         wxWindowMac 
*child 
= node
->GetData(); 
1992         child
->MacSuperChangedPosition() ; 
1993         node 
= node
->GetNext(); 
1997 void wxWindowMac::MacTopLevelWindowChangedPosition() 
1999     // only screen-absolute structures have to be moved i.e. glcanvas 
2001     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
2004         wxWindowMac 
*child 
= node
->GetData(); 
2005         child
->MacTopLevelWindowChangedPosition() ; 
2006         node 
= node
->GetNext(); 
2009 long wxWindowMac::MacGetLeftBorderSize( ) const 
2014     if (m_windowStyle 
& wxRAISED_BORDER 
|| m_windowStyle 
& wxSUNKEN_BORDER 
) 
2017 #if wxMAC_USE_THEME_BORDER 
2019           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
2024     else if (  m_windowStyle 
&wxDOUBLE_BORDER
) 
2027 #if wxMAC_USE_THEME_BORDER 
2029           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
2034     else if (m_windowStyle 
&wxSIMPLE_BORDER
) 
2041 long wxWindowMac::MacGetRightBorderSize( ) const 
2043     // they are all symmetric in mac themes 
2044     return MacGetLeftBorderSize() ; 
2047 long wxWindowMac::MacGetTopBorderSize( ) const 
2049     // they are all symmetric in mac themes 
2050     return MacGetLeftBorderSize() ; 
2053 long wxWindowMac::MacGetBottomBorderSize( ) const 
2055     // they are all symmetric in mac themes 
2056     return MacGetLeftBorderSize() ; 
2059 long wxWindowMac::MacRemoveBordersFromStyle( long style 
) 
2061     return style 
& ~( wxDOUBLE_BORDER 
| wxSUNKEN_BORDER 
| wxRAISED_BORDER 
| wxBORDER 
| wxSTATIC_BORDER 
) ; 
2064 // Find the wxWindowMac at the current mouse position, returning the mouse 
2066 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
) 
2068     pt 
= wxGetMousePosition(); 
2069     wxWindowMac
* found 
= wxFindWindowAtPoint(pt
); 
2073 // Get the current mouse position. 
2074 wxPoint 
wxGetMousePosition() 
2077     wxGetMousePosition(& x
, & y
); 
2078     return wxPoint(x
, y
); 
2081 void wxWindowMac::OnMouseEvent( wxMouseEvent 
&event 
) 
2083         if ( event
.GetEventType() == wxEVT_RIGHT_DOWN 
) 
2085                 // copied from wxGTK : CS 
2086         // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN 
2089         // (a) it's a command event and so is propagated to the parent 
2090         // (b) under MSW it can be generated from kbd too 
2091         // (c) it uses screen coords (because of (a)) 
2092         wxContextMenuEvent 
evtCtx(wxEVT_CONTEXT_MENU
, 
2094                                   this->ClientToScreen(event
.GetPosition())); 
2095         if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )