1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxWindowMac 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "window.h" 
  18 #include "wx/window.h" 
  20 #include "wx/dcclient.h" 
  24 #include "wx/layout.h" 
  25 #include "wx/dialog.h" 
  26 #include "wx/listbox.h" 
  27 #include "wx/scrolbar.h" 
  28 #include "wx/statbox.h" 
  29 #include "wx/button.h" 
  30 #include "wx/settings.h" 
  31 #include "wx/msgdlg.h" 
  33 #include "wx/notebook.h" 
  34 #include "wx/tabctrl.h" 
  35 #include "wx/tooltip.h" 
  36 #include "wx/statusbr.h" 
  37 #include "wx/menuitem.h" 
  38 #include "wx/spinctrl.h" 
  40 #include "wx/geometry.h" 
  46 #define wxWINDOW_HSCROLL 5998 
  47 #define wxWINDOW_VSCROLL 5997 
  48 #define MAC_SCROLLBAR_SIZE 16 
  50 #include "wx/mac/uma.h" 
  53 #include <ToolUtils.h> 
  56 #if  wxUSE_DRAG_AND_DROP 
  62 extern wxList wxPendingDelete
; 
  63 wxWindowMac
* gFocusWindow 
= NULL 
; 
  65 #ifdef __WXUNIVERSAL__ 
  66     IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
) 
  68     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
) 
  69 #endif // __WXUNIVERSAL__/__WXMAC__ 
  71 #if !USE_SHARED_LIBRARY 
  73 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
) 
  74   EVT_NC_PAINT(wxWindowMac::OnNcPaint
) 
  75   EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
) 
  76   EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
) 
  77   EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
) 
  78   EVT_SET_FOCUS(wxWindowMac::OnSetFocus
) 
  79   EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
) 
  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() 
 103     m_backgroundTransparent 
= FALSE
; 
 105     // as all windows are created with WS_VISIBLE style... 
 113     m_hScrollBar 
= NULL 
; 
 114     m_vScrollBar 
= NULL 
; 
 118 wxWindowMac::~wxWindowMac() 
 122     // deleting a window while it is shown invalidates the region 
 124         wxWindowMac
* iter 
= this ; 
 126             if ( iter
->IsTopLevel() ) 
 131             iter 
= iter
->GetParent() ; 
 136     m_isBeingDeleted 
= TRUE
; 
 138 #ifndef __WXUNIVERSAL__ 
 139     // VS: make sure there's no wxFrame with last focus set to us: 
 140     for ( wxWindow 
*win 
= GetParent(); win
; win 
= win
->GetParent() ) 
 142         wxFrame 
*frame 
= wxDynamicCast(win
, wxFrame
); 
 145             if ( frame
->GetLastFocus() == this ) 
 147                 frame
->SetLastFocus((wxWindow
*)NULL
); 
 152 #endif // __WXUNIVERSAL__ 
 154     if ( s_lastMouseWindow 
== this ) 
 156         s_lastMouseWindow 
= NULL 
; 
 159     wxFrame
* frame 
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame 
) ; 
 162         if ( frame
->GetLastFocus() == this ) 
 163             frame
->SetLastFocus( NULL 
) ; 
 166     if ( gFocusWindow 
== this ) 
 168         gFocusWindow 
= NULL 
; 
 173     // delete our drop target if we've got one 
 174 #if wxUSE_DRAG_AND_DROP 
 175     if ( m_dropTarget 
!= NULL 
) 
 180 #endif // wxUSE_DRAG_AND_DROP 
 184 bool wxWindowMac::Create(wxWindowMac 
*parent
, wxWindowID id
, 
 188            const wxString
& name
) 
 190     wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") ); 
 193     // wxGTK doesn't allow to create controls with static box as the parent so 
 194     // this will result in a crash when the program is ported to wxGTK - warn 
 197     // the correct solution is to create the controls as siblings of the 
 199     wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
), 
 200                   _T("wxStaticBox can't be used as a window parent!") ); 
 201 #endif // wxUSE_STATBOX 
 203     if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) ) 
 206     parent
->AddChild(this); 
 210     AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
); 
 211     m_width 
= WidthDefault( size
.x 
); 
 212     m_height 
= HeightDefault( size
.y 
) ; 
 213 #ifndef __WXUNIVERSAL__ 
 214     // Don't give scrollbars to wxControls unless they ask for them 
 215     if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) || 
 216          (IsKindOf(CLASSINFO(wxControl
)) && ( style 
& wxHSCROLL 
|| style 
& wxVSCROLL
))) 
 218         MacCreateScrollBars( style 
) ; 
 222     wxWindowCreateEvent 
event(this); 
 223     GetEventHandler()->AddPendingEvent(event
); 
 228 void wxWindowMac::SetFocus() 
 230     if ( gFocusWindow 
== this ) 
 233     if ( AcceptsFocus() ) 
 239                 if ( gFocusWindow
->m_caret 
) 
 241                       gFocusWindow
->m_caret
->OnKillFocus(); 
 243 #endif // wxUSE_CARET 
 244 #ifndef __WXUNIVERSAL__ 
 245             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 246             if ( control 
&& control
->GetMacControl() ) 
 248                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNoPart 
) ; 
 249                 control
->MacRedrawControl() ; 
 252             // Without testing the window id, for some reason 
 253             // a kill focus event can still be sent to 
 254             // the control just being focussed. 
 255             int thisId 
= this->m_windowId
; 
 256             int gFocusWindowId 
= gFocusWindow
->m_windowId
; 
 257             if (gFocusWindowId 
!= thisId
) 
 259                 wxFocusEvent 
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
); 
 260                 event
.SetEventObject(gFocusWindow
); 
 261                 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ; 
 264         gFocusWindow 
= this ; 
 270                 m_caret
->OnSetFocus(); 
 272             #endif // wxUSE_CARET 
 273             // panel wants to track the window which was the last to have focus in it 
 274             wxChildFocusEvent 
eventFocus(this); 
 275             GetEventHandler()->ProcessEvent(eventFocus
); 
 277       #ifndef __WXUNIVERSAL__ 
 278             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 279             if ( control 
&& control
->GetMacControl() ) 
 281                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNextPart 
) ; 
 284             wxFocusEvent 
event(wxEVT_SET_FOCUS
, m_windowId
); 
 285             event
.SetEventObject(this); 
 286             GetEventHandler()->ProcessEvent(event
) ; 
 291 bool wxWindowMac::Enable(bool enable
) 
 293     if ( !wxWindowBase::Enable(enable
) ) 
 296     MacSuperEnabled( enable 
) ; 
 301 void wxWindowMac::DoCaptureMouse() 
 303     wxTheApp
->s_captureWindow 
= this ; 
 306 wxWindow
* wxWindowBase::GetCapture() 
 308     return wxTheApp
->s_captureWindow 
; 
 311 void wxWindowMac::DoReleaseMouse() 
 313     wxTheApp
->s_captureWindow 
= NULL 
; 
 316 #if    wxUSE_DRAG_AND_DROP 
 318 void wxWindowMac::SetDropTarget(wxDropTarget 
*pDropTarget
) 
 320     if ( m_dropTarget 
!= 0 ) { 
 324     m_dropTarget 
= pDropTarget
; 
 325     if ( m_dropTarget 
!= 0 ) 
 333 // Old style file-manager drag&drop 
 334 void wxWindowMac::DragAcceptFiles(bool accept
) 
 340 void wxWindowMac::DoGetSize(int *x
, int *y
) const 
 343      if(y
)   *y 
= m_height 
; 
 346 void wxWindowMac::DoGetPosition(int *x
, int *y
) const 
 352     if ( !IsTopLevel() && GetParent()) 
 354         wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
 363 bool wxWindowMac::DoPopupMenu(wxMenu 
*menu
, int x
, int y
) 
 365     menu
->SetInvokingWindow(this); 
 367     ClientToScreen( &x 
, &y 
) ; 
 369     menu
->MacBeforeDisplay( true ) ; 
 370     long menuResult 
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ; 
 371     if ( HiWord(menuResult
) != 0 ) 
 374         GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id 
) ; 
 375         wxMenuItem
* item 
= NULL 
; 
 377         item 
= menu
->FindItem(id
, &realmenu
) ; 
 378         if (item
->IsCheckable()) 
 380             item
->Check( !item
->IsChecked() ) ; 
 382         menu
->SendEvent( id 
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ; 
 384     menu
->MacAfterDisplay( true ) ; 
 386     menu
->SetInvokingWindow(NULL
); 
 392 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const 
 394     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 396     Point       localwhere 
= {0,0} ; 
 398     if(x
)   localwhere
.h 
= * x 
; 
 399     if(y
)   localwhere
.v 
= * y 
; 
 403     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 404     ::GlobalToLocal( &localwhere 
) ; 
 407     if(x
)   *x 
= localwhere
.h 
; 
 408     if(y
)   *y 
= localwhere
.v 
; 
 410     MacRootWindowToWindow( x 
, y 
) ; 
 412         *x 
-= MacGetLeftBorderSize() ; 
 414         *y 
-= MacGetTopBorderSize() ; 
 417 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const 
 419     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 422         *x 
+= MacGetLeftBorderSize() ; 
 424         *y 
+= MacGetTopBorderSize() ; 
 426     MacWindowToRootWindow( x 
, y 
) ; 
 428     Point       localwhere 
= { 0,0 }; 
 429     if(x
)   localwhere
.h 
= * x 
; 
 430     if(y
)   localwhere
.v 
= * y 
; 
 434     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 436     ::LocalToGlobal( &localwhere 
) ; 
 438     if(x
)   *x 
= localwhere
.h 
; 
 439     if(y
)   *y 
= localwhere
.v 
; 
 442 void wxWindowMac::MacClientToRootWindow( int *x 
, int *y 
) const 
 444     wxPoint origin 
= GetClientAreaOrigin() ; 
 445     if(x
)   *x 
+= origin
.x 
; 
 446     if(y
)   *y 
+= origin
.y 
; 
 448     MacWindowToRootWindow( x 
, y 
) ; 
 451 void wxWindowMac::MacRootWindowToClient( int *x 
, int *y 
) const 
 453     wxPoint origin 
= GetClientAreaOrigin() ; 
 454     MacRootWindowToWindow( x 
, y 
) ; 
 455     if(x
)   *x 
-= origin
.x 
; 
 456     if(y
)   *y 
-= origin
.y 
; 
 459 void wxWindowMac::MacWindowToRootWindow( int *x 
, int *y 
) const 
 465         GetParent()->MacWindowToRootWindow( x 
, y 
) ; 
 469 void wxWindowMac::MacRootWindowToWindow( int *x 
, int *y 
) const 
 475         GetParent()->MacRootWindowToWindow( x 
, y 
) ; 
 479 bool wxWindowMac::SetCursor(const wxCursor
& cursor
) 
 481     if (m_cursor 
== cursor
) 
 484     if (wxNullCursor 
== cursor
) 
 486         if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR 
) ) 
 491         if ( ! wxWindowBase::SetCursor( cursor 
) ) 
 495     wxASSERT_MSG( m_cursor
.Ok(), 
 496         wxT("cursor must be valid after call to the base version")); 
 499     wxWindowMac 
*mouseWin 
; 
 502     // Change the cursor NOW if we're within the correct window 
 504     if ( MacGetWindowFromPoint( wxPoint( pt
.h 
, pt
.v 
) , &mouseWin 
) ) 
 506         if ( mouseWin 
== this && !wxIsBusy() ) 
 508             m_cursor
.MacInstall() ; 
 516 // Get size *available for subwindows* i.e. excluding menu bar etc. 
 517 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const 
 523     ww 
-= MacGetLeftBorderSize(  )  + MacGetRightBorderSize(  ) ; 
 524     hh 
-= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ); 
 526     if ( (m_vScrollBar 
&& m_vScrollBar
->IsShown()) || (m_hScrollBar  
&& m_hScrollBar
->IsShown()) ) 
 533         MacClientToRootWindow( &x1 
, &y1 
) ; 
 534         MacClientToRootWindow( &w 
, &h 
) ; 
 536         wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
 538         int totW 
= 10000 , totH 
= 10000; 
 541             if ( iter
->IsTopLevel() ) 
 543                 totW 
= iter
->m_width 
; 
 544                 totH 
= iter
->m_height 
; 
 548             iter 
= iter
->GetParent() ; 
 551         if (m_hScrollBar  
&& m_hScrollBar
->IsShown() ) 
 553             hh 
-= MAC_SCROLLBAR_SIZE
; 
 559         if (m_vScrollBar  
&& m_vScrollBar
->IsShown() ) 
 561             ww 
-= MAC_SCROLLBAR_SIZE
; 
 573 // ---------------------------------------------------------------------------- 
 575 // ---------------------------------------------------------------------------- 
 579 void wxWindowMac::DoSetToolTip(wxToolTip 
*tooltip
) 
 581     wxWindowBase::DoSetToolTip(tooltip
); 
 584         m_tooltip
->SetWindow(this); 
 587 #endif // wxUSE_TOOLTIPS 
 589 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
) 
 593     int former_w 
= m_width 
; 
 594     int former_h 
= m_height 
; 
 596     int actualWidth 
= width
; 
 597     int actualHeight 
= height
; 
 601     if ((m_minWidth 
!= -1) && (actualWidth 
< m_minWidth
)) 
 602         actualWidth 
= m_minWidth
; 
 603     if ((m_minHeight 
!= -1) && (actualHeight 
< m_minHeight
)) 
 604         actualHeight 
= m_minHeight
; 
 605     if ((m_maxWidth 
!= -1) && (actualWidth 
> m_maxWidth
)) 
 606         actualWidth 
= m_maxWidth
; 
 607     if ((m_maxHeight 
!= -1) && (actualHeight 
> m_maxHeight
)) 
 608         actualHeight 
= m_maxHeight
; 
 610     bool doMove 
= false ; 
 611     bool doResize 
= false ; 
 613     if ( actualX 
!= former_x 
|| actualY 
!= former_y 
) 
 617     if ( actualWidth 
!= former_w 
|| actualHeight 
!= former_h 
) 
 622     if ( doMove 
|| doResize 
) 
 624         // erase former position 
 626         bool partialRepaint 
= false ; 
 628         if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) ) 
 630             wxPoint 
oldPos( m_x 
, m_y 
) ; 
 631             wxPoint 
newPos( actualX 
, actualY 
) ; 
 632             MacWindowToRootWindow( &oldPos
.x 
, &oldPos
.y 
) ; 
 633             MacWindowToRootWindow( &newPos
.x 
, &newPos
.y 
) ; 
 634             if ( oldPos 
== newPos 
) 
 636                 partialRepaint 
= true ; 
 637                 RgnHandle oldRgn
,newRgn
,diffRgn 
; 
 642                 // invalidate the differences between the old and the new area 
 644                 SetRectRgn(oldRgn 
, oldPos
.x 
, oldPos
.y 
, oldPos
.x 
+ m_width 
, oldPos
.y 
+ m_height 
) ; 
 645                 SetRectRgn(newRgn 
, newPos
.x 
, newPos
.y 
, newPos
.x 
+ actualWidth 
, newPos
.y 
+ actualHeight 
) ; 
 646                 DiffRgn( newRgn 
, oldRgn 
, diffRgn 
) ; 
 647                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 648                 DiffRgn( oldRgn 
, newRgn 
, diffRgn 
) ; 
 649                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 651                 // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really 
 652                 // changing pixels... 
 654                 if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 ||  
 655                         MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 ) 
 657                         RgnHandle innerOldRgn
, innerNewRgn 
; 
 658                         innerOldRgn 
= NewRgn() ; 
 659                         innerNewRgn 
= NewRgn() ; 
 661                         SetRectRgn(innerOldRgn 
, oldPos
.x 
+ MacGetLeftBorderSize()  , oldPos
.y 
+ MacGetTopBorderSize() ,  
 662                                 oldPos
.x 
+ m_width 
- MacGetRightBorderSize() , oldPos
.y 
+ m_height 
- MacGetBottomBorderSize() ) ; 
 663                     DiffRgn( oldRgn 
, innerOldRgn 
, diffRgn 
) ; 
 664                         InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 666                         SetRectRgn(innerNewRgn 
, newPos
.x 
+ MacGetLeftBorderSize()  , newPos
.y 
+ MacGetTopBorderSize() ,  
 667                                 newPos
.x 
+ actualWidth 
- MacGetRightBorderSize() , newPos
.y 
+ actualHeight 
- MacGetBottomBorderSize() ) ; 
 668                     DiffRgn( newRgn 
, innerNewRgn 
, diffRgn 
) ; 
 669                         InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 671                         DisposeRgn( innerOldRgn 
) ; 
 672                         DisposeRgn( innerNewRgn 
) ; 
 677                 DisposeRgn(diffRgn
) ; 
 681         if ( !partialRepaint 
) 
 686         m_width 
= actualWidth 
; 
 687         m_height 
= actualHeight 
; 
 689         // update any low-level frame-relative positions 
 691         MacUpdateDimensions() ; 
 692         // erase new position 
 694         if ( !partialRepaint 
) 
 697             wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified 
 699         MacRepositionScrollBars() ; 
 702             wxPoint 
point(m_x
, m_y
); 
 703             wxMoveEvent 
event(point
, m_windowId
); 
 704             event
.SetEventObject(this); 
 705             GetEventHandler()->ProcessEvent(event
) ; 
 709             MacRepositionScrollBars() ; 
 710             wxSize 
size(m_width
, m_height
); 
 711             wxSizeEvent 
event(size
, m_windowId
); 
 712             event
.SetEventObject(this); 
 713             GetEventHandler()->ProcessEvent(event
); 
 719 // set the size of the window: if the dimensions are positive, just use them, 
 720 // but if any of them is equal to -1, it means that we must find the value for 
 721 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in 
 722 // which case -1 is a valid value for x and y) 
 724 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate 
 725 // the width/height to best suit our contents, otherwise we reuse the current 
 727 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 729     // get the current size and position... 
 730     int currentX
, currentY
; 
 731     GetPosition(¤tX
, ¤tY
); 
 733     int currentW
,currentH
; 
 734     GetSize(¤tW
, ¤tH
); 
 736     // ... and don't do anything (avoiding flicker) if it's already ok 
 737     if ( x 
== currentX 
&& y 
== currentY 
&& 
 738         width 
== currentW 
&& height 
== currentH 
) 
 740         MacRepositionScrollBars() ; // we might have a real position shift 
 744     if ( x 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 746     if ( y 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 749     AdjustForParentClientOrigin(x
, y
, sizeFlags
); 
 754         if ( sizeFlags 
& wxSIZE_AUTO_WIDTH 
) 
 756             size 
= DoGetBestSize(); 
 761             // just take the current one 
 768         if ( sizeFlags 
& wxSIZE_AUTO_HEIGHT 
) 
 772                 size 
= DoGetBestSize(); 
 774             //else: already called DoGetBestSize() above 
 780             // just take the current one 
 785     DoMoveWindow(x
, y
, width
, height
); 
 788 // For implementation purposes - sometimes decorations make the client area 
 791 wxPoint 
wxWindowMac::GetClientAreaOrigin() const 
 793     return wxPoint(MacGetLeftBorderSize(  ) , MacGetTopBorderSize(  ) ); 
 796 void wxWindowMac::SetTitle(const wxString
& title
) 
 801 wxString 
wxWindowMac::GetTitle() const 
 806 bool wxWindowMac::Show(bool show
) 
 808     if ( !wxWindowBase::Show(show
) ) 
 811     MacSuperShown( show 
) ; 
 817 void wxWindowMac::MacSuperShown( bool show 
) 
 819     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
 822         wxWindowMac 
*child 
= node
->GetData(); 
 823         if ( child
->m_isShown 
) 
 824             child
->MacSuperShown( show 
) ; 
 825         node 
= node
->GetNext(); 
 829 void wxWindowMac::MacSuperEnabled( bool enabled 
) 
 833       // to be absolutely correct we'd have to invalidate (with eraseBkground 
 834       // because unter MacOSX the frames are drawn with an addXXX mode) 
 837     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
 840         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->GetData(); 
 841         if ( child
->m_isShown 
) 
 842             child
->MacSuperEnabled( enabled 
) ; 
 843         node 
= node
->GetNext(); 
 847 bool wxWindowMac::MacIsReallyShown() const 
 849     if ( m_isShown 
&& (m_parent 
!= NULL 
&& !IsTopLevel() ) ) { 
 850         return m_parent
->MacIsReallyShown(); 
 854     bool status = m_isShown ; 
 855     wxWindowMac * win = this ; 
 856     while ( status && win->m_parent != NULL ) 
 858         win = win->m_parent ; 
 859         status = win->m_isShown ; 
 865 int wxWindowMac::GetCharHeight() const 
 867     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 868     return dc
.GetCharHeight() ; 
 871 int wxWindowMac::GetCharWidth() const 
 873     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 874     return dc
.GetCharWidth() ; 
 877 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
, 
 878                            int *descent
, int *externalLeading
, const wxFont 
*theFont 
) const 
 880     const wxFont 
*fontToUse 
= theFont
; 
 884     wxClientDC 
dc( (wxWindowMac
*) this ) ; 
 886     dc
.GetTextExtent( string 
, &lx 
, &ly 
, &ld
, &le
, (wxFont 
*)fontToUse 
) ; 
 887     if ( externalLeading 
) 
 888         *externalLeading 
= le 
; 
 898  * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect 
 899  * we always intersect with the entire window, not only with the client area 
 902 void wxWindowMac::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 904     if ( MacGetTopLevelWindow() == NULL 
) 
 907     if ( !MacIsReallyShown() ) 
 910      wxPoint client 
= GetClientAreaOrigin(); 
 913     int x2 
= m_width 
- client
.x
; 
 914     int y2 
= m_height 
- client
.y
; 
 916     if (IsKindOf( CLASSINFO(wxButton
))) 
 918         // buttons have an "aura" 
 925     Rect clientrect 
= { y1
, x1
, y2
, x2 
}; 
 929         Rect r 
= { rect
->y 
, rect
->x 
, rect
->y 
+ rect
->height 
, rect
->x 
+ rect
->width 
} ; 
 930         SectRect( &clientrect 
, &r 
, &clientrect 
) ; 
 933     if ( !EmptyRect( &clientrect 
) ) 
 935       int top 
= 0 , left 
= 0 ; 
 937       MacClientToRootWindow( &left 
, &top 
) ; 
 938       OffsetRect( &clientrect 
, left 
, top 
) ; 
 940       MacGetTopLevelWindow()->MacInvalidate( &clientrect 
, eraseBack 
) ; 
 944 wxWindowMac 
*wxGetActiveWindow() 
 946     // actually this is a windows-only concept 
 950 // Coordinates relative to the window 
 951 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
) 
 953     // We really don't move the mouse programmatically under Mac. 
 956 const wxBrush
& wxWindowMac::MacGetBackgroundBrush() 
 958     if ( m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 960         m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground 
) ; 
 962     else if (  m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) ) 
 964         // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether 
 965         // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have 
 966         // either a non gray background color or a non control window 
 968         WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 970         wxWindowMac
* parent 
= GetParent() ; 
 973             if ( parent
->MacGetRootWindow() != window 
) 
 975                 // we are in a different window on the mac system 
 981                 if ( parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) 
 982                     && parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 984                     // if we have any other colours in the hierarchy 
 985                     m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour 
) ; 
 988                 // if we have the normal colours in the hierarchy but another control etc. -> use it's background 
 989                 if ( parent
->IsKindOf( CLASSINFO( wxNotebook 
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl 
) )) 
 991                     Rect extent 
= { 0 , 0 , 0 , 0 } ; 
 994                     wxSize size 
= parent
->GetSize() ; 
 995                     parent
->MacClientToRootWindow( &x 
, &y 
) ; 
 999                     extent
.right 
= x 
+ size
.x 
; 
1000                     extent
.bottom 
= y 
+ size
.y 
; 
1001                     m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane 
, (WXRECTPTR
) &extent 
) ; // todo eventually change for inactive 
1005             parent 
= parent
->GetParent() ; 
1009             m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive 
) ; // todo eventually change for inactive 
1014         m_macBackgroundBrush
.SetColour( m_backgroundColour 
) ; 
1017     return m_macBackgroundBrush 
; 
1020 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
) 
1022     event
.GetDC()->Clear() ; 
1025 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event 
) 
1027     wxWindowDC 
dc(this) ; 
1028     wxMacPortSetter 
helper(&dc
) ; 
1030     MacPaintBorders( dc
.m_macLocalOrigin
.x 
, dc
.m_macLocalOrigin
.y
) ; 
1033 int wxWindowMac::GetScrollPos(int orient
) const 
1035     if ( orient 
== wxHORIZONTAL 
) 
1038            return m_hScrollBar
->GetThumbPosition() ; 
1043            return m_vScrollBar
->GetThumbPosition() ; 
1048 // This now returns the whole range, not just the number 
1049 // of positions that we can scroll. 
1050 int wxWindowMac::GetScrollRange(int orient
) const 
1052     if ( orient 
== wxHORIZONTAL 
) 
1055            return m_hScrollBar
->GetRange() ; 
1060            return m_vScrollBar
->GetRange() ; 
1065 int wxWindowMac::GetScrollThumb(int orient
) const 
1067     if ( orient 
== wxHORIZONTAL 
) 
1070            return m_hScrollBar
->GetThumbSize() ; 
1075            return m_vScrollBar
->GetThumbSize() ; 
1080 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
) 
1082     if ( orient 
== wxHORIZONTAL 
) 
1085            m_hScrollBar
->SetThumbPosition( pos 
) ; 
1090            m_vScrollBar
->SetThumbPosition( pos 
) ; 
1094 void wxWindowMac::MacPaintBorders( int left 
, int top 
) 
1100     wxGetOsVersion( &major
, &minor 
); 
1102     RGBColor white 
= { 0xFFFF, 0xFFFF , 0xFFFF } ; 
1103     RGBColor face 
= { 0xDDDD, 0xDDDD , 0xDDDD } ; 
1105     RGBColor darkShadow 
= { 0x0000, 0x0000 , 0x0000 } ; 
1106     RGBColor lightShadow 
= { 0x4444, 0x4444 , 0x4444 } ; 
1107     // OS X has lighter border edges than classic: 
1110         darkShadow
.red          
= 0x8E8E; 
1111         darkShadow
.green        
= 0x8E8E; 
1112         darkShadow
.blue         
= 0x8E8E; 
1113         lightShadow
.red         
= 0xBDBD; 
1114         lightShadow
.green       
= 0xBDBD; 
1115         lightShadow
.blue        
= 0xBDBD; 
1120     if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) ) 
1122 #if wxMAC_USE_THEME_BORDER 
1123         Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1126         GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; 
1127         InsetRect( &rect , border , border ); 
1128         DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; 
1131         DrawThemePrimaryGroup(&rect  
,IsEnabled() ? kThemeStateActive 
: kThemeStateInactive
) ; 
1133         bool sunken 
= HasFlag( wxSUNKEN_BORDER 
) ; 
1134         RGBForeColor( &face 
); 
1135         MoveTo( left 
+ 0 , top 
+ m_height 
- 2 ); 
1136         LineTo( left 
+ 0 , top 
+ 0 ); 
1137         LineTo( left 
+ m_width 
- 2 , top 
+ 0 ); 
1139         MoveTo( left 
+ 2 , top 
+ m_height 
- 3 ); 
1140         LineTo( left 
+ m_width 
- 3 , top 
+ m_height 
- 3 ); 
1141         LineTo( left 
+ m_width 
- 3 , top 
+ 2 ); 
1143         RGBForeColor( sunken 
? &face 
: &darkShadow 
); 
1144         MoveTo( left 
+ 0 , top 
+ m_height 
- 1 ); 
1145         LineTo( left 
+ m_width 
- 1 , top 
+ m_height 
- 1 ); 
1146         LineTo( left 
+ m_width 
- 1 , top 
+ 0 ); 
1148         RGBForeColor( sunken 
? &lightShadow 
: &white 
); 
1149         MoveTo( left 
+ 1 , top 
+ m_height 
- 3 ); 
1150         LineTo( left 
+ 1, top 
+ 1 ); 
1151         LineTo( left 
+ m_width 
- 3 , top 
+ 1 ); 
1153         RGBForeColor( sunken 
? &white 
: &lightShadow 
); 
1154         MoveTo( left 
+ 1 , top 
+ m_height 
- 2 ); 
1155         LineTo( left 
+ m_width 
- 2 , top 
+ m_height 
- 2 ); 
1156         LineTo( left 
+ m_width 
- 2 , top 
+ 1 ); 
1158         RGBForeColor( sunken 
? &darkShadow 
: &face 
); 
1159         MoveTo( left 
+ 2 , top 
+ m_height 
- 4 ); 
1160         LineTo( left 
+ 2 , top 
+ 2 ); 
1161         LineTo( left 
+ m_width 
- 4 , top 
+ 2 ); 
1164     else if (HasFlag(wxSIMPLE_BORDER
)) 
1166         Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1167         RGBForeColor( &darkShadow 
) ; 
1168         FrameRect( &rect 
) ; 
1172 void wxWindowMac::RemoveChild( wxWindowBase 
*child 
) 
1174     if ( child 
== m_hScrollBar 
) 
1175         m_hScrollBar 
= NULL 
; 
1176     if ( child 
== m_vScrollBar 
) 
1177         m_vScrollBar 
= NULL 
; 
1179     wxWindowBase::RemoveChild( child 
) ; 
1182 // New function that will replace some of the above. 
1183 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
, 
1184     int range
, bool refresh
) 
1186     if ( orient 
== wxHORIZONTAL 
) 
1190             if ( range 
== 0 || thumbVisible 
>= range 
) 
1192                 if ( m_hScrollBar
->IsShown() ) 
1193                     m_hScrollBar
->Show(false) ; 
1197                 if ( !m_hScrollBar
->IsShown() ) 
1198                     m_hScrollBar
->Show(true) ; 
1199                 m_hScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1207             if ( range 
== 0 || thumbVisible 
>= range 
) 
1209                 if ( m_vScrollBar
->IsShown() ) 
1210                     m_vScrollBar
->Show(false) ; 
1214                 if ( !m_vScrollBar
->IsShown() ) 
1215                     m_vScrollBar
->Show(true) ; 
1216                 m_vScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1220     MacRepositionScrollBars() ; 
1223 // Does a physical scroll 
1224 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
1226     if( dx 
== 0 && dy 
==0 ) 
1231         wxClientDC 
dc(this) ; 
1232         wxMacPortSetter 
helper(&dc
) ; 
1234         int width 
, height 
; 
1235         GetClientSize( &width 
, &height 
) ; 
1237         Rect scrollrect 
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ; 
1238         RgnHandle updateRgn 
= NewRgn() ; 
1239         ClipRect( &scrollrect 
) ; 
1242             Rect r 
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y 
+ rect
->height
) , 
1243                 dc
.XLOG2DEVMAC(rect
->x 
+ rect
->width
) } ; 
1244             SectRect( &scrollrect 
, &r 
, &scrollrect 
) ; 
1246         ScrollRect( &scrollrect 
, dx 
, dy 
, updateRgn 
) ; 
1247         // we also have to scroll the update rgn in this rectangle  
1248         // in order not to loose updates 
1249         WindowRef rootWindow 
= (WindowRef
) MacGetRootWindow() ; 
1250         RgnHandle formerUpdateRgn 
= NewRgn() ; 
1251         RgnHandle scrollRgn 
= NewRgn() ; 
1252         RectRgn( scrollRgn 
, &scrollrect 
) ; 
1253         GetWindowUpdateRgn( rootWindow 
, formerUpdateRgn 
) ; 
1255         LocalToGlobal( &pt 
) ; 
1256         OffsetRgn( formerUpdateRgn 
, -pt
.h 
, -pt
.v 
) ; 
1257         SectRgn( formerUpdateRgn 
, scrollRgn 
, formerUpdateRgn 
) ; 
1258         if ( !EmptyRgn( formerUpdateRgn 
) ) 
1260             MacOffsetRgn( formerUpdateRgn 
, dx 
, dy 
) ; 
1261             SectRgn( formerUpdateRgn 
, scrollRgn 
, formerUpdateRgn 
) ; 
1262             InvalWindowRgn(rootWindow  
,  formerUpdateRgn 
) ; 
1264         InvalWindowRgn(rootWindow  
,  updateRgn 
) ; 
1265         DisposeRgn( updateRgn 
) ; 
1266         DisposeRgn( formerUpdateRgn 
) ; 
1267         DisposeRgn( scrollRgn 
) ; 
1270     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1272         wxWindowMac 
*child 
= node
->GetData(); 
1273         if (child 
== m_vScrollBar
) continue; 
1274         if (child 
== m_hScrollBar
) continue; 
1275         if (child
->IsTopLevel()) continue; 
1278         child
->GetPosition( &x
, &y 
); 
1280         child
->GetSize( &w
, &h 
); 
1284             if (rect
->Intersects(rc
)) 
1285                 child
->SetSize( x
+dx
, y
+dy
, w
, h 
); 
1289             child
->SetSize( x
+dx
, y
+dy
, w
, h 
);          
1297 void wxWindowMac::MacOnScroll(wxScrollEvent 
&event 
) 
1299     if ( event
.m_eventObject 
== m_vScrollBar 
|| event
.m_eventObject 
== m_hScrollBar 
) 
1301         wxScrollWinEvent wevent
; 
1302         wevent
.SetPosition(event
.GetPosition()); 
1303         wevent
.SetOrientation(event
.GetOrientation()); 
1304         wevent
.m_eventObject 
= this; 
1306         if (event
.m_eventType 
== wxEVT_SCROLL_TOP
) 
1307             wevent
.m_eventType 
= wxEVT_SCROLLWIN_TOP
; 
1308         else if (event
.m_eventType 
== wxEVT_SCROLL_BOTTOM
) 
1309             wevent
.m_eventType 
= wxEVT_SCROLLWIN_BOTTOM
; 
1310         else if (event
.m_eventType 
== wxEVT_SCROLL_LINEUP
) 
1311             wevent
.m_eventType 
= wxEVT_SCROLLWIN_LINEUP
; 
1312         else if (event
.m_eventType 
== wxEVT_SCROLL_LINEDOWN
) 
1313             wevent
.m_eventType 
= wxEVT_SCROLLWIN_LINEDOWN
; 
1314         else if (event
.m_eventType 
== wxEVT_SCROLL_PAGEUP
) 
1315             wevent
.m_eventType 
= wxEVT_SCROLLWIN_PAGEUP
; 
1316         else if (event
.m_eventType 
== wxEVT_SCROLL_PAGEDOWN
) 
1317             wevent
.m_eventType 
= wxEVT_SCROLLWIN_PAGEDOWN
; 
1318         else if (event
.m_eventType 
== wxEVT_SCROLL_THUMBTRACK
) 
1319             wevent
.m_eventType 
= wxEVT_SCROLLWIN_THUMBTRACK
; 
1320         else if (event
.m_eventType 
== wxEVT_SCROLL_THUMBRELEASE
) 
1321             wevent
.m_eventType 
= wxEVT_SCROLLWIN_THUMBRELEASE
; 
1323         GetEventHandler()->ProcessEvent(wevent
); 
1327 // Get the window with the focus 
1328 wxWindowMac 
*wxWindowBase::FindFocus() 
1330     return gFocusWindow 
; 
1333 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
) 
1335     // panel wants to track the window which was the last to have focus in it, 
1336     // so we want to set ourselves as the window which last had focus 
1338     // notice that it's also important to do it upwards the tree becaus 
1339     // otherwise when the top level panel gets focus, it won't set it back to 
1340     // us, but to some other sibling 
1342     // CS:don't know if this is still needed: 
1343     //wxChildFocusEvent eventFocus(this); 
1344     //(void)GetEventHandler()->ProcessEvent(eventFocus); 
1349 // Setup background and foreground colours correctly 
1350 void wxWindowMac::SetupColours() 
1353         SetBackgroundColour(GetParent()->GetBackgroundColour()); 
1356 void wxWindowMac::OnInternalIdle() 
1358     // This calls the UI-update mechanism (querying windows for 
1359     // menu/toolbar/control state information) 
1360     if (wxUpdateUIEvent::CanUpdate(this)) 
1361         UpdateWindowUI(wxUPDATE_UI_FROMIDLE
); 
1364 // Raise the window to the top of the Z order 
1365 void wxWindowMac::Raise() 
1369 // Lower the window to the bottom of the Z order 
1370 void wxWindowMac::Lower() 
1374 void wxWindowMac::DoSetClientSize(int width
, int height
) 
1376     if ( width 
!= -1 || height 
!= -1 ) 
1379         if ( width 
!= -1 && m_vScrollBar 
) 
1380             width 
+= MAC_SCROLLBAR_SIZE 
; 
1381         if ( height 
!= -1 && m_vScrollBar 
) 
1382             height 
+= MAC_SCROLLBAR_SIZE 
; 
1384         width 
+= MacGetLeftBorderSize(  ) + MacGetRightBorderSize( ) ; 
1385         height 
+= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ) ; 
1387         DoSetSize( -1 , -1 , width 
, height 
) ; 
1392 wxWindowMac
* wxWindowMac::s_lastMouseWindow 
= NULL 
; 
1394 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint 
&point 
, wxWindowMac
** outWin 
) 
1398         if ((point
.x 
< 0) || (point
.y 
< 0) || 
1399             (point
.x 
> (m_width
)) || (point
.y 
> (m_height
))) 
1404         if ((point
.x 
< m_x
) || (point
.y 
< m_y
) || 
1405             (point
.x 
> (m_x 
+ m_width
)) || (point
.y 
> (m_y 
+ m_height
))) 
1409     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1411     wxPoint 
newPoint( point 
) ; 
1413     if ( !IsTopLevel() ) 
1419     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1421         wxWindowMac 
*child 
= node
->GetData(); 
1422         // added the m_isShown test --dmazzoni 
1423         if ( child
->MacGetRootWindow() == window 
&& child
->m_isShown 
) 
1425             if (child
->MacGetWindowFromPointSub(newPoint 
, outWin 
)) 
1434 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint 
&screenpoint 
, wxWindowMac
** outWin 
) 
1438     Point pt 
= { screenpoint
.y 
, screenpoint
.x 
} ; 
1439     if ( ::FindWindow( pt 
, &window 
) == 3 ) 
1442         wxWindowMac
* win 
= wxFindWinFromMacWindow( window 
) ; 
1445             // No, this yields the CLIENT are, we need the whole frame. RR. 
1446             // point = win->ScreenToClient( point ) ; 
1449             ::GetPort( &port 
) ; 
1450             ::SetPort( UMAGetWindowPort( window 
) ) ; 
1451             ::GlobalToLocal( &pt 
) ; 
1454             wxPoint 
point( pt
.h
, pt
.v 
) ; 
1456             return win
->MacGetWindowFromPointSub( point 
, outWin 
) ; 
1462 static wxWindow 
*gs_lastWhich 
= NULL
; 
1464 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
) 
1466     // first trigger a set cursor event 
1468     wxPoint clientorigin 
= GetClientAreaOrigin() ; 
1469     wxSize clientsize 
= GetClientSize() ; 
1471     if ( wxRect2DInt( clientorigin
.x 
, clientorigin
.y 
, clientsize
.x 
, clientsize
.y 
).Contains( wxPoint2DInt( pt 
) ) ) 
1473         wxSetCursorEvent 
event( pt
.x 
, pt
.y 
); 
1475         bool processedEvtSetCursor 
= GetEventHandler()->ProcessEvent(event
); 
1476         if ( processedEvtSetCursor 
&& event
.HasCursor() ) 
1478             cursor 
= event
.GetCursor() ; 
1483             // the test for processedEvtSetCursor is here to prevent using m_cursor 
1484             // if the user code caught EVT_SET_CURSOR() and returned nothing from 
1485             // it - this is a way to say that our cursor shouldn't be used for this 
1487             if ( !processedEvtSetCursor 
&& m_cursor
.Ok() ) 
1497                     cursor 
= *wxSTANDARD_CURSOR  
; 
1501             cursor
.MacInstall() ; 
1503     return cursor
.Ok() ; 
1506 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
) 
1508     if ((event
.m_x 
< m_x
) || (event
.m_y 
< m_y
) || 
1509         (event
.m_x 
> (m_x 
+ m_width
)) || (event
.m_y 
> (m_y 
+ m_height
))) 
1513     if ( IsKindOf( CLASSINFO ( wxStaticBox 
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */) 
1516     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1524     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1526         wxWindowMac 
*child 
= node
->GetData(); 
1527         if ( child
->MacGetRootWindow() == window 
&& child
->IsShown() && child
->IsEnabled() ) 
1529             if (child
->MacDispatchMouseEvent(event
)) 
1534     wxWindow
* cursorTarget 
= this ; 
1535     wxPoint 
cursorPoint( x 
, y 
) ; 
1537     while( cursorTarget 
&& !cursorTarget
->MacSetupCursor( cursorPoint 
) ) 
1539         cursorTarget 
= cursorTarget
->GetParent() ; 
1541             cursorPoint 
+= cursorTarget
->GetPosition() ; 
1545     event
.SetEventObject( this ) ; 
1547     if ( event
.GetEventType() == wxEVT_LEFT_DOWN 
) 
1549         // set focus to this window 
1550         if (AcceptsFocus() && FindFocus()!=this) 
1555     if ( event
.GetEventType() == wxEVT_MOTION
 
1556         || event
.GetEventType() == wxEVT_ENTER_WINDOW
 
1557         || event
.GetEventType() == wxEVT_LEAVE_WINDOW 
) 
1558         wxToolTip::RelayEvent( this , event
); 
1559 #endif // wxUSE_TOOLTIPS 
1561     if (gs_lastWhich 
!= this) 
1563         gs_lastWhich 
= this; 
1565         // Double clicks must always occur on the same window 
1566         if (event
.GetEventType() == wxEVT_LEFT_DCLICK
) 
1567             event
.SetEventType( wxEVT_LEFT_DOWN 
); 
1568         if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) 
1569             event
.SetEventType( wxEVT_RIGHT_DOWN 
); 
1571         // Same for mouse up events 
1572         if (event
.GetEventType() == wxEVT_LEFT_UP
) 
1574         if (event
.GetEventType() == wxEVT_RIGHT_UP
) 
1578     GetEventHandler()->ProcessEvent( event 
) ; 
1583 wxString 
wxWindowMac::MacGetToolTipString( wxPoint 
&pt 
) 
1587         return m_tooltip
->GetTip() ; 
1589     return wxEmptyString 
; 
1592 void wxWindowMac::Update() 
1594     wxRegion visRgn 
= MacGetVisibleRegion( false ) ; 
1595     int top 
= 0 , left 
= 0 ; 
1596     MacWindowToRootWindow( &left 
, &top 
) ; 
1597     WindowRef rootWindow 
= (WindowRef
) MacGetRootWindow() ; 
1598     RgnHandle updateRgn 
= NewRgn() ;     
1599     // getting the update region in macos local coordinates 
1600     GetWindowUpdateRgn( rootWindow 
, updateRgn 
) ; 
1602     ::GetPort( &port 
) ; 
1603     ::SetPort( UMAGetWindowPort( rootWindow 
) ) ; 
1605     LocalToGlobal( &pt 
) ; 
1607     OffsetRgn( updateRgn 
, -pt
.h 
, -pt
.v 
) ; 
1608     // translate to window local coordinates 
1609     OffsetRgn( updateRgn 
, -left 
, -top 
) ; 
1610     SectRgn( updateRgn 
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn 
) ; 
1611     MacRedraw( updateRgn 
, 0 , true ) ; 
1612     // for flushing and validating we need macos-local coordinates again 
1613     OffsetRgn( updateRgn 
, left 
, top 
) ; 
1614 #if TARGET_API_MAC_CARBON 
1615     if ( QDIsPortBuffered( GetWindowPort( rootWindow 
) ) ) 
1617         QDFlushPortBuffer( GetWindowPort( rootWindow 
) , updateRgn 
) ; 
1620     ValidWindowRgn( rootWindow 
, updateRgn 
) ; 
1621     DisposeRgn( updateRgn 
) ; 
1624 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const 
1626     wxTopLevelWindowMac
* win 
= NULL 
; 
1627     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1630         win 
= wxFindWinFromMacWindow( window 
) ; 
1635 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings 
) 
1637     RgnHandle visRgn 
= NewRgn() ; 
1638     RgnHandle tempRgn 
= NewRgn() ; 
1639     RgnHandle tempStaticBoxRgn 
= NewRgn() ; 
1641     if ( MacIsReallyShown() ) 
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 ; 
1650             if ( UMAGetSystemVersion() >= 0x1030 ) 
1653             SetRectRgn( tempStaticBoxRgn 
, borderOther 
, borderTop 
, m_width 
- borderOther 
, m_height 
- borderOther 
) ; 
1654             DiffRgn( visRgn 
, tempStaticBoxRgn 
, visRgn 
) ; 
1657         if ( !IsTopLevel() ) 
1659             wxWindow
* parent 
= GetParent() ; 
1662                 wxSize size 
= parent
->GetSize() ; 
1665                 parent
->MacWindowToRootWindow( &x
, &y 
) ; 
1666                 MacRootWindowToWindow( &x 
, &y 
) ; 
1668                 SetRectRgn( tempRgn 
, 
1669                     x 
+ parent
->MacGetLeftBorderSize() , y 
+ parent
->MacGetTopBorderSize() , 
1670                     x 
+ size
.x 
- parent
->MacGetRightBorderSize(), 
1671                     y 
+ size
.y 
- parent
->MacGetBottomBorderSize()) ; 
1673                 SectRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1674                 if ( parent
->IsTopLevel() ) 
1676                 parent 
= parent
->GetParent() ; 
1679         if ( respectChildrenAndSiblings 
) 
1681             if ( GetWindowStyle() & wxCLIP_CHILDREN 
) 
1683                 for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1685                     wxWindowMac 
*child 
= node
->GetData(); 
1687                     if ( !child
->IsTopLevel() && child
->IsShown() ) 
1689                         SetRectRgn( tempRgn 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1690                         if ( child
->IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1692                             int borderTop 
= 14 ; 
1693                             int borderOther 
= 4 ; 
1694                             if ( UMAGetSystemVersion() >= 0x1030 ) 
1697                             SetRectRgn( tempStaticBoxRgn 
, child
->m_x 
+ borderOther 
, child
->m_y 
+ borderTop 
, child
->m_x 
+ child
->m_width 
- borderOther 
, child
->m_y 
+ child
->m_height 
- borderOther 
) ; 
1698                             DiffRgn( tempRgn 
, tempStaticBoxRgn 
, tempRgn 
) ; 
1700                         DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1705             if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() ) 
1707                 bool thisWindowThrough 
= false ; 
1708                 for (wxWindowListNode 
*node 
= GetParent()->GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1710                     wxWindowMac 
*sibling 
= node
->GetData(); 
1711                     if ( sibling 
== this ) 
1713                         thisWindowThrough 
= true ; 
1716                     if( !thisWindowThrough 
) 
1721                     if ( !sibling
->IsTopLevel() && sibling
->IsShown() ) 
1723                         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 
) ; 
1724                         if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1726                             int borderTop 
= 14 ; 
1727                             int borderOther 
= 4 ; 
1728                             if ( UMAGetSystemVersion() >= 0x1030 ) 
1731                             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 
) ; 
1732                             DiffRgn( tempRgn 
, tempStaticBoxRgn 
, tempRgn 
) ; 
1734                         DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1740     m_macVisibleRegion 
= visRgn 
; 
1741     DisposeRgn( visRgn 
) ; 
1742     DisposeRgn( tempRgn 
) ; 
1743     DisposeRgn( tempStaticBoxRgn 
) ; 
1744     return m_macVisibleRegion 
; 
1747 void wxWindowMac::MacRedraw( WXHRGN updatergnr 
, long time
, bool erase
) 
1749     RgnHandle updatergn 
= (RgnHandle
) updatergnr 
; 
1750     // updatergn is always already clipped to our boundaries 
1751     // it is in window coordinates, not in client coordinates 
1753     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1756         // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates 
1757         RgnHandle ownUpdateRgn 
= NewRgn() ; 
1758         CopyRgn( updatergn 
, ownUpdateRgn 
) ; 
1760         SectRgn( ownUpdateRgn 
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn 
) ; 
1762         // newupdate is the update region in client coordinates 
1763         RgnHandle newupdate 
= NewRgn() ; 
1764         wxSize point 
= GetClientSize() ; 
1765         wxPoint origin 
= GetClientAreaOrigin() ; 
1766         SetRectRgn( newupdate 
, origin
.x 
, origin
.y 
, origin
.x 
+ point
.x 
, origin
.y
+point
.y 
) ; 
1767         SectRgn( newupdate 
, ownUpdateRgn 
, newupdate 
) ; 
1768         OffsetRgn( newupdate 
, -origin
.x 
, -origin
.y 
) ; 
1769         m_updateRegion 
= newupdate 
; 
1770         DisposeRgn( newupdate 
) ; // it's been cloned to m_updateRegion 
1772         if ( erase 
&& !EmptyRgn(ownUpdateRgn
) ) 
1774             wxWindowDC 
dc(this); 
1775             if (!EmptyRgn(ownUpdateRgn
)) 
1776                 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
)); 
1777             wxEraseEvent 
eevent( GetId(), &dc 
); 
1778             eevent
.SetEventObject( this ); 
1779             GetEventHandler()->ProcessEvent( eevent 
); 
1781             wxNcPaintEvent 
eventNc( GetId() ); 
1782             eventNc
.SetEventObject( this ); 
1783             GetEventHandler()->ProcessEvent( eventNc 
); 
1785         DisposeRgn( ownUpdateRgn 
) ; 
1786         if ( !m_updateRegion
.Empty() ) 
1788             wxWindowList hiddenWindows 
; 
1789             for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1791                 wxControl 
*child 
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl 
) ; 
1793                 if ( child 
&& child
->MacGetRootWindow() == window 
&& child
->IsShown() && child
->GetMacControl() ) 
1795                     SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ; 
1796                     hiddenWindows
.Append( child 
) ; 
1801             event
.m_timeStamp 
= time 
; 
1802             event
.SetEventObject(this); 
1803             GetEventHandler()->ProcessEvent(event
); 
1805             for (wxWindowListNode 
*node 
= hiddenWindows
.GetFirst(); node
; node 
= node
->GetNext()) 
1807                 wxControl 
*child 
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl 
) ; 
1809                 if ( child 
&& child
->GetMacControl() ) 
1811                     SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ; 
1817     // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively 
1819     RgnHandle childupdate 
= NewRgn() ; 
1820     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1822         // calculate the update region for the child windows by intersecting the window rectangle with our own 
1823         // passed in update region and then offset it to be client-wise window coordinates again 
1824         wxWindowMac 
*child 
= node
->GetData(); 
1825         SetRectRgn( childupdate 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1826         SectRgn( childupdate 
, updatergn 
, childupdate 
) ; 
1827         OffsetRgn( childupdate 
, -child
->m_x 
, -child
->m_y 
) ; 
1828         if ( child
->MacGetRootWindow() == window 
&& child
->IsShown() && !EmptyRgn( childupdate 
) ) 
1830             // because dialogs may also be children 
1831             child
->MacRedraw( childupdate 
, time 
, erase 
) ; 
1834     DisposeRgn( childupdate 
) ; 
1835     // eventually a draw grow box here 
1839 WXHWND 
wxWindowMac::MacGetRootWindow() const 
1841     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1845         if ( iter
->IsTopLevel() ) 
1846             return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ; 
1848         iter 
= iter
->GetParent() ; 
1850     wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; 
1854 void wxWindowMac::MacCreateScrollBars( long style 
) 
1856     wxASSERT_MSG( m_vScrollBar 
== NULL 
&& m_hScrollBar 
== NULL 
, wxT("attempt to create window twice") ) ; 
1858     bool hasBoth 
= ( style 
& wxVSCROLL 
) && ( style 
& wxHSCROLL 
) ; 
1859     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1: 0 ; 
1861     GetClientSize( &width 
, &height 
) ; 
1863     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1864     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1865     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1866     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1868     m_vScrollBar 
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
, 
1869         vSize 
, wxVERTICAL
); 
1871     if ( style 
& wxVSCROLL 
) 
1877         m_vScrollBar
->Show(false) ; 
1879     m_hScrollBar 
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
, 
1880         hSize 
, wxHORIZONTAL
); 
1881     if ( style  
& wxHSCROLL 
) 
1886         m_hScrollBar
->Show(false) ; 
1889     // because the create does not take into account the client area origin 
1890     MacRepositionScrollBars() ; // we might have a real position shift 
1893 void wxWindowMac::MacRepositionScrollBars() 
1895     bool hasBoth 
= ( m_hScrollBar 
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar 
&& m_vScrollBar
->IsShown()) ; 
1896     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1 : 0 ; 
1898     // get real client area 
1900     int width 
= m_width 
; 
1901     int height 
= m_height 
; 
1903     width 
-= MacGetLeftBorderSize() + MacGetRightBorderSize(); 
1904     height 
-= MacGetTopBorderSize() + MacGetBottomBorderSize(); 
1906     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1907     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1908     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1909     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1916     MacClientToRootWindow( &x 
, &y 
) ; 
1917     MacClientToRootWindow( &w 
, &h 
) ; 
1919     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1921     int totW 
= 10000 , totH 
= 10000; 
1924         if ( iter
->IsTopLevel() ) 
1926             totW 
= iter
->m_width 
; 
1927             totH 
= iter
->m_height 
; 
1931         iter 
= iter
->GetParent() ; 
1959         m_vScrollBar
->SetSize( vPoint
.x 
, vPoint
.y
, vSize
.x
, vSize
.y 
, wxSIZE_ALLOW_MINUS_ONE
); 
1963         m_hScrollBar
->SetSize( hPoint
.x 
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
); 
1967 bool wxWindowMac::AcceptsFocus() const 
1969     return MacCanFocus() && wxWindowBase::AcceptsFocus(); 
1972 WXWidget 
wxWindowMac::MacGetContainerForEmbedding() 
1974     return GetParent()->MacGetContainerForEmbedding() ; 
1977 void wxWindowMac::MacSuperChangedPosition() 
1979     // only window-absolute structures have to be moved i.e. controls 
1981     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
1984         wxWindowMac 
*child 
= node
->GetData(); 
1985         child
->MacSuperChangedPosition() ; 
1986         node 
= node
->GetNext(); 
1990 void wxWindowMac::MacTopLevelWindowChangedPosition() 
1992     // only screen-absolute structures have to be moved i.e. glcanvas 
1994     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
1997         wxWindowMac 
*child 
= node
->GetData(); 
1998         child
->MacTopLevelWindowChangedPosition() ; 
1999         node 
= node
->GetNext(); 
2002 long wxWindowMac::MacGetLeftBorderSize( ) const 
2007     if (m_windowStyle 
& wxRAISED_BORDER 
|| m_windowStyle 
& wxSUNKEN_BORDER 
) 
2010 #if wxMAC_USE_THEME_BORDER 
2012           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
2017     else if (  m_windowStyle 
&wxDOUBLE_BORDER
) 
2020 #if wxMAC_USE_THEME_BORDER 
2022           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
2027     else if (m_windowStyle 
&wxSIMPLE_BORDER
) 
2034 long wxWindowMac::MacGetRightBorderSize( ) const 
2036     // they are all symmetric in mac themes 
2037     return MacGetLeftBorderSize() ; 
2040 long wxWindowMac::MacGetTopBorderSize( ) const 
2042     // they are all symmetric in mac themes 
2043     return MacGetLeftBorderSize() ; 
2046 long wxWindowMac::MacGetBottomBorderSize( ) const 
2048     // they are all symmetric in mac themes 
2049     return MacGetLeftBorderSize() ; 
2052 long wxWindowMac::MacRemoveBordersFromStyle( long style 
) 
2054     return style 
& ~( wxDOUBLE_BORDER 
| wxSUNKEN_BORDER 
| wxRAISED_BORDER 
| wxBORDER 
| wxSTATIC_BORDER 
) ; 
2057 // Find the wxWindowMac at the current mouse position, returning the mouse 
2059 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
) 
2061     pt 
= wxGetMousePosition(); 
2062     wxWindowMac
* found 
= wxFindWindowAtPoint(pt
); 
2066 // Get the current mouse position. 
2067 wxPoint 
wxGetMousePosition() 
2070     wxGetMousePosition(& x
, & y
); 
2071     return wxPoint(x
, y
); 
2074 void wxWindowMac::OnMouseEvent( wxMouseEvent 
&event 
) 
2076         if ( event
.GetEventType() == wxEVT_RIGHT_DOWN 
) 
2078                 // copied from wxGTK : CS 
2079         // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN 
2082         // (a) it's a command event and so is propagated to the parent 
2083         // (b) under MSW it can be generated from kbd too 
2084         // (c) it uses screen coords (because of (a)) 
2085         wxContextMenuEvent 
evtCtx(wxEVT_CONTEXT_MENU
, 
2087                                   this->ClientToScreen(event
.GetPosition())); 
2088         if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )