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 void wxWindowMac::SetPeer(wxOSXWidgetImpl
* peer
)
274 // todo event check handlers
278 // ---------------------------------------------------------------------------
279 // Utility Routines to move between different coordinate systems
280 // ---------------------------------------------------------------------------
283 * Right now we have the following setup :
284 * a border that is not part of the native control is always outside the
285 * control's border (otherwise we loose all native intelligence, future ways
286 * may be to have a second embedding control responsible for drawing borders
287 * and backgrounds eventually)
288 * so all this border calculations have to be taken into account when calling
289 * native methods or getting native oriented data
290 * so we have three coordinate systems here
291 * wx client coordinates
292 * wx window coordinates (including window frames)
300 bool wxWindowMac::Create(wxWindowMac
*parent
,
305 const wxString
& name
)
307 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
309 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
312 m_windowVariant
= parent
->GetWindowVariant() ;
314 if ( m_macIsUserPane
)
316 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
317 MacPostControlCreate(pos
, size
) ;
320 #ifndef __WXUNIVERSAL__
321 // Don't give scrollbars to wxControls unless they ask for them
322 if ( (! IsKindOf(CLASSINFO(wxControl
))
324 && ! IsKindOf(CLASSINFO(wxStatusBar
))
327 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
329 MacCreateScrollBars( style
) ;
333 wxWindowCreateEvent
event((wxWindow
*)this);
334 GetEventHandler()->AddPendingEvent(event
);
339 void wxWindowMac::MacChildAdded()
343 m_vScrollBar
->Raise() ;
345 m_hScrollBar
->Raise() ;
351 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
353 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
355 GetParent()->AddChild( this );
357 m_peer
->InstallEventHandler();
358 m_peer
->Embed(GetParent()->GetPeer());
360 GetParent()->MacChildAdded() ;
362 // adjust font, controlsize etc
363 DoSetWindowVariant( m_windowVariant
) ;
365 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
367 // for controls we want to use best size for wxDefaultSize params )
368 if ( !m_macIsUserPane
)
369 SetInitialSize(size
);
371 SetCursor( *wxSTANDARD_CURSOR
) ;
374 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
376 // Don't assert, in case we set the window variant before
377 // the window is created
378 // wxASSERT( m_peer->Ok() ) ;
380 m_windowVariant
= variant
;
382 if (m_peer
== NULL
|| !m_peer
->IsOk())
385 m_peer
->SetControlSize( variant
);
389 // we will get that from the settings later
390 // and make this NORMAL later, but first
391 // we have a few calculations that we must fix
395 case wxWINDOW_VARIANT_NORMAL
:
396 size
= kControlSizeNormal
;
399 case wxWINDOW_VARIANT_SMALL
:
400 size
= kControlSizeSmall
;
403 case wxWINDOW_VARIANT_MINI
:
404 // not always defined in the headers
408 case wxWINDOW_VARIANT_LARGE
:
409 size
= kControlSizeLarge
;
413 wxFAIL_MSG(wxT("unexpected window variant"));
416 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
422 case wxWINDOW_VARIANT_NORMAL
:
423 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
427 case wxWINDOW_VARIANT_SMALL
:
428 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
432 case wxWINDOW_VARIANT_MINI
:
433 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
437 case wxWINDOW_VARIANT_LARGE
:
438 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
443 wxFAIL_MSG(wxT("unexpected window variant"));
448 void wxWindowMac::MacUpdateControlFont()
451 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
453 // do not trigger refreshes upon invisible and possible partly created objects
454 if ( IsShownOnScreen() )
458 bool wxWindowMac::SetFont(const wxFont
& font
)
460 bool retval
= wxWindowBase::SetFont( font
);
462 MacUpdateControlFont() ;
467 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
469 bool retval
= wxWindowBase::SetForegroundColour( col
);
472 MacUpdateControlFont();
477 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
479 if ( !wxWindowBase::SetBackgroundStyle(style
) )
483 m_peer
->SetBackgroundStyle(style
);
487 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
491 if ( m_backgroundColour
.Ok() )
492 m_growBox
->SetBackgroundColour(m_backgroundColour
);
494 m_growBox
->SetBackgroundColour(*wxWHITE
);
497 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
501 m_peer
->SetBackgroundColour( col
) ;
506 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
508 while (w
&& !w
->IsTopLevel())
517 void wxWindowMac::SetFocus()
519 if ( !AcceptsFocus() )
522 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
525 wxWindow
* former
= FindFocus() ;
526 if ( former
== this )
532 void wxWindowMac::DoCaptureMouse()
534 wxApp::s_captureWindow
= (wxWindow
*) this ;
535 m_peer
->CaptureMouse() ;
538 wxWindow
* wxWindowBase::GetCapture()
540 return wxApp::s_captureWindow
;
543 void wxWindowMac::DoReleaseMouse()
545 wxApp::s_captureWindow
= NULL
;
547 m_peer
->ReleaseMouse() ;
550 #if wxUSE_DRAG_AND_DROP
552 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
556 m_dropTarget
= pDropTarget
;
557 if ( m_dropTarget
!= NULL
)
565 // Old-style File Manager Drag & Drop
566 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
571 // From a wx position / size calculate the appropriate size of the native control
573 bool wxWindowMac::MacGetBoundsForControl(
577 int& w
, int& h
, bool adjustOrigin
) const
579 // the desired size, minus the border pixels gives the correct size of the control
583 w
= WidthDefault( size
.x
);
584 h
= HeightDefault( size
.y
);
586 x
+= MacGetLeftBorderSize() ;
587 y
+= MacGetTopBorderSize() ;
588 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
589 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
592 AdjustForParentClientOrigin( x
, y
) ;
594 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
595 if ( GetParent() && !GetParent()->IsTopLevel() )
597 x
-= GetParent()->MacGetLeftBorderSize() ;
598 y
-= GetParent()->MacGetTopBorderSize() ;
604 // Get window size (not client size)
605 void wxWindowMac::DoGetSize(int *x
, int *y
) const
608 m_peer
->GetSize( width
, height
);
611 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
613 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
616 // get the position of the bounds of this window in client coordinates of its parent
617 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
621 m_peer
->GetPosition( x1
, y1
) ;
623 // get the wx window position from the native one
624 x1
-= MacGetLeftBorderSize() ;
625 y1
-= MacGetTopBorderSize() ;
629 wxWindow
*parent
= GetParent();
632 // we must first adjust it to be in window coordinates of the parent,
633 // as otherwise it gets lost by the ClientAreaOrigin fix
634 x1
+= parent
->MacGetLeftBorderSize() ;
635 y1
+= parent
->MacGetTopBorderSize() ;
637 // and now to client coordinates
638 wxPoint
pt(parent
->GetClientAreaOrigin());
650 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
652 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
653 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
654 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
655 MacRootWindowToWindow( x
, y
) ;
657 wxPoint origin
= GetClientAreaOrigin() ;
664 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
666 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
667 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
669 wxPoint origin
= GetClientAreaOrigin() ;
675 MacWindowToRootWindow( x
, y
) ;
676 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
679 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
681 wxPoint origin
= GetClientAreaOrigin() ;
687 MacWindowToRootWindow( x
, y
) ;
690 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
701 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
704 pt
.x
-= MacGetLeftBorderSize() ;
705 pt
.y
-= MacGetTopBorderSize() ;
706 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
716 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
727 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
730 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
731 pt
.x
+= MacGetLeftBorderSize() ;
732 pt
.y
+= MacGetTopBorderSize() ;
742 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
744 wxSize sizeTotal
= size
;
746 int innerwidth
, innerheight
;
748 int outerwidth
, outerheight
;
750 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
751 m_peer
->GetSize( outerwidth
, outerheight
);
753 sizeTotal
.x
+= outerwidth
-innerwidth
;
754 sizeTotal
.y
+= outerheight
-innerheight
;
756 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
757 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
762 // Get size *available for subwindows* i.e. excluding menu bar etc.
763 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
769 m_peer
->GetContentArea( left
, top
, ww
, hh
);
771 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
772 hh
-= m_hScrollBar
->GetSize().y
;
774 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
775 ww
-= m_vScrollBar
->GetSize().x
;
784 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
786 if (m_cursor
.IsSameAs(cursor
))
791 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
796 if ( ! wxWindowBase::SetCursor( cursor
) )
800 wxASSERT_MSG( m_cursor
.Ok(),
801 wxT("cursor must be valid after call to the base version"));
803 if ( GetPeer() != NULL
)
804 GetPeer()->SetCursor( m_cursor
);
810 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
812 #ifndef __WXUNIVERSAL__
815 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
817 wxPoint mouse
= wxGetMousePosition();
823 ClientToScreen( &x
, &y
) ;
825 menu
->GetPeer()->PopUp(this, x
, y
);
828 // actually this shouldn't be called, because universal is having its own implementation
834 // ----------------------------------------------------------------------------
836 // ----------------------------------------------------------------------------
840 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
842 wxWindowBase::DoSetToolTip(tooltip
);
845 m_tooltip
->SetWindow(this);
848 m_peer
->SetToolTip(tooltip
);
853 void wxWindowMac::MacInvalidateBorders()
855 if ( m_peer
== NULL
)
858 bool vis
= IsShownOnScreen() ;
862 int outerBorder
= MacGetLeftBorderSize() ;
864 if ( m_peer
->NeedsFocusRect() )
867 if ( outerBorder
== 0 )
870 // now we know that we have something to do at all
874 m_peer
->GetSize( tw
, th
);
875 m_peer
->GetPosition( tx
, ty
);
877 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
878 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
879 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
880 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
883 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
884 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
885 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
886 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
890 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
892 // this is never called for a toplevel window, so we know we have a parent
893 int former_x
, former_y
, former_w
, former_h
;
895 // Get true coordinates of former position
896 DoGetPosition( &former_x
, &former_y
) ;
897 DoGetSize( &former_w
, &former_h
) ;
899 wxWindow
*parent
= GetParent();
902 wxPoint
pt(parent
->GetClientAreaOrigin());
907 int actualWidth
= width
;
908 int actualHeight
= height
;
913 // min and max sizes are only for sizers, not for explicit size setting
914 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
915 actualWidth
= m_minWidth
;
916 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
917 actualHeight
= m_minHeight
;
918 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
919 actualWidth
= m_maxWidth
;
920 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
921 actualHeight
= m_maxHeight
;
924 bool doMove
= false, doResize
= false ;
926 if ( actualX
!= former_x
|| actualY
!= former_y
)
929 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
932 if ( doMove
|| doResize
)
934 // as the borders are drawn outside the native control, we adjust now
936 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
937 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
938 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
940 if ( parent
&& !parent
->IsTopLevel() )
942 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
945 MacInvalidateBorders() ;
947 m_cachedClippedRectValid
= false ;
949 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
951 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
953 MacInvalidateBorders() ;
955 MacRepositionScrollBars() ;
958 wxPoint
point(actualX
, actualY
);
959 wxMoveEvent
event(point
, m_windowId
);
960 event
.SetEventObject(this);
961 HandleWindowEvent(event
) ;
966 MacRepositionScrollBars() ;
967 wxSize
size(actualWidth
, actualHeight
);
968 wxSizeEvent
event(size
, m_windowId
);
969 event
.SetEventObject(this);
970 HandleWindowEvent(event
);
975 wxSize
wxWindowMac::DoGetBestSize() const
977 if ( m_macIsUserPane
|| IsTopLevel() )
979 return wxWindowBase::DoGetBestSize() ;
985 m_peer
->GetBestRect(&r
);
987 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
995 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1002 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1009 // return wxWindowBase::DoGetBestSize() ;
1013 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1014 MacGetRightBorderSize();
1015 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1016 MacGetBottomBorderSize();
1017 if ( bestHeight
< 10 )
1020 return wxSize(bestWidth
, bestHeight
);
1024 // set the size of the window: if the dimensions are positive, just use them,
1025 // but if any of them is equal to -1, it means that we must find the value for
1026 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1027 // which case -1 is a valid value for x and y)
1029 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1030 // the width/height to best suit our contents, otherwise we reuse the current
1032 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1034 // get the current size and position...
1035 int currentX
, currentY
;
1036 int currentW
, currentH
;
1038 GetPosition(¤tX
, ¤tY
);
1039 GetSize(¤tW
, ¤tH
);
1041 // ... and don't do anything (avoiding flicker) if it's already ok
1042 if ( x
== currentX
&& y
== currentY
&&
1043 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1046 MacRepositionScrollBars() ; // we might have a real position shift
1048 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1050 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1051 event
.SetEventObject( this );
1052 HandleWindowEvent( event
);
1058 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1060 if ( x
== wxDefaultCoord
)
1062 if ( y
== wxDefaultCoord
)
1066 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1068 wxSize size
= wxDefaultSize
;
1069 if ( width
== wxDefaultCoord
)
1071 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1073 size
= DoGetBestSize();
1078 // just take the current one
1083 if ( height
== wxDefaultCoord
)
1085 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1087 if ( size
.x
== wxDefaultCoord
)
1088 size
= DoGetBestSize();
1089 // else: already called DoGetBestSize() above
1095 // just take the current one
1100 DoMoveWindow( x
, y
, width
, height
);
1103 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1105 int left
,top
,width
,height
;
1106 m_peer
->GetContentArea( left
, top
, width
, height
);
1107 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1110 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1112 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1114 int currentclientwidth
, currentclientheight
;
1115 int currentwidth
, currentheight
;
1117 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1118 GetSize( ¤twidth
, ¤theight
) ;
1120 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1121 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1125 float wxWindowMac::GetContentScaleFactor() const
1127 return m_peer
->GetContentScaleFactor();
1130 void wxWindowMac::SetLabel(const wxString
& title
)
1132 if ( title
== m_label
)
1137 InvalidateBestSize();
1139 if ( m_peer
&& m_peer
->IsOk() )
1140 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1142 // do not trigger refreshes upon invisible and possible partly created objects
1143 if ( IsShownOnScreen() )
1147 wxString
wxWindowMac::GetLabel() const
1152 bool wxWindowMac::Show(bool show
)
1154 if ( !wxWindowBase::Show(show
) )
1158 m_peer
->SetVisibility( show
) ;
1160 #ifdef __WXOSX_IPHONE__
1161 // only when there's no native event support
1162 if ( !IsTopLevel() )
1165 wxShowEvent
eventShow(GetId(), show
);
1166 eventShow
.SetEventObject(this);
1168 HandleWindowEvent(eventShow
);
1174 bool wxWindowMac::OSXShowWithEffect(bool show
,
1175 wxShowEffect effect
,
1178 if ( effect
== wxSHOW_EFFECT_NONE
||
1179 !m_peer
|| !m_peer
->ShowWithEffect(show
, effect
, timeout
) )
1185 void wxWindowMac::DoEnable(bool enable
)
1187 m_peer
->Enable( enable
) ;
1188 MacInvalidateBorders();
1192 // status change notifications
1195 void wxWindowMac::MacVisibilityChanged()
1199 void wxWindowMac::MacHiliteChanged()
1203 void wxWindowMac::MacEnabledStateChanged()
1205 OnEnabled( m_peer
->IsEnabled() );
1209 // status queries on the inherited window's state
1212 bool wxWindowMac::MacIsReallyEnabled()
1214 return m_peer
->IsEnabled() ;
1217 bool wxWindowMac::MacIsReallyHilited()
1219 #if wxOSX_USE_CARBON
1220 return m_peer
->IsActive();
1222 return true; // TODO
1226 int wxWindowMac::GetCharHeight() const
1229 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1234 int wxWindowMac::GetCharWidth() const
1237 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1242 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1245 int *externalLeading
,
1246 const wxFont
*theFont
) const
1248 const wxFont
*fontToUse
= theFont
;
1252 tempFont
= GetFont();
1253 fontToUse
= &tempFont
;
1256 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1257 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1259 wxDouble h
, d
, e
, w
;
1260 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1264 if ( externalLeading
)
1265 *externalLeading
= (wxCoord
)(e
+0.5);
1267 *descent
= (wxCoord
)(d
+0.5);
1269 *x
= (wxCoord
)(w
+0.5);
1271 *y
= (wxCoord
)(h
+0.5);
1275 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1276 * we always intersect with the entire window, not only with the client area
1279 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1281 if ( m_peer
== NULL
)
1284 if ( !IsShownOnScreen() )
1287 m_peer
->SetNeedsDisplay( rect
) ;
1290 void wxWindowMac::DoFreeze()
1292 #if wxOSX_USE_CARBON
1293 if ( m_peer
&& m_peer
->IsOk() )
1294 m_peer
->SetDrawingEnabled( false ) ;
1298 void wxWindowMac::DoThaw()
1300 #if wxOSX_USE_CARBON
1301 if ( m_peer
&& m_peer
->IsOk() )
1303 m_peer
->SetDrawingEnabled( true ) ;
1304 m_peer
->InvalidateWithChildren() ;
1309 wxWindow
*wxGetActiveWindow()
1311 // actually this is a windows-only concept
1315 // Coordinates relative to the window
1316 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1318 #if wxOSX_USE_COCOA_OR_CARBON
1321 DoClientToScreen(&x
, &y
);
1322 CGPoint cgpoint
= CGPointMake( x
, y
);
1323 CGWarpMouseCursorPosition( cgpoint
);
1325 // At least GTK sends a mouse moved event after WarpMouse
1326 wxMouseEvent
event(wxEVT_MOTION
);
1329 wxMouseState mState
= ::wxGetMouseState();
1331 event
.m_altDown
= mState
.AltDown();
1332 event
.m_controlDown
= mState
.ControlDown();
1333 event
.m_leftDown
= mState
.LeftIsDown();
1334 event
.m_middleDown
= mState
.MiddleIsDown();
1335 event
.m_rightDown
= mState
.RightIsDown();
1336 event
.m_metaDown
= mState
.MetaDown();
1337 event
.m_shiftDown
= mState
.ShiftDown();
1338 event
.SetId(GetId());
1339 event
.SetEventObject(this);
1340 GetEventHandler()->ProcessEvent(event
);
1344 int wxWindowMac::GetScrollPos(int orient
) const
1347 if ( orient
== wxHORIZONTAL
)
1350 return m_hScrollBar
->GetThumbPosition() ;
1355 return m_vScrollBar
->GetThumbPosition() ;
1361 // This now returns the whole range, not just the number
1362 // of positions that we can scroll.
1363 int wxWindowMac::GetScrollRange(int orient
) const
1366 if ( orient
== wxHORIZONTAL
)
1369 return m_hScrollBar
->GetRange() ;
1374 return m_vScrollBar
->GetRange() ;
1380 int wxWindowMac::GetScrollThumb(int orient
) const
1383 if ( orient
== wxHORIZONTAL
)
1386 return m_hScrollBar
->GetThumbSize() ;
1391 return m_vScrollBar
->GetThumbSize() ;
1397 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1400 if ( orient
== wxHORIZONTAL
)
1403 m_hScrollBar
->SetThumbPosition( pos
) ;
1408 m_vScrollBar
->SetThumbPosition( pos
) ;
1414 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1416 bool needVisibilityUpdate
= false;
1418 if ( m_hScrollBarAlwaysShown
!= hflag
)
1420 m_hScrollBarAlwaysShown
= hflag
;
1421 needVisibilityUpdate
= true;
1424 if ( m_vScrollBarAlwaysShown
!= vflag
)
1426 m_vScrollBarAlwaysShown
= vflag
;
1427 needVisibilityUpdate
= true;
1430 if ( needVisibilityUpdate
)
1431 DoUpdateScrollbarVisibility();
1435 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1436 // our own window origin is at leftOrigin/rightOrigin
1439 void wxWindowMac::MacPaintGrowBox()
1445 if ( MacHasScrollBarCorner() )
1448 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1449 wxASSERT( cgContext
) ;
1453 m_peer
->GetSize( tw
, th
);
1454 m_peer
->GetPosition( tx
, ty
);
1456 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1459 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1460 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1461 CGContextSaveGState( cgContext
);
1463 if ( m_backgroundColour
.Ok() )
1465 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1469 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1471 CGContextFillRect( cgContext
, cgrect
);
1472 CGContextRestoreGState( cgContext
);
1476 if ( m_backgroundColour
.Ok() )
1477 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1479 m_growBox
->SetBackgroundColour(*wxWHITE
);
1487 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1492 bool hasFocus
= m_peer
->NeedsFocusRect() && HasFocus();
1494 // back to the surrounding frame rectangle
1497 m_peer
->GetSize( tw
, th
);
1498 m_peer
->GetPosition( tx
, ty
);
1500 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1502 #if wxOSX_USE_COCOA_OR_CARBON
1504 InsetRect( &rect
, -1 , -1 ) ;
1507 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1508 rect
.bottom
- rect
.top
) ;
1510 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1511 wxASSERT( cgContext
) ;
1513 if ( m_peer
->NeedsFrame() )
1515 HIThemeFrameDrawInfo info
;
1516 memset( &info
, 0 , sizeof(info
) ) ;
1520 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1521 info
.isFocused
= hasFocus
;
1523 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1525 info
.kind
= kHIThemeFrameTextFieldSquare
;
1526 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1528 else if ( HasFlag(wxSIMPLE_BORDER
) )
1530 info
.kind
= kHIThemeFrameListBox
;
1531 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1537 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1540 #endif // wxOSX_USE_COCOA_OR_CARBON
1543 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1546 if ( child
== m_hScrollBar
)
1547 m_hScrollBar
= NULL
;
1548 if ( child
== m_vScrollBar
)
1549 m_vScrollBar
= NULL
;
1550 if ( child
== m_growBox
)
1553 wxWindowBase::RemoveChild( child
) ;
1556 void wxWindowMac::DoUpdateScrollbarVisibility()
1559 bool triggerSizeEvent
= false;
1563 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1565 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1567 m_hScrollBar
->Show( showHScrollBar
);
1568 triggerSizeEvent
= true;
1574 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1576 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1578 m_vScrollBar
->Show( showVScrollBar
) ;
1579 triggerSizeEvent
= true;
1583 MacRepositionScrollBars() ;
1584 if ( triggerSizeEvent
)
1586 wxSizeEvent
event(GetSize(), m_windowId
);
1587 event
.SetEventObject(this);
1588 HandleWindowEvent(event
);
1593 // New function that will replace some of the above.
1594 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1595 int range
, bool refresh
)
1598 // Updating scrollbars when window is being deleted is useless and
1599 // currently results in asserts in client-to-screen coordinates conversion
1600 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1601 if ( m_isBeingDeleted
)
1604 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1605 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1606 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1607 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1609 DoUpdateScrollbarVisibility();
1613 // Does a physical scroll
1614 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1616 if ( dx
== 0 && dy
== 0 )
1619 int width
, height
;
1620 GetClientSize( &width
, &height
) ;
1623 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1625 scrollrect
.Intersect( *rect
) ;
1626 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1627 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1629 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1634 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1636 child
= node
->GetData();
1640 if (child
->IsTopLevel())
1643 if ( !IsClientAreaChild(child
) )
1646 child
->GetPosition( &x
, &y
);
1647 child
->GetSize( &w
, &h
);
1650 wxRect
rc( x
, y
, w
, h
);
1651 if (rect
->Intersects( rc
))
1652 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1656 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1661 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1664 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1666 wxScrollWinEvent wevent
;
1667 wevent
.SetPosition(event
.GetPosition());
1668 wevent
.SetOrientation(event
.GetOrientation());
1669 wevent
.SetEventObject(this);
1671 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1672 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1673 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1674 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1675 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1676 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1677 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1678 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1679 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1680 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1681 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1682 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1683 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1684 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1685 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1686 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1688 HandleWindowEvent(wevent
);
1693 wxWindow
*wxWindowBase::DoFindFocus()
1695 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1698 // Raise the window to the top of the Z order
1699 void wxWindowMac::Raise()
1704 // Lower the window to the bottom of the Z order
1705 void wxWindowMac::Lower()
1710 // static wxWindow *gs_lastWhich = NULL;
1712 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1714 // first trigger a set cursor event
1716 wxPoint clientorigin
= GetClientAreaOrigin() ;
1717 wxSize clientsize
= GetClientSize() ;
1719 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1721 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1723 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1724 if ( processedEvtSetCursor
&& event
.HasCursor() )
1726 cursor
= event
.GetCursor() ;
1730 // the test for processedEvtSetCursor is here to prevent using m_cursor
1731 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1732 // it - this is a way to say that our cursor shouldn't be used for this
1734 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1737 if ( !wxIsBusy() && !GetParent() )
1738 cursor
= *wxSTANDARD_CURSOR
;
1742 cursor
.MacInstall() ;
1745 return cursor
.Ok() ;
1748 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1752 return m_tooltip
->GetTip() ;
1755 return wxEmptyString
;
1758 void wxWindowMac::ClearBackground()
1764 void wxWindowMac::Update()
1766 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1771 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1773 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1777 if ( iter
->IsTopLevel() )
1779 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1783 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1788 iter
= iter
->GetParent() ;
1794 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1796 MacUpdateClippedRects() ;
1798 return m_cachedClippedClientRect
;
1801 const wxRect
& wxWindowMac::MacGetClippedRect() const
1803 MacUpdateClippedRects() ;
1805 return m_cachedClippedRect
;
1808 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1810 MacUpdateClippedRects() ;
1812 return m_cachedClippedRectWithOuterStructure
;
1815 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1817 static wxRegion emptyrgn
;
1819 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1821 MacUpdateClippedRects() ;
1822 if ( includeOuterStructures
)
1823 return m_cachedClippedRegionWithOuterStructure
;
1825 return m_cachedClippedRegion
;
1833 void wxWindowMac::MacUpdateClippedRects() const
1835 #if wxOSX_USE_CARBON
1836 if ( m_cachedClippedRectValid
)
1839 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1840 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1841 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1842 // to add focus borders everywhere
1844 Rect rIncludingOuterStructures
;
1848 m_peer
->GetSize( tw
, th
);
1849 m_peer
->GetPosition( tx
, ty
);
1851 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1853 r
.left
-= MacGetLeftBorderSize() ;
1854 r
.top
-= MacGetTopBorderSize() ;
1855 r
.bottom
+= MacGetBottomBorderSize() ;
1856 r
.right
+= MacGetRightBorderSize() ;
1863 rIncludingOuterStructures
= r
;
1864 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1866 wxRect cl
= GetClientRect() ;
1867 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1871 const wxWindow
* child
= (wxWindow
*) this ;
1872 const wxWindow
* parent
= NULL
;
1874 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1876 if ( parent
->MacIsChildOfClientArea(child
) )
1878 size
= parent
->GetClientSize() ;
1879 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1885 // this will be true for scrollbars, toolbars etc.
1886 size
= parent
->GetSize() ;
1887 y
= parent
->MacGetTopBorderSize() ;
1888 x
= parent
->MacGetLeftBorderSize() ;
1889 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1890 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1893 parent
->MacWindowToRootWindow( &x
, &y
) ;
1894 MacRootWindowToWindow( &x
, &y
) ;
1896 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1898 // the wxwindow and client rects will always be clipped
1899 SectRect( &r
, &rparent
, &r
) ;
1900 SectRect( &rClient
, &rparent
, &rClient
) ;
1902 // the structure only at 'hard' borders
1903 if ( parent
->MacClipChildren() ||
1904 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1906 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1912 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1913 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1914 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1915 m_cachedClippedRectWithOuterStructure
= wxRect(
1916 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1917 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1918 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1920 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1921 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1922 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1924 m_cachedClippedRectValid
= true ;
1929 This function must not change the updatergn !
1931 bool wxWindowMac::MacDoRedraw( long time
)
1933 bool handled
= false ;
1935 wxRegion formerUpdateRgn
= m_updateRegion
;
1936 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1938 const wxRect clientRect
= GetClientRect();
1940 clientUpdateRgn
.Intersect(clientRect
);
1942 // first send an erase event to the entire update area
1943 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1946 case wxBG_STYLE_ERASE
:
1947 case wxBG_STYLE_SYSTEM
:
1948 case wxBG_STYLE_COLOUR
:
1950 // for the toplevel window this really is the entire area for
1951 // all the others only their client area, otherwise they might
1952 // be drawing with full alpha and eg put blue into the grow-box
1953 // area of a scrolled window (scroll sample)
1954 wxWindowDC
dc(this);
1956 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1958 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1960 if ( bgStyle
== wxBG_STYLE_ERASE
)
1962 wxEraseEvent
eevent( GetId(), &dc
);
1963 eevent
.SetEventObject( this );
1964 if ( ProcessWindowEvent( eevent
) )
1970 dc
.SetBackground(GetBackgroundColour());
1976 case wxBG_STYLE_PAINT
:
1977 case wxBG_STYLE_TRANSPARENT
:
1978 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1979 // entire window client area
1983 wxFAIL_MSG( "unsupported background style" );
1986 // as this is a full window, shouldn't be necessary anymore
1987 // MacPaintGrowBox();
1989 // calculate a client-origin version of the update rgn and set
1990 // m_updateRegion to that
1991 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1992 m_updateRegion
= clientUpdateRgn
;
1994 if ( !m_updateRegion
.Empty() )
1996 // paint the window itself
1998 wxPaintEvent
event(GetId());
1999 event
.SetTimestamp(time
);
2000 event
.SetEventObject(this);
2001 handled
= HandleWindowEvent(event
);
2004 m_updateRegion
= formerUpdateRgn
;
2008 void wxWindowMac::MacPaintChildrenBorders()
2010 // now we cannot rely on having its borders drawn by a window itself, as it does not
2011 // get the updateRgn wide enough to always do so, so we do it from the parent
2012 // this would also be the place to draw any custom backgrounds for native controls
2013 // in Composited windowing
2014 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2018 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2020 child
= node
->GetData();
2024 if (child
== m_vScrollBar
)
2026 if (child
== m_hScrollBar
)
2028 if (child
== m_growBox
)
2031 if (child
->IsTopLevel())
2033 if (!child
->IsShown())
2036 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2038 child
->GetPosition( &x
, &y
);
2039 child
->GetSize( &w
, &h
);
2041 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2043 // paint custom borders
2044 wxNcPaintEvent
eventNc( child
->GetId() );
2045 eventNc
.SetEventObject( child
);
2046 if ( !child
->HandleWindowEvent( eventNc
) )
2048 child
->MacPaintBorders(0, 0) ;
2055 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2057 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2058 return tlw
? tlw
->GetWXWindow() : NULL
;
2061 bool wxWindowMac::MacHasScrollBarCorner() const
2064 /* Returns whether the scroll bars in a wxScrolledWindow should be
2065 * shortened. Scroll bars should be shortened if either:
2067 * - both scroll bars are visible, or
2069 * - there is a resize box in the parent frame's corner and this
2070 * window shares the bottom and right edge with the parent
2074 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2077 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2078 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2080 // Both scroll bars visible
2085 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2087 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2089 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2092 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2094 // Parent frame has resize handle
2095 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2097 // Note: allow for some wiggle room here as wxMac's
2098 // window rect calculations seem to be imprecise
2099 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2100 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2102 // Parent frame has resize handle and shares
2103 // right bottom corner
2108 // Parent frame has resize handle but doesn't
2109 // share right bottom corner
2115 // Parent frame doesn't have resize handle
2121 // No parent frame found
2129 void wxWindowMac::MacCreateScrollBars( long style
)
2132 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2134 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2136 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2137 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2139 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2142 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2144 GetClientSize( &width
, &height
) ;
2146 wxPoint
vPoint(width
- scrlsize
, 0) ;
2147 wxSize
vSize(scrlsize
, height
- adjust
) ;
2148 wxPoint
hPoint(0, height
- scrlsize
) ;
2149 wxSize
hSize(width
- adjust
, scrlsize
) ;
2151 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2152 if ( style
& wxVSCROLL
)
2154 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2155 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2158 if ( style
& wxHSCROLL
)
2160 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2161 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2164 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2165 wxSize
gSize(scrlsize
, scrlsize
);
2166 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2169 // because the create does not take into account the client area origin
2170 // we might have a real position shift
2171 MacRepositionScrollBars() ;
2175 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2177 bool result
= ((child
== NULL
)
2179 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2186 void wxWindowMac::MacRepositionScrollBars()
2189 if ( !m_hScrollBar
&& !m_vScrollBar
)
2192 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2193 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2195 // get real client area
2197 GetSize( &width
, &height
);
2199 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2200 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2202 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2203 wxSize
vSize( scrlsize
, height
- adjust
) ;
2204 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2205 wxSize
hSize( width
- adjust
, scrlsize
) ;
2208 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2210 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2213 if ( MacHasScrollBarCorner() )
2215 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2216 if ( !m_growBox
->IsShown() )
2221 if ( m_growBox
->IsShown() )
2228 bool wxWindowMac::AcceptsFocus() const
2230 if ( MacIsUserPane() )
2231 return wxWindowBase::AcceptsFocus();
2233 return m_peer
->CanFocus();
2236 void wxWindowMac::MacSuperChangedPosition()
2238 // only window-absolute structures have to be moved i.e. controls
2240 m_cachedClippedRectValid
= false ;
2243 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2246 child
= node
->GetData();
2247 child
->MacSuperChangedPosition() ;
2249 node
= node
->GetNext();
2253 void wxWindowMac::MacTopLevelWindowChangedPosition()
2255 // only screen-absolute structures have to be moved i.e. glcanvas
2258 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2261 child
= node
->GetData();
2262 child
->MacTopLevelWindowChangedPosition() ;
2264 node
= node
->GetNext();
2268 long wxWindowMac::MacGetWXBorderSize() const
2275 if ( m_peer
&& m_peer
->NeedsFrame() )
2277 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2279 #if wxOSX_USE_COCOA_OR_CARBON
2280 // this metric is only the 'outset' outside the simple frame rect
2281 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2287 else if (HasFlag(wxSIMPLE_BORDER
))
2289 #if wxOSX_USE_COCOA_OR_CARBON
2290 // this metric is only the 'outset' outside the simple frame rect
2291 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2302 long wxWindowMac::MacGetLeftBorderSize() const
2304 // the wx borders are all symmetric in mac themes
2305 long border
= MacGetWXBorderSize() ;
2309 int left
, top
, right
, bottom
;
2310 m_peer
->GetLayoutInset( left
, top
, right
, bottom
);
2318 long wxWindowMac::MacGetRightBorderSize() const
2320 // the wx borders are all symmetric in mac themes
2321 long border
= MacGetWXBorderSize() ;
2325 int left
, top
, right
, bottom
;
2326 m_peer
->GetLayoutInset( left
, top
, right
, bottom
);
2333 long wxWindowMac::MacGetTopBorderSize() const
2335 // the wx borders are all symmetric in mac themes
2336 long border
= MacGetWXBorderSize() ;
2340 int left
, top
, right
, bottom
;
2341 m_peer
->GetLayoutInset( left
, top
, right
, bottom
);
2348 long wxWindowMac::MacGetBottomBorderSize() const
2350 // the wx borders are all symmetric in mac themes
2351 long border
= MacGetWXBorderSize() ;
2355 int left
, top
, right
, bottom
;
2356 m_peer
->GetLayoutInset( left
, top
, right
, bottom
);
2363 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2365 return style
& ~wxBORDER_MASK
;
2368 // Find the wxWindowMac at the current mouse position, returning the mouse
2370 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2372 pt
= wxGetMousePosition();
2373 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2375 return (wxWindow
*) found
;
2378 // Get the current mouse position.
2379 wxPoint
wxGetMousePosition()
2383 wxGetMousePosition( &x
, &y
);
2385 return wxPoint(x
, y
);
2388 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2390 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2392 // copied from wxGTK : CS
2393 // VZ: shouldn't we move this to base class then?
2395 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2398 // (a) it's a command event and so is propagated to the parent
2399 // (b) under MSW it can be generated from kbd too
2400 // (c) it uses screen coords (because of (a))
2401 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2403 this->ClientToScreen(event
.GetPosition()));
2404 evtCtx
.SetEventObject(this);
2405 if ( ! HandleWindowEvent(evtCtx
) )
2414 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2418 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2422 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2423 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2428 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2433 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2435 #if wxOSX_USE_COCOA_OR_CARBON
2436 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2439 return eventNotHandledErr
;
2445 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2447 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2448 if ( !wxWindowBase::Reparent(newParent
) )
2451 m_peer
->RemoveFromParent();
2452 m_peer
->Embed( GetParent()->GetPeer() );
2458 bool wxWindowMac::SetTransparent(wxByte alpha
)
2460 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2462 if ( alpha
!= m_macAlpha
)
2464 m_macAlpha
= alpha
;
2471 bool wxWindowMac::CanSetTransparent()
2476 wxByte
wxWindowMac::GetTransparent() const
2481 bool wxWindowMac::IsShownOnScreen() const
2483 if ( m_peer
&& m_peer
->IsOk() )
2485 bool peerVis
= m_peer
->IsVisible();
2486 bool wxVis
= wxWindowBase::IsShownOnScreen();
2487 if( peerVis
!= wxVis
)
2489 // CS : put a breakpoint here to investigate differences
2490 // between native an wx visibilities
2491 // the only place where I've encountered them until now
2492 // are the hiding/showing sequences where the vis-changed event is
2493 // first sent to the innermost control, while wx does things
2494 // from the outmost control
2495 wxVis
= wxWindowBase::IsShownOnScreen();
2499 return m_peer
->IsVisible();
2501 return wxWindowBase::IsShownOnScreen();
2504 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2506 bool handled
= false;
2508 // moved the ordinary key event sending AFTER the accel evaluation
2511 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2513 wxWindow
*ancestor
= this;
2516 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2519 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2521 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2522 handled
= handler
->ProcessEvent( command_event
);
2526 // accelerators can also be used with buttons, try them too
2527 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2528 handled
= handler
->ProcessEvent( command_event
);
2534 if (ancestor
->IsTopLevel())
2537 ancestor
= ancestor
->GetParent();
2540 #endif // wxUSE_ACCEL
2544 handled
= HandleWindowEvent( event
) ;
2545 if ( handled
&& event
.GetSkipped() )
2556 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2558 static MacControlMap wxWinMacControlList
;
2560 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2562 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2564 return impl
->GetWXPeer();
2569 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2571 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2573 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2576 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2578 // adding NULL ControlRef is (first) surely a result of an error and
2579 // (secondly) breaks native event processing
2580 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2582 wxWinMacControlList
[inControl
] = impl
;
2585 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2587 // iterate over all the elements in the class
2588 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2589 // we should go on...
2595 MacControlMap::iterator it
;
2596 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2598 if ( it
->second
== impl
)
2600 wxWinMacControlList
.erase(it
);
2608 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2610 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
, bool isUserPane
)
2613 m_isRootControl
= isRootControl
;
2614 m_isUserPane
= isUserPane
;
2616 m_shouldSendEvents
= true;
2619 wxWidgetImpl::wxWidgetImpl()
2624 wxWidgetImpl::~wxWidgetImpl()
2628 void wxWidgetImpl::Init()
2630 m_isRootControl
= false;
2632 m_needsFocusRect
= false;
2633 m_needsFrame
= true;
2636 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2638 m_needsFocusRect
= needs
;
2641 bool wxWidgetImpl::NeedsFocusRect() const
2643 return m_needsFocusRect
;
2646 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2648 m_needsFrame
= needs
;
2651 bool wxWidgetImpl::NeedsFrame() const
2653 return m_needsFrame
;