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_NC_PAINT(wxWindowMac::OnNcPaint
)
87 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
88 EVT_PAINT(wxWindowMac::OnPaint
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
92 #define wxMAC_DEBUG_REDRAW 0
93 #ifndef wxMAC_DEBUG_REDRAW
94 #define wxMAC_DEBUG_REDRAW 0
97 // ===========================================================================
99 // ===========================================================================
101 // ----------------------------------------------------------------------------
102 // constructors and such
103 // ----------------------------------------------------------------------------
105 wxWindowMac::wxWindowMac()
110 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
115 const wxString
& name
)
118 Create(parent
, id
, pos
, size
, style
, name
);
121 void wxWindowMac::Init()
125 m_cgContextRef
= NULL
;
127 // as all windows are created with WS_VISIBLE style...
130 m_hScrollBar
= NULL
;
131 m_vScrollBar
= NULL
;
132 m_hScrollBarAlwaysShown
= false;
133 m_vScrollBarAlwaysShown
= false;
135 m_macIsUserPane
= true;
136 m_clipChildren
= false ;
137 m_cachedClippedRectValid
= false ;
140 wxWindowMac::~wxWindowMac()
144 m_isBeingDeleted
= true;
146 MacInvalidateBorders() ;
148 #ifndef __WXUNIVERSAL__
149 // VS: make sure there's no wxFrame with last focus set to us:
150 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
152 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
155 if ( frame
->GetLastFocus() == this )
156 frame
->SetLastFocus(NULL
);
162 // destroy children before destroying this window itself
165 // wxRemoveMacControlAssociation( this ) ;
166 // If we delete an item, we should initialize the parent panel,
167 // because it could now be invalid.
168 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
171 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
172 tlw
->SetDefaultItem(NULL
);
175 if ( g_MacLastWindow
== this )
176 g_MacLastWindow
= NULL
;
178 #ifndef __WXUNIVERSAL__
179 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
182 if ( frame
->GetLastFocus() == this )
183 frame
->SetLastFocus( NULL
) ;
187 // delete our drop target if we've got one
188 #if wxUSE_DRAG_AND_DROP
189 if ( m_dropTarget
!= NULL
)
199 WXWidget
wxWindowMac::GetHandle() const
201 return (WXWidget
) m_peer
->GetWXWidget() ;
205 // TODO END move to window_osx.cpp
208 // ---------------------------------------------------------------------------
209 // Utility Routines to move between different coordinate systems
210 // ---------------------------------------------------------------------------
213 * Right now we have the following setup :
214 * a border that is not part of the native control is always outside the
215 * control's border (otherwise we loose all native intelligence, future ways
216 * may be to have a second embedding control responsible for drawing borders
217 * and backgrounds eventually)
218 * so all this border calculations have to be taken into account when calling
219 * native methods or getting native oriented data
220 * so we have three coordinate systems here
221 * wx client coordinates
222 * wx window coordinates (including window frames)
230 bool wxWindowMac::Create(wxWindowMac
*parent
,
235 const wxString
& name
)
237 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
239 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
242 m_windowVariant
= parent
->GetWindowVariant() ;
244 if ( m_macIsUserPane
)
246 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
247 MacPostControlCreate(pos
, size
) ;
250 #ifndef __WXUNIVERSAL__
251 // Don't give scrollbars to wxControls unless they ask for them
252 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
253 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
255 MacCreateScrollBars( style
) ;
259 wxWindowCreateEvent
event((wxWindow
*)this);
260 GetEventHandler()->AddPendingEvent(event
);
265 void wxWindowMac::MacChildAdded()
268 m_vScrollBar
->Raise() ;
270 m_hScrollBar
->Raise() ;
273 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
275 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
277 GetParent()->AddChild( this );
279 m_peer
->InstallEventHandler();
280 m_peer
->Embed(GetParent()->GetPeer());
282 GetParent()->MacChildAdded() ;
284 // adjust font, controlsize etc
285 DoSetWindowVariant( m_windowVariant
) ;
287 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
289 // for controls we want to use best size for wxDefaultSize params )
290 if ( !m_macIsUserPane
)
291 SetInitialSize(size
);
293 SetCursor( *wxSTANDARD_CURSOR
) ;
296 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
298 // Don't assert, in case we set the window variant before
299 // the window is created
300 // wxASSERT( m_peer->Ok() ) ;
302 m_windowVariant
= variant
;
304 if (m_peer
== NULL
|| !m_peer
->IsOk())
307 m_peer
->SetControlSize( variant
);
311 // we will get that from the settings later
312 // and make this NORMAL later, but first
313 // we have a few calculations that we must fix
317 case wxWINDOW_VARIANT_NORMAL
:
318 size
= kControlSizeNormal
;
321 case wxWINDOW_VARIANT_SMALL
:
322 size
= kControlSizeSmall
;
325 case wxWINDOW_VARIANT_MINI
:
326 // not always defined in the headers
330 case wxWINDOW_VARIANT_LARGE
:
331 size
= kControlSizeLarge
;
335 wxFAIL_MSG(_T("unexpected window variant"));
338 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
341 #if wxOSX_USE_COCOA_OR_CARBON
344 #if wxOSX_USE_ATSU_TEXT
345 ThemeFontID themeFont
= kThemeSystemFont
;
347 // we will get that from the settings later
348 // and make this NORMAL later, but first
349 // we have a few calculations that we must fix
353 case wxWINDOW_VARIANT_NORMAL
:
354 themeFont
= kThemeSystemFont
;
357 case wxWINDOW_VARIANT_SMALL
:
358 themeFont
= kThemeSmallSystemFont
;
361 case wxWINDOW_VARIANT_MINI
:
362 // not always defined in the headers
366 case wxWINDOW_VARIANT_LARGE
:
367 themeFont
= kThemeSystemFont
;
371 wxFAIL_MSG(_T("unexpected window variant"));
375 font
.MacCreateFromThemeFont( themeFont
) ;
377 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
380 case wxWINDOW_VARIANT_NORMAL
:
381 themeFont
= kCTFontSystemFontType
;
384 case wxWINDOW_VARIANT_SMALL
:
385 themeFont
= kCTFontSmallSystemFontType
;
388 case wxWINDOW_VARIANT_MINI
:
389 themeFont
= kCTFontMiniSystemFontType
;
392 case wxWINDOW_VARIANT_LARGE
:
393 themeFont
= kCTFontSystemFontType
;
397 wxFAIL_MSG(_T("unexpected window variant"));
400 font
.MacCreateFromUIFont( themeFont
) ;
407 void wxWindowMac::MacUpdateControlFont()
410 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
412 // do not trigger refreshes upon invisible and possible partly created objects
413 if ( IsShownOnScreen() )
417 bool wxWindowMac::SetFont(const wxFont
& font
)
419 bool retval
= wxWindowBase::SetFont( font
);
421 MacUpdateControlFont() ;
426 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
428 bool retval
= wxWindowBase::SetForegroundColour( col
);
431 MacUpdateControlFont();
436 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
438 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
442 m_peer
->SetBackgroundColour( col
) ;
447 void wxWindowMac::SetFocus()
449 if ( !AcceptsFocus() )
452 wxWindow
* former
= FindFocus() ;
453 if ( former
== this )
459 void wxWindowMac::DoCaptureMouse()
461 wxApp::s_captureWindow
= (wxWindow
*) this ;
462 #ifdef wxOSX_USE_COCOA
463 // TODO do we really need this ?
466 m_peer
->CaptureMouse() ;
469 wxWindow
* wxWindowBase::GetCapture()
471 return wxApp::s_captureWindow
;
474 void wxWindowMac::DoReleaseMouse()
476 wxApp::s_captureWindow
= NULL
;
478 m_peer
->ReleaseMouse() ;
481 #if wxUSE_DRAG_AND_DROP
483 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
487 m_dropTarget
= pDropTarget
;
488 if ( m_dropTarget
!= NULL
)
496 // Old-style File Manager Drag & Drop
497 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
502 // From a wx position / size calculate the appropriate size of the native control
504 bool wxWindowMac::MacGetBoundsForControl(
508 int& w
, int& h
, bool adjustOrigin
) const
510 // the desired size, minus the border pixels gives the correct size of the control
514 w
= WidthDefault( size
.x
);
515 h
= HeightDefault( size
.y
);
517 x
+= MacGetLeftBorderSize() ;
518 y
+= MacGetTopBorderSize() ;
519 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
520 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
523 AdjustForParentClientOrigin( x
, y
) ;
525 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
526 if ( GetParent() && !GetParent()->IsTopLevel() )
528 x
-= GetParent()->MacGetLeftBorderSize() ;
529 y
-= GetParent()->MacGetTopBorderSize() ;
535 // Get window size (not client size)
536 void wxWindowMac::DoGetSize(int *x
, int *y
) const
539 m_peer
->GetSize( width
, height
);
542 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
544 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
547 // get the position of the bounds of this window in client coordinates of its parent
548 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
552 m_peer
->GetPosition( x1
, y1
) ;
554 // get the wx window position from the native one
555 x1
-= MacGetLeftBorderSize() ;
556 y1
-= MacGetTopBorderSize() ;
560 wxWindow
*parent
= GetParent();
563 // we must first adjust it to be in window coordinates of the parent,
564 // as otherwise it gets lost by the ClientAreaOrigin fix
565 x1
+= parent
->MacGetLeftBorderSize() ;
566 y1
+= parent
->MacGetTopBorderSize() ;
568 // and now to client coordinates
569 wxPoint
pt(parent
->GetClientAreaOrigin());
581 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
583 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
584 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
585 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
586 MacRootWindowToWindow( x
, y
) ;
588 wxPoint origin
= GetClientAreaOrigin() ;
595 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
597 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
598 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
600 wxPoint origin
= GetClientAreaOrigin() ;
606 MacWindowToRootWindow( x
, y
) ;
607 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
610 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
612 wxPoint origin
= GetClientAreaOrigin() ;
618 MacWindowToRootWindow( x
, y
) ;
621 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
632 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
635 pt
.x
-= MacGetLeftBorderSize() ;
636 pt
.y
-= MacGetTopBorderSize() ;
637 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
647 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
658 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
661 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
662 pt
.x
+= MacGetLeftBorderSize() ;
663 pt
.y
+= MacGetTopBorderSize() ;
673 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
675 wxSize sizeTotal
= size
;
677 int innerwidth
, innerheight
;
679 int outerwidth
, outerheight
;
681 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
682 m_peer
->GetSize( outerwidth
, outerheight
);
684 sizeTotal
.x
+= outerwidth
-innerwidth
;
685 sizeTotal
.y
+= outerheight
-innerheight
;
687 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
688 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
693 // Get size *available for subwindows* i.e. excluding menu bar etc.
694 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
700 m_peer
->GetContentArea( left
, top
, ww
, hh
);
702 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
703 hh
-= m_hScrollBar
->GetSize().y
;
705 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
706 ww
-= m_vScrollBar
->GetSize().x
;
714 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
716 if (m_cursor
.IsSameAs(cursor
))
721 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
726 if ( ! wxWindowBase::SetCursor( cursor
) )
730 wxASSERT_MSG( m_cursor
.Ok(),
731 wxT("cursor must be valid after call to the base version"));
733 if ( GetPeer() != NULL
)
734 GetPeer()->SetCursor( m_cursor
);
740 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
742 #ifndef __WXUNIVERSAL__
743 menu
->SetInvokingWindow((wxWindow
*)this);
746 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
748 wxPoint mouse
= wxGetMousePosition();
754 ClientToScreen( &x
, &y
) ;
756 menu
->GetPeer()->PopUp(this, x
, y
);
757 menu
->SetInvokingWindow( NULL
);
760 // actually this shouldn't be called, because universal is having its own implementation
766 // ----------------------------------------------------------------------------
768 // ----------------------------------------------------------------------------
772 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
774 wxWindowBase::DoSetToolTip(tooltip
);
777 m_tooltip
->SetWindow(this);
782 void wxWindowMac::MacInvalidateBorders()
784 if ( m_peer
== NULL
)
787 bool vis
= IsShownOnScreen() ;
791 int outerBorder
= MacGetLeftBorderSize() ;
793 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
797 if ( outerBorder
== 0 )
800 // now we know that we have something to do at all
805 m_peer
->GetSize( tw
, th
);
806 m_peer
->GetPosition( tx
, ty
);
808 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
809 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
810 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
811 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
814 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
815 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
816 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
817 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
821 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
823 // this is never called for a toplevel window, so we know we have a parent
824 int former_x
, former_y
, former_w
, former_h
;
826 // Get true coordinates of former position
827 DoGetPosition( &former_x
, &former_y
) ;
828 DoGetSize( &former_w
, &former_h
) ;
830 wxWindow
*parent
= GetParent();
833 wxPoint
pt(parent
->GetClientAreaOrigin());
838 int actualWidth
= width
;
839 int actualHeight
= height
;
843 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
844 actualWidth
= m_minWidth
;
845 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
846 actualHeight
= m_minHeight
;
847 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
848 actualWidth
= m_maxWidth
;
849 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
850 actualHeight
= m_maxHeight
;
852 bool doMove
= false, doResize
= false ;
854 if ( actualX
!= former_x
|| actualY
!= former_y
)
857 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
860 if ( doMove
|| doResize
)
862 // as the borders are drawn outside the native control, we adjust now
864 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
865 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
866 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
868 if ( parent
&& !parent
->IsTopLevel() )
870 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
873 MacInvalidateBorders() ;
875 m_cachedClippedRectValid
= false ;
877 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
879 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
881 MacInvalidateBorders() ;
883 MacRepositionScrollBars() ;
886 wxPoint
point(actualX
, actualY
);
887 wxMoveEvent
event(point
, m_windowId
);
888 event
.SetEventObject(this);
889 HandleWindowEvent(event
) ;
894 MacRepositionScrollBars() ;
895 wxSize
size(actualWidth
, actualHeight
);
896 wxSizeEvent
event(size
, m_windowId
);
897 event
.SetEventObject(this);
898 HandleWindowEvent(event
);
903 wxSize
wxWindowMac::DoGetBestSize() const
905 if ( m_macIsUserPane
|| IsTopLevel() )
907 return wxWindowBase::DoGetBestSize() ;
913 m_peer
->GetBestRect(&r
);
915 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
922 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
927 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
934 // return wxWindowBase::DoGetBestSize() ;
938 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
939 MacGetRightBorderSize();
940 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
941 MacGetBottomBorderSize();
942 if ( bestHeight
< 10 )
945 return wxSize(bestWidth
, bestHeight
);
949 // set the size of the window: if the dimensions are positive, just use them,
950 // but if any of them is equal to -1, it means that we must find the value for
951 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
952 // which case -1 is a valid value for x and y)
954 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
955 // the width/height to best suit our contents, otherwise we reuse the current
957 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
959 // get the current size and position...
960 int currentX
, currentY
;
961 int currentW
, currentH
;
963 GetPosition(¤tX
, ¤tY
);
964 GetSize(¤tW
, ¤tH
);
966 // ... and don't do anything (avoiding flicker) if it's already ok
967 if ( x
== currentX
&& y
== currentY
&&
968 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
971 MacRepositionScrollBars() ; // we might have a real position shift
976 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
978 if ( x
== wxDefaultCoord
)
980 if ( y
== wxDefaultCoord
)
984 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
986 wxSize size
= wxDefaultSize
;
987 if ( width
== wxDefaultCoord
)
989 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
991 size
= DoGetBestSize();
996 // just take the current one
1001 if ( height
== wxDefaultCoord
)
1003 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1005 if ( size
.x
== wxDefaultCoord
)
1006 size
= DoGetBestSize();
1007 // else: already called DoGetBestSize() above
1013 // just take the current one
1018 DoMoveWindow( x
, y
, width
, height
);
1021 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1023 int left
,top
,width
,height
;
1024 m_peer
->GetContentArea( left
, top
, width
, height
);
1025 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1028 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1030 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1032 int currentclientwidth
, currentclientheight
;
1033 int currentwidth
, currentheight
;
1035 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1036 GetSize( ¤twidth
, ¤theight
) ;
1038 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1039 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1043 void wxWindowMac::SetLabel(const wxString
& title
)
1047 if ( m_peer
&& m_peer
->IsOk() )
1048 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1050 // do not trigger refreshes upon invisible and possible partly created objects
1051 if ( IsShownOnScreen() )
1055 wxString
wxWindowMac::GetLabel() const
1060 bool wxWindowMac::Show(bool show
)
1062 if ( !wxWindowBase::Show(show
) )
1066 m_peer
->SetVisibility( show
) ;
1071 void wxWindowMac::DoEnable(bool enable
)
1073 m_peer
->Enable( enable
) ;
1077 // status change notifications
1080 void wxWindowMac::MacVisibilityChanged()
1084 void wxWindowMac::MacHiliteChanged()
1088 void wxWindowMac::MacEnabledStateChanged()
1090 OnEnabled( m_peer
->IsEnabled() );
1094 // status queries on the inherited window's state
1097 bool wxWindowMac::MacIsReallyEnabled()
1099 return m_peer
->IsEnabled() ;
1102 bool wxWindowMac::MacIsReallyHilited()
1104 #if wxOSX_USE_CARBON
1105 return m_peer
->IsActive();
1107 return true; // TODO
1111 int wxWindowMac::GetCharHeight() const
1114 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1119 int wxWindowMac::GetCharWidth() const
1122 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1127 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1128 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1130 const wxFont
*fontToUse
= theFont
;
1134 tempFont
= GetFont();
1135 fontToUse
= &tempFont
;
1138 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1139 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1141 wxDouble h
, d
, e
, w
;
1142 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1146 if ( externalLeading
)
1147 *externalLeading
= (wxCoord
)(e
+0.5);
1149 *descent
= (wxCoord
)(d
+0.5);
1151 *x
= (wxCoord
)(w
+0.5);
1153 *y
= (wxCoord
)(h
+0.5);
1157 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1158 * we always intersect with the entire window, not only with the client area
1161 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1163 if ( m_peer
== NULL
)
1166 if ( !IsShownOnScreen() )
1169 m_peer
->SetNeedsDisplay( rect
) ;
1172 void wxWindowMac::DoFreeze()
1174 #if wxOSX_USE_CARBON
1175 if ( m_peer
&& m_peer
->IsOk() )
1176 m_peer
->SetDrawingEnabled( false ) ;
1180 void wxWindowMac::DoThaw()
1182 #if wxOSX_USE_CARBON
1183 if ( m_peer
&& m_peer
->IsOk() )
1185 m_peer
->SetDrawingEnabled( true ) ;
1186 m_peer
->InvalidateWithChildren() ;
1191 wxWindow
*wxGetActiveWindow()
1193 // actually this is a windows-only concept
1197 // Coordinates relative to the window
1198 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1200 // We really don't move the mouse programmatically under Mac.
1203 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1205 if ( MacGetTopLevelWindow() == NULL
)
1208 #if TARGET_API_MAC_OSX
1209 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1215 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1217 event
.GetDC()->Clear() ;
1219 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1221 // don't skip the event here, custom background means that the app
1222 // is drawing it itself in its OnPaint(), so don't draw it at all
1223 // now to avoid flicker
1231 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1236 int wxWindowMac::GetScrollPos(int orient
) const
1238 if ( orient
== wxHORIZONTAL
)
1241 return m_hScrollBar
->GetThumbPosition() ;
1246 return m_vScrollBar
->GetThumbPosition() ;
1252 // This now returns the whole range, not just the number
1253 // of positions that we can scroll.
1254 int wxWindowMac::GetScrollRange(int orient
) const
1256 if ( orient
== wxHORIZONTAL
)
1259 return m_hScrollBar
->GetRange() ;
1264 return m_vScrollBar
->GetRange() ;
1270 int wxWindowMac::GetScrollThumb(int orient
) const
1272 if ( orient
== wxHORIZONTAL
)
1275 return m_hScrollBar
->GetThumbSize() ;
1280 return m_vScrollBar
->GetThumbSize() ;
1286 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1288 if ( orient
== wxHORIZONTAL
)
1291 m_hScrollBar
->SetThumbPosition( pos
) ;
1296 m_vScrollBar
->SetThumbPosition( pos
) ;
1301 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1303 bool needVisibilityUpdate
= false;
1305 if ( m_hScrollBarAlwaysShown
!= hflag
)
1307 m_hScrollBarAlwaysShown
= hflag
;
1308 needVisibilityUpdate
= true;
1311 if ( m_vScrollBarAlwaysShown
!= vflag
)
1313 m_vScrollBarAlwaysShown
= vflag
;
1314 needVisibilityUpdate
= true;
1317 if ( needVisibilityUpdate
)
1318 DoUpdateScrollbarVisibility();
1322 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1323 // our own window origin is at leftOrigin/rightOrigin
1326 void wxWindowMac::MacPaintGrowBox()
1331 if ( MacHasScrollBarCorner() )
1333 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1334 wxASSERT( cgContext
) ;
1338 m_peer
->GetSize( tw
, th
);
1339 m_peer
->GetPosition( tx
, ty
);
1341 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1344 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1345 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1346 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1347 CGContextSaveGState( cgContext
);
1349 if ( m_backgroundColour
.Ok() )
1351 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1355 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1357 CGContextFillRect( cgContext
, cgrect
);
1358 CGContextRestoreGState( cgContext
);
1362 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1367 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1369 // back to the surrounding frame rectangle
1372 m_peer
->GetSize( tw
, th
);
1373 m_peer
->GetPosition( tx
, ty
);
1375 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1377 #if wxOSX_USE_COCOA_OR_CARBON
1379 InsetRect( &rect
, -1 , -1 ) ;
1382 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1383 rect
.bottom
- rect
.top
) ;
1385 HIThemeFrameDrawInfo info
;
1386 memset( &info
, 0 , sizeof(info
) ) ;
1390 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1391 info
.isFocused
= hasFocus
;
1393 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1394 wxASSERT( cgContext
) ;
1396 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1398 info
.kind
= kHIThemeFrameTextFieldSquare
;
1399 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1401 else if ( HasFlag(wxSIMPLE_BORDER
) )
1403 info
.kind
= kHIThemeFrameListBox
;
1404 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1406 else if ( hasFocus
)
1408 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1410 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1411 m_peer
->GetRect( &rect
) ;
1412 if ( MacHasScrollBarCorner() )
1414 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1415 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1416 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1417 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1418 HIThemeGrowBoxDrawInfo info
;
1419 memset( &info
, 0, sizeof(info
) ) ;
1421 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1422 info
.kind
= kHIThemeGrowBoxKindNone
;
1423 // contrary to the docs ...SizeSmall does not work
1424 info
.size
= kHIThemeGrowBoxSizeNormal
;
1425 info
.direction
= 0 ;
1426 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1430 #endif // wxOSX_USE_COCOA_OR_CARBON
1433 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1435 if ( child
== m_hScrollBar
)
1436 m_hScrollBar
= NULL
;
1437 if ( child
== m_vScrollBar
)
1438 m_vScrollBar
= NULL
;
1440 wxWindowBase::RemoveChild( child
) ;
1443 void wxWindowMac::DoUpdateScrollbarVisibility()
1445 bool triggerSizeEvent
= false;
1449 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1451 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1453 m_hScrollBar
->Show( showHScrollBar
);
1454 triggerSizeEvent
= true;
1460 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1462 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1464 m_vScrollBar
->Show( showVScrollBar
) ;
1465 triggerSizeEvent
= true;
1469 MacRepositionScrollBars() ;
1470 if ( triggerSizeEvent
)
1472 wxSizeEvent
event(GetSize(), m_windowId
);
1473 event
.SetEventObject(this);
1474 HandleWindowEvent(event
);
1478 // New function that will replace some of the above.
1479 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1480 int range
, bool refresh
)
1482 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1483 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1484 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1485 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1487 DoUpdateScrollbarVisibility();
1490 // Does a physical scroll
1491 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1493 if ( dx
== 0 && dy
== 0 )
1496 int width
, height
;
1497 GetClientSize( &width
, &height
) ;
1500 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1502 scrollrect
.Intersect( *rect
) ;
1503 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1504 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1506 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1511 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1513 child
= node
->GetData();
1516 if (child
== m_vScrollBar
)
1518 if (child
== m_hScrollBar
)
1520 if (child
->IsTopLevel())
1523 child
->GetPosition( &x
, &y
);
1524 child
->GetSize( &w
, &h
);
1527 wxRect
rc( x
, y
, w
, h
);
1528 if (rect
->Intersects( rc
))
1529 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1533 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1538 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1540 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1542 wxScrollWinEvent wevent
;
1543 wevent
.SetPosition(event
.GetPosition());
1544 wevent
.SetOrientation(event
.GetOrientation());
1545 wevent
.SetEventObject(this);
1547 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1548 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1549 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1550 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1551 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1552 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1553 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1554 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1555 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1556 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1557 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1558 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1559 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1560 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1561 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1562 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1564 HandleWindowEvent(wevent
);
1568 // Get the window with the focus
1569 wxWindow
*wxWindowBase::DoFindFocus()
1571 #if wxOSX_USE_CARBON
1572 ControlRef control
;
1573 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1574 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1580 void wxWindowMac::OnInternalIdle()
1582 // This calls the UI-update mechanism (querying windows for
1583 // menu/toolbar/control state information)
1584 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1585 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1588 // Raise the window to the top of the Z order
1589 void wxWindowMac::Raise()
1594 // Lower the window to the bottom of the Z order
1595 void wxWindowMac::Lower()
1600 // static wxWindow *gs_lastWhich = NULL;
1602 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1604 // first trigger a set cursor event
1606 wxPoint clientorigin
= GetClientAreaOrigin() ;
1607 wxSize clientsize
= GetClientSize() ;
1609 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1611 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1613 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1614 if ( processedEvtSetCursor
&& event
.HasCursor() )
1616 cursor
= event
.GetCursor() ;
1620 // the test for processedEvtSetCursor is here to prevent using m_cursor
1621 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1622 // it - this is a way to say that our cursor shouldn't be used for this
1624 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1627 if ( !wxIsBusy() && !GetParent() )
1628 cursor
= *wxSTANDARD_CURSOR
;
1632 cursor
.MacInstall() ;
1635 return cursor
.Ok() ;
1638 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1642 return m_tooltip
->GetTip() ;
1645 return wxEmptyString
;
1648 void wxWindowMac::ClearBackground()
1654 void wxWindowMac::Update()
1656 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1661 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1663 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1667 if ( iter
->IsTopLevel() )
1669 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1673 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1678 iter
= iter
->GetParent() ;
1684 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1686 MacUpdateClippedRects() ;
1688 return m_cachedClippedClientRect
;
1691 const wxRect
& wxWindowMac::MacGetClippedRect() const
1693 MacUpdateClippedRects() ;
1695 return m_cachedClippedRect
;
1698 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1700 MacUpdateClippedRects() ;
1702 return m_cachedClippedRectWithOuterStructure
;
1705 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1707 static wxRegion emptyrgn
;
1709 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1711 MacUpdateClippedRects() ;
1712 if ( includeOuterStructures
)
1713 return m_cachedClippedRegionWithOuterStructure
;
1715 return m_cachedClippedRegion
;
1723 void wxWindowMac::MacUpdateClippedRects() const
1725 #if wxOSX_USE_CARBON
1726 if ( m_cachedClippedRectValid
)
1729 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1730 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1731 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1732 // to add focus borders everywhere
1734 Rect rIncludingOuterStructures
;
1738 m_peer
->GetSize( tw
, th
);
1739 m_peer
->GetPosition( tx
, ty
);
1741 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1743 r
.left
-= MacGetLeftBorderSize() ;
1744 r
.top
-= MacGetTopBorderSize() ;
1745 r
.bottom
+= MacGetBottomBorderSize() ;
1746 r
.right
+= MacGetRightBorderSize() ;
1753 rIncludingOuterStructures
= r
;
1754 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1756 wxRect cl
= GetClientRect() ;
1757 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1761 const wxWindow
* child
= (wxWindow
*) this ;
1762 const wxWindow
* parent
= NULL
;
1764 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1766 if ( parent
->MacIsChildOfClientArea(child
) )
1768 size
= parent
->GetClientSize() ;
1769 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1775 // this will be true for scrollbars, toolbars etc.
1776 size
= parent
->GetSize() ;
1777 y
= parent
->MacGetTopBorderSize() ;
1778 x
= parent
->MacGetLeftBorderSize() ;
1779 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1780 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1783 parent
->MacWindowToRootWindow( &x
, &y
) ;
1784 MacRootWindowToWindow( &x
, &y
) ;
1786 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1788 // the wxwindow and client rects will always be clipped
1789 SectRect( &r
, &rparent
, &r
) ;
1790 SectRect( &rClient
, &rparent
, &rClient
) ;
1792 // the structure only at 'hard' borders
1793 if ( parent
->MacClipChildren() ||
1794 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1796 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1802 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1803 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1804 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1805 m_cachedClippedRectWithOuterStructure
= wxRect(
1806 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1807 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1808 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1810 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1811 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1812 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1814 m_cachedClippedRectValid
= true ;
1819 This function must not change the updatergn !
1821 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1823 bool handled
= false ;
1824 #if wxOSX_USE_CARBON
1826 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1827 GetRegionBounds( updatergn
, &updatebounds
) ;
1829 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1831 if ( !EmptyRgn(updatergn
) )
1833 RgnHandle newupdate
= NewRgn() ;
1834 wxSize point
= GetClientSize() ;
1835 wxPoint origin
= GetClientAreaOrigin() ;
1836 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1837 SectRgn( newupdate
, updatergn
, newupdate
) ;
1839 // first send an erase event to the entire update area
1841 // for the toplevel window this really is the entire area
1842 // for all the others only their client area, otherwise they
1843 // might be drawing with full alpha and eg put blue into
1844 // the grow-box area of a scrolled window (scroll sample)
1845 wxDC
* dc
= new wxWindowDC(this);
1847 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1849 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1851 wxEraseEvent
eevent( GetId(), dc
);
1852 eevent
.SetEventObject( this );
1853 HandleWindowEvent( eevent
);
1859 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1860 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1861 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1862 DisposeRgn( newupdate
) ;
1864 if ( !m_updateRegion
.Empty() )
1866 // paint the window itself
1869 event
.SetTimestamp(time
);
1870 event
.SetEventObject(this);
1871 HandleWindowEvent(event
);
1875 // now we cannot rely on having its borders drawn by a window itself, as it does not
1876 // get the updateRgn wide enough to always do so, so we do it from the parent
1877 // this would also be the place to draw any custom backgrounds for native controls
1878 // in Composited windowing
1879 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1883 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1885 child
= node
->GetData();
1888 if (child
== m_vScrollBar
)
1890 if (child
== m_hScrollBar
)
1892 if (child
->IsTopLevel())
1894 if (!child
->IsShown())
1897 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1899 child
->GetPosition( &x
, &y
);
1900 child
->GetSize( &w
, &h
);
1901 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1902 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1903 InsetRect( &childRect
, -10 , -10) ;
1905 if ( RectInRgn( &childRect
, updatergn
) )
1907 // paint custom borders
1908 wxNcPaintEvent
eventNc( child
->GetId() );
1909 eventNc
.SetEventObject( child
);
1910 if ( !child
->HandleWindowEvent( eventNc
) )
1912 child
->MacPaintBorders(0, 0) ;
1922 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1924 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1925 return tlw
? tlw
->GetWXWindow() : NULL
;
1928 bool wxWindowMac::MacHasScrollBarCorner() const
1930 /* Returns whether the scroll bars in a wxScrolledWindow should be
1931 * shortened. Scroll bars should be shortened if either:
1933 * - both scroll bars are visible, or
1935 * - there is a resize box in the parent frame's corner and this
1936 * window shares the bottom and right edge with the parent
1940 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1943 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1944 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1946 // Both scroll bars visible
1951 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1953 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1955 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1958 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1960 // Parent frame has resize handle
1961 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1963 // Note: allow for some wiggle room here as wxMac's
1964 // window rect calculations seem to be imprecise
1965 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1966 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1968 // Parent frame has resize handle and shares
1969 // right bottom corner
1974 // Parent frame has resize handle but doesn't
1975 // share right bottom corner
1981 // Parent frame doesn't have resize handle
1987 // No parent frame found
1992 void wxWindowMac::MacCreateScrollBars( long style
)
1994 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1996 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1998 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1999 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2001 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2004 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2006 GetClientSize( &width
, &height
) ;
2008 wxPoint
vPoint(width
- scrlsize
, 0) ;
2009 wxSize
vSize(scrlsize
, height
- adjust
) ;
2010 wxPoint
hPoint(0, height
- scrlsize
) ;
2011 wxSize
hSize(width
- adjust
, scrlsize
) ;
2013 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2014 if ( style
& wxVSCROLL
)
2016 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2017 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2020 if ( style
& wxHSCROLL
)
2022 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2023 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2027 // because the create does not take into account the client area origin
2028 // we might have a real position shift
2029 MacRepositionScrollBars() ;
2032 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2034 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2039 void wxWindowMac::MacRepositionScrollBars()
2041 if ( !m_hScrollBar
&& !m_vScrollBar
)
2044 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2045 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2047 // get real client area
2049 GetSize( &width
, &height
);
2051 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2052 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2054 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2055 wxSize
vSize( scrlsize
, height
- adjust
) ;
2056 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2057 wxSize
hSize( width
- adjust
, scrlsize
) ;
2060 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2062 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2065 bool wxWindowMac::AcceptsFocus() const
2067 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2070 void wxWindowMac::MacSuperChangedPosition()
2072 // only window-absolute structures have to be moved i.e. controls
2074 m_cachedClippedRectValid
= false ;
2077 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2080 child
= node
->GetData();
2081 child
->MacSuperChangedPosition() ;
2083 node
= node
->GetNext();
2087 void wxWindowMac::MacTopLevelWindowChangedPosition()
2089 // only screen-absolute structures have to be moved i.e. glcanvas
2092 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2095 child
= node
->GetData();
2096 child
->MacTopLevelWindowChangedPosition() ;
2098 node
= node
->GetNext();
2102 long wxWindowMac::MacGetLeftBorderSize() const
2109 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2111 #if wxOSX_USE_COCOA_OR_CARBON
2112 // this metric is only the 'outset' outside the simple frame rect
2113 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2119 else if (HasFlag(wxSIMPLE_BORDER
))
2121 #if wxOSX_USE_COCOA_OR_CARBON
2122 // this metric is only the 'outset' outside the simple frame rect
2123 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2133 long wxWindowMac::MacGetRightBorderSize() const
2135 // they are all symmetric in mac themes
2136 return MacGetLeftBorderSize() ;
2139 long wxWindowMac::MacGetTopBorderSize() const
2141 // they are all symmetric in mac themes
2142 return MacGetLeftBorderSize() ;
2145 long wxWindowMac::MacGetBottomBorderSize() const
2147 // they are all symmetric in mac themes
2148 return MacGetLeftBorderSize() ;
2151 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2153 return style
& ~wxBORDER_MASK
;
2156 // Find the wxWindowMac at the current mouse position, returning the mouse
2158 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2160 pt
= wxGetMousePosition();
2161 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2163 return (wxWindow
*) found
;
2166 // Get the current mouse position.
2167 wxPoint
wxGetMousePosition()
2171 wxGetMousePosition( &x
, &y
);
2173 return wxPoint(x
, y
);
2176 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2178 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2180 // copied from wxGTK : CS
2181 // VZ: shouldn't we move this to base class then?
2183 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2186 // (a) it's a command event and so is propagated to the parent
2187 // (b) under MSW it can be generated from kbd too
2188 // (c) it uses screen coords (because of (a))
2189 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2191 this->ClientToScreen(event
.GetPosition()));
2192 evtCtx
.SetEventObject(this);
2193 if ( ! HandleWindowEvent(evtCtx
) )
2202 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2204 #if wxOSX_USE_COCOA_OR_CARBON
2205 // for native controls: call their native paint method
2206 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2208 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2209 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2210 CallNextEventHandler(
2211 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2212 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2217 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
2218 wxInt16
WXUNUSED(controlpart
),
2219 bool WXUNUSED(mouseStillDown
))
2223 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2227 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2228 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2233 bool wxWindowMac::HandleClicked( double timestampsec
)
2238 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2240 #if wxOSX_USE_COCOA_OR_CARBON
2241 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2244 return eventNotHandledErr
;
2250 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2252 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2253 if ( !wxWindowBase::Reparent(newParent
) )
2256 m_peer
->RemoveFromParent();
2257 m_peer
->Embed( GetParent()->GetPeer() );
2261 bool wxWindowMac::SetTransparent(wxByte alpha
)
2263 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2265 if ( alpha
!= m_macAlpha
)
2267 m_macAlpha
= alpha
;
2274 bool wxWindowMac::CanSetTransparent()
2279 wxByte
wxWindowMac::GetTransparent() const
2284 bool wxWindowMac::IsShownOnScreen() const
2286 if ( m_peer
&& m_peer
->IsOk() )
2288 bool peerVis
= m_peer
->IsVisible();
2289 bool wxVis
= wxWindowBase::IsShownOnScreen();
2290 if( peerVis
!= wxVis
)
2292 // CS : put a breakpoint here to investigate differences
2293 // between native an wx visibilities
2294 // the only place where I've encountered them until now
2295 // are the hiding/showing sequences where the vis-changed event is
2296 // first sent to the innermost control, while wx does things
2297 // from the outmost control
2298 wxVis
= wxWindowBase::IsShownOnScreen();
2302 return m_peer
->IsVisible();
2304 return wxWindowBase::IsShownOnScreen();
2311 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2313 static MacControlMap wxWinMacControlList
;
2315 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2317 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2319 return impl
->GetWXPeer();
2324 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2326 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2328 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2331 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2333 // adding NULL ControlRef is (first) surely a result of an error and
2334 // (secondly) breaks native event processing
2335 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2337 wxWinMacControlList
[inControl
] = impl
;
2340 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2342 // iterate over all the elements in the class
2343 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2344 // we should go on...
2350 MacControlMap::iterator it
;
2351 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2353 if ( it
->second
== impl
)
2355 wxWinMacControlList
.erase(it
);
2363 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2365 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2368 m_isRootControl
= isRootControl
;
2372 wxWidgetImpl::wxWidgetImpl()
2377 wxWidgetImpl::~wxWidgetImpl()
2381 void wxWidgetImpl::Init()
2383 m_isRootControl
= false;
2385 m_needsFocusRect
= false;
2388 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2390 m_needsFocusRect
= needs
;
2393 bool wxWidgetImpl::NeedsFocusRect() const
2395 return m_needsFocusRect
;