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 WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1195 // We really don't move the mouse programmatically under Mac.
1198 int wxWindowMac::GetScrollPos(int orient
) const
1201 if ( orient
== wxHORIZONTAL
)
1204 return m_hScrollBar
->GetThumbPosition() ;
1209 return m_vScrollBar
->GetThumbPosition() ;
1215 // This now returns the whole range, not just the number
1216 // of positions that we can scroll.
1217 int wxWindowMac::GetScrollRange(int orient
) const
1220 if ( orient
== wxHORIZONTAL
)
1223 return m_hScrollBar
->GetRange() ;
1228 return m_vScrollBar
->GetRange() ;
1234 int wxWindowMac::GetScrollThumb(int orient
) const
1237 if ( orient
== wxHORIZONTAL
)
1240 return m_hScrollBar
->GetThumbSize() ;
1245 return m_vScrollBar
->GetThumbSize() ;
1251 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1254 if ( orient
== wxHORIZONTAL
)
1257 m_hScrollBar
->SetThumbPosition( pos
) ;
1262 m_vScrollBar
->SetThumbPosition( pos
) ;
1268 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1270 bool needVisibilityUpdate
= false;
1272 if ( m_hScrollBarAlwaysShown
!= hflag
)
1274 m_hScrollBarAlwaysShown
= hflag
;
1275 needVisibilityUpdate
= true;
1278 if ( m_vScrollBarAlwaysShown
!= vflag
)
1280 m_vScrollBarAlwaysShown
= vflag
;
1281 needVisibilityUpdate
= true;
1284 if ( needVisibilityUpdate
)
1285 DoUpdateScrollbarVisibility();
1289 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1290 // our own window origin is at leftOrigin/rightOrigin
1293 void wxWindowMac::MacPaintGrowBox()
1299 if ( MacHasScrollBarCorner() )
1301 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1302 wxASSERT( cgContext
) ;
1306 m_peer
->GetSize( tw
, th
);
1307 m_peer
->GetPosition( tx
, ty
);
1309 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1312 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1313 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1314 CGContextSaveGState( cgContext
);
1316 if ( m_backgroundColour
.Ok() )
1318 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1322 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1324 CGContextFillRect( cgContext
, cgrect
);
1325 CGContextRestoreGState( cgContext
);
1330 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1335 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1337 // back to the surrounding frame rectangle
1340 m_peer
->GetSize( tw
, th
);
1341 m_peer
->GetPosition( tx
, ty
);
1343 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1345 #if wxOSX_USE_COCOA_OR_CARBON
1347 InsetRect( &rect
, -1 , -1 ) ;
1350 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1351 rect
.bottom
- rect
.top
) ;
1353 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1354 wxASSERT( cgContext
) ;
1356 if ( m_peer
->NeedsFrame() )
1358 HIThemeFrameDrawInfo info
;
1359 memset( &info
, 0 , sizeof(info
) ) ;
1363 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1364 info
.isFocused
= hasFocus
;
1366 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1368 info
.kind
= kHIThemeFrameTextFieldSquare
;
1369 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1371 else if ( HasFlag(wxSIMPLE_BORDER
) )
1373 info
.kind
= kHIThemeFrameListBox
;
1374 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1380 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1383 #endif // wxOSX_USE_COCOA_OR_CARBON
1386 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1389 if ( child
== m_hScrollBar
)
1390 m_hScrollBar
= NULL
;
1391 if ( child
== m_vScrollBar
)
1392 m_vScrollBar
= NULL
;
1394 wxWindowBase::RemoveChild( child
) ;
1397 void wxWindowMac::DoUpdateScrollbarVisibility()
1400 bool triggerSizeEvent
= false;
1404 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1406 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1408 m_hScrollBar
->Show( showHScrollBar
);
1409 triggerSizeEvent
= true;
1415 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1417 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1419 m_vScrollBar
->Show( showVScrollBar
) ;
1420 triggerSizeEvent
= true;
1424 MacRepositionScrollBars() ;
1425 if ( triggerSizeEvent
)
1427 wxSizeEvent
event(GetSize(), m_windowId
);
1428 event
.SetEventObject(this);
1429 HandleWindowEvent(event
);
1434 // New function that will replace some of the above.
1435 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1436 int range
, bool refresh
)
1439 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1440 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1441 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1442 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1444 DoUpdateScrollbarVisibility();
1448 // Does a physical scroll
1449 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1451 if ( dx
== 0 && dy
== 0 )
1454 int width
, height
;
1455 GetClientSize( &width
, &height
) ;
1458 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1460 scrollrect
.Intersect( *rect
) ;
1461 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1462 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1464 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1469 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1471 child
= node
->GetData();
1475 if (child
== m_vScrollBar
)
1477 if (child
== m_hScrollBar
)
1480 if (child
->IsTopLevel())
1483 child
->GetPosition( &x
, &y
);
1484 child
->GetSize( &w
, &h
);
1487 wxRect
rc( x
, y
, w
, h
);
1488 if (rect
->Intersects( rc
))
1489 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1493 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1498 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1501 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1503 wxScrollWinEvent wevent
;
1504 wevent
.SetPosition(event
.GetPosition());
1505 wevent
.SetOrientation(event
.GetOrientation());
1506 wevent
.SetEventObject(this);
1508 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1509 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1510 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1511 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1512 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1513 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1514 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1515 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1516 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1517 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1518 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1519 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1520 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1521 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1522 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1523 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1525 HandleWindowEvent(wevent
);
1530 wxWindow
*wxWindowBase::DoFindFocus()
1532 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1535 void wxWindowMac::OnInternalIdle()
1537 // This calls the UI-update mechanism (querying windows for
1538 // menu/toolbar/control state information)
1539 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1540 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1543 // Raise the window to the top of the Z order
1544 void wxWindowMac::Raise()
1549 // Lower the window to the bottom of the Z order
1550 void wxWindowMac::Lower()
1555 // static wxWindow *gs_lastWhich = NULL;
1557 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1559 // first trigger a set cursor event
1561 wxPoint clientorigin
= GetClientAreaOrigin() ;
1562 wxSize clientsize
= GetClientSize() ;
1564 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1566 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1568 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1569 if ( processedEvtSetCursor
&& event
.HasCursor() )
1571 cursor
= event
.GetCursor() ;
1575 // the test for processedEvtSetCursor is here to prevent using m_cursor
1576 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1577 // it - this is a way to say that our cursor shouldn't be used for this
1579 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1582 if ( !wxIsBusy() && !GetParent() )
1583 cursor
= *wxSTANDARD_CURSOR
;
1587 cursor
.MacInstall() ;
1590 return cursor
.Ok() ;
1593 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1597 return m_tooltip
->GetTip() ;
1600 return wxEmptyString
;
1603 void wxWindowMac::ClearBackground()
1609 void wxWindowMac::Update()
1611 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1616 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1618 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1622 if ( iter
->IsTopLevel() )
1624 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1628 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1633 iter
= iter
->GetParent() ;
1639 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1641 MacUpdateClippedRects() ;
1643 return m_cachedClippedClientRect
;
1646 const wxRect
& wxWindowMac::MacGetClippedRect() const
1648 MacUpdateClippedRects() ;
1650 return m_cachedClippedRect
;
1653 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1655 MacUpdateClippedRects() ;
1657 return m_cachedClippedRectWithOuterStructure
;
1660 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1662 static wxRegion emptyrgn
;
1664 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1666 MacUpdateClippedRects() ;
1667 if ( includeOuterStructures
)
1668 return m_cachedClippedRegionWithOuterStructure
;
1670 return m_cachedClippedRegion
;
1678 void wxWindowMac::MacUpdateClippedRects() const
1680 #if wxOSX_USE_CARBON
1681 if ( m_cachedClippedRectValid
)
1684 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1685 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1686 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1687 // to add focus borders everywhere
1689 Rect rIncludingOuterStructures
;
1693 m_peer
->GetSize( tw
, th
);
1694 m_peer
->GetPosition( tx
, ty
);
1696 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1698 r
.left
-= MacGetLeftBorderSize() ;
1699 r
.top
-= MacGetTopBorderSize() ;
1700 r
.bottom
+= MacGetBottomBorderSize() ;
1701 r
.right
+= MacGetRightBorderSize() ;
1708 rIncludingOuterStructures
= r
;
1709 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1711 wxRect cl
= GetClientRect() ;
1712 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1716 const wxWindow
* child
= (wxWindow
*) this ;
1717 const wxWindow
* parent
= NULL
;
1719 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1721 if ( parent
->MacIsChildOfClientArea(child
) )
1723 size
= parent
->GetClientSize() ;
1724 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1730 // this will be true for scrollbars, toolbars etc.
1731 size
= parent
->GetSize() ;
1732 y
= parent
->MacGetTopBorderSize() ;
1733 x
= parent
->MacGetLeftBorderSize() ;
1734 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1735 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1738 parent
->MacWindowToRootWindow( &x
, &y
) ;
1739 MacRootWindowToWindow( &x
, &y
) ;
1741 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1743 // the wxwindow and client rects will always be clipped
1744 SectRect( &r
, &rparent
, &r
) ;
1745 SectRect( &rClient
, &rparent
, &rClient
) ;
1747 // the structure only at 'hard' borders
1748 if ( parent
->MacClipChildren() ||
1749 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1751 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1757 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1758 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1759 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1760 m_cachedClippedRectWithOuterStructure
= wxRect(
1761 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1762 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1763 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1765 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1766 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1767 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1769 m_cachedClippedRectValid
= true ;
1774 This function must not change the updatergn !
1776 bool wxWindowMac::MacDoRedraw( long time
)
1778 bool handled
= false ;
1780 wxRegion formerUpdateRgn
= m_updateRegion
;
1781 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1783 const wxRect clientRect
= GetClientRect();
1785 clientUpdateRgn
.Intersect(clientRect
);
1787 // first send an erase event to the entire update area
1788 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1791 case wxBG_STYLE_ERASE
:
1792 case wxBG_STYLE_SYSTEM
:
1794 // for the toplevel window this really is the entire area for
1795 // all the others only their client area, otherwise they might
1796 // be drawing with full alpha and eg put blue into the grow-box
1797 // area of a scrolled window (scroll sample)
1798 wxWindowDC
dc(this);
1800 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1802 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1804 if ( bgStyle
== wxBG_STYLE_ERASE
)
1806 wxEraseEvent
eevent( GetId(), &dc
);
1807 eevent
.SetEventObject( this );
1808 if ( ProcessWindowEvent( eevent
) )
1814 dc
.SetBackground(GetBackgroundColour());
1820 case wxBG_STYLE_PAINT
:
1821 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1822 // entire window client area
1826 wxFAIL_MSG( "unsupported background style" );
1831 // calculate a client-origin version of the update rgn and set
1832 // m_updateRegion to that
1833 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1834 m_updateRegion
= clientUpdateRgn
;
1836 if ( !m_updateRegion
.Empty() )
1838 // paint the window itself
1840 wxPaintEvent
event(GetId());
1841 event
.SetTimestamp(time
);
1842 event
.SetEventObject(this);
1843 handled
= HandleWindowEvent(event
);
1846 m_updateRegion
= formerUpdateRgn
;
1850 void wxWindowMac::MacPaintChildrenBorders()
1852 // now we cannot rely on having its borders drawn by a window itself, as it does not
1853 // get the updateRgn wide enough to always do so, so we do it from the parent
1854 // this would also be the place to draw any custom backgrounds for native controls
1855 // in Composited windowing
1856 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1860 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1862 child
= node
->GetData();
1866 if (child
== m_vScrollBar
)
1868 if (child
== m_hScrollBar
)
1871 if (child
->IsTopLevel())
1873 if (!child
->IsShown())
1876 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1878 child
->GetPosition( &x
, &y
);
1879 child
->GetSize( &w
, &h
);
1881 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
1883 // paint custom borders
1884 wxNcPaintEvent
eventNc( child
->GetId() );
1885 eventNc
.SetEventObject( child
);
1886 if ( !child
->HandleWindowEvent( eventNc
) )
1888 child
->MacPaintBorders(0, 0) ;
1895 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1897 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1898 return tlw
? tlw
->GetWXWindow() : NULL
;
1901 bool wxWindowMac::MacHasScrollBarCorner() const
1904 /* Returns whether the scroll bars in a wxScrolledWindow should be
1905 * shortened. Scroll bars should be shortened if either:
1907 * - both scroll bars are visible, or
1909 * - there is a resize box in the parent frame's corner and this
1910 * window shares the bottom and right edge with the parent
1914 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1917 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1918 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1920 // Both scroll bars visible
1925 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1927 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1929 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1932 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1934 // Parent frame has resize handle
1935 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1937 // Note: allow for some wiggle room here as wxMac's
1938 // window rect calculations seem to be imprecise
1939 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1940 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1942 // Parent frame has resize handle and shares
1943 // right bottom corner
1948 // Parent frame has resize handle but doesn't
1949 // share right bottom corner
1955 // Parent frame doesn't have resize handle
1961 // No parent frame found
1969 void wxWindowMac::MacCreateScrollBars( long style
)
1972 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1974 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1976 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1977 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1979 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
1982 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
1984 GetClientSize( &width
, &height
) ;
1986 wxPoint
vPoint(width
- scrlsize
, 0) ;
1987 wxSize
vSize(scrlsize
, height
- adjust
) ;
1988 wxPoint
hPoint(0, height
- scrlsize
) ;
1989 wxSize
hSize(width
- adjust
, scrlsize
) ;
1991 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
1992 if ( style
& wxVSCROLL
)
1994 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
1995 m_vScrollBar
->SetMinSize( wxDefaultSize
);
1998 if ( style
& wxHSCROLL
)
2000 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2001 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2005 // because the create does not take into account the client area origin
2006 // we might have a real position shift
2007 MacRepositionScrollBars() ;
2011 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2013 bool result
= ((child
== NULL
)
2015 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
))
2022 void wxWindowMac::MacRepositionScrollBars()
2025 if ( !m_hScrollBar
&& !m_vScrollBar
)
2028 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2029 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2031 // get real client area
2033 GetSize( &width
, &height
);
2035 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2036 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2038 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2039 wxSize
vSize( scrlsize
, height
- adjust
) ;
2040 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2041 wxSize
hSize( width
- adjust
, scrlsize
) ;
2044 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2046 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2050 bool wxWindowMac::AcceptsFocus() const
2052 if ( MacIsUserPane() )
2053 return wxWindowBase::AcceptsFocus();
2055 return m_peer
->CanFocus();
2058 void wxWindowMac::MacSuperChangedPosition()
2060 // only window-absolute structures have to be moved i.e. controls
2062 m_cachedClippedRectValid
= false ;
2065 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2068 child
= node
->GetData();
2069 child
->MacSuperChangedPosition() ;
2071 node
= node
->GetNext();
2075 void wxWindowMac::MacTopLevelWindowChangedPosition()
2077 // only screen-absolute structures have to be moved i.e. glcanvas
2080 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2083 child
= node
->GetData();
2084 child
->MacTopLevelWindowChangedPosition() ;
2086 node
= node
->GetNext();
2090 long wxWindowMac::MacGetLeftBorderSize() const
2097 if ( m_peer
&& m_peer
->NeedsFrame() )
2099 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2101 #if wxOSX_USE_COCOA_OR_CARBON
2102 // this metric is only the 'outset' outside the simple frame rect
2103 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2109 else if (HasFlag(wxSIMPLE_BORDER
))
2111 #if wxOSX_USE_COCOA_OR_CARBON
2112 // this metric is only the 'outset' outside the simple frame rect
2113 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2124 long wxWindowMac::MacGetRightBorderSize() const
2126 // they are all symmetric in mac themes
2127 return MacGetLeftBorderSize() ;
2130 long wxWindowMac::MacGetTopBorderSize() const
2132 // they are all symmetric in mac themes
2133 return MacGetLeftBorderSize() ;
2136 long wxWindowMac::MacGetBottomBorderSize() const
2138 // they are all symmetric in mac themes
2139 return MacGetLeftBorderSize() ;
2142 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2144 return style
& ~wxBORDER_MASK
;
2147 // Find the wxWindowMac at the current mouse position, returning the mouse
2149 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2151 pt
= wxGetMousePosition();
2152 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2154 return (wxWindow
*) found
;
2157 // Get the current mouse position.
2158 wxPoint
wxGetMousePosition()
2162 wxGetMousePosition( &x
, &y
);
2164 return wxPoint(x
, y
);
2167 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2169 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2171 // copied from wxGTK : CS
2172 // VZ: shouldn't we move this to base class then?
2174 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2177 // (a) it's a command event and so is propagated to the parent
2178 // (b) under MSW it can be generated from kbd too
2179 // (c) it uses screen coords (because of (a))
2180 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2182 this->ClientToScreen(event
.GetPosition()));
2183 evtCtx
.SetEventObject(this);
2184 if ( ! HandleWindowEvent(evtCtx
) )
2193 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2197 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2201 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2202 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2207 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2212 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2214 #if wxOSX_USE_COCOA_OR_CARBON
2215 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2218 return eventNotHandledErr
;
2224 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2226 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2227 if ( !wxWindowBase::Reparent(newParent
) )
2230 m_peer
->RemoveFromParent();
2231 m_peer
->Embed( GetParent()->GetPeer() );
2235 bool wxWindowMac::SetTransparent(wxByte alpha
)
2237 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2239 if ( alpha
!= m_macAlpha
)
2241 m_macAlpha
= alpha
;
2248 bool wxWindowMac::CanSetTransparent()
2253 wxByte
wxWindowMac::GetTransparent() const
2258 bool wxWindowMac::IsShownOnScreen() const
2260 if ( m_peer
&& m_peer
->IsOk() )
2262 bool peerVis
= m_peer
->IsVisible();
2263 bool wxVis
= wxWindowBase::IsShownOnScreen();
2264 if( peerVis
!= wxVis
)
2266 // CS : put a breakpoint here to investigate differences
2267 // between native an wx visibilities
2268 // the only place where I've encountered them until now
2269 // are the hiding/showing sequences where the vis-changed event is
2270 // first sent to the innermost control, while wx does things
2271 // from the outmost control
2272 wxVis
= wxWindowBase::IsShownOnScreen();
2276 return m_peer
->IsVisible();
2278 return wxWindowBase::IsShownOnScreen();
2281 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2283 bool handled
= HandleWindowEvent( event
) ;
2284 if ( handled
&& event
.GetSkipped() )
2288 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2290 wxWindow
*ancestor
= this;
2293 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2296 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2298 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2299 handled
= handler
->ProcessEvent( command_event
);
2303 // accelerators can also be used with buttons, try them too
2304 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2305 handled
= handler
->ProcessEvent( command_event
);
2311 if (ancestor
->IsTopLevel())
2314 ancestor
= ancestor
->GetParent();
2317 #endif // wxUSE_ACCEL
2326 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2328 static MacControlMap wxWinMacControlList
;
2330 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2332 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2334 return impl
->GetWXPeer();
2339 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2341 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2343 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2346 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2348 // adding NULL ControlRef is (first) surely a result of an error and
2349 // (secondly) breaks native event processing
2350 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2352 wxWinMacControlList
[inControl
] = impl
;
2355 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2357 // iterate over all the elements in the class
2358 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2359 // we should go on...
2365 MacControlMap::iterator it
;
2366 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2368 if ( it
->second
== impl
)
2370 wxWinMacControlList
.erase(it
);
2378 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2380 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2383 m_isRootControl
= isRootControl
;
2387 wxWidgetImpl::wxWidgetImpl()
2392 wxWidgetImpl::~wxWidgetImpl()
2396 void wxWidgetImpl::Init()
2398 m_isRootControl
= false;
2400 m_needsFocusRect
= false;
2401 m_needsFrame
= true;
2404 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2406 m_needsFocusRect
= needs
;
2409 bool wxWidgetImpl::NeedsFocusRect() const
2411 return m_needsFocusRect
;
2414 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2416 m_needsFrame
= needs
;
2419 bool wxWidgetImpl::NeedsFrame() const
2421 return m_needsFrame
;