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 // the grow box has to be implemented as an inactive window, so that nothing can direct
99 class WXDLLIMPEXP_CORE wxBlindPlateWindow
: public wxWindow
102 wxBlindPlateWindow() { Init(); }
104 // Old-style constructor (no default values for coordinates to avoid
105 // ambiguity with the new one)
106 wxBlindPlateWindow(wxWindow
*parent
,
107 int x
, int y
, int width
, int height
,
108 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
109 const wxString
& name
= wxPanelNameStr
)
113 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), style
, name
);
117 wxBlindPlateWindow(wxWindow
*parent
,
118 wxWindowID winid
= wxID_ANY
,
119 const wxPoint
& pos
= wxDefaultPosition
,
120 const wxSize
& size
= wxDefaultSize
,
121 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
122 const wxString
& name
= wxPanelNameStr
)
126 Create(parent
, winid
, pos
, size
, style
, name
);
130 bool Create(wxWindow
*parent
,
131 wxWindowID winid
= wxID_ANY
,
132 const wxPoint
& pos
= wxDefaultPosition
,
133 const wxSize
& size
= wxDefaultSize
,
134 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
135 const wxString
& name
= wxPanelNameStr
)
137 if ( !wxWindow::Create(parent
, winid
, pos
, size
, style
, name
) )
140 // so that non-solid background renders correctly under GTK+:
141 SetThemeEnabled(true);
144 virtual ~wxBlindPlateWindow();
146 virtual bool AcceptsFocus() const
152 // common part of all ctors
157 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow
)
158 DECLARE_EVENT_TABLE()
161 wxBlindPlateWindow::~wxBlindPlateWindow()
165 IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow
, wxWindow
)
167 BEGIN_EVENT_TABLE(wxBlindPlateWindow
, wxWindow
)
171 // ----------------------------------------------------------------------------
172 // constructors and such
173 // ----------------------------------------------------------------------------
175 wxWindowMac::wxWindowMac()
180 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
185 const wxString
& name
)
188 Create(parent
, id
, pos
, size
, style
, name
);
191 void wxWindowMac::Init()
195 m_cgContextRef
= NULL
;
197 // as all windows are created with WS_VISIBLE style...
200 m_hScrollBar
= NULL
;
201 m_vScrollBar
= NULL
;
202 m_hScrollBarAlwaysShown
= false;
203 m_vScrollBarAlwaysShown
= false;
206 m_macIsUserPane
= true;
207 m_clipChildren
= false ;
208 m_cachedClippedRectValid
= false ;
209 m_isNativeWindowWrapper
= false;
212 wxWindowMac::~wxWindowMac()
216 MacInvalidateBorders() ;
218 #ifndef __WXUNIVERSAL__
219 // VS: make sure there's no wxFrame with last focus set to us:
220 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
222 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
225 if ( frame
->GetLastFocus() == this )
226 frame
->SetLastFocus(NULL
);
232 // destroy children before destroying this window itself
235 // wxRemoveMacControlAssociation( this ) ;
236 // If we delete an item, we should initialize the parent panel,
237 // because it could now be invalid.
238 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
241 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
242 tlw
->SetDefaultItem(NULL
);
245 if ( g_MacLastWindow
== this )
246 g_MacLastWindow
= NULL
;
248 #ifndef __WXUNIVERSAL__
249 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
252 if ( frame
->GetLastFocus() == this )
253 frame
->SetLastFocus( NULL
) ;
257 // delete our drop target if we've got one
258 #if wxUSE_DRAG_AND_DROP
259 if ( m_dropTarget
!= NULL
)
269 WXWidget
wxWindowMac::GetHandle() const
272 return (WXWidget
) m_peer
->GetWXWidget() ;
276 // ---------------------------------------------------------------------------
277 // Utility Routines to move between different coordinate systems
278 // ---------------------------------------------------------------------------
281 * Right now we have the following setup :
282 * a border that is not part of the native control is always outside the
283 * control's border (otherwise we loose all native intelligence, future ways
284 * may be to have a second embedding control responsible for drawing borders
285 * and backgrounds eventually)
286 * so all this border calculations have to be taken into account when calling
287 * native methods or getting native oriented data
288 * so we have three coordinate systems here
289 * wx client coordinates
290 * wx window coordinates (including window frames)
298 bool wxWindowMac::Create(wxWindowMac
*parent
,
303 const wxString
& name
)
305 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
307 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
310 m_windowVariant
= parent
->GetWindowVariant() ;
312 if ( m_macIsUserPane
)
314 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
315 MacPostControlCreate(pos
, size
) ;
318 #ifndef __WXUNIVERSAL__
319 // Don't give scrollbars to wxControls unless they ask for them
320 if ( (! IsKindOf(CLASSINFO(wxControl
))
322 && ! IsKindOf(CLASSINFO(wxStatusBar
))
325 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
327 MacCreateScrollBars( style
) ;
331 wxWindowCreateEvent
event((wxWindow
*)this);
332 GetEventHandler()->AddPendingEvent(event
);
337 void wxWindowMac::MacChildAdded()
341 m_vScrollBar
->Raise() ;
343 m_hScrollBar
->Raise() ;
349 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
351 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
353 GetParent()->AddChild( this );
355 m_peer
->InstallEventHandler();
356 m_peer
->Embed(GetParent()->GetPeer());
358 GetParent()->MacChildAdded() ;
360 // adjust font, controlsize etc
361 DoSetWindowVariant( m_windowVariant
) ;
363 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
365 // for controls we want to use best size for wxDefaultSize params )
366 if ( !m_macIsUserPane
)
367 SetInitialSize(size
);
369 SetCursor( *wxSTANDARD_CURSOR
) ;
372 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
374 // Don't assert, in case we set the window variant before
375 // the window is created
376 // wxASSERT( m_peer->Ok() ) ;
378 m_windowVariant
= variant
;
380 if (m_peer
== NULL
|| !m_peer
->IsOk())
383 m_peer
->SetControlSize( variant
);
387 // we will get that from the settings later
388 // and make this NORMAL later, but first
389 // we have a few calculations that we must fix
393 case wxWINDOW_VARIANT_NORMAL
:
394 size
= kControlSizeNormal
;
397 case wxWINDOW_VARIANT_SMALL
:
398 size
= kControlSizeSmall
;
401 case wxWINDOW_VARIANT_MINI
:
402 // not always defined in the headers
406 case wxWINDOW_VARIANT_LARGE
:
407 size
= kControlSizeLarge
;
411 wxFAIL_MSG(wxT("unexpected window variant"));
414 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
420 case wxWINDOW_VARIANT_NORMAL
:
421 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
425 case wxWINDOW_VARIANT_SMALL
:
426 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
430 case wxWINDOW_VARIANT_MINI
:
431 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
435 case wxWINDOW_VARIANT_LARGE
:
436 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
441 wxFAIL_MSG(wxT("unexpected window variant"));
446 void wxWindowMac::MacUpdateControlFont()
449 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
451 // do not trigger refreshes upon invisible and possible partly created objects
452 if ( IsShownOnScreen() )
456 bool wxWindowMac::SetFont(const wxFont
& font
)
458 bool retval
= wxWindowBase::SetFont( font
);
460 MacUpdateControlFont() ;
465 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
467 bool retval
= wxWindowBase::SetForegroundColour( col
);
470 MacUpdateControlFont();
475 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
477 if ( !wxWindowBase::SetBackgroundStyle(style
) )
481 m_peer
->SetBackgroundStyle(style
);
485 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
489 if ( m_backgroundColour
.Ok() )
490 m_growBox
->SetBackgroundColour(m_backgroundColour
);
492 m_growBox
->SetBackgroundColour(*wxWHITE
);
495 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
499 m_peer
->SetBackgroundColour( col
) ;
504 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
506 while (w
&& !w
->IsTopLevel())
515 void wxWindowMac::SetFocus()
517 if ( !AcceptsFocus() )
520 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
523 wxWindow
* former
= FindFocus() ;
524 if ( former
== this )
530 void wxWindowMac::DoCaptureMouse()
532 wxApp::s_captureWindow
= (wxWindow
*) this ;
533 m_peer
->CaptureMouse() ;
536 wxWindow
* wxWindowBase::GetCapture()
538 return wxApp::s_captureWindow
;
541 void wxWindowMac::DoReleaseMouse()
543 wxApp::s_captureWindow
= NULL
;
545 m_peer
->ReleaseMouse() ;
548 #if wxUSE_DRAG_AND_DROP
550 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
554 m_dropTarget
= pDropTarget
;
555 if ( m_dropTarget
!= NULL
)
563 // Old-style File Manager Drag & Drop
564 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
569 // From a wx position / size calculate the appropriate size of the native control
571 bool wxWindowMac::MacGetBoundsForControl(
575 int& w
, int& h
, bool adjustOrigin
) const
577 // the desired size, minus the border pixels gives the correct size of the control
581 w
= WidthDefault( size
.x
);
582 h
= HeightDefault( size
.y
);
584 x
+= MacGetLeftBorderSize() ;
585 y
+= MacGetTopBorderSize() ;
586 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
587 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
590 AdjustForParentClientOrigin( x
, y
) ;
592 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
593 if ( GetParent() && !GetParent()->IsTopLevel() )
595 x
-= GetParent()->MacGetLeftBorderSize() ;
596 y
-= GetParent()->MacGetTopBorderSize() ;
602 // Get window size (not client size)
603 void wxWindowMac::DoGetSize(int *x
, int *y
) const
606 m_peer
->GetSize( width
, height
);
609 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
611 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
614 // get the position of the bounds of this window in client coordinates of its parent
615 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
619 m_peer
->GetPosition( x1
, y1
) ;
621 // get the wx window position from the native one
622 x1
-= MacGetLeftBorderSize() ;
623 y1
-= MacGetTopBorderSize() ;
627 wxWindow
*parent
= GetParent();
630 // we must first adjust it to be in window coordinates of the parent,
631 // as otherwise it gets lost by the ClientAreaOrigin fix
632 x1
+= parent
->MacGetLeftBorderSize() ;
633 y1
+= parent
->MacGetTopBorderSize() ;
635 // and now to client coordinates
636 wxPoint
pt(parent
->GetClientAreaOrigin());
648 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
650 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
651 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
652 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
653 MacRootWindowToWindow( x
, y
) ;
655 wxPoint origin
= GetClientAreaOrigin() ;
662 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
664 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
665 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
667 wxPoint origin
= GetClientAreaOrigin() ;
673 MacWindowToRootWindow( x
, y
) ;
674 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
677 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
679 wxPoint origin
= GetClientAreaOrigin() ;
685 MacWindowToRootWindow( x
, y
) ;
688 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
699 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
702 pt
.x
-= MacGetLeftBorderSize() ;
703 pt
.y
-= MacGetTopBorderSize() ;
704 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
714 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
725 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
728 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
729 pt
.x
+= MacGetLeftBorderSize() ;
730 pt
.y
+= MacGetTopBorderSize() ;
740 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
742 wxSize sizeTotal
= size
;
744 int innerwidth
, innerheight
;
746 int outerwidth
, outerheight
;
748 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
749 m_peer
->GetSize( outerwidth
, outerheight
);
751 sizeTotal
.x
+= outerwidth
-innerwidth
;
752 sizeTotal
.y
+= outerheight
-innerheight
;
754 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
755 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
760 // Get size *available for subwindows* i.e. excluding menu bar etc.
761 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
767 m_peer
->GetContentArea( left
, top
, ww
, hh
);
769 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
770 hh
-= m_hScrollBar
->GetSize().y
;
772 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
773 ww
-= m_vScrollBar
->GetSize().x
;
782 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
784 if (m_cursor
.IsSameAs(cursor
))
789 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
794 if ( ! wxWindowBase::SetCursor( cursor
) )
798 wxASSERT_MSG( m_cursor
.Ok(),
799 wxT("cursor must be valid after call to the base version"));
801 if ( GetPeer() != NULL
)
802 GetPeer()->SetCursor( m_cursor
);
808 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
810 #ifndef __WXUNIVERSAL__
811 menu
->SetInvokingWindow((wxWindow
*)this);
814 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
816 wxPoint mouse
= wxGetMousePosition();
822 ClientToScreen( &x
, &y
) ;
824 menu
->GetPeer()->PopUp(this, x
, y
);
825 menu
->SetInvokingWindow( NULL
);
828 // actually this shouldn't be called, because universal is having its own implementation
834 // ----------------------------------------------------------------------------
836 // ----------------------------------------------------------------------------
840 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
842 wxWindowBase::DoSetToolTip(tooltip
);
845 m_tooltip
->SetWindow(this);
848 m_peer
->SetToolTip(tooltip
);
853 void wxWindowMac::MacInvalidateBorders()
855 if ( m_peer
== NULL
)
858 bool vis
= IsShownOnScreen() ;
862 int outerBorder
= MacGetLeftBorderSize() ;
864 if ( m_peer
->NeedsFocusRect() )
867 if ( outerBorder
== 0 )
870 // now we know that we have something to do at all
874 m_peer
->GetSize( tw
, th
);
875 m_peer
->GetPosition( tx
, ty
);
877 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
878 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
879 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
880 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
883 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
884 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
885 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
886 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
890 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
892 // this is never called for a toplevel window, so we know we have a parent
893 int former_x
, former_y
, former_w
, former_h
;
895 // Get true coordinates of former position
896 DoGetPosition( &former_x
, &former_y
) ;
897 DoGetSize( &former_w
, &former_h
) ;
899 wxWindow
*parent
= GetParent();
902 wxPoint
pt(parent
->GetClientAreaOrigin());
907 int actualWidth
= width
;
908 int actualHeight
= height
;
913 // min and max sizes are only for sizers, not for explicit size setting
914 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
915 actualWidth
= m_minWidth
;
916 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
917 actualHeight
= m_minHeight
;
918 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
919 actualWidth
= m_maxWidth
;
920 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
921 actualHeight
= m_maxHeight
;
924 bool doMove
= false, doResize
= false ;
926 if ( actualX
!= former_x
|| actualY
!= former_y
)
929 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
932 if ( doMove
|| doResize
)
934 // as the borders are drawn outside the native control, we adjust now
936 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
937 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
938 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
940 if ( parent
&& !parent
->IsTopLevel() )
942 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
945 MacInvalidateBorders() ;
947 m_cachedClippedRectValid
= false ;
949 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
951 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
953 MacInvalidateBorders() ;
955 MacRepositionScrollBars() ;
958 wxPoint
point(actualX
, actualY
);
959 wxMoveEvent
event(point
, m_windowId
);
960 event
.SetEventObject(this);
961 HandleWindowEvent(event
) ;
966 MacRepositionScrollBars() ;
967 wxSize
size(actualWidth
, actualHeight
);
968 wxSizeEvent
event(size
, m_windowId
);
969 event
.SetEventObject(this);
970 HandleWindowEvent(event
);
975 wxSize
wxWindowMac::DoGetBestSize() const
977 if ( m_macIsUserPane
|| IsTopLevel() )
979 return wxWindowBase::DoGetBestSize() ;
985 m_peer
->GetBestRect(&r
);
987 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
995 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1002 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1009 // return wxWindowBase::DoGetBestSize() ;
1013 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1014 MacGetRightBorderSize();
1015 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1016 MacGetBottomBorderSize();
1017 if ( bestHeight
< 10 )
1020 return wxSize(bestWidth
, bestHeight
);
1024 // set the size of the window: if the dimensions are positive, just use them,
1025 // but if any of them is equal to -1, it means that we must find the value for
1026 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1027 // which case -1 is a valid value for x and y)
1029 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1030 // the width/height to best suit our contents, otherwise we reuse the current
1032 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1034 // get the current size and position...
1035 int currentX
, currentY
;
1036 int currentW
, currentH
;
1038 GetPosition(¤tX
, ¤tY
);
1039 GetSize(¤tW
, ¤tH
);
1041 // ... and don't do anything (avoiding flicker) if it's already ok
1042 if ( x
== currentX
&& y
== currentY
&&
1043 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1046 MacRepositionScrollBars() ; // we might have a real position shift
1048 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1050 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1051 event
.SetEventObject( this );
1052 HandleWindowEvent( event
);
1058 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1060 if ( x
== wxDefaultCoord
)
1062 if ( y
== wxDefaultCoord
)
1066 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1068 wxSize size
= wxDefaultSize
;
1069 if ( width
== wxDefaultCoord
)
1071 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1073 size
= DoGetBestSize();
1078 // just take the current one
1083 if ( height
== wxDefaultCoord
)
1085 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1087 if ( size
.x
== wxDefaultCoord
)
1088 size
= DoGetBestSize();
1089 // else: already called DoGetBestSize() above
1095 // just take the current one
1100 DoMoveWindow( x
, y
, width
, height
);
1103 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1105 int left
,top
,width
,height
;
1106 m_peer
->GetContentArea( left
, top
, width
, height
);
1107 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1110 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1112 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1114 int currentclientwidth
, currentclientheight
;
1115 int currentwidth
, currentheight
;
1117 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1118 GetSize( ¤twidth
, ¤theight
) ;
1120 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1121 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1125 void wxWindowMac::SetLabel(const wxString
& title
)
1127 if ( title
== m_label
)
1132 InvalidateBestSize();
1134 if ( m_peer
&& m_peer
->IsOk() )
1135 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1137 // do not trigger refreshes upon invisible and possible partly created objects
1138 if ( IsShownOnScreen() )
1142 wxString
wxWindowMac::GetLabel() const
1147 bool wxWindowMac::Show(bool show
)
1149 if ( !wxWindowBase::Show(show
) )
1153 m_peer
->SetVisibility( show
) ;
1155 #ifdef __WXOSX_IPHONE__
1156 // only when there's no native event support
1157 if ( !IsTopLevel() )
1160 wxShowEvent
eventShow(GetId(), show
);
1161 eventShow
.SetEventObject(this);
1163 HandleWindowEvent(eventShow
);
1169 bool wxWindowMac::OSXShowWithEffect(bool show
,
1170 wxShowEffect effect
,
1173 if ( effect
== wxSHOW_EFFECT_NONE
||
1174 !m_peer
|| !m_peer
->ShowWithEffect(show
, effect
, timeout
) )
1180 void wxWindowMac::DoEnable(bool enable
)
1182 m_peer
->Enable( enable
) ;
1183 MacInvalidateBorders();
1187 // status change notifications
1190 void wxWindowMac::MacVisibilityChanged()
1194 void wxWindowMac::MacHiliteChanged()
1198 void wxWindowMac::MacEnabledStateChanged()
1200 OnEnabled( m_peer
->IsEnabled() );
1204 // status queries on the inherited window's state
1207 bool wxWindowMac::MacIsReallyEnabled()
1209 return m_peer
->IsEnabled() ;
1212 bool wxWindowMac::MacIsReallyHilited()
1214 #if wxOSX_USE_CARBON
1215 return m_peer
->IsActive();
1217 return true; // TODO
1221 int wxWindowMac::GetCharHeight() const
1224 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1229 int wxWindowMac::GetCharWidth() const
1232 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1237 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1240 int *externalLeading
,
1241 const wxFont
*theFont
) const
1243 const wxFont
*fontToUse
= theFont
;
1247 tempFont
= GetFont();
1248 fontToUse
= &tempFont
;
1251 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1252 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1254 wxDouble h
, d
, e
, w
;
1255 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1259 if ( externalLeading
)
1260 *externalLeading
= (wxCoord
)(e
+0.5);
1262 *descent
= (wxCoord
)(d
+0.5);
1264 *x
= (wxCoord
)(w
+0.5);
1266 *y
= (wxCoord
)(h
+0.5);
1270 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1271 * we always intersect with the entire window, not only with the client area
1274 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1276 if ( m_peer
== NULL
)
1279 if ( !IsShownOnScreen() )
1282 m_peer
->SetNeedsDisplay( rect
) ;
1285 void wxWindowMac::DoFreeze()
1287 #if wxOSX_USE_CARBON
1288 if ( m_peer
&& m_peer
->IsOk() )
1289 m_peer
->SetDrawingEnabled( false ) ;
1293 void wxWindowMac::DoThaw()
1295 #if wxOSX_USE_CARBON
1296 if ( m_peer
&& m_peer
->IsOk() )
1298 m_peer
->SetDrawingEnabled( true ) ;
1299 m_peer
->InvalidateWithChildren() ;
1304 wxWindow
*wxGetActiveWindow()
1306 // actually this is a windows-only concept
1310 // Coordinates relative to the window
1311 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1313 #if wxOSX_USE_COCOA_OR_CARBON
1316 DoClientToScreen(&x
, &y
);
1317 CGPoint cgpoint
= CGPointMake( x
, y
);
1318 CGWarpMouseCursorPosition( cgpoint
);
1320 // At least GTK sends a mouse moved event after WarpMouse
1321 wxMouseEvent
event(wxEVT_MOTION
);
1324 wxMouseState mState
= ::wxGetMouseState();
1326 event
.m_altDown
= mState
.AltDown();
1327 event
.m_controlDown
= mState
.ControlDown();
1328 event
.m_leftDown
= mState
.LeftIsDown();
1329 event
.m_middleDown
= mState
.MiddleIsDown();
1330 event
.m_rightDown
= mState
.RightIsDown();
1331 event
.m_metaDown
= mState
.MetaDown();
1332 event
.m_shiftDown
= mState
.ShiftDown();
1333 event
.SetId(GetId());
1334 event
.SetEventObject(this);
1335 GetEventHandler()->ProcessEvent(event
);
1339 int wxWindowMac::GetScrollPos(int orient
) const
1342 if ( orient
== wxHORIZONTAL
)
1345 return m_hScrollBar
->GetThumbPosition() ;
1350 return m_vScrollBar
->GetThumbPosition() ;
1356 // This now returns the whole range, not just the number
1357 // of positions that we can scroll.
1358 int wxWindowMac::GetScrollRange(int orient
) const
1361 if ( orient
== wxHORIZONTAL
)
1364 return m_hScrollBar
->GetRange() ;
1369 return m_vScrollBar
->GetRange() ;
1375 int wxWindowMac::GetScrollThumb(int orient
) const
1378 if ( orient
== wxHORIZONTAL
)
1381 return m_hScrollBar
->GetThumbSize() ;
1386 return m_vScrollBar
->GetThumbSize() ;
1392 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1395 if ( orient
== wxHORIZONTAL
)
1398 m_hScrollBar
->SetThumbPosition( pos
) ;
1403 m_vScrollBar
->SetThumbPosition( pos
) ;
1409 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1411 bool needVisibilityUpdate
= false;
1413 if ( m_hScrollBarAlwaysShown
!= hflag
)
1415 m_hScrollBarAlwaysShown
= hflag
;
1416 needVisibilityUpdate
= true;
1419 if ( m_vScrollBarAlwaysShown
!= vflag
)
1421 m_vScrollBarAlwaysShown
= vflag
;
1422 needVisibilityUpdate
= true;
1425 if ( needVisibilityUpdate
)
1426 DoUpdateScrollbarVisibility();
1430 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1431 // our own window origin is at leftOrigin/rightOrigin
1434 void wxWindowMac::MacPaintGrowBox()
1440 if ( MacHasScrollBarCorner() )
1443 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1444 wxASSERT( cgContext
) ;
1448 m_peer
->GetSize( tw
, th
);
1449 m_peer
->GetPosition( tx
, ty
);
1451 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1454 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1455 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1456 CGContextSaveGState( cgContext
);
1458 if ( m_backgroundColour
.Ok() )
1460 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1464 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1466 CGContextFillRect( cgContext
, cgrect
);
1467 CGContextRestoreGState( cgContext
);
1471 if ( m_backgroundColour
.Ok() )
1472 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1474 m_growBox
->SetBackgroundColour(*wxWHITE
);
1482 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1487 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1489 // back to the surrounding frame rectangle
1492 m_peer
->GetSize( tw
, th
);
1493 m_peer
->GetPosition( tx
, ty
);
1495 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1497 #if wxOSX_USE_COCOA_OR_CARBON
1499 InsetRect( &rect
, -1 , -1 ) ;
1502 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1503 rect
.bottom
- rect
.top
) ;
1505 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1506 wxASSERT( cgContext
) ;
1508 if ( m_peer
->NeedsFrame() )
1510 HIThemeFrameDrawInfo info
;
1511 memset( &info
, 0 , sizeof(info
) ) ;
1515 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1516 info
.isFocused
= hasFocus
;
1518 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1520 info
.kind
= kHIThemeFrameTextFieldSquare
;
1521 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1523 else if ( HasFlag(wxSIMPLE_BORDER
) )
1525 info
.kind
= kHIThemeFrameListBox
;
1526 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1532 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1535 #endif // wxOSX_USE_COCOA_OR_CARBON
1538 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1541 if ( child
== m_hScrollBar
)
1542 m_hScrollBar
= NULL
;
1543 if ( child
== m_vScrollBar
)
1544 m_vScrollBar
= NULL
;
1545 if ( child
== m_growBox
)
1548 wxWindowBase::RemoveChild( child
) ;
1551 void wxWindowMac::DoUpdateScrollbarVisibility()
1554 bool triggerSizeEvent
= false;
1558 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1560 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1562 m_hScrollBar
->Show( showHScrollBar
);
1563 triggerSizeEvent
= true;
1569 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1571 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1573 m_vScrollBar
->Show( showVScrollBar
) ;
1574 triggerSizeEvent
= true;
1578 MacRepositionScrollBars() ;
1579 if ( triggerSizeEvent
)
1581 wxSizeEvent
event(GetSize(), m_windowId
);
1582 event
.SetEventObject(this);
1583 HandleWindowEvent(event
);
1588 // New function that will replace some of the above.
1589 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1590 int range
, bool refresh
)
1593 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1594 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1595 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1596 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1598 DoUpdateScrollbarVisibility();
1602 // Does a physical scroll
1603 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1605 if ( dx
== 0 && dy
== 0 )
1608 int width
, height
;
1609 GetClientSize( &width
, &height
) ;
1612 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1614 scrollrect
.Intersect( *rect
) ;
1615 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1616 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1618 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1623 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1625 child
= node
->GetData();
1629 if (child
->IsTopLevel())
1632 if ( !IsClientAreaChild(child
) )
1635 child
->GetPosition( &x
, &y
);
1636 child
->GetSize( &w
, &h
);
1639 wxRect
rc( x
, y
, w
, h
);
1640 if (rect
->Intersects( rc
))
1641 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1645 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1650 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1653 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1655 wxScrollWinEvent wevent
;
1656 wevent
.SetPosition(event
.GetPosition());
1657 wevent
.SetOrientation(event
.GetOrientation());
1658 wevent
.SetEventObject(this);
1660 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1661 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1662 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1663 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1664 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1665 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1666 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1667 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1668 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1669 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1670 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1671 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1672 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1673 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1674 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1675 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1677 HandleWindowEvent(wevent
);
1682 wxWindow
*wxWindowBase::DoFindFocus()
1684 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1687 void wxWindowMac::OnInternalIdle()
1689 // This calls the UI-update mechanism (querying windows for
1690 // menu/toolbar/control state information)
1691 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1692 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1695 // Raise the window to the top of the Z order
1696 void wxWindowMac::Raise()
1701 // Lower the window to the bottom of the Z order
1702 void wxWindowMac::Lower()
1707 // static wxWindow *gs_lastWhich = NULL;
1709 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1711 // first trigger a set cursor event
1713 wxPoint clientorigin
= GetClientAreaOrigin() ;
1714 wxSize clientsize
= GetClientSize() ;
1716 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1718 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1720 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1721 if ( processedEvtSetCursor
&& event
.HasCursor() )
1723 cursor
= event
.GetCursor() ;
1727 // the test for processedEvtSetCursor is here to prevent using m_cursor
1728 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1729 // it - this is a way to say that our cursor shouldn't be used for this
1731 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1734 if ( !wxIsBusy() && !GetParent() )
1735 cursor
= *wxSTANDARD_CURSOR
;
1739 cursor
.MacInstall() ;
1742 return cursor
.Ok() ;
1745 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1749 return m_tooltip
->GetTip() ;
1752 return wxEmptyString
;
1755 void wxWindowMac::ClearBackground()
1761 void wxWindowMac::Update()
1763 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1768 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1770 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1774 if ( iter
->IsTopLevel() )
1776 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1780 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1785 iter
= iter
->GetParent() ;
1791 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1793 MacUpdateClippedRects() ;
1795 return m_cachedClippedClientRect
;
1798 const wxRect
& wxWindowMac::MacGetClippedRect() const
1800 MacUpdateClippedRects() ;
1802 return m_cachedClippedRect
;
1805 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1807 MacUpdateClippedRects() ;
1809 return m_cachedClippedRectWithOuterStructure
;
1812 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1814 static wxRegion emptyrgn
;
1816 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1818 MacUpdateClippedRects() ;
1819 if ( includeOuterStructures
)
1820 return m_cachedClippedRegionWithOuterStructure
;
1822 return m_cachedClippedRegion
;
1830 void wxWindowMac::MacUpdateClippedRects() const
1832 #if wxOSX_USE_CARBON
1833 if ( m_cachedClippedRectValid
)
1836 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1837 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1838 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1839 // to add focus borders everywhere
1841 Rect rIncludingOuterStructures
;
1845 m_peer
->GetSize( tw
, th
);
1846 m_peer
->GetPosition( tx
, ty
);
1848 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1850 r
.left
-= MacGetLeftBorderSize() ;
1851 r
.top
-= MacGetTopBorderSize() ;
1852 r
.bottom
+= MacGetBottomBorderSize() ;
1853 r
.right
+= MacGetRightBorderSize() ;
1860 rIncludingOuterStructures
= r
;
1861 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1863 wxRect cl
= GetClientRect() ;
1864 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1868 const wxWindow
* child
= (wxWindow
*) this ;
1869 const wxWindow
* parent
= NULL
;
1871 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1873 if ( parent
->MacIsChildOfClientArea(child
) )
1875 size
= parent
->GetClientSize() ;
1876 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1882 // this will be true for scrollbars, toolbars etc.
1883 size
= parent
->GetSize() ;
1884 y
= parent
->MacGetTopBorderSize() ;
1885 x
= parent
->MacGetLeftBorderSize() ;
1886 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1887 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1890 parent
->MacWindowToRootWindow( &x
, &y
) ;
1891 MacRootWindowToWindow( &x
, &y
) ;
1893 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1895 // the wxwindow and client rects will always be clipped
1896 SectRect( &r
, &rparent
, &r
) ;
1897 SectRect( &rClient
, &rparent
, &rClient
) ;
1899 // the structure only at 'hard' borders
1900 if ( parent
->MacClipChildren() ||
1901 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1903 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1909 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1910 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1911 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1912 m_cachedClippedRectWithOuterStructure
= wxRect(
1913 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1914 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1915 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1917 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1918 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1919 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1921 m_cachedClippedRectValid
= true ;
1926 This function must not change the updatergn !
1928 bool wxWindowMac::MacDoRedraw( long time
)
1930 bool handled
= false ;
1932 wxRegion formerUpdateRgn
= m_updateRegion
;
1933 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1935 const wxRect clientRect
= GetClientRect();
1937 clientUpdateRgn
.Intersect(clientRect
);
1939 // first send an erase event to the entire update area
1940 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1943 case wxBG_STYLE_ERASE
:
1944 case wxBG_STYLE_SYSTEM
:
1945 case wxBG_STYLE_COLOUR
:
1947 // for the toplevel window this really is the entire area for
1948 // all the others only their client area, otherwise they might
1949 // be drawing with full alpha and eg put blue into the grow-box
1950 // area of a scrolled window (scroll sample)
1951 wxWindowDC
dc(this);
1953 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1955 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1957 if ( bgStyle
== wxBG_STYLE_ERASE
)
1959 wxEraseEvent
eevent( GetId(), &dc
);
1960 eevent
.SetEventObject( this );
1961 if ( ProcessWindowEvent( eevent
) )
1967 dc
.SetBackground(GetBackgroundColour());
1973 case wxBG_STYLE_PAINT
:
1974 case wxBG_STYLE_TRANSPARENT
:
1975 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1976 // entire window client area
1980 wxFAIL_MSG( "unsupported background style" );
1983 // as this is a full window, shouldn't be necessary anymore
1984 // MacPaintGrowBox();
1986 // calculate a client-origin version of the update rgn and set
1987 // m_updateRegion to that
1988 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1989 m_updateRegion
= clientUpdateRgn
;
1991 if ( !m_updateRegion
.Empty() )
1993 // paint the window itself
1995 wxPaintEvent
event(GetId());
1996 event
.SetTimestamp(time
);
1997 event
.SetEventObject(this);
1998 handled
= HandleWindowEvent(event
);
2001 m_updateRegion
= formerUpdateRgn
;
2005 void wxWindowMac::MacPaintChildrenBorders()
2007 // now we cannot rely on having its borders drawn by a window itself, as it does not
2008 // get the updateRgn wide enough to always do so, so we do it from the parent
2009 // this would also be the place to draw any custom backgrounds for native controls
2010 // in Composited windowing
2011 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2015 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2017 child
= node
->GetData();
2021 if (child
== m_vScrollBar
)
2023 if (child
== m_hScrollBar
)
2025 if (child
== m_growBox
)
2028 if (child
->IsTopLevel())
2030 if (!child
->IsShown())
2033 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2035 child
->GetPosition( &x
, &y
);
2036 child
->GetSize( &w
, &h
);
2038 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2040 // paint custom borders
2041 wxNcPaintEvent
eventNc( child
->GetId() );
2042 eventNc
.SetEventObject( child
);
2043 if ( !child
->HandleWindowEvent( eventNc
) )
2045 child
->MacPaintBorders(0, 0) ;
2052 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2054 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2055 return tlw
? tlw
->GetWXWindow() : NULL
;
2058 bool wxWindowMac::MacHasScrollBarCorner() const
2061 /* Returns whether the scroll bars in a wxScrolledWindow should be
2062 * shortened. Scroll bars should be shortened if either:
2064 * - both scroll bars are visible, or
2066 * - there is a resize box in the parent frame's corner and this
2067 * window shares the bottom and right edge with the parent
2071 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2074 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2075 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2077 // Both scroll bars visible
2082 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2084 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2086 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2089 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2091 // Parent frame has resize handle
2092 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2094 // Note: allow for some wiggle room here as wxMac's
2095 // window rect calculations seem to be imprecise
2096 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2097 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2099 // Parent frame has resize handle and shares
2100 // right bottom corner
2105 // Parent frame has resize handle but doesn't
2106 // share right bottom corner
2112 // Parent frame doesn't have resize handle
2118 // No parent frame found
2126 void wxWindowMac::MacCreateScrollBars( long style
)
2129 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2131 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2133 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2134 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2136 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2139 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2141 GetClientSize( &width
, &height
) ;
2143 wxPoint
vPoint(width
- scrlsize
, 0) ;
2144 wxSize
vSize(scrlsize
, height
- adjust
) ;
2145 wxPoint
hPoint(0, height
- scrlsize
) ;
2146 wxSize
hSize(width
- adjust
, scrlsize
) ;
2148 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2149 if ( style
& wxVSCROLL
)
2151 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2152 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2155 if ( style
& wxHSCROLL
)
2157 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2158 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2161 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2162 wxSize
gSize(scrlsize
, scrlsize
);
2163 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2166 // because the create does not take into account the client area origin
2167 // we might have a real position shift
2168 MacRepositionScrollBars() ;
2172 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2174 bool result
= ((child
== NULL
)
2176 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2183 void wxWindowMac::MacRepositionScrollBars()
2186 if ( !m_hScrollBar
&& !m_vScrollBar
)
2189 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2190 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2192 // get real client area
2194 GetSize( &width
, &height
);
2196 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2197 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2199 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2200 wxSize
vSize( scrlsize
, height
- adjust
) ;
2201 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2202 wxSize
hSize( width
- adjust
, scrlsize
) ;
2205 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2207 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2210 if ( MacHasScrollBarCorner() )
2212 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2213 if ( !m_growBox
->IsShown() )
2218 if ( m_growBox
->IsShown() )
2225 bool wxWindowMac::AcceptsFocus() const
2227 if ( MacIsUserPane() )
2228 return wxWindowBase::AcceptsFocus();
2230 return m_peer
->CanFocus();
2233 void wxWindowMac::MacSuperChangedPosition()
2235 // only window-absolute structures have to be moved i.e. controls
2237 m_cachedClippedRectValid
= false ;
2240 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2243 child
= node
->GetData();
2244 child
->MacSuperChangedPosition() ;
2246 node
= node
->GetNext();
2250 void wxWindowMac::MacTopLevelWindowChangedPosition()
2252 // only screen-absolute structures have to be moved i.e. glcanvas
2255 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2258 child
= node
->GetData();
2259 child
->MacTopLevelWindowChangedPosition() ;
2261 node
= node
->GetNext();
2265 long wxWindowMac::MacGetLeftBorderSize() const
2272 if ( m_peer
&& m_peer
->NeedsFrame() )
2274 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2276 #if wxOSX_USE_COCOA_OR_CARBON
2277 // this metric is only the 'outset' outside the simple frame rect
2278 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2284 else if (HasFlag(wxSIMPLE_BORDER
))
2286 #if wxOSX_USE_COCOA_OR_CARBON
2287 // this metric is only the 'outset' outside the simple frame rect
2288 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2299 long wxWindowMac::MacGetRightBorderSize() const
2301 // they are all symmetric in mac themes
2302 return MacGetLeftBorderSize() ;
2305 long wxWindowMac::MacGetTopBorderSize() const
2307 // they are all symmetric in mac themes
2308 return MacGetLeftBorderSize() ;
2311 long wxWindowMac::MacGetBottomBorderSize() const
2313 // they are all symmetric in mac themes
2314 return MacGetLeftBorderSize() ;
2317 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2319 return style
& ~wxBORDER_MASK
;
2322 // Find the wxWindowMac at the current mouse position, returning the mouse
2324 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2326 pt
= wxGetMousePosition();
2327 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2329 return (wxWindow
*) found
;
2332 // Get the current mouse position.
2333 wxPoint
wxGetMousePosition()
2337 wxGetMousePosition( &x
, &y
);
2339 return wxPoint(x
, y
);
2342 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2344 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2346 // copied from wxGTK : CS
2347 // VZ: shouldn't we move this to base class then?
2349 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2352 // (a) it's a command event and so is propagated to the parent
2353 // (b) under MSW it can be generated from kbd too
2354 // (c) it uses screen coords (because of (a))
2355 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2357 this->ClientToScreen(event
.GetPosition()));
2358 evtCtx
.SetEventObject(this);
2359 if ( ! HandleWindowEvent(evtCtx
) )
2368 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2372 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2376 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2377 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2382 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2387 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2389 #if wxOSX_USE_COCOA_OR_CARBON
2390 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2393 return eventNotHandledErr
;
2399 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2401 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2402 if ( !wxWindowBase::Reparent(newParent
) )
2405 m_peer
->RemoveFromParent();
2406 m_peer
->Embed( GetParent()->GetPeer() );
2412 bool wxWindowMac::SetTransparent(wxByte alpha
)
2414 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2416 if ( alpha
!= m_macAlpha
)
2418 m_macAlpha
= alpha
;
2425 bool wxWindowMac::CanSetTransparent()
2430 wxByte
wxWindowMac::GetTransparent() const
2435 bool wxWindowMac::IsShownOnScreen() const
2437 if ( m_peer
&& m_peer
->IsOk() )
2439 bool peerVis
= m_peer
->IsVisible();
2440 bool wxVis
= wxWindowBase::IsShownOnScreen();
2441 if( peerVis
!= wxVis
)
2443 // CS : put a breakpoint here to investigate differences
2444 // between native an wx visibilities
2445 // the only place where I've encountered them until now
2446 // are the hiding/showing sequences where the vis-changed event is
2447 // first sent to the innermost control, while wx does things
2448 // from the outmost control
2449 wxVis
= wxWindowBase::IsShownOnScreen();
2453 return m_peer
->IsVisible();
2455 return wxWindowBase::IsShownOnScreen();
2458 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2460 bool handled
= HandleWindowEvent( event
) ;
2461 if ( handled
&& event
.GetSkipped() )
2465 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2467 wxWindow
*ancestor
= this;
2470 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2473 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2475 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2476 handled
= handler
->ProcessEvent( command_event
);
2480 // accelerators can also be used with buttons, try them too
2481 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2482 handled
= handler
->ProcessEvent( command_event
);
2488 if (ancestor
->IsTopLevel())
2491 ancestor
= ancestor
->GetParent();
2494 #endif // wxUSE_ACCEL
2503 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2505 static MacControlMap wxWinMacControlList
;
2507 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2509 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2511 return impl
->GetWXPeer();
2516 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2518 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2520 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2523 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2525 // adding NULL ControlRef is (first) surely a result of an error and
2526 // (secondly) breaks native event processing
2527 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2529 wxWinMacControlList
[inControl
] = impl
;
2532 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2534 // iterate over all the elements in the class
2535 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2536 // we should go on...
2542 MacControlMap::iterator it
;
2543 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2545 if ( it
->second
== impl
)
2547 wxWinMacControlList
.erase(it
);
2555 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2557 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2560 m_isRootControl
= isRootControl
;
2562 m_shouldSendEvents
= true;
2565 wxWidgetImpl::wxWidgetImpl()
2570 wxWidgetImpl::~wxWidgetImpl()
2574 void wxWidgetImpl::Init()
2576 m_isRootControl
= false;
2578 m_needsFocusRect
= false;
2579 m_needsFrame
= true;
2582 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2584 m_needsFocusRect
= needs
;
2587 bool wxWidgetImpl::NeedsFocusRect() const
2589 return m_needsFocusRect
;
2592 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2594 m_needsFrame
= needs
;
2597 bool wxWidgetImpl::NeedsFrame() const
2599 return m_needsFrame
;