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"
71 #include <Carbon/Carbon.h>
74 #define MAC_SCROLLBAR_SIZE 15
75 #define MAC_SMALL_SCROLLBAR_SIZE 11
79 #ifdef __WXUNIVERSAL__
80 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
82 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
85 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
89 #define wxMAC_DEBUG_REDRAW 0
90 #ifndef wxMAC_DEBUG_REDRAW
91 #define wxMAC_DEBUG_REDRAW 0
94 // ===========================================================================
96 // ===========================================================================
98 // ----------------------------------------------------------------------------
99 // constructors and such
100 // ----------------------------------------------------------------------------
102 wxWindowMac::wxWindowMac()
107 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
112 const wxString
& name
)
115 Create(parent
, id
, pos
, size
, style
, name
);
118 void wxWindowMac::Init()
122 m_cgContextRef
= NULL
;
124 // as all windows are created with WS_VISIBLE style...
127 m_hScrollBar
= NULL
;
128 m_vScrollBar
= NULL
;
129 m_hScrollBarAlwaysShown
= false;
130 m_vScrollBarAlwaysShown
= false;
132 m_macIsUserPane
= true;
133 m_clipChildren
= false ;
134 m_cachedClippedRectValid
= false ;
137 wxWindowMac::~wxWindowMac()
141 MacInvalidateBorders() ;
143 #ifndef __WXUNIVERSAL__
144 // VS: make sure there's no wxFrame with last focus set to us:
145 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
147 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
150 if ( frame
->GetLastFocus() == this )
151 frame
->SetLastFocus(NULL
);
157 // destroy children before destroying this window itself
160 // wxRemoveMacControlAssociation( this ) ;
161 // If we delete an item, we should initialize the parent panel,
162 // because it could now be invalid.
163 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
166 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
167 tlw
->SetDefaultItem(NULL
);
170 if ( g_MacLastWindow
== this )
171 g_MacLastWindow
= NULL
;
173 #ifndef __WXUNIVERSAL__
174 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
177 if ( frame
->GetLastFocus() == this )
178 frame
->SetLastFocus( NULL
) ;
182 // delete our drop target if we've got one
183 #if wxUSE_DRAG_AND_DROP
184 if ( m_dropTarget
!= NULL
)
194 WXWidget
wxWindowMac::GetHandle() const
197 return (WXWidget
) m_peer
->GetWXWidget() ;
201 // ---------------------------------------------------------------------------
202 // Utility Routines to move between different coordinate systems
203 // ---------------------------------------------------------------------------
206 * Right now we have the following setup :
207 * a border that is not part of the native control is always outside the
208 * control's border (otherwise we loose all native intelligence, future ways
209 * may be to have a second embedding control responsible for drawing borders
210 * and backgrounds eventually)
211 * so all this border calculations have to be taken into account when calling
212 * native methods or getting native oriented data
213 * so we have three coordinate systems here
214 * wx client coordinates
215 * wx window coordinates (including window frames)
223 bool wxWindowMac::Create(wxWindowMac
*parent
,
228 const wxString
& name
)
230 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
232 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
235 m_windowVariant
= parent
->GetWindowVariant() ;
237 if ( m_macIsUserPane
)
239 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
240 MacPostControlCreate(pos
, size
) ;
243 #ifndef __WXUNIVERSAL__
244 // Don't give scrollbars to wxControls unless they ask for them
245 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
246 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
248 MacCreateScrollBars( style
) ;
252 wxWindowCreateEvent
event((wxWindow
*)this);
253 GetEventHandler()->AddPendingEvent(event
);
258 void wxWindowMac::MacChildAdded()
261 m_vScrollBar
->Raise() ;
263 m_hScrollBar
->Raise() ;
266 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
268 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
270 GetParent()->AddChild( this );
272 m_peer
->InstallEventHandler();
273 m_peer
->Embed(GetParent()->GetPeer());
275 GetParent()->MacChildAdded() ;
277 // adjust font, controlsize etc
278 DoSetWindowVariant( m_windowVariant
) ;
280 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
282 // for controls we want to use best size for wxDefaultSize params )
283 if ( !m_macIsUserPane
)
284 SetInitialSize(size
);
286 SetCursor( *wxSTANDARD_CURSOR
) ;
289 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
291 // Don't assert, in case we set the window variant before
292 // the window is created
293 // wxASSERT( m_peer->Ok() ) ;
295 m_windowVariant
= variant
;
297 if (m_peer
== NULL
|| !m_peer
->IsOk())
300 m_peer
->SetControlSize( variant
);
304 // we will get that from the settings later
305 // and make this NORMAL later, but first
306 // we have a few calculations that we must fix
310 case wxWINDOW_VARIANT_NORMAL
:
311 size
= kControlSizeNormal
;
314 case wxWINDOW_VARIANT_SMALL
:
315 size
= kControlSizeSmall
;
318 case wxWINDOW_VARIANT_MINI
:
319 // not always defined in the headers
323 case wxWINDOW_VARIANT_LARGE
:
324 size
= kControlSizeLarge
;
328 wxFAIL_MSG(_T("unexpected window variant"));
331 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
336 wxOSXSystemFont systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
340 case wxWINDOW_VARIANT_NORMAL
:
341 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
344 case wxWINDOW_VARIANT_SMALL
:
345 systemFont
= wxOSX_SYSTEM_FONT_SMALL
;
348 case wxWINDOW_VARIANT_MINI
:
349 systemFont
= wxOSX_SYSTEM_FONT_MINI
;
352 case wxWINDOW_VARIANT_LARGE
:
353 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
357 wxFAIL_MSG(_T("unexpected window variant"));
361 font
.CreateSystemFont( systemFont
) ;
366 void wxWindowMac::MacUpdateControlFont()
369 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
371 // do not trigger refreshes upon invisible and possible partly created objects
372 if ( IsShownOnScreen() )
376 bool wxWindowMac::SetFont(const wxFont
& font
)
378 bool retval
= wxWindowBase::SetFont( font
);
380 MacUpdateControlFont() ;
385 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
387 bool retval
= wxWindowBase::SetForegroundColour( col
);
390 MacUpdateControlFont();
395 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
397 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
401 m_peer
->SetBackgroundColour( col
) ;
406 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
408 while (w
&& !w
->IsTopLevel())
417 void wxWindowMac::SetFocus()
419 if ( !AcceptsFocus() )
422 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
425 wxWindow
* former
= FindFocus() ;
426 if ( former
== this )
432 void wxWindowMac::DoCaptureMouse()
434 wxApp::s_captureWindow
= (wxWindow
*) this ;
435 m_peer
->CaptureMouse() ;
438 wxWindow
* wxWindowBase::GetCapture()
440 return wxApp::s_captureWindow
;
443 void wxWindowMac::DoReleaseMouse()
445 wxApp::s_captureWindow
= NULL
;
447 m_peer
->ReleaseMouse() ;
450 #if wxUSE_DRAG_AND_DROP
452 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
456 m_dropTarget
= pDropTarget
;
457 if ( m_dropTarget
!= NULL
)
465 // Old-style File Manager Drag & Drop
466 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
471 // From a wx position / size calculate the appropriate size of the native control
473 bool wxWindowMac::MacGetBoundsForControl(
477 int& w
, int& h
, bool adjustOrigin
) const
479 // the desired size, minus the border pixels gives the correct size of the control
483 w
= WidthDefault( size
.x
);
484 h
= HeightDefault( size
.y
);
486 x
+= MacGetLeftBorderSize() ;
487 y
+= MacGetTopBorderSize() ;
488 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
489 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
492 AdjustForParentClientOrigin( x
, y
) ;
494 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
495 if ( GetParent() && !GetParent()->IsTopLevel() )
497 x
-= GetParent()->MacGetLeftBorderSize() ;
498 y
-= GetParent()->MacGetTopBorderSize() ;
504 // Get window size (not client size)
505 void wxWindowMac::DoGetSize(int *x
, int *y
) const
508 m_peer
->GetSize( width
, height
);
511 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
513 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
516 // get the position of the bounds of this window in client coordinates of its parent
517 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
521 m_peer
->GetPosition( x1
, y1
) ;
523 // get the wx window position from the native one
524 x1
-= MacGetLeftBorderSize() ;
525 y1
-= MacGetTopBorderSize() ;
529 wxWindow
*parent
= GetParent();
532 // we must first adjust it to be in window coordinates of the parent,
533 // as otherwise it gets lost by the ClientAreaOrigin fix
534 x1
+= parent
->MacGetLeftBorderSize() ;
535 y1
+= parent
->MacGetTopBorderSize() ;
537 // and now to client coordinates
538 wxPoint
pt(parent
->GetClientAreaOrigin());
550 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
552 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
553 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
554 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
555 MacRootWindowToWindow( x
, y
) ;
557 wxPoint origin
= GetClientAreaOrigin() ;
564 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
566 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
567 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
569 wxPoint origin
= GetClientAreaOrigin() ;
575 MacWindowToRootWindow( x
, y
) ;
576 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
579 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
581 wxPoint origin
= GetClientAreaOrigin() ;
587 MacWindowToRootWindow( x
, y
) ;
590 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
601 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
604 pt
.x
-= MacGetLeftBorderSize() ;
605 pt
.y
-= MacGetTopBorderSize() ;
606 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
616 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
627 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
630 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
631 pt
.x
+= MacGetLeftBorderSize() ;
632 pt
.y
+= MacGetTopBorderSize() ;
642 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
644 wxSize sizeTotal
= size
;
646 int innerwidth
, innerheight
;
648 int outerwidth
, outerheight
;
650 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
651 m_peer
->GetSize( outerwidth
, outerheight
);
653 sizeTotal
.x
+= outerwidth
-innerwidth
;
654 sizeTotal
.y
+= outerheight
-innerheight
;
656 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
657 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
662 // Get size *available for subwindows* i.e. excluding menu bar etc.
663 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
669 m_peer
->GetContentArea( left
, top
, ww
, hh
);
671 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
672 hh
-= m_hScrollBar
->GetSize().y
;
674 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
675 ww
-= m_vScrollBar
->GetSize().x
;
683 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
685 if (m_cursor
.IsSameAs(cursor
))
690 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
695 if ( ! wxWindowBase::SetCursor( cursor
) )
699 wxASSERT_MSG( m_cursor
.Ok(),
700 wxT("cursor must be valid after call to the base version"));
702 if ( GetPeer() != NULL
)
703 GetPeer()->SetCursor( m_cursor
);
709 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
711 #ifndef __WXUNIVERSAL__
712 menu
->SetInvokingWindow((wxWindow
*)this);
715 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
717 wxPoint mouse
= wxGetMousePosition();
723 ClientToScreen( &x
, &y
) ;
725 menu
->GetPeer()->PopUp(this, x
, y
);
726 menu
->SetInvokingWindow( NULL
);
729 // actually this shouldn't be called, because universal is having its own implementation
735 // ----------------------------------------------------------------------------
737 // ----------------------------------------------------------------------------
741 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
743 wxWindowBase::DoSetToolTip(tooltip
);
746 m_tooltip
->SetWindow(this);
751 void wxWindowMac::MacInvalidateBorders()
753 if ( m_peer
== NULL
)
756 bool vis
= IsShownOnScreen() ;
760 int outerBorder
= MacGetLeftBorderSize() ;
762 if ( m_peer
->NeedsFocusRect() )
765 if ( outerBorder
== 0 )
768 // now we know that we have something to do at all
772 m_peer
->GetSize( tw
, th
);
773 m_peer
->GetPosition( tx
, ty
);
775 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
776 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
777 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
778 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
781 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
782 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
783 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
784 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
788 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
790 // this is never called for a toplevel window, so we know we have a parent
791 int former_x
, former_y
, former_w
, former_h
;
793 // Get true coordinates of former position
794 DoGetPosition( &former_x
, &former_y
) ;
795 DoGetSize( &former_w
, &former_h
) ;
797 wxWindow
*parent
= GetParent();
800 wxPoint
pt(parent
->GetClientAreaOrigin());
805 int actualWidth
= width
;
806 int actualHeight
= height
;
811 // min and max sizes are only for sizers, not for explicit size setting
812 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
813 actualWidth
= m_minWidth
;
814 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
815 actualHeight
= m_minHeight
;
816 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
817 actualWidth
= m_maxWidth
;
818 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
819 actualHeight
= m_maxHeight
;
822 bool doMove
= false, doResize
= false ;
824 if ( actualX
!= former_x
|| actualY
!= former_y
)
827 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
830 if ( doMove
|| doResize
)
832 // as the borders are drawn outside the native control, we adjust now
834 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
835 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
836 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
838 if ( parent
&& !parent
->IsTopLevel() )
840 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
843 MacInvalidateBorders() ;
845 m_cachedClippedRectValid
= false ;
847 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
849 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
851 MacInvalidateBorders() ;
853 MacRepositionScrollBars() ;
856 wxPoint
point(actualX
, actualY
);
857 wxMoveEvent
event(point
, m_windowId
);
858 event
.SetEventObject(this);
859 HandleWindowEvent(event
) ;
864 MacRepositionScrollBars() ;
865 wxSize
size(actualWidth
, actualHeight
);
866 wxSizeEvent
event(size
, m_windowId
);
867 event
.SetEventObject(this);
868 HandleWindowEvent(event
);
873 wxSize
wxWindowMac::DoGetBestSize() const
875 if ( m_macIsUserPane
|| IsTopLevel() )
877 return wxWindowBase::DoGetBestSize() ;
883 m_peer
->GetBestRect(&r
);
885 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
892 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
897 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
904 // return wxWindowBase::DoGetBestSize() ;
908 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
909 MacGetRightBorderSize();
910 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
911 MacGetBottomBorderSize();
912 if ( bestHeight
< 10 )
915 return wxSize(bestWidth
, bestHeight
);
919 // set the size of the window: if the dimensions are positive, just use them,
920 // but if any of them is equal to -1, it means that we must find the value for
921 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
922 // which case -1 is a valid value for x and y)
924 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
925 // the width/height to best suit our contents, otherwise we reuse the current
927 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
929 // get the current size and position...
930 int currentX
, currentY
;
931 int currentW
, currentH
;
933 GetPosition(¤tX
, ¤tY
);
934 GetSize(¤tW
, ¤tH
);
936 // ... and don't do anything (avoiding flicker) if it's already ok
937 if ( x
== currentX
&& y
== currentY
&&
938 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
941 MacRepositionScrollBars() ; // we might have a real position shift
943 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
945 wxSizeEvent
event( wxSize(width
,height
), GetId() );
946 event
.SetEventObject( this );
947 HandleWindowEvent( event
);
953 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
955 if ( x
== wxDefaultCoord
)
957 if ( y
== wxDefaultCoord
)
961 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
963 wxSize size
= wxDefaultSize
;
964 if ( width
== wxDefaultCoord
)
966 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
968 size
= DoGetBestSize();
973 // just take the current one
978 if ( height
== wxDefaultCoord
)
980 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
982 if ( size
.x
== wxDefaultCoord
)
983 size
= DoGetBestSize();
984 // else: already called DoGetBestSize() above
990 // just take the current one
995 DoMoveWindow( x
, y
, width
, height
);
998 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1000 int left
,top
,width
,height
;
1001 m_peer
->GetContentArea( left
, top
, width
, height
);
1002 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1005 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1007 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1009 int currentclientwidth
, currentclientheight
;
1010 int currentwidth
, currentheight
;
1012 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1013 GetSize( ¤twidth
, ¤theight
) ;
1015 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1016 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1020 void wxWindowMac::SetLabel(const wxString
& title
)
1022 if ( title
== m_label
)
1027 InvalidateBestSize();
1029 if ( m_peer
&& m_peer
->IsOk() )
1030 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1032 // do not trigger refreshes upon invisible and possible partly created objects
1033 if ( IsShownOnScreen() )
1037 wxString
wxWindowMac::GetLabel() const
1042 bool wxWindowMac::Show(bool show
)
1044 if ( !wxWindowBase::Show(show
) )
1048 m_peer
->SetVisibility( show
) ;
1053 void wxWindowMac::DoEnable(bool enable
)
1055 m_peer
->Enable( enable
) ;
1059 // status change notifications
1062 void wxWindowMac::MacVisibilityChanged()
1066 void wxWindowMac::MacHiliteChanged()
1070 void wxWindowMac::MacEnabledStateChanged()
1072 OnEnabled( m_peer
->IsEnabled() );
1076 // status queries on the inherited window's state
1079 bool wxWindowMac::MacIsReallyEnabled()
1081 return m_peer
->IsEnabled() ;
1084 bool wxWindowMac::MacIsReallyHilited()
1086 #if wxOSX_USE_CARBON
1087 return m_peer
->IsActive();
1089 return true; // TODO
1093 int wxWindowMac::GetCharHeight() const
1096 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1101 int wxWindowMac::GetCharWidth() const
1104 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1109 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1112 int *externalLeading
,
1113 const wxFont
*theFont
) const
1115 const wxFont
*fontToUse
= theFont
;
1119 tempFont
= GetFont();
1120 fontToUse
= &tempFont
;
1123 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1124 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1126 wxDouble h
, d
, e
, w
;
1127 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1131 if ( externalLeading
)
1132 *externalLeading
= (wxCoord
)(e
+0.5);
1134 *descent
= (wxCoord
)(d
+0.5);
1136 *x
= (wxCoord
)(w
+0.5);
1138 *y
= (wxCoord
)(h
+0.5);
1142 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1143 * we always intersect with the entire window, not only with the client area
1146 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1148 if ( m_peer
== NULL
)
1151 if ( !IsShownOnScreen() )
1154 m_peer
->SetNeedsDisplay( rect
) ;
1157 void wxWindowMac::DoFreeze()
1159 #if wxOSX_USE_CARBON
1160 if ( m_peer
&& m_peer
->IsOk() )
1161 m_peer
->SetDrawingEnabled( false ) ;
1165 void wxWindowMac::DoThaw()
1167 #if wxOSX_USE_CARBON
1168 if ( m_peer
&& m_peer
->IsOk() )
1170 m_peer
->SetDrawingEnabled( true ) ;
1171 m_peer
->InvalidateWithChildren() ;
1176 wxWindow
*wxGetActiveWindow()
1178 // actually this is a windows-only concept
1182 // Coordinates relative to the window
1183 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1185 // We really don't move the mouse programmatically under Mac.
1188 int wxWindowMac::GetScrollPos(int orient
) const
1190 if ( orient
== wxHORIZONTAL
)
1193 return m_hScrollBar
->GetThumbPosition() ;
1198 return m_vScrollBar
->GetThumbPosition() ;
1204 // This now returns the whole range, not just the number
1205 // of positions that we can scroll.
1206 int wxWindowMac::GetScrollRange(int orient
) const
1208 if ( orient
== wxHORIZONTAL
)
1211 return m_hScrollBar
->GetRange() ;
1216 return m_vScrollBar
->GetRange() ;
1222 int wxWindowMac::GetScrollThumb(int orient
) const
1224 if ( orient
== wxHORIZONTAL
)
1227 return m_hScrollBar
->GetThumbSize() ;
1232 return m_vScrollBar
->GetThumbSize() ;
1238 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1240 if ( orient
== wxHORIZONTAL
)
1243 m_hScrollBar
->SetThumbPosition( pos
) ;
1248 m_vScrollBar
->SetThumbPosition( pos
) ;
1253 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1255 bool needVisibilityUpdate
= false;
1257 if ( m_hScrollBarAlwaysShown
!= hflag
)
1259 m_hScrollBarAlwaysShown
= hflag
;
1260 needVisibilityUpdate
= true;
1263 if ( m_vScrollBarAlwaysShown
!= vflag
)
1265 m_vScrollBarAlwaysShown
= vflag
;
1266 needVisibilityUpdate
= true;
1269 if ( needVisibilityUpdate
)
1270 DoUpdateScrollbarVisibility();
1274 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1275 // our own window origin is at leftOrigin/rightOrigin
1278 void wxWindowMac::MacPaintGrowBox()
1283 if ( MacHasScrollBarCorner() )
1285 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1286 wxASSERT( cgContext
) ;
1290 m_peer
->GetSize( tw
, th
);
1291 m_peer
->GetPosition( tx
, ty
);
1293 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1296 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1297 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1298 CGContextSaveGState( cgContext
);
1300 if ( m_backgroundColour
.Ok() )
1302 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1306 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1308 CGContextFillRect( cgContext
, cgrect
);
1309 CGContextRestoreGState( cgContext
);
1313 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1318 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1320 // back to the surrounding frame rectangle
1323 m_peer
->GetSize( tw
, th
);
1324 m_peer
->GetPosition( tx
, ty
);
1326 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1328 #if wxOSX_USE_COCOA_OR_CARBON
1330 InsetRect( &rect
, -1 , -1 ) ;
1333 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1334 rect
.bottom
- rect
.top
) ;
1336 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1337 wxASSERT( cgContext
) ;
1339 if ( m_peer
->NeedsFrame() )
1341 HIThemeFrameDrawInfo info
;
1342 memset( &info
, 0 , sizeof(info
) ) ;
1346 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1347 info
.isFocused
= hasFocus
;
1349 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1351 info
.kind
= kHIThemeFrameTextFieldSquare
;
1352 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1354 else if ( HasFlag(wxSIMPLE_BORDER
) )
1356 info
.kind
= kHIThemeFrameListBox
;
1357 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1363 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1366 #endif // wxOSX_USE_COCOA_OR_CARBON
1369 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1371 if ( child
== m_hScrollBar
)
1372 m_hScrollBar
= NULL
;
1373 if ( child
== m_vScrollBar
)
1374 m_vScrollBar
= NULL
;
1376 wxWindowBase::RemoveChild( child
) ;
1379 void wxWindowMac::DoUpdateScrollbarVisibility()
1381 bool triggerSizeEvent
= false;
1385 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1387 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1389 m_hScrollBar
->Show( showHScrollBar
);
1390 triggerSizeEvent
= true;
1396 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1398 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1400 m_vScrollBar
->Show( showVScrollBar
) ;
1401 triggerSizeEvent
= true;
1405 MacRepositionScrollBars() ;
1406 if ( triggerSizeEvent
)
1408 wxSizeEvent
event(GetSize(), m_windowId
);
1409 event
.SetEventObject(this);
1410 HandleWindowEvent(event
);
1414 // New function that will replace some of the above.
1415 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1416 int range
, bool refresh
)
1418 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1419 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1420 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1421 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1423 DoUpdateScrollbarVisibility();
1426 // Does a physical scroll
1427 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1429 if ( dx
== 0 && dy
== 0 )
1432 int width
, height
;
1433 GetClientSize( &width
, &height
) ;
1436 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1438 scrollrect
.Intersect( *rect
) ;
1439 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1440 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1442 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1447 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1449 child
= node
->GetData();
1452 if (child
== m_vScrollBar
)
1454 if (child
== m_hScrollBar
)
1456 if (child
->IsTopLevel())
1459 child
->GetPosition( &x
, &y
);
1460 child
->GetSize( &w
, &h
);
1463 wxRect
rc( x
, y
, w
, h
);
1464 if (rect
->Intersects( rc
))
1465 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1469 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1474 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1476 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1478 wxScrollWinEvent wevent
;
1479 wevent
.SetPosition(event
.GetPosition());
1480 wevent
.SetOrientation(event
.GetOrientation());
1481 wevent
.SetEventObject(this);
1483 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1484 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1485 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1486 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1487 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1488 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1489 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1490 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1491 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1492 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1493 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1494 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1495 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1496 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1497 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1498 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1500 HandleWindowEvent(wevent
);
1504 wxWindow
*wxWindowBase::DoFindFocus()
1506 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1509 void wxWindowMac::OnInternalIdle()
1511 // This calls the UI-update mechanism (querying windows for
1512 // menu/toolbar/control state information)
1513 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1514 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1517 // Raise the window to the top of the Z order
1518 void wxWindowMac::Raise()
1523 // Lower the window to the bottom of the Z order
1524 void wxWindowMac::Lower()
1529 // static wxWindow *gs_lastWhich = NULL;
1531 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1533 // first trigger a set cursor event
1535 wxPoint clientorigin
= GetClientAreaOrigin() ;
1536 wxSize clientsize
= GetClientSize() ;
1538 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1540 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1542 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1543 if ( processedEvtSetCursor
&& event
.HasCursor() )
1545 cursor
= event
.GetCursor() ;
1549 // the test for processedEvtSetCursor is here to prevent using m_cursor
1550 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1551 // it - this is a way to say that our cursor shouldn't be used for this
1553 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1556 if ( !wxIsBusy() && !GetParent() )
1557 cursor
= *wxSTANDARD_CURSOR
;
1561 cursor
.MacInstall() ;
1564 return cursor
.Ok() ;
1567 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1571 return m_tooltip
->GetTip() ;
1574 return wxEmptyString
;
1577 void wxWindowMac::ClearBackground()
1583 void wxWindowMac::Update()
1585 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1590 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1592 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1596 if ( iter
->IsTopLevel() )
1598 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1602 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1607 iter
= iter
->GetParent() ;
1613 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1615 MacUpdateClippedRects() ;
1617 return m_cachedClippedClientRect
;
1620 const wxRect
& wxWindowMac::MacGetClippedRect() const
1622 MacUpdateClippedRects() ;
1624 return m_cachedClippedRect
;
1627 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1629 MacUpdateClippedRects() ;
1631 return m_cachedClippedRectWithOuterStructure
;
1634 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1636 static wxRegion emptyrgn
;
1638 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1640 MacUpdateClippedRects() ;
1641 if ( includeOuterStructures
)
1642 return m_cachedClippedRegionWithOuterStructure
;
1644 return m_cachedClippedRegion
;
1652 void wxWindowMac::MacUpdateClippedRects() const
1654 #if wxOSX_USE_CARBON
1655 if ( m_cachedClippedRectValid
)
1658 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1659 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1660 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1661 // to add focus borders everywhere
1663 Rect rIncludingOuterStructures
;
1667 m_peer
->GetSize( tw
, th
);
1668 m_peer
->GetPosition( tx
, ty
);
1670 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1672 r
.left
-= MacGetLeftBorderSize() ;
1673 r
.top
-= MacGetTopBorderSize() ;
1674 r
.bottom
+= MacGetBottomBorderSize() ;
1675 r
.right
+= MacGetRightBorderSize() ;
1682 rIncludingOuterStructures
= r
;
1683 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1685 wxRect cl
= GetClientRect() ;
1686 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1690 const wxWindow
* child
= (wxWindow
*) this ;
1691 const wxWindow
* parent
= NULL
;
1693 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1695 if ( parent
->MacIsChildOfClientArea(child
) )
1697 size
= parent
->GetClientSize() ;
1698 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1704 // this will be true for scrollbars, toolbars etc.
1705 size
= parent
->GetSize() ;
1706 y
= parent
->MacGetTopBorderSize() ;
1707 x
= parent
->MacGetLeftBorderSize() ;
1708 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1709 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1712 parent
->MacWindowToRootWindow( &x
, &y
) ;
1713 MacRootWindowToWindow( &x
, &y
) ;
1715 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1717 // the wxwindow and client rects will always be clipped
1718 SectRect( &r
, &rparent
, &r
) ;
1719 SectRect( &rClient
, &rparent
, &rClient
) ;
1721 // the structure only at 'hard' borders
1722 if ( parent
->MacClipChildren() ||
1723 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1725 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1731 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1732 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1733 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1734 m_cachedClippedRectWithOuterStructure
= wxRect(
1735 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1736 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1737 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1739 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1740 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1741 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1743 m_cachedClippedRectValid
= true ;
1748 This function must not change the updatergn !
1750 bool wxWindowMac::MacDoRedraw( long time
)
1752 bool handled
= false ;
1754 wxRegion formerUpdateRgn
= m_updateRegion
;
1755 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1757 const wxRect clientRect
= GetClientRect();
1759 clientUpdateRgn
.Intersect(clientRect
);
1761 // first send an erase event to the entire update area
1762 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
1765 case wxBG_STYLE_ERASE
:
1766 case wxBG_STYLE_SYSTEM
:
1768 // for the toplevel window this really is the entire area for
1769 // all the others only their client area, otherwise they might
1770 // be drawing with full alpha and eg put blue into the grow-box
1771 // area of a scrolled window (scroll sample)
1772 wxWindowDC
dc(this);
1774 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
1776 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
1778 if ( bgStyle
== wxBG_STYLE_ERASE
)
1780 wxEraseEvent
eevent( GetId(), &dc
);
1781 eevent
.SetEventObject( this );
1782 if ( ProcessWindowEvent( eevent
) )
1788 dc
.SetBackground(GetBackgroundColour());
1794 case wxBG_STYLE_PAINT
:
1795 // nothing to do, user-defined EVT_PAINT handler will overwrite the
1796 // entire window client area
1800 wxFAIL_MSG( "unsupported background style" );
1805 // calculate a client-origin version of the update rgn and set
1806 // m_updateRegion to that
1807 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
1808 m_updateRegion
= clientUpdateRgn
;
1810 if ( !m_updateRegion
.Empty() )
1812 // paint the window itself
1814 wxPaintEvent
event(GetId());
1815 event
.SetTimestamp(time
);
1816 event
.SetEventObject(this);
1817 handled
= HandleWindowEvent(event
);
1820 m_updateRegion
= formerUpdateRgn
;
1824 void wxWindowMac::MacPaintChildrenBorders()
1826 // now we cannot rely on having its borders drawn by a window itself, as it does not
1827 // get the updateRgn wide enough to always do so, so we do it from the parent
1828 // this would also be the place to draw any custom backgrounds for native controls
1829 // in Composited windowing
1830 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1834 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1836 child
= node
->GetData();
1839 if (child
== m_vScrollBar
)
1841 if (child
== m_hScrollBar
)
1843 if (child
->IsTopLevel())
1845 if (!child
->IsShown())
1848 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1850 child
->GetPosition( &x
, &y
);
1851 child
->GetSize( &w
, &h
);
1853 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
1855 // paint custom borders
1856 wxNcPaintEvent
eventNc( child
->GetId() );
1857 eventNc
.SetEventObject( child
);
1858 if ( !child
->HandleWindowEvent( eventNc
) )
1860 child
->MacPaintBorders(0, 0) ;
1867 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1869 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1870 return tlw
? tlw
->GetWXWindow() : NULL
;
1873 bool wxWindowMac::MacHasScrollBarCorner() const
1875 /* Returns whether the scroll bars in a wxScrolledWindow should be
1876 * shortened. Scroll bars should be shortened if either:
1878 * - both scroll bars are visible, or
1880 * - there is a resize box in the parent frame's corner and this
1881 * window shares the bottom and right edge with the parent
1885 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1888 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1889 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1891 // Both scroll bars visible
1896 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1898 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1900 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1903 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1905 // Parent frame has resize handle
1906 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1908 // Note: allow for some wiggle room here as wxMac's
1909 // window rect calculations seem to be imprecise
1910 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1911 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1913 // Parent frame has resize handle and shares
1914 // right bottom corner
1919 // Parent frame has resize handle but doesn't
1920 // share right bottom corner
1926 // Parent frame doesn't have resize handle
1932 // No parent frame found
1937 void wxWindowMac::MacCreateScrollBars( long style
)
1939 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1941 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1943 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1944 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1946 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
1949 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
1951 GetClientSize( &width
, &height
) ;
1953 wxPoint
vPoint(width
- scrlsize
, 0) ;
1954 wxSize
vSize(scrlsize
, height
- adjust
) ;
1955 wxPoint
hPoint(0, height
- scrlsize
) ;
1956 wxSize
hSize(width
- adjust
, scrlsize
) ;
1958 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
1959 if ( style
& wxVSCROLL
)
1961 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
1962 m_vScrollBar
->SetMinSize( wxDefaultSize
);
1965 if ( style
& wxHSCROLL
)
1967 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
1968 m_hScrollBar
->SetMinSize( wxDefaultSize
);
1972 // because the create does not take into account the client area origin
1973 // we might have a real position shift
1974 MacRepositionScrollBars() ;
1977 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
1979 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
1984 void wxWindowMac::MacRepositionScrollBars()
1986 if ( !m_hScrollBar
&& !m_vScrollBar
)
1989 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1990 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
1992 // get real client area
1994 GetSize( &width
, &height
);
1996 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1997 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1999 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2000 wxSize
vSize( scrlsize
, height
- adjust
) ;
2001 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2002 wxSize
hSize( width
- adjust
, scrlsize
) ;
2005 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2007 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2010 bool wxWindowMac::AcceptsFocus() const
2012 if ( MacIsUserPane() )
2013 return wxWindowBase::AcceptsFocus();
2015 return m_peer
->CanFocus();
2018 void wxWindowMac::MacSuperChangedPosition()
2020 // only window-absolute structures have to be moved i.e. controls
2022 m_cachedClippedRectValid
= false ;
2025 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2028 child
= node
->GetData();
2029 child
->MacSuperChangedPosition() ;
2031 node
= node
->GetNext();
2035 void wxWindowMac::MacTopLevelWindowChangedPosition()
2037 // only screen-absolute structures have to be moved i.e. glcanvas
2040 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2043 child
= node
->GetData();
2044 child
->MacTopLevelWindowChangedPosition() ;
2046 node
= node
->GetNext();
2050 long wxWindowMac::MacGetLeftBorderSize() const
2057 if ( m_peer
&& m_peer
->NeedsFrame() )
2059 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2061 #if wxOSX_USE_COCOA_OR_CARBON
2062 // this metric is only the 'outset' outside the simple frame rect
2063 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2069 else if (HasFlag(wxSIMPLE_BORDER
))
2071 #if wxOSX_USE_COCOA_OR_CARBON
2072 // this metric is only the 'outset' outside the simple frame rect
2073 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2084 long wxWindowMac::MacGetRightBorderSize() const
2086 // they are all symmetric in mac themes
2087 return MacGetLeftBorderSize() ;
2090 long wxWindowMac::MacGetTopBorderSize() const
2092 // they are all symmetric in mac themes
2093 return MacGetLeftBorderSize() ;
2096 long wxWindowMac::MacGetBottomBorderSize() const
2098 // they are all symmetric in mac themes
2099 return MacGetLeftBorderSize() ;
2102 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2104 return style
& ~wxBORDER_MASK
;
2107 // Find the wxWindowMac at the current mouse position, returning the mouse
2109 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2111 pt
= wxGetMousePosition();
2112 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2114 return (wxWindow
*) found
;
2117 // Get the current mouse position.
2118 wxPoint
wxGetMousePosition()
2122 wxGetMousePosition( &x
, &y
);
2124 return wxPoint(x
, y
);
2127 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2129 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2131 // copied from wxGTK : CS
2132 // VZ: shouldn't we move this to base class then?
2134 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2137 // (a) it's a command event and so is propagated to the parent
2138 // (b) under MSW it can be generated from kbd too
2139 // (c) it uses screen coords (because of (a))
2140 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2142 this->ClientToScreen(event
.GetPosition()));
2143 evtCtx
.SetEventObject(this);
2144 if ( ! HandleWindowEvent(evtCtx
) )
2153 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2157 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2161 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2162 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2167 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2172 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2174 #if wxOSX_USE_COCOA_OR_CARBON
2175 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2178 return eventNotHandledErr
;
2184 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2186 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2187 if ( !wxWindowBase::Reparent(newParent
) )
2190 m_peer
->RemoveFromParent();
2191 m_peer
->Embed( GetParent()->GetPeer() );
2195 bool wxWindowMac::SetTransparent(wxByte alpha
)
2197 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2199 if ( alpha
!= m_macAlpha
)
2201 m_macAlpha
= alpha
;
2208 bool wxWindowMac::CanSetTransparent()
2213 wxByte
wxWindowMac::GetTransparent() const
2218 bool wxWindowMac::IsShownOnScreen() const
2220 if ( m_peer
&& m_peer
->IsOk() )
2222 bool peerVis
= m_peer
->IsVisible();
2223 bool wxVis
= wxWindowBase::IsShownOnScreen();
2224 if( peerVis
!= wxVis
)
2226 // CS : put a breakpoint here to investigate differences
2227 // between native an wx visibilities
2228 // the only place where I've encountered them until now
2229 // are the hiding/showing sequences where the vis-changed event is
2230 // first sent to the innermost control, while wx does things
2231 // from the outmost control
2232 wxVis
= wxWindowBase::IsShownOnScreen();
2236 return m_peer
->IsVisible();
2238 return wxWindowBase::IsShownOnScreen();
2241 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2243 bool handled
= HandleWindowEvent( event
) ;
2244 if ( handled
&& event
.GetSkipped() )
2248 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2250 wxWindow
*ancestor
= this;
2253 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2256 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2258 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2259 handled
= handler
->ProcessEvent( command_event
);
2263 // accelerators can also be used with buttons, try them too
2264 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2265 handled
= handler
->ProcessEvent( command_event
);
2271 if (ancestor
->IsTopLevel())
2274 ancestor
= ancestor
->GetParent();
2277 #endif // wxUSE_ACCEL
2286 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2288 static MacControlMap wxWinMacControlList
;
2290 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2292 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2294 return impl
->GetWXPeer();
2299 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2301 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2303 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2306 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2308 // adding NULL ControlRef is (first) surely a result of an error and
2309 // (secondly) breaks native event processing
2310 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2312 wxWinMacControlList
[inControl
] = impl
;
2315 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2317 // iterate over all the elements in the class
2318 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2319 // we should go on...
2325 MacControlMap::iterator it
;
2326 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2328 if ( it
->second
== impl
)
2330 wxWinMacControlList
.erase(it
);
2338 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2340 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2343 m_isRootControl
= isRootControl
;
2347 wxWidgetImpl::wxWidgetImpl()
2352 wxWidgetImpl::~wxWidgetImpl()
2356 void wxWidgetImpl::Init()
2358 m_isRootControl
= false;
2360 m_needsFocusRect
= false;
2361 m_needsFrame
= true;
2364 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2366 m_needsFocusRect
= needs
;
2369 bool wxWidgetImpl::NeedsFocusRect() const
2371 return m_needsFocusRect
;
2374 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2376 m_needsFrame
= needs
;
2379 bool wxWidgetImpl::NeedsFrame() const
2381 return m_needsFrame
;