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 #include <Carbon/Carbon.h>
76 #define MAC_SCROLLBAR_SIZE 15
77 #define MAC_SMALL_SCROLLBAR_SIZE 11
81 #ifdef __WXUNIVERSAL__
82 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
84 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
87 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
88 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 // ===========================================================================
98 // ===========================================================================
100 // ----------------------------------------------------------------------------
101 // constructors and such
102 // ----------------------------------------------------------------------------
104 wxWindowMac::wxWindowMac()
109 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
114 const wxString
& name
)
117 Create(parent
, id
, pos
, size
, style
, name
);
120 void wxWindowMac::Init()
124 m_cgContextRef
= NULL
;
126 // as all windows are created with WS_VISIBLE style...
129 m_hScrollBar
= NULL
;
130 m_vScrollBar
= NULL
;
131 m_hScrollBarAlwaysShown
= false;
132 m_vScrollBarAlwaysShown
= false;
134 m_macIsUserPane
= true;
135 m_clipChildren
= false ;
136 m_cachedClippedRectValid
= false ;
139 wxWindowMac::~wxWindowMac()
143 MacInvalidateBorders() ;
145 #ifndef __WXUNIVERSAL__
146 // VS: make sure there's no wxFrame with last focus set to us:
147 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
149 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
152 if ( frame
->GetLastFocus() == this )
153 frame
->SetLastFocus(NULL
);
159 // destroy children before destroying this window itself
162 // wxRemoveMacControlAssociation( this ) ;
163 // If we delete an item, we should initialize the parent panel,
164 // because it could now be invalid.
165 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
168 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
169 tlw
->SetDefaultItem(NULL
);
172 if ( g_MacLastWindow
== this )
173 g_MacLastWindow
= NULL
;
175 #ifndef __WXUNIVERSAL__
176 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
179 if ( frame
->GetLastFocus() == this )
180 frame
->SetLastFocus( NULL
) ;
184 // delete our drop target if we've got one
185 #if wxUSE_DRAG_AND_DROP
186 if ( m_dropTarget
!= NULL
)
196 WXWidget
wxWindowMac::GetHandle() const
199 return (WXWidget
) m_peer
->GetWXWidget() ;
203 // ---------------------------------------------------------------------------
204 // Utility Routines to move between different coordinate systems
205 // ---------------------------------------------------------------------------
208 * Right now we have the following setup :
209 * a border that is not part of the native control is always outside the
210 * control's border (otherwise we loose all native intelligence, future ways
211 * may be to have a second embedding control responsible for drawing borders
212 * and backgrounds eventually)
213 * so all this border calculations have to be taken into account when calling
214 * native methods or getting native oriented data
215 * so we have three coordinate systems here
216 * wx client coordinates
217 * wx window coordinates (including window frames)
225 bool wxWindowMac::Create(wxWindowMac
*parent
,
230 const wxString
& name
)
232 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
234 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
237 m_windowVariant
= parent
->GetWindowVariant() ;
239 if ( m_macIsUserPane
)
241 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
242 MacPostControlCreate(pos
, size
) ;
245 #ifndef __WXUNIVERSAL__
246 // Don't give scrollbars to wxControls unless they ask for them
247 if ( (! IsKindOf(CLASSINFO(wxControl
))
249 && ! IsKindOf(CLASSINFO(wxStatusBar
))
252 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
254 MacCreateScrollBars( style
) ;
258 wxWindowCreateEvent
event((wxWindow
*)this);
259 GetEventHandler()->AddPendingEvent(event
);
264 void wxWindowMac::MacChildAdded()
268 m_vScrollBar
->Raise() ;
270 m_hScrollBar
->Raise() ;
274 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
276 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
278 GetParent()->AddChild( this );
280 m_peer
->InstallEventHandler();
281 m_peer
->Embed(GetParent()->GetPeer());
283 GetParent()->MacChildAdded() ;
285 // adjust font, controlsize etc
286 DoSetWindowVariant( m_windowVariant
) ;
288 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
290 // for controls we want to use best size for wxDefaultSize params )
291 if ( !m_macIsUserPane
)
292 SetInitialSize(size
);
294 SetCursor( *wxSTANDARD_CURSOR
) ;
297 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
299 // Don't assert, in case we set the window variant before
300 // the window is created
301 // wxASSERT( m_peer->Ok() ) ;
303 m_windowVariant
= variant
;
305 if (m_peer
== NULL
|| !m_peer
->IsOk())
308 m_peer
->SetControlSize( variant
);
312 // we will get that from the settings later
313 // and make this NORMAL later, but first
314 // we have a few calculations that we must fix
318 case wxWINDOW_VARIANT_NORMAL
:
319 size
= kControlSizeNormal
;
322 case wxWINDOW_VARIANT_SMALL
:
323 size
= kControlSizeSmall
;
326 case wxWINDOW_VARIANT_MINI
:
327 // not always defined in the headers
331 case wxWINDOW_VARIANT_LARGE
:
332 size
= kControlSizeLarge
;
336 wxFAIL_MSG(wxT("unexpected window variant"));
339 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
344 wxOSXSystemFont systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
348 case wxWINDOW_VARIANT_NORMAL
:
349 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
352 case wxWINDOW_VARIANT_SMALL
:
353 systemFont
= wxOSX_SYSTEM_FONT_SMALL
;
356 case wxWINDOW_VARIANT_MINI
:
357 systemFont
= wxOSX_SYSTEM_FONT_MINI
;
360 case wxWINDOW_VARIANT_LARGE
:
361 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
365 wxFAIL_MSG(wxT("unexpected window variant"));
369 font
.CreateSystemFont( systemFont
) ;
374 void wxWindowMac::MacUpdateControlFont()
377 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
379 // do not trigger refreshes upon invisible and possible partly created objects
380 if ( IsShownOnScreen() )
384 bool wxWindowMac::SetFont(const wxFont
& font
)
386 bool retval
= wxWindowBase::SetFont( font
);
388 MacUpdateControlFont() ;
393 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
395 bool retval
= wxWindowBase::SetForegroundColour( col
);
398 MacUpdateControlFont();
403 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
405 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
409 m_peer
->SetBackgroundColour( col
) ;
414 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
416 while (w
&& !w
->IsTopLevel())
425 void wxWindowMac::SetFocus()
427 if ( !AcceptsFocus() )
430 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
433 wxWindow
* former
= FindFocus() ;
434 if ( former
== this )
440 void wxWindowMac::DoCaptureMouse()
442 wxApp::s_captureWindow
= (wxWindow
*) this ;
443 m_peer
->CaptureMouse() ;
446 wxWindow
* wxWindowBase::GetCapture()
448 return wxApp::s_captureWindow
;
451 void wxWindowMac::DoReleaseMouse()
453 wxApp::s_captureWindow
= NULL
;
455 m_peer
->ReleaseMouse() ;
458 #if wxUSE_DRAG_AND_DROP
460 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
464 m_dropTarget
= pDropTarget
;
465 if ( m_dropTarget
!= NULL
)
473 // Old-style File Manager Drag & Drop
474 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
479 // From a wx position / size calculate the appropriate size of the native control
481 bool wxWindowMac::MacGetBoundsForControl(
485 int& w
, int& h
, bool adjustOrigin
) const
487 // the desired size, minus the border pixels gives the correct size of the control
491 w
= WidthDefault( size
.x
);
492 h
= HeightDefault( size
.y
);
494 x
+= MacGetLeftBorderSize() ;
495 y
+= MacGetTopBorderSize() ;
496 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
497 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
500 AdjustForParentClientOrigin( x
, y
) ;
502 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
503 if ( GetParent() && !GetParent()->IsTopLevel() )
505 x
-= GetParent()->MacGetLeftBorderSize() ;
506 y
-= GetParent()->MacGetTopBorderSize() ;
512 // Get window size (not client size)
513 void wxWindowMac::DoGetSize(int *x
, int *y
) const
516 m_peer
->GetSize( width
, height
);
519 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
521 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
524 // get the position of the bounds of this window in client coordinates of its parent
525 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
529 m_peer
->GetPosition( x1
, y1
) ;
531 // get the wx window position from the native one
532 x1
-= MacGetLeftBorderSize() ;
533 y1
-= MacGetTopBorderSize() ;
537 wxWindow
*parent
= GetParent();
540 // we must first adjust it to be in window coordinates of the parent,
541 // as otherwise it gets lost by the ClientAreaOrigin fix
542 x1
+= parent
->MacGetLeftBorderSize() ;
543 y1
+= parent
->MacGetTopBorderSize() ;
545 // and now to client coordinates
546 wxPoint
pt(parent
->GetClientAreaOrigin());
558 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
560 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
561 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
562 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
563 MacRootWindowToWindow( x
, y
) ;
565 wxPoint origin
= GetClientAreaOrigin() ;
572 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
574 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
575 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
577 wxPoint origin
= GetClientAreaOrigin() ;
583 MacWindowToRootWindow( x
, y
) ;
584 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
587 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
589 wxPoint origin
= GetClientAreaOrigin() ;
595 MacWindowToRootWindow( x
, y
) ;
598 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
609 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
612 pt
.x
-= MacGetLeftBorderSize() ;
613 pt
.y
-= MacGetTopBorderSize() ;
614 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
624 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
635 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
638 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
639 pt
.x
+= MacGetLeftBorderSize() ;
640 pt
.y
+= MacGetTopBorderSize() ;
650 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
652 wxSize sizeTotal
= size
;
654 int innerwidth
, innerheight
;
656 int outerwidth
, outerheight
;
658 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
659 m_peer
->GetSize( outerwidth
, outerheight
);
661 sizeTotal
.x
+= outerwidth
-innerwidth
;
662 sizeTotal
.y
+= outerheight
-innerheight
;
664 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
665 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
670 // Get size *available for subwindows* i.e. excluding menu bar etc.
671 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
677 m_peer
->GetContentArea( left
, top
, ww
, hh
);
679 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
680 hh
-= m_hScrollBar
->GetSize().y
;
682 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
683 ww
-= m_vScrollBar
->GetSize().x
;
692 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
694 if (m_cursor
.IsSameAs(cursor
))
699 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
704 if ( ! wxWindowBase::SetCursor( cursor
) )
708 wxASSERT_MSG( m_cursor
.Ok(),
709 wxT("cursor must be valid after call to the base version"));
711 if ( GetPeer() != NULL
)
712 GetPeer()->SetCursor( m_cursor
);
718 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
720 #ifndef __WXUNIVERSAL__
721 menu
->SetInvokingWindow((wxWindow
*)this);
724 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
726 wxPoint mouse
= wxGetMousePosition();
732 ClientToScreen( &x
, &y
) ;
734 menu
->GetPeer()->PopUp(this, x
, y
);
735 menu
->SetInvokingWindow( NULL
);
738 // actually this shouldn't be called, because universal is having its own implementation
744 // ----------------------------------------------------------------------------
746 // ----------------------------------------------------------------------------
750 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
752 wxWindowBase::DoSetToolTip(tooltip
);
755 m_tooltip
->SetWindow(this);
760 void wxWindowMac::MacInvalidateBorders()
762 if ( m_peer
== NULL
)
765 bool vis
= IsShownOnScreen() ;
769 int outerBorder
= MacGetLeftBorderSize() ;
771 if ( m_peer
->NeedsFocusRect() )
774 if ( outerBorder
== 0 )
777 // now we know that we have something to do at all
781 m_peer
->GetSize( tw
, th
);
782 m_peer
->GetPosition( tx
, ty
);
784 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
785 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
786 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
787 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
790 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
791 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
792 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
793 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
797 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
799 // this is never called for a toplevel window, so we know we have a parent
800 int former_x
, former_y
, former_w
, former_h
;
802 // Get true coordinates of former position
803 DoGetPosition( &former_x
, &former_y
) ;
804 DoGetSize( &former_w
, &former_h
) ;
806 wxWindow
*parent
= GetParent();
809 wxPoint
pt(parent
->GetClientAreaOrigin());
814 int actualWidth
= width
;
815 int actualHeight
= height
;
820 // min and max sizes are only for sizers, not for explicit size setting
821 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
822 actualWidth
= m_minWidth
;
823 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
824 actualHeight
= m_minHeight
;
825 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
826 actualWidth
= m_maxWidth
;
827 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
828 actualHeight
= m_maxHeight
;
831 bool doMove
= false, doResize
= false ;
833 if ( actualX
!= former_x
|| actualY
!= former_y
)
836 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
839 if ( doMove
|| doResize
)
841 // as the borders are drawn outside the native control, we adjust now
843 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
844 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
845 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
847 if ( parent
&& !parent
->IsTopLevel() )
849 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
852 MacInvalidateBorders() ;
854 m_cachedClippedRectValid
= false ;
856 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
858 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
860 MacInvalidateBorders() ;
862 MacRepositionScrollBars() ;
865 wxPoint
point(actualX
, actualY
);
866 wxMoveEvent
event(point
, m_windowId
);
867 event
.SetEventObject(this);
868 HandleWindowEvent(event
) ;
873 MacRepositionScrollBars() ;
874 wxSize
size(actualWidth
, actualHeight
);
875 wxSizeEvent
event(size
, m_windowId
);
876 event
.SetEventObject(this);
877 HandleWindowEvent(event
);
882 wxSize
wxWindowMac::DoGetBestSize() const
884 if ( m_macIsUserPane
|| IsTopLevel() )
886 return wxWindowBase::DoGetBestSize() ;
892 m_peer
->GetBestRect(&r
);
894 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
905 else if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
911 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
918 // return wxWindowBase::DoGetBestSize() ;
922 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
923 MacGetRightBorderSize();
924 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
925 MacGetBottomBorderSize();
926 if ( bestHeight
< 10 )
929 return wxSize(bestWidth
, bestHeight
);
933 // set the size of the window: if the dimensions are positive, just use them,
934 // but if any of them is equal to -1, it means that we must find the value for
935 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
936 // which case -1 is a valid value for x and y)
938 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
939 // the width/height to best suit our contents, otherwise we reuse the current
941 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
943 // get the current size and position...
944 int currentX
, currentY
;
945 int currentW
, currentH
;
947 GetPosition(¤tX
, ¤tY
);
948 GetSize(¤tW
, ¤tH
);
950 // ... and don't do anything (avoiding flicker) if it's already ok
951 if ( x
== currentX
&& y
== currentY
&&
952 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
955 MacRepositionScrollBars() ; // we might have a real position shift
957 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
959 wxSizeEvent
event( wxSize(width
,height
), GetId() );
960 event
.SetEventObject( this );
961 HandleWindowEvent( event
);
967 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
969 if ( x
== wxDefaultCoord
)
971 if ( y
== wxDefaultCoord
)
975 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
977 wxSize size
= wxDefaultSize
;
978 if ( width
== wxDefaultCoord
)
980 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
982 size
= DoGetBestSize();
987 // just take the current one
992 if ( height
== wxDefaultCoord
)
994 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
996 if ( size
.x
== wxDefaultCoord
)
997 size
= DoGetBestSize();
998 // else: already called DoGetBestSize() above
1004 // just take the current one
1009 DoMoveWindow( x
, y
, width
, height
);
1012 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1014 int left
,top
,width
,height
;
1015 m_peer
->GetContentArea( left
, top
, width
, height
);
1016 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1019 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1021 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1023 int currentclientwidth
, currentclientheight
;
1024 int currentwidth
, currentheight
;
1026 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1027 GetSize( ¤twidth
, ¤theight
) ;
1029 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1030 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1034 void wxWindowMac::SetLabel(const wxString
& title
)
1036 if ( title
== m_label
)
1041 InvalidateBestSize();
1043 if ( m_peer
&& m_peer
->IsOk() )
1044 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1046 // do not trigger refreshes upon invisible and possible partly created objects
1047 if ( IsShownOnScreen() )
1051 wxString
wxWindowMac::GetLabel() const
1056 bool wxWindowMac::Show(bool show
)
1058 if ( !wxWindowBase::Show(show
) )
1062 m_peer
->SetVisibility( show
) ;
1067 void wxWindowMac::DoEnable(bool enable
)
1069 m_peer
->Enable( enable
) ;
1073 // status change notifications
1076 void wxWindowMac::MacVisibilityChanged()
1080 void wxWindowMac::MacHiliteChanged()
1084 void wxWindowMac::MacEnabledStateChanged()
1086 OnEnabled( m_peer
->IsEnabled() );
1090 // status queries on the inherited window's state
1093 bool wxWindowMac::MacIsReallyEnabled()
1095 return m_peer
->IsEnabled() ;
1098 bool wxWindowMac::MacIsReallyHilited()
1100 #if wxOSX_USE_CARBON
1101 return m_peer
->IsActive();
1103 return true; // TODO
1107 int wxWindowMac::GetCharHeight() const
1110 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1115 int wxWindowMac::GetCharWidth() const
1118 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1123 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1126 int *externalLeading
,
1127 const wxFont
*theFont
) const
1129 const wxFont
*fontToUse
= theFont
;
1133 tempFont
= GetFont();
1134 fontToUse
= &tempFont
;
1137 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1138 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1140 wxDouble h
, d
, e
, w
;
1141 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1145 if ( externalLeading
)
1146 *externalLeading
= (wxCoord
)(e
+0.5);
1148 *descent
= (wxCoord
)(d
+0.5);
1150 *x
= (wxCoord
)(w
+0.5);
1152 *y
= (wxCoord
)(h
+0.5);
1156 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1157 * we always intersect with the entire window, not only with the client area
1160 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1162 if ( m_peer
== NULL
)
1165 if ( !IsShownOnScreen() )
1168 m_peer
->SetNeedsDisplay( rect
) ;
1171 void wxWindowMac::DoFreeze()
1173 #if wxOSX_USE_CARBON
1174 if ( m_peer
&& m_peer
->IsOk() )
1175 m_peer
->SetDrawingEnabled( false ) ;
1179 void wxWindowMac::DoThaw()
1181 #if wxOSX_USE_CARBON
1182 if ( m_peer
&& m_peer
->IsOk() )
1184 m_peer
->SetDrawingEnabled( true ) ;
1185 m_peer
->InvalidateWithChildren() ;
1190 wxWindow
*wxGetActiveWindow()
1192 // actually this is a windows-only concept
1196 // Coordinates relative to the window
1197 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1199 // We really don't move the mouse programmatically under Mac.
1202 int wxWindowMac::GetScrollPos(int orient
) const
1205 if ( orient
== wxHORIZONTAL
)
1208 return m_hScrollBar
->GetThumbPosition() ;
1213 return m_vScrollBar
->GetThumbPosition() ;
1219 // This now returns the whole range, not just the number
1220 // of positions that we can scroll.
1221 int wxWindowMac::GetScrollRange(int orient
) const
1224 if ( orient
== wxHORIZONTAL
)
1227 return m_hScrollBar
->GetRange() ;
1232 return m_vScrollBar
->GetRange() ;
1238 int wxWindowMac::GetScrollThumb(int orient
) const
1241 if ( orient
== wxHORIZONTAL
)
1244 return m_hScrollBar
->GetThumbSize() ;
1249 return m_vScrollBar
->GetThumbSize() ;
1255 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1258 if ( orient
== wxHORIZONTAL
)
1261 m_hScrollBar
->SetThumbPosition( pos
) ;
1266 m_vScrollBar
->SetThumbPosition( pos
) ;
1272 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1274 bool needVisibilityUpdate
= false;
1276 if ( m_hScrollBarAlwaysShown
!= hflag
)
1278 m_hScrollBarAlwaysShown
= hflag
;
1279 needVisibilityUpdate
= true;
1282 if ( m_vScrollBarAlwaysShown
!= vflag
)
1284 m_vScrollBarAlwaysShown
= vflag
;
1285 needVisibilityUpdate
= true;
1288 if ( needVisibilityUpdate
)
1289 DoUpdateScrollbarVisibility();
1293 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1294 // our own window origin is at leftOrigin/rightOrigin
1297 void wxWindowMac::MacPaintGrowBox()
1303 if ( MacHasScrollBarCorner() )
1305 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1306 wxASSERT( cgContext
) ;
1310 m_peer
->GetSize( tw
, th
);
1311 m_peer
->GetPosition( tx
, ty
);
1313 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1316 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1317 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1318 CGContextSaveGState( cgContext
);
1320 if ( m_backgroundColour
.Ok() )
1322 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1326 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1328 CGContextFillRect( cgContext
, cgrect
);
1329 CGContextRestoreGState( cgContext
);
1334 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1339 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1341 // back to the surrounding frame rectangle
1344 m_peer
->GetSize( tw
, th
);
1345 m_peer
->GetPosition( tx
, ty
);
1347 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1349 #if wxOSX_USE_COCOA_OR_CARBON
1351 InsetRect( &rect
, -1 , -1 ) ;
1354 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1355 rect
.bottom
- rect
.top
) ;
1357 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1358 wxASSERT( cgContext
) ;
1360 if ( m_peer
->NeedsFrame() )
1362 HIThemeFrameDrawInfo info
;
1363 memset( &info
, 0 , sizeof(info
) ) ;
1367 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1368 info
.isFocused
= hasFocus
;
1370 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1372 info
.kind
= kHIThemeFrameTextFieldSquare
;
1373 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1375 else if ( HasFlag(wxSIMPLE_BORDER
) )
1377 info
.kind
= kHIThemeFrameListBox
;
1378 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1384 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1387 #endif // wxOSX_USE_COCOA_OR_CARBON
1390 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1393 if ( child
== m_hScrollBar
)
1394 m_hScrollBar
= NULL
;
1395 if ( child
== m_vScrollBar
)
1396 m_vScrollBar
= NULL
;
1398 wxWindowBase::RemoveChild( child
) ;
1401 void wxWindowMac::DoUpdateScrollbarVisibility()
1404 bool triggerSizeEvent
= false;
1408 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1410 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1412 m_hScrollBar
->Show( showHScrollBar
);
1413 triggerSizeEvent
= true;
1419 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1421 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1423 m_vScrollBar
->Show( showVScrollBar
) ;
1424 triggerSizeEvent
= true;
1428 MacRepositionScrollBars() ;
1429 if ( triggerSizeEvent
)
1431 wxSizeEvent
event(GetSize(), m_windowId
);
1432 event
.SetEventObject(this);
1433 HandleWindowEvent(event
);
1438 // New function that will replace some of the above.
1439 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1440 int range
, bool refresh
)
1443 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1444 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1445 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1446 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1448 DoUpdateScrollbarVisibility();
1452 // Does a physical scroll
1453 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1455 if ( dx
== 0 && dy
== 0 )
1458 int width
, height
;
1459 GetClientSize( &width
, &height
) ;
1462 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1464 scrollrect
.Intersect( *rect
) ;
1465 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1466 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1468 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1473 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1475 child
= node
->GetData();
1479 if (child
== m_vScrollBar
)
1481 if (child
== m_hScrollBar
)
1484 if (child
->IsTopLevel())
1487 child
->GetPosition( &x
, &y
);
1488 child
->GetSize( &w
, &h
);
1491 wxRect
rc( x
, y
, w
, h
);
1492 if (rect
->Intersects( rc
))
1493 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1497 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1502 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1505 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1507 wxScrollWinEvent wevent
;
1508 wevent
.SetPosition(event
.GetPosition());
1509 wevent
.SetOrientation(event
.GetOrientation());
1510 wevent
.SetEventObject(this);
1512 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1513 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1514 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1515 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1516 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1517 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1518 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1519 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1520 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1521 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1522 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1523 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1524 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1525 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1526 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1527 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1529 HandleWindowEvent(wevent
);
1534 wxWindow
*wxWindowBase::DoFindFocus()
1536 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1539 void wxWindowMac::OnInternalIdle()
1541 // This calls the UI-update mechanism (querying windows for
1542 // menu/toolbar/control state information)
1543 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1544 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1547 // Raise the window to the top of the Z order
1548 void wxWindowMac::Raise()
1553 // Lower the window to the bottom of the Z order
1554 void wxWindowMac::Lower()
1559 // static wxWindow *gs_lastWhich = NULL;
1561 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1563 // first trigger a set cursor event
1565 wxPoint clientorigin
= GetClientAreaOrigin() ;
1566 wxSize clientsize
= GetClientSize() ;
1568 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1570 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1572 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1573 if ( processedEvtSetCursor
&& event
.HasCursor() )
1575 cursor
= event
.GetCursor() ;
1579 // the test for processedEvtSetCursor is here to prevent using m_cursor
1580 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1581 // it - this is a way to say that our cursor shouldn't be used for this
1583 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1586 if ( !wxIsBusy() && !GetParent() )
1587 cursor
= *wxSTANDARD_CURSOR
;
1591 cursor
.MacInstall() ;
1594 return cursor
.Ok() ;
1597 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1601 return m_tooltip
->GetTip() ;
1604 return wxEmptyString
;
1607 void wxWindowMac::ClearBackground()
1613 void wxWindowMac::Update()
1615 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1620 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1622 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1626 if ( iter
->IsTopLevel() )
1628 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1632 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1637 iter
= iter
->GetParent() ;
1643 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1645 MacUpdateClippedRects() ;
1647 return m_cachedClippedClientRect
;
1650 const wxRect
& wxWindowMac::MacGetClippedRect() const
1652 MacUpdateClippedRects() ;
1654 return m_cachedClippedRect
;
1657 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1659 MacUpdateClippedRects() ;
1661 return m_cachedClippedRectWithOuterStructure
;
1664 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1666 static wxRegion emptyrgn
;
1668 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1670 MacUpdateClippedRects() ;
1671 if ( includeOuterStructures
)
1672 return m_cachedClippedRegionWithOuterStructure
;
1674 return m_cachedClippedRegion
;
1682 void wxWindowMac::MacUpdateClippedRects() const
1684 #if wxOSX_USE_CARBON
1685 if ( m_cachedClippedRectValid
)
1688 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1689 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1690 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1691 // to add focus borders everywhere
1693 Rect rIncludingOuterStructures
;
1697 m_peer
->GetSize( tw
, th
);
1698 m_peer
->GetPosition( tx
, ty
);
1700 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1702 r
.left
-= MacGetLeftBorderSize() ;
1703 r
.top
-= MacGetTopBorderSize() ;
1704 r
.bottom
+= MacGetBottomBorderSize() ;
1705 r
.right
+= MacGetRightBorderSize() ;
1712 rIncludingOuterStructures
= r
;
1713 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1715 wxRect cl
= GetClientRect() ;
1716 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1720 const wxWindow
* child
= (wxWindow
*) this ;
1721 const wxWindow
* parent
= NULL
;
1723 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1725 if ( parent
->MacIsChildOfClientArea(child
) )
1727 size
= parent
->GetClientSize() ;
1728 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1734 // this will be true for scrollbars, toolbars etc.
1735 size
= parent
->GetSize() ;
1736 y
= parent
->MacGetTopBorderSize() ;
1737 x
= parent
->MacGetLeftBorderSize() ;
1738 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1739 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1742 parent
->MacWindowToRootWindow( &x
, &y
) ;
1743 MacRootWindowToWindow( &x
, &y
) ;
1745 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1747 // the wxwindow and client rects will always be clipped
1748 SectRect( &r
, &rparent
, &r
) ;
1749 SectRect( &rClient
, &rparent
, &rClient
) ;
1751 // the structure only at 'hard' borders
1752 if ( parent
->MacClipChildren() ||
1753 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1755 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1761 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1762 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1763 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1764 m_cachedClippedRectWithOuterStructure
= wxRect(
1765 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1766 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1767 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1769 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1770 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1771 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1773 m_cachedClippedRectValid
= true ;
1778 This function must not change the updatergn !
1780 bool wxWindowMac::MacDoRedraw( long time
)
1782 bool handled
= false ;
1784 wxRegion formerUpdateRgn
= m_updateRegion
;
1785 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1787 const wxRect clientRect
= GetClientRect();
1789 clientUpdateRgn
.Intersect(clientRect
);
1791 // first send an erase event to the entire update area
1792 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1795 case wxBG_STYLE_ERASE
:
1796 case wxBG_STYLE_SYSTEM
:
1798 // for the toplevel window this really is the entire area for
1799 // all the others only their client area, otherwise they might
1800 // be drawing with full alpha and eg put blue into the grow-box
1801 // area of a scrolled window (scroll sample)
1802 wxWindowDC
dc(this);
1804 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1806 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1808 if ( bgStyle
== wxBG_STYLE_ERASE
)
1810 wxEraseEvent
eevent( GetId(), &dc
);
1811 eevent
.SetEventObject( this );
1812 if ( ProcessWindowEvent( eevent
) )
1818 dc
.SetBackground(GetBackgroundColour());
1824 case wxBG_STYLE_PAINT
:
1825 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1826 // entire window client area
1830 wxFAIL_MSG( "unsupported background style" );
1835 // calculate a client-origin version of the update rgn and set
1836 // m_updateRegion to that
1837 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1838 m_updateRegion
= clientUpdateRgn
;
1840 if ( !m_updateRegion
.Empty() )
1842 // paint the window itself
1844 wxPaintEvent
event(GetId());
1845 event
.SetTimestamp(time
);
1846 event
.SetEventObject(this);
1847 handled
= HandleWindowEvent(event
);
1850 m_updateRegion
= formerUpdateRgn
;
1854 void wxWindowMac::MacPaintChildrenBorders()
1856 // now we cannot rely on having its borders drawn by a window itself, as it does not
1857 // get the updateRgn wide enough to always do so, so we do it from the parent
1858 // this would also be the place to draw any custom backgrounds for native controls
1859 // in Composited windowing
1860 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1864 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1866 child
= node
->GetData();
1870 if (child
== m_vScrollBar
)
1872 if (child
== m_hScrollBar
)
1875 if (child
->IsTopLevel())
1877 if (!child
->IsShown())
1880 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1882 child
->GetPosition( &x
, &y
);
1883 child
->GetSize( &w
, &h
);
1885 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
1887 // paint custom borders
1888 wxNcPaintEvent
eventNc( child
->GetId() );
1889 eventNc
.SetEventObject( child
);
1890 if ( !child
->HandleWindowEvent( eventNc
) )
1892 child
->MacPaintBorders(0, 0) ;
1899 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1901 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1902 return tlw
? tlw
->GetWXWindow() : NULL
;
1905 bool wxWindowMac::MacHasScrollBarCorner() const
1908 /* Returns whether the scroll bars in a wxScrolledWindow should be
1909 * shortened. Scroll bars should be shortened if either:
1911 * - both scroll bars are visible, or
1913 * - there is a resize box in the parent frame's corner and this
1914 * window shares the bottom and right edge with the parent
1918 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1921 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1922 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1924 // Both scroll bars visible
1929 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1931 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1933 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1936 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1938 // Parent frame has resize handle
1939 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1941 // Note: allow for some wiggle room here as wxMac's
1942 // window rect calculations seem to be imprecise
1943 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1944 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1946 // Parent frame has resize handle and shares
1947 // right bottom corner
1952 // Parent frame has resize handle but doesn't
1953 // share right bottom corner
1959 // Parent frame doesn't have resize handle
1965 // No parent frame found
1973 void wxWindowMac::MacCreateScrollBars( long style
)
1976 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1978 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1980 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1981 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1983 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
1986 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
1988 GetClientSize( &width
, &height
) ;
1990 wxPoint
vPoint(width
- scrlsize
, 0) ;
1991 wxSize
vSize(scrlsize
, height
- adjust
) ;
1992 wxPoint
hPoint(0, height
- scrlsize
) ;
1993 wxSize
hSize(width
- adjust
, scrlsize
) ;
1995 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
1996 if ( style
& wxVSCROLL
)
1998 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
1999 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2002 if ( style
& wxHSCROLL
)
2004 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2005 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2009 // because the create does not take into account the client area origin
2010 // we might have a real position shift
2011 MacRepositionScrollBars() ;
2015 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2017 bool result
= ((child
== NULL
)
2019 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
))
2026 void wxWindowMac::MacRepositionScrollBars()
2029 if ( !m_hScrollBar
&& !m_vScrollBar
)
2032 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2033 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2035 // get real client area
2037 GetSize( &width
, &height
);
2039 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2040 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2042 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2043 wxSize
vSize( scrlsize
, height
- adjust
) ;
2044 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2045 wxSize
hSize( width
- adjust
, scrlsize
) ;
2048 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2050 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2054 bool wxWindowMac::AcceptsFocus() const
2056 if ( MacIsUserPane() )
2057 return wxWindowBase::AcceptsFocus();
2059 return m_peer
->CanFocus();
2062 void wxWindowMac::MacSuperChangedPosition()
2064 // only window-absolute structures have to be moved i.e. controls
2066 m_cachedClippedRectValid
= false ;
2069 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2072 child
= node
->GetData();
2073 child
->MacSuperChangedPosition() ;
2075 node
= node
->GetNext();
2079 void wxWindowMac::MacTopLevelWindowChangedPosition()
2081 // only screen-absolute structures have to be moved i.e. glcanvas
2084 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2087 child
= node
->GetData();
2088 child
->MacTopLevelWindowChangedPosition() ;
2090 node
= node
->GetNext();
2094 long wxWindowMac::MacGetLeftBorderSize() const
2101 if ( m_peer
&& m_peer
->NeedsFrame() )
2103 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2105 #if wxOSX_USE_COCOA_OR_CARBON
2106 // this metric is only the 'outset' outside the simple frame rect
2107 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2113 else if (HasFlag(wxSIMPLE_BORDER
))
2115 #if wxOSX_USE_COCOA_OR_CARBON
2116 // this metric is only the 'outset' outside the simple frame rect
2117 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2128 long wxWindowMac::MacGetRightBorderSize() const
2130 // they are all symmetric in mac themes
2131 return MacGetLeftBorderSize() ;
2134 long wxWindowMac::MacGetTopBorderSize() const
2136 // they are all symmetric in mac themes
2137 return MacGetLeftBorderSize() ;
2140 long wxWindowMac::MacGetBottomBorderSize() const
2142 // they are all symmetric in mac themes
2143 return MacGetLeftBorderSize() ;
2146 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2148 return style
& ~wxBORDER_MASK
;
2151 // Find the wxWindowMac at the current mouse position, returning the mouse
2153 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2155 pt
= wxGetMousePosition();
2156 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2158 return (wxWindow
*) found
;
2161 // Get the current mouse position.
2162 wxPoint
wxGetMousePosition()
2166 wxGetMousePosition( &x
, &y
);
2168 return wxPoint(x
, y
);
2171 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2173 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2175 // copied from wxGTK : CS
2176 // VZ: shouldn't we move this to base class then?
2178 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2181 // (a) it's a command event and so is propagated to the parent
2182 // (b) under MSW it can be generated from kbd too
2183 // (c) it uses screen coords (because of (a))
2184 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2186 this->ClientToScreen(event
.GetPosition()));
2187 evtCtx
.SetEventObject(this);
2188 if ( ! HandleWindowEvent(evtCtx
) )
2197 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2201 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2205 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2206 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2211 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2216 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2218 #if wxOSX_USE_COCOA_OR_CARBON
2219 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2222 return eventNotHandledErr
;
2228 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2230 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2231 if ( !wxWindowBase::Reparent(newParent
) )
2234 m_peer
->RemoveFromParent();
2235 m_peer
->Embed( GetParent()->GetPeer() );
2239 bool wxWindowMac::SetTransparent(wxByte alpha
)
2241 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2243 if ( alpha
!= m_macAlpha
)
2245 m_macAlpha
= alpha
;
2252 bool wxWindowMac::CanSetTransparent()
2257 wxByte
wxWindowMac::GetTransparent() const
2262 bool wxWindowMac::IsShownOnScreen() const
2264 if ( m_peer
&& m_peer
->IsOk() )
2266 bool peerVis
= m_peer
->IsVisible();
2267 bool wxVis
= wxWindowBase::IsShownOnScreen();
2268 if( peerVis
!= wxVis
)
2270 // CS : put a breakpoint here to investigate differences
2271 // between native an wx visibilities
2272 // the only place where I've encountered them until now
2273 // are the hiding/showing sequences where the vis-changed event is
2274 // first sent to the innermost control, while wx does things
2275 // from the outmost control
2276 wxVis
= wxWindowBase::IsShownOnScreen();
2280 return m_peer
->IsVisible();
2282 return wxWindowBase::IsShownOnScreen();
2285 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2287 bool handled
= HandleWindowEvent( event
) ;
2288 if ( handled
&& event
.GetSkipped() )
2292 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2294 wxWindow
*ancestor
= this;
2297 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2300 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2302 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2303 handled
= handler
->ProcessEvent( command_event
);
2307 // accelerators can also be used with buttons, try them too
2308 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2309 handled
= handler
->ProcessEvent( command_event
);
2315 if (ancestor
->IsTopLevel())
2318 ancestor
= ancestor
->GetParent();
2321 #endif // wxUSE_ACCEL
2330 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2332 static MacControlMap wxWinMacControlList
;
2334 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2336 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2338 return impl
->GetWXPeer();
2343 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2345 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2347 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2350 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2352 // adding NULL ControlRef is (first) surely a result of an error and
2353 // (secondly) breaks native event processing
2354 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2356 wxWinMacControlList
[inControl
] = impl
;
2359 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2361 // iterate over all the elements in the class
2362 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2363 // we should go on...
2369 MacControlMap::iterator it
;
2370 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2372 if ( it
->second
== impl
)
2374 wxWinMacControlList
.erase(it
);
2382 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2384 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2387 m_isRootControl
= isRootControl
;
2391 wxWidgetImpl::wxWidgetImpl()
2396 wxWidgetImpl::~wxWidgetImpl()
2400 void wxWidgetImpl::Init()
2402 m_isRootControl
= false;
2404 m_needsFocusRect
= false;
2405 m_needsFrame
= true;
2408 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2410 m_needsFocusRect
= needs
;
2413 bool wxWidgetImpl::NeedsFocusRect() const
2415 return m_needsFocusRect
;
2418 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2420 m_needsFrame
= needs
;
2423 bool wxWidgetImpl::NeedsFrame() const
2425 return m_needsFrame
;