1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $
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/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
57 #include "wx/popupwin.h"
60 #if wxUSE_DRAG_AND_DROP
64 #include "wx/graphics.h"
67 #include "wx/osx/uma.h"
69 #include "wx/osx/private.h"
72 #define MAC_SCROLLBAR_SIZE 15
73 #define MAC_SMALL_SCROLLBAR_SIZE 11
77 #ifdef __WXUNIVERSAL__
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
80 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
83 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
92 // ===========================================================================
94 // ===========================================================================
96 // ----------------------------------------------------------------------------
97 // constructors and such
98 // ----------------------------------------------------------------------------
100 wxWindowMac::wxWindowMac()
105 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
110 const wxString
& name
)
113 Create(parent
, id
, pos
, size
, style
, name
);
116 void wxWindowMac::Init()
120 m_cgContextRef
= NULL
;
122 // as all windows are created with WS_VISIBLE style...
125 m_hScrollBar
= NULL
;
126 m_vScrollBar
= NULL
;
127 m_hScrollBarAlwaysShown
= false;
128 m_vScrollBarAlwaysShown
= false;
130 m_macIsUserPane
= true;
131 m_clipChildren
= false ;
132 m_cachedClippedRectValid
= false ;
135 wxWindowMac::~wxWindowMac()
139 MacInvalidateBorders() ;
141 #ifndef __WXUNIVERSAL__
142 // VS: make sure there's no wxFrame with last focus set to us:
143 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
145 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
148 if ( frame
->GetLastFocus() == this )
149 frame
->SetLastFocus(NULL
);
155 // destroy children before destroying this window itself
158 // wxRemoveMacControlAssociation( this ) ;
159 // If we delete an item, we should initialize the parent panel,
160 // because it could now be invalid.
161 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
164 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
165 tlw
->SetDefaultItem(NULL
);
168 if ( g_MacLastWindow
== this )
169 g_MacLastWindow
= NULL
;
171 #ifndef __WXUNIVERSAL__
172 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
175 if ( frame
->GetLastFocus() == this )
176 frame
->SetLastFocus( NULL
) ;
180 // delete our drop target if we've got one
181 #if wxUSE_DRAG_AND_DROP
182 if ( m_dropTarget
!= NULL
)
192 WXWidget
wxWindowMac::GetHandle() const
195 return (WXWidget
) m_peer
->GetWXWidget() ;
199 // ---------------------------------------------------------------------------
200 // Utility Routines to move between different coordinate systems
201 // ---------------------------------------------------------------------------
204 * Right now we have the following setup :
205 * a border that is not part of the native control is always outside the
206 * control's border (otherwise we loose all native intelligence, future ways
207 * may be to have a second embedding control responsible for drawing borders
208 * and backgrounds eventually)
209 * so all this border calculations have to be taken into account when calling
210 * native methods or getting native oriented data
211 * so we have three coordinate systems here
212 * wx client coordinates
213 * wx window coordinates (including window frames)
221 bool wxWindowMac::Create(wxWindowMac
*parent
,
226 const wxString
& name
)
228 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
230 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
233 m_windowVariant
= parent
->GetWindowVariant() ;
235 if ( m_macIsUserPane
)
237 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
238 MacPostControlCreate(pos
, size
) ;
241 #ifndef __WXUNIVERSAL__
242 // Don't give scrollbars to wxControls unless they ask for them
243 if ( (! IsKindOf(CLASSINFO(wxControl
))
245 && ! IsKindOf(CLASSINFO(wxStatusBar
))
248 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
250 MacCreateScrollBars( style
) ;
254 wxWindowCreateEvent
event((wxWindow
*)this);
255 GetEventHandler()->AddPendingEvent(event
);
260 void wxWindowMac::MacChildAdded()
264 m_vScrollBar
->Raise() ;
266 m_hScrollBar
->Raise() ;
270 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
272 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
274 GetParent()->AddChild( this );
276 m_peer
->InstallEventHandler();
277 m_peer
->Embed(GetParent()->GetPeer());
279 GetParent()->MacChildAdded() ;
281 // adjust font, controlsize etc
282 DoSetWindowVariant( m_windowVariant
) ;
284 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
286 // for controls we want to use best size for wxDefaultSize params )
287 if ( !m_macIsUserPane
)
288 SetInitialSize(size
);
290 SetCursor( *wxSTANDARD_CURSOR
) ;
293 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
295 // Don't assert, in case we set the window variant before
296 // the window is created
297 // wxASSERT( m_peer->Ok() ) ;
299 m_windowVariant
= variant
;
301 if (m_peer
== NULL
|| !m_peer
->IsOk())
304 m_peer
->SetControlSize( variant
);
308 // we will get that from the settings later
309 // and make this NORMAL later, but first
310 // we have a few calculations that we must fix
314 case wxWINDOW_VARIANT_NORMAL
:
315 size
= kControlSizeNormal
;
318 case wxWINDOW_VARIANT_SMALL
:
319 size
= kControlSizeSmall
;
322 case wxWINDOW_VARIANT_MINI
:
323 // not always defined in the headers
327 case wxWINDOW_VARIANT_LARGE
:
328 size
= kControlSizeLarge
;
332 wxFAIL_MSG(wxT("unexpected window variant"));
335 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
340 wxOSXSystemFont systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
344 case wxWINDOW_VARIANT_NORMAL
:
345 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
348 case wxWINDOW_VARIANT_SMALL
:
349 systemFont
= wxOSX_SYSTEM_FONT_SMALL
;
352 case wxWINDOW_VARIANT_MINI
:
353 systemFont
= wxOSX_SYSTEM_FONT_MINI
;
356 case wxWINDOW_VARIANT_LARGE
:
357 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
361 wxFAIL_MSG(wxT("unexpected window variant"));
365 font
.CreateSystemFont( systemFont
) ;
370 void wxWindowMac::MacUpdateControlFont()
373 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
375 // do not trigger refreshes upon invisible and possible partly created objects
376 if ( IsShownOnScreen() )
380 bool wxWindowMac::SetFont(const wxFont
& font
)
382 bool retval
= wxWindowBase::SetFont( font
);
384 MacUpdateControlFont() ;
389 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
391 bool retval
= wxWindowBase::SetForegroundColour( col
);
394 MacUpdateControlFont();
399 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
401 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
405 m_peer
->SetBackgroundColour( col
) ;
410 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
412 while (w
&& !w
->IsTopLevel())
421 void wxWindowMac::SetFocus()
423 if ( !AcceptsFocus() )
426 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
429 wxWindow
* former
= FindFocus() ;
430 if ( former
== this )
436 void wxWindowMac::DoCaptureMouse()
438 wxApp::s_captureWindow
= (wxWindow
*) this ;
439 m_peer
->CaptureMouse() ;
442 wxWindow
* wxWindowBase::GetCapture()
444 return wxApp::s_captureWindow
;
447 void wxWindowMac::DoReleaseMouse()
449 wxApp::s_captureWindow
= NULL
;
451 m_peer
->ReleaseMouse() ;
454 #if wxUSE_DRAG_AND_DROP
456 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
460 m_dropTarget
= pDropTarget
;
461 if ( m_dropTarget
!= NULL
)
469 // Old-style File Manager Drag & Drop
470 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
475 // From a wx position / size calculate the appropriate size of the native control
477 bool wxWindowMac::MacGetBoundsForControl(
481 int& w
, int& h
, bool adjustOrigin
) const
483 // the desired size, minus the border pixels gives the correct size of the control
487 w
= WidthDefault( size
.x
);
488 h
= HeightDefault( size
.y
);
490 x
+= MacGetLeftBorderSize() ;
491 y
+= MacGetTopBorderSize() ;
492 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
493 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
496 AdjustForParentClientOrigin( x
, y
) ;
498 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
499 if ( GetParent() && !GetParent()->IsTopLevel() )
501 x
-= GetParent()->MacGetLeftBorderSize() ;
502 y
-= GetParent()->MacGetTopBorderSize() ;
508 // Get window size (not client size)
509 void wxWindowMac::DoGetSize(int *x
, int *y
) const
512 m_peer
->GetSize( width
, height
);
515 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
517 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
520 // get the position of the bounds of this window in client coordinates of its parent
521 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
525 m_peer
->GetPosition( x1
, y1
) ;
527 // get the wx window position from the native one
528 x1
-= MacGetLeftBorderSize() ;
529 y1
-= MacGetTopBorderSize() ;
533 wxWindow
*parent
= GetParent();
536 // we must first adjust it to be in window coordinates of the parent,
537 // as otherwise it gets lost by the ClientAreaOrigin fix
538 x1
+= parent
->MacGetLeftBorderSize() ;
539 y1
+= parent
->MacGetTopBorderSize() ;
541 // and now to client coordinates
542 wxPoint
pt(parent
->GetClientAreaOrigin());
554 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
556 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
557 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
558 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
559 MacRootWindowToWindow( x
, y
) ;
561 wxPoint origin
= GetClientAreaOrigin() ;
568 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
570 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
571 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
573 wxPoint origin
= GetClientAreaOrigin() ;
579 MacWindowToRootWindow( x
, y
) ;
580 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
583 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
585 wxPoint origin
= GetClientAreaOrigin() ;
591 MacWindowToRootWindow( x
, y
) ;
594 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
605 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
608 pt
.x
-= MacGetLeftBorderSize() ;
609 pt
.y
-= MacGetTopBorderSize() ;
610 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
620 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
631 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
634 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
635 pt
.x
+= MacGetLeftBorderSize() ;
636 pt
.y
+= MacGetTopBorderSize() ;
646 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
648 wxSize sizeTotal
= size
;
650 int innerwidth
, innerheight
;
652 int outerwidth
, outerheight
;
654 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
655 m_peer
->GetSize( outerwidth
, outerheight
);
657 sizeTotal
.x
+= outerwidth
-innerwidth
;
658 sizeTotal
.y
+= outerheight
-innerheight
;
660 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
661 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
666 // Get size *available for subwindows* i.e. excluding menu bar etc.
667 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
673 m_peer
->GetContentArea( left
, top
, ww
, hh
);
675 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
676 hh
-= m_hScrollBar
->GetSize().y
;
678 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
679 ww
-= m_vScrollBar
->GetSize().x
;
688 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
690 if (m_cursor
.IsSameAs(cursor
))
695 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
700 if ( ! wxWindowBase::SetCursor( cursor
) )
704 wxASSERT_MSG( m_cursor
.Ok(),
705 wxT("cursor must be valid after call to the base version"));
707 if ( GetPeer() != NULL
)
708 GetPeer()->SetCursor( m_cursor
);
714 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
716 #ifndef __WXUNIVERSAL__
717 menu
->SetInvokingWindow((wxWindow
*)this);
720 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
722 wxPoint mouse
= wxGetMousePosition();
728 ClientToScreen( &x
, &y
) ;
730 menu
->GetPeer()->PopUp(this, x
, y
);
731 menu
->SetInvokingWindow( NULL
);
734 // actually this shouldn't be called, because universal is having its own implementation
740 // ----------------------------------------------------------------------------
742 // ----------------------------------------------------------------------------
746 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
748 wxWindowBase::DoSetToolTip(tooltip
);
751 m_tooltip
->SetWindow(this);
756 void wxWindowMac::MacInvalidateBorders()
758 if ( m_peer
== NULL
)
761 bool vis
= IsShownOnScreen() ;
765 int outerBorder
= MacGetLeftBorderSize() ;
767 if ( m_peer
->NeedsFocusRect() )
770 if ( outerBorder
== 0 )
773 // now we know that we have something to do at all
777 m_peer
->GetSize( tw
, th
);
778 m_peer
->GetPosition( tx
, ty
);
780 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
781 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
782 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
783 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
786 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
787 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
788 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
789 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
793 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
795 // this is never called for a toplevel window, so we know we have a parent
796 int former_x
, former_y
, former_w
, former_h
;
798 // Get true coordinates of former position
799 DoGetPosition( &former_x
, &former_y
) ;
800 DoGetSize( &former_w
, &former_h
) ;
802 wxWindow
*parent
= GetParent();
805 wxPoint
pt(parent
->GetClientAreaOrigin());
810 int actualWidth
= width
;
811 int actualHeight
= height
;
816 // min and max sizes are only for sizers, not for explicit size setting
817 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
818 actualWidth
= m_minWidth
;
819 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
820 actualHeight
= m_minHeight
;
821 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
822 actualWidth
= m_maxWidth
;
823 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
824 actualHeight
= m_maxHeight
;
827 bool doMove
= false, doResize
= false ;
829 if ( actualX
!= former_x
|| actualY
!= former_y
)
832 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
835 if ( doMove
|| doResize
)
837 // as the borders are drawn outside the native control, we adjust now
839 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
840 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
841 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
843 if ( parent
&& !parent
->IsTopLevel() )
845 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
848 MacInvalidateBorders() ;
850 m_cachedClippedRectValid
= false ;
852 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
854 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
856 MacInvalidateBorders() ;
858 MacRepositionScrollBars() ;
861 wxPoint
point(actualX
, actualY
);
862 wxMoveEvent
event(point
, m_windowId
);
863 event
.SetEventObject(this);
864 HandleWindowEvent(event
) ;
869 MacRepositionScrollBars() ;
870 wxSize
size(actualWidth
, actualHeight
);
871 wxSizeEvent
event(size
, m_windowId
);
872 event
.SetEventObject(this);
873 HandleWindowEvent(event
);
878 wxSize
wxWindowMac::DoGetBestSize() const
880 if ( m_macIsUserPane
|| IsTopLevel() )
882 return wxWindowBase::DoGetBestSize() ;
888 m_peer
->GetBestRect(&r
);
890 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
901 else if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
907 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
914 // return wxWindowBase::DoGetBestSize() ;
918 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
919 MacGetRightBorderSize();
920 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
921 MacGetBottomBorderSize();
922 if ( bestHeight
< 10 )
925 return wxSize(bestWidth
, bestHeight
);
929 // set the size of the window: if the dimensions are positive, just use them,
930 // but if any of them is equal to -1, it means that we must find the value for
931 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
932 // which case -1 is a valid value for x and y)
934 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
935 // the width/height to best suit our contents, otherwise we reuse the current
937 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
939 // get the current size and position...
940 int currentX
, currentY
;
941 int currentW
, currentH
;
943 GetPosition(¤tX
, ¤tY
);
944 GetSize(¤tW
, ¤tH
);
946 // ... and don't do anything (avoiding flicker) if it's already ok
947 if ( x
== currentX
&& y
== currentY
&&
948 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
951 MacRepositionScrollBars() ; // we might have a real position shift
953 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
955 wxSizeEvent
event( wxSize(width
,height
), GetId() );
956 event
.SetEventObject( this );
957 HandleWindowEvent( event
);
963 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
965 if ( x
== wxDefaultCoord
)
967 if ( y
== wxDefaultCoord
)
971 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
973 wxSize size
= wxDefaultSize
;
974 if ( width
== wxDefaultCoord
)
976 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
978 size
= DoGetBestSize();
983 // just take the current one
988 if ( height
== wxDefaultCoord
)
990 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
992 if ( size
.x
== wxDefaultCoord
)
993 size
= DoGetBestSize();
994 // else: already called DoGetBestSize() above
1000 // just take the current one
1005 DoMoveWindow( x
, y
, width
, height
);
1008 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1010 int left
,top
,width
,height
;
1011 m_peer
->GetContentArea( left
, top
, width
, height
);
1012 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1015 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1017 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1019 int currentclientwidth
, currentclientheight
;
1020 int currentwidth
, currentheight
;
1022 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1023 GetSize( ¤twidth
, ¤theight
) ;
1025 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1026 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1030 void wxWindowMac::SetLabel(const wxString
& title
)
1032 if ( title
== m_label
)
1037 InvalidateBestSize();
1039 if ( m_peer
&& m_peer
->IsOk() )
1040 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1042 // do not trigger refreshes upon invisible and possible partly created objects
1043 if ( IsShownOnScreen() )
1047 wxString
wxWindowMac::GetLabel() const
1052 bool wxWindowMac::Show(bool show
)
1054 if ( !wxWindowBase::Show(show
) )
1058 m_peer
->SetVisibility( show
) ;
1063 void wxWindowMac::DoEnable(bool enable
)
1065 m_peer
->Enable( enable
) ;
1069 // status change notifications
1072 void wxWindowMac::MacVisibilityChanged()
1076 void wxWindowMac::MacHiliteChanged()
1080 void wxWindowMac::MacEnabledStateChanged()
1082 OnEnabled( m_peer
->IsEnabled() );
1086 // status queries on the inherited window's state
1089 bool wxWindowMac::MacIsReallyEnabled()
1091 return m_peer
->IsEnabled() ;
1094 bool wxWindowMac::MacIsReallyHilited()
1096 #if wxOSX_USE_CARBON
1097 return m_peer
->IsActive();
1099 return true; // TODO
1103 int wxWindowMac::GetCharHeight() const
1106 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1111 int wxWindowMac::GetCharWidth() const
1114 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1119 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1122 int *externalLeading
,
1123 const wxFont
*theFont
) const
1125 const wxFont
*fontToUse
= theFont
;
1129 tempFont
= GetFont();
1130 fontToUse
= &tempFont
;
1133 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1134 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1136 wxDouble h
, d
, e
, w
;
1137 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1141 if ( externalLeading
)
1142 *externalLeading
= (wxCoord
)(e
+0.5);
1144 *descent
= (wxCoord
)(d
+0.5);
1146 *x
= (wxCoord
)(w
+0.5);
1148 *y
= (wxCoord
)(h
+0.5);
1152 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1153 * we always intersect with the entire window, not only with the client area
1156 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1158 if ( m_peer
== NULL
)
1161 if ( !IsShownOnScreen() )
1164 m_peer
->SetNeedsDisplay( rect
) ;
1167 void wxWindowMac::DoFreeze()
1169 #if wxOSX_USE_CARBON
1170 if ( m_peer
&& m_peer
->IsOk() )
1171 m_peer
->SetDrawingEnabled( false ) ;
1175 void wxWindowMac::DoThaw()
1177 #if wxOSX_USE_CARBON
1178 if ( m_peer
&& m_peer
->IsOk() )
1180 m_peer
->SetDrawingEnabled( true ) ;
1181 m_peer
->InvalidateWithChildren() ;
1186 wxWindow
*wxGetActiveWindow()
1188 // actually this is a windows-only concept
1192 // Coordinates relative to the window
1193 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1197 DoClientToScreen(&x
, &y
);
1198 CGPoint cgpoint
= CGPointMake( x
, y
);
1199 CGWarpMouseCursorPosition( cgpoint
);
1201 // At least GTK sends a mouse moved event after WarpMouse
1202 wxMouseEvent
event(wxEVT_MOTION
);
1205 wxMouseState mState
= ::wxGetMouseState();
1207 event
.m_altDown
= mState
.AltDown();
1208 event
.m_controlDown
= mState
.ControlDown();
1209 event
.m_leftDown
= mState
.LeftDown();
1210 event
.m_middleDown
= mState
.MiddleDown();
1211 event
.m_rightDown
= mState
.RightDown();
1212 event
.m_metaDown
= mState
.MetaDown();
1213 event
.m_shiftDown
= mState
.ShiftDown();
1214 event
.SetId(GetId());
1215 event
.SetEventObject(this);
1216 GetEventHandler()->ProcessEvent(event
);
1219 int wxWindowMac::GetScrollPos(int orient
) const
1222 if ( orient
== wxHORIZONTAL
)
1225 return m_hScrollBar
->GetThumbPosition() ;
1230 return m_vScrollBar
->GetThumbPosition() ;
1236 // This now returns the whole range, not just the number
1237 // of positions that we can scroll.
1238 int wxWindowMac::GetScrollRange(int orient
) const
1241 if ( orient
== wxHORIZONTAL
)
1244 return m_hScrollBar
->GetRange() ;
1249 return m_vScrollBar
->GetRange() ;
1255 int wxWindowMac::GetScrollThumb(int orient
) const
1258 if ( orient
== wxHORIZONTAL
)
1261 return m_hScrollBar
->GetThumbSize() ;
1266 return m_vScrollBar
->GetThumbSize() ;
1272 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1275 if ( orient
== wxHORIZONTAL
)
1278 m_hScrollBar
->SetThumbPosition( pos
) ;
1283 m_vScrollBar
->SetThumbPosition( pos
) ;
1289 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1291 bool needVisibilityUpdate
= false;
1293 if ( m_hScrollBarAlwaysShown
!= hflag
)
1295 m_hScrollBarAlwaysShown
= hflag
;
1296 needVisibilityUpdate
= true;
1299 if ( m_vScrollBarAlwaysShown
!= vflag
)
1301 m_vScrollBarAlwaysShown
= vflag
;
1302 needVisibilityUpdate
= true;
1305 if ( needVisibilityUpdate
)
1306 DoUpdateScrollbarVisibility();
1310 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1311 // our own window origin is at leftOrigin/rightOrigin
1314 void wxWindowMac::MacPaintGrowBox()
1320 if ( MacHasScrollBarCorner() )
1322 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1323 wxASSERT( cgContext
) ;
1327 m_peer
->GetSize( tw
, th
);
1328 m_peer
->GetPosition( tx
, ty
);
1330 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1333 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1334 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1335 CGContextSaveGState( cgContext
);
1337 if ( m_backgroundColour
.Ok() )
1339 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1343 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1345 CGContextFillRect( cgContext
, cgrect
);
1346 CGContextRestoreGState( cgContext
);
1351 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1356 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1358 // back to the surrounding frame rectangle
1361 m_peer
->GetSize( tw
, th
);
1362 m_peer
->GetPosition( tx
, ty
);
1364 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1366 #if wxOSX_USE_COCOA_OR_CARBON
1368 InsetRect( &rect
, -1 , -1 ) ;
1371 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1372 rect
.bottom
- rect
.top
) ;
1374 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1375 wxASSERT( cgContext
) ;
1377 if ( m_peer
->NeedsFrame() )
1379 HIThemeFrameDrawInfo info
;
1380 memset( &info
, 0 , sizeof(info
) ) ;
1384 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1385 info
.isFocused
= hasFocus
;
1387 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1389 info
.kind
= kHIThemeFrameTextFieldSquare
;
1390 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1392 else if ( HasFlag(wxSIMPLE_BORDER
) )
1394 info
.kind
= kHIThemeFrameListBox
;
1395 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1401 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1404 #endif // wxOSX_USE_COCOA_OR_CARBON
1407 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1410 if ( child
== m_hScrollBar
)
1411 m_hScrollBar
= NULL
;
1412 if ( child
== m_vScrollBar
)
1413 m_vScrollBar
= NULL
;
1415 wxWindowBase::RemoveChild( child
) ;
1418 void wxWindowMac::DoUpdateScrollbarVisibility()
1421 bool triggerSizeEvent
= false;
1425 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1427 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1429 m_hScrollBar
->Show( showHScrollBar
);
1430 triggerSizeEvent
= true;
1436 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1438 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1440 m_vScrollBar
->Show( showVScrollBar
) ;
1441 triggerSizeEvent
= true;
1445 MacRepositionScrollBars() ;
1446 if ( triggerSizeEvent
)
1448 wxSizeEvent
event(GetSize(), m_windowId
);
1449 event
.SetEventObject(this);
1450 HandleWindowEvent(event
);
1455 // New function that will replace some of the above.
1456 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1457 int range
, bool refresh
)
1460 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1461 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1462 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1463 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1465 DoUpdateScrollbarVisibility();
1469 // Does a physical scroll
1470 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1472 if ( dx
== 0 && dy
== 0 )
1475 int width
, height
;
1476 GetClientSize( &width
, &height
) ;
1479 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1481 scrollrect
.Intersect( *rect
) ;
1482 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1483 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1485 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1490 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1492 child
= node
->GetData();
1496 if (child
== m_vScrollBar
)
1498 if (child
== m_hScrollBar
)
1501 if (child
->IsTopLevel())
1504 child
->GetPosition( &x
, &y
);
1505 child
->GetSize( &w
, &h
);
1508 wxRect
rc( x
, y
, w
, h
);
1509 if (rect
->Intersects( rc
))
1510 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1514 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1519 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1522 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1524 wxScrollWinEvent wevent
;
1525 wevent
.SetPosition(event
.GetPosition());
1526 wevent
.SetOrientation(event
.GetOrientation());
1527 wevent
.SetEventObject(this);
1529 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1530 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1531 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1532 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1533 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1534 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1535 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1536 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1537 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1538 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1539 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1540 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1541 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1542 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1543 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1544 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1546 HandleWindowEvent(wevent
);
1551 wxWindow
*wxWindowBase::DoFindFocus()
1553 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1556 void wxWindowMac::OnInternalIdle()
1558 // This calls the UI-update mechanism (querying windows for
1559 // menu/toolbar/control state information)
1560 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1561 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1564 // Raise the window to the top of the Z order
1565 void wxWindowMac::Raise()
1570 // Lower the window to the bottom of the Z order
1571 void wxWindowMac::Lower()
1576 // static wxWindow *gs_lastWhich = NULL;
1578 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1580 // first trigger a set cursor event
1582 wxPoint clientorigin
= GetClientAreaOrigin() ;
1583 wxSize clientsize
= GetClientSize() ;
1585 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1587 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1589 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1590 if ( processedEvtSetCursor
&& event
.HasCursor() )
1592 cursor
= event
.GetCursor() ;
1596 // the test for processedEvtSetCursor is here to prevent using m_cursor
1597 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1598 // it - this is a way to say that our cursor shouldn't be used for this
1600 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1603 if ( !wxIsBusy() && !GetParent() )
1604 cursor
= *wxSTANDARD_CURSOR
;
1608 cursor
.MacInstall() ;
1611 return cursor
.Ok() ;
1614 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1618 return m_tooltip
->GetTip() ;
1621 return wxEmptyString
;
1624 void wxWindowMac::ClearBackground()
1630 void wxWindowMac::Update()
1632 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1637 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1639 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1643 if ( iter
->IsTopLevel() )
1645 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1649 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1654 iter
= iter
->GetParent() ;
1660 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1662 MacUpdateClippedRects() ;
1664 return m_cachedClippedClientRect
;
1667 const wxRect
& wxWindowMac::MacGetClippedRect() const
1669 MacUpdateClippedRects() ;
1671 return m_cachedClippedRect
;
1674 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1676 MacUpdateClippedRects() ;
1678 return m_cachedClippedRectWithOuterStructure
;
1681 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1683 static wxRegion emptyrgn
;
1685 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1687 MacUpdateClippedRects() ;
1688 if ( includeOuterStructures
)
1689 return m_cachedClippedRegionWithOuterStructure
;
1691 return m_cachedClippedRegion
;
1699 void wxWindowMac::MacUpdateClippedRects() const
1701 #if wxOSX_USE_CARBON
1702 if ( m_cachedClippedRectValid
)
1705 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1706 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1707 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1708 // to add focus borders everywhere
1710 Rect rIncludingOuterStructures
;
1714 m_peer
->GetSize( tw
, th
);
1715 m_peer
->GetPosition( tx
, ty
);
1717 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1719 r
.left
-= MacGetLeftBorderSize() ;
1720 r
.top
-= MacGetTopBorderSize() ;
1721 r
.bottom
+= MacGetBottomBorderSize() ;
1722 r
.right
+= MacGetRightBorderSize() ;
1729 rIncludingOuterStructures
= r
;
1730 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1732 wxRect cl
= GetClientRect() ;
1733 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1737 const wxWindow
* child
= (wxWindow
*) this ;
1738 const wxWindow
* parent
= NULL
;
1740 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1742 if ( parent
->MacIsChildOfClientArea(child
) )
1744 size
= parent
->GetClientSize() ;
1745 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1751 // this will be true for scrollbars, toolbars etc.
1752 size
= parent
->GetSize() ;
1753 y
= parent
->MacGetTopBorderSize() ;
1754 x
= parent
->MacGetLeftBorderSize() ;
1755 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1756 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1759 parent
->MacWindowToRootWindow( &x
, &y
) ;
1760 MacRootWindowToWindow( &x
, &y
) ;
1762 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1764 // the wxwindow and client rects will always be clipped
1765 SectRect( &r
, &rparent
, &r
) ;
1766 SectRect( &rClient
, &rparent
, &rClient
) ;
1768 // the structure only at 'hard' borders
1769 if ( parent
->MacClipChildren() ||
1770 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1772 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1778 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1779 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1780 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1781 m_cachedClippedRectWithOuterStructure
= wxRect(
1782 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1783 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1784 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1786 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1787 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1788 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1790 m_cachedClippedRectValid
= true ;
1795 This function must not change the updatergn !
1797 bool wxWindowMac::MacDoRedraw( long time
)
1799 bool handled
= false ;
1801 wxRegion formerUpdateRgn
= m_updateRegion
;
1802 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1804 const wxRect clientRect
= GetClientRect();
1806 clientUpdateRgn
.Intersect(clientRect
);
1808 // first send an erase event to the entire update area
1809 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1812 case wxBG_STYLE_ERASE
:
1813 case wxBG_STYLE_SYSTEM
:
1815 // for the toplevel window this really is the entire area for
1816 // all the others only their client area, otherwise they might
1817 // be drawing with full alpha and eg put blue into the grow-box
1818 // area of a scrolled window (scroll sample)
1819 wxWindowDC
dc(this);
1821 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1823 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1825 if ( bgStyle
== wxBG_STYLE_ERASE
)
1827 wxEraseEvent
eevent( GetId(), &dc
);
1828 eevent
.SetEventObject( this );
1829 if ( ProcessWindowEvent( eevent
) )
1835 dc
.SetBackground(GetBackgroundColour());
1841 case wxBG_STYLE_PAINT
:
1842 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1843 // entire window client area
1847 wxFAIL_MSG( "unsupported background style" );
1852 // calculate a client-origin version of the update rgn and set
1853 // m_updateRegion to that
1854 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1855 m_updateRegion
= clientUpdateRgn
;
1857 if ( !m_updateRegion
.Empty() )
1859 // paint the window itself
1861 wxPaintEvent
event(GetId());
1862 event
.SetTimestamp(time
);
1863 event
.SetEventObject(this);
1864 handled
= HandleWindowEvent(event
);
1867 m_updateRegion
= formerUpdateRgn
;
1871 void wxWindowMac::MacPaintChildrenBorders()
1873 // now we cannot rely on having its borders drawn by a window itself, as it does not
1874 // get the updateRgn wide enough to always do so, so we do it from the parent
1875 // this would also be the place to draw any custom backgrounds for native controls
1876 // in Composited windowing
1877 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1881 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1883 child
= node
->GetData();
1887 if (child
== m_vScrollBar
)
1889 if (child
== m_hScrollBar
)
1892 if (child
->IsTopLevel())
1894 if (!child
->IsShown())
1897 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1899 child
->GetPosition( &x
, &y
);
1900 child
->GetSize( &w
, &h
);
1902 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
1904 // paint custom borders
1905 wxNcPaintEvent
eventNc( child
->GetId() );
1906 eventNc
.SetEventObject( child
);
1907 if ( !child
->HandleWindowEvent( eventNc
) )
1909 child
->MacPaintBorders(0, 0) ;
1916 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1918 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1919 return tlw
? tlw
->GetWXWindow() : NULL
;
1922 bool wxWindowMac::MacHasScrollBarCorner() const
1925 /* Returns whether the scroll bars in a wxScrolledWindow should be
1926 * shortened. Scroll bars should be shortened if either:
1928 * - both scroll bars are visible, or
1930 * - there is a resize box in the parent frame's corner and this
1931 * window shares the bottom and right edge with the parent
1935 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1938 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1939 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1941 // Both scroll bars visible
1946 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1948 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1950 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1953 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1955 // Parent frame has resize handle
1956 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1958 // Note: allow for some wiggle room here as wxMac's
1959 // window rect calculations seem to be imprecise
1960 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1961 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1963 // Parent frame has resize handle and shares
1964 // right bottom corner
1969 // Parent frame has resize handle but doesn't
1970 // share right bottom corner
1976 // Parent frame doesn't have resize handle
1982 // No parent frame found
1990 void wxWindowMac::MacCreateScrollBars( long style
)
1993 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1995 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1997 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1998 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2000 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2003 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2005 GetClientSize( &width
, &height
) ;
2007 wxPoint
vPoint(width
- scrlsize
, 0) ;
2008 wxSize
vSize(scrlsize
, height
- adjust
) ;
2009 wxPoint
hPoint(0, height
- scrlsize
) ;
2010 wxSize
hSize(width
- adjust
, scrlsize
) ;
2012 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2013 if ( style
& wxVSCROLL
)
2015 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2016 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2019 if ( style
& wxHSCROLL
)
2021 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2022 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2026 // because the create does not take into account the client area origin
2027 // we might have a real position shift
2028 MacRepositionScrollBars() ;
2032 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2034 bool result
= ((child
== NULL
)
2036 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
))
2043 void wxWindowMac::MacRepositionScrollBars()
2046 if ( !m_hScrollBar
&& !m_vScrollBar
)
2049 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2050 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2052 // get real client area
2054 GetSize( &width
, &height
);
2056 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2057 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2059 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2060 wxSize
vSize( scrlsize
, height
- adjust
) ;
2061 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2062 wxSize
hSize( width
- adjust
, scrlsize
) ;
2065 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2067 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2071 bool wxWindowMac::AcceptsFocus() const
2073 if ( MacIsUserPane() )
2074 return wxWindowBase::AcceptsFocus();
2076 return m_peer
->CanFocus();
2079 void wxWindowMac::MacSuperChangedPosition()
2081 // only window-absolute structures have to be moved i.e. controls
2083 m_cachedClippedRectValid
= false ;
2086 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2089 child
= node
->GetData();
2090 child
->MacSuperChangedPosition() ;
2092 node
= node
->GetNext();
2096 void wxWindowMac::MacTopLevelWindowChangedPosition()
2098 // only screen-absolute structures have to be moved i.e. glcanvas
2101 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2104 child
= node
->GetData();
2105 child
->MacTopLevelWindowChangedPosition() ;
2107 node
= node
->GetNext();
2111 long wxWindowMac::MacGetLeftBorderSize() const
2118 if ( m_peer
&& m_peer
->NeedsFrame() )
2120 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2122 #if wxOSX_USE_COCOA_OR_CARBON
2123 // this metric is only the 'outset' outside the simple frame rect
2124 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2130 else if (HasFlag(wxSIMPLE_BORDER
))
2132 #if wxOSX_USE_COCOA_OR_CARBON
2133 // this metric is only the 'outset' outside the simple frame rect
2134 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2145 long wxWindowMac::MacGetRightBorderSize() const
2147 // they are all symmetric in mac themes
2148 return MacGetLeftBorderSize() ;
2151 long wxWindowMac::MacGetTopBorderSize() const
2153 // they are all symmetric in mac themes
2154 return MacGetLeftBorderSize() ;
2157 long wxWindowMac::MacGetBottomBorderSize() const
2159 // they are all symmetric in mac themes
2160 return MacGetLeftBorderSize() ;
2163 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2165 return style
& ~wxBORDER_MASK
;
2168 // Find the wxWindowMac at the current mouse position, returning the mouse
2170 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2172 pt
= wxGetMousePosition();
2173 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2175 return (wxWindow
*) found
;
2178 // Get the current mouse position.
2179 wxPoint
wxGetMousePosition()
2183 wxGetMousePosition( &x
, &y
);
2185 return wxPoint(x
, y
);
2188 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2190 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2192 // copied from wxGTK : CS
2193 // VZ: shouldn't we move this to base class then?
2195 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2198 // (a) it's a command event and so is propagated to the parent
2199 // (b) under MSW it can be generated from kbd too
2200 // (c) it uses screen coords (because of (a))
2201 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2203 this->ClientToScreen(event
.GetPosition()));
2204 evtCtx
.SetEventObject(this);
2205 if ( ! HandleWindowEvent(evtCtx
) )
2214 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2218 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2222 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2223 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2228 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2233 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2235 #if wxOSX_USE_COCOA_OR_CARBON
2236 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2239 return eventNotHandledErr
;
2245 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2247 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2248 if ( !wxWindowBase::Reparent(newParent
) )
2251 m_peer
->RemoveFromParent();
2252 m_peer
->Embed( GetParent()->GetPeer() );
2256 bool wxWindowMac::SetTransparent(wxByte alpha
)
2258 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2260 if ( alpha
!= m_macAlpha
)
2262 m_macAlpha
= alpha
;
2269 bool wxWindowMac::CanSetTransparent()
2274 wxByte
wxWindowMac::GetTransparent() const
2279 bool wxWindowMac::IsShownOnScreen() const
2281 if ( m_peer
&& m_peer
->IsOk() )
2283 bool peerVis
= m_peer
->IsVisible();
2284 bool wxVis
= wxWindowBase::IsShownOnScreen();
2285 if( peerVis
!= wxVis
)
2287 // CS : put a breakpoint here to investigate differences
2288 // between native an wx visibilities
2289 // the only place where I've encountered them until now
2290 // are the hiding/showing sequences where the vis-changed event is
2291 // first sent to the innermost control, while wx does things
2292 // from the outmost control
2293 wxVis
= wxWindowBase::IsShownOnScreen();
2297 return m_peer
->IsVisible();
2299 return wxWindowBase::IsShownOnScreen();
2302 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2304 bool handled
= HandleWindowEvent( event
) ;
2305 if ( handled
&& event
.GetSkipped() )
2309 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2311 wxWindow
*ancestor
= this;
2314 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2317 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2319 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2320 handled
= handler
->ProcessEvent( command_event
);
2324 // accelerators can also be used with buttons, try them too
2325 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2326 handled
= handler
->ProcessEvent( command_event
);
2332 if (ancestor
->IsTopLevel())
2335 ancestor
= ancestor
->GetParent();
2338 #endif // wxUSE_ACCEL
2347 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2349 static MacControlMap wxWinMacControlList
;
2351 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2353 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2355 return impl
->GetWXPeer();
2360 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2362 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2364 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2367 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2369 // adding NULL ControlRef is (first) surely a result of an error and
2370 // (secondly) breaks native event processing
2371 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2373 wxWinMacControlList
[inControl
] = impl
;
2376 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2378 // iterate over all the elements in the class
2379 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2380 // we should go on...
2386 MacControlMap::iterator it
;
2387 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2389 if ( it
->second
== impl
)
2391 wxWinMacControlList
.erase(it
);
2399 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2401 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2404 m_isRootControl
= isRootControl
;
2408 wxWidgetImpl::wxWidgetImpl()
2413 wxWidgetImpl::~wxWidgetImpl()
2417 void wxWidgetImpl::Init()
2419 m_isRootControl
= false;
2421 m_needsFocusRect
= false;
2422 m_needsFrame
= true;
2425 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2427 m_needsFocusRect
= needs
;
2430 bool wxWidgetImpl::NeedsFocusRect() const
2432 return m_needsFocusRect
;
2435 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2437 m_needsFrame
= needs
;
2440 bool wxWidgetImpl::NeedsFrame() const
2442 return m_needsFrame
;