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
)
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);
145 virtual ~wxBlindPlateWindow();
147 virtual bool AcceptsFocus() const
153 // common part of all ctors
158 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow
)
159 DECLARE_EVENT_TABLE()
162 wxBlindPlateWindow::~wxBlindPlateWindow()
166 IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow
, wxWindow
)
168 BEGIN_EVENT_TABLE(wxBlindPlateWindow
, wxWindow
)
172 // ----------------------------------------------------------------------------
173 // constructors and such
174 // ----------------------------------------------------------------------------
176 wxWindowMac::wxWindowMac()
181 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
186 const wxString
& name
)
189 Create(parent
, id
, pos
, size
, style
, name
);
192 void wxWindowMac::Init()
196 m_cgContextRef
= NULL
;
198 // as all windows are created with WS_VISIBLE style...
201 m_hScrollBar
= NULL
;
202 m_vScrollBar
= NULL
;
203 m_hScrollBarAlwaysShown
= false;
204 m_vScrollBarAlwaysShown
= false;
207 m_macIsUserPane
= true;
208 m_clipChildren
= false ;
209 m_cachedClippedRectValid
= false ;
210 m_isNativeWindowWrapper
= false;
213 wxWindowMac::~wxWindowMac()
217 MacInvalidateBorders() ;
219 #ifndef __WXUNIVERSAL__
220 // VS: make sure there's no wxFrame with last focus set to us:
221 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
223 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
226 if ( frame
->GetLastFocus() == this )
227 frame
->SetLastFocus(NULL
);
233 // destroy children before destroying this window itself
236 // wxRemoveMacControlAssociation( this ) ;
237 // If we delete an item, we should initialize the parent panel,
238 // because it could now be invalid.
239 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
242 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
243 tlw
->SetDefaultItem(NULL
);
246 if ( g_MacLastWindow
== this )
247 g_MacLastWindow
= NULL
;
249 #ifndef __WXUNIVERSAL__
250 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
253 if ( frame
->GetLastFocus() == this )
254 frame
->SetLastFocus( NULL
) ;
258 // delete our drop target if we've got one
259 #if wxUSE_DRAG_AND_DROP
260 wxDELETE(m_dropTarget
);
266 WXWidget
wxWindowMac::GetHandle() const
269 return (WXWidget
) m_peer
->GetWXWidget() ;
273 // ---------------------------------------------------------------------------
274 // Utility Routines to move between different coordinate systems
275 // ---------------------------------------------------------------------------
278 * Right now we have the following setup :
279 * a border that is not part of the native control is always outside the
280 * control's border (otherwise we loose all native intelligence, future ways
281 * may be to have a second embedding control responsible for drawing borders
282 * and backgrounds eventually)
283 * so all this border calculations have to be taken into account when calling
284 * native methods or getting native oriented data
285 * so we have three coordinate systems here
286 * wx client coordinates
287 * wx window coordinates (including window frames)
295 bool wxWindowMac::Create(wxWindowMac
*parent
,
300 const wxString
& name
)
302 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
304 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
307 m_windowVariant
= parent
->GetWindowVariant() ;
309 if ( m_macIsUserPane
)
311 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
312 MacPostControlCreate(pos
, size
) ;
315 #ifndef __WXUNIVERSAL__
316 // Don't give scrollbars to wxControls unless they ask for them
317 if ( (! IsKindOf(CLASSINFO(wxControl
))
319 && ! IsKindOf(CLASSINFO(wxStatusBar
))
322 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
324 MacCreateScrollBars( style
) ;
328 wxWindowCreateEvent
event((wxWindow
*)this);
329 GetEventHandler()->AddPendingEvent(event
);
334 void wxWindowMac::MacChildAdded()
338 m_vScrollBar
->Raise() ;
340 m_hScrollBar
->Raise() ;
346 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
348 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
350 GetParent()->AddChild( this );
352 m_peer
->InstallEventHandler();
353 m_peer
->Embed(GetParent()->GetPeer());
355 GetParent()->MacChildAdded() ;
357 // adjust font, controlsize etc
358 DoSetWindowVariant( m_windowVariant
) ;
360 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
362 // for controls we want to use best size for wxDefaultSize params )
363 if ( !m_macIsUserPane
)
364 SetInitialSize(size
);
366 SetCursor( *wxSTANDARD_CURSOR
) ;
369 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
371 // Don't assert, in case we set the window variant before
372 // the window is created
373 // wxASSERT( m_peer->Ok() ) ;
375 m_windowVariant
= variant
;
377 if (m_peer
== NULL
|| !m_peer
->IsOk())
380 m_peer
->SetControlSize( variant
);
384 // we will get that from the settings later
385 // and make this NORMAL later, but first
386 // we have a few calculations that we must fix
390 case wxWINDOW_VARIANT_NORMAL
:
391 size
= kControlSizeNormal
;
394 case wxWINDOW_VARIANT_SMALL
:
395 size
= kControlSizeSmall
;
398 case wxWINDOW_VARIANT_MINI
:
399 // not always defined in the headers
403 case wxWINDOW_VARIANT_LARGE
:
404 size
= kControlSizeLarge
;
408 wxFAIL_MSG(wxT("unexpected window variant"));
411 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
417 case wxWINDOW_VARIANT_NORMAL
:
418 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
422 case wxWINDOW_VARIANT_SMALL
:
423 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
427 case wxWINDOW_VARIANT_MINI
:
428 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
432 case wxWINDOW_VARIANT_LARGE
:
433 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
438 wxFAIL_MSG(wxT("unexpected window variant"));
443 void wxWindowMac::MacUpdateControlFont()
446 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
448 // do not trigger refreshes upon invisible and possible partly created objects
449 if ( IsShownOnScreen() )
453 bool wxWindowMac::SetFont(const wxFont
& font
)
455 bool retval
= wxWindowBase::SetFont( font
);
457 MacUpdateControlFont() ;
462 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
464 bool retval
= wxWindowBase::SetForegroundColour( col
);
467 MacUpdateControlFont();
472 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
474 if ( !wxWindowBase::SetBackgroundStyle(style
) )
478 m_peer
->SetBackgroundStyle(style
);
482 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
486 if ( m_backgroundColour
.Ok() )
487 m_growBox
->SetBackgroundColour(m_backgroundColour
);
489 m_growBox
->SetBackgroundColour(*wxWHITE
);
492 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
496 m_peer
->SetBackgroundColour( col
) ;
501 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
503 while (w
&& !w
->IsTopLevel())
512 void wxWindowMac::SetFocus()
514 if ( !AcceptsFocus() )
517 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
520 wxWindow
* former
= FindFocus() ;
521 if ( former
== this )
527 void wxWindowMac::DoCaptureMouse()
529 wxApp::s_captureWindow
= (wxWindow
*) this ;
530 m_peer
->CaptureMouse() ;
533 wxWindow
* wxWindowBase::GetCapture()
535 return wxApp::s_captureWindow
;
538 void wxWindowMac::DoReleaseMouse()
540 wxApp::s_captureWindow
= NULL
;
542 m_peer
->ReleaseMouse() ;
545 #if wxUSE_DRAG_AND_DROP
547 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
551 m_dropTarget
= pDropTarget
;
552 if ( m_dropTarget
!= NULL
)
560 // Old-style File Manager Drag & Drop
561 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
566 // From a wx position / size calculate the appropriate size of the native control
568 bool wxWindowMac::MacGetBoundsForControl(
572 int& w
, int& h
, bool adjustOrigin
) const
574 // the desired size, minus the border pixels gives the correct size of the control
578 w
= WidthDefault( size
.x
);
579 h
= HeightDefault( size
.y
);
581 x
+= MacGetLeftBorderSize() ;
582 y
+= MacGetTopBorderSize() ;
583 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
584 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
587 AdjustForParentClientOrigin( x
, y
) ;
589 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
590 if ( GetParent() && !GetParent()->IsTopLevel() )
592 x
-= GetParent()->MacGetLeftBorderSize() ;
593 y
-= GetParent()->MacGetTopBorderSize() ;
599 // Get window size (not client size)
600 void wxWindowMac::DoGetSize(int *x
, int *y
) const
603 m_peer
->GetSize( width
, height
);
606 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
608 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
611 // get the position of the bounds of this window in client coordinates of its parent
612 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
616 m_peer
->GetPosition( x1
, y1
) ;
618 // get the wx window position from the native one
619 x1
-= MacGetLeftBorderSize() ;
620 y1
-= MacGetTopBorderSize() ;
624 wxWindow
*parent
= GetParent();
627 // we must first adjust it to be in window coordinates of the parent,
628 // as otherwise it gets lost by the ClientAreaOrigin fix
629 x1
+= parent
->MacGetLeftBorderSize() ;
630 y1
+= parent
->MacGetTopBorderSize() ;
632 // and now to client coordinates
633 wxPoint
pt(parent
->GetClientAreaOrigin());
645 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
647 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
648 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
649 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
650 MacRootWindowToWindow( x
, y
) ;
652 wxPoint origin
= GetClientAreaOrigin() ;
659 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
661 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
662 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
664 wxPoint origin
= GetClientAreaOrigin() ;
670 MacWindowToRootWindow( x
, y
) ;
671 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
674 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
676 wxPoint origin
= GetClientAreaOrigin() ;
682 MacWindowToRootWindow( x
, y
) ;
685 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
696 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
699 pt
.x
-= MacGetLeftBorderSize() ;
700 pt
.y
-= MacGetTopBorderSize() ;
701 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
711 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
722 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
725 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
726 pt
.x
+= MacGetLeftBorderSize() ;
727 pt
.y
+= MacGetTopBorderSize() ;
737 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
739 wxSize sizeTotal
= size
;
741 int innerwidth
, innerheight
;
743 int outerwidth
, outerheight
;
745 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
746 m_peer
->GetSize( outerwidth
, outerheight
);
748 sizeTotal
.x
+= outerwidth
-innerwidth
;
749 sizeTotal
.y
+= outerheight
-innerheight
;
751 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
752 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
757 // Get size *available for subwindows* i.e. excluding menu bar etc.
758 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
764 m_peer
->GetContentArea( left
, top
, ww
, hh
);
766 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
767 hh
-= m_hScrollBar
->GetSize().y
;
769 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
770 ww
-= m_vScrollBar
->GetSize().x
;
779 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
781 if (m_cursor
.IsSameAs(cursor
))
786 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
791 if ( ! wxWindowBase::SetCursor( cursor
) )
795 wxASSERT_MSG( m_cursor
.Ok(),
796 wxT("cursor must be valid after call to the base version"));
798 if ( GetPeer() != NULL
)
799 GetPeer()->SetCursor( m_cursor
);
805 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
807 #ifndef __WXUNIVERSAL__
810 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
812 wxPoint mouse
= wxGetMousePosition();
818 ClientToScreen( &x
, &y
) ;
820 menu
->GetPeer()->PopUp(this, x
, y
);
823 // actually this shouldn't be called, because universal is having its own implementation
829 // ----------------------------------------------------------------------------
831 // ----------------------------------------------------------------------------
835 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
837 wxWindowBase::DoSetToolTip(tooltip
);
840 m_tooltip
->SetWindow(this);
843 m_peer
->SetToolTip(tooltip
);
848 void wxWindowMac::MacInvalidateBorders()
850 if ( m_peer
== NULL
)
853 bool vis
= IsShownOnScreen() ;
857 int outerBorder
= MacGetLeftBorderSize() ;
859 if ( m_peer
->NeedsFocusRect() )
862 if ( outerBorder
== 0 )
865 // now we know that we have something to do at all
869 m_peer
->GetSize( tw
, th
);
870 m_peer
->GetPosition( tx
, ty
);
872 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
873 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
874 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
875 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
878 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
879 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
880 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
881 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
885 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
887 // this is never called for a toplevel window, so we know we have a parent
888 int former_x
, former_y
, former_w
, former_h
;
890 // Get true coordinates of former position
891 DoGetPosition( &former_x
, &former_y
) ;
892 DoGetSize( &former_w
, &former_h
) ;
894 wxWindow
*parent
= GetParent();
897 wxPoint
pt(parent
->GetClientAreaOrigin());
902 int actualWidth
= width
;
903 int actualHeight
= height
;
908 // min and max sizes are only for sizers, not for explicit size setting
909 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
910 actualWidth
= m_minWidth
;
911 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
912 actualHeight
= m_minHeight
;
913 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
914 actualWidth
= m_maxWidth
;
915 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
916 actualHeight
= m_maxHeight
;
919 bool doMove
= false, doResize
= false ;
921 if ( actualX
!= former_x
|| actualY
!= former_y
)
924 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
927 if ( doMove
|| doResize
)
929 // as the borders are drawn outside the native control, we adjust now
931 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
932 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
933 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
935 if ( parent
&& !parent
->IsTopLevel() )
937 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
940 MacInvalidateBorders() ;
942 m_cachedClippedRectValid
= false ;
944 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
946 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
948 MacInvalidateBorders() ;
950 MacRepositionScrollBars() ;
953 wxPoint
point(actualX
, actualY
);
954 wxMoveEvent
event(point
, m_windowId
);
955 event
.SetEventObject(this);
956 HandleWindowEvent(event
) ;
961 MacRepositionScrollBars() ;
962 wxSize
size(actualWidth
, actualHeight
);
963 wxSizeEvent
event(size
, m_windowId
);
964 event
.SetEventObject(this);
965 HandleWindowEvent(event
);
970 wxSize
wxWindowMac::DoGetBestSize() const
972 if ( m_macIsUserPane
|| IsTopLevel() )
974 return wxWindowBase::DoGetBestSize() ;
980 m_peer
->GetBestRect(&r
);
982 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
990 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
997 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1004 // return wxWindowBase::DoGetBestSize() ;
1008 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1009 MacGetRightBorderSize();
1010 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1011 MacGetBottomBorderSize();
1012 if ( bestHeight
< 10 )
1015 return wxSize(bestWidth
, bestHeight
);
1019 // set the size of the window: if the dimensions are positive, just use them,
1020 // but if any of them is equal to -1, it means that we must find the value for
1021 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1022 // which case -1 is a valid value for x and y)
1024 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1025 // the width/height to best suit our contents, otherwise we reuse the current
1027 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1029 // get the current size and position...
1030 int currentX
, currentY
;
1031 int currentW
, currentH
;
1033 GetPosition(¤tX
, ¤tY
);
1034 GetSize(¤tW
, ¤tH
);
1036 // ... and don't do anything (avoiding flicker) if it's already ok
1037 if ( x
== currentX
&& y
== currentY
&&
1038 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1041 MacRepositionScrollBars() ; // we might have a real position shift
1043 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1045 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1046 event
.SetEventObject( this );
1047 HandleWindowEvent( event
);
1053 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1055 if ( x
== wxDefaultCoord
)
1057 if ( y
== wxDefaultCoord
)
1061 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1063 wxSize size
= wxDefaultSize
;
1064 if ( width
== wxDefaultCoord
)
1066 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1068 size
= DoGetBestSize();
1073 // just take the current one
1078 if ( height
== wxDefaultCoord
)
1080 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1082 if ( size
.x
== wxDefaultCoord
)
1083 size
= DoGetBestSize();
1084 // else: already called DoGetBestSize() above
1090 // just take the current one
1095 DoMoveWindow( x
, y
, width
, height
);
1098 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1100 int left
,top
,width
,height
;
1101 m_peer
->GetContentArea( left
, top
, width
, height
);
1102 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1105 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1107 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1109 int currentclientwidth
, currentclientheight
;
1110 int currentwidth
, currentheight
;
1112 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1113 GetSize( ¤twidth
, ¤theight
) ;
1115 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1116 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1120 void wxWindowMac::SetLabel(const wxString
& title
)
1122 if ( title
== m_label
)
1127 InvalidateBestSize();
1129 if ( m_peer
&& m_peer
->IsOk() )
1130 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1132 // do not trigger refreshes upon invisible and possible partly created objects
1133 if ( IsShownOnScreen() )
1137 wxString
wxWindowMac::GetLabel() const
1142 bool wxWindowMac::Show(bool show
)
1144 if ( !wxWindowBase::Show(show
) )
1148 m_peer
->SetVisibility( show
) ;
1150 #ifdef __WXOSX_IPHONE__
1151 // only when there's no native event support
1152 if ( !IsTopLevel() )
1155 wxShowEvent
eventShow(GetId(), show
);
1156 eventShow
.SetEventObject(this);
1158 HandleWindowEvent(eventShow
);
1164 bool wxWindowMac::OSXShowWithEffect(bool show
,
1165 wxShowEffect effect
,
1168 if ( effect
== wxSHOW_EFFECT_NONE
||
1169 !m_peer
|| !m_peer
->ShowWithEffect(show
, effect
, timeout
) )
1175 void wxWindowMac::DoEnable(bool enable
)
1177 m_peer
->Enable( enable
) ;
1178 MacInvalidateBorders();
1182 // status change notifications
1185 void wxWindowMac::MacVisibilityChanged()
1189 void wxWindowMac::MacHiliteChanged()
1193 void wxWindowMac::MacEnabledStateChanged()
1195 OnEnabled( m_peer
->IsEnabled() );
1199 // status queries on the inherited window's state
1202 bool wxWindowMac::MacIsReallyEnabled()
1204 return m_peer
->IsEnabled() ;
1207 bool wxWindowMac::MacIsReallyHilited()
1209 #if wxOSX_USE_CARBON
1210 return m_peer
->IsActive();
1212 return true; // TODO
1216 int wxWindowMac::GetCharHeight() const
1219 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1224 int wxWindowMac::GetCharWidth() const
1227 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1232 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1235 int *externalLeading
,
1236 const wxFont
*theFont
) const
1238 const wxFont
*fontToUse
= theFont
;
1242 tempFont
= GetFont();
1243 fontToUse
= &tempFont
;
1246 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1247 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1249 wxDouble h
, d
, e
, w
;
1250 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1254 if ( externalLeading
)
1255 *externalLeading
= (wxCoord
)(e
+0.5);
1257 *descent
= (wxCoord
)(d
+0.5);
1259 *x
= (wxCoord
)(w
+0.5);
1261 *y
= (wxCoord
)(h
+0.5);
1265 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1266 * we always intersect with the entire window, not only with the client area
1269 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1271 if ( m_peer
== NULL
)
1274 if ( !IsShownOnScreen() )
1277 m_peer
->SetNeedsDisplay( rect
) ;
1280 void wxWindowMac::DoFreeze()
1282 #if wxOSX_USE_CARBON
1283 if ( m_peer
&& m_peer
->IsOk() )
1284 m_peer
->SetDrawingEnabled( false ) ;
1288 void wxWindowMac::DoThaw()
1290 #if wxOSX_USE_CARBON
1291 if ( m_peer
&& m_peer
->IsOk() )
1293 m_peer
->SetDrawingEnabled( true ) ;
1294 m_peer
->InvalidateWithChildren() ;
1299 wxWindow
*wxGetActiveWindow()
1301 // actually this is a windows-only concept
1305 // Coordinates relative to the window
1306 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1308 #if wxOSX_USE_COCOA_OR_CARBON
1311 DoClientToScreen(&x
, &y
);
1312 CGPoint cgpoint
= CGPointMake( x
, y
);
1313 CGWarpMouseCursorPosition( cgpoint
);
1315 // At least GTK sends a mouse moved event after WarpMouse
1316 wxMouseEvent
event(wxEVT_MOTION
);
1319 wxMouseState mState
= ::wxGetMouseState();
1321 event
.m_altDown
= mState
.AltDown();
1322 event
.m_controlDown
= mState
.ControlDown();
1323 event
.m_leftDown
= mState
.LeftIsDown();
1324 event
.m_middleDown
= mState
.MiddleIsDown();
1325 event
.m_rightDown
= mState
.RightIsDown();
1326 event
.m_metaDown
= mState
.MetaDown();
1327 event
.m_shiftDown
= mState
.ShiftDown();
1328 event
.SetId(GetId());
1329 event
.SetEventObject(this);
1330 GetEventHandler()->ProcessEvent(event
);
1334 int wxWindowMac::GetScrollPos(int orient
) const
1337 if ( orient
== wxHORIZONTAL
)
1340 return m_hScrollBar
->GetThumbPosition() ;
1345 return m_vScrollBar
->GetThumbPosition() ;
1351 // This now returns the whole range, not just the number
1352 // of positions that we can scroll.
1353 int wxWindowMac::GetScrollRange(int orient
) const
1356 if ( orient
== wxHORIZONTAL
)
1359 return m_hScrollBar
->GetRange() ;
1364 return m_vScrollBar
->GetRange() ;
1370 int wxWindowMac::GetScrollThumb(int orient
) const
1373 if ( orient
== wxHORIZONTAL
)
1376 return m_hScrollBar
->GetThumbSize() ;
1381 return m_vScrollBar
->GetThumbSize() ;
1387 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1390 if ( orient
== wxHORIZONTAL
)
1393 m_hScrollBar
->SetThumbPosition( pos
) ;
1398 m_vScrollBar
->SetThumbPosition( pos
) ;
1404 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1406 bool needVisibilityUpdate
= false;
1408 if ( m_hScrollBarAlwaysShown
!= hflag
)
1410 m_hScrollBarAlwaysShown
= hflag
;
1411 needVisibilityUpdate
= true;
1414 if ( m_vScrollBarAlwaysShown
!= vflag
)
1416 m_vScrollBarAlwaysShown
= vflag
;
1417 needVisibilityUpdate
= true;
1420 if ( needVisibilityUpdate
)
1421 DoUpdateScrollbarVisibility();
1425 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1426 // our own window origin is at leftOrigin/rightOrigin
1429 void wxWindowMac::MacPaintGrowBox()
1435 if ( MacHasScrollBarCorner() )
1438 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1439 wxASSERT( cgContext
) ;
1443 m_peer
->GetSize( tw
, th
);
1444 m_peer
->GetPosition( tx
, ty
);
1446 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1449 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1450 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1451 CGContextSaveGState( cgContext
);
1453 if ( m_backgroundColour
.Ok() )
1455 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1459 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1461 CGContextFillRect( cgContext
, cgrect
);
1462 CGContextRestoreGState( cgContext
);
1466 if ( m_backgroundColour
.Ok() )
1467 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1469 m_growBox
->SetBackgroundColour(*wxWHITE
);
1477 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1482 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1484 // back to the surrounding frame rectangle
1487 m_peer
->GetSize( tw
, th
);
1488 m_peer
->GetPosition( tx
, ty
);
1490 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1492 #if wxOSX_USE_COCOA_OR_CARBON
1494 InsetRect( &rect
, -1 , -1 ) ;
1497 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1498 rect
.bottom
- rect
.top
) ;
1500 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1501 wxASSERT( cgContext
) ;
1503 if ( m_peer
->NeedsFrame() )
1505 HIThemeFrameDrawInfo info
;
1506 memset( &info
, 0 , sizeof(info
) ) ;
1510 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1511 info
.isFocused
= hasFocus
;
1513 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1515 info
.kind
= kHIThemeFrameTextFieldSquare
;
1516 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1518 else if ( HasFlag(wxSIMPLE_BORDER
) )
1520 info
.kind
= kHIThemeFrameListBox
;
1521 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1527 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1530 #endif // wxOSX_USE_COCOA_OR_CARBON
1533 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1536 if ( child
== m_hScrollBar
)
1537 m_hScrollBar
= NULL
;
1538 if ( child
== m_vScrollBar
)
1539 m_vScrollBar
= NULL
;
1540 if ( child
== m_growBox
)
1543 wxWindowBase::RemoveChild( child
) ;
1546 void wxWindowMac::DoUpdateScrollbarVisibility()
1549 bool triggerSizeEvent
= false;
1553 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1555 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1557 m_hScrollBar
->Show( showHScrollBar
);
1558 triggerSizeEvent
= true;
1564 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1566 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1568 m_vScrollBar
->Show( showVScrollBar
) ;
1569 triggerSizeEvent
= true;
1573 MacRepositionScrollBars() ;
1574 if ( triggerSizeEvent
)
1576 wxSizeEvent
event(GetSize(), m_windowId
);
1577 event
.SetEventObject(this);
1578 HandleWindowEvent(event
);
1583 // New function that will replace some of the above.
1584 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1585 int range
, bool refresh
)
1588 // Updating scrollbars when window is being deleted is useless and
1589 // currently results in asserts in client-to-screen coordinates conversion
1590 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1591 if ( m_isBeingDeleted
)
1594 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1595 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1596 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1597 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1599 DoUpdateScrollbarVisibility();
1603 // Does a physical scroll
1604 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1606 if ( dx
== 0 && dy
== 0 )
1609 int width
, height
;
1610 GetClientSize( &width
, &height
) ;
1613 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1615 scrollrect
.Intersect( *rect
) ;
1616 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1617 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1619 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1624 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1626 child
= node
->GetData();
1630 if (child
->IsTopLevel())
1633 if ( !IsClientAreaChild(child
) )
1636 child
->GetPosition( &x
, &y
);
1637 child
->GetSize( &w
, &h
);
1640 wxRect
rc( x
, y
, w
, h
);
1641 if (rect
->Intersects( rc
))
1642 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1646 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1651 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1654 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1656 wxScrollWinEvent wevent
;
1657 wevent
.SetPosition(event
.GetPosition());
1658 wevent
.SetOrientation(event
.GetOrientation());
1659 wevent
.SetEventObject(this);
1661 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1662 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1663 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1664 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1665 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1666 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1667 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1668 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1669 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1670 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1671 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1672 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1673 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1674 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1675 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1676 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1678 HandleWindowEvent(wevent
);
1683 wxWindow
*wxWindowBase::DoFindFocus()
1685 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1688 void wxWindowMac::OnInternalIdle()
1690 // This calls the UI-update mechanism (querying windows for
1691 // menu/toolbar/control state information)
1692 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1693 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1696 // Raise the window to the top of the Z order
1697 void wxWindowMac::Raise()
1702 // Lower the window to the bottom of the Z order
1703 void wxWindowMac::Lower()
1708 // static wxWindow *gs_lastWhich = NULL;
1710 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1712 // first trigger a set cursor event
1714 wxPoint clientorigin
= GetClientAreaOrigin() ;
1715 wxSize clientsize
= GetClientSize() ;
1717 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1719 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1721 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1722 if ( processedEvtSetCursor
&& event
.HasCursor() )
1724 cursor
= event
.GetCursor() ;
1728 // the test for processedEvtSetCursor is here to prevent using m_cursor
1729 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1730 // it - this is a way to say that our cursor shouldn't be used for this
1732 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1735 if ( !wxIsBusy() && !GetParent() )
1736 cursor
= *wxSTANDARD_CURSOR
;
1740 cursor
.MacInstall() ;
1743 return cursor
.Ok() ;
1746 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1750 return m_tooltip
->GetTip() ;
1753 return wxEmptyString
;
1756 void wxWindowMac::ClearBackground()
1762 void wxWindowMac::Update()
1764 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1769 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1771 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1775 if ( iter
->IsTopLevel() )
1777 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1781 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1786 iter
= iter
->GetParent() ;
1792 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1794 MacUpdateClippedRects() ;
1796 return m_cachedClippedClientRect
;
1799 const wxRect
& wxWindowMac::MacGetClippedRect() const
1801 MacUpdateClippedRects() ;
1803 return m_cachedClippedRect
;
1806 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1808 MacUpdateClippedRects() ;
1810 return m_cachedClippedRectWithOuterStructure
;
1813 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1815 static wxRegion emptyrgn
;
1817 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1819 MacUpdateClippedRects() ;
1820 if ( includeOuterStructures
)
1821 return m_cachedClippedRegionWithOuterStructure
;
1823 return m_cachedClippedRegion
;
1831 void wxWindowMac::MacUpdateClippedRects() const
1833 #if wxOSX_USE_CARBON
1834 if ( m_cachedClippedRectValid
)
1837 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1838 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1839 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1840 // to add focus borders everywhere
1842 Rect rIncludingOuterStructures
;
1846 m_peer
->GetSize( tw
, th
);
1847 m_peer
->GetPosition( tx
, ty
);
1849 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1851 r
.left
-= MacGetLeftBorderSize() ;
1852 r
.top
-= MacGetTopBorderSize() ;
1853 r
.bottom
+= MacGetBottomBorderSize() ;
1854 r
.right
+= MacGetRightBorderSize() ;
1861 rIncludingOuterStructures
= r
;
1862 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1864 wxRect cl
= GetClientRect() ;
1865 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1869 const wxWindow
* child
= (wxWindow
*) this ;
1870 const wxWindow
* parent
= NULL
;
1872 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1874 if ( parent
->MacIsChildOfClientArea(child
) )
1876 size
= parent
->GetClientSize() ;
1877 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1883 // this will be true for scrollbars, toolbars etc.
1884 size
= parent
->GetSize() ;
1885 y
= parent
->MacGetTopBorderSize() ;
1886 x
= parent
->MacGetLeftBorderSize() ;
1887 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1888 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1891 parent
->MacWindowToRootWindow( &x
, &y
) ;
1892 MacRootWindowToWindow( &x
, &y
) ;
1894 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1896 // the wxwindow and client rects will always be clipped
1897 SectRect( &r
, &rparent
, &r
) ;
1898 SectRect( &rClient
, &rparent
, &rClient
) ;
1900 // the structure only at 'hard' borders
1901 if ( parent
->MacClipChildren() ||
1902 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1904 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1910 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1911 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1912 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1913 m_cachedClippedRectWithOuterStructure
= wxRect(
1914 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1915 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1916 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1918 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1919 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1920 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1922 m_cachedClippedRectValid
= true ;
1927 This function must not change the updatergn !
1929 bool wxWindowMac::MacDoRedraw( long time
)
1931 bool handled
= false ;
1933 wxRegion formerUpdateRgn
= m_updateRegion
;
1934 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1936 const wxRect clientRect
= GetClientRect();
1938 clientUpdateRgn
.Intersect(clientRect
);
1940 // first send an erase event to the entire update area
1941 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1944 case wxBG_STYLE_ERASE
:
1945 case wxBG_STYLE_SYSTEM
:
1946 case wxBG_STYLE_COLOUR
:
1948 // for the toplevel window this really is the entire area for
1949 // all the others only their client area, otherwise they might
1950 // be drawing with full alpha and eg put blue into the grow-box
1951 // area of a scrolled window (scroll sample)
1952 wxWindowDC
dc(this);
1954 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1956 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1958 if ( bgStyle
== wxBG_STYLE_ERASE
)
1960 wxEraseEvent
eevent( GetId(), &dc
);
1961 eevent
.SetEventObject( this );
1962 if ( ProcessWindowEvent( eevent
) )
1968 dc
.SetBackground(GetBackgroundColour());
1974 case wxBG_STYLE_PAINT
:
1975 case wxBG_STYLE_TRANSPARENT
:
1976 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1977 // entire window client area
1981 wxFAIL_MSG( "unsupported background style" );
1984 // as this is a full window, shouldn't be necessary anymore
1985 // MacPaintGrowBox();
1987 // calculate a client-origin version of the update rgn and set
1988 // m_updateRegion to that
1989 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1990 m_updateRegion
= clientUpdateRgn
;
1992 if ( !m_updateRegion
.Empty() )
1994 // paint the window itself
1996 wxPaintEvent
event(GetId());
1997 event
.SetTimestamp(time
);
1998 event
.SetEventObject(this);
1999 handled
= HandleWindowEvent(event
);
2002 m_updateRegion
= formerUpdateRgn
;
2006 void wxWindowMac::MacPaintChildrenBorders()
2008 // now we cannot rely on having its borders drawn by a window itself, as it does not
2009 // get the updateRgn wide enough to always do so, so we do it from the parent
2010 // this would also be the place to draw any custom backgrounds for native controls
2011 // in Composited windowing
2012 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2016 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2018 child
= node
->GetData();
2022 if (child
== m_vScrollBar
)
2024 if (child
== m_hScrollBar
)
2026 if (child
== m_growBox
)
2029 if (child
->IsTopLevel())
2031 if (!child
->IsShown())
2034 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2036 child
->GetPosition( &x
, &y
);
2037 child
->GetSize( &w
, &h
);
2039 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2041 // paint custom borders
2042 wxNcPaintEvent
eventNc( child
->GetId() );
2043 eventNc
.SetEventObject( child
);
2044 if ( !child
->HandleWindowEvent( eventNc
) )
2046 child
->MacPaintBorders(0, 0) ;
2053 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2055 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2056 return tlw
? tlw
->GetWXWindow() : NULL
;
2059 bool wxWindowMac::MacHasScrollBarCorner() const
2062 /* Returns whether the scroll bars in a wxScrolledWindow should be
2063 * shortened. Scroll bars should be shortened if either:
2065 * - both scroll bars are visible, or
2067 * - there is a resize box in the parent frame's corner and this
2068 * window shares the bottom and right edge with the parent
2072 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2075 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2076 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2078 // Both scroll bars visible
2083 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2085 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2087 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2090 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2092 // Parent frame has resize handle
2093 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2095 // Note: allow for some wiggle room here as wxMac's
2096 // window rect calculations seem to be imprecise
2097 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2098 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2100 // Parent frame has resize handle and shares
2101 // right bottom corner
2106 // Parent frame has resize handle but doesn't
2107 // share right bottom corner
2113 // Parent frame doesn't have resize handle
2119 // No parent frame found
2127 void wxWindowMac::MacCreateScrollBars( long style
)
2130 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2132 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2134 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2135 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2137 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2140 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2142 GetClientSize( &width
, &height
) ;
2144 wxPoint
vPoint(width
- scrlsize
, 0) ;
2145 wxSize
vSize(scrlsize
, height
- adjust
) ;
2146 wxPoint
hPoint(0, height
- scrlsize
) ;
2147 wxSize
hSize(width
- adjust
, scrlsize
) ;
2149 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2150 if ( style
& wxVSCROLL
)
2152 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2153 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2156 if ( style
& wxHSCROLL
)
2158 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2159 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2162 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2163 wxSize
gSize(scrlsize
, scrlsize
);
2164 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2167 // because the create does not take into account the client area origin
2168 // we might have a real position shift
2169 MacRepositionScrollBars() ;
2173 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2175 bool result
= ((child
== NULL
)
2177 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2184 void wxWindowMac::MacRepositionScrollBars()
2187 if ( !m_hScrollBar
&& !m_vScrollBar
)
2190 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2191 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2193 // get real client area
2195 GetSize( &width
, &height
);
2197 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2198 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2200 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2201 wxSize
vSize( scrlsize
, height
- adjust
) ;
2202 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2203 wxSize
hSize( width
- adjust
, scrlsize
) ;
2206 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2208 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2211 if ( MacHasScrollBarCorner() )
2213 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2214 if ( !m_growBox
->IsShown() )
2219 if ( m_growBox
->IsShown() )
2226 bool wxWindowMac::AcceptsFocus() const
2228 if ( MacIsUserPane() )
2229 return wxWindowBase::AcceptsFocus();
2231 return m_peer
->CanFocus();
2234 void wxWindowMac::MacSuperChangedPosition()
2236 // only window-absolute structures have to be moved i.e. controls
2238 m_cachedClippedRectValid
= false ;
2241 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2244 child
= node
->GetData();
2245 child
->MacSuperChangedPosition() ;
2247 node
= node
->GetNext();
2251 void wxWindowMac::MacTopLevelWindowChangedPosition()
2253 // only screen-absolute structures have to be moved i.e. glcanvas
2256 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2259 child
= node
->GetData();
2260 child
->MacTopLevelWindowChangedPosition() ;
2262 node
= node
->GetNext();
2266 long wxWindowMac::MacGetLeftBorderSize() const
2273 if ( m_peer
&& m_peer
->NeedsFrame() )
2275 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2277 #if wxOSX_USE_COCOA_OR_CARBON
2278 // this metric is only the 'outset' outside the simple frame rect
2279 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2285 else if (HasFlag(wxSIMPLE_BORDER
))
2287 #if wxOSX_USE_COCOA_OR_CARBON
2288 // this metric is only the 'outset' outside the simple frame rect
2289 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2300 long wxWindowMac::MacGetRightBorderSize() const
2302 // they are all symmetric in mac themes
2303 return MacGetLeftBorderSize() ;
2306 long wxWindowMac::MacGetTopBorderSize() const
2308 // they are all symmetric in mac themes
2309 return MacGetLeftBorderSize() ;
2312 long wxWindowMac::MacGetBottomBorderSize() const
2314 // they are all symmetric in mac themes
2315 return MacGetLeftBorderSize() ;
2318 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2320 return style
& ~wxBORDER_MASK
;
2323 // Find the wxWindowMac at the current mouse position, returning the mouse
2325 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2327 pt
= wxGetMousePosition();
2328 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2330 return (wxWindow
*) found
;
2333 // Get the current mouse position.
2334 wxPoint
wxGetMousePosition()
2338 wxGetMousePosition( &x
, &y
);
2340 return wxPoint(x
, y
);
2343 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2345 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2347 // copied from wxGTK : CS
2348 // VZ: shouldn't we move this to base class then?
2350 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2353 // (a) it's a command event and so is propagated to the parent
2354 // (b) under MSW it can be generated from kbd too
2355 // (c) it uses screen coords (because of (a))
2356 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2358 this->ClientToScreen(event
.GetPosition()));
2359 evtCtx
.SetEventObject(this);
2360 if ( ! HandleWindowEvent(evtCtx
) )
2369 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2373 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2377 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2378 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2383 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2388 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2390 #if wxOSX_USE_COCOA_OR_CARBON
2391 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2394 return eventNotHandledErr
;
2400 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2402 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2403 if ( !wxWindowBase::Reparent(newParent
) )
2406 m_peer
->RemoveFromParent();
2407 m_peer
->Embed( GetParent()->GetPeer() );
2413 bool wxWindowMac::SetTransparent(wxByte alpha
)
2415 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2417 if ( alpha
!= m_macAlpha
)
2419 m_macAlpha
= alpha
;
2426 bool wxWindowMac::CanSetTransparent()
2431 wxByte
wxWindowMac::GetTransparent() const
2436 bool wxWindowMac::IsShownOnScreen() const
2438 if ( m_peer
&& m_peer
->IsOk() )
2440 bool peerVis
= m_peer
->IsVisible();
2441 bool wxVis
= wxWindowBase::IsShownOnScreen();
2442 if( peerVis
!= wxVis
)
2444 // CS : put a breakpoint here to investigate differences
2445 // between native an wx visibilities
2446 // the only place where I've encountered them until now
2447 // are the hiding/showing sequences where the vis-changed event is
2448 // first sent to the innermost control, while wx does things
2449 // from the outmost control
2450 wxVis
= wxWindowBase::IsShownOnScreen();
2454 return m_peer
->IsVisible();
2456 return wxWindowBase::IsShownOnScreen();
2459 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2461 bool handled
= HandleWindowEvent( event
) ;
2462 if ( handled
&& event
.GetSkipped() )
2466 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2468 wxWindow
*ancestor
= this;
2471 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2474 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2476 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2477 handled
= handler
->ProcessEvent( command_event
);
2481 // accelerators can also be used with buttons, try them too
2482 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2483 handled
= handler
->ProcessEvent( command_event
);
2489 if (ancestor
->IsTopLevel())
2492 ancestor
= ancestor
->GetParent();
2495 #endif // wxUSE_ACCEL
2504 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2506 static MacControlMap wxWinMacControlList
;
2508 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2510 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2512 return impl
->GetWXPeer();
2517 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2519 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2521 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2524 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2526 // adding NULL ControlRef is (first) surely a result of an error and
2527 // (secondly) breaks native event processing
2528 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2530 wxWinMacControlList
[inControl
] = impl
;
2533 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2535 // iterate over all the elements in the class
2536 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2537 // we should go on...
2543 MacControlMap::iterator it
;
2544 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2546 if ( it
->second
== impl
)
2548 wxWinMacControlList
.erase(it
);
2556 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2558 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2561 m_isRootControl
= isRootControl
;
2563 m_shouldSendEvents
= true;
2566 wxWidgetImpl::wxWidgetImpl()
2571 wxWidgetImpl::~wxWidgetImpl()
2575 void wxWidgetImpl::Init()
2577 m_isRootControl
= false;
2579 m_needsFocusRect
= false;
2580 m_needsFrame
= true;
2583 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2585 m_needsFocusRect
= needs
;
2588 bool wxWidgetImpl::NeedsFocusRect() const
2590 return m_needsFocusRect
;
2593 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2595 m_needsFrame
= needs
;
2598 bool wxWidgetImpl::NeedsFrame() const
2600 return m_needsFrame
;