1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
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
)
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
85 #define wxMAC_DEBUG_REDRAW 0
86 #ifndef wxMAC_DEBUG_REDRAW
87 #define wxMAC_DEBUG_REDRAW 0
90 // ===========================================================================
92 // ===========================================================================
94 // the grow box has to be implemented as an inactive window, so that nothing can direct
97 class WXDLLIMPEXP_CORE wxBlindPlateWindow
: public wxWindow
100 wxBlindPlateWindow() { Init(); }
102 // Old-style constructor (no default values for coordinates to avoid
103 // ambiguity with the new one)
104 wxBlindPlateWindow(wxWindow
*parent
,
105 int x
, int y
, int width
, int height
,
106 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
107 const wxString
& name
= wxPanelNameStr
)
111 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), style
, name
);
115 wxBlindPlateWindow(wxWindow
*parent
,
116 wxWindowID winid
= wxID_ANY
,
117 const wxPoint
& pos
= wxDefaultPosition
,
118 const wxSize
& size
= wxDefaultSize
,
119 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
120 const wxString
& name
= wxPanelNameStr
)
124 Create(parent
, winid
, pos
, size
, style
, name
);
128 bool Create(wxWindow
*parent
,
129 wxWindowID winid
= wxID_ANY
,
130 const wxPoint
& pos
= wxDefaultPosition
,
131 const wxSize
& size
= wxDefaultSize
,
132 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
133 const wxString
& name
= wxPanelNameStr
)
135 if ( !wxWindow::Create(parent
, winid
, pos
, size
, style
, name
) )
138 // so that non-solid background renders correctly under GTK+:
139 SetThemeEnabled(true);
143 virtual ~wxBlindPlateWindow();
145 virtual bool AcceptsFocus() const
151 // common part of all ctors
156 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow
)
157 DECLARE_EVENT_TABLE()
160 wxBlindPlateWindow::~wxBlindPlateWindow()
164 IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow
, wxWindow
)
166 BEGIN_EVENT_TABLE(wxBlindPlateWindow
, wxWindow
)
170 // ----------------------------------------------------------------------------
171 // constructors and such
172 // ----------------------------------------------------------------------------
174 wxWindowMac::wxWindowMac()
179 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
184 const wxString
& name
)
187 Create(parent
, id
, pos
, size
, style
, name
);
190 void wxWindowMac::Init()
194 m_cgContextRef
= NULL
;
196 // as all windows are created with WS_VISIBLE style...
199 m_hScrollBar
= NULL
;
200 m_vScrollBar
= NULL
;
201 m_hScrollBarAlwaysShown
= false;
202 m_vScrollBarAlwaysShown
= false;
205 m_macIsUserPane
= true;
206 m_clipChildren
= false ;
207 m_cachedClippedRectValid
= false ;
208 m_isNativeWindowWrapper
= false;
211 wxWindowMac::~wxWindowMac()
215 MacInvalidateBorders() ;
217 #ifndef __WXUNIVERSAL__
218 // VS: make sure there's no wxFrame with last focus set to us:
219 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
221 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
224 if ( frame
->GetLastFocus() == this )
225 frame
->SetLastFocus(NULL
);
231 // destroy children before destroying this window itself
234 // wxRemoveMacControlAssociation( this ) ;
235 // If we delete an item, we should initialize the parent panel,
236 // because it could now be invalid.
237 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
240 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
241 tlw
->SetDefaultItem(NULL
);
244 if ( g_MacLastWindow
== this )
245 g_MacLastWindow
= NULL
;
247 #ifndef __WXUNIVERSAL__
248 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
251 if ( frame
->GetLastFocus() == this )
252 frame
->SetLastFocus( NULL
) ;
256 // delete our drop target if we've got one
257 #if wxUSE_DRAG_AND_DROP
258 wxDELETE(m_dropTarget
);
264 WXWidget
wxWindowMac::GetHandle() const
267 return (WXWidget
) m_peer
->GetWXWidget() ;
271 // ---------------------------------------------------------------------------
272 // Utility Routines to move between different coordinate systems
273 // ---------------------------------------------------------------------------
276 * Right now we have the following setup :
277 * a border that is not part of the native control is always outside the
278 * control's border (otherwise we loose all native intelligence, future ways
279 * may be to have a second embedding control responsible for drawing borders
280 * and backgrounds eventually)
281 * so all this border calculations have to be taken into account when calling
282 * native methods or getting native oriented data
283 * so we have three coordinate systems here
284 * wx client coordinates
285 * wx window coordinates (including window frames)
293 bool wxWindowMac::Create(wxWindowMac
*parent
,
298 const wxString
& name
)
300 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
302 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
305 m_windowVariant
= parent
->GetWindowVariant() ;
307 if ( m_macIsUserPane
)
309 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
310 MacPostControlCreate(pos
, size
) ;
313 #ifndef __WXUNIVERSAL__
314 // Don't give scrollbars to wxControls unless they ask for them
315 if ( (! IsKindOf(CLASSINFO(wxControl
))
317 && ! IsKindOf(CLASSINFO(wxStatusBar
))
320 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
322 MacCreateScrollBars( style
) ;
326 wxWindowCreateEvent
event((wxWindow
*)this);
327 GetEventHandler()->AddPendingEvent(event
);
332 void wxWindowMac::MacChildAdded()
336 m_vScrollBar
->Raise() ;
338 m_hScrollBar
->Raise() ;
344 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
346 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
348 GetParent()->AddChild( this );
350 m_peer
->InstallEventHandler();
351 m_peer
->Embed(GetParent()->GetPeer());
353 GetParent()->MacChildAdded() ;
355 // adjust font, controlsize etc
356 DoSetWindowVariant( m_windowVariant
) ;
358 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
360 // for controls we want to use best size for wxDefaultSize params )
361 if ( !m_macIsUserPane
)
362 SetInitialSize(size
);
364 SetCursor( *wxSTANDARD_CURSOR
) ;
367 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
369 // Don't assert, in case we set the window variant before
370 // the window is created
371 // wxASSERT( m_peer->Ok() ) ;
373 m_windowVariant
= variant
;
375 if (m_peer
== NULL
|| !m_peer
->IsOk())
378 m_peer
->SetControlSize( variant
);
382 // we will get that from the settings later
383 // and make this NORMAL later, but first
384 // we have a few calculations that we must fix
388 case wxWINDOW_VARIANT_NORMAL
:
389 size
= kControlSizeNormal
;
392 case wxWINDOW_VARIANT_SMALL
:
393 size
= kControlSizeSmall
;
396 case wxWINDOW_VARIANT_MINI
:
397 // not always defined in the headers
401 case wxWINDOW_VARIANT_LARGE
:
402 size
= kControlSizeLarge
;
406 wxFAIL_MSG(wxT("unexpected window variant"));
409 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
415 case wxWINDOW_VARIANT_NORMAL
:
416 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
420 case wxWINDOW_VARIANT_SMALL
:
421 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
425 case wxWINDOW_VARIANT_MINI
:
426 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
430 case wxWINDOW_VARIANT_LARGE
:
431 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
436 wxFAIL_MSG(wxT("unexpected window variant"));
441 void wxWindowMac::MacUpdateControlFont()
444 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
446 // do not trigger refreshes upon invisible and possible partly created objects
447 if ( IsShownOnScreen() )
451 bool wxWindowMac::SetFont(const wxFont
& font
)
453 bool retval
= wxWindowBase::SetFont( font
);
455 MacUpdateControlFont() ;
460 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
462 bool retval
= wxWindowBase::SetForegroundColour( col
);
465 MacUpdateControlFont();
470 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
472 if ( !wxWindowBase::SetBackgroundStyle(style
) )
476 m_peer
->SetBackgroundStyle(style
);
480 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
484 if ( m_backgroundColour
.Ok() )
485 m_growBox
->SetBackgroundColour(m_backgroundColour
);
487 m_growBox
->SetBackgroundColour(*wxWHITE
);
490 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
494 m_peer
->SetBackgroundColour( col
) ;
499 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
501 while (w
&& !w
->IsTopLevel())
510 void wxWindowMac::SetFocus()
512 if ( !AcceptsFocus() )
515 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
518 wxWindow
* former
= FindFocus() ;
519 if ( former
== this )
525 void wxWindowMac::DoCaptureMouse()
527 wxApp::s_captureWindow
= (wxWindow
*) this ;
528 m_peer
->CaptureMouse() ;
531 wxWindow
* wxWindowBase::GetCapture()
533 return wxApp::s_captureWindow
;
536 void wxWindowMac::DoReleaseMouse()
538 wxApp::s_captureWindow
= NULL
;
540 m_peer
->ReleaseMouse() ;
543 #if wxUSE_DRAG_AND_DROP
545 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
549 m_dropTarget
= pDropTarget
;
550 if ( m_dropTarget
!= NULL
)
558 // Old-style File Manager Drag & Drop
559 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
564 // From a wx position / size calculate the appropriate size of the native control
566 bool wxWindowMac::MacGetBoundsForControl(
570 int& w
, int& h
, bool adjustOrigin
) const
572 // the desired size, minus the border pixels gives the correct size of the control
576 w
= WidthDefault( size
.x
);
577 h
= HeightDefault( size
.y
);
579 x
+= MacGetLeftBorderSize() ;
580 y
+= MacGetTopBorderSize() ;
581 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
582 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
585 AdjustForParentClientOrigin( x
, y
) ;
587 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
588 if ( GetParent() && !GetParent()->IsTopLevel() )
590 x
-= GetParent()->MacGetLeftBorderSize() ;
591 y
-= GetParent()->MacGetTopBorderSize() ;
597 // Get window size (not client size)
598 void wxWindowMac::DoGetSize(int *x
, int *y
) const
601 m_peer
->GetSize( width
, height
);
604 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
606 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
609 // get the position of the bounds of this window in client coordinates of its parent
610 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
614 m_peer
->GetPosition( x1
, y1
) ;
616 // get the wx window position from the native one
617 x1
-= MacGetLeftBorderSize() ;
618 y1
-= MacGetTopBorderSize() ;
622 wxWindow
*parent
= GetParent();
625 // we must first adjust it to be in window coordinates of the parent,
626 // as otherwise it gets lost by the ClientAreaOrigin fix
627 x1
+= parent
->MacGetLeftBorderSize() ;
628 y1
+= parent
->MacGetTopBorderSize() ;
630 // and now to client coordinates
631 wxPoint
pt(parent
->GetClientAreaOrigin());
643 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
645 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
646 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
647 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
648 MacRootWindowToWindow( x
, y
) ;
650 wxPoint origin
= GetClientAreaOrigin() ;
657 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
659 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
660 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
662 wxPoint origin
= GetClientAreaOrigin() ;
668 MacWindowToRootWindow( x
, y
) ;
669 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
672 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
674 wxPoint origin
= GetClientAreaOrigin() ;
680 MacWindowToRootWindow( x
, y
) ;
683 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
694 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
697 pt
.x
-= MacGetLeftBorderSize() ;
698 pt
.y
-= MacGetTopBorderSize() ;
699 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
709 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
720 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
723 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
724 pt
.x
+= MacGetLeftBorderSize() ;
725 pt
.y
+= MacGetTopBorderSize() ;
735 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
737 wxSize sizeTotal
= size
;
739 int innerwidth
, innerheight
;
741 int outerwidth
, outerheight
;
743 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
744 m_peer
->GetSize( outerwidth
, outerheight
);
746 sizeTotal
.x
+= outerwidth
-innerwidth
;
747 sizeTotal
.y
+= outerheight
-innerheight
;
749 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
750 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
755 // Get size *available for subwindows* i.e. excluding menu bar etc.
756 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
762 m_peer
->GetContentArea( left
, top
, ww
, hh
);
764 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
765 hh
-= m_hScrollBar
->GetSize().y
;
767 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
768 ww
-= m_vScrollBar
->GetSize().x
;
777 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
779 if (m_cursor
.IsSameAs(cursor
))
784 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
789 if ( ! wxWindowBase::SetCursor( cursor
) )
793 wxASSERT_MSG( m_cursor
.Ok(),
794 wxT("cursor must be valid after call to the base version"));
796 if ( GetPeer() != NULL
)
797 GetPeer()->SetCursor( m_cursor
);
803 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
805 #ifndef __WXUNIVERSAL__
808 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
810 wxPoint mouse
= wxGetMousePosition();
816 ClientToScreen( &x
, &y
) ;
818 menu
->GetPeer()->PopUp(this, x
, y
);
821 // actually this shouldn't be called, because universal is having its own implementation
827 // ----------------------------------------------------------------------------
829 // ----------------------------------------------------------------------------
833 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
835 wxWindowBase::DoSetToolTip(tooltip
);
838 m_tooltip
->SetWindow(this);
841 m_peer
->SetToolTip(tooltip
);
846 void wxWindowMac::MacInvalidateBorders()
848 if ( m_peer
== NULL
)
851 bool vis
= IsShownOnScreen() ;
855 int outerBorder
= MacGetLeftBorderSize() ;
857 if ( m_peer
->NeedsFocusRect() )
860 if ( outerBorder
== 0 )
863 // now we know that we have something to do at all
867 m_peer
->GetSize( tw
, th
);
868 m_peer
->GetPosition( tx
, ty
);
870 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
871 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
872 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
873 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
876 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
877 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
878 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
879 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
883 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
885 // this is never called for a toplevel window, so we know we have a parent
886 int former_x
, former_y
, former_w
, former_h
;
888 // Get true coordinates of former position
889 DoGetPosition( &former_x
, &former_y
) ;
890 DoGetSize( &former_w
, &former_h
) ;
892 wxWindow
*parent
= GetParent();
895 wxPoint
pt(parent
->GetClientAreaOrigin());
900 int actualWidth
= width
;
901 int actualHeight
= height
;
906 // min and max sizes are only for sizers, not for explicit size setting
907 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
908 actualWidth
= m_minWidth
;
909 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
910 actualHeight
= m_minHeight
;
911 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
912 actualWidth
= m_maxWidth
;
913 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
914 actualHeight
= m_maxHeight
;
917 bool doMove
= false, doResize
= false ;
919 if ( actualX
!= former_x
|| actualY
!= former_y
)
922 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
925 if ( doMove
|| doResize
)
927 // as the borders are drawn outside the native control, we adjust now
929 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
930 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
931 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
933 if ( parent
&& !parent
->IsTopLevel() )
935 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
938 MacInvalidateBorders() ;
940 m_cachedClippedRectValid
= false ;
942 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
944 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
946 MacInvalidateBorders() ;
948 MacRepositionScrollBars() ;
951 wxPoint
point(actualX
, actualY
);
952 wxMoveEvent
event(point
, m_windowId
);
953 event
.SetEventObject(this);
954 HandleWindowEvent(event
) ;
959 MacRepositionScrollBars() ;
960 wxSize
size(actualWidth
, actualHeight
);
961 wxSizeEvent
event(size
, m_windowId
);
962 event
.SetEventObject(this);
963 HandleWindowEvent(event
);
968 wxSize
wxWindowMac::DoGetBestSize() const
970 if ( m_macIsUserPane
|| IsTopLevel() )
972 return wxWindowBase::DoGetBestSize() ;
978 m_peer
->GetBestRect(&r
);
980 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
988 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
995 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1002 // return wxWindowBase::DoGetBestSize() ;
1006 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1007 MacGetRightBorderSize();
1008 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1009 MacGetBottomBorderSize();
1010 if ( bestHeight
< 10 )
1013 return wxSize(bestWidth
, bestHeight
);
1017 // set the size of the window: if the dimensions are positive, just use them,
1018 // but if any of them is equal to -1, it means that we must find the value for
1019 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1020 // which case -1 is a valid value for x and y)
1022 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1023 // the width/height to best suit our contents, otherwise we reuse the current
1025 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1027 // get the current size and position...
1028 int currentX
, currentY
;
1029 int currentW
, currentH
;
1031 GetPosition(¤tX
, ¤tY
);
1032 GetSize(¤tW
, ¤tH
);
1034 // ... and don't do anything (avoiding flicker) if it's already ok
1035 if ( x
== currentX
&& y
== currentY
&&
1036 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1039 MacRepositionScrollBars() ; // we might have a real position shift
1041 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1043 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1044 event
.SetEventObject( this );
1045 HandleWindowEvent( event
);
1051 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1053 if ( x
== wxDefaultCoord
)
1055 if ( y
== wxDefaultCoord
)
1059 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1061 wxSize size
= wxDefaultSize
;
1062 if ( width
== wxDefaultCoord
)
1064 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1066 size
= DoGetBestSize();
1071 // just take the current one
1076 if ( height
== wxDefaultCoord
)
1078 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1080 if ( size
.x
== wxDefaultCoord
)
1081 size
= DoGetBestSize();
1082 // else: already called DoGetBestSize() above
1088 // just take the current one
1093 DoMoveWindow( x
, y
, width
, height
);
1096 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1098 int left
,top
,width
,height
;
1099 m_peer
->GetContentArea( left
, top
, width
, height
);
1100 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1103 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1105 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1107 int currentclientwidth
, currentclientheight
;
1108 int currentwidth
, currentheight
;
1110 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1111 GetSize( ¤twidth
, ¤theight
) ;
1113 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1114 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1118 void wxWindowMac::SetLabel(const wxString
& title
)
1120 if ( title
== m_label
)
1125 InvalidateBestSize();
1127 if ( m_peer
&& m_peer
->IsOk() )
1128 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1130 // do not trigger refreshes upon invisible and possible partly created objects
1131 if ( IsShownOnScreen() )
1135 wxString
wxWindowMac::GetLabel() const
1140 bool wxWindowMac::Show(bool show
)
1142 if ( !wxWindowBase::Show(show
) )
1146 m_peer
->SetVisibility( show
) ;
1148 #ifdef __WXOSX_IPHONE__
1149 // only when there's no native event support
1150 if ( !IsTopLevel() )
1153 wxShowEvent
eventShow(GetId(), show
);
1154 eventShow
.SetEventObject(this);
1156 HandleWindowEvent(eventShow
);
1162 bool wxWindowMac::OSXShowWithEffect(bool show
,
1163 wxShowEffect effect
,
1166 if ( effect
== wxSHOW_EFFECT_NONE
||
1167 !m_peer
|| !m_peer
->ShowWithEffect(show
, effect
, timeout
) )
1173 void wxWindowMac::DoEnable(bool enable
)
1175 m_peer
->Enable( enable
) ;
1176 MacInvalidateBorders();
1180 // status change notifications
1183 void wxWindowMac::MacVisibilityChanged()
1187 void wxWindowMac::MacHiliteChanged()
1191 void wxWindowMac::MacEnabledStateChanged()
1193 OnEnabled( m_peer
->IsEnabled() );
1197 // status queries on the inherited window's state
1200 bool wxWindowMac::MacIsReallyEnabled()
1202 return m_peer
->IsEnabled() ;
1205 bool wxWindowMac::MacIsReallyHilited()
1207 #if wxOSX_USE_CARBON
1208 return m_peer
->IsActive();
1210 return true; // TODO
1214 int wxWindowMac::GetCharHeight() const
1217 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1222 int wxWindowMac::GetCharWidth() const
1225 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1230 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1233 int *externalLeading
,
1234 const wxFont
*theFont
) const
1236 const wxFont
*fontToUse
= theFont
;
1240 tempFont
= GetFont();
1241 fontToUse
= &tempFont
;
1244 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1245 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1247 wxDouble h
, d
, e
, w
;
1248 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1252 if ( externalLeading
)
1253 *externalLeading
= (wxCoord
)(e
+0.5);
1255 *descent
= (wxCoord
)(d
+0.5);
1257 *x
= (wxCoord
)(w
+0.5);
1259 *y
= (wxCoord
)(h
+0.5);
1263 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1264 * we always intersect with the entire window, not only with the client area
1267 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1269 if ( m_peer
== NULL
)
1272 if ( !IsShownOnScreen() )
1275 m_peer
->SetNeedsDisplay( rect
) ;
1278 void wxWindowMac::DoFreeze()
1280 #if wxOSX_USE_CARBON
1281 if ( m_peer
&& m_peer
->IsOk() )
1282 m_peer
->SetDrawingEnabled( false ) ;
1286 void wxWindowMac::DoThaw()
1288 #if wxOSX_USE_CARBON
1289 if ( m_peer
&& m_peer
->IsOk() )
1291 m_peer
->SetDrawingEnabled( true ) ;
1292 m_peer
->InvalidateWithChildren() ;
1297 wxWindow
*wxGetActiveWindow()
1299 // actually this is a windows-only concept
1303 // Coordinates relative to the window
1304 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1306 #if wxOSX_USE_COCOA_OR_CARBON
1309 DoClientToScreen(&x
, &y
);
1310 CGPoint cgpoint
= CGPointMake( x
, y
);
1311 CGWarpMouseCursorPosition( cgpoint
);
1313 // At least GTK sends a mouse moved event after WarpMouse
1314 wxMouseEvent
event(wxEVT_MOTION
);
1317 wxMouseState mState
= ::wxGetMouseState();
1319 event
.m_altDown
= mState
.AltDown();
1320 event
.m_controlDown
= mState
.ControlDown();
1321 event
.m_leftDown
= mState
.LeftIsDown();
1322 event
.m_middleDown
= mState
.MiddleIsDown();
1323 event
.m_rightDown
= mState
.RightIsDown();
1324 event
.m_metaDown
= mState
.MetaDown();
1325 event
.m_shiftDown
= mState
.ShiftDown();
1326 event
.SetId(GetId());
1327 event
.SetEventObject(this);
1328 GetEventHandler()->ProcessEvent(event
);
1332 int wxWindowMac::GetScrollPos(int orient
) const
1335 if ( orient
== wxHORIZONTAL
)
1338 return m_hScrollBar
->GetThumbPosition() ;
1343 return m_vScrollBar
->GetThumbPosition() ;
1349 // This now returns the whole range, not just the number
1350 // of positions that we can scroll.
1351 int wxWindowMac::GetScrollRange(int orient
) const
1354 if ( orient
== wxHORIZONTAL
)
1357 return m_hScrollBar
->GetRange() ;
1362 return m_vScrollBar
->GetRange() ;
1368 int wxWindowMac::GetScrollThumb(int orient
) const
1371 if ( orient
== wxHORIZONTAL
)
1374 return m_hScrollBar
->GetThumbSize() ;
1379 return m_vScrollBar
->GetThumbSize() ;
1385 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1388 if ( orient
== wxHORIZONTAL
)
1391 m_hScrollBar
->SetThumbPosition( pos
) ;
1396 m_vScrollBar
->SetThumbPosition( pos
) ;
1402 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1404 bool needVisibilityUpdate
= false;
1406 if ( m_hScrollBarAlwaysShown
!= hflag
)
1408 m_hScrollBarAlwaysShown
= hflag
;
1409 needVisibilityUpdate
= true;
1412 if ( m_vScrollBarAlwaysShown
!= vflag
)
1414 m_vScrollBarAlwaysShown
= vflag
;
1415 needVisibilityUpdate
= true;
1418 if ( needVisibilityUpdate
)
1419 DoUpdateScrollbarVisibility();
1423 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1424 // our own window origin is at leftOrigin/rightOrigin
1427 void wxWindowMac::MacPaintGrowBox()
1433 if ( MacHasScrollBarCorner() )
1436 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1437 wxASSERT( cgContext
) ;
1441 m_peer
->GetSize( tw
, th
);
1442 m_peer
->GetPosition( tx
, ty
);
1444 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1447 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1448 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1449 CGContextSaveGState( cgContext
);
1451 if ( m_backgroundColour
.Ok() )
1453 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1457 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1459 CGContextFillRect( cgContext
, cgrect
);
1460 CGContextRestoreGState( cgContext
);
1464 if ( m_backgroundColour
.Ok() )
1465 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1467 m_growBox
->SetBackgroundColour(*wxWHITE
);
1475 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1480 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1482 // back to the surrounding frame rectangle
1485 m_peer
->GetSize( tw
, th
);
1486 m_peer
->GetPosition( tx
, ty
);
1488 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1490 #if wxOSX_USE_COCOA_OR_CARBON
1492 InsetRect( &rect
, -1 , -1 ) ;
1495 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1496 rect
.bottom
- rect
.top
) ;
1498 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1499 wxASSERT( cgContext
) ;
1501 if ( m_peer
->NeedsFrame() )
1503 HIThemeFrameDrawInfo info
;
1504 memset( &info
, 0 , sizeof(info
) ) ;
1508 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1509 info
.isFocused
= hasFocus
;
1511 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1513 info
.kind
= kHIThemeFrameTextFieldSquare
;
1514 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1516 else if ( HasFlag(wxSIMPLE_BORDER
) )
1518 info
.kind
= kHIThemeFrameListBox
;
1519 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1525 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1528 #endif // wxOSX_USE_COCOA_OR_CARBON
1531 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1534 if ( child
== m_hScrollBar
)
1535 m_hScrollBar
= NULL
;
1536 if ( child
== m_vScrollBar
)
1537 m_vScrollBar
= NULL
;
1538 if ( child
== m_growBox
)
1541 wxWindowBase::RemoveChild( child
) ;
1544 void wxWindowMac::DoUpdateScrollbarVisibility()
1547 bool triggerSizeEvent
= false;
1551 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1553 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1555 m_hScrollBar
->Show( showHScrollBar
);
1556 triggerSizeEvent
= true;
1562 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1564 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1566 m_vScrollBar
->Show( showVScrollBar
) ;
1567 triggerSizeEvent
= true;
1571 MacRepositionScrollBars() ;
1572 if ( triggerSizeEvent
)
1574 wxSizeEvent
event(GetSize(), m_windowId
);
1575 event
.SetEventObject(this);
1576 HandleWindowEvent(event
);
1581 // New function that will replace some of the above.
1582 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1583 int range
, bool refresh
)
1586 // Updating scrollbars when window is being deleted is useless and
1587 // currently results in asserts in client-to-screen coordinates conversion
1588 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1589 if ( m_isBeingDeleted
)
1592 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1593 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1594 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1595 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1597 DoUpdateScrollbarVisibility();
1601 // Does a physical scroll
1602 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1604 if ( dx
== 0 && dy
== 0 )
1607 int width
, height
;
1608 GetClientSize( &width
, &height
) ;
1611 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1613 scrollrect
.Intersect( *rect
) ;
1614 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1615 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1617 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1622 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1624 child
= node
->GetData();
1628 if (child
->IsTopLevel())
1631 if ( !IsClientAreaChild(child
) )
1634 child
->GetPosition( &x
, &y
);
1635 child
->GetSize( &w
, &h
);
1638 wxRect
rc( x
, y
, w
, h
);
1639 if (rect
->Intersects( rc
))
1640 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1644 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1649 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1652 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1654 wxScrollWinEvent wevent
;
1655 wevent
.SetPosition(event
.GetPosition());
1656 wevent
.SetOrientation(event
.GetOrientation());
1657 wevent
.SetEventObject(this);
1659 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1660 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1661 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1662 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1663 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1664 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1665 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1666 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1667 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1668 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1669 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1670 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1671 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1672 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1673 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1674 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1676 HandleWindowEvent(wevent
);
1681 wxWindow
*wxWindowBase::DoFindFocus()
1683 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1686 void wxWindowMac::OnInternalIdle()
1688 // This calls the UI-update mechanism (querying windows for
1689 // menu/toolbar/control state information)
1690 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1691 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1694 // Raise the window to the top of the Z order
1695 void wxWindowMac::Raise()
1700 // Lower the window to the bottom of the Z order
1701 void wxWindowMac::Lower()
1706 // static wxWindow *gs_lastWhich = NULL;
1708 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1710 // first trigger a set cursor event
1712 wxPoint clientorigin
= GetClientAreaOrigin() ;
1713 wxSize clientsize
= GetClientSize() ;
1715 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1717 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1719 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1720 if ( processedEvtSetCursor
&& event
.HasCursor() )
1722 cursor
= event
.GetCursor() ;
1726 // the test for processedEvtSetCursor is here to prevent using m_cursor
1727 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1728 // it - this is a way to say that our cursor shouldn't be used for this
1730 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1733 if ( !wxIsBusy() && !GetParent() )
1734 cursor
= *wxSTANDARD_CURSOR
;
1738 cursor
.MacInstall() ;
1741 return cursor
.Ok() ;
1744 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1748 return m_tooltip
->GetTip() ;
1751 return wxEmptyString
;
1754 void wxWindowMac::ClearBackground()
1760 void wxWindowMac::Update()
1762 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1767 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1769 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1773 if ( iter
->IsTopLevel() )
1775 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1779 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1784 iter
= iter
->GetParent() ;
1790 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1792 MacUpdateClippedRects() ;
1794 return m_cachedClippedClientRect
;
1797 const wxRect
& wxWindowMac::MacGetClippedRect() const
1799 MacUpdateClippedRects() ;
1801 return m_cachedClippedRect
;
1804 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1806 MacUpdateClippedRects() ;
1808 return m_cachedClippedRectWithOuterStructure
;
1811 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1813 static wxRegion emptyrgn
;
1815 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1817 MacUpdateClippedRects() ;
1818 if ( includeOuterStructures
)
1819 return m_cachedClippedRegionWithOuterStructure
;
1821 return m_cachedClippedRegion
;
1829 void wxWindowMac::MacUpdateClippedRects() const
1831 #if wxOSX_USE_CARBON
1832 if ( m_cachedClippedRectValid
)
1835 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1836 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1837 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1838 // to add focus borders everywhere
1840 Rect rIncludingOuterStructures
;
1844 m_peer
->GetSize( tw
, th
);
1845 m_peer
->GetPosition( tx
, ty
);
1847 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1849 r
.left
-= MacGetLeftBorderSize() ;
1850 r
.top
-= MacGetTopBorderSize() ;
1851 r
.bottom
+= MacGetBottomBorderSize() ;
1852 r
.right
+= MacGetRightBorderSize() ;
1859 rIncludingOuterStructures
= r
;
1860 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1862 wxRect cl
= GetClientRect() ;
1863 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1867 const wxWindow
* child
= (wxWindow
*) this ;
1868 const wxWindow
* parent
= NULL
;
1870 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1872 if ( parent
->MacIsChildOfClientArea(child
) )
1874 size
= parent
->GetClientSize() ;
1875 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1881 // this will be true for scrollbars, toolbars etc.
1882 size
= parent
->GetSize() ;
1883 y
= parent
->MacGetTopBorderSize() ;
1884 x
= parent
->MacGetLeftBorderSize() ;
1885 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1886 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1889 parent
->MacWindowToRootWindow( &x
, &y
) ;
1890 MacRootWindowToWindow( &x
, &y
) ;
1892 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1894 // the wxwindow and client rects will always be clipped
1895 SectRect( &r
, &rparent
, &r
) ;
1896 SectRect( &rClient
, &rparent
, &rClient
) ;
1898 // the structure only at 'hard' borders
1899 if ( parent
->MacClipChildren() ||
1900 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1902 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1908 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1909 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1910 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1911 m_cachedClippedRectWithOuterStructure
= wxRect(
1912 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1913 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1914 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1916 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1917 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1918 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1920 m_cachedClippedRectValid
= true ;
1925 This function must not change the updatergn !
1927 bool wxWindowMac::MacDoRedraw( long time
)
1929 bool handled
= false ;
1931 wxRegion formerUpdateRgn
= m_updateRegion
;
1932 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1934 const wxRect clientRect
= GetClientRect();
1936 clientUpdateRgn
.Intersect(clientRect
);
1938 // first send an erase event to the entire update area
1939 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1942 case wxBG_STYLE_ERASE
:
1943 case wxBG_STYLE_SYSTEM
:
1944 case wxBG_STYLE_COLOUR
:
1946 // for the toplevel window this really is the entire area for
1947 // all the others only their client area, otherwise they might
1948 // be drawing with full alpha and eg put blue into the grow-box
1949 // area of a scrolled window (scroll sample)
1950 wxWindowDC
dc(this);
1952 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1954 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1956 if ( bgStyle
== wxBG_STYLE_ERASE
)
1958 wxEraseEvent
eevent( GetId(), &dc
);
1959 eevent
.SetEventObject( this );
1960 if ( ProcessWindowEvent( eevent
) )
1966 dc
.SetBackground(GetBackgroundColour());
1972 case wxBG_STYLE_PAINT
:
1973 case wxBG_STYLE_TRANSPARENT
:
1974 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1975 // entire window client area
1979 wxFAIL_MSG( "unsupported background style" );
1982 // as this is a full window, shouldn't be necessary anymore
1983 // MacPaintGrowBox();
1985 // calculate a client-origin version of the update rgn and set
1986 // m_updateRegion to that
1987 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1988 m_updateRegion
= clientUpdateRgn
;
1990 if ( !m_updateRegion
.Empty() )
1992 // paint the window itself
1994 wxPaintEvent
event(GetId());
1995 event
.SetTimestamp(time
);
1996 event
.SetEventObject(this);
1997 handled
= HandleWindowEvent(event
);
2000 m_updateRegion
= formerUpdateRgn
;
2004 void wxWindowMac::MacPaintChildrenBorders()
2006 // now we cannot rely on having its borders drawn by a window itself, as it does not
2007 // get the updateRgn wide enough to always do so, so we do it from the parent
2008 // this would also be the place to draw any custom backgrounds for native controls
2009 // in Composited windowing
2010 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2014 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2016 child
= node
->GetData();
2020 if (child
== m_vScrollBar
)
2022 if (child
== m_hScrollBar
)
2024 if (child
== m_growBox
)
2027 if (child
->IsTopLevel())
2029 if (!child
->IsShown())
2032 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2034 child
->GetPosition( &x
, &y
);
2035 child
->GetSize( &w
, &h
);
2037 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2039 // paint custom borders
2040 wxNcPaintEvent
eventNc( child
->GetId() );
2041 eventNc
.SetEventObject( child
);
2042 if ( !child
->HandleWindowEvent( eventNc
) )
2044 child
->MacPaintBorders(0, 0) ;
2051 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2053 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2054 return tlw
? tlw
->GetWXWindow() : NULL
;
2057 bool wxWindowMac::MacHasScrollBarCorner() const
2060 /* Returns whether the scroll bars in a wxScrolledWindow should be
2061 * shortened. Scroll bars should be shortened if either:
2063 * - both scroll bars are visible, or
2065 * - there is a resize box in the parent frame's corner and this
2066 * window shares the bottom and right edge with the parent
2070 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2073 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2074 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2076 // Both scroll bars visible
2081 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2083 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2085 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2088 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2090 // Parent frame has resize handle
2091 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2093 // Note: allow for some wiggle room here as wxMac's
2094 // window rect calculations seem to be imprecise
2095 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2096 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2098 // Parent frame has resize handle and shares
2099 // right bottom corner
2104 // Parent frame has resize handle but doesn't
2105 // share right bottom corner
2111 // Parent frame doesn't have resize handle
2117 // No parent frame found
2125 void wxWindowMac::MacCreateScrollBars( long style
)
2128 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2130 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2132 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2133 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2135 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2138 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2140 GetClientSize( &width
, &height
) ;
2142 wxPoint
vPoint(width
- scrlsize
, 0) ;
2143 wxSize
vSize(scrlsize
, height
- adjust
) ;
2144 wxPoint
hPoint(0, height
- scrlsize
) ;
2145 wxSize
hSize(width
- adjust
, scrlsize
) ;
2147 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2148 if ( style
& wxVSCROLL
)
2150 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2151 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2154 if ( style
& wxHSCROLL
)
2156 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2157 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2160 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2161 wxSize
gSize(scrlsize
, scrlsize
);
2162 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2165 // because the create does not take into account the client area origin
2166 // we might have a real position shift
2167 MacRepositionScrollBars() ;
2171 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2173 bool result
= ((child
== NULL
)
2175 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2182 void wxWindowMac::MacRepositionScrollBars()
2185 if ( !m_hScrollBar
&& !m_vScrollBar
)
2188 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2189 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2191 // get real client area
2193 GetSize( &width
, &height
);
2195 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2196 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2198 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2199 wxSize
vSize( scrlsize
, height
- adjust
) ;
2200 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2201 wxSize
hSize( width
- adjust
, scrlsize
) ;
2204 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2206 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2209 if ( MacHasScrollBarCorner() )
2211 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2212 if ( !m_growBox
->IsShown() )
2217 if ( m_growBox
->IsShown() )
2224 bool wxWindowMac::AcceptsFocus() const
2226 if ( MacIsUserPane() )
2227 return wxWindowBase::AcceptsFocus();
2229 return m_peer
->CanFocus();
2232 void wxWindowMac::MacSuperChangedPosition()
2234 // only window-absolute structures have to be moved i.e. controls
2236 m_cachedClippedRectValid
= false ;
2239 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2242 child
= node
->GetData();
2243 child
->MacSuperChangedPosition() ;
2245 node
= node
->GetNext();
2249 void wxWindowMac::MacTopLevelWindowChangedPosition()
2251 // only screen-absolute structures have to be moved i.e. glcanvas
2254 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2257 child
= node
->GetData();
2258 child
->MacTopLevelWindowChangedPosition() ;
2260 node
= node
->GetNext();
2264 long wxWindowMac::MacGetWXBorderSize() const
2271 if ( m_peer
&& m_peer
->NeedsFrame() )
2273 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2275 #if wxOSX_USE_COCOA_OR_CARBON
2276 // this metric is only the 'outset' outside the simple frame rect
2277 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2283 else if (HasFlag(wxSIMPLE_BORDER
))
2285 #if wxOSX_USE_COCOA_OR_CARBON
2286 // this metric is only the 'outset' outside the simple frame rect
2287 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2298 long wxWindowMac::MacGetLeftBorderSize() const
2300 // the wx borders are all symmetric in mac themes
2301 long border
= MacGetWXBorderSize() ;
2305 int left
, top
, right
, bottom
;
2306 m_peer
->GetLayoutInset( left
, top
, right
, bottom
);
2314 long wxWindowMac::MacGetRightBorderSize() const
2316 // the wx borders are all symmetric in mac themes
2317 long border
= MacGetWXBorderSize() ;
2321 int left
, top
, right
, bottom
;
2322 m_peer
->GetLayoutInset( left
, top
, right
, bottom
);
2329 long wxWindowMac::MacGetTopBorderSize() const
2331 // the wx borders are all symmetric in mac themes
2332 long border
= MacGetWXBorderSize() ;
2336 int left
, top
, right
, bottom
;
2337 m_peer
->GetLayoutInset( left
, top
, right
, bottom
);
2344 long wxWindowMac::MacGetBottomBorderSize() const
2346 // the wx borders are all symmetric in mac themes
2347 long border
= MacGetWXBorderSize() ;
2351 int left
, top
, right
, bottom
;
2352 m_peer
->GetLayoutInset( left
, top
, right
, bottom
);
2359 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2361 return style
& ~wxBORDER_MASK
;
2364 // Find the wxWindowMac at the current mouse position, returning the mouse
2366 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2368 pt
= wxGetMousePosition();
2369 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2371 return (wxWindow
*) found
;
2374 // Get the current mouse position.
2375 wxPoint
wxGetMousePosition()
2379 wxGetMousePosition( &x
, &y
);
2381 return wxPoint(x
, y
);
2384 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2386 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2388 // copied from wxGTK : CS
2389 // VZ: shouldn't we move this to base class then?
2391 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2394 // (a) it's a command event and so is propagated to the parent
2395 // (b) under MSW it can be generated from kbd too
2396 // (c) it uses screen coords (because of (a))
2397 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2399 this->ClientToScreen(event
.GetPosition()));
2400 evtCtx
.SetEventObject(this);
2401 if ( ! HandleWindowEvent(evtCtx
) )
2410 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2414 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2418 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2419 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2424 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2429 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2431 #if wxOSX_USE_COCOA_OR_CARBON
2432 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2435 return eventNotHandledErr
;
2441 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2443 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2444 if ( !wxWindowBase::Reparent(newParent
) )
2447 m_peer
->RemoveFromParent();
2448 m_peer
->Embed( GetParent()->GetPeer() );
2454 bool wxWindowMac::SetTransparent(wxByte alpha
)
2456 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2458 if ( alpha
!= m_macAlpha
)
2460 m_macAlpha
= alpha
;
2467 bool wxWindowMac::CanSetTransparent()
2472 wxByte
wxWindowMac::GetTransparent() const
2477 bool wxWindowMac::IsShownOnScreen() const
2479 if ( m_peer
&& m_peer
->IsOk() )
2481 bool peerVis
= m_peer
->IsVisible();
2482 bool wxVis
= wxWindowBase::IsShownOnScreen();
2483 if( peerVis
!= wxVis
)
2485 // CS : put a breakpoint here to investigate differences
2486 // between native an wx visibilities
2487 // the only place where I've encountered them until now
2488 // are the hiding/showing sequences where the vis-changed event is
2489 // first sent to the innermost control, while wx does things
2490 // from the outmost control
2491 wxVis
= wxWindowBase::IsShownOnScreen();
2495 return m_peer
->IsVisible();
2497 return wxWindowBase::IsShownOnScreen();
2500 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2502 bool handled
= HandleWindowEvent( event
) ;
2503 if ( handled
&& event
.GetSkipped() )
2507 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2509 wxWindow
*ancestor
= this;
2512 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2515 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2517 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2518 handled
= handler
->ProcessEvent( command_event
);
2522 // accelerators can also be used with buttons, try them too
2523 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2524 handled
= handler
->ProcessEvent( command_event
);
2530 if (ancestor
->IsTopLevel())
2533 ancestor
= ancestor
->GetParent();
2536 #endif // wxUSE_ACCEL
2545 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2547 static MacControlMap wxWinMacControlList
;
2549 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2551 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2553 return impl
->GetWXPeer();
2558 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2560 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2562 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2565 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2567 // adding NULL ControlRef is (first) surely a result of an error and
2568 // (secondly) breaks native event processing
2569 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2571 wxWinMacControlList
[inControl
] = impl
;
2574 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2576 // iterate over all the elements in the class
2577 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2578 // we should go on...
2584 MacControlMap::iterator it
;
2585 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2587 if ( it
->second
== impl
)
2589 wxWinMacControlList
.erase(it
);
2597 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2599 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2602 m_isRootControl
= isRootControl
;
2604 m_shouldSendEvents
= true;
2607 wxWidgetImpl::wxWidgetImpl()
2612 wxWidgetImpl::~wxWidgetImpl()
2616 void wxWidgetImpl::Init()
2618 m_isRootControl
= false;
2620 m_needsFocusRect
= false;
2621 m_needsFrame
= true;
2624 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2626 m_needsFocusRect
= needs
;
2629 bool wxWidgetImpl::NeedsFocusRect() const
2631 return m_needsFocusRect
;
2634 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2636 m_needsFrame
= needs
;
2639 bool wxWidgetImpl::NeedsFrame() const
2641 return m_needsFrame
;