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 ;
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 if ( m_dropTarget
!= NULL
)
268 WXWidget
wxWindowMac::GetHandle() const
271 return (WXWidget
) m_peer
->GetWXWidget() ;
275 // ---------------------------------------------------------------------------
276 // Utility Routines to move between different coordinate systems
277 // ---------------------------------------------------------------------------
280 * Right now we have the following setup :
281 * a border that is not part of the native control is always outside the
282 * control's border (otherwise we loose all native intelligence, future ways
283 * may be to have a second embedding control responsible for drawing borders
284 * and backgrounds eventually)
285 * so all this border calculations have to be taken into account when calling
286 * native methods or getting native oriented data
287 * so we have three coordinate systems here
288 * wx client coordinates
289 * wx window coordinates (including window frames)
297 bool wxWindowMac::Create(wxWindowMac
*parent
,
302 const wxString
& name
)
304 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
306 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
309 m_windowVariant
= parent
->GetWindowVariant() ;
311 if ( m_macIsUserPane
)
313 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
314 MacPostControlCreate(pos
, size
) ;
317 #ifndef __WXUNIVERSAL__
318 // Don't give scrollbars to wxControls unless they ask for them
319 if ( (! IsKindOf(CLASSINFO(wxControl
))
321 && ! IsKindOf(CLASSINFO(wxStatusBar
))
324 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
326 MacCreateScrollBars( style
) ;
330 wxWindowCreateEvent
event((wxWindow
*)this);
331 GetEventHandler()->AddPendingEvent(event
);
336 void wxWindowMac::MacChildAdded()
340 m_vScrollBar
->Raise() ;
342 m_hScrollBar
->Raise() ;
348 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
350 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
352 GetParent()->AddChild( this );
354 m_peer
->InstallEventHandler();
355 m_peer
->Embed(GetParent()->GetPeer());
357 GetParent()->MacChildAdded() ;
359 // adjust font, controlsize etc
360 DoSetWindowVariant( m_windowVariant
) ;
362 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
364 // for controls we want to use best size for wxDefaultSize params )
365 if ( !m_macIsUserPane
)
366 SetInitialSize(size
);
368 SetCursor( *wxSTANDARD_CURSOR
) ;
371 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
373 // Don't assert, in case we set the window variant before
374 // the window is created
375 // wxASSERT( m_peer->Ok() ) ;
377 m_windowVariant
= variant
;
379 if (m_peer
== NULL
|| !m_peer
->IsOk())
382 m_peer
->SetControlSize( variant
);
386 // we will get that from the settings later
387 // and make this NORMAL later, but first
388 // we have a few calculations that we must fix
392 case wxWINDOW_VARIANT_NORMAL
:
393 size
= kControlSizeNormal
;
396 case wxWINDOW_VARIANT_SMALL
:
397 size
= kControlSizeSmall
;
400 case wxWINDOW_VARIANT_MINI
:
401 // not always defined in the headers
405 case wxWINDOW_VARIANT_LARGE
:
406 size
= kControlSizeLarge
;
410 wxFAIL_MSG(wxT("unexpected window variant"));
413 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
419 case wxWINDOW_VARIANT_NORMAL
:
420 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
424 case wxWINDOW_VARIANT_SMALL
:
425 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
429 case wxWINDOW_VARIANT_MINI
:
430 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
434 case wxWINDOW_VARIANT_LARGE
:
435 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
440 wxFAIL_MSG(wxT("unexpected window variant"));
445 void wxWindowMac::MacUpdateControlFont()
448 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
450 // do not trigger refreshes upon invisible and possible partly created objects
451 if ( IsShownOnScreen() )
455 bool wxWindowMac::SetFont(const wxFont
& font
)
457 bool retval
= wxWindowBase::SetFont( font
);
459 MacUpdateControlFont() ;
464 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
466 bool retval
= wxWindowBase::SetForegroundColour( col
);
469 MacUpdateControlFont();
474 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
478 if ( m_backgroundColour
.Ok() )
479 m_growBox
->SetBackgroundColour(m_backgroundColour
);
481 m_growBox
->SetBackgroundColour(*wxWHITE
);
484 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
488 m_peer
->SetBackgroundColour( col
) ;
493 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
495 while (w
&& !w
->IsTopLevel())
504 void wxWindowMac::SetFocus()
506 if ( !AcceptsFocus() )
509 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
512 wxWindow
* former
= FindFocus() ;
513 if ( former
== this )
519 void wxWindowMac::DoCaptureMouse()
521 wxApp::s_captureWindow
= (wxWindow
*) this ;
522 m_peer
->CaptureMouse() ;
525 wxWindow
* wxWindowBase::GetCapture()
527 return wxApp::s_captureWindow
;
530 void wxWindowMac::DoReleaseMouse()
532 wxApp::s_captureWindow
= NULL
;
534 m_peer
->ReleaseMouse() ;
537 #if wxUSE_DRAG_AND_DROP
539 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
543 m_dropTarget
= pDropTarget
;
544 if ( m_dropTarget
!= NULL
)
552 // Old-style File Manager Drag & Drop
553 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
558 // From a wx position / size calculate the appropriate size of the native control
560 bool wxWindowMac::MacGetBoundsForControl(
564 int& w
, int& h
, bool adjustOrigin
) const
566 // the desired size, minus the border pixels gives the correct size of the control
570 w
= WidthDefault( size
.x
);
571 h
= HeightDefault( size
.y
);
573 x
+= MacGetLeftBorderSize() ;
574 y
+= MacGetTopBorderSize() ;
575 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
576 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
579 AdjustForParentClientOrigin( x
, y
) ;
581 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
582 if ( GetParent() && !GetParent()->IsTopLevel() )
584 x
-= GetParent()->MacGetLeftBorderSize() ;
585 y
-= GetParent()->MacGetTopBorderSize() ;
591 // Get window size (not client size)
592 void wxWindowMac::DoGetSize(int *x
, int *y
) const
595 m_peer
->GetSize( width
, height
);
598 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
600 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
603 // get the position of the bounds of this window in client coordinates of its parent
604 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
608 m_peer
->GetPosition( x1
, y1
) ;
610 // get the wx window position from the native one
611 x1
-= MacGetLeftBorderSize() ;
612 y1
-= MacGetTopBorderSize() ;
616 wxWindow
*parent
= GetParent();
619 // we must first adjust it to be in window coordinates of the parent,
620 // as otherwise it gets lost by the ClientAreaOrigin fix
621 x1
+= parent
->MacGetLeftBorderSize() ;
622 y1
+= parent
->MacGetTopBorderSize() ;
624 // and now to client coordinates
625 wxPoint
pt(parent
->GetClientAreaOrigin());
637 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
639 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
640 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
641 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
642 MacRootWindowToWindow( x
, y
) ;
644 wxPoint origin
= GetClientAreaOrigin() ;
651 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
653 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
654 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
656 wxPoint origin
= GetClientAreaOrigin() ;
662 MacWindowToRootWindow( x
, y
) ;
663 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
666 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
668 wxPoint origin
= GetClientAreaOrigin() ;
674 MacWindowToRootWindow( x
, y
) ;
677 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
688 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
691 pt
.x
-= MacGetLeftBorderSize() ;
692 pt
.y
-= MacGetTopBorderSize() ;
693 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
703 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
714 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
717 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
718 pt
.x
+= MacGetLeftBorderSize() ;
719 pt
.y
+= MacGetTopBorderSize() ;
729 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
731 wxSize sizeTotal
= size
;
733 int innerwidth
, innerheight
;
735 int outerwidth
, outerheight
;
737 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
738 m_peer
->GetSize( outerwidth
, outerheight
);
740 sizeTotal
.x
+= outerwidth
-innerwidth
;
741 sizeTotal
.y
+= outerheight
-innerheight
;
743 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
744 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
749 // Get size *available for subwindows* i.e. excluding menu bar etc.
750 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
756 m_peer
->GetContentArea( left
, top
, ww
, hh
);
758 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
759 hh
-= m_hScrollBar
->GetSize().y
;
761 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
762 ww
-= m_vScrollBar
->GetSize().x
;
771 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
773 if (m_cursor
.IsSameAs(cursor
))
778 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
783 if ( ! wxWindowBase::SetCursor( cursor
) )
787 wxASSERT_MSG( m_cursor
.Ok(),
788 wxT("cursor must be valid after call to the base version"));
790 if ( GetPeer() != NULL
)
791 GetPeer()->SetCursor( m_cursor
);
797 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
799 #ifndef __WXUNIVERSAL__
800 menu
->SetInvokingWindow((wxWindow
*)this);
803 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
805 wxPoint mouse
= wxGetMousePosition();
811 ClientToScreen( &x
, &y
) ;
813 menu
->GetPeer()->PopUp(this, x
, y
);
814 menu
->SetInvokingWindow( NULL
);
817 // actually this shouldn't be called, because universal is having its own implementation
823 // ----------------------------------------------------------------------------
825 // ----------------------------------------------------------------------------
829 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
831 wxWindowBase::DoSetToolTip(tooltip
);
834 m_tooltip
->SetWindow(this);
837 m_peer
->SetToolTip(tooltip
);
842 void wxWindowMac::MacInvalidateBorders()
844 if ( m_peer
== NULL
)
847 bool vis
= IsShownOnScreen() ;
851 int outerBorder
= MacGetLeftBorderSize() ;
853 if ( m_peer
->NeedsFocusRect() )
856 if ( outerBorder
== 0 )
859 // now we know that we have something to do at all
863 m_peer
->GetSize( tw
, th
);
864 m_peer
->GetPosition( tx
, ty
);
866 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
867 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
868 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
869 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
872 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
873 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
874 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
875 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
879 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
881 // this is never called for a toplevel window, so we know we have a parent
882 int former_x
, former_y
, former_w
, former_h
;
884 // Get true coordinates of former position
885 DoGetPosition( &former_x
, &former_y
) ;
886 DoGetSize( &former_w
, &former_h
) ;
888 wxWindow
*parent
= GetParent();
891 wxPoint
pt(parent
->GetClientAreaOrigin());
896 int actualWidth
= width
;
897 int actualHeight
= height
;
902 // min and max sizes are only for sizers, not for explicit size setting
903 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
904 actualWidth
= m_minWidth
;
905 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
906 actualHeight
= m_minHeight
;
907 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
908 actualWidth
= m_maxWidth
;
909 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
910 actualHeight
= m_maxHeight
;
913 bool doMove
= false, doResize
= false ;
915 if ( actualX
!= former_x
|| actualY
!= former_y
)
918 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
921 if ( doMove
|| doResize
)
923 // as the borders are drawn outside the native control, we adjust now
925 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
926 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
927 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
929 if ( parent
&& !parent
->IsTopLevel() )
931 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
934 MacInvalidateBorders() ;
936 m_cachedClippedRectValid
= false ;
938 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
940 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
942 MacInvalidateBorders() ;
944 MacRepositionScrollBars() ;
947 wxPoint
point(actualX
, actualY
);
948 wxMoveEvent
event(point
, m_windowId
);
949 event
.SetEventObject(this);
950 HandleWindowEvent(event
) ;
955 MacRepositionScrollBars() ;
956 wxSize
size(actualWidth
, actualHeight
);
957 wxSizeEvent
event(size
, m_windowId
);
958 event
.SetEventObject(this);
959 HandleWindowEvent(event
);
964 wxSize
wxWindowMac::DoGetBestSize() const
966 if ( m_macIsUserPane
|| IsTopLevel() )
968 return wxWindowBase::DoGetBestSize() ;
974 m_peer
->GetBestRect(&r
);
976 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
984 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
991 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
998 // return wxWindowBase::DoGetBestSize() ;
1002 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1003 MacGetRightBorderSize();
1004 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1005 MacGetBottomBorderSize();
1006 if ( bestHeight
< 10 )
1009 return wxSize(bestWidth
, bestHeight
);
1013 // set the size of the window: if the dimensions are positive, just use them,
1014 // but if any of them is equal to -1, it means that we must find the value for
1015 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1016 // which case -1 is a valid value for x and y)
1018 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1019 // the width/height to best suit our contents, otherwise we reuse the current
1021 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1023 // get the current size and position...
1024 int currentX
, currentY
;
1025 int currentW
, currentH
;
1027 GetPosition(¤tX
, ¤tY
);
1028 GetSize(¤tW
, ¤tH
);
1030 // ... and don't do anything (avoiding flicker) if it's already ok
1031 if ( x
== currentX
&& y
== currentY
&&
1032 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1035 MacRepositionScrollBars() ; // we might have a real position shift
1037 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1039 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1040 event
.SetEventObject( this );
1041 HandleWindowEvent( event
);
1047 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1049 if ( x
== wxDefaultCoord
)
1051 if ( y
== wxDefaultCoord
)
1055 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1057 wxSize size
= wxDefaultSize
;
1058 if ( width
== wxDefaultCoord
)
1060 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1062 size
= DoGetBestSize();
1067 // just take the current one
1072 if ( height
== wxDefaultCoord
)
1074 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1076 if ( size
.x
== wxDefaultCoord
)
1077 size
= DoGetBestSize();
1078 // else: already called DoGetBestSize() above
1084 // just take the current one
1089 DoMoveWindow( x
, y
, width
, height
);
1092 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1094 int left
,top
,width
,height
;
1095 m_peer
->GetContentArea( left
, top
, width
, height
);
1096 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1099 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1101 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1103 int currentclientwidth
, currentclientheight
;
1104 int currentwidth
, currentheight
;
1106 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1107 GetSize( ¤twidth
, ¤theight
) ;
1109 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1110 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1114 void wxWindowMac::SetLabel(const wxString
& title
)
1116 if ( title
== m_label
)
1121 InvalidateBestSize();
1123 if ( m_peer
&& m_peer
->IsOk() )
1124 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1126 // do not trigger refreshes upon invisible and possible partly created objects
1127 if ( IsShownOnScreen() )
1131 wxString
wxWindowMac::GetLabel() const
1136 bool wxWindowMac::Show(bool show
)
1138 if ( !wxWindowBase::Show(show
) )
1142 m_peer
->SetVisibility( show
) ;
1144 #ifdef __WXOSX_IPHONE__
1145 // only when there's no native event support
1146 if ( !IsTopLevel() )
1149 wxShowEvent
eventShow(GetId(), show
);
1150 eventShow
.SetEventObject(this);
1152 HandleWindowEvent(eventShow
);
1158 bool wxWindowMac::OSXShowWithEffect(bool show
,
1159 wxShowEffect effect
,
1162 if ( effect
== wxSHOW_EFFECT_NONE
||
1163 !m_peer
|| !m_peer
->ShowWithEffect(show
, effect
, timeout
) )
1169 void wxWindowMac::DoEnable(bool enable
)
1171 m_peer
->Enable( enable
) ;
1172 MacInvalidateBorders();
1176 // status change notifications
1179 void wxWindowMac::MacVisibilityChanged()
1183 void wxWindowMac::MacHiliteChanged()
1187 void wxWindowMac::MacEnabledStateChanged()
1189 OnEnabled( m_peer
->IsEnabled() );
1193 // status queries on the inherited window's state
1196 bool wxWindowMac::MacIsReallyEnabled()
1198 return m_peer
->IsEnabled() ;
1201 bool wxWindowMac::MacIsReallyHilited()
1203 #if wxOSX_USE_CARBON
1204 return m_peer
->IsActive();
1206 return true; // TODO
1210 int wxWindowMac::GetCharHeight() const
1213 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1218 int wxWindowMac::GetCharWidth() const
1221 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1226 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1229 int *externalLeading
,
1230 const wxFont
*theFont
) const
1232 const wxFont
*fontToUse
= theFont
;
1236 tempFont
= GetFont();
1237 fontToUse
= &tempFont
;
1240 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1241 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1243 wxDouble h
, d
, e
, w
;
1244 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1248 if ( externalLeading
)
1249 *externalLeading
= (wxCoord
)(e
+0.5);
1251 *descent
= (wxCoord
)(d
+0.5);
1253 *x
= (wxCoord
)(w
+0.5);
1255 *y
= (wxCoord
)(h
+0.5);
1259 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1260 * we always intersect with the entire window, not only with the client area
1263 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1265 if ( m_peer
== NULL
)
1268 if ( !IsShownOnScreen() )
1271 m_peer
->SetNeedsDisplay( rect
) ;
1274 void wxWindowMac::DoFreeze()
1276 #if wxOSX_USE_CARBON
1277 if ( m_peer
&& m_peer
->IsOk() )
1278 m_peer
->SetDrawingEnabled( false ) ;
1282 void wxWindowMac::DoThaw()
1284 #if wxOSX_USE_CARBON
1285 if ( m_peer
&& m_peer
->IsOk() )
1287 m_peer
->SetDrawingEnabled( true ) ;
1288 m_peer
->InvalidateWithChildren() ;
1293 wxWindow
*wxGetActiveWindow()
1295 // actually this is a windows-only concept
1299 // Coordinates relative to the window
1300 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1302 #if wxOSX_USE_COCOA_OR_CARBON
1305 DoClientToScreen(&x
, &y
);
1306 CGPoint cgpoint
= CGPointMake( x
, y
);
1307 CGWarpMouseCursorPosition( cgpoint
);
1309 // At least GTK sends a mouse moved event after WarpMouse
1310 wxMouseEvent
event(wxEVT_MOTION
);
1313 wxMouseState mState
= ::wxGetMouseState();
1315 event
.m_altDown
= mState
.AltDown();
1316 event
.m_controlDown
= mState
.ControlDown();
1317 event
.m_leftDown
= mState
.LeftIsDown();
1318 event
.m_middleDown
= mState
.MiddleIsDown();
1319 event
.m_rightDown
= mState
.RightIsDown();
1320 event
.m_metaDown
= mState
.MetaDown();
1321 event
.m_shiftDown
= mState
.ShiftDown();
1322 event
.SetId(GetId());
1323 event
.SetEventObject(this);
1324 GetEventHandler()->ProcessEvent(event
);
1328 int wxWindowMac::GetScrollPos(int orient
) const
1331 if ( orient
== wxHORIZONTAL
)
1334 return m_hScrollBar
->GetThumbPosition() ;
1339 return m_vScrollBar
->GetThumbPosition() ;
1345 // This now returns the whole range, not just the number
1346 // of positions that we can scroll.
1347 int wxWindowMac::GetScrollRange(int orient
) const
1350 if ( orient
== wxHORIZONTAL
)
1353 return m_hScrollBar
->GetRange() ;
1358 return m_vScrollBar
->GetRange() ;
1364 int wxWindowMac::GetScrollThumb(int orient
) const
1367 if ( orient
== wxHORIZONTAL
)
1370 return m_hScrollBar
->GetThumbSize() ;
1375 return m_vScrollBar
->GetThumbSize() ;
1381 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1384 if ( orient
== wxHORIZONTAL
)
1387 m_hScrollBar
->SetThumbPosition( pos
) ;
1392 m_vScrollBar
->SetThumbPosition( pos
) ;
1398 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1400 bool needVisibilityUpdate
= false;
1402 if ( m_hScrollBarAlwaysShown
!= hflag
)
1404 m_hScrollBarAlwaysShown
= hflag
;
1405 needVisibilityUpdate
= true;
1408 if ( m_vScrollBarAlwaysShown
!= vflag
)
1410 m_vScrollBarAlwaysShown
= vflag
;
1411 needVisibilityUpdate
= true;
1414 if ( needVisibilityUpdate
)
1415 DoUpdateScrollbarVisibility();
1419 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1420 // our own window origin is at leftOrigin/rightOrigin
1423 void wxWindowMac::MacPaintGrowBox()
1429 if ( MacHasScrollBarCorner() )
1432 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1433 wxASSERT( cgContext
) ;
1437 m_peer
->GetSize( tw
, th
);
1438 m_peer
->GetPosition( tx
, ty
);
1440 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1443 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1444 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1445 CGContextSaveGState( cgContext
);
1447 if ( m_backgroundColour
.Ok() )
1449 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1453 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1455 CGContextFillRect( cgContext
, cgrect
);
1456 CGContextRestoreGState( cgContext
);
1460 if ( m_backgroundColour
.Ok() )
1461 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1463 m_growBox
->SetBackgroundColour(*wxWHITE
);
1471 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1476 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1478 // back to the surrounding frame rectangle
1481 m_peer
->GetSize( tw
, th
);
1482 m_peer
->GetPosition( tx
, ty
);
1484 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1486 #if wxOSX_USE_COCOA_OR_CARBON
1488 InsetRect( &rect
, -1 , -1 ) ;
1491 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1492 rect
.bottom
- rect
.top
) ;
1494 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1495 wxASSERT( cgContext
) ;
1497 if ( m_peer
->NeedsFrame() )
1499 HIThemeFrameDrawInfo info
;
1500 memset( &info
, 0 , sizeof(info
) ) ;
1504 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1505 info
.isFocused
= hasFocus
;
1507 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1509 info
.kind
= kHIThemeFrameTextFieldSquare
;
1510 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1512 else if ( HasFlag(wxSIMPLE_BORDER
) )
1514 info
.kind
= kHIThemeFrameListBox
;
1515 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1521 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1524 #endif // wxOSX_USE_COCOA_OR_CARBON
1527 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1530 if ( child
== m_hScrollBar
)
1531 m_hScrollBar
= NULL
;
1532 if ( child
== m_vScrollBar
)
1533 m_vScrollBar
= NULL
;
1534 if ( child
== m_growBox
)
1537 wxWindowBase::RemoveChild( child
) ;
1540 void wxWindowMac::DoUpdateScrollbarVisibility()
1543 bool triggerSizeEvent
= false;
1547 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1549 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1551 m_hScrollBar
->Show( showHScrollBar
);
1552 triggerSizeEvent
= true;
1558 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1560 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1562 m_vScrollBar
->Show( showVScrollBar
) ;
1563 triggerSizeEvent
= true;
1567 MacRepositionScrollBars() ;
1568 if ( triggerSizeEvent
)
1570 wxSizeEvent
event(GetSize(), m_windowId
);
1571 event
.SetEventObject(this);
1572 HandleWindowEvent(event
);
1577 // New function that will replace some of the above.
1578 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1579 int range
, bool refresh
)
1582 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1583 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1584 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1585 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1587 DoUpdateScrollbarVisibility();
1591 // Does a physical scroll
1592 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1594 if ( dx
== 0 && dy
== 0 )
1597 int width
, height
;
1598 GetClientSize( &width
, &height
) ;
1601 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1603 scrollrect
.Intersect( *rect
) ;
1604 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1605 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1607 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1612 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1614 child
= node
->GetData();
1618 if (child
->IsTopLevel())
1621 if ( !IsClientAreaChild(child
) )
1624 child
->GetPosition( &x
, &y
);
1625 child
->GetSize( &w
, &h
);
1628 wxRect
rc( x
, y
, w
, h
);
1629 if (rect
->Intersects( rc
))
1630 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1634 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1639 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1642 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1644 wxScrollWinEvent wevent
;
1645 wevent
.SetPosition(event
.GetPosition());
1646 wevent
.SetOrientation(event
.GetOrientation());
1647 wevent
.SetEventObject(this);
1649 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1650 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1651 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1652 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1653 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1654 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1655 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1656 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1657 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1658 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1659 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1660 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1661 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1662 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1663 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1664 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1666 HandleWindowEvent(wevent
);
1671 wxWindow
*wxWindowBase::DoFindFocus()
1673 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1676 void wxWindowMac::OnInternalIdle()
1678 // This calls the UI-update mechanism (querying windows for
1679 // menu/toolbar/control state information)
1680 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1681 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1684 // Raise the window to the top of the Z order
1685 void wxWindowMac::Raise()
1690 // Lower the window to the bottom of the Z order
1691 void wxWindowMac::Lower()
1696 // static wxWindow *gs_lastWhich = NULL;
1698 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1700 // first trigger a set cursor event
1702 wxPoint clientorigin
= GetClientAreaOrigin() ;
1703 wxSize clientsize
= GetClientSize() ;
1705 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1707 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1709 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1710 if ( processedEvtSetCursor
&& event
.HasCursor() )
1712 cursor
= event
.GetCursor() ;
1716 // the test for processedEvtSetCursor is here to prevent using m_cursor
1717 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1718 // it - this is a way to say that our cursor shouldn't be used for this
1720 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1723 if ( !wxIsBusy() && !GetParent() )
1724 cursor
= *wxSTANDARD_CURSOR
;
1728 cursor
.MacInstall() ;
1731 return cursor
.Ok() ;
1734 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1738 return m_tooltip
->GetTip() ;
1741 return wxEmptyString
;
1744 void wxWindowMac::ClearBackground()
1750 void wxWindowMac::Update()
1752 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1757 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1759 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1763 if ( iter
->IsTopLevel() )
1765 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1769 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1774 iter
= iter
->GetParent() ;
1780 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1782 MacUpdateClippedRects() ;
1784 return m_cachedClippedClientRect
;
1787 const wxRect
& wxWindowMac::MacGetClippedRect() const
1789 MacUpdateClippedRects() ;
1791 return m_cachedClippedRect
;
1794 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1796 MacUpdateClippedRects() ;
1798 return m_cachedClippedRectWithOuterStructure
;
1801 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1803 static wxRegion emptyrgn
;
1805 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1807 MacUpdateClippedRects() ;
1808 if ( includeOuterStructures
)
1809 return m_cachedClippedRegionWithOuterStructure
;
1811 return m_cachedClippedRegion
;
1819 void wxWindowMac::MacUpdateClippedRects() const
1821 #if wxOSX_USE_CARBON
1822 if ( m_cachedClippedRectValid
)
1825 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1826 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1827 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1828 // to add focus borders everywhere
1830 Rect rIncludingOuterStructures
;
1834 m_peer
->GetSize( tw
, th
);
1835 m_peer
->GetPosition( tx
, ty
);
1837 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1839 r
.left
-= MacGetLeftBorderSize() ;
1840 r
.top
-= MacGetTopBorderSize() ;
1841 r
.bottom
+= MacGetBottomBorderSize() ;
1842 r
.right
+= MacGetRightBorderSize() ;
1849 rIncludingOuterStructures
= r
;
1850 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1852 wxRect cl
= GetClientRect() ;
1853 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1857 const wxWindow
* child
= (wxWindow
*) this ;
1858 const wxWindow
* parent
= NULL
;
1860 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1862 if ( parent
->MacIsChildOfClientArea(child
) )
1864 size
= parent
->GetClientSize() ;
1865 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1871 // this will be true for scrollbars, toolbars etc.
1872 size
= parent
->GetSize() ;
1873 y
= parent
->MacGetTopBorderSize() ;
1874 x
= parent
->MacGetLeftBorderSize() ;
1875 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1876 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1879 parent
->MacWindowToRootWindow( &x
, &y
) ;
1880 MacRootWindowToWindow( &x
, &y
) ;
1882 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1884 // the wxwindow and client rects will always be clipped
1885 SectRect( &r
, &rparent
, &r
) ;
1886 SectRect( &rClient
, &rparent
, &rClient
) ;
1888 // the structure only at 'hard' borders
1889 if ( parent
->MacClipChildren() ||
1890 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1892 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1898 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1899 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1900 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1901 m_cachedClippedRectWithOuterStructure
= wxRect(
1902 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1903 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1904 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1906 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1907 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1908 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1910 m_cachedClippedRectValid
= true ;
1915 This function must not change the updatergn !
1917 bool wxWindowMac::MacDoRedraw( long time
)
1919 bool handled
= false ;
1921 wxRegion formerUpdateRgn
= m_updateRegion
;
1922 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1924 const wxRect clientRect
= GetClientRect();
1926 clientUpdateRgn
.Intersect(clientRect
);
1928 // first send an erase event to the entire update area
1929 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1932 case wxBG_STYLE_ERASE
:
1933 case wxBG_STYLE_SYSTEM
:
1934 case wxBG_STYLE_COLOUR
:
1936 // for the toplevel window this really is the entire area for
1937 // all the others only their client area, otherwise they might
1938 // be drawing with full alpha and eg put blue into the grow-box
1939 // area of a scrolled window (scroll sample)
1940 wxWindowDC
dc(this);
1942 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1944 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1946 if ( bgStyle
== wxBG_STYLE_ERASE
)
1948 wxEraseEvent
eevent( GetId(), &dc
);
1949 eevent
.SetEventObject( this );
1950 if ( ProcessWindowEvent( eevent
) )
1956 dc
.SetBackground(GetBackgroundColour());
1962 case wxBG_STYLE_PAINT
:
1963 case wxBG_STYLE_TRANSPARENT
:
1964 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1965 // entire window client area
1969 wxFAIL_MSG( "unsupported background style" );
1972 // as this is a full window, shouldn't be necessary anymore
1973 // MacPaintGrowBox();
1975 // calculate a client-origin version of the update rgn and set
1976 // m_updateRegion to that
1977 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1978 m_updateRegion
= clientUpdateRgn
;
1980 if ( !m_updateRegion
.Empty() )
1982 // paint the window itself
1984 wxPaintEvent
event(GetId());
1985 event
.SetTimestamp(time
);
1986 event
.SetEventObject(this);
1987 handled
= HandleWindowEvent(event
);
1990 m_updateRegion
= formerUpdateRgn
;
1994 void wxWindowMac::MacPaintChildrenBorders()
1996 // now we cannot rely on having its borders drawn by a window itself, as it does not
1997 // get the updateRgn wide enough to always do so, so we do it from the parent
1998 // this would also be the place to draw any custom backgrounds for native controls
1999 // in Composited windowing
2000 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2004 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2006 child
= node
->GetData();
2010 if (child
== m_vScrollBar
)
2012 if (child
== m_hScrollBar
)
2014 if (child
== m_growBox
)
2017 if (child
->IsTopLevel())
2019 if (!child
->IsShown())
2022 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2024 child
->GetPosition( &x
, &y
);
2025 child
->GetSize( &w
, &h
);
2027 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2029 // paint custom borders
2030 wxNcPaintEvent
eventNc( child
->GetId() );
2031 eventNc
.SetEventObject( child
);
2032 if ( !child
->HandleWindowEvent( eventNc
) )
2034 child
->MacPaintBorders(0, 0) ;
2041 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2043 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2044 return tlw
? tlw
->GetWXWindow() : NULL
;
2047 bool wxWindowMac::MacHasScrollBarCorner() const
2050 /* Returns whether the scroll bars in a wxScrolledWindow should be
2051 * shortened. Scroll bars should be shortened if either:
2053 * - both scroll bars are visible, or
2055 * - there is a resize box in the parent frame's corner and this
2056 * window shares the bottom and right edge with the parent
2060 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2063 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2064 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2066 // Both scroll bars visible
2071 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2073 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2075 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2078 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2080 // Parent frame has resize handle
2081 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2083 // Note: allow for some wiggle room here as wxMac's
2084 // window rect calculations seem to be imprecise
2085 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2086 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2088 // Parent frame has resize handle and shares
2089 // right bottom corner
2094 // Parent frame has resize handle but doesn't
2095 // share right bottom corner
2101 // Parent frame doesn't have resize handle
2107 // No parent frame found
2115 void wxWindowMac::MacCreateScrollBars( long style
)
2118 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2120 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2122 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2123 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2125 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2128 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2130 GetClientSize( &width
, &height
) ;
2132 wxPoint
vPoint(width
- scrlsize
, 0) ;
2133 wxSize
vSize(scrlsize
, height
- adjust
) ;
2134 wxPoint
hPoint(0, height
- scrlsize
) ;
2135 wxSize
hSize(width
- adjust
, scrlsize
) ;
2137 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2138 if ( style
& wxVSCROLL
)
2140 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2141 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2144 if ( style
& wxHSCROLL
)
2146 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2147 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2150 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2151 wxSize
gSize(scrlsize
, scrlsize
);
2152 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2155 // because the create does not take into account the client area origin
2156 // we might have a real position shift
2157 MacRepositionScrollBars() ;
2161 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2163 bool result
= ((child
== NULL
)
2165 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2172 void wxWindowMac::MacRepositionScrollBars()
2175 if ( !m_hScrollBar
&& !m_vScrollBar
)
2178 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2179 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2181 // get real client area
2183 GetSize( &width
, &height
);
2185 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2186 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2188 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2189 wxSize
vSize( scrlsize
, height
- adjust
) ;
2190 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2191 wxSize
hSize( width
- adjust
, scrlsize
) ;
2194 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2196 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2199 if ( MacHasScrollBarCorner() )
2201 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2202 if ( !m_growBox
->IsShown() )
2207 if ( m_growBox
->IsShown() )
2214 bool wxWindowMac::AcceptsFocus() const
2216 if ( MacIsUserPane() )
2217 return wxWindowBase::AcceptsFocus();
2219 return m_peer
->CanFocus();
2222 void wxWindowMac::MacSuperChangedPosition()
2224 // only window-absolute structures have to be moved i.e. controls
2226 m_cachedClippedRectValid
= false ;
2229 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2232 child
= node
->GetData();
2233 child
->MacSuperChangedPosition() ;
2235 node
= node
->GetNext();
2239 void wxWindowMac::MacTopLevelWindowChangedPosition()
2241 // only screen-absolute structures have to be moved i.e. glcanvas
2244 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2247 child
= node
->GetData();
2248 child
->MacTopLevelWindowChangedPosition() ;
2250 node
= node
->GetNext();
2254 long wxWindowMac::MacGetLeftBorderSize() const
2261 if ( m_peer
&& m_peer
->NeedsFrame() )
2263 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2265 #if wxOSX_USE_COCOA_OR_CARBON
2266 // this metric is only the 'outset' outside the simple frame rect
2267 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2273 else if (HasFlag(wxSIMPLE_BORDER
))
2275 #if wxOSX_USE_COCOA_OR_CARBON
2276 // this metric is only the 'outset' outside the simple frame rect
2277 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2288 long wxWindowMac::MacGetRightBorderSize() const
2290 // they are all symmetric in mac themes
2291 return MacGetLeftBorderSize() ;
2294 long wxWindowMac::MacGetTopBorderSize() const
2296 // they are all symmetric in mac themes
2297 return MacGetLeftBorderSize() ;
2300 long wxWindowMac::MacGetBottomBorderSize() const
2302 // they are all symmetric in mac themes
2303 return MacGetLeftBorderSize() ;
2306 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2308 return style
& ~wxBORDER_MASK
;
2311 // Find the wxWindowMac at the current mouse position, returning the mouse
2313 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2315 pt
= wxGetMousePosition();
2316 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2318 return (wxWindow
*) found
;
2321 // Get the current mouse position.
2322 wxPoint
wxGetMousePosition()
2326 wxGetMousePosition( &x
, &y
);
2328 return wxPoint(x
, y
);
2331 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2333 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2335 // copied from wxGTK : CS
2336 // VZ: shouldn't we move this to base class then?
2338 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2341 // (a) it's a command event and so is propagated to the parent
2342 // (b) under MSW it can be generated from kbd too
2343 // (c) it uses screen coords (because of (a))
2344 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2346 this->ClientToScreen(event
.GetPosition()));
2347 evtCtx
.SetEventObject(this);
2348 if ( ! HandleWindowEvent(evtCtx
) )
2357 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2361 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2365 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2366 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2371 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2376 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2378 #if wxOSX_USE_COCOA_OR_CARBON
2379 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2382 return eventNotHandledErr
;
2388 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2390 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2391 if ( !wxWindowBase::Reparent(newParent
) )
2394 m_peer
->RemoveFromParent();
2395 m_peer
->Embed( GetParent()->GetPeer() );
2401 bool wxWindowMac::SetTransparent(wxByte alpha
)
2403 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2405 if ( alpha
!= m_macAlpha
)
2407 m_macAlpha
= alpha
;
2414 bool wxWindowMac::CanSetTransparent()
2419 wxByte
wxWindowMac::GetTransparent() const
2424 bool wxWindowMac::IsShownOnScreen() const
2426 if ( m_peer
&& m_peer
->IsOk() )
2428 bool peerVis
= m_peer
->IsVisible();
2429 bool wxVis
= wxWindowBase::IsShownOnScreen();
2430 if( peerVis
!= wxVis
)
2432 // CS : put a breakpoint here to investigate differences
2433 // between native an wx visibilities
2434 // the only place where I've encountered them until now
2435 // are the hiding/showing sequences where the vis-changed event is
2436 // first sent to the innermost control, while wx does things
2437 // from the outmost control
2438 wxVis
= wxWindowBase::IsShownOnScreen();
2442 return m_peer
->IsVisible();
2444 return wxWindowBase::IsShownOnScreen();
2447 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2449 bool handled
= HandleWindowEvent( event
) ;
2450 if ( handled
&& event
.GetSkipped() )
2454 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2456 wxWindow
*ancestor
= this;
2459 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2462 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2464 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2465 handled
= handler
->ProcessEvent( command_event
);
2469 // accelerators can also be used with buttons, try them too
2470 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2471 handled
= handler
->ProcessEvent( command_event
);
2477 if (ancestor
->IsTopLevel())
2480 ancestor
= ancestor
->GetParent();
2483 #endif // wxUSE_ACCEL
2492 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2494 static MacControlMap wxWinMacControlList
;
2496 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2498 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2500 return impl
->GetWXPeer();
2505 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2507 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2509 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2512 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2514 // adding NULL ControlRef is (first) surely a result of an error and
2515 // (secondly) breaks native event processing
2516 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2518 wxWinMacControlList
[inControl
] = impl
;
2521 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2523 // iterate over all the elements in the class
2524 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2525 // we should go on...
2531 MacControlMap::iterator it
;
2532 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2534 if ( it
->second
== impl
)
2536 wxWinMacControlList
.erase(it
);
2544 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2546 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2549 m_isRootControl
= isRootControl
;
2551 m_shouldSendEvents
= true;
2554 wxWidgetImpl::wxWidgetImpl()
2559 wxWidgetImpl::~wxWidgetImpl()
2563 void wxWidgetImpl::Init()
2565 m_isRootControl
= false;
2567 m_needsFocusRect
= false;
2568 m_needsFrame
= true;
2571 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2573 m_needsFocusRect
= needs
;
2576 bool wxWidgetImpl::NeedsFocusRect() const
2578 return m_needsFocusRect
;
2581 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2583 m_needsFrame
= needs
;
2586 bool wxWidgetImpl::NeedsFrame() const
2588 return m_needsFrame
;