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;
131 m_macIsUserPane
= true;
132 m_clipChildren
= false ;
133 m_cachedClippedRectValid
= false ;
136 wxWindowMac::~wxWindowMac()
140 MacInvalidateBorders() ;
142 #ifndef __WXUNIVERSAL__
143 // VS: make sure there's no wxFrame with last focus set to us:
144 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
146 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
149 if ( frame
->GetLastFocus() == this )
150 frame
->SetLastFocus(NULL
);
156 // destroy children before destroying this window itself
159 // wxRemoveMacControlAssociation( this ) ;
160 // If we delete an item, we should initialize the parent panel,
161 // because it could now be invalid.
162 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
165 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
166 tlw
->SetDefaultItem(NULL
);
169 if ( g_MacLastWindow
== this )
170 g_MacLastWindow
= NULL
;
172 #ifndef __WXUNIVERSAL__
173 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
176 if ( frame
->GetLastFocus() == this )
177 frame
->SetLastFocus( NULL
) ;
181 // delete our drop target if we've got one
182 #if wxUSE_DRAG_AND_DROP
183 if ( m_dropTarget
!= NULL
)
193 WXWidget
wxWindowMac::GetHandle() const
196 return (WXWidget
) m_peer
->GetWXWidget() ;
200 // ---------------------------------------------------------------------------
201 // Utility Routines to move between different coordinate systems
202 // ---------------------------------------------------------------------------
205 * Right now we have the following setup :
206 * a border that is not part of the native control is always outside the
207 * control's border (otherwise we loose all native intelligence, future ways
208 * may be to have a second embedding control responsible for drawing borders
209 * and backgrounds eventually)
210 * so all this border calculations have to be taken into account when calling
211 * native methods or getting native oriented data
212 * so we have three coordinate systems here
213 * wx client coordinates
214 * wx window coordinates (including window frames)
222 bool wxWindowMac::Create(wxWindowMac
*parent
,
227 const wxString
& name
)
229 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
231 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
234 m_windowVariant
= parent
->GetWindowVariant() ;
236 if ( m_macIsUserPane
)
238 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
239 MacPostControlCreate(pos
, size
) ;
242 #ifndef __WXUNIVERSAL__
243 // Don't give scrollbars to wxControls unless they ask for them
244 if ( (! IsKindOf(CLASSINFO(wxControl
))
246 && ! IsKindOf(CLASSINFO(wxStatusBar
))
249 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
251 MacCreateScrollBars( style
) ;
255 wxWindowCreateEvent
event((wxWindow
*)this);
256 GetEventHandler()->AddPendingEvent(event
);
261 void wxWindowMac::MacChildAdded()
265 m_vScrollBar
->Raise() ;
267 m_hScrollBar
->Raise() ;
273 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
275 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
277 GetParent()->AddChild( this );
279 m_peer
->InstallEventHandler();
280 m_peer
->Embed(GetParent()->GetPeer());
282 GetParent()->MacChildAdded() ;
284 // adjust font, controlsize etc
285 DoSetWindowVariant( m_windowVariant
) ;
287 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
289 // for controls we want to use best size for wxDefaultSize params )
290 if ( !m_macIsUserPane
)
291 SetInitialSize(size
);
293 SetCursor( *wxSTANDARD_CURSOR
) ;
296 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
298 // Don't assert, in case we set the window variant before
299 // the window is created
300 // wxASSERT( m_peer->Ok() ) ;
302 m_windowVariant
= variant
;
304 if (m_peer
== NULL
|| !m_peer
->IsOk())
307 m_peer
->SetControlSize( variant
);
311 // we will get that from the settings later
312 // and make this NORMAL later, but first
313 // we have a few calculations that we must fix
317 case wxWINDOW_VARIANT_NORMAL
:
318 size
= kControlSizeNormal
;
321 case wxWINDOW_VARIANT_SMALL
:
322 size
= kControlSizeSmall
;
325 case wxWINDOW_VARIANT_MINI
:
326 // not always defined in the headers
330 case wxWINDOW_VARIANT_LARGE
:
331 size
= kControlSizeLarge
;
335 wxFAIL_MSG(wxT("unexpected window variant"));
338 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
343 wxOSXSystemFont systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
347 case wxWINDOW_VARIANT_NORMAL
:
348 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
351 case wxWINDOW_VARIANT_SMALL
:
352 systemFont
= wxOSX_SYSTEM_FONT_SMALL
;
355 case wxWINDOW_VARIANT_MINI
:
356 systemFont
= wxOSX_SYSTEM_FONT_MINI
;
359 case wxWINDOW_VARIANT_LARGE
:
360 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
364 wxFAIL_MSG(wxT("unexpected window variant"));
368 font
.CreateSystemFont( systemFont
) ;
373 void wxWindowMac::MacUpdateControlFont()
376 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
378 // do not trigger refreshes upon invisible and possible partly created objects
379 if ( IsShownOnScreen() )
383 bool wxWindowMac::SetFont(const wxFont
& font
)
385 bool retval
= wxWindowBase::SetFont( font
);
387 MacUpdateControlFont() ;
392 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
394 bool retval
= wxWindowBase::SetForegroundColour( col
);
397 MacUpdateControlFont();
402 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
404 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
408 m_peer
->SetBackgroundColour( col
) ;
413 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
415 while (w
&& !w
->IsTopLevel())
424 void wxWindowMac::SetFocus()
426 if ( !AcceptsFocus() )
429 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
432 wxWindow
* former
= FindFocus() ;
433 if ( former
== this )
439 void wxWindowMac::DoCaptureMouse()
441 wxApp::s_captureWindow
= (wxWindow
*) this ;
442 m_peer
->CaptureMouse() ;
445 wxWindow
* wxWindowBase::GetCapture()
447 return wxApp::s_captureWindow
;
450 void wxWindowMac::DoReleaseMouse()
452 wxApp::s_captureWindow
= NULL
;
454 m_peer
->ReleaseMouse() ;
457 #if wxUSE_DRAG_AND_DROP
459 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
463 m_dropTarget
= pDropTarget
;
464 if ( m_dropTarget
!= NULL
)
472 // Old-style File Manager Drag & Drop
473 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
478 // From a wx position / size calculate the appropriate size of the native control
480 bool wxWindowMac::MacGetBoundsForControl(
484 int& w
, int& h
, bool adjustOrigin
) const
486 // the desired size, minus the border pixels gives the correct size of the control
490 w
= WidthDefault( size
.x
);
491 h
= HeightDefault( size
.y
);
493 x
+= MacGetLeftBorderSize() ;
494 y
+= MacGetTopBorderSize() ;
495 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
496 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
499 AdjustForParentClientOrigin( x
, y
) ;
501 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
502 if ( GetParent() && !GetParent()->IsTopLevel() )
504 x
-= GetParent()->MacGetLeftBorderSize() ;
505 y
-= GetParent()->MacGetTopBorderSize() ;
511 // Get window size (not client size)
512 void wxWindowMac::DoGetSize(int *x
, int *y
) const
515 m_peer
->GetSize( width
, height
);
518 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
520 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
523 // get the position of the bounds of this window in client coordinates of its parent
524 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
528 m_peer
->GetPosition( x1
, y1
) ;
530 // get the wx window position from the native one
531 x1
-= MacGetLeftBorderSize() ;
532 y1
-= MacGetTopBorderSize() ;
536 wxWindow
*parent
= GetParent();
539 // we must first adjust it to be in window coordinates of the parent,
540 // as otherwise it gets lost by the ClientAreaOrigin fix
541 x1
+= parent
->MacGetLeftBorderSize() ;
542 y1
+= parent
->MacGetTopBorderSize() ;
544 // and now to client coordinates
545 wxPoint
pt(parent
->GetClientAreaOrigin());
557 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
559 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
560 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
561 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
562 MacRootWindowToWindow( x
, y
) ;
564 wxPoint origin
= GetClientAreaOrigin() ;
571 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
573 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
574 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
576 wxPoint origin
= GetClientAreaOrigin() ;
582 MacWindowToRootWindow( x
, y
) ;
583 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
586 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
588 wxPoint origin
= GetClientAreaOrigin() ;
594 MacWindowToRootWindow( x
, y
) ;
597 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
608 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
611 pt
.x
-= MacGetLeftBorderSize() ;
612 pt
.y
-= MacGetTopBorderSize() ;
613 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
623 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
634 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
637 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
638 pt
.x
+= MacGetLeftBorderSize() ;
639 pt
.y
+= MacGetTopBorderSize() ;
649 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
651 wxSize sizeTotal
= size
;
653 int innerwidth
, innerheight
;
655 int outerwidth
, outerheight
;
657 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
658 m_peer
->GetSize( outerwidth
, outerheight
);
660 sizeTotal
.x
+= outerwidth
-innerwidth
;
661 sizeTotal
.y
+= outerheight
-innerheight
;
663 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
664 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
669 // Get size *available for subwindows* i.e. excluding menu bar etc.
670 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
676 m_peer
->GetContentArea( left
, top
, ww
, hh
);
678 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
679 hh
-= m_hScrollBar
->GetSize().y
;
681 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
682 ww
-= m_vScrollBar
->GetSize().x
;
691 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
693 if (m_cursor
.IsSameAs(cursor
))
698 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
703 if ( ! wxWindowBase::SetCursor( cursor
) )
707 wxASSERT_MSG( m_cursor
.Ok(),
708 wxT("cursor must be valid after call to the base version"));
710 if ( GetPeer() != NULL
)
711 GetPeer()->SetCursor( m_cursor
);
717 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
719 #ifndef __WXUNIVERSAL__
720 menu
->SetInvokingWindow((wxWindow
*)this);
723 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
725 wxPoint mouse
= wxGetMousePosition();
731 ClientToScreen( &x
, &y
) ;
733 menu
->GetPeer()->PopUp(this, x
, y
);
734 menu
->SetInvokingWindow( NULL
);
737 // actually this shouldn't be called, because universal is having its own implementation
743 // ----------------------------------------------------------------------------
745 // ----------------------------------------------------------------------------
749 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
751 wxWindowBase::DoSetToolTip(tooltip
);
754 m_tooltip
->SetWindow(this);
759 void wxWindowMac::MacInvalidateBorders()
761 if ( m_peer
== NULL
)
764 bool vis
= IsShownOnScreen() ;
768 int outerBorder
= MacGetLeftBorderSize() ;
770 if ( m_peer
->NeedsFocusRect() )
773 if ( outerBorder
== 0 )
776 // now we know that we have something to do at all
780 m_peer
->GetSize( tw
, th
);
781 m_peer
->GetPosition( tx
, ty
);
783 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
784 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
785 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
786 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
789 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
790 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
791 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
792 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
796 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
798 // this is never called for a toplevel window, so we know we have a parent
799 int former_x
, former_y
, former_w
, former_h
;
801 // Get true coordinates of former position
802 DoGetPosition( &former_x
, &former_y
) ;
803 DoGetSize( &former_w
, &former_h
) ;
805 wxWindow
*parent
= GetParent();
808 wxPoint
pt(parent
->GetClientAreaOrigin());
813 int actualWidth
= width
;
814 int actualHeight
= height
;
819 // min and max sizes are only for sizers, not for explicit size setting
820 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
821 actualWidth
= m_minWidth
;
822 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
823 actualHeight
= m_minHeight
;
824 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
825 actualWidth
= m_maxWidth
;
826 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
827 actualHeight
= m_maxHeight
;
830 bool doMove
= false, doResize
= false ;
832 if ( actualX
!= former_x
|| actualY
!= former_y
)
835 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
838 if ( doMove
|| doResize
)
840 // as the borders are drawn outside the native control, we adjust now
842 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
843 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
844 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
846 if ( parent
&& !parent
->IsTopLevel() )
848 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
851 MacInvalidateBorders() ;
853 m_cachedClippedRectValid
= false ;
855 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
857 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
859 MacInvalidateBorders() ;
861 MacRepositionScrollBars() ;
864 wxPoint
point(actualX
, actualY
);
865 wxMoveEvent
event(point
, m_windowId
);
866 event
.SetEventObject(this);
867 HandleWindowEvent(event
) ;
872 MacRepositionScrollBars() ;
873 wxSize
size(actualWidth
, actualHeight
);
874 wxSizeEvent
event(size
, m_windowId
);
875 event
.SetEventObject(this);
876 HandleWindowEvent(event
);
881 wxSize
wxWindowMac::DoGetBestSize() const
883 if ( m_macIsUserPane
|| IsTopLevel() )
885 return wxWindowBase::DoGetBestSize() ;
891 m_peer
->GetBestRect(&r
);
893 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
904 else if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
910 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
917 // return wxWindowBase::DoGetBestSize() ;
921 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
922 MacGetRightBorderSize();
923 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
924 MacGetBottomBorderSize();
925 if ( bestHeight
< 10 )
928 return wxSize(bestWidth
, bestHeight
);
932 // set the size of the window: if the dimensions are positive, just use them,
933 // but if any of them is equal to -1, it means that we must find the value for
934 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
935 // which case -1 is a valid value for x and y)
937 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
938 // the width/height to best suit our contents, otherwise we reuse the current
940 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
942 // get the current size and position...
943 int currentX
, currentY
;
944 int currentW
, currentH
;
946 GetPosition(¤tX
, ¤tY
);
947 GetSize(¤tW
, ¤tH
);
949 // ... and don't do anything (avoiding flicker) if it's already ok
950 if ( x
== currentX
&& y
== currentY
&&
951 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
954 MacRepositionScrollBars() ; // we might have a real position shift
956 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
958 wxSizeEvent
event( wxSize(width
,height
), GetId() );
959 event
.SetEventObject( this );
960 HandleWindowEvent( event
);
966 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
968 if ( x
== wxDefaultCoord
)
970 if ( y
== wxDefaultCoord
)
974 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
976 wxSize size
= wxDefaultSize
;
977 if ( width
== wxDefaultCoord
)
979 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
981 size
= DoGetBestSize();
986 // just take the current one
991 if ( height
== wxDefaultCoord
)
993 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
995 if ( size
.x
== wxDefaultCoord
)
996 size
= DoGetBestSize();
997 // else: already called DoGetBestSize() above
1003 // just take the current one
1008 DoMoveWindow( x
, y
, width
, height
);
1011 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1013 int left
,top
,width
,height
;
1014 m_peer
->GetContentArea( left
, top
, width
, height
);
1015 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1018 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1020 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1022 int currentclientwidth
, currentclientheight
;
1023 int currentwidth
, currentheight
;
1025 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1026 GetSize( ¤twidth
, ¤theight
) ;
1028 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1029 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1033 void wxWindowMac::SetLabel(const wxString
& title
)
1035 if ( title
== m_label
)
1040 InvalidateBestSize();
1042 if ( m_peer
&& m_peer
->IsOk() )
1043 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1045 // do not trigger refreshes upon invisible and possible partly created objects
1046 if ( IsShownOnScreen() )
1050 wxString
wxWindowMac::GetLabel() const
1055 bool wxWindowMac::Show(bool show
)
1057 if ( !wxWindowBase::Show(show
) )
1061 m_peer
->SetVisibility( show
) ;
1063 wxShowEvent
eventShow(GetId(), show
);
1064 eventShow
.SetEventObject(this);
1066 HandleWindowEvent(eventShow
);
1071 bool wxWindowMac::OSXShowWithEffect(bool show
,
1072 wxShowEffect effect
,
1075 if ( effect
== wxSHOW_EFFECT_NONE
||
1076 !m_peer
|| !m_peer
->ShowWithEffect(show
, effect
, timeout
) )
1082 void wxWindowMac::DoEnable(bool enable
)
1084 m_peer
->Enable( enable
) ;
1088 // status change notifications
1091 void wxWindowMac::MacVisibilityChanged()
1095 void wxWindowMac::MacHiliteChanged()
1099 void wxWindowMac::MacEnabledStateChanged()
1101 OnEnabled( m_peer
->IsEnabled() );
1105 // status queries on the inherited window's state
1108 bool wxWindowMac::MacIsReallyEnabled()
1110 return m_peer
->IsEnabled() ;
1113 bool wxWindowMac::MacIsReallyHilited()
1115 #if wxOSX_USE_CARBON
1116 return m_peer
->IsActive();
1118 return true; // TODO
1122 int wxWindowMac::GetCharHeight() const
1125 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1130 int wxWindowMac::GetCharWidth() const
1133 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1138 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1141 int *externalLeading
,
1142 const wxFont
*theFont
) const
1144 const wxFont
*fontToUse
= theFont
;
1148 tempFont
= GetFont();
1149 fontToUse
= &tempFont
;
1152 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1153 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1155 wxDouble h
, d
, e
, w
;
1156 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1160 if ( externalLeading
)
1161 *externalLeading
= (wxCoord
)(e
+0.5);
1163 *descent
= (wxCoord
)(d
+0.5);
1165 *x
= (wxCoord
)(w
+0.5);
1167 *y
= (wxCoord
)(h
+0.5);
1171 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1172 * we always intersect with the entire window, not only with the client area
1175 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1177 if ( m_peer
== NULL
)
1180 if ( !IsShownOnScreen() )
1183 m_peer
->SetNeedsDisplay( rect
) ;
1186 void wxWindowMac::DoFreeze()
1188 #if wxOSX_USE_CARBON
1189 if ( m_peer
&& m_peer
->IsOk() )
1190 m_peer
->SetDrawingEnabled( false ) ;
1194 void wxWindowMac::DoThaw()
1196 #if wxOSX_USE_CARBON
1197 if ( m_peer
&& m_peer
->IsOk() )
1199 m_peer
->SetDrawingEnabled( true ) ;
1200 m_peer
->InvalidateWithChildren() ;
1205 wxWindow
*wxGetActiveWindow()
1207 // actually this is a windows-only concept
1211 // Coordinates relative to the window
1212 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1214 #if wxOSX_USE_COCOA_OR_CARBON
1217 DoClientToScreen(&x
, &y
);
1218 CGPoint cgpoint
= CGPointMake( x
, y
);
1219 CGWarpMouseCursorPosition( cgpoint
);
1221 // At least GTK sends a mouse moved event after WarpMouse
1222 wxMouseEvent
event(wxEVT_MOTION
);
1225 wxMouseState mState
= ::wxGetMouseState();
1227 event
.m_altDown
= mState
.AltDown();
1228 event
.m_controlDown
= mState
.ControlDown();
1229 event
.m_leftDown
= mState
.LeftIsDown();
1230 event
.m_middleDown
= mState
.MiddleIsDown();
1231 event
.m_rightDown
= mState
.RightIsDown();
1232 event
.m_metaDown
= mState
.MetaDown();
1233 event
.m_shiftDown
= mState
.ShiftDown();
1234 event
.SetId(GetId());
1235 event
.SetEventObject(this);
1236 GetEventHandler()->ProcessEvent(event
);
1240 int wxWindowMac::GetScrollPos(int orient
) const
1243 if ( orient
== wxHORIZONTAL
)
1246 return m_hScrollBar
->GetThumbPosition() ;
1251 return m_vScrollBar
->GetThumbPosition() ;
1257 // This now returns the whole range, not just the number
1258 // of positions that we can scroll.
1259 int wxWindowMac::GetScrollRange(int orient
) const
1262 if ( orient
== wxHORIZONTAL
)
1265 return m_hScrollBar
->GetRange() ;
1270 return m_vScrollBar
->GetRange() ;
1276 int wxWindowMac::GetScrollThumb(int orient
) const
1279 if ( orient
== wxHORIZONTAL
)
1282 return m_hScrollBar
->GetThumbSize() ;
1287 return m_vScrollBar
->GetThumbSize() ;
1293 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1296 if ( orient
== wxHORIZONTAL
)
1299 m_hScrollBar
->SetThumbPosition( pos
) ;
1304 m_vScrollBar
->SetThumbPosition( pos
) ;
1310 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1312 bool needVisibilityUpdate
= false;
1314 if ( m_hScrollBarAlwaysShown
!= hflag
)
1316 m_hScrollBarAlwaysShown
= hflag
;
1317 needVisibilityUpdate
= true;
1320 if ( m_vScrollBarAlwaysShown
!= vflag
)
1322 m_vScrollBarAlwaysShown
= vflag
;
1323 needVisibilityUpdate
= true;
1326 if ( needVisibilityUpdate
)
1327 DoUpdateScrollbarVisibility();
1331 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1332 // our own window origin is at leftOrigin/rightOrigin
1335 void wxWindowMac::MacPaintGrowBox()
1341 if ( MacHasScrollBarCorner() )
1344 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1345 wxASSERT( cgContext
) ;
1349 m_peer
->GetSize( tw
, th
);
1350 m_peer
->GetPosition( tx
, ty
);
1352 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1355 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1356 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1357 CGContextSaveGState( cgContext
);
1359 if ( m_backgroundColour
.Ok() )
1361 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1365 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1367 CGContextFillRect( cgContext
, cgrect
);
1368 CGContextRestoreGState( cgContext
);
1372 if ( m_backgroundColour
.Ok() )
1373 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1375 m_growBox
->SetBackgroundColour(*wxWHITE
);
1383 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1388 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1390 // back to the surrounding frame rectangle
1393 m_peer
->GetSize( tw
, th
);
1394 m_peer
->GetPosition( tx
, ty
);
1396 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1398 #if wxOSX_USE_COCOA_OR_CARBON
1400 InsetRect( &rect
, -1 , -1 ) ;
1403 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1404 rect
.bottom
- rect
.top
) ;
1406 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1407 wxASSERT( cgContext
) ;
1409 if ( m_peer
->NeedsFrame() )
1411 HIThemeFrameDrawInfo info
;
1412 memset( &info
, 0 , sizeof(info
) ) ;
1416 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1417 info
.isFocused
= hasFocus
;
1419 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1421 info
.kind
= kHIThemeFrameTextFieldSquare
;
1422 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1424 else if ( HasFlag(wxSIMPLE_BORDER
) )
1426 info
.kind
= kHIThemeFrameListBox
;
1427 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1433 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1436 #endif // wxOSX_USE_COCOA_OR_CARBON
1439 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1442 if ( child
== m_hScrollBar
)
1443 m_hScrollBar
= NULL
;
1444 if ( child
== m_vScrollBar
)
1445 m_vScrollBar
= NULL
;
1446 if ( child
== m_growBox
)
1449 wxWindowBase::RemoveChild( child
) ;
1452 void wxWindowMac::DoUpdateScrollbarVisibility()
1455 bool triggerSizeEvent
= false;
1459 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1461 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1463 m_hScrollBar
->Show( showHScrollBar
);
1464 triggerSizeEvent
= true;
1470 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1472 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1474 m_vScrollBar
->Show( showVScrollBar
) ;
1475 triggerSizeEvent
= true;
1479 MacRepositionScrollBars() ;
1480 if ( triggerSizeEvent
)
1482 wxSizeEvent
event(GetSize(), m_windowId
);
1483 event
.SetEventObject(this);
1484 HandleWindowEvent(event
);
1489 // New function that will replace some of the above.
1490 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1491 int range
, bool refresh
)
1494 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1495 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1496 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1497 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1499 DoUpdateScrollbarVisibility();
1503 // Does a physical scroll
1504 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1506 if ( dx
== 0 && dy
== 0 )
1509 int width
, height
;
1510 GetClientSize( &width
, &height
) ;
1513 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1515 scrollrect
.Intersect( *rect
) ;
1516 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1517 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1519 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1524 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1526 child
= node
->GetData();
1530 if (child
== m_vScrollBar
)
1532 if (child
== m_hScrollBar
)
1534 if (child
== m_growBox
)
1537 if (child
->IsTopLevel())
1540 child
->GetPosition( &x
, &y
);
1541 child
->GetSize( &w
, &h
);
1544 wxRect
rc( x
, y
, w
, h
);
1545 if (rect
->Intersects( rc
))
1546 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1550 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1555 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1558 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1560 wxScrollWinEvent wevent
;
1561 wevent
.SetPosition(event
.GetPosition());
1562 wevent
.SetOrientation(event
.GetOrientation());
1563 wevent
.SetEventObject(this);
1565 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1566 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1567 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1568 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1569 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1570 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1571 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1572 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1573 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1574 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1575 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1576 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1577 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1578 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1579 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1580 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1582 HandleWindowEvent(wevent
);
1587 wxWindow
*wxWindowBase::DoFindFocus()
1589 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1592 void wxWindowMac::OnInternalIdle()
1594 // This calls the UI-update mechanism (querying windows for
1595 // menu/toolbar/control state information)
1596 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1597 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1600 // Raise the window to the top of the Z order
1601 void wxWindowMac::Raise()
1606 // Lower the window to the bottom of the Z order
1607 void wxWindowMac::Lower()
1612 // static wxWindow *gs_lastWhich = NULL;
1614 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1616 // first trigger a set cursor event
1618 wxPoint clientorigin
= GetClientAreaOrigin() ;
1619 wxSize clientsize
= GetClientSize() ;
1621 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1623 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1625 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1626 if ( processedEvtSetCursor
&& event
.HasCursor() )
1628 cursor
= event
.GetCursor() ;
1632 // the test for processedEvtSetCursor is here to prevent using m_cursor
1633 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1634 // it - this is a way to say that our cursor shouldn't be used for this
1636 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1639 if ( !wxIsBusy() && !GetParent() )
1640 cursor
= *wxSTANDARD_CURSOR
;
1644 cursor
.MacInstall() ;
1647 return cursor
.Ok() ;
1650 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1654 return m_tooltip
->GetTip() ;
1657 return wxEmptyString
;
1660 void wxWindowMac::ClearBackground()
1666 void wxWindowMac::Update()
1668 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1673 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1675 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1679 if ( iter
->IsTopLevel() )
1681 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1685 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1690 iter
= iter
->GetParent() ;
1696 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1698 MacUpdateClippedRects() ;
1700 return m_cachedClippedClientRect
;
1703 const wxRect
& wxWindowMac::MacGetClippedRect() const
1705 MacUpdateClippedRects() ;
1707 return m_cachedClippedRect
;
1710 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1712 MacUpdateClippedRects() ;
1714 return m_cachedClippedRectWithOuterStructure
;
1717 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1719 static wxRegion emptyrgn
;
1721 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1723 MacUpdateClippedRects() ;
1724 if ( includeOuterStructures
)
1725 return m_cachedClippedRegionWithOuterStructure
;
1727 return m_cachedClippedRegion
;
1735 void wxWindowMac::MacUpdateClippedRects() const
1737 #if wxOSX_USE_CARBON
1738 if ( m_cachedClippedRectValid
)
1741 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1742 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1743 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1744 // to add focus borders everywhere
1746 Rect rIncludingOuterStructures
;
1750 m_peer
->GetSize( tw
, th
);
1751 m_peer
->GetPosition( tx
, ty
);
1753 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1755 r
.left
-= MacGetLeftBorderSize() ;
1756 r
.top
-= MacGetTopBorderSize() ;
1757 r
.bottom
+= MacGetBottomBorderSize() ;
1758 r
.right
+= MacGetRightBorderSize() ;
1765 rIncludingOuterStructures
= r
;
1766 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1768 wxRect cl
= GetClientRect() ;
1769 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1773 const wxWindow
* child
= (wxWindow
*) this ;
1774 const wxWindow
* parent
= NULL
;
1776 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1778 if ( parent
->MacIsChildOfClientArea(child
) )
1780 size
= parent
->GetClientSize() ;
1781 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1787 // this will be true for scrollbars, toolbars etc.
1788 size
= parent
->GetSize() ;
1789 y
= parent
->MacGetTopBorderSize() ;
1790 x
= parent
->MacGetLeftBorderSize() ;
1791 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1792 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1795 parent
->MacWindowToRootWindow( &x
, &y
) ;
1796 MacRootWindowToWindow( &x
, &y
) ;
1798 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1800 // the wxwindow and client rects will always be clipped
1801 SectRect( &r
, &rparent
, &r
) ;
1802 SectRect( &rClient
, &rparent
, &rClient
) ;
1804 // the structure only at 'hard' borders
1805 if ( parent
->MacClipChildren() ||
1806 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1808 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1814 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1815 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1816 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1817 m_cachedClippedRectWithOuterStructure
= wxRect(
1818 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1819 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1820 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1822 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1823 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1824 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1826 m_cachedClippedRectValid
= true ;
1831 This function must not change the updatergn !
1833 bool wxWindowMac::MacDoRedraw( long time
)
1835 bool handled
= false ;
1837 wxRegion formerUpdateRgn
= m_updateRegion
;
1838 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1840 const wxRect clientRect
= GetClientRect();
1842 clientUpdateRgn
.Intersect(clientRect
);
1844 // first send an erase event to the entire update area
1845 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1848 case wxBG_STYLE_ERASE
:
1849 case wxBG_STYLE_SYSTEM
:
1851 // for the toplevel window this really is the entire area for
1852 // all the others only their client area, otherwise they might
1853 // be drawing with full alpha and eg put blue into the grow-box
1854 // area of a scrolled window (scroll sample)
1855 wxWindowDC
dc(this);
1857 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1859 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1861 if ( bgStyle
== wxBG_STYLE_ERASE
)
1863 wxEraseEvent
eevent( GetId(), &dc
);
1864 eevent
.SetEventObject( this );
1865 if ( ProcessWindowEvent( eevent
) )
1871 dc
.SetBackground(GetBackgroundColour());
1877 case wxBG_STYLE_PAINT
:
1878 case wxBG_STYLE_TRANSPARENT
:
1879 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1880 // entire window client area
1884 wxFAIL_MSG( "unsupported background style" );
1889 // calculate a client-origin version of the update rgn and set
1890 // m_updateRegion to that
1891 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1892 m_updateRegion
= clientUpdateRgn
;
1894 if ( !m_updateRegion
.Empty() )
1896 // paint the window itself
1898 wxPaintEvent
event(GetId());
1899 event
.SetTimestamp(time
);
1900 event
.SetEventObject(this);
1901 handled
= HandleWindowEvent(event
);
1904 m_updateRegion
= formerUpdateRgn
;
1908 void wxWindowMac::MacPaintChildrenBorders()
1910 // now we cannot rely on having its borders drawn by a window itself, as it does not
1911 // get the updateRgn wide enough to always do so, so we do it from the parent
1912 // this would also be the place to draw any custom backgrounds for native controls
1913 // in Composited windowing
1914 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1918 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1920 child
= node
->GetData();
1924 if (child
== m_vScrollBar
)
1926 if (child
== m_hScrollBar
)
1928 if (child
== m_growBox
)
1931 if (child
->IsTopLevel())
1933 if (!child
->IsShown())
1936 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1938 child
->GetPosition( &x
, &y
);
1939 child
->GetSize( &w
, &h
);
1941 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
1943 // paint custom borders
1944 wxNcPaintEvent
eventNc( child
->GetId() );
1945 eventNc
.SetEventObject( child
);
1946 if ( !child
->HandleWindowEvent( eventNc
) )
1948 child
->MacPaintBorders(0, 0) ;
1955 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1957 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1958 return tlw
? tlw
->GetWXWindow() : NULL
;
1961 bool wxWindowMac::MacHasScrollBarCorner() const
1964 /* Returns whether the scroll bars in a wxScrolledWindow should be
1965 * shortened. Scroll bars should be shortened if either:
1967 * - both scroll bars are visible, or
1969 * - there is a resize box in the parent frame's corner and this
1970 * window shares the bottom and right edge with the parent
1974 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1977 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1978 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1980 // Both scroll bars visible
1985 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1987 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1989 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1992 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1994 // Parent frame has resize handle
1995 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1997 // Note: allow for some wiggle room here as wxMac's
1998 // window rect calculations seem to be imprecise
1999 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2000 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2002 // Parent frame has resize handle and shares
2003 // right bottom corner
2008 // Parent frame has resize handle but doesn't
2009 // share right bottom corner
2015 // Parent frame doesn't have resize handle
2021 // No parent frame found
2029 void wxWindowMac::MacCreateScrollBars( long style
)
2032 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2034 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2036 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2037 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2039 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2042 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2044 GetClientSize( &width
, &height
) ;
2046 wxPoint
vPoint(width
- scrlsize
, 0) ;
2047 wxSize
vSize(scrlsize
, height
- adjust
) ;
2048 wxPoint
hPoint(0, height
- scrlsize
) ;
2049 wxSize
hSize(width
- adjust
, scrlsize
) ;
2051 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2052 if ( style
& wxVSCROLL
)
2054 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2055 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2058 if ( style
& wxHSCROLL
)
2060 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2061 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2064 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2065 wxSize
gSize(scrlsize
, scrlsize
);
2066 m_growBox
= new wxPanel((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2069 // because the create does not take into account the client area origin
2070 // we might have a real position shift
2071 MacRepositionScrollBars() ;
2075 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2077 bool result
= ((child
== NULL
)
2079 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2086 void wxWindowMac::MacRepositionScrollBars()
2089 if ( !m_hScrollBar
&& !m_vScrollBar
)
2092 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2093 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2095 // get real client area
2097 GetSize( &width
, &height
);
2099 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2100 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2102 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2103 wxSize
vSize( scrlsize
, height
- adjust
) ;
2104 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2105 wxSize
hSize( width
- adjust
, scrlsize
) ;
2108 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2110 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2113 if ( MacHasScrollBarCorner() )
2115 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2116 if ( !m_growBox
->IsShown() )
2121 if ( m_growBox
->IsShown() )
2128 bool wxWindowMac::AcceptsFocus() const
2130 if ( MacIsUserPane() )
2131 return wxWindowBase::AcceptsFocus();
2133 return m_peer
->CanFocus();
2136 void wxWindowMac::MacSuperChangedPosition()
2138 // only window-absolute structures have to be moved i.e. controls
2140 m_cachedClippedRectValid
= false ;
2143 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2146 child
= node
->GetData();
2147 child
->MacSuperChangedPosition() ;
2149 node
= node
->GetNext();
2153 void wxWindowMac::MacTopLevelWindowChangedPosition()
2155 // only screen-absolute structures have to be moved i.e. glcanvas
2158 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2161 child
= node
->GetData();
2162 child
->MacTopLevelWindowChangedPosition() ;
2164 node
= node
->GetNext();
2168 long wxWindowMac::MacGetLeftBorderSize() const
2175 if ( m_peer
&& m_peer
->NeedsFrame() )
2177 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2179 #if wxOSX_USE_COCOA_OR_CARBON
2180 // this metric is only the 'outset' outside the simple frame rect
2181 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2187 else if (HasFlag(wxSIMPLE_BORDER
))
2189 #if wxOSX_USE_COCOA_OR_CARBON
2190 // this metric is only the 'outset' outside the simple frame rect
2191 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2202 long wxWindowMac::MacGetRightBorderSize() const
2204 // they are all symmetric in mac themes
2205 return MacGetLeftBorderSize() ;
2208 long wxWindowMac::MacGetTopBorderSize() const
2210 // they are all symmetric in mac themes
2211 return MacGetLeftBorderSize() ;
2214 long wxWindowMac::MacGetBottomBorderSize() const
2216 // they are all symmetric in mac themes
2217 return MacGetLeftBorderSize() ;
2220 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2222 return style
& ~wxBORDER_MASK
;
2225 // Find the wxWindowMac at the current mouse position, returning the mouse
2227 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2229 pt
= wxGetMousePosition();
2230 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2232 return (wxWindow
*) found
;
2235 // Get the current mouse position.
2236 wxPoint
wxGetMousePosition()
2240 wxGetMousePosition( &x
, &y
);
2242 return wxPoint(x
, y
);
2245 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2247 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2249 // copied from wxGTK : CS
2250 // VZ: shouldn't we move this to base class then?
2252 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2255 // (a) it's a command event and so is propagated to the parent
2256 // (b) under MSW it can be generated from kbd too
2257 // (c) it uses screen coords (because of (a))
2258 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2260 this->ClientToScreen(event
.GetPosition()));
2261 evtCtx
.SetEventObject(this);
2262 if ( ! HandleWindowEvent(evtCtx
) )
2271 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2275 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2279 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2280 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2285 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2290 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2292 #if wxOSX_USE_COCOA_OR_CARBON
2293 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2296 return eventNotHandledErr
;
2302 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2304 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2305 if ( !wxWindowBase::Reparent(newParent
) )
2308 m_peer
->RemoveFromParent();
2309 m_peer
->Embed( GetParent()->GetPeer() );
2315 bool wxWindowMac::SetTransparent(wxByte alpha
)
2317 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2319 if ( alpha
!= m_macAlpha
)
2321 m_macAlpha
= alpha
;
2328 bool wxWindowMac::CanSetTransparent()
2333 wxByte
wxWindowMac::GetTransparent() const
2338 bool wxWindowMac::IsShownOnScreen() const
2340 if ( m_peer
&& m_peer
->IsOk() )
2342 bool peerVis
= m_peer
->IsVisible();
2343 bool wxVis
= wxWindowBase::IsShownOnScreen();
2344 if( peerVis
!= wxVis
)
2346 // CS : put a breakpoint here to investigate differences
2347 // between native an wx visibilities
2348 // the only place where I've encountered them until now
2349 // are the hiding/showing sequences where the vis-changed event is
2350 // first sent to the innermost control, while wx does things
2351 // from the outmost control
2352 wxVis
= wxWindowBase::IsShownOnScreen();
2356 return m_peer
->IsVisible();
2358 return wxWindowBase::IsShownOnScreen();
2361 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2363 bool handled
= HandleWindowEvent( event
) ;
2364 if ( handled
&& event
.GetSkipped() )
2368 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2370 wxWindow
*ancestor
= this;
2373 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2376 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2378 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2379 handled
= handler
->ProcessEvent( command_event
);
2383 // accelerators can also be used with buttons, try them too
2384 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2385 handled
= handler
->ProcessEvent( command_event
);
2391 if (ancestor
->IsTopLevel())
2394 ancestor
= ancestor
->GetParent();
2397 #endif // wxUSE_ACCEL
2406 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2408 static MacControlMap wxWinMacControlList
;
2410 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2412 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2414 return impl
->GetWXPeer();
2419 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2421 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2423 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2426 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2428 // adding NULL ControlRef is (first) surely a result of an error and
2429 // (secondly) breaks native event processing
2430 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2432 wxWinMacControlList
[inControl
] = impl
;
2435 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2437 // iterate over all the elements in the class
2438 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2439 // we should go on...
2445 MacControlMap::iterator it
;
2446 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2448 if ( it
->second
== impl
)
2450 wxWinMacControlList
.erase(it
);
2458 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2460 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2463 m_isRootControl
= isRootControl
;
2467 wxWidgetImpl::wxWidgetImpl()
2472 wxWidgetImpl::~wxWidgetImpl()
2476 void wxWidgetImpl::Init()
2478 m_isRootControl
= false;
2480 m_needsFocusRect
= false;
2481 m_needsFrame
= true;
2484 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2486 m_needsFocusRect
= needs
;
2489 bool wxWidgetImpl::NeedsFocusRect() const
2491 return m_needsFocusRect
;
2494 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2496 m_needsFrame
= needs
;
2499 bool wxWidgetImpl::NeedsFrame() const
2501 return m_needsFrame
;