1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/classic/window.cpp 
   3 // Purpose:     wxWindowMac 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  14 #include "wx/window.h" 
  23     #include "wx/dcclient.h" 
  24     #include "wx/button.h" 
  26     #include "wx/dialog.h" 
  27     #include "wx/settings.h" 
  28     #include "wx/msgdlg.h" 
  29     #include "wx/scrolbar.h" 
  30     #include "wx/statbox.h" 
  31     #include "wx/listbox.h" 
  34 #include "wx/layout.h" 
  35 #include "wx/notebook.h" 
  36 #include "wx/tabctrl.h" 
  37 #include "wx/tooltip.h" 
  38 #include "wx/statusbr.h" 
  39 #include "wx/menuitem.h" 
  40 #include "wx/spinctrl.h" 
  41 #include "wx/geometry.h" 
  47 #define wxWINDOW_HSCROLL 5998 
  48 #define wxWINDOW_VSCROLL 5997 
  49 #define MAC_SCROLLBAR_SIZE 16 
  51 #include "wx/mac/uma.h" 
  54 #include <ToolUtils.h> 
  57 #if  wxUSE_DRAG_AND_DROP 
  63 wxWindowMac
* gFocusWindow 
= NULL 
; 
  65 #ifdef __WXUNIVERSAL__ 
  66     IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
) 
  68     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
) 
  69 #endif // __WXUNIVERSAL__/__WXMAC__ 
  71 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
) 
  72   EVT_NC_PAINT(wxWindowMac::OnNcPaint
) 
  73   EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
) 
  74   EVT_SET_FOCUS(wxWindowMac::OnSetFocus
) 
  75   EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
) 
  78 #define wxMAC_DEBUG_REDRAW 0 
  79 #ifndef wxMAC_DEBUG_REDRAW 
  80 #define wxMAC_DEBUG_REDRAW 0 
  83 #define wxMAC_USE_THEME_BORDER 0 
  86 // =========================================================================== 
  88 // =========================================================================== 
  91 // ---------------------------------------------------------------------------- 
  92 // constructors and such 
  93 // ---------------------------------------------------------------------------- 
  95 void wxWindowMac::Init() 
  97     m_backgroundTransparent 
= false; 
  99     // as all windows are created with WS_VISIBLE style... 
 107     m_hScrollBar 
= NULL 
; 
 108     m_vScrollBar 
= NULL 
; 
 112 wxWindowMac::~wxWindowMac() 
 116     // deleting a window while it is shown invalidates the region 
 118         wxWindowMac
* iter 
= this ; 
 120             if ( iter
->IsTopLevel() ) 
 125             iter 
= iter
->GetParent() ; 
 130     m_isBeingDeleted 
= true; 
 132 #ifndef __WXUNIVERSAL__ 
 133     // VS: make sure there's no wxFrame with last focus set to us: 
 134     for ( wxWindow 
*win 
= GetParent(); win
; win 
= win
->GetParent() ) 
 136         wxFrame 
*frame 
= wxDynamicCast(win
, wxFrame
); 
 139             if ( frame
->GetLastFocus() == this ) 
 141                 frame
->SetLastFocus((wxWindow
*)NULL
); 
 146 #endif // __WXUNIVERSAL__ 
 148     if ( s_lastMouseWindow 
== this ) 
 150         s_lastMouseWindow 
= NULL 
; 
 153     wxFrame
* frame 
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame 
) ; 
 156         if ( frame
->GetLastFocus() == this ) 
 157             frame
->SetLastFocus( NULL 
) ; 
 160     if ( gFocusWindow 
== this ) 
 162         gFocusWindow 
= NULL 
; 
 167     // delete our drop target if we've got one 
 168 #if wxUSE_DRAG_AND_DROP 
 169     if ( m_dropTarget 
!= NULL 
) 
 174 #endif // wxUSE_DRAG_AND_DROP 
 178 bool wxWindowMac::Create(wxWindowMac 
*parent
, wxWindowID id
, 
 182            const wxString
& name
) 
 184     wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") ); 
 187     // wxGTK doesn't allow to create controls with static box as the parent so 
 188     // this will result in a crash when the program is ported to wxGTK - warn 
 191     // the correct solution is to create the controls as siblings of the 
 193     wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
), 
 194                   _T("wxStaticBox can't be used as a window parent!") ); 
 195 #endif // wxUSE_STATBOX 
 197     if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) ) 
 200     parent
->AddChild(this); 
 204     AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
); 
 205     m_width 
= WidthDefault( size
.x 
); 
 206     m_height 
= HeightDefault( size
.y 
) ; 
 207 #ifndef __WXUNIVERSAL__ 
 208     // Don't give scrollbars to wxControls unless they ask for them 
 209     if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) || 
 210          (IsKindOf(CLASSINFO(wxControl
)) && ( style 
& wxHSCROLL 
|| style 
& wxVSCROLL
))) 
 212         MacCreateScrollBars( style 
) ; 
 216     wxWindowCreateEvent 
event(this); 
 217     GetEventHandler()->AddPendingEvent(event
); 
 222 void wxWindowMac::SetFocus() 
 224     if ( gFocusWindow 
== this ) 
 227     if ( AcceptsFocus() ) 
 233                 if ( gFocusWindow
->m_caret 
) 
 235                       gFocusWindow
->m_caret
->OnKillFocus(); 
 237 #endif // wxUSE_CARET 
 238 #ifndef __WXUNIVERSAL__ 
 239             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 240             if ( control 
&& control
->GetMacControl() ) 
 242                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNoPart 
) ; 
 243                 control
->MacRedrawControl() ; 
 246             // Without testing the window id, for some reason 
 247             // a kill focus event can still be sent to 
 248             // the control just being focussed. 
 249             int thisId 
= this->m_windowId
; 
 250             int gFocusWindowId 
= gFocusWindow
->m_windowId
; 
 251             if (gFocusWindowId 
!= thisId
) 
 253                 wxFocusEvent 
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
); 
 254                 event
.SetEventObject(gFocusWindow
); 
 255                 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ; 
 258         gFocusWindow 
= this ; 
 264                 m_caret
->OnSetFocus(); 
 266             #endif // wxUSE_CARET 
 267             // panel wants to track the window which was the last to have focus in it 
 268             wxChildFocusEvent 
eventFocus(this); 
 269             GetEventHandler()->ProcessEvent(eventFocus
); 
 271       #ifndef __WXUNIVERSAL__ 
 272             wxControl
* control 
= wxDynamicCast( gFocusWindow 
, wxControl 
) ; 
 273             if ( control 
&& control
->GetMacControl() ) 
 275                 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl()  , kControlFocusNextPart 
) ; 
 278             wxFocusEvent 
event(wxEVT_SET_FOCUS
, m_windowId
); 
 279             event
.SetEventObject(this); 
 280             GetEventHandler()->ProcessEvent(event
) ; 
 285 bool wxWindowMac::Enable(bool enable
) 
 287     if ( !wxWindowBase::Enable(enable
) ) 
 290     MacSuperEnabled( enable 
) ; 
 295 void wxWindowMac::DoCaptureMouse() 
 297     wxTheApp
->s_captureWindow 
= this ; 
 300 wxWindow
* wxWindowBase::GetCapture() 
 302     return wxTheApp
->s_captureWindow 
; 
 305 void wxWindowMac::DoReleaseMouse() 
 307     wxTheApp
->s_captureWindow 
= NULL 
; 
 310 #if    wxUSE_DRAG_AND_DROP 
 312 void wxWindowMac::SetDropTarget(wxDropTarget 
*pDropTarget
) 
 314     if ( m_dropTarget 
!= 0 ) { 
 318     m_dropTarget 
= pDropTarget
; 
 319     if ( m_dropTarget 
!= 0 ) 
 327 // Old style file-manager drag&drop 
 328 void wxWindowMac::DragAcceptFiles(bool accept
) 
 334 void wxWindowMac::DoGetSize(int *x
, int *y
) const 
 337      if(y
)   *y 
= m_height 
; 
 340 void wxWindowMac::DoGetPosition(int *x
, int *y
) const 
 346     if ( !IsTopLevel() && GetParent()) 
 348         wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
 357 bool wxWindowMac::DoPopupMenu(wxMenu 
*menu
, int x
, int y
) 
 359     menu
->SetInvokingWindow(this); 
 362     if ( x 
== -1 && y 
== -1 ) 
 364         wxPoint mouse 
= wxGetMousePosition(); 
 365         x 
= mouse
.x
; y 
= mouse
.y
; 
 369         ClientToScreen( &x 
, &y 
) ; 
 372     menu
->MacBeforeDisplay( true ) ; 
 373     long menuResult 
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ; 
 374     if ( HiWord(menuResult
) != 0 ) 
 377         GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id 
) ; 
 378         wxMenuItem
* item 
= NULL 
; 
 380         item 
= menu
->FindItem(id
, &realmenu
) ; 
 381         if (item
->IsCheckable()) 
 383             item
->Check( !item
->IsChecked() ) ; 
 385         menu
->SendEvent( id 
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ; 
 387     menu
->MacAfterDisplay( true ) ; 
 389     menu
->SetInvokingWindow(NULL
); 
 395 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const 
 397     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 399     Point       localwhere 
= {0,0} ; 
 401     if(x
)   localwhere
.h 
= * x 
; 
 402     if(y
)   localwhere
.v 
= * y 
; 
 406     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 407     ::GlobalToLocal( &localwhere 
) ; 
 410     if(x
)   *x 
= localwhere
.h 
; 
 411     if(y
)   *y 
= localwhere
.v 
; 
 413     MacRootWindowToWindow( x 
, y 
) ; 
 415         *x 
-= MacGetLeftBorderSize() ; 
 417         *y 
-= MacGetTopBorderSize() ; 
 420 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const 
 422     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 425         *x 
+= MacGetLeftBorderSize() ; 
 427         *y 
+= MacGetTopBorderSize() ; 
 429     MacWindowToRootWindow( x 
, y 
) ; 
 431     Point       localwhere 
= { 0,0 }; 
 432     if(x
)   localwhere
.h 
= * x 
; 
 433     if(y
)   localwhere
.v 
= * y 
; 
 437     ::SetPort( UMAGetWindowPort( window 
) ) ; 
 439     ::LocalToGlobal( &localwhere 
) ; 
 441     if(x
)   *x 
= localwhere
.h 
; 
 442     if(y
)   *y 
= localwhere
.v 
; 
 445 void wxWindowMac::MacClientToRootWindow( int *x 
, int *y 
) const 
 447     wxPoint origin 
= GetClientAreaOrigin() ; 
 448     if(x
)   *x 
+= origin
.x 
; 
 449     if(y
)   *y 
+= origin
.y 
; 
 451     MacWindowToRootWindow( x 
, y 
) ; 
 454 void wxWindowMac::MacRootWindowToClient( int *x 
, int *y 
) const 
 456     wxPoint origin 
= GetClientAreaOrigin() ; 
 457     MacRootWindowToWindow( x 
, y 
) ; 
 458     if(x
)   *x 
-= origin
.x 
; 
 459     if(y
)   *y 
-= origin
.y 
; 
 462 void wxWindowMac::MacWindowToRootWindow( int *x 
, int *y 
) const 
 468         GetParent()->MacWindowToRootWindow( x 
, y 
) ; 
 472 void wxWindowMac::MacRootWindowToWindow( int *x 
, int *y 
) const 
 478         GetParent()->MacRootWindowToWindow( x 
, y 
) ; 
 482 bool wxWindowMac::SetCursor(const wxCursor
& cursor
) 
 484     if (m_cursor 
== cursor
) 
 487     if (wxNullCursor 
== cursor
) 
 489         if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR 
) ) 
 494         if ( ! wxWindowBase::SetCursor( cursor 
) ) 
 498     wxASSERT_MSG( m_cursor
.Ok(), 
 499         wxT("cursor must be valid after call to the base version")); 
 502     wxWindowMac 
*mouseWin 
; 
 505     // Change the cursor NOW if we're within the correct window 
 507     if ( MacGetWindowFromPoint( wxPoint( pt
.h 
, pt
.v 
) , &mouseWin 
) ) 
 509         if ( mouseWin 
== this && !wxIsBusy() ) 
 511             m_cursor
.MacInstall() ; 
 519 // Get size *available for subwindows* i.e. excluding menu bar etc. 
 520 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const 
 526     ww 
-= MacGetLeftBorderSize(  )  + MacGetRightBorderSize(  ) ; 
 527     hh 
-= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ); 
 529     if ( (m_vScrollBar 
&& m_vScrollBar
->IsShown()) || (m_hScrollBar  
&& m_hScrollBar
->IsShown()) ) 
 536         MacClientToRootWindow( &x1 
, &y1 
) ; 
 537         MacClientToRootWindow( &w 
, &h 
) ; 
 539         wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
 541         int totW 
= 10000 , totH 
= 10000; 
 544             if ( iter
->IsTopLevel() ) 
 546                 totW 
= iter
->m_width 
; 
 547                 totH 
= iter
->m_height 
; 
 551             iter 
= iter
->GetParent() ; 
 554         if (m_hScrollBar  
&& m_hScrollBar
->IsShown() ) 
 556             hh 
-= MAC_SCROLLBAR_SIZE
; 
 562         if (m_vScrollBar  
&& m_vScrollBar
->IsShown() ) 
 564             ww 
-= MAC_SCROLLBAR_SIZE
; 
 576 // ---------------------------------------------------------------------------- 
 578 // ---------------------------------------------------------------------------- 
 582 void wxWindowMac::DoSetToolTip(wxToolTip 
*tooltip
) 
 584     wxWindowBase::DoSetToolTip(tooltip
); 
 587         m_tooltip
->SetWindow(this); 
 590 #endif // wxUSE_TOOLTIPS 
 592 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
) 
 596     int former_w 
= m_width 
; 
 597     int former_h 
= m_height 
; 
 599     int actualWidth 
= width
; 
 600     int actualHeight 
= height
; 
 604     if ((m_minWidth 
!= -1) && (actualWidth 
< m_minWidth
)) 
 605         actualWidth 
= m_minWidth
; 
 606     if ((m_minHeight 
!= -1) && (actualHeight 
< m_minHeight
)) 
 607         actualHeight 
= m_minHeight
; 
 608     if ((m_maxWidth 
!= -1) && (actualWidth 
> m_maxWidth
)) 
 609         actualWidth 
= m_maxWidth
; 
 610     if ((m_maxHeight 
!= -1) && (actualHeight 
> m_maxHeight
)) 
 611         actualHeight 
= m_maxHeight
; 
 613     bool doMove 
= false ; 
 614     bool doResize 
= false ; 
 616     if ( actualX 
!= former_x 
|| actualY 
!= former_y 
) 
 620     if ( actualWidth 
!= former_w 
|| actualHeight 
!= former_h 
) 
 625     if ( doMove 
|| doResize 
) 
 627         // erase former position 
 629         bool partialRepaint 
= false ; 
 631         if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) ) 
 633             wxPoint 
oldPos( m_x 
, m_y 
) ; 
 634             wxPoint 
newPos( actualX 
, actualY 
) ; 
 635             MacWindowToRootWindow( &oldPos
.x 
, &oldPos
.y 
) ; 
 636             MacWindowToRootWindow( &newPos
.x 
, &newPos
.y 
) ; 
 637             if ( oldPos 
== newPos 
) 
 639                 partialRepaint 
= true ; 
 640                 RgnHandle oldRgn
,newRgn
,diffRgn 
; 
 645                 // invalidate the differences between the old and the new area 
 647                 SetRectRgn(oldRgn 
, oldPos
.x 
, oldPos
.y 
, oldPos
.x 
+ m_width 
, oldPos
.y 
+ m_height 
) ; 
 648                 SetRectRgn(newRgn 
, newPos
.x 
, newPos
.y 
, newPos
.x 
+ actualWidth 
, newPos
.y 
+ actualHeight 
) ; 
 649                 DiffRgn( newRgn 
, oldRgn 
, diffRgn 
) ; 
 650                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 651                 DiffRgn( oldRgn 
, newRgn 
, diffRgn 
) ; 
 652                 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 654                 // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really 
 655                 // changing pixels... 
 657                 if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 || 
 658                      MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 ) 
 660                     RgnHandle innerOldRgn
, innerNewRgn 
; 
 661                     innerOldRgn 
= NewRgn() ; 
 662                     innerNewRgn 
= NewRgn() ; 
 664                     SetRectRgn(innerOldRgn 
, oldPos
.x 
+ MacGetLeftBorderSize()  , oldPos
.y 
+ MacGetTopBorderSize() , 
 665                                oldPos
.x 
+ m_width 
- MacGetRightBorderSize() , oldPos
.y 
+ m_height 
- MacGetBottomBorderSize() ) ; 
 666                     DiffRgn( oldRgn 
, innerOldRgn 
, diffRgn 
) ; 
 667                     InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 669                     SetRectRgn(innerNewRgn 
, newPos
.x 
+ MacGetLeftBorderSize()  , newPos
.y 
+ MacGetTopBorderSize() , 
 670                                newPos
.x 
+ actualWidth 
- MacGetRightBorderSize() , newPos
.y 
+ actualHeight 
- MacGetBottomBorderSize() ) ; 
 671                     DiffRgn( newRgn 
, innerNewRgn 
, diffRgn 
) ; 
 672                     InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn 
) ; 
 674                     DisposeRgn( innerOldRgn 
) ; 
 675                     DisposeRgn( innerNewRgn 
) ; 
 680                 DisposeRgn(diffRgn
) ; 
 684         if ( !partialRepaint 
) 
 689         m_width 
= actualWidth 
; 
 690         m_height 
= actualHeight 
; 
 692         // update any low-level frame-relative positions 
 694         MacUpdateDimensions() ; 
 695         // erase new position 
 697         if ( !partialRepaint 
) 
 700             wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified 
 702         MacRepositionScrollBars() ; 
 705             wxPoint 
point(m_x
, m_y
); 
 706             wxMoveEvent 
event(point
, m_windowId
); 
 707             event
.SetEventObject(this); 
 708             GetEventHandler()->ProcessEvent(event
) ; 
 712             MacRepositionScrollBars() ; 
 713             wxSize 
size(m_width
, m_height
); 
 714             wxSizeEvent 
event(size
, m_windowId
); 
 715             event
.SetEventObject(this); 
 716             GetEventHandler()->ProcessEvent(event
); 
 722 // set the size of the window: if the dimensions are positive, just use them, 
 723 // but if any of them is equal to -1, it means that we must find the value for 
 724 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in 
 725 // which case -1 is a valid value for x and y) 
 727 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate 
 728 // the width/height to best suit our contents, otherwise we reuse the current 
 730 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 732     // get the current size and position... 
 733     int currentX
, currentY
; 
 734     GetPosition(¤tX
, ¤tY
); 
 736     int currentW
,currentH
; 
 737     GetSize(¤tW
, ¤tH
); 
 739     // ... and don't do anything (avoiding flicker) if it's already ok 
 740     if ( x 
== currentX 
&& y 
== currentY 
&& 
 741         width 
== currentW 
&& height 
== currentH 
) 
 743         MacRepositionScrollBars() ; // we might have a real position shift 
 747     if ( x 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 749     if ( y 
== -1 && !(sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
) ) 
 752     AdjustForParentClientOrigin(x
, y
, sizeFlags
); 
 757         if ( sizeFlags 
& wxSIZE_AUTO_WIDTH 
) 
 759             size 
= DoGetBestSize(); 
 764             // just take the current one 
 771         if ( sizeFlags 
& wxSIZE_AUTO_HEIGHT 
) 
 775                 size 
= DoGetBestSize(); 
 777             //else: already called DoGetBestSize() above 
 783             // just take the current one 
 788     DoMoveWindow(x
, y
, width
, height
); 
 791 // For implementation purposes - sometimes decorations make the client area 
 794 wxPoint 
wxWindowMac::GetClientAreaOrigin() const 
 796     return wxPoint(MacGetLeftBorderSize(  ) , MacGetTopBorderSize(  ) ); 
 799 void wxWindowMac::SetLabel(const wxString
& label
) 
 804 wxString 
wxWindowMac::GetLabel() const 
 809 bool wxWindowMac::Show(bool show
) 
 811     if ( !wxWindowBase::Show(show
) ) 
 814     MacSuperShown( show 
) ; 
 820 void wxWindowMac::MacSuperShown( bool show 
) 
 822     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
 825         wxWindowMac 
*child 
= node
->GetData(); 
 826         if ( child
->m_isShown 
) 
 827             child
->MacSuperShown( show 
) ; 
 828         node 
= node
->GetNext(); 
 832 void wxWindowMac::MacSuperEnabled( bool enabled 
) 
 836       // to be absolutely correct we'd have to invalidate (with eraseBkground 
 837       // because unter MacOSX the frames are drawn with an addXXX mode) 
 840     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
 843         wxWindowMac 
*child 
= (wxWindowMac 
*)node
->GetData(); 
 844         if ( child
->m_isShown 
) 
 845             child
->MacSuperEnabled( enabled 
) ; 
 846         node 
= node
->GetNext(); 
 850 bool wxWindowMac::MacIsReallyShown() const 
 852     if ( m_isShown 
&& (m_parent 
!= NULL 
&& !IsTopLevel() ) ) { 
 853         return m_parent
->MacIsReallyShown(); 
 857     bool status = m_isShown ; 
 858     wxWindowMac * win = this ; 
 859     while ( status && win->m_parent != NULL ) 
 861         win = win->m_parent ; 
 862         status = win->m_isShown ; 
 868 int wxWindowMac::GetCharHeight() const 
 870     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 871     return dc
.GetCharHeight() ; 
 874 int wxWindowMac::GetCharWidth() const 
 876     wxClientDC 
dc ( (wxWindowMac
*)this ) ; 
 877     return dc
.GetCharWidth() ; 
 880 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
, 
 881                            int *descent
, int *externalLeading
, const wxFont 
*theFont 
) const 
 883     const wxFont 
*fontToUse 
= theFont
; 
 887     wxClientDC 
dc( (wxWindowMac
*) this ) ; 
 889     dc
.GetTextExtent( string 
, &lx 
, &ly 
, &ld
, &le
, (wxFont 
*)fontToUse 
) ; 
 890     if ( externalLeading 
) 
 891         *externalLeading 
= le 
; 
 901  * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect 
 902  * we always intersect with the entire window, not only with the client area 
 905 void wxWindowMac::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 907     if ( MacGetTopLevelWindow() == NULL 
) 
 910     if ( !MacIsReallyShown() ) 
 913      wxPoint client 
= GetClientAreaOrigin(); 
 916     int x2 
= m_width 
- client
.x
; 
 917     int y2 
= m_height 
- client
.y
; 
 919     if (IsKindOf( CLASSINFO(wxButton
))) 
 921         // buttons have an "aura" 
 928     Rect clientrect 
= { y1
, x1
, y2
, x2 
}; 
 932         Rect r 
= { rect
->y 
, rect
->x 
, rect
->y 
+ rect
->height 
, rect
->x 
+ rect
->width 
} ; 
 933         SectRect( &clientrect 
, &r 
, &clientrect 
) ; 
 936     if ( !EmptyRect( &clientrect 
) ) 
 938       int top 
= 0 , left 
= 0 ; 
 940       MacClientToRootWindow( &left 
, &top 
) ; 
 941       OffsetRect( &clientrect 
, left 
, top 
) ; 
 943       MacGetTopLevelWindow()->MacInvalidate( &clientrect 
, eraseBack 
) ; 
 947 wxWindowMac 
*wxGetActiveWindow() 
 949     // actually this is a windows-only concept 
 953 // Coordinates relative to the window 
 954 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
) 
 956     // We really don't move the mouse programmatically under Mac. 
 959 const wxBrush
& wxWindowMac::MacGetBackgroundBrush() 
 961     if ( m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 963         m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground 
) ; 
 965     else if (  m_backgroundColour 
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) ) 
 967         // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether 
 968         // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have 
 969         // either a non gray background color or a non control window 
 971         WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
 973         wxWindowMac
* parent 
= GetParent() ; 
 976             if ( parent
->MacGetRootWindow() != (WXWindow
) window 
) 
 978                 // we are in a different window on the mac system 
 984                 if ( parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE 
) 
 985                     && parent
->m_backgroundColour 
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) ) 
 987                     // if we have any other colours in the hierarchy 
 988                     m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour 
) ; 
 991                 // if we have the normal colours in the hierarchy but another control etc. -> use it's background 
 992                 if ( parent
->IsKindOf( CLASSINFO( wxNotebook 
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl 
) )) 
 994                     Rect extent 
= { 0 , 0 , 0 , 0 } ; 
 997                     wxSize size 
= parent
->GetSize() ; 
 998                     parent
->MacClientToRootWindow( &x 
, &y 
) ; 
1002                     extent
.right 
= x 
+ size
.x 
; 
1003                     extent
.bottom 
= y 
+ size
.y 
; 
1004                     m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane 
, (WXRECTPTR
) &extent 
) ; // todo eventually change for inactive 
1008             parent 
= parent
->GetParent() ; 
1012             m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive 
) ; // todo eventually change for inactive 
1017         m_macBackgroundBrush
.SetColour( m_backgroundColour 
) ; 
1020     return m_macBackgroundBrush 
; 
1023 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
) 
1025     event
.GetDC()->Clear() ; 
1028 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event 
) 
1030     wxWindowDC 
dc(this) ; 
1031     wxMacPortSetter 
helper(&dc
) ; 
1033     MacPaintBorders( dc
.m_macLocalOrigin
.x 
, dc
.m_macLocalOrigin
.y
) ; 
1036 int wxWindowMac::GetScrollPos(int orient
) const 
1038     if ( orient 
== wxHORIZONTAL 
) 
1041            return m_hScrollBar
->GetThumbPosition() ; 
1046            return m_vScrollBar
->GetThumbPosition() ; 
1051 // This now returns the whole range, not just the number 
1052 // of positions that we can scroll. 
1053 int wxWindowMac::GetScrollRange(int orient
) const 
1055     if ( orient 
== wxHORIZONTAL 
) 
1058            return m_hScrollBar
->GetRange() ; 
1063            return m_vScrollBar
->GetRange() ; 
1068 int wxWindowMac::GetScrollThumb(int orient
) const 
1070     if ( orient 
== wxHORIZONTAL 
) 
1073            return m_hScrollBar
->GetThumbSize() ; 
1078            return m_vScrollBar
->GetThumbSize() ; 
1083 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
) 
1085     if ( orient 
== wxHORIZONTAL 
) 
1088            m_hScrollBar
->SetThumbPosition( pos 
) ; 
1093            m_vScrollBar
->SetThumbPosition( pos 
) ; 
1097 void wxWindowMac::MacPaintBorders( int left 
, int top 
) 
1103     wxGetOsVersion( &major
, &minor 
); 
1105     RGBColor white 
= { 0xFFFF, 0xFFFF , 0xFFFF } ; 
1106     RGBColor face 
= { 0xDDDD, 0xDDDD , 0xDDDD } ; 
1108     RGBColor darkShadow 
= { 0x0000, 0x0000 , 0x0000 } ; 
1109     RGBColor lightShadow 
= { 0x4444, 0x4444 , 0x4444 } ; 
1110     // OS X has lighter border edges than classic: 
1113         darkShadow
.red      
= 0x8E8E; 
1114         darkShadow
.green    
= 0x8E8E; 
1115         darkShadow
.blue     
= 0x8E8E; 
1116         lightShadow
.red     
= 0xBDBD; 
1117         lightShadow
.green   
= 0xBDBD; 
1118         lightShadow
.blue    
= 0xBDBD; 
1123     if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) ) 
1125 #if wxMAC_USE_THEME_BORDER 
1126         Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1129         GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; 
1130         InsetRect( &rect , border , border ); 
1131         DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; 
1134         DrawThemePrimaryGroup(&rect  
,IsEnabled() ? kThemeStateActive 
: kThemeStateInactive
) ; 
1136         bool sunken 
= HasFlag( wxSUNKEN_BORDER 
) ; 
1137         RGBForeColor( &face 
); 
1138         MoveTo( left 
+ 0 , top 
+ m_height 
- 2 ); 
1139         LineTo( left 
+ 0 , top 
+ 0 ); 
1140         LineTo( left 
+ m_width 
- 2 , top 
+ 0 ); 
1142         MoveTo( left 
+ 2 , top 
+ m_height 
- 3 ); 
1143         LineTo( left 
+ m_width 
- 3 , top 
+ m_height 
- 3 ); 
1144         LineTo( left 
+ m_width 
- 3 , top 
+ 2 ); 
1146         RGBForeColor( sunken 
? &face 
: &darkShadow 
); 
1147         MoveTo( left 
+ 0 , top 
+ m_height 
- 1 ); 
1148         LineTo( left 
+ m_width 
- 1 , top 
+ m_height 
- 1 ); 
1149         LineTo( left 
+ m_width 
- 1 , top 
+ 0 ); 
1151         RGBForeColor( sunken 
? &lightShadow 
: &white 
); 
1152         MoveTo( left 
+ 1 , top 
+ m_height 
- 3 ); 
1153         LineTo( left 
+ 1, top 
+ 1 ); 
1154         LineTo( left 
+ m_width 
- 3 , top 
+ 1 ); 
1156         RGBForeColor( sunken 
? &white 
: &lightShadow 
); 
1157         MoveTo( left 
+ 1 , top 
+ m_height 
- 2 ); 
1158         LineTo( left 
+ m_width 
- 2 , top 
+ m_height 
- 2 ); 
1159         LineTo( left 
+ m_width 
- 2 , top 
+ 1 ); 
1161         RGBForeColor( sunken 
? &darkShadow 
: &face 
); 
1162         MoveTo( left 
+ 2 , top 
+ m_height 
- 4 ); 
1163         LineTo( left 
+ 2 , top 
+ 2 ); 
1164         LineTo( left 
+ m_width 
- 4 , top 
+ 2 ); 
1167     else if (HasFlag(wxSIMPLE_BORDER
)) 
1169         Rect rect 
= { top 
, left 
, m_height 
+ top 
, m_width 
+ left 
} ; 
1170         RGBForeColor( &darkShadow 
) ; 
1171         FrameRect( &rect 
) ; 
1175 void wxWindowMac::RemoveChild( wxWindowBase 
*child 
) 
1177     if ( child 
== m_hScrollBar 
) 
1178         m_hScrollBar 
= NULL 
; 
1179     if ( child 
== m_vScrollBar 
) 
1180         m_vScrollBar 
= NULL 
; 
1182     wxWindowBase::RemoveChild( child 
) ; 
1185 // New function that will replace some of the above. 
1186 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
, 
1187     int range
, bool refresh
) 
1189     if ( orient 
== wxHORIZONTAL 
) 
1193             if ( range 
== 0 || thumbVisible 
>= range 
) 
1195                 if ( m_hScrollBar
->IsShown() ) 
1196                     m_hScrollBar
->Show(false) ; 
1200                 if ( !m_hScrollBar
->IsShown() ) 
1201                     m_hScrollBar
->Show(true) ; 
1202                 m_hScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1210             if ( range 
== 0 || thumbVisible 
>= range 
) 
1212                 if ( m_vScrollBar
->IsShown() ) 
1213                     m_vScrollBar
->Show(false) ; 
1217                 if ( !m_vScrollBar
->IsShown() ) 
1218                     m_vScrollBar
->Show(true) ; 
1219                 m_vScrollBar
->SetScrollbar( pos 
, thumbVisible 
, range 
, thumbVisible 
, refresh 
) ; 
1223     MacRepositionScrollBars() ; 
1226 // Does a physical scroll 
1227 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
1229     if( dx 
== 0 && dy 
==0 ) 
1234         wxClientDC 
dc(this) ; 
1235         wxMacPortSetter 
helper(&dc
) ; 
1237         int width 
, height 
; 
1238         GetClientSize( &width 
, &height 
) ; 
1240         Rect scrollrect 
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ; 
1241         RgnHandle updateRgn 
= NewRgn() ; 
1242         ClipRect( &scrollrect 
) ; 
1245             Rect r 
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y 
+ rect
->height
) , 
1246                 dc
.XLOG2DEVMAC(rect
->x 
+ rect
->width
) } ; 
1247             SectRect( &scrollrect 
, &r 
, &scrollrect 
) ; 
1249         ScrollRect( &scrollrect 
, dx 
, dy 
, updateRgn 
) ; 
1250         // we also have to scroll the update rgn in this rectangle 
1251         // in order not to loose updates 
1252         WindowRef rootWindow 
= (WindowRef
) MacGetRootWindow() ; 
1253         RgnHandle formerUpdateRgn 
= NewRgn() ; 
1254         RgnHandle scrollRgn 
= NewRgn() ; 
1255         RectRgn( scrollRgn 
, &scrollrect 
) ; 
1256         GetWindowUpdateRgn( rootWindow 
, formerUpdateRgn 
) ; 
1258         LocalToGlobal( &pt 
) ; 
1259         OffsetRgn( formerUpdateRgn 
, -pt
.h 
, -pt
.v 
) ; 
1260         SectRgn( formerUpdateRgn 
, scrollRgn 
, formerUpdateRgn 
) ; 
1261         if ( !EmptyRgn( formerUpdateRgn 
) ) 
1263             MacOffsetRgn( formerUpdateRgn 
, dx 
, dy 
) ; 
1264             SectRgn( formerUpdateRgn 
, scrollRgn 
, formerUpdateRgn 
) ; 
1265             InvalWindowRgn(rootWindow  
,  formerUpdateRgn 
) ; 
1267         InvalWindowRgn(rootWindow  
,  updateRgn 
) ; 
1268         DisposeRgn( updateRgn 
) ; 
1269         DisposeRgn( formerUpdateRgn 
) ; 
1270         DisposeRgn( scrollRgn 
) ; 
1273     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1275         wxWindowMac 
*child 
= node
->GetData(); 
1276         if (child 
== m_vScrollBar
) continue; 
1277         if (child 
== m_hScrollBar
) continue; 
1278         if (child
->IsTopLevel()) continue; 
1281         child
->GetPosition( &x
, &y 
); 
1283         child
->GetSize( &w
, &h 
); 
1287             if (rect
->Intersects(rc
)) 
1288                 child
->SetSize( x
+dx
, y
+dy
, w
, h 
); 
1292             child
->SetSize( x
+dx
, y
+dy
, w
, h 
); 
1300 void wxWindowMac::MacOnScroll(wxScrollEvent 
&event 
) 
1302     if ( event
.GetEventObject() == m_vScrollBar 
|| event
.GetEventObject() == m_hScrollBar 
) 
1304         wxScrollWinEvent wevent
; 
1305         wevent
.SetPosition(event
.GetPosition()); 
1306         wevent
.SetOrientation(event
.GetOrientation()); 
1307         wevent
.SetEventObject(this); 
1309         if (event
.GetEventType() == wxEVT_SCROLL_TOP
) 
1310             wevent
.SetEventType( wxEVT_SCROLLWIN_TOP 
); 
1311         else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
) 
1312             wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM 
); 
1313         else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
) 
1314             wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP 
); 
1315         else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
) 
1316             wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN 
); 
1317         else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
) 
1318             wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP 
); 
1319         else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
) 
1320             wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN 
); 
1321         else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) 
1322             wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK 
); 
1323         else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
) 
1324             wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE 
); 
1326         GetEventHandler()->ProcessEvent(wevent
); 
1330 // Get the window with the focus 
1331 wxWindowMac 
*wxWindowBase::DoFindFocus() 
1333     return gFocusWindow 
; 
1336 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
) 
1338     // panel wants to track the window which was the last to have focus in it, 
1339     // so we want to set ourselves as the window which last had focus 
1341     // notice that it's also important to do it upwards the tree becaus 
1342     // otherwise when the top level panel gets focus, it won't set it back to 
1343     // us, but to some other sibling 
1345     // CS:don't know if this is still needed: 
1346     //wxChildFocusEvent eventFocus(this); 
1347     //(void)GetEventHandler()->ProcessEvent(eventFocus); 
1352 // Setup background and foreground colours correctly 
1353 void wxWindowMac::SetupColours() 
1356         SetBackgroundColour(GetParent()->GetBackgroundColour()); 
1359 void wxWindowMac::OnInternalIdle() 
1361     // This calls the UI-update mechanism (querying windows for 
1362     // menu/toolbar/control state information) 
1363     if (wxUpdateUIEvent::CanUpdate(this)) 
1364         UpdateWindowUI(wxUPDATE_UI_FROMIDLE
); 
1367 // Raise the window to the top of the Z order 
1368 void wxWindowMac::Raise() 
1372 // Lower the window to the bottom of the Z order 
1373 void wxWindowMac::Lower() 
1377 void wxWindowMac::DoSetClientSize(int width
, int height
) 
1379     if ( width 
!= -1 || height 
!= -1 ) 
1382         if ( width 
!= -1 && m_vScrollBar 
) 
1383             width 
+= MAC_SCROLLBAR_SIZE 
; 
1384         if ( height 
!= -1 && m_vScrollBar 
) 
1385             height 
+= MAC_SCROLLBAR_SIZE 
; 
1387         width 
+= MacGetLeftBorderSize(  ) + MacGetRightBorderSize( ) ; 
1388         height 
+= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ) ; 
1390         DoSetSize( -1 , -1 , width 
, height 
) ; 
1395 wxWindowMac
* wxWindowMac::s_lastMouseWindow 
= NULL 
; 
1397 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint 
&point 
, wxWindowMac
** outWin 
) 
1401         if ((point
.x 
< 0) || (point
.y 
< 0) || 
1402             (point
.x 
> (m_width
)) || (point
.y 
> (m_height
))) 
1407         if ((point
.x 
< m_x
) || (point
.y 
< m_y
) || 
1408             (point
.x 
> (m_x 
+ m_width
)) || (point
.y 
> (m_y 
+ m_height
))) 
1412     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1414     wxPoint 
newPoint( point 
) ; 
1416     if ( !IsTopLevel() ) 
1422     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1424         wxWindowMac 
*child 
= node
->GetData(); 
1425         // added the m_isShown test --dmazzoni 
1426         if ( child
->MacGetRootWindow() == (WXWindow
) window 
&& child
->m_isShown 
) 
1428             if (child
->MacGetWindowFromPointSub(newPoint 
, outWin 
)) 
1437 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint 
&screenpoint 
, wxWindowMac
** outWin 
) 
1441     Point pt 
= { screenpoint
.y 
, screenpoint
.x 
} ; 
1442     if ( ::FindWindow( pt 
, &window 
) == 3 ) 
1445         wxWindowMac
* win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
1448             // No, this yields the CLIENT are, we need the whole frame. RR. 
1449             // point = win->ScreenToClient( point ) ; 
1452             ::GetPort( &port 
) ; 
1453             ::SetPort( UMAGetWindowPort( window 
) ) ; 
1454             ::GlobalToLocal( &pt 
) ; 
1457             wxPoint 
point( pt
.h
, pt
.v 
) ; 
1459             return win
->MacGetWindowFromPointSub( point 
, outWin 
) ; 
1465 static wxWindow 
*gs_lastWhich 
= NULL
; 
1467 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
) 
1469     // first trigger a set cursor event 
1471     wxPoint clientorigin 
= GetClientAreaOrigin() ; 
1472     wxSize clientsize 
= GetClientSize() ; 
1474     if ( wxRect2DInt( clientorigin
.x 
, clientorigin
.y 
, clientsize
.x 
, clientsize
.y 
).Contains( wxPoint2DInt( pt 
) ) ) 
1476         wxSetCursorEvent 
event( pt
.x 
, pt
.y 
); 
1478         bool processedEvtSetCursor 
= GetEventHandler()->ProcessEvent(event
); 
1479         if ( processedEvtSetCursor 
&& event
.HasCursor() ) 
1481             cursor 
= event
.GetCursor() ; 
1486             // the test for processedEvtSetCursor is here to prevent using m_cursor 
1487             // if the user code caught EVT_SET_CURSOR() and returned nothing from 
1488             // it - this is a way to say that our cursor shouldn't be used for this 
1490             if ( !processedEvtSetCursor 
&& m_cursor
.Ok() ) 
1500                     cursor 
= *wxSTANDARD_CURSOR  
; 
1504             cursor
.MacInstall() ; 
1506     return cursor
.Ok() ; 
1509 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
) 
1511     if ((event
.m_x 
< m_x
) || (event
.m_y 
< m_y
) || 
1512         (event
.m_x 
> (m_x 
+ m_width
)) || (event
.m_y 
> (m_y 
+ m_height
))) 
1516     if ( IsKindOf( CLASSINFO ( wxStaticBox 
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */) 
1519     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1527     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1529         wxWindowMac 
*child 
= node
->GetData(); 
1530         if ( child
->MacGetRootWindow() == (WXWindow
) window 
&& child
->IsShown() && child
->IsEnabled() ) 
1532             if (child
->MacDispatchMouseEvent(event
)) 
1537     wxWindow
* cursorTarget 
= this ; 
1538     wxPoint 
cursorPoint( x 
, y 
) ; 
1540     while( cursorTarget 
&& !cursorTarget
->MacSetupCursor( cursorPoint 
) ) 
1542         cursorTarget 
= cursorTarget
->GetParent() ; 
1544             cursorPoint 
+= cursorTarget
->GetPosition() ; 
1548     event
.SetEventObject( this ) ; 
1550     if ( event
.GetEventType() == wxEVT_LEFT_DOWN 
) 
1552         // set focus to this window 
1553         if (AcceptsFocus() && FindFocus()!=this) 
1558     if ( event
.GetEventType() == wxEVT_MOTION
 
1559         || event
.GetEventType() == wxEVT_ENTER_WINDOW
 
1560         || event
.GetEventType() == wxEVT_LEAVE_WINDOW 
) 
1561         wxToolTip::RelayEvent( this , event
); 
1562 #endif // wxUSE_TOOLTIPS 
1564     if (gs_lastWhich 
!= this) 
1566         gs_lastWhich 
= this; 
1568         // Double clicks must always occur on the same window 
1569         if (event
.GetEventType() == wxEVT_LEFT_DCLICK
) 
1570             event
.SetEventType( wxEVT_LEFT_DOWN 
); 
1571         if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) 
1572             event
.SetEventType( wxEVT_RIGHT_DOWN 
); 
1574         // Same for mouse up events 
1575         if (event
.GetEventType() == wxEVT_LEFT_UP
) 
1577         if (event
.GetEventType() == wxEVT_RIGHT_UP
) 
1581     GetEventHandler()->ProcessEvent( event 
) ; 
1586 wxString 
wxWindowMac::MacGetToolTipString( wxPoint 
&pt 
) 
1590         return m_tooltip
->GetTip() ; 
1592     return wxEmptyString 
; 
1595 void wxWindowMac::Update() 
1597     wxRegion visRgn 
= MacGetVisibleRegion( false ) ; 
1598     int top 
= 0 , left 
= 0 ; 
1599     MacWindowToRootWindow( &left 
, &top 
) ; 
1600     WindowRef rootWindow 
= (WindowRef
) MacGetRootWindow() ; 
1601     RgnHandle updateRgn 
= NewRgn() ; 
1602     // getting the update region in macos local coordinates 
1603     GetWindowUpdateRgn( rootWindow 
, updateRgn 
) ; 
1605     ::GetPort( &port 
) ; 
1606     ::SetPort( UMAGetWindowPort( rootWindow 
) ) ; 
1608     LocalToGlobal( &pt 
) ; 
1610     OffsetRgn( updateRgn 
, -pt
.h 
, -pt
.v 
) ; 
1611     // translate to window local coordinates 
1612     OffsetRgn( updateRgn 
, -left 
, -top 
) ; 
1613     SectRgn( updateRgn 
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn 
) ; 
1614     MacRedraw( updateRgn 
, 0 , true ) ; 
1615     // for flushing and validating we need macos-local coordinates again 
1616     OffsetRgn( updateRgn 
, left 
, top 
) ; 
1617 #if TARGET_API_MAC_CARBON 
1618     if ( QDIsPortBuffered( GetWindowPort( rootWindow 
) ) ) 
1620         QDFlushPortBuffer( GetWindowPort( rootWindow 
) , updateRgn 
) ; 
1623     ValidWindowRgn( rootWindow 
, updateRgn 
) ; 
1624     DisposeRgn( updateRgn 
) ; 
1627 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const 
1629     wxTopLevelWindowMac
* win 
= NULL 
; 
1630     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1633         win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
1638 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings 
) 
1640     RgnHandle visRgn 
= NewRgn() ; 
1641     RgnHandle tempRgn 
= NewRgn() ; 
1642     RgnHandle tempStaticBoxRgn 
= NewRgn() ; 
1644     if ( MacIsReallyShown() ) 
1646         SetRectRgn( visRgn 
, 0 , 0 , m_width 
, m_height 
) ; 
1648         //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox 
1649         if ( IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1651             int borderTop 
= 14 ; 
1652             int borderOther 
= 4 ; 
1653             if ( UMAGetSystemVersion() >= 0x1030 ) 
1656             SetRectRgn( tempStaticBoxRgn 
, borderOther 
, borderTop 
, m_width 
- borderOther 
, m_height 
- borderOther 
) ; 
1657             DiffRgn( visRgn 
, tempStaticBoxRgn 
, visRgn 
) ; 
1660         if ( !IsTopLevel() ) 
1662             wxWindow
* parent 
= GetParent() ; 
1665                 wxSize size 
= parent
->GetSize() ; 
1668                 parent
->MacWindowToRootWindow( &x
, &y 
) ; 
1669                 MacRootWindowToWindow( &x 
, &y 
) ; 
1671                 SetRectRgn( tempRgn 
, 
1672                     x 
+ parent
->MacGetLeftBorderSize() , y 
+ parent
->MacGetTopBorderSize() , 
1673                     x 
+ size
.x 
- parent
->MacGetRightBorderSize(), 
1674                     y 
+ size
.y 
- parent
->MacGetBottomBorderSize()) ; 
1676                 SectRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1677                 if ( parent
->IsTopLevel() ) 
1679                 parent 
= parent
->GetParent() ; 
1682         if ( respectChildrenAndSiblings 
) 
1684             if ( GetWindowStyle() & wxCLIP_CHILDREN 
) 
1686                 for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1688                     wxWindowMac 
*child 
= node
->GetData(); 
1690                     if ( !child
->IsTopLevel() && child
->IsShown() ) 
1692                         SetRectRgn( tempRgn 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1693                         if ( child
->IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1695                             int borderTop 
= 14 ; 
1696                             int borderOther 
= 4 ; 
1697                             if ( UMAGetSystemVersion() >= 0x1030 ) 
1700                             SetRectRgn( tempStaticBoxRgn 
, child
->m_x 
+ borderOther 
, child
->m_y 
+ borderTop 
, child
->m_x 
+ child
->m_width 
- borderOther 
, child
->m_y 
+ child
->m_height 
- borderOther 
) ; 
1701                             DiffRgn( tempRgn 
, tempStaticBoxRgn 
, tempRgn 
) ; 
1703                         DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1708             if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() ) 
1710                 bool thisWindowThrough 
= false ; 
1711                 for (wxWindowListNode 
*node 
= GetParent()->GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1713                     wxWindowMac 
*sibling 
= node
->GetData(); 
1714                     if ( sibling 
== this ) 
1716                         thisWindowThrough 
= true ; 
1719                     if( !thisWindowThrough 
) 
1724                     if ( !sibling
->IsTopLevel() && sibling
->IsShown() ) 
1726                         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 
) ; 
1727                         if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox 
) ) ) 
1729                             int borderTop 
= 14 ; 
1730                             int borderOther 
= 4 ; 
1731                             if ( UMAGetSystemVersion() >= 0x1030 ) 
1734                             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 
) ; 
1735                             DiffRgn( tempRgn 
, tempStaticBoxRgn 
, tempRgn 
) ; 
1737                         DiffRgn( visRgn 
, tempRgn 
, visRgn 
) ; 
1743     m_macVisibleRegion 
= visRgn 
; 
1744     DisposeRgn( visRgn 
) ; 
1745     DisposeRgn( tempRgn 
) ; 
1746     DisposeRgn( tempStaticBoxRgn 
) ; 
1747     return m_macVisibleRegion 
; 
1750 void wxWindowMac::MacRedraw( WXHRGN updatergnr 
, long time
, bool erase
) 
1752     RgnHandle updatergn 
= (RgnHandle
) updatergnr 
; 
1753     // updatergn is always already clipped to our boundaries 
1754     // it is in window coordinates, not in client coordinates 
1756     WindowRef window 
= (WindowRef
) MacGetRootWindow() ; 
1759         // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates 
1760         RgnHandle ownUpdateRgn 
= NewRgn() ; 
1761         CopyRgn( updatergn 
, ownUpdateRgn 
) ; 
1763         SectRgn( ownUpdateRgn 
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn 
) ; 
1765         // newupdate is the update region in client coordinates 
1766         RgnHandle newupdate 
= NewRgn() ; 
1767         wxSize point 
= GetClientSize() ; 
1768         wxPoint origin 
= GetClientAreaOrigin() ; 
1769         SetRectRgn( newupdate 
, origin
.x 
, origin
.y 
, origin
.x 
+ point
.x 
, origin
.y
+point
.y 
) ; 
1770         SectRgn( newupdate 
, ownUpdateRgn 
, newupdate 
) ; 
1771         OffsetRgn( newupdate 
, -origin
.x 
, -origin
.y 
) ; 
1772         m_updateRegion 
= newupdate 
; 
1773         DisposeRgn( newupdate 
) ; // it's been cloned to m_updateRegion 
1775         if ( erase 
&& !EmptyRgn(ownUpdateRgn
) ) 
1777             wxWindowDC 
dc(this); 
1778             if (!EmptyRgn(ownUpdateRgn
)) 
1779                 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
)); 
1780             wxEraseEvent 
eevent( GetId(), &dc 
); 
1781             eevent
.SetEventObject( this ); 
1782             GetEventHandler()->ProcessEvent( eevent 
); 
1784             wxNcPaintEvent 
eventNc( GetId() ); 
1785             eventNc
.SetEventObject( this ); 
1786             GetEventHandler()->ProcessEvent( eventNc 
); 
1788         DisposeRgn( ownUpdateRgn 
) ; 
1789         if ( !m_updateRegion
.Empty() ) 
1791             wxWindowList hiddenWindows 
; 
1792             for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1794                 wxControl 
*child 
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl 
) ; 
1796                 if ( child 
&& child
->MacGetRootWindow() == (WXWindow
) window 
&& child
->IsShown() && child
->GetMacControl() ) 
1798                     SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ; 
1799                     hiddenWindows
.Append( child 
) ; 
1804             event
.SetTimestamp(time
); 
1805             event
.SetEventObject(this); 
1806             GetEventHandler()->ProcessEvent(event
); 
1808             for (wxWindowListNode 
*node 
= hiddenWindows
.GetFirst(); node
; node 
= node
->GetNext()) 
1810                 wxControl 
*child 
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl 
) ; 
1812                 if ( child 
&& child
->GetMacControl() ) 
1814                     SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ; 
1820     // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively 
1822     RgnHandle childupdate 
= NewRgn() ; 
1823     for (wxWindowListNode 
*node 
= GetChildren().GetFirst(); node
; node 
= node
->GetNext()) 
1825         // calculate the update region for the child windows by intersecting the window rectangle with our own 
1826         // passed in update region and then offset it to be client-wise window coordinates again 
1827         wxWindowMac 
*child 
= node
->GetData(); 
1828         SetRectRgn( childupdate 
, child
->m_x 
, child
->m_y 
, child
->m_x 
+ child
->m_width 
,  child
->m_y 
+ child
->m_height 
) ; 
1829         SectRgn( childupdate 
, updatergn 
, childupdate 
) ; 
1830         OffsetRgn( childupdate 
, -child
->m_x 
, -child
->m_y 
) ; 
1831         if ( child
->MacGetRootWindow() == (WXWindow
) window 
&& child
->IsShown() && !EmptyRgn( childupdate 
) ) 
1833             // because dialogs may also be children 
1834             child
->MacRedraw( childupdate 
, time 
, erase 
) ; 
1837     DisposeRgn( childupdate 
) ; 
1838     // eventually a draw grow box here 
1842 WXWindow 
wxWindowMac::MacGetRootWindow() const 
1844     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1848         if ( iter
->IsTopLevel() ) 
1849             return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ; 
1851         iter 
= iter
->GetParent() ; 
1853     wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; 
1857 void wxWindowMac::MacCreateScrollBars( long style 
) 
1859     wxASSERT_MSG( m_vScrollBar 
== NULL 
&& m_hScrollBar 
== NULL 
, wxT("attempt to create window twice") ) ; 
1861     bool hasBoth 
= ( style 
& wxVSCROLL 
) && ( style 
& wxHSCROLL 
) ; 
1862     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1: 0 ; 
1864     GetClientSize( &width 
, &height 
) ; 
1866     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1867     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1868     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1869     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1871     m_vScrollBar 
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
, 
1872         vSize 
, wxVERTICAL
); 
1874     if ( style 
& wxVSCROLL 
) 
1880         m_vScrollBar
->Show(false) ; 
1882     m_hScrollBar 
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
, 
1883         hSize 
, wxHORIZONTAL
); 
1884     if ( style  
& wxHSCROLL 
) 
1889         m_hScrollBar
->Show(false) ; 
1892     // because the create does not take into account the client area origin 
1893     MacRepositionScrollBars() ; // we might have a real position shift 
1896 void wxWindowMac::MacRepositionScrollBars() 
1898     bool hasBoth 
= ( m_hScrollBar 
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar 
&& m_vScrollBar
->IsShown()) ; 
1899     int adjust 
= hasBoth 
? MAC_SCROLLBAR_SIZE 
- 1 : 0 ; 
1901     // get real client area 
1903     int width 
= m_width 
; 
1904     int height 
= m_height 
; 
1906     width 
-= MacGetLeftBorderSize() + MacGetRightBorderSize(); 
1907     height 
-= MacGetTopBorderSize() + MacGetBottomBorderSize(); 
1909     wxPoint 
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ; 
1910     wxSize 
vSize(MAC_SCROLLBAR_SIZE
, height 
- adjust
) ; 
1911     wxPoint 
hPoint(0 , height
-MAC_SCROLLBAR_SIZE 
) ; 
1912     wxSize 
hSize( width 
- adjust
, MAC_SCROLLBAR_SIZE
) ; 
1919     MacClientToRootWindow( &x 
, &y 
) ; 
1920     MacClientToRootWindow( &w 
, &h 
) ; 
1922     wxWindowMac 
*iter 
= (wxWindowMac
*)this ; 
1924     int totW 
= 10000 , totH 
= 10000; 
1927         if ( iter
->IsTopLevel() ) 
1929             totW 
= iter
->m_width 
; 
1930             totH 
= iter
->m_height 
; 
1934         iter 
= iter
->GetParent() ; 
1962         m_vScrollBar
->SetSize( vPoint
.x 
, vPoint
.y
, vSize
.x
, vSize
.y 
, wxSIZE_ALLOW_MINUS_ONE
); 
1966         m_hScrollBar
->SetSize( hPoint
.x 
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
); 
1970 bool wxWindowMac::AcceptsFocus() const 
1972     return MacCanFocus() && wxWindowBase::AcceptsFocus(); 
1975 WXWidget 
wxWindowMac::MacGetContainerForEmbedding() 
1977     return GetParent()->MacGetContainerForEmbedding() ; 
1980 void wxWindowMac::MacSuperChangedPosition() 
1982     // only window-absolute structures have to be moved i.e. controls 
1984     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
1987         wxWindowMac 
*child 
= node
->GetData(); 
1988         child
->MacSuperChangedPosition() ; 
1989         node 
= node
->GetNext(); 
1993 void wxWindowMac::MacTopLevelWindowChangedPosition() 
1995     // only screen-absolute structures have to be moved i.e. glcanvas 
1997     wxWindowListNode 
*node 
= GetChildren().GetFirst(); 
2000         wxWindowMac 
*child 
= node
->GetData(); 
2001         child
->MacTopLevelWindowChangedPosition() ; 
2002         node 
= node
->GetNext(); 
2005 long wxWindowMac::MacGetLeftBorderSize( ) const 
2010     if (m_windowStyle 
& wxRAISED_BORDER 
|| m_windowStyle 
& wxSUNKEN_BORDER 
) 
2013 #if wxMAC_USE_THEME_BORDER 
2015           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
2020     else if (  m_windowStyle 
&wxDOUBLE_BORDER
) 
2023 #if wxMAC_USE_THEME_BORDER 
2025           GetThemeMetric( kThemeMetricListBoxFrameOutset 
, &border 
) ; 
2030     else if (m_windowStyle 
&wxSIMPLE_BORDER
) 
2037 long wxWindowMac::MacGetRightBorderSize( ) const 
2039     // they are all symmetric in mac themes 
2040     return MacGetLeftBorderSize() ; 
2043 long wxWindowMac::MacGetTopBorderSize( ) const 
2045     // they are all symmetric in mac themes 
2046     return MacGetLeftBorderSize() ; 
2049 long wxWindowMac::MacGetBottomBorderSize( ) const 
2051     // they are all symmetric in mac themes 
2052     return MacGetLeftBorderSize() ; 
2055 long wxWindowMac::MacRemoveBordersFromStyle( long style 
) 
2057     return style 
& ~( wxDOUBLE_BORDER 
| wxSUNKEN_BORDER 
| wxRAISED_BORDER 
| wxBORDER 
| wxSTATIC_BORDER 
) ; 
2060 // Find the wxWindowMac at the current mouse position, returning the mouse 
2062 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
) 
2064     pt 
= wxGetMousePosition(); 
2065     wxWindowMac
* found 
= wxFindWindowAtPoint(pt
); 
2069 // Get the current mouse position. 
2070 wxPoint 
wxGetMousePosition() 
2073     wxGetMousePosition(& x
, & y
); 
2074     return wxPoint(x
, y
); 
2077 void wxWindowMac::OnMouseEvent( wxMouseEvent 
&event 
) 
2079     if ( event
.GetEventType() == wxEVT_RIGHT_DOWN 
) 
2081         // copied from wxGTK : CS 
2082         // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN 
2085         // (a) it's a command event and so is propagated to the parent 
2086         // (b) under MSW it can be generated from kbd too 
2087         // (c) it uses screen coords (because of (a)) 
2088         wxContextMenuEvent 
evtCtx(wxEVT_CONTEXT_MENU
, 
2090                                   this->ClientToScreen(event
.GetPosition())); 
2091         if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )