1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/window.h"
16 #include "wx/dcclient.h"
20 #include "wx/layout.h"
21 #include "wx/dialog.h"
22 #include "wx/listbox.h"
23 #include "wx/scrolbar.h"
24 #include "wx/statbox.h"
25 #include "wx/button.h"
26 #include "wx/settings.h"
27 #include "wx/msgdlg.h"
29 #include "wx/notebook.h"
30 #include "wx/tabctrl.h"
31 #include "wx/tooltip.h"
32 #include "wx/statusbr.h"
33 #include "wx/menuitem.h"
34 #include "wx/spinctrl.h"
36 #include "wx/geometry.h"
42 #define wxWINDOW_HSCROLL 5998
43 #define wxWINDOW_VSCROLL 5997
44 #define MAC_SCROLLBAR_SIZE 16
46 #include "wx/mac/uma.h"
49 #include <ToolUtils.h>
52 #if wxUSE_DRAG_AND_DROP
58 extern wxList wxPendingDelete
;
59 wxWindowMac
* gFocusWindow
= NULL
;
61 #ifdef __WXUNIVERSAL__
62 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
64 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
65 #endif // __WXUNIVERSAL__/__WXMAC__
67 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
68 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
69 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
70 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
71 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
74 #define wxMAC_DEBUG_REDRAW 0
75 #ifndef wxMAC_DEBUG_REDRAW
76 #define wxMAC_DEBUG_REDRAW 0
79 #define wxMAC_USE_THEME_BORDER 0
82 // ===========================================================================
84 // ===========================================================================
87 // ----------------------------------------------------------------------------
88 // constructors and such
89 // ----------------------------------------------------------------------------
91 void wxWindowMac::Init()
93 m_backgroundTransparent
= FALSE
;
95 // as all windows are created with WS_VISIBLE style...
103 m_hScrollBar
= NULL
;
104 m_vScrollBar
= NULL
;
108 wxWindowMac::~wxWindowMac()
112 // deleting a window while it is shown invalidates the region
114 wxWindowMac
* iter
= this ;
116 if ( iter
->IsTopLevel() )
121 iter
= iter
->GetParent() ;
126 m_isBeingDeleted
= TRUE
;
128 #ifndef __WXUNIVERSAL__
129 // VS: make sure there's no wxFrame with last focus set to us:
130 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
132 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
135 if ( frame
->GetLastFocus() == this )
137 frame
->SetLastFocus((wxWindow
*)NULL
);
142 #endif // __WXUNIVERSAL__
144 if ( s_lastMouseWindow
== this )
146 s_lastMouseWindow
= NULL
;
149 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
152 if ( frame
->GetLastFocus() == this )
153 frame
->SetLastFocus( NULL
) ;
156 if ( gFocusWindow
== this )
158 gFocusWindow
= NULL
;
163 // delete our drop target if we've got one
164 #if wxUSE_DRAG_AND_DROP
165 if ( m_dropTarget
!= NULL
)
170 #endif // wxUSE_DRAG_AND_DROP
174 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
178 const wxString
& name
)
180 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
183 // wxGTK doesn't allow to create controls with static box as the parent so
184 // this will result in a crash when the program is ported to wxGTK - warn
187 // the correct solution is to create the controls as siblings of the
189 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
190 _T("wxStaticBox can't be used as a window parent!") );
191 #endif // wxUSE_STATBOX
193 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
196 parent
->AddChild(this);
200 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
201 m_width
= WidthDefault( size
.x
);
202 m_height
= HeightDefault( size
.y
) ;
203 #ifndef __WXUNIVERSAL__
204 // Don't give scrollbars to wxControls unless they ask for them
205 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
206 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
208 MacCreateScrollBars( style
) ;
212 wxWindowCreateEvent
event(this);
213 GetEventHandler()->AddPendingEvent(event
);
218 void wxWindowMac::SetFocus()
220 if ( gFocusWindow
== this )
223 if ( AcceptsFocus() )
229 if ( gFocusWindow
->m_caret
)
231 gFocusWindow
->m_caret
->OnKillFocus();
233 #endif // wxUSE_CARET
234 #ifndef __WXUNIVERSAL__
235 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
236 if ( control
&& control
->GetMacControl() )
238 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
239 control
->MacRedrawControl() ;
242 // Without testing the window id, for some reason
243 // a kill focus event can still be sent to
244 // the control just being focussed.
245 int thisId
= this->m_windowId
;
246 int gFocusWindowId
= gFocusWindow
->m_windowId
;
247 if (gFocusWindowId
!= thisId
)
249 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
250 event
.SetEventObject(gFocusWindow
);
251 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
254 gFocusWindow
= this ;
260 m_caret
->OnSetFocus();
262 #endif // wxUSE_CARET
263 // panel wants to track the window which was the last to have focus in it
264 wxChildFocusEvent
eventFocus(this);
265 GetEventHandler()->ProcessEvent(eventFocus
);
267 #ifndef __WXUNIVERSAL__
268 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
269 if ( control
&& control
->GetMacControl() )
271 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
274 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
275 event
.SetEventObject(this);
276 GetEventHandler()->ProcessEvent(event
) ;
281 bool wxWindowMac::Enable(bool enable
)
283 if ( !wxWindowBase::Enable(enable
) )
286 MacSuperEnabled( enable
) ;
291 void wxWindowMac::DoCaptureMouse()
293 wxTheApp
->s_captureWindow
= this ;
296 wxWindow
* wxWindowBase::GetCapture()
298 return wxTheApp
->s_captureWindow
;
301 void wxWindowMac::DoReleaseMouse()
303 wxTheApp
->s_captureWindow
= NULL
;
306 #if wxUSE_DRAG_AND_DROP
308 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
310 if ( m_dropTarget
!= 0 ) {
314 m_dropTarget
= pDropTarget
;
315 if ( m_dropTarget
!= 0 )
323 // Old style file-manager drag&drop
324 void wxWindowMac::DragAcceptFiles(bool accept
)
330 void wxWindowMac::DoGetSize(int *x
, int *y
) const
333 if(y
) *y
= m_height
;
336 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
342 if ( !IsTopLevel() && GetParent())
344 wxPoint
pt(GetParent()->GetClientAreaOrigin());
353 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
355 menu
->SetInvokingWindow(this);
358 if ( x
== -1 && y
== -1 )
360 wxPoint mouse
= wxGetMousePosition();
361 x
= mouse
.x
; y
= mouse
.y
;
365 ClientToScreen( &x
, &y
) ;
368 menu
->MacBeforeDisplay( true ) ;
369 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
370 if ( HiWord(menuResult
) != 0 )
373 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
374 wxMenuItem
* item
= NULL
;
376 item
= menu
->FindItem(id
, &realmenu
) ;
377 if (item
->IsCheckable())
379 item
->Check( !item
->IsChecked() ) ;
381 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
383 menu
->MacAfterDisplay( true ) ;
385 menu
->SetInvokingWindow(NULL
);
391 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
393 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
395 Point localwhere
= {0,0} ;
397 if(x
) localwhere
.h
= * x
;
398 if(y
) localwhere
.v
= * y
;
402 ::SetPort( UMAGetWindowPort( window
) ) ;
403 ::GlobalToLocal( &localwhere
) ;
406 if(x
) *x
= localwhere
.h
;
407 if(y
) *y
= localwhere
.v
;
409 MacRootWindowToWindow( x
, y
) ;
411 *x
-= MacGetLeftBorderSize() ;
413 *y
-= MacGetTopBorderSize() ;
416 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
418 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
421 *x
+= MacGetLeftBorderSize() ;
423 *y
+= MacGetTopBorderSize() ;
425 MacWindowToRootWindow( x
, y
) ;
427 Point localwhere
= { 0,0 };
428 if(x
) localwhere
.h
= * x
;
429 if(y
) localwhere
.v
= * y
;
433 ::SetPort( UMAGetWindowPort( window
) ) ;
435 ::LocalToGlobal( &localwhere
) ;
437 if(x
) *x
= localwhere
.h
;
438 if(y
) *y
= localwhere
.v
;
441 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
443 wxPoint origin
= GetClientAreaOrigin() ;
444 if(x
) *x
+= origin
.x
;
445 if(y
) *y
+= origin
.y
;
447 MacWindowToRootWindow( x
, y
) ;
450 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
452 wxPoint origin
= GetClientAreaOrigin() ;
453 MacRootWindowToWindow( x
, y
) ;
454 if(x
) *x
-= origin
.x
;
455 if(y
) *y
-= origin
.y
;
458 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
464 GetParent()->MacWindowToRootWindow( x
, y
) ;
468 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
474 GetParent()->MacRootWindowToWindow( x
, y
) ;
478 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
480 if (m_cursor
== cursor
)
483 if (wxNullCursor
== cursor
)
485 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
490 if ( ! wxWindowBase::SetCursor( cursor
) )
494 wxASSERT_MSG( m_cursor
.Ok(),
495 wxT("cursor must be valid after call to the base version"));
498 wxWindowMac
*mouseWin
;
501 // Change the cursor NOW if we're within the correct window
503 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
505 if ( mouseWin
== this && !wxIsBusy() )
507 m_cursor
.MacInstall() ;
515 // Get size *available for subwindows* i.e. excluding menu bar etc.
516 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
522 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
523 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
525 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
532 MacClientToRootWindow( &x1
, &y1
) ;
533 MacClientToRootWindow( &w
, &h
) ;
535 wxWindowMac
*iter
= (wxWindowMac
*)this ;
537 int totW
= 10000 , totH
= 10000;
540 if ( iter
->IsTopLevel() )
542 totW
= iter
->m_width
;
543 totH
= iter
->m_height
;
547 iter
= iter
->GetParent() ;
550 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
552 hh
-= MAC_SCROLLBAR_SIZE
;
558 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
560 ww
-= MAC_SCROLLBAR_SIZE
;
572 // ----------------------------------------------------------------------------
574 // ----------------------------------------------------------------------------
578 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
580 wxWindowBase::DoSetToolTip(tooltip
);
583 m_tooltip
->SetWindow(this);
586 #endif // wxUSE_TOOLTIPS
588 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
592 int former_w
= m_width
;
593 int former_h
= m_height
;
595 int actualWidth
= width
;
596 int actualHeight
= height
;
600 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
601 actualWidth
= m_minWidth
;
602 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
603 actualHeight
= m_minHeight
;
604 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
605 actualWidth
= m_maxWidth
;
606 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
607 actualHeight
= m_maxHeight
;
609 bool doMove
= false ;
610 bool doResize
= false ;
612 if ( actualX
!= former_x
|| actualY
!= former_y
)
616 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
621 if ( doMove
|| doResize
)
623 // erase former position
625 bool partialRepaint
= false ;
627 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
629 wxPoint
oldPos( m_x
, m_y
) ;
630 wxPoint
newPos( actualX
, actualY
) ;
631 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
632 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
633 if ( oldPos
== newPos
)
635 partialRepaint
= true ;
636 RgnHandle oldRgn
,newRgn
,diffRgn
;
641 // invalidate the differences between the old and the new area
643 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
644 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
645 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
646 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
647 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
648 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
650 // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really
651 // changing pixels...
653 if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 ||
654 MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 )
656 RgnHandle innerOldRgn
, innerNewRgn
;
657 innerOldRgn
= NewRgn() ;
658 innerNewRgn
= NewRgn() ;
660 SetRectRgn(innerOldRgn
, oldPos
.x
+ MacGetLeftBorderSize() , oldPos
.y
+ MacGetTopBorderSize() ,
661 oldPos
.x
+ m_width
- MacGetRightBorderSize() , oldPos
.y
+ m_height
- MacGetBottomBorderSize() ) ;
662 DiffRgn( oldRgn
, innerOldRgn
, diffRgn
) ;
663 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
665 SetRectRgn(innerNewRgn
, newPos
.x
+ MacGetLeftBorderSize() , newPos
.y
+ MacGetTopBorderSize() ,
666 newPos
.x
+ actualWidth
- MacGetRightBorderSize() , newPos
.y
+ actualHeight
- MacGetBottomBorderSize() ) ;
667 DiffRgn( newRgn
, innerNewRgn
, diffRgn
) ;
668 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
670 DisposeRgn( innerOldRgn
) ;
671 DisposeRgn( innerNewRgn
) ;
676 DisposeRgn(diffRgn
) ;
680 if ( !partialRepaint
)
685 m_width
= actualWidth
;
686 m_height
= actualHeight
;
688 // update any low-level frame-relative positions
690 MacUpdateDimensions() ;
691 // erase new position
693 if ( !partialRepaint
)
696 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
698 MacRepositionScrollBars() ;
701 wxPoint
point(m_x
, m_y
);
702 wxMoveEvent
event(point
, m_windowId
);
703 event
.SetEventObject(this);
704 GetEventHandler()->ProcessEvent(event
) ;
708 MacRepositionScrollBars() ;
709 wxSize
size(m_width
, m_height
);
710 wxSizeEvent
event(size
, m_windowId
);
711 event
.SetEventObject(this);
712 GetEventHandler()->ProcessEvent(event
);
718 // set the size of the window: if the dimensions are positive, just use them,
719 // but if any of them is equal to -1, it means that we must find the value for
720 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
721 // which case -1 is a valid value for x and y)
723 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
724 // the width/height to best suit our contents, otherwise we reuse the current
726 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
728 // get the current size and position...
729 int currentX
, currentY
;
730 GetPosition(¤tX
, ¤tY
);
732 int currentW
,currentH
;
733 GetSize(¤tW
, ¤tH
);
735 // ... and don't do anything (avoiding flicker) if it's already ok
736 if ( x
== currentX
&& y
== currentY
&&
737 width
== currentW
&& height
== currentH
)
739 MacRepositionScrollBars() ; // we might have a real position shift
743 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
745 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
748 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
753 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
755 size
= DoGetBestSize();
760 // just take the current one
767 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
771 size
= DoGetBestSize();
773 //else: already called DoGetBestSize() above
779 // just take the current one
784 DoMoveWindow(x
, y
, width
, height
);
787 // For implementation purposes - sometimes decorations make the client area
790 wxPoint
wxWindowMac::GetClientAreaOrigin() const
792 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
795 void wxWindowMac::SetTitle(const wxString
& title
)
800 wxString
wxWindowMac::GetTitle() const
805 bool wxWindowMac::Show(bool show
)
807 if ( !wxWindowBase::Show(show
) )
810 MacSuperShown( show
) ;
816 void wxWindowMac::MacSuperShown( bool show
)
818 wxWindowListNode
*node
= GetChildren().GetFirst();
821 wxWindowMac
*child
= node
->GetData();
822 if ( child
->m_isShown
)
823 child
->MacSuperShown( show
) ;
824 node
= node
->GetNext();
828 void wxWindowMac::MacSuperEnabled( bool enabled
)
832 // to be absolutely correct we'd have to invalidate (with eraseBkground
833 // because unter MacOSX the frames are drawn with an addXXX mode)
836 wxWindowListNode
*node
= GetChildren().GetFirst();
839 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
840 if ( child
->m_isShown
)
841 child
->MacSuperEnabled( enabled
) ;
842 node
= node
->GetNext();
846 bool wxWindowMac::MacIsReallyShown() const
848 if ( m_isShown
&& (m_parent
!= NULL
&& !IsTopLevel() ) ) {
849 return m_parent
->MacIsReallyShown();
853 bool status = m_isShown ;
854 wxWindowMac * win = this ;
855 while ( status && win->m_parent != NULL )
857 win = win->m_parent ;
858 status = win->m_isShown ;
864 int wxWindowMac::GetCharHeight() const
866 wxClientDC
dc ( (wxWindowMac
*)this ) ;
867 return dc
.GetCharHeight() ;
870 int wxWindowMac::GetCharWidth() const
872 wxClientDC
dc ( (wxWindowMac
*)this ) ;
873 return dc
.GetCharWidth() ;
876 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
877 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
879 const wxFont
*fontToUse
= theFont
;
883 wxClientDC
dc( (wxWindowMac
*) this ) ;
885 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
886 if ( externalLeading
)
887 *externalLeading
= le
;
897 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
898 * we always intersect with the entire window, not only with the client area
901 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
903 if ( MacGetTopLevelWindow() == NULL
)
906 if ( !MacIsReallyShown() )
909 wxPoint client
= GetClientAreaOrigin();
912 int x2
= m_width
- client
.x
;
913 int y2
= m_height
- client
.y
;
915 if (IsKindOf( CLASSINFO(wxButton
)))
917 // buttons have an "aura"
924 Rect clientrect
= { y1
, x1
, y2
, x2
};
928 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
929 SectRect( &clientrect
, &r
, &clientrect
) ;
932 if ( !EmptyRect( &clientrect
) )
934 int top
= 0 , left
= 0 ;
936 MacClientToRootWindow( &left
, &top
) ;
937 OffsetRect( &clientrect
, left
, top
) ;
939 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
943 wxWindowMac
*wxGetActiveWindow()
945 // actually this is a windows-only concept
949 // Coordinates relative to the window
950 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
952 // We really don't move the mouse programmatically under Mac.
955 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
957 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
959 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
961 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
963 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
964 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
965 // either a non gray background color or a non control window
967 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
969 wxWindowMac
* parent
= GetParent() ;
972 if ( parent
->MacGetRootWindow() != (WXWindow
) window
)
974 // we are in a different window on the mac system
980 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
981 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
983 // if we have any other colours in the hierarchy
984 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
987 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
988 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
990 Rect extent
= { 0 , 0 , 0 , 0 } ;
993 wxSize size
= parent
->GetSize() ;
994 parent
->MacClientToRootWindow( &x
, &y
) ;
998 extent
.right
= x
+ size
.x
;
999 extent
.bottom
= y
+ size
.y
;
1000 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1004 parent
= parent
->GetParent() ;
1008 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1013 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1016 return m_macBackgroundBrush
;
1019 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1021 event
.GetDC()->Clear() ;
1024 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1026 wxWindowDC
dc(this) ;
1027 wxMacPortSetter
helper(&dc
) ;
1029 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1032 int wxWindowMac::GetScrollPos(int orient
) const
1034 if ( orient
== wxHORIZONTAL
)
1037 return m_hScrollBar
->GetThumbPosition() ;
1042 return m_vScrollBar
->GetThumbPosition() ;
1047 // This now returns the whole range, not just the number
1048 // of positions that we can scroll.
1049 int wxWindowMac::GetScrollRange(int orient
) const
1051 if ( orient
== wxHORIZONTAL
)
1054 return m_hScrollBar
->GetRange() ;
1059 return m_vScrollBar
->GetRange() ;
1064 int wxWindowMac::GetScrollThumb(int orient
) const
1066 if ( orient
== wxHORIZONTAL
)
1069 return m_hScrollBar
->GetThumbSize() ;
1074 return m_vScrollBar
->GetThumbSize() ;
1079 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1081 if ( orient
== wxHORIZONTAL
)
1084 m_hScrollBar
->SetThumbPosition( pos
) ;
1089 m_vScrollBar
->SetThumbPosition( pos
) ;
1093 void wxWindowMac::MacPaintBorders( int left
, int top
)
1099 wxGetOsVersion( &major
, &minor
);
1101 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1102 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1104 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1105 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1106 // OS X has lighter border edges than classic:
1109 darkShadow
.red
= 0x8E8E;
1110 darkShadow
.green
= 0x8E8E;
1111 darkShadow
.blue
= 0x8E8E;
1112 lightShadow
.red
= 0xBDBD;
1113 lightShadow
.green
= 0xBDBD;
1114 lightShadow
.blue
= 0xBDBD;
1119 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1121 #if wxMAC_USE_THEME_BORDER
1122 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1125 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1126 InsetRect( &rect , border , border );
1127 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1130 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1132 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1133 RGBForeColor( &face
);
1134 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1135 LineTo( left
+ 0 , top
+ 0 );
1136 LineTo( left
+ m_width
- 2 , top
+ 0 );
1138 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1139 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1140 LineTo( left
+ m_width
- 3 , top
+ 2 );
1142 RGBForeColor( sunken
? &face
: &darkShadow
);
1143 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1144 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1145 LineTo( left
+ m_width
- 1 , top
+ 0 );
1147 RGBForeColor( sunken
? &lightShadow
: &white
);
1148 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1149 LineTo( left
+ 1, top
+ 1 );
1150 LineTo( left
+ m_width
- 3 , top
+ 1 );
1152 RGBForeColor( sunken
? &white
: &lightShadow
);
1153 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1154 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1155 LineTo( left
+ m_width
- 2 , top
+ 1 );
1157 RGBForeColor( sunken
? &darkShadow
: &face
);
1158 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1159 LineTo( left
+ 2 , top
+ 2 );
1160 LineTo( left
+ m_width
- 4 , top
+ 2 );
1163 else if (HasFlag(wxSIMPLE_BORDER
))
1165 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1166 RGBForeColor( &darkShadow
) ;
1167 FrameRect( &rect
) ;
1171 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1173 if ( child
== m_hScrollBar
)
1174 m_hScrollBar
= NULL
;
1175 if ( child
== m_vScrollBar
)
1176 m_vScrollBar
= NULL
;
1178 wxWindowBase::RemoveChild( child
) ;
1181 // New function that will replace some of the above.
1182 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1183 int range
, bool refresh
)
1185 if ( orient
== wxHORIZONTAL
)
1189 if ( range
== 0 || thumbVisible
>= range
)
1191 if ( m_hScrollBar
->IsShown() )
1192 m_hScrollBar
->Show(false) ;
1196 if ( !m_hScrollBar
->IsShown() )
1197 m_hScrollBar
->Show(true) ;
1198 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1206 if ( range
== 0 || thumbVisible
>= range
)
1208 if ( m_vScrollBar
->IsShown() )
1209 m_vScrollBar
->Show(false) ;
1213 if ( !m_vScrollBar
->IsShown() )
1214 m_vScrollBar
->Show(true) ;
1215 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1219 MacRepositionScrollBars() ;
1222 // Does a physical scroll
1223 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1225 if( dx
== 0 && dy
==0 )
1230 wxClientDC
dc(this) ;
1231 wxMacPortSetter
helper(&dc
) ;
1233 int width
, height
;
1234 GetClientSize( &width
, &height
) ;
1236 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1237 RgnHandle updateRgn
= NewRgn() ;
1238 ClipRect( &scrollrect
) ;
1241 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1242 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1243 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1245 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1246 // we also have to scroll the update rgn in this rectangle
1247 // in order not to loose updates
1248 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1249 RgnHandle formerUpdateRgn
= NewRgn() ;
1250 RgnHandle scrollRgn
= NewRgn() ;
1251 RectRgn( scrollRgn
, &scrollrect
) ;
1252 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1254 LocalToGlobal( &pt
) ;
1255 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1256 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1257 if ( !EmptyRgn( formerUpdateRgn
) )
1259 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1260 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1261 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1263 InvalWindowRgn(rootWindow
, updateRgn
) ;
1264 DisposeRgn( updateRgn
) ;
1265 DisposeRgn( formerUpdateRgn
) ;
1266 DisposeRgn( scrollRgn
) ;
1269 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1271 wxWindowMac
*child
= node
->GetData();
1272 if (child
== m_vScrollBar
) continue;
1273 if (child
== m_hScrollBar
) continue;
1274 if (child
->IsTopLevel()) continue;
1277 child
->GetPosition( &x
, &y
);
1279 child
->GetSize( &w
, &h
);
1283 if (rect
->Intersects(rc
))
1284 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1288 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1296 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1298 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1300 wxScrollWinEvent wevent
;
1301 wevent
.SetPosition(event
.GetPosition());
1302 wevent
.SetOrientation(event
.GetOrientation());
1303 wevent
.SetEventObject(this);
1305 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1306 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1307 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1308 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1309 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1310 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1311 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1312 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1313 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1314 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1315 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1316 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1317 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1318 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1319 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1320 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1322 GetEventHandler()->ProcessEvent(wevent
);
1326 // Get the window with the focus
1327 wxWindowMac
*wxWindowBase::DoFindFocus()
1329 return gFocusWindow
;
1332 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1334 // panel wants to track the window which was the last to have focus in it,
1335 // so we want to set ourselves as the window which last had focus
1337 // notice that it's also important to do it upwards the tree becaus
1338 // otherwise when the top level panel gets focus, it won't set it back to
1339 // us, but to some other sibling
1341 // CS:don't know if this is still needed:
1342 //wxChildFocusEvent eventFocus(this);
1343 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1348 // Setup background and foreground colours correctly
1349 void wxWindowMac::SetupColours()
1352 SetBackgroundColour(GetParent()->GetBackgroundColour());
1355 void wxWindowMac::OnInternalIdle()
1357 // This calls the UI-update mechanism (querying windows for
1358 // menu/toolbar/control state information)
1359 if (wxUpdateUIEvent::CanUpdate(this))
1360 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1363 // Raise the window to the top of the Z order
1364 void wxWindowMac::Raise()
1368 // Lower the window to the bottom of the Z order
1369 void wxWindowMac::Lower()
1373 void wxWindowMac::DoSetClientSize(int width
, int height
)
1375 if ( width
!= -1 || height
!= -1 )
1378 if ( width
!= -1 && m_vScrollBar
)
1379 width
+= MAC_SCROLLBAR_SIZE
;
1380 if ( height
!= -1 && m_vScrollBar
)
1381 height
+= MAC_SCROLLBAR_SIZE
;
1383 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1384 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1386 DoSetSize( -1 , -1 , width
, height
) ;
1391 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1393 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1397 if ((point
.x
< 0) || (point
.y
< 0) ||
1398 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1403 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1404 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1408 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1410 wxPoint
newPoint( point
) ;
1412 if ( !IsTopLevel() )
1418 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1420 wxWindowMac
*child
= node
->GetData();
1421 // added the m_isShown test --dmazzoni
1422 if ( child
->MacGetRootWindow() == (WXWindow
) window
&& child
->m_isShown
)
1424 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1433 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1437 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1438 if ( ::FindWindow( pt
, &window
) == 3 )
1441 wxWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
1444 // No, this yields the CLIENT are, we need the whole frame. RR.
1445 // point = win->ScreenToClient( point ) ;
1448 ::GetPort( &port
) ;
1449 ::SetPort( UMAGetWindowPort( window
) ) ;
1450 ::GlobalToLocal( &pt
) ;
1453 wxPoint
point( pt
.h
, pt
.v
) ;
1455 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1461 static wxWindow
*gs_lastWhich
= NULL
;
1463 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1465 // first trigger a set cursor event
1467 wxPoint clientorigin
= GetClientAreaOrigin() ;
1468 wxSize clientsize
= GetClientSize() ;
1470 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1472 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1474 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1475 if ( processedEvtSetCursor
&& event
.HasCursor() )
1477 cursor
= event
.GetCursor() ;
1482 // the test for processedEvtSetCursor is here to prevent using m_cursor
1483 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1484 // it - this is a way to say that our cursor shouldn't be used for this
1486 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1496 cursor
= *wxSTANDARD_CURSOR
;
1500 cursor
.MacInstall() ;
1502 return cursor
.Ok() ;
1505 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1507 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1508 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1512 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1515 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1523 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1525 wxWindowMac
*child
= node
->GetData();
1526 if ( child
->MacGetRootWindow() == (WXWindow
) window
&& child
->IsShown() && child
->IsEnabled() )
1528 if (child
->MacDispatchMouseEvent(event
))
1533 wxWindow
* cursorTarget
= this ;
1534 wxPoint
cursorPoint( x
, y
) ;
1536 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1538 cursorTarget
= cursorTarget
->GetParent() ;
1540 cursorPoint
+= cursorTarget
->GetPosition() ;
1544 event
.SetEventObject( this ) ;
1546 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1548 // set focus to this window
1549 if (AcceptsFocus() && FindFocus()!=this)
1554 if ( event
.GetEventType() == wxEVT_MOTION
1555 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1556 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1557 wxToolTip::RelayEvent( this , event
);
1558 #endif // wxUSE_TOOLTIPS
1560 if (gs_lastWhich
!= this)
1562 gs_lastWhich
= this;
1564 // Double clicks must always occur on the same window
1565 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1566 event
.SetEventType( wxEVT_LEFT_DOWN
);
1567 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1568 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1570 // Same for mouse up events
1571 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1573 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1577 GetEventHandler()->ProcessEvent( event
) ;
1582 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1586 return m_tooltip
->GetTip() ;
1588 return wxEmptyString
;
1591 void wxWindowMac::Update()
1593 wxRegion visRgn
= MacGetVisibleRegion( false ) ;
1594 int top
= 0 , left
= 0 ;
1595 MacWindowToRootWindow( &left
, &top
) ;
1596 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1597 RgnHandle updateRgn
= NewRgn() ;
1598 // getting the update region in macos local coordinates
1599 GetWindowUpdateRgn( rootWindow
, updateRgn
) ;
1601 ::GetPort( &port
) ;
1602 ::SetPort( UMAGetWindowPort( rootWindow
) ) ;
1604 LocalToGlobal( &pt
) ;
1606 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
1607 // translate to window local coordinates
1608 OffsetRgn( updateRgn
, -left
, -top
) ;
1609 SectRgn( updateRgn
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn
) ;
1610 MacRedraw( updateRgn
, 0 , true ) ;
1611 // for flushing and validating we need macos-local coordinates again
1612 OffsetRgn( updateRgn
, left
, top
) ;
1613 #if TARGET_API_MAC_CARBON
1614 if ( QDIsPortBuffered( GetWindowPort( rootWindow
) ) )
1616 QDFlushPortBuffer( GetWindowPort( rootWindow
) , updateRgn
) ;
1619 ValidWindowRgn( rootWindow
, updateRgn
) ;
1620 DisposeRgn( updateRgn
) ;
1623 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1625 wxTopLevelWindowMac
* win
= NULL
;
1626 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1629 win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
1634 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1636 RgnHandle visRgn
= NewRgn() ;
1637 RgnHandle tempRgn
= NewRgn() ;
1638 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1640 if ( MacIsReallyShown() )
1642 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1644 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1645 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1647 int borderTop
= 14 ;
1648 int borderOther
= 4 ;
1649 if ( UMAGetSystemVersion() >= 0x1030 )
1652 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1653 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1656 if ( !IsTopLevel() )
1658 wxWindow
* parent
= GetParent() ;
1661 wxSize size
= parent
->GetSize() ;
1664 parent
->MacWindowToRootWindow( &x
, &y
) ;
1665 MacRootWindowToWindow( &x
, &y
) ;
1667 SetRectRgn( tempRgn
,
1668 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1669 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1670 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1672 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1673 if ( parent
->IsTopLevel() )
1675 parent
= parent
->GetParent() ;
1678 if ( respectChildrenAndSiblings
)
1680 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1682 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1684 wxWindowMac
*child
= node
->GetData();
1686 if ( !child
->IsTopLevel() && child
->IsShown() )
1688 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1689 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1691 int borderTop
= 14 ;
1692 int borderOther
= 4 ;
1693 if ( UMAGetSystemVersion() >= 0x1030 )
1696 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1697 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1699 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1704 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1706 bool thisWindowThrough
= false ;
1707 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1709 wxWindowMac
*sibling
= node
->GetData();
1710 if ( sibling
== this )
1712 thisWindowThrough
= true ;
1715 if( !thisWindowThrough
)
1720 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1722 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
) ;
1723 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1725 int borderTop
= 14 ;
1726 int borderOther
= 4 ;
1727 if ( UMAGetSystemVersion() >= 0x1030 )
1730 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
) ;
1731 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1733 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1739 m_macVisibleRegion
= visRgn
;
1740 DisposeRgn( visRgn
) ;
1741 DisposeRgn( tempRgn
) ;
1742 DisposeRgn( tempStaticBoxRgn
) ;
1743 return m_macVisibleRegion
;
1746 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1748 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1749 // updatergn is always already clipped to our boundaries
1750 // it is in window coordinates, not in client coordinates
1752 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1755 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1756 RgnHandle ownUpdateRgn
= NewRgn() ;
1757 CopyRgn( updatergn
, ownUpdateRgn
) ;
1759 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1761 // newupdate is the update region in client coordinates
1762 RgnHandle newupdate
= NewRgn() ;
1763 wxSize point
= GetClientSize() ;
1764 wxPoint origin
= GetClientAreaOrigin() ;
1765 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1766 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1767 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1768 m_updateRegion
= newupdate
;
1769 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1771 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1773 wxWindowDC
dc(this);
1774 if (!EmptyRgn(ownUpdateRgn
))
1775 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1776 wxEraseEvent
eevent( GetId(), &dc
);
1777 eevent
.SetEventObject( this );
1778 GetEventHandler()->ProcessEvent( eevent
);
1780 wxNcPaintEvent
eventNc( GetId() );
1781 eventNc
.SetEventObject( this );
1782 GetEventHandler()->ProcessEvent( eventNc
);
1784 DisposeRgn( ownUpdateRgn
) ;
1785 if ( !m_updateRegion
.Empty() )
1787 wxWindowList hiddenWindows
;
1788 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1790 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1792 if ( child
&& child
->MacGetRootWindow() == (WXWindow
) window
&& child
->IsShown() && child
->GetMacControl() )
1794 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ;
1795 hiddenWindows
.Append( child
) ;
1800 event
.SetTimestamp(time
);
1801 event
.SetEventObject(this);
1802 GetEventHandler()->ProcessEvent(event
);
1804 for (wxWindowListNode
*node
= hiddenWindows
.GetFirst(); node
; node
= node
->GetNext())
1806 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1808 if ( child
&& child
->GetMacControl() )
1810 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ;
1816 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1818 RgnHandle childupdate
= NewRgn() ;
1819 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1821 // calculate the update region for the child windows by intersecting the window rectangle with our own
1822 // passed in update region and then offset it to be client-wise window coordinates again
1823 wxWindowMac
*child
= node
->GetData();
1824 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1825 SectRgn( childupdate
, updatergn
, childupdate
) ;
1826 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1827 if ( child
->MacGetRootWindow() == (WXWindow
) window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1829 // because dialogs may also be children
1830 child
->MacRedraw( childupdate
, time
, erase
) ;
1833 DisposeRgn( childupdate
) ;
1834 // eventually a draw grow box here
1838 WXWindow
wxWindowMac::MacGetRootWindow() const
1840 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1844 if ( iter
->IsTopLevel() )
1845 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1847 iter
= iter
->GetParent() ;
1849 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
1853 void wxWindowMac::MacCreateScrollBars( long style
)
1855 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1857 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1858 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1860 GetClientSize( &width
, &height
) ;
1862 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1863 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1864 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1865 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1867 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1868 vSize
, wxVERTICAL
);
1870 if ( style
& wxVSCROLL
)
1876 m_vScrollBar
->Show(false) ;
1878 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1879 hSize
, wxHORIZONTAL
);
1880 if ( style
& wxHSCROLL
)
1885 m_hScrollBar
->Show(false) ;
1888 // because the create does not take into account the client area origin
1889 MacRepositionScrollBars() ; // we might have a real position shift
1892 void wxWindowMac::MacRepositionScrollBars()
1894 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1895 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1897 // get real client area
1899 int width
= m_width
;
1900 int height
= m_height
;
1902 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1903 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1905 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1906 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1907 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1908 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1915 MacClientToRootWindow( &x
, &y
) ;
1916 MacClientToRootWindow( &w
, &h
) ;
1918 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1920 int totW
= 10000 , totH
= 10000;
1923 if ( iter
->IsTopLevel() )
1925 totW
= iter
->m_width
;
1926 totH
= iter
->m_height
;
1930 iter
= iter
->GetParent() ;
1958 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1962 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1966 bool wxWindowMac::AcceptsFocus() const
1968 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1971 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1973 return GetParent()->MacGetContainerForEmbedding() ;
1976 void wxWindowMac::MacSuperChangedPosition()
1978 // only window-absolute structures have to be moved i.e. controls
1980 wxWindowListNode
*node
= GetChildren().GetFirst();
1983 wxWindowMac
*child
= node
->GetData();
1984 child
->MacSuperChangedPosition() ;
1985 node
= node
->GetNext();
1989 void wxWindowMac::MacTopLevelWindowChangedPosition()
1991 // only screen-absolute structures have to be moved i.e. glcanvas
1993 wxWindowListNode
*node
= GetChildren().GetFirst();
1996 wxWindowMac
*child
= node
->GetData();
1997 child
->MacTopLevelWindowChangedPosition() ;
1998 node
= node
->GetNext();
2001 long wxWindowMac::MacGetLeftBorderSize( ) const
2006 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2009 #if wxMAC_USE_THEME_BORDER
2011 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2016 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2019 #if wxMAC_USE_THEME_BORDER
2021 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2026 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2033 long wxWindowMac::MacGetRightBorderSize( ) const
2035 // they are all symmetric in mac themes
2036 return MacGetLeftBorderSize() ;
2039 long wxWindowMac::MacGetTopBorderSize( ) const
2041 // they are all symmetric in mac themes
2042 return MacGetLeftBorderSize() ;
2045 long wxWindowMac::MacGetBottomBorderSize( ) const
2047 // they are all symmetric in mac themes
2048 return MacGetLeftBorderSize() ;
2051 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2053 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2056 // Find the wxWindowMac at the current mouse position, returning the mouse
2058 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2060 pt
= wxGetMousePosition();
2061 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2065 // Get the current mouse position.
2066 wxPoint
wxGetMousePosition()
2069 wxGetMousePosition(& x
, & y
);
2070 return wxPoint(x
, y
);
2073 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2075 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2077 // copied from wxGTK : CS
2078 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2081 // (a) it's a command event and so is propagated to the parent
2082 // (b) under MSW it can be generated from kbd too
2083 // (c) it uses screen coords (because of (a))
2084 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2086 this->ClientToScreen(event
.GetPosition()));
2087 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )