1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
57 #include "wx/popupwin.h"
60 #if wxUSE_DRAG_AND_DROP
64 #include "wx/graphics.h"
67 #include "wx/osx/uma.h"
69 #include "wx/osx/private.h"
72 #define MAC_SCROLLBAR_SIZE 15
73 #define MAC_SMALL_SCROLLBAR_SIZE 11
77 #ifdef __WXUNIVERSAL__
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
80 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
83 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
92 // ===========================================================================
94 // ===========================================================================
96 // the grow box has to be implemented as an inactive window, so that nothing can direct
99 class WXDLLIMPEXP_CORE wxBlindPlateWindow
: public wxWindow
102 wxBlindPlateWindow() { Init(); }
104 // Old-style constructor (no default values for coordinates to avoid
105 // ambiguity with the new one)
106 wxBlindPlateWindow(wxWindow
*parent
,
107 int x
, int y
, int width
, int height
,
108 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
109 const wxString
& name
= wxPanelNameStr
)
113 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), style
, name
);
117 wxBlindPlateWindow(wxWindow
*parent
,
118 wxWindowID winid
= wxID_ANY
,
119 const wxPoint
& pos
= wxDefaultPosition
,
120 const wxSize
& size
= wxDefaultSize
,
121 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
122 const wxString
& name
= wxPanelNameStr
)
126 Create(parent
, winid
, pos
, size
, style
, name
);
130 bool Create(wxWindow
*parent
,
131 wxWindowID winid
= wxID_ANY
,
132 const wxPoint
& pos
= wxDefaultPosition
,
133 const wxSize
& size
= wxDefaultSize
,
134 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
135 const wxString
& name
= wxPanelNameStr
)
137 if ( !wxWindow::Create(parent
, winid
, pos
, size
, style
, name
) )
140 // so that non-solid background renders correctly under GTK+:
141 SetThemeEnabled(true);
144 virtual ~wxBlindPlateWindow();
146 virtual bool AcceptsFocus() const
152 // common part of all ctors
157 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow
)
158 DECLARE_EVENT_TABLE()
161 wxBlindPlateWindow::~wxBlindPlateWindow()
165 IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow
, wxWindow
)
167 BEGIN_EVENT_TABLE(wxBlindPlateWindow
, wxWindow
)
171 // ----------------------------------------------------------------------------
172 // constructors and such
173 // ----------------------------------------------------------------------------
175 wxWindowMac::wxWindowMac()
180 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
185 const wxString
& name
)
188 Create(parent
, id
, pos
, size
, style
, name
);
191 void wxWindowMac::Init()
195 m_cgContextRef
= NULL
;
197 // as all windows are created with WS_VISIBLE style...
200 m_hScrollBar
= NULL
;
201 m_vScrollBar
= NULL
;
202 m_hScrollBarAlwaysShown
= false;
203 m_vScrollBarAlwaysShown
= false;
206 m_macIsUserPane
= true;
207 m_clipChildren
= false ;
208 m_cachedClippedRectValid
= false ;
209 m_isNativeWindowWrapper
= false;
212 wxWindowMac::~wxWindowMac()
216 MacInvalidateBorders() ;
218 #ifndef __WXUNIVERSAL__
219 // VS: make sure there's no wxFrame with last focus set to us:
220 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
222 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
225 if ( frame
->GetLastFocus() == this )
226 frame
->SetLastFocus(NULL
);
232 // destroy children before destroying this window itself
235 // wxRemoveMacControlAssociation( this ) ;
236 // If we delete an item, we should initialize the parent panel,
237 // because it could now be invalid.
238 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
241 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
242 tlw
->SetDefaultItem(NULL
);
245 if ( g_MacLastWindow
== this )
246 g_MacLastWindow
= NULL
;
248 #ifndef __WXUNIVERSAL__
249 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
252 if ( frame
->GetLastFocus() == this )
253 frame
->SetLastFocus( NULL
) ;
257 // delete our drop target if we've got one
258 #if wxUSE_DRAG_AND_DROP
259 if ( m_dropTarget
!= NULL
)
269 WXWidget
wxWindowMac::GetHandle() const
272 return (WXWidget
) m_peer
->GetWXWidget() ;
276 // ---------------------------------------------------------------------------
277 // Utility Routines to move between different coordinate systems
278 // ---------------------------------------------------------------------------
281 * Right now we have the following setup :
282 * a border that is not part of the native control is always outside the
283 * control's border (otherwise we loose all native intelligence, future ways
284 * may be to have a second embedding control responsible for drawing borders
285 * and backgrounds eventually)
286 * so all this border calculations have to be taken into account when calling
287 * native methods or getting native oriented data
288 * so we have three coordinate systems here
289 * wx client coordinates
290 * wx window coordinates (including window frames)
298 bool wxWindowMac::Create(wxWindowMac
*parent
,
303 const wxString
& name
)
305 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
307 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
310 m_windowVariant
= parent
->GetWindowVariant() ;
312 if ( m_macIsUserPane
)
314 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
315 MacPostControlCreate(pos
, size
) ;
318 #ifndef __WXUNIVERSAL__
319 // Don't give scrollbars to wxControls unless they ask for them
320 if ( (! IsKindOf(CLASSINFO(wxControl
))
322 && ! IsKindOf(CLASSINFO(wxStatusBar
))
325 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
327 MacCreateScrollBars( style
) ;
331 wxWindowCreateEvent
event((wxWindow
*)this);
332 GetEventHandler()->AddPendingEvent(event
);
337 void wxWindowMac::MacChildAdded()
341 m_vScrollBar
->Raise() ;
343 m_hScrollBar
->Raise() ;
349 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
351 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
353 GetParent()->AddChild( this );
355 m_peer
->InstallEventHandler();
356 m_peer
->Embed(GetParent()->GetPeer());
358 GetParent()->MacChildAdded() ;
360 // adjust font, controlsize etc
361 DoSetWindowVariant( m_windowVariant
) ;
363 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
365 // for controls we want to use best size for wxDefaultSize params )
366 if ( !m_macIsUserPane
)
367 SetInitialSize(size
);
369 SetCursor( *wxSTANDARD_CURSOR
) ;
372 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
374 // Don't assert, in case we set the window variant before
375 // the window is created
376 // wxASSERT( m_peer->Ok() ) ;
378 m_windowVariant
= variant
;
380 if (m_peer
== NULL
|| !m_peer
->IsOk())
383 m_peer
->SetControlSize( variant
);
387 // we will get that from the settings later
388 // and make this NORMAL later, but first
389 // we have a few calculations that we must fix
393 case wxWINDOW_VARIANT_NORMAL
:
394 size
= kControlSizeNormal
;
397 case wxWINDOW_VARIANT_SMALL
:
398 size
= kControlSizeSmall
;
401 case wxWINDOW_VARIANT_MINI
:
402 // not always defined in the headers
406 case wxWINDOW_VARIANT_LARGE
:
407 size
= kControlSizeLarge
;
411 wxFAIL_MSG(wxT("unexpected window variant"));
414 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
420 case wxWINDOW_VARIANT_NORMAL
:
421 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
425 case wxWINDOW_VARIANT_SMALL
:
426 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
430 case wxWINDOW_VARIANT_MINI
:
431 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
435 case wxWINDOW_VARIANT_LARGE
:
436 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
441 wxFAIL_MSG(wxT("unexpected window variant"));
446 void wxWindowMac::MacUpdateControlFont()
449 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
451 // do not trigger refreshes upon invisible and possible partly created objects
452 if ( IsShownOnScreen() )
456 bool wxWindowMac::SetFont(const wxFont
& font
)
458 bool retval
= wxWindowBase::SetFont( font
);
460 MacUpdateControlFont() ;
465 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
467 bool retval
= wxWindowBase::SetForegroundColour( col
);
470 MacUpdateControlFont();
475 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
479 if ( m_backgroundColour
.Ok() )
480 m_growBox
->SetBackgroundColour(m_backgroundColour
);
482 m_growBox
->SetBackgroundColour(*wxWHITE
);
485 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
489 m_peer
->SetBackgroundColour( col
) ;
494 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
496 while (w
&& !w
->IsTopLevel())
505 void wxWindowMac::SetFocus()
507 if ( !AcceptsFocus() )
510 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
513 wxWindow
* former
= FindFocus() ;
514 if ( former
== this )
520 void wxWindowMac::DoCaptureMouse()
522 wxApp::s_captureWindow
= (wxWindow
*) this ;
523 m_peer
->CaptureMouse() ;
526 wxWindow
* wxWindowBase::GetCapture()
528 return wxApp::s_captureWindow
;
531 void wxWindowMac::DoReleaseMouse()
533 wxApp::s_captureWindow
= NULL
;
535 m_peer
->ReleaseMouse() ;
538 #if wxUSE_DRAG_AND_DROP
540 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
544 m_dropTarget
= pDropTarget
;
545 if ( m_dropTarget
!= NULL
)
553 // Old-style File Manager Drag & Drop
554 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
559 // From a wx position / size calculate the appropriate size of the native control
561 bool wxWindowMac::MacGetBoundsForControl(
565 int& w
, int& h
, bool adjustOrigin
) const
567 // the desired size, minus the border pixels gives the correct size of the control
571 w
= WidthDefault( size
.x
);
572 h
= HeightDefault( size
.y
);
574 x
+= MacGetLeftBorderSize() ;
575 y
+= MacGetTopBorderSize() ;
576 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
577 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
580 AdjustForParentClientOrigin( x
, y
) ;
582 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
583 if ( GetParent() && !GetParent()->IsTopLevel() )
585 x
-= GetParent()->MacGetLeftBorderSize() ;
586 y
-= GetParent()->MacGetTopBorderSize() ;
592 // Get window size (not client size)
593 void wxWindowMac::DoGetSize(int *x
, int *y
) const
596 m_peer
->GetSize( width
, height
);
599 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
601 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
604 // get the position of the bounds of this window in client coordinates of its parent
605 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
609 m_peer
->GetPosition( x1
, y1
) ;
611 // get the wx window position from the native one
612 x1
-= MacGetLeftBorderSize() ;
613 y1
-= MacGetTopBorderSize() ;
617 wxWindow
*parent
= GetParent();
620 // we must first adjust it to be in window coordinates of the parent,
621 // as otherwise it gets lost by the ClientAreaOrigin fix
622 x1
+= parent
->MacGetLeftBorderSize() ;
623 y1
+= parent
->MacGetTopBorderSize() ;
625 // and now to client coordinates
626 wxPoint
pt(parent
->GetClientAreaOrigin());
638 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
640 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
641 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
642 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
643 MacRootWindowToWindow( x
, y
) ;
645 wxPoint origin
= GetClientAreaOrigin() ;
652 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
654 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
655 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
657 wxPoint origin
= GetClientAreaOrigin() ;
663 MacWindowToRootWindow( x
, y
) ;
664 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
667 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
669 wxPoint origin
= GetClientAreaOrigin() ;
675 MacWindowToRootWindow( x
, y
) ;
678 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
689 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
692 pt
.x
-= MacGetLeftBorderSize() ;
693 pt
.y
-= MacGetTopBorderSize() ;
694 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
704 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
715 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
718 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
719 pt
.x
+= MacGetLeftBorderSize() ;
720 pt
.y
+= MacGetTopBorderSize() ;
730 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
732 wxSize sizeTotal
= size
;
734 int innerwidth
, innerheight
;
736 int outerwidth
, outerheight
;
738 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
739 m_peer
->GetSize( outerwidth
, outerheight
);
741 sizeTotal
.x
+= outerwidth
-innerwidth
;
742 sizeTotal
.y
+= outerheight
-innerheight
;
744 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
745 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
750 // Get size *available for subwindows* i.e. excluding menu bar etc.
751 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
757 m_peer
->GetContentArea( left
, top
, ww
, hh
);
759 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
760 hh
-= m_hScrollBar
->GetSize().y
;
762 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
763 ww
-= m_vScrollBar
->GetSize().x
;
772 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
774 if (m_cursor
.IsSameAs(cursor
))
779 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
784 if ( ! wxWindowBase::SetCursor( cursor
) )
788 wxASSERT_MSG( m_cursor
.Ok(),
789 wxT("cursor must be valid after call to the base version"));
791 if ( GetPeer() != NULL
)
792 GetPeer()->SetCursor( m_cursor
);
798 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
800 #ifndef __WXUNIVERSAL__
801 menu
->SetInvokingWindow((wxWindow
*)this);
804 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
806 wxPoint mouse
= wxGetMousePosition();
812 ClientToScreen( &x
, &y
) ;
814 menu
->GetPeer()->PopUp(this, x
, y
);
815 menu
->SetInvokingWindow( NULL
);
818 // actually this shouldn't be called, because universal is having its own implementation
824 // ----------------------------------------------------------------------------
826 // ----------------------------------------------------------------------------
830 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
832 wxWindowBase::DoSetToolTip(tooltip
);
835 m_tooltip
->SetWindow(this);
838 m_peer
->SetToolTip(tooltip
);
843 void wxWindowMac::MacInvalidateBorders()
845 if ( m_peer
== NULL
)
848 bool vis
= IsShownOnScreen() ;
852 int outerBorder
= MacGetLeftBorderSize() ;
854 if ( m_peer
->NeedsFocusRect() )
857 if ( outerBorder
== 0 )
860 // now we know that we have something to do at all
864 m_peer
->GetSize( tw
, th
);
865 m_peer
->GetPosition( tx
, ty
);
867 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
868 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
869 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
870 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
873 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
874 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
875 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
876 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
880 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
882 // this is never called for a toplevel window, so we know we have a parent
883 int former_x
, former_y
, former_w
, former_h
;
885 // Get true coordinates of former position
886 DoGetPosition( &former_x
, &former_y
) ;
887 DoGetSize( &former_w
, &former_h
) ;
889 wxWindow
*parent
= GetParent();
892 wxPoint
pt(parent
->GetClientAreaOrigin());
897 int actualWidth
= width
;
898 int actualHeight
= height
;
903 // min and max sizes are only for sizers, not for explicit size setting
904 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
905 actualWidth
= m_minWidth
;
906 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
907 actualHeight
= m_minHeight
;
908 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
909 actualWidth
= m_maxWidth
;
910 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
911 actualHeight
= m_maxHeight
;
914 bool doMove
= false, doResize
= false ;
916 if ( actualX
!= former_x
|| actualY
!= former_y
)
919 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
922 if ( doMove
|| doResize
)
924 // as the borders are drawn outside the native control, we adjust now
926 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
927 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
928 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
930 if ( parent
&& !parent
->IsTopLevel() )
932 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
935 MacInvalidateBorders() ;
937 m_cachedClippedRectValid
= false ;
939 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
941 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
943 MacInvalidateBorders() ;
945 MacRepositionScrollBars() ;
948 wxPoint
point(actualX
, actualY
);
949 wxMoveEvent
event(point
, m_windowId
);
950 event
.SetEventObject(this);
951 HandleWindowEvent(event
) ;
956 MacRepositionScrollBars() ;
957 wxSize
size(actualWidth
, actualHeight
);
958 wxSizeEvent
event(size
, m_windowId
);
959 event
.SetEventObject(this);
960 HandleWindowEvent(event
);
965 wxSize
wxWindowMac::DoGetBestSize() const
967 if ( m_macIsUserPane
|| IsTopLevel() )
969 return wxWindowBase::DoGetBestSize() ;
975 m_peer
->GetBestRect(&r
);
977 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
985 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
992 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
999 // return wxWindowBase::DoGetBestSize() ;
1003 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1004 MacGetRightBorderSize();
1005 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1006 MacGetBottomBorderSize();
1007 if ( bestHeight
< 10 )
1010 return wxSize(bestWidth
, bestHeight
);
1014 // set the size of the window: if the dimensions are positive, just use them,
1015 // but if any of them is equal to -1, it means that we must find the value for
1016 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1017 // which case -1 is a valid value for x and y)
1019 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1020 // the width/height to best suit our contents, otherwise we reuse the current
1022 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1024 // get the current size and position...
1025 int currentX
, currentY
;
1026 int currentW
, currentH
;
1028 GetPosition(¤tX
, ¤tY
);
1029 GetSize(¤tW
, ¤tH
);
1031 // ... and don't do anything (avoiding flicker) if it's already ok
1032 if ( x
== currentX
&& y
== currentY
&&
1033 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1036 MacRepositionScrollBars() ; // we might have a real position shift
1038 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1040 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1041 event
.SetEventObject( this );
1042 HandleWindowEvent( event
);
1048 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1050 if ( x
== wxDefaultCoord
)
1052 if ( y
== wxDefaultCoord
)
1056 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1058 wxSize size
= wxDefaultSize
;
1059 if ( width
== wxDefaultCoord
)
1061 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1063 size
= DoGetBestSize();
1068 // just take the current one
1073 if ( height
== wxDefaultCoord
)
1075 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1077 if ( size
.x
== wxDefaultCoord
)
1078 size
= DoGetBestSize();
1079 // else: already called DoGetBestSize() above
1085 // just take the current one
1090 DoMoveWindow( x
, y
, width
, height
);
1093 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1095 int left
,top
,width
,height
;
1096 m_peer
->GetContentArea( left
, top
, width
, height
);
1097 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1100 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1102 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1104 int currentclientwidth
, currentclientheight
;
1105 int currentwidth
, currentheight
;
1107 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1108 GetSize( ¤twidth
, ¤theight
) ;
1110 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1111 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1115 void wxWindowMac::SetLabel(const wxString
& title
)
1117 if ( title
== m_label
)
1122 InvalidateBestSize();
1124 if ( m_peer
&& m_peer
->IsOk() )
1125 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1127 // do not trigger refreshes upon invisible and possible partly created objects
1128 if ( IsShownOnScreen() )
1132 wxString
wxWindowMac::GetLabel() const
1137 bool wxWindowMac::Show(bool show
)
1139 if ( !wxWindowBase::Show(show
) )
1143 m_peer
->SetVisibility( show
) ;
1145 #ifdef __WXOSX_IPHONE__
1146 // only when there's no native event support
1147 if ( !IsTopLevel() )
1150 wxShowEvent
eventShow(GetId(), show
);
1151 eventShow
.SetEventObject(this);
1153 HandleWindowEvent(eventShow
);
1159 bool wxWindowMac::OSXShowWithEffect(bool show
,
1160 wxShowEffect effect
,
1163 if ( effect
== wxSHOW_EFFECT_NONE
||
1164 !m_peer
|| !m_peer
->ShowWithEffect(show
, effect
, timeout
) )
1170 void wxWindowMac::DoEnable(bool enable
)
1172 m_peer
->Enable( enable
) ;
1173 MacInvalidateBorders();
1177 // status change notifications
1180 void wxWindowMac::MacVisibilityChanged()
1184 void wxWindowMac::MacHiliteChanged()
1188 void wxWindowMac::MacEnabledStateChanged()
1190 OnEnabled( m_peer
->IsEnabled() );
1194 // status queries on the inherited window's state
1197 bool wxWindowMac::MacIsReallyEnabled()
1199 return m_peer
->IsEnabled() ;
1202 bool wxWindowMac::MacIsReallyHilited()
1204 #if wxOSX_USE_CARBON
1205 return m_peer
->IsActive();
1207 return true; // TODO
1211 int wxWindowMac::GetCharHeight() const
1214 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1219 int wxWindowMac::GetCharWidth() const
1222 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1227 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1230 int *externalLeading
,
1231 const wxFont
*theFont
) const
1233 const wxFont
*fontToUse
= theFont
;
1237 tempFont
= GetFont();
1238 fontToUse
= &tempFont
;
1241 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1242 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1244 wxDouble h
, d
, e
, w
;
1245 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1249 if ( externalLeading
)
1250 *externalLeading
= (wxCoord
)(e
+0.5);
1252 *descent
= (wxCoord
)(d
+0.5);
1254 *x
= (wxCoord
)(w
+0.5);
1256 *y
= (wxCoord
)(h
+0.5);
1260 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1261 * we always intersect with the entire window, not only with the client area
1264 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1266 if ( m_peer
== NULL
)
1269 if ( !IsShownOnScreen() )
1272 m_peer
->SetNeedsDisplay( rect
) ;
1275 void wxWindowMac::DoFreeze()
1277 #if wxOSX_USE_CARBON
1278 if ( m_peer
&& m_peer
->IsOk() )
1279 m_peer
->SetDrawingEnabled( false ) ;
1283 void wxWindowMac::DoThaw()
1285 #if wxOSX_USE_CARBON
1286 if ( m_peer
&& m_peer
->IsOk() )
1288 m_peer
->SetDrawingEnabled( true ) ;
1289 m_peer
->InvalidateWithChildren() ;
1294 wxWindow
*wxGetActiveWindow()
1296 // actually this is a windows-only concept
1300 // Coordinates relative to the window
1301 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1303 #if wxOSX_USE_COCOA_OR_CARBON
1306 DoClientToScreen(&x
, &y
);
1307 CGPoint cgpoint
= CGPointMake( x
, y
);
1308 CGWarpMouseCursorPosition( cgpoint
);
1310 // At least GTK sends a mouse moved event after WarpMouse
1311 wxMouseEvent
event(wxEVT_MOTION
);
1314 wxMouseState mState
= ::wxGetMouseState();
1316 event
.m_altDown
= mState
.AltDown();
1317 event
.m_controlDown
= mState
.ControlDown();
1318 event
.m_leftDown
= mState
.LeftIsDown();
1319 event
.m_middleDown
= mState
.MiddleIsDown();
1320 event
.m_rightDown
= mState
.RightIsDown();
1321 event
.m_metaDown
= mState
.MetaDown();
1322 event
.m_shiftDown
= mState
.ShiftDown();
1323 event
.SetId(GetId());
1324 event
.SetEventObject(this);
1325 GetEventHandler()->ProcessEvent(event
);
1329 int wxWindowMac::GetScrollPos(int orient
) const
1332 if ( orient
== wxHORIZONTAL
)
1335 return m_hScrollBar
->GetThumbPosition() ;
1340 return m_vScrollBar
->GetThumbPosition() ;
1346 // This now returns the whole range, not just the number
1347 // of positions that we can scroll.
1348 int wxWindowMac::GetScrollRange(int orient
) const
1351 if ( orient
== wxHORIZONTAL
)
1354 return m_hScrollBar
->GetRange() ;
1359 return m_vScrollBar
->GetRange() ;
1365 int wxWindowMac::GetScrollThumb(int orient
) const
1368 if ( orient
== wxHORIZONTAL
)
1371 return m_hScrollBar
->GetThumbSize() ;
1376 return m_vScrollBar
->GetThumbSize() ;
1382 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1385 if ( orient
== wxHORIZONTAL
)
1388 m_hScrollBar
->SetThumbPosition( pos
) ;
1393 m_vScrollBar
->SetThumbPosition( pos
) ;
1399 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1401 bool needVisibilityUpdate
= false;
1403 if ( m_hScrollBarAlwaysShown
!= hflag
)
1405 m_hScrollBarAlwaysShown
= hflag
;
1406 needVisibilityUpdate
= true;
1409 if ( m_vScrollBarAlwaysShown
!= vflag
)
1411 m_vScrollBarAlwaysShown
= vflag
;
1412 needVisibilityUpdate
= true;
1415 if ( needVisibilityUpdate
)
1416 DoUpdateScrollbarVisibility();
1420 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1421 // our own window origin is at leftOrigin/rightOrigin
1424 void wxWindowMac::MacPaintGrowBox()
1430 if ( MacHasScrollBarCorner() )
1433 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1434 wxASSERT( cgContext
) ;
1438 m_peer
->GetSize( tw
, th
);
1439 m_peer
->GetPosition( tx
, ty
);
1441 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1444 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1445 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1446 CGContextSaveGState( cgContext
);
1448 if ( m_backgroundColour
.Ok() )
1450 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1454 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1456 CGContextFillRect( cgContext
, cgrect
);
1457 CGContextRestoreGState( cgContext
);
1461 if ( m_backgroundColour
.Ok() )
1462 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1464 m_growBox
->SetBackgroundColour(*wxWHITE
);
1472 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1477 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1479 // back to the surrounding frame rectangle
1482 m_peer
->GetSize( tw
, th
);
1483 m_peer
->GetPosition( tx
, ty
);
1485 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1487 #if wxOSX_USE_COCOA_OR_CARBON
1489 InsetRect( &rect
, -1 , -1 ) ;
1492 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1493 rect
.bottom
- rect
.top
) ;
1495 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1496 wxASSERT( cgContext
) ;
1498 if ( m_peer
->NeedsFrame() )
1500 HIThemeFrameDrawInfo info
;
1501 memset( &info
, 0 , sizeof(info
) ) ;
1505 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1506 info
.isFocused
= hasFocus
;
1508 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1510 info
.kind
= kHIThemeFrameTextFieldSquare
;
1511 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1513 else if ( HasFlag(wxSIMPLE_BORDER
) )
1515 info
.kind
= kHIThemeFrameListBox
;
1516 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1522 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1525 #endif // wxOSX_USE_COCOA_OR_CARBON
1528 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1531 if ( child
== m_hScrollBar
)
1532 m_hScrollBar
= NULL
;
1533 if ( child
== m_vScrollBar
)
1534 m_vScrollBar
= NULL
;
1535 if ( child
== m_growBox
)
1538 wxWindowBase::RemoveChild( child
) ;
1541 void wxWindowMac::DoUpdateScrollbarVisibility()
1544 bool triggerSizeEvent
= false;
1548 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1550 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1552 m_hScrollBar
->Show( showHScrollBar
);
1553 triggerSizeEvent
= true;
1559 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1561 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1563 m_vScrollBar
->Show( showVScrollBar
) ;
1564 triggerSizeEvent
= true;
1568 MacRepositionScrollBars() ;
1569 if ( triggerSizeEvent
)
1571 wxSizeEvent
event(GetSize(), m_windowId
);
1572 event
.SetEventObject(this);
1573 HandleWindowEvent(event
);
1578 // New function that will replace some of the above.
1579 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1580 int range
, bool refresh
)
1583 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1584 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1585 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1586 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1588 DoUpdateScrollbarVisibility();
1592 // Does a physical scroll
1593 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1595 if ( dx
== 0 && dy
== 0 )
1598 int width
, height
;
1599 GetClientSize( &width
, &height
) ;
1602 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1604 scrollrect
.Intersect( *rect
) ;
1605 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1606 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1608 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1613 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1615 child
= node
->GetData();
1619 if (child
->IsTopLevel())
1622 if ( !IsClientAreaChild(child
) )
1625 child
->GetPosition( &x
, &y
);
1626 child
->GetSize( &w
, &h
);
1629 wxRect
rc( x
, y
, w
, h
);
1630 if (rect
->Intersects( rc
))
1631 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1635 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1640 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1643 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1645 wxScrollWinEvent wevent
;
1646 wevent
.SetPosition(event
.GetPosition());
1647 wevent
.SetOrientation(event
.GetOrientation());
1648 wevent
.SetEventObject(this);
1650 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1651 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1652 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1653 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1654 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1655 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1656 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1657 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1658 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1659 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1660 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1661 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1662 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1663 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1664 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1665 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1667 HandleWindowEvent(wevent
);
1672 wxWindow
*wxWindowBase::DoFindFocus()
1674 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1677 void wxWindowMac::OnInternalIdle()
1679 // This calls the UI-update mechanism (querying windows for
1680 // menu/toolbar/control state information)
1681 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1682 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1685 // Raise the window to the top of the Z order
1686 void wxWindowMac::Raise()
1691 // Lower the window to the bottom of the Z order
1692 void wxWindowMac::Lower()
1697 // static wxWindow *gs_lastWhich = NULL;
1699 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1701 // first trigger a set cursor event
1703 wxPoint clientorigin
= GetClientAreaOrigin() ;
1704 wxSize clientsize
= GetClientSize() ;
1706 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1708 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1710 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1711 if ( processedEvtSetCursor
&& event
.HasCursor() )
1713 cursor
= event
.GetCursor() ;
1717 // the test for processedEvtSetCursor is here to prevent using m_cursor
1718 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1719 // it - this is a way to say that our cursor shouldn't be used for this
1721 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1724 if ( !wxIsBusy() && !GetParent() )
1725 cursor
= *wxSTANDARD_CURSOR
;
1729 cursor
.MacInstall() ;
1732 return cursor
.Ok() ;
1735 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1739 return m_tooltip
->GetTip() ;
1742 return wxEmptyString
;
1745 void wxWindowMac::ClearBackground()
1751 void wxWindowMac::Update()
1753 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1758 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1760 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1764 if ( iter
->IsTopLevel() )
1766 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1770 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1775 iter
= iter
->GetParent() ;
1781 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1783 MacUpdateClippedRects() ;
1785 return m_cachedClippedClientRect
;
1788 const wxRect
& wxWindowMac::MacGetClippedRect() const
1790 MacUpdateClippedRects() ;
1792 return m_cachedClippedRect
;
1795 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1797 MacUpdateClippedRects() ;
1799 return m_cachedClippedRectWithOuterStructure
;
1802 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1804 static wxRegion emptyrgn
;
1806 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1808 MacUpdateClippedRects() ;
1809 if ( includeOuterStructures
)
1810 return m_cachedClippedRegionWithOuterStructure
;
1812 return m_cachedClippedRegion
;
1820 void wxWindowMac::MacUpdateClippedRects() const
1822 #if wxOSX_USE_CARBON
1823 if ( m_cachedClippedRectValid
)
1826 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1827 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1828 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1829 // to add focus borders everywhere
1831 Rect rIncludingOuterStructures
;
1835 m_peer
->GetSize( tw
, th
);
1836 m_peer
->GetPosition( tx
, ty
);
1838 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1840 r
.left
-= MacGetLeftBorderSize() ;
1841 r
.top
-= MacGetTopBorderSize() ;
1842 r
.bottom
+= MacGetBottomBorderSize() ;
1843 r
.right
+= MacGetRightBorderSize() ;
1850 rIncludingOuterStructures
= r
;
1851 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1853 wxRect cl
= GetClientRect() ;
1854 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1858 const wxWindow
* child
= (wxWindow
*) this ;
1859 const wxWindow
* parent
= NULL
;
1861 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1863 if ( parent
->MacIsChildOfClientArea(child
) )
1865 size
= parent
->GetClientSize() ;
1866 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1872 // this will be true for scrollbars, toolbars etc.
1873 size
= parent
->GetSize() ;
1874 y
= parent
->MacGetTopBorderSize() ;
1875 x
= parent
->MacGetLeftBorderSize() ;
1876 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1877 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1880 parent
->MacWindowToRootWindow( &x
, &y
) ;
1881 MacRootWindowToWindow( &x
, &y
) ;
1883 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1885 // the wxwindow and client rects will always be clipped
1886 SectRect( &r
, &rparent
, &r
) ;
1887 SectRect( &rClient
, &rparent
, &rClient
) ;
1889 // the structure only at 'hard' borders
1890 if ( parent
->MacClipChildren() ||
1891 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1893 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1899 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1900 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1901 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1902 m_cachedClippedRectWithOuterStructure
= wxRect(
1903 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1904 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1905 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1907 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1908 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1909 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1911 m_cachedClippedRectValid
= true ;
1916 This function must not change the updatergn !
1918 bool wxWindowMac::MacDoRedraw( long time
)
1920 bool handled
= false ;
1922 wxRegion formerUpdateRgn
= m_updateRegion
;
1923 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1925 const wxRect clientRect
= GetClientRect();
1927 clientUpdateRgn
.Intersect(clientRect
);
1929 // first send an erase event to the entire update area
1930 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1933 case wxBG_STYLE_ERASE
:
1934 case wxBG_STYLE_SYSTEM
:
1935 case wxBG_STYLE_COLOUR
:
1937 // for the toplevel window this really is the entire area for
1938 // all the others only their client area, otherwise they might
1939 // be drawing with full alpha and eg put blue into the grow-box
1940 // area of a scrolled window (scroll sample)
1941 wxWindowDC
dc(this);
1943 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1945 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1947 if ( bgStyle
== wxBG_STYLE_ERASE
)
1949 wxEraseEvent
eevent( GetId(), &dc
);
1950 eevent
.SetEventObject( this );
1951 if ( ProcessWindowEvent( eevent
) )
1957 dc
.SetBackground(GetBackgroundColour());
1963 case wxBG_STYLE_PAINT
:
1964 case wxBG_STYLE_TRANSPARENT
:
1965 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1966 // entire window client area
1970 wxFAIL_MSG( "unsupported background style" );
1973 // as this is a full window, shouldn't be necessary anymore
1974 // MacPaintGrowBox();
1976 // calculate a client-origin version of the update rgn and set
1977 // m_updateRegion to that
1978 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1979 m_updateRegion
= clientUpdateRgn
;
1981 if ( !m_updateRegion
.Empty() )
1983 // paint the window itself
1985 wxPaintEvent
event(GetId());
1986 event
.SetTimestamp(time
);
1987 event
.SetEventObject(this);
1988 handled
= HandleWindowEvent(event
);
1991 m_updateRegion
= formerUpdateRgn
;
1995 void wxWindowMac::MacPaintChildrenBorders()
1997 // now we cannot rely on having its borders drawn by a window itself, as it does not
1998 // get the updateRgn wide enough to always do so, so we do it from the parent
1999 // this would also be the place to draw any custom backgrounds for native controls
2000 // in Composited windowing
2001 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2005 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2007 child
= node
->GetData();
2011 if (child
== m_vScrollBar
)
2013 if (child
== m_hScrollBar
)
2015 if (child
== m_growBox
)
2018 if (child
->IsTopLevel())
2020 if (!child
->IsShown())
2023 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2025 child
->GetPosition( &x
, &y
);
2026 child
->GetSize( &w
, &h
);
2028 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2030 // paint custom borders
2031 wxNcPaintEvent
eventNc( child
->GetId() );
2032 eventNc
.SetEventObject( child
);
2033 if ( !child
->HandleWindowEvent( eventNc
) )
2035 child
->MacPaintBorders(0, 0) ;
2042 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2044 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2045 return tlw
? tlw
->GetWXWindow() : NULL
;
2048 bool wxWindowMac::MacHasScrollBarCorner() const
2051 /* Returns whether the scroll bars in a wxScrolledWindow should be
2052 * shortened. Scroll bars should be shortened if either:
2054 * - both scroll bars are visible, or
2056 * - there is a resize box in the parent frame's corner and this
2057 * window shares the bottom and right edge with the parent
2061 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2064 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2065 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2067 // Both scroll bars visible
2072 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2074 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2076 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2079 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2081 // Parent frame has resize handle
2082 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2084 // Note: allow for some wiggle room here as wxMac's
2085 // window rect calculations seem to be imprecise
2086 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2087 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2089 // Parent frame has resize handle and shares
2090 // right bottom corner
2095 // Parent frame has resize handle but doesn't
2096 // share right bottom corner
2102 // Parent frame doesn't have resize handle
2108 // No parent frame found
2116 void wxWindowMac::MacCreateScrollBars( long style
)
2119 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2121 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2123 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2124 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2126 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2129 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2131 GetClientSize( &width
, &height
) ;
2133 wxPoint
vPoint(width
- scrlsize
, 0) ;
2134 wxSize
vSize(scrlsize
, height
- adjust
) ;
2135 wxPoint
hPoint(0, height
- scrlsize
) ;
2136 wxSize
hSize(width
- adjust
, scrlsize
) ;
2138 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2139 if ( style
& wxVSCROLL
)
2141 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2142 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2145 if ( style
& wxHSCROLL
)
2147 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2148 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2151 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2152 wxSize
gSize(scrlsize
, scrlsize
);
2153 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2156 // because the create does not take into account the client area origin
2157 // we might have a real position shift
2158 MacRepositionScrollBars() ;
2162 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2164 bool result
= ((child
== NULL
)
2166 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2173 void wxWindowMac::MacRepositionScrollBars()
2176 if ( !m_hScrollBar
&& !m_vScrollBar
)
2179 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2180 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2182 // get real client area
2184 GetSize( &width
, &height
);
2186 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2187 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2189 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2190 wxSize
vSize( scrlsize
, height
- adjust
) ;
2191 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2192 wxSize
hSize( width
- adjust
, scrlsize
) ;
2195 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2197 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2200 if ( MacHasScrollBarCorner() )
2202 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2203 if ( !m_growBox
->IsShown() )
2208 if ( m_growBox
->IsShown() )
2215 bool wxWindowMac::AcceptsFocus() const
2217 if ( MacIsUserPane() )
2218 return wxWindowBase::AcceptsFocus();
2220 return m_peer
->CanFocus();
2223 void wxWindowMac::MacSuperChangedPosition()
2225 // only window-absolute structures have to be moved i.e. controls
2227 m_cachedClippedRectValid
= false ;
2230 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2233 child
= node
->GetData();
2234 child
->MacSuperChangedPosition() ;
2236 node
= node
->GetNext();
2240 void wxWindowMac::MacTopLevelWindowChangedPosition()
2242 // only screen-absolute structures have to be moved i.e. glcanvas
2245 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2248 child
= node
->GetData();
2249 child
->MacTopLevelWindowChangedPosition() ;
2251 node
= node
->GetNext();
2255 long wxWindowMac::MacGetLeftBorderSize() const
2262 if ( m_peer
&& m_peer
->NeedsFrame() )
2264 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2266 #if wxOSX_USE_COCOA_OR_CARBON
2267 // this metric is only the 'outset' outside the simple frame rect
2268 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2274 else if (HasFlag(wxSIMPLE_BORDER
))
2276 #if wxOSX_USE_COCOA_OR_CARBON
2277 // this metric is only the 'outset' outside the simple frame rect
2278 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2289 long wxWindowMac::MacGetRightBorderSize() const
2291 // they are all symmetric in mac themes
2292 return MacGetLeftBorderSize() ;
2295 long wxWindowMac::MacGetTopBorderSize() const
2297 // they are all symmetric in mac themes
2298 return MacGetLeftBorderSize() ;
2301 long wxWindowMac::MacGetBottomBorderSize() const
2303 // they are all symmetric in mac themes
2304 return MacGetLeftBorderSize() ;
2307 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2309 return style
& ~wxBORDER_MASK
;
2312 // Find the wxWindowMac at the current mouse position, returning the mouse
2314 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2316 pt
= wxGetMousePosition();
2317 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2319 return (wxWindow
*) found
;
2322 // Get the current mouse position.
2323 wxPoint
wxGetMousePosition()
2327 wxGetMousePosition( &x
, &y
);
2329 return wxPoint(x
, y
);
2332 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2334 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2336 // copied from wxGTK : CS
2337 // VZ: shouldn't we move this to base class then?
2339 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2342 // (a) it's a command event and so is propagated to the parent
2343 // (b) under MSW it can be generated from kbd too
2344 // (c) it uses screen coords (because of (a))
2345 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2347 this->ClientToScreen(event
.GetPosition()));
2348 evtCtx
.SetEventObject(this);
2349 if ( ! HandleWindowEvent(evtCtx
) )
2358 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2362 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2366 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2367 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2372 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2377 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2379 #if wxOSX_USE_COCOA_OR_CARBON
2380 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2383 return eventNotHandledErr
;
2389 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2391 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2392 if ( !wxWindowBase::Reparent(newParent
) )
2395 m_peer
->RemoveFromParent();
2396 m_peer
->Embed( GetParent()->GetPeer() );
2402 bool wxWindowMac::SetTransparent(wxByte alpha
)
2404 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2406 if ( alpha
!= m_macAlpha
)
2408 m_macAlpha
= alpha
;
2415 bool wxWindowMac::CanSetTransparent()
2420 wxByte
wxWindowMac::GetTransparent() const
2425 bool wxWindowMac::IsShownOnScreen() const
2427 if ( m_peer
&& m_peer
->IsOk() )
2429 bool peerVis
= m_peer
->IsVisible();
2430 bool wxVis
= wxWindowBase::IsShownOnScreen();
2431 if( peerVis
!= wxVis
)
2433 // CS : put a breakpoint here to investigate differences
2434 // between native an wx visibilities
2435 // the only place where I've encountered them until now
2436 // are the hiding/showing sequences where the vis-changed event is
2437 // first sent to the innermost control, while wx does things
2438 // from the outmost control
2439 wxVis
= wxWindowBase::IsShownOnScreen();
2443 return m_peer
->IsVisible();
2445 return wxWindowBase::IsShownOnScreen();
2448 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2450 bool handled
= HandleWindowEvent( event
) ;
2451 if ( handled
&& event
.GetSkipped() )
2455 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2457 wxWindow
*ancestor
= this;
2460 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2463 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2465 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2466 handled
= handler
->ProcessEvent( command_event
);
2470 // accelerators can also be used with buttons, try them too
2471 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2472 handled
= handler
->ProcessEvent( command_event
);
2478 if (ancestor
->IsTopLevel())
2481 ancestor
= ancestor
->GetParent();
2484 #endif // wxUSE_ACCEL
2493 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2495 static MacControlMap wxWinMacControlList
;
2497 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2499 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2501 return impl
->GetWXPeer();
2506 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2508 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2510 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2513 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2515 // adding NULL ControlRef is (first) surely a result of an error and
2516 // (secondly) breaks native event processing
2517 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2519 wxWinMacControlList
[inControl
] = impl
;
2522 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2524 // iterate over all the elements in the class
2525 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2526 // we should go on...
2532 MacControlMap::iterator it
;
2533 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2535 if ( it
->second
== impl
)
2537 wxWinMacControlList
.erase(it
);
2545 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2547 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2550 m_isRootControl
= isRootControl
;
2552 m_shouldSendEvents
= true;
2555 wxWidgetImpl::wxWidgetImpl()
2560 wxWidgetImpl::~wxWidgetImpl()
2564 void wxWidgetImpl::Init()
2566 m_isRootControl
= false;
2568 m_needsFocusRect
= false;
2569 m_needsFrame
= true;
2572 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2574 m_needsFocusRect
= needs
;
2577 bool wxWidgetImpl::NeedsFocusRect() const
2579 return m_needsFocusRect
;
2582 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2584 m_needsFrame
= needs
;
2587 bool wxWidgetImpl::NeedsFrame() const
2589 return m_needsFrame
;