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_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 // ===========================================================================
98 // ===========================================================================
100 // ----------------------------------------------------------------------------
101 // constructors and such
102 // ----------------------------------------------------------------------------
104 wxWindowMac::wxWindowMac()
109 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
114 const wxString
& name
)
117 Create(parent
, id
, pos
, size
, style
, name
);
120 void wxWindowMac::Init()
124 m_cgContextRef
= NULL
;
126 // as all windows are created with WS_VISIBLE style...
129 m_hScrollBar
= NULL
;
130 m_vScrollBar
= NULL
;
131 m_hScrollBarAlwaysShown
= false;
132 m_vScrollBarAlwaysShown
= false;
134 m_macIsUserPane
= true;
135 m_clipChildren
= false ;
136 m_cachedClippedRectValid
= false ;
139 wxWindowMac::~wxWindowMac()
143 MacInvalidateBorders() ;
145 #ifndef __WXUNIVERSAL__
146 // VS: make sure there's no wxFrame with last focus set to us:
147 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
149 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
152 if ( frame
->GetLastFocus() == this )
153 frame
->SetLastFocus(NULL
);
159 // destroy children before destroying this window itself
162 // wxRemoveMacControlAssociation( this ) ;
163 // If we delete an item, we should initialize the parent panel,
164 // because it could now be invalid.
165 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
168 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
169 tlw
->SetDefaultItem(NULL
);
172 if ( g_MacLastWindow
== this )
173 g_MacLastWindow
= NULL
;
175 #ifndef __WXUNIVERSAL__
176 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
179 if ( frame
->GetLastFocus() == this )
180 frame
->SetLastFocus( NULL
) ;
184 // delete our drop target if we've got one
185 #if wxUSE_DRAG_AND_DROP
186 if ( m_dropTarget
!= NULL
)
196 WXWidget
wxWindowMac::GetHandle() const
199 return (WXWidget
) m_peer
->GetWXWidget() ;
203 // ---------------------------------------------------------------------------
204 // Utility Routines to move between different coordinate systems
205 // ---------------------------------------------------------------------------
208 * Right now we have the following setup :
209 * a border that is not part of the native control is always outside the
210 * control's border (otherwise we loose all native intelligence, future ways
211 * may be to have a second embedding control responsible for drawing borders
212 * and backgrounds eventually)
213 * so all this border calculations have to be taken into account when calling
214 * native methods or getting native oriented data
215 * so we have three coordinate systems here
216 * wx client coordinates
217 * wx window coordinates (including window frames)
225 bool wxWindowMac::Create(wxWindowMac
*parent
,
230 const wxString
& name
)
232 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
234 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
237 m_windowVariant
= parent
->GetWindowVariant() ;
239 if ( m_macIsUserPane
)
241 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
242 MacPostControlCreate(pos
, size
) ;
245 #ifndef __WXUNIVERSAL__
246 // Don't give scrollbars to wxControls unless they ask for them
247 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
248 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
250 MacCreateScrollBars( style
) ;
254 wxWindowCreateEvent
event((wxWindow
*)this);
255 GetEventHandler()->AddPendingEvent(event
);
260 void wxWindowMac::MacChildAdded()
263 m_vScrollBar
->Raise() ;
265 m_hScrollBar
->Raise() ;
268 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
270 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
272 GetParent()->AddChild( this );
274 m_peer
->InstallEventHandler();
275 m_peer
->Embed(GetParent()->GetPeer());
277 GetParent()->MacChildAdded() ;
279 // adjust font, controlsize etc
280 DoSetWindowVariant( m_windowVariant
) ;
282 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
284 // for controls we want to use best size for wxDefaultSize params )
285 if ( !m_macIsUserPane
)
286 SetInitialSize(size
);
288 SetCursor( *wxSTANDARD_CURSOR
) ;
291 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
293 // Don't assert, in case we set the window variant before
294 // the window is created
295 // wxASSERT( m_peer->Ok() ) ;
297 m_windowVariant
= variant
;
299 if (m_peer
== NULL
|| !m_peer
->IsOk())
302 m_peer
->SetControlSize( variant
);
306 // we will get that from the settings later
307 // and make this NORMAL later, but first
308 // we have a few calculations that we must fix
312 case wxWINDOW_VARIANT_NORMAL
:
313 size
= kControlSizeNormal
;
316 case wxWINDOW_VARIANT_SMALL
:
317 size
= kControlSizeSmall
;
320 case wxWINDOW_VARIANT_MINI
:
321 // not always defined in the headers
325 case wxWINDOW_VARIANT_LARGE
:
326 size
= kControlSizeLarge
;
330 wxFAIL_MSG(_T("unexpected window variant"));
333 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
338 wxOSXSystemFont systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
342 case wxWINDOW_VARIANT_NORMAL
:
343 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
346 case wxWINDOW_VARIANT_SMALL
:
347 systemFont
= wxOSX_SYSTEM_FONT_SMALL
;
350 case wxWINDOW_VARIANT_MINI
:
351 systemFont
= wxOSX_SYSTEM_FONT_MINI
;
354 case wxWINDOW_VARIANT_LARGE
:
355 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
359 wxFAIL_MSG(_T("unexpected window variant"));
363 font
.CreateSystemFont( systemFont
) ;
368 void wxWindowMac::MacUpdateControlFont()
371 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
373 // do not trigger refreshes upon invisible and possible partly created objects
374 if ( IsShownOnScreen() )
378 bool wxWindowMac::SetFont(const wxFont
& font
)
380 bool retval
= wxWindowBase::SetFont( font
);
382 MacUpdateControlFont() ;
387 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
389 bool retval
= wxWindowBase::SetForegroundColour( col
);
392 MacUpdateControlFont();
397 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
399 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
403 m_peer
->SetBackgroundColour( col
) ;
408 void wxWindowMac::SetFocus()
410 if ( !AcceptsFocus() )
413 wxWindow
* former
= FindFocus() ;
414 if ( former
== this )
420 void wxWindowMac::DoCaptureMouse()
422 wxApp::s_captureWindow
= (wxWindow
*) this ;
423 m_peer
->CaptureMouse() ;
426 wxWindow
* wxWindowBase::GetCapture()
428 return wxApp::s_captureWindow
;
431 void wxWindowMac::DoReleaseMouse()
433 wxApp::s_captureWindow
= NULL
;
435 m_peer
->ReleaseMouse() ;
438 #if wxUSE_DRAG_AND_DROP
440 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
444 m_dropTarget
= pDropTarget
;
445 if ( m_dropTarget
!= NULL
)
453 // Old-style File Manager Drag & Drop
454 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
459 // From a wx position / size calculate the appropriate size of the native control
461 bool wxWindowMac::MacGetBoundsForControl(
465 int& w
, int& h
, bool adjustOrigin
) const
467 // the desired size, minus the border pixels gives the correct size of the control
471 w
= WidthDefault( size
.x
);
472 h
= HeightDefault( size
.y
);
474 x
+= MacGetLeftBorderSize() ;
475 y
+= MacGetTopBorderSize() ;
476 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
477 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
480 AdjustForParentClientOrigin( x
, y
) ;
482 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
483 if ( GetParent() && !GetParent()->IsTopLevel() )
485 x
-= GetParent()->MacGetLeftBorderSize() ;
486 y
-= GetParent()->MacGetTopBorderSize() ;
492 // Get window size (not client size)
493 void wxWindowMac::DoGetSize(int *x
, int *y
) const
496 m_peer
->GetSize( width
, height
);
499 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
501 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
504 // get the position of the bounds of this window in client coordinates of its parent
505 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
509 m_peer
->GetPosition( x1
, y1
) ;
511 // get the wx window position from the native one
512 x1
-= MacGetLeftBorderSize() ;
513 y1
-= MacGetTopBorderSize() ;
517 wxWindow
*parent
= GetParent();
520 // we must first adjust it to be in window coordinates of the parent,
521 // as otherwise it gets lost by the ClientAreaOrigin fix
522 x1
+= parent
->MacGetLeftBorderSize() ;
523 y1
+= parent
->MacGetTopBorderSize() ;
525 // and now to client coordinates
526 wxPoint
pt(parent
->GetClientAreaOrigin());
538 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
540 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
541 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
542 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
543 MacRootWindowToWindow( x
, y
) ;
545 wxPoint origin
= GetClientAreaOrigin() ;
552 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
554 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
555 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
557 wxPoint origin
= GetClientAreaOrigin() ;
563 MacWindowToRootWindow( x
, y
) ;
564 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
567 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
569 wxPoint origin
= GetClientAreaOrigin() ;
575 MacWindowToRootWindow( x
, y
) ;
578 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
589 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
592 pt
.x
-= MacGetLeftBorderSize() ;
593 pt
.y
-= MacGetTopBorderSize() ;
594 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
604 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
615 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
618 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
619 pt
.x
+= MacGetLeftBorderSize() ;
620 pt
.y
+= MacGetTopBorderSize() ;
630 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
632 wxSize sizeTotal
= size
;
634 int innerwidth
, innerheight
;
636 int outerwidth
, outerheight
;
638 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
639 m_peer
->GetSize( outerwidth
, outerheight
);
641 sizeTotal
.x
+= outerwidth
-innerwidth
;
642 sizeTotal
.y
+= outerheight
-innerheight
;
644 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
645 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
650 // Get size *available for subwindows* i.e. excluding menu bar etc.
651 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
657 m_peer
->GetContentArea( left
, top
, ww
, hh
);
659 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
660 hh
-= m_hScrollBar
->GetSize().y
;
662 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
663 ww
-= m_vScrollBar
->GetSize().x
;
671 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
673 if (m_cursor
.IsSameAs(cursor
))
678 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
683 if ( ! wxWindowBase::SetCursor( cursor
) )
687 wxASSERT_MSG( m_cursor
.Ok(),
688 wxT("cursor must be valid after call to the base version"));
690 if ( GetPeer() != NULL
)
691 GetPeer()->SetCursor( m_cursor
);
697 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
699 #ifndef __WXUNIVERSAL__
700 menu
->SetInvokingWindow((wxWindow
*)this);
703 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
705 wxPoint mouse
= wxGetMousePosition();
711 ClientToScreen( &x
, &y
) ;
713 menu
->GetPeer()->PopUp(this, x
, y
);
714 menu
->SetInvokingWindow( NULL
);
717 // actually this shouldn't be called, because universal is having its own implementation
723 // ----------------------------------------------------------------------------
725 // ----------------------------------------------------------------------------
729 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
731 wxWindowBase::DoSetToolTip(tooltip
);
734 m_tooltip
->SetWindow(this);
739 void wxWindowMac::MacInvalidateBorders()
741 if ( m_peer
== NULL
)
744 bool vis
= IsShownOnScreen() ;
748 int outerBorder
= MacGetLeftBorderSize() ;
750 if ( m_peer
->NeedsFocusRect() )
753 if ( outerBorder
== 0 )
756 // now we know that we have something to do at all
760 m_peer
->GetSize( tw
, th
);
761 m_peer
->GetPosition( tx
, ty
);
763 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
764 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
765 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
766 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
769 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
770 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
771 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
772 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
776 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
778 // this is never called for a toplevel window, so we know we have a parent
779 int former_x
, former_y
, former_w
, former_h
;
781 // Get true coordinates of former position
782 DoGetPosition( &former_x
, &former_y
) ;
783 DoGetSize( &former_w
, &former_h
) ;
785 wxWindow
*parent
= GetParent();
788 wxPoint
pt(parent
->GetClientAreaOrigin());
793 int actualWidth
= width
;
794 int actualHeight
= height
;
799 // min and max sizes are only for sizers, not for explicit size setting
800 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
801 actualWidth
= m_minWidth
;
802 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
803 actualHeight
= m_minHeight
;
804 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
805 actualWidth
= m_maxWidth
;
806 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
807 actualHeight
= m_maxHeight
;
810 bool doMove
= false, doResize
= false ;
812 if ( actualX
!= former_x
|| actualY
!= former_y
)
815 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
818 if ( doMove
|| doResize
)
820 // as the borders are drawn outside the native control, we adjust now
822 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
823 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
824 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
826 if ( parent
&& !parent
->IsTopLevel() )
828 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
831 MacInvalidateBorders() ;
833 m_cachedClippedRectValid
= false ;
835 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
837 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
839 MacInvalidateBorders() ;
841 MacRepositionScrollBars() ;
844 wxPoint
point(actualX
, actualY
);
845 wxMoveEvent
event(point
, m_windowId
);
846 event
.SetEventObject(this);
847 HandleWindowEvent(event
) ;
852 MacRepositionScrollBars() ;
853 wxSize
size(actualWidth
, actualHeight
);
854 wxSizeEvent
event(size
, m_windowId
);
855 event
.SetEventObject(this);
856 HandleWindowEvent(event
);
861 wxSize
wxWindowMac::DoGetBestSize() const
863 if ( m_macIsUserPane
|| IsTopLevel() )
865 return wxWindowBase::DoGetBestSize() ;
871 m_peer
->GetBestRect(&r
);
873 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
880 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
885 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
892 // return wxWindowBase::DoGetBestSize() ;
896 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
897 MacGetRightBorderSize();
898 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
899 MacGetBottomBorderSize();
900 if ( bestHeight
< 10 )
903 return wxSize(bestWidth
, bestHeight
);
907 // set the size of the window: if the dimensions are positive, just use them,
908 // but if any of them is equal to -1, it means that we must find the value for
909 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
910 // which case -1 is a valid value for x and y)
912 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
913 // the width/height to best suit our contents, otherwise we reuse the current
915 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
917 // get the current size and position...
918 int currentX
, currentY
;
919 int currentW
, currentH
;
921 GetPosition(¤tX
, ¤tY
);
922 GetSize(¤tW
, ¤tH
);
924 // ... and don't do anything (avoiding flicker) if it's already ok
925 if ( x
== currentX
&& y
== currentY
&&
926 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
929 MacRepositionScrollBars() ; // we might have a real position shift
931 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
933 wxSizeEvent
event( wxSize(width
,height
), GetId() );
934 event
.SetEventObject( this );
935 HandleWindowEvent( event
);
941 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
943 if ( x
== wxDefaultCoord
)
945 if ( y
== wxDefaultCoord
)
949 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
951 wxSize size
= wxDefaultSize
;
952 if ( width
== wxDefaultCoord
)
954 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
956 size
= DoGetBestSize();
961 // just take the current one
966 if ( height
== wxDefaultCoord
)
968 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
970 if ( size
.x
== wxDefaultCoord
)
971 size
= DoGetBestSize();
972 // else: already called DoGetBestSize() above
978 // just take the current one
983 DoMoveWindow( x
, y
, width
, height
);
986 wxPoint
wxWindowMac::GetClientAreaOrigin() const
988 int left
,top
,width
,height
;
989 m_peer
->GetContentArea( left
, top
, width
, height
);
990 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
993 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
995 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
997 int currentclientwidth
, currentclientheight
;
998 int currentwidth
, currentheight
;
1000 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1001 GetSize( ¤twidth
, ¤theight
) ;
1003 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1004 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1008 void wxWindowMac::SetLabel(const wxString
& title
)
1012 if ( m_peer
&& m_peer
->IsOk() && !(IsKindOf( CLASSINFO(wxButton
) ) && GetId() == wxID_HELP
) )
1013 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1015 // do not trigger refreshes upon invisible and possible partly created objects
1016 if ( IsShownOnScreen() )
1020 wxString
wxWindowMac::GetLabel() const
1025 bool wxWindowMac::Show(bool show
)
1027 if ( !wxWindowBase::Show(show
) )
1031 m_peer
->SetVisibility( show
) ;
1036 void wxWindowMac::DoEnable(bool enable
)
1038 m_peer
->Enable( enable
) ;
1042 // status change notifications
1045 void wxWindowMac::MacVisibilityChanged()
1049 void wxWindowMac::MacHiliteChanged()
1053 void wxWindowMac::MacEnabledStateChanged()
1055 OnEnabled( m_peer
->IsEnabled() );
1059 // status queries on the inherited window's state
1062 bool wxWindowMac::MacIsReallyEnabled()
1064 return m_peer
->IsEnabled() ;
1067 bool wxWindowMac::MacIsReallyHilited()
1069 #if wxOSX_USE_CARBON
1070 return m_peer
->IsActive();
1072 return true; // TODO
1076 int wxWindowMac::GetCharHeight() const
1079 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1084 int wxWindowMac::GetCharWidth() const
1087 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1092 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1093 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1095 const wxFont
*fontToUse
= theFont
;
1099 tempFont
= GetFont();
1100 fontToUse
= &tempFont
;
1103 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1104 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1106 wxDouble h
, d
, e
, w
;
1107 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1111 if ( externalLeading
)
1112 *externalLeading
= (wxCoord
)(e
+0.5);
1114 *descent
= (wxCoord
)(d
+0.5);
1116 *x
= (wxCoord
)(w
+0.5);
1118 *y
= (wxCoord
)(h
+0.5);
1122 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1123 * we always intersect with the entire window, not only with the client area
1126 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1128 if ( m_peer
== NULL
)
1131 if ( !IsShownOnScreen() )
1134 m_peer
->SetNeedsDisplay( rect
) ;
1137 void wxWindowMac::DoFreeze()
1139 #if wxOSX_USE_CARBON
1140 if ( m_peer
&& m_peer
->IsOk() )
1141 m_peer
->SetDrawingEnabled( false ) ;
1145 void wxWindowMac::DoThaw()
1147 #if wxOSX_USE_CARBON
1148 if ( m_peer
&& m_peer
->IsOk() )
1150 m_peer
->SetDrawingEnabled( true ) ;
1151 m_peer
->InvalidateWithChildren() ;
1156 wxWindow
*wxGetActiveWindow()
1158 // actually this is a windows-only concept
1162 // Coordinates relative to the window
1163 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1165 // We really don't move the mouse programmatically under Mac.
1168 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1170 if ( MacGetTopLevelWindow() == NULL
)
1173 #if TARGET_API_MAC_OSX
1174 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1180 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1182 event
.GetDC()->Clear() ;
1184 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1186 // don't skip the event here, custom background means that the app
1187 // is drawing it itself in its OnPaint(), so don't draw it at all
1188 // now to avoid flicker
1196 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1201 int wxWindowMac::GetScrollPos(int orient
) const
1203 if ( orient
== wxHORIZONTAL
)
1206 return m_hScrollBar
->GetThumbPosition() ;
1211 return m_vScrollBar
->GetThumbPosition() ;
1217 // This now returns the whole range, not just the number
1218 // of positions that we can scroll.
1219 int wxWindowMac::GetScrollRange(int orient
) const
1221 if ( orient
== wxHORIZONTAL
)
1224 return m_hScrollBar
->GetRange() ;
1229 return m_vScrollBar
->GetRange() ;
1235 int wxWindowMac::GetScrollThumb(int orient
) const
1237 if ( orient
== wxHORIZONTAL
)
1240 return m_hScrollBar
->GetThumbSize() ;
1245 return m_vScrollBar
->GetThumbSize() ;
1251 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1253 if ( orient
== wxHORIZONTAL
)
1256 m_hScrollBar
->SetThumbPosition( pos
) ;
1261 m_vScrollBar
->SetThumbPosition( pos
) ;
1266 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1268 bool needVisibilityUpdate
= false;
1270 if ( m_hScrollBarAlwaysShown
!= hflag
)
1272 m_hScrollBarAlwaysShown
= hflag
;
1273 needVisibilityUpdate
= true;
1276 if ( m_vScrollBarAlwaysShown
!= vflag
)
1278 m_vScrollBarAlwaysShown
= vflag
;
1279 needVisibilityUpdate
= true;
1282 if ( needVisibilityUpdate
)
1283 DoUpdateScrollbarVisibility();
1287 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1288 // our own window origin is at leftOrigin/rightOrigin
1291 void wxWindowMac::MacPaintGrowBox()
1296 if ( MacHasScrollBarCorner() )
1298 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1299 wxASSERT( cgContext
) ;
1303 m_peer
->GetSize( tw
, th
);
1304 m_peer
->GetPosition( tx
, ty
);
1306 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1309 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1310 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1311 CGContextSaveGState( cgContext
);
1313 if ( m_backgroundColour
.Ok() )
1315 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1319 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1321 CGContextFillRect( cgContext
, cgrect
);
1322 CGContextRestoreGState( cgContext
);
1326 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1331 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1333 // back to the surrounding frame rectangle
1336 m_peer
->GetSize( tw
, th
);
1337 m_peer
->GetPosition( tx
, ty
);
1339 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1341 #if wxOSX_USE_COCOA_OR_CARBON
1343 InsetRect( &rect
, -1 , -1 ) ;
1346 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1347 rect
.bottom
- rect
.top
) ;
1349 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1350 wxASSERT( cgContext
) ;
1352 if ( m_peer
->NeedsFrame() )
1354 HIThemeFrameDrawInfo info
;
1355 memset( &info
, 0 , sizeof(info
) ) ;
1359 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1360 info
.isFocused
= hasFocus
;
1362 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1364 info
.kind
= kHIThemeFrameTextFieldSquare
;
1365 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1367 else if ( HasFlag(wxSIMPLE_BORDER
) )
1369 info
.kind
= kHIThemeFrameListBox
;
1370 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1376 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1379 #endif // wxOSX_USE_COCOA_OR_CARBON
1382 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1384 if ( child
== m_hScrollBar
)
1385 m_hScrollBar
= NULL
;
1386 if ( child
== m_vScrollBar
)
1387 m_vScrollBar
= NULL
;
1389 wxWindowBase::RemoveChild( child
) ;
1392 void wxWindowMac::DoUpdateScrollbarVisibility()
1394 bool triggerSizeEvent
= false;
1398 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1400 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1402 m_hScrollBar
->Show( showHScrollBar
);
1403 triggerSizeEvent
= true;
1409 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1411 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1413 m_vScrollBar
->Show( showVScrollBar
) ;
1414 triggerSizeEvent
= true;
1418 MacRepositionScrollBars() ;
1419 if ( triggerSizeEvent
)
1421 wxSizeEvent
event(GetSize(), m_windowId
);
1422 event
.SetEventObject(this);
1423 HandleWindowEvent(event
);
1427 // New function that will replace some of the above.
1428 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1429 int range
, bool refresh
)
1431 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1432 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1433 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1434 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1436 DoUpdateScrollbarVisibility();
1439 // Does a physical scroll
1440 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1442 if ( dx
== 0 && dy
== 0 )
1445 int width
, height
;
1446 GetClientSize( &width
, &height
) ;
1449 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1451 scrollrect
.Intersect( *rect
) ;
1452 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1453 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1455 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1460 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1462 child
= node
->GetData();
1465 if (child
== m_vScrollBar
)
1467 if (child
== m_hScrollBar
)
1469 if (child
->IsTopLevel())
1472 child
->GetPosition( &x
, &y
);
1473 child
->GetSize( &w
, &h
);
1476 wxRect
rc( x
, y
, w
, h
);
1477 if (rect
->Intersects( rc
))
1478 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1482 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1487 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1489 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1491 wxScrollWinEvent wevent
;
1492 wevent
.SetPosition(event
.GetPosition());
1493 wevent
.SetOrientation(event
.GetOrientation());
1494 wevent
.SetEventObject(this);
1496 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1497 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1498 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1499 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1500 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1501 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1502 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1503 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1504 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1505 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1506 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1507 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1508 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1509 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1510 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1511 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1513 HandleWindowEvent(wevent
);
1517 wxWindow
*wxWindowBase::DoFindFocus()
1519 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1522 void wxWindowMac::OnInternalIdle()
1524 // This calls the UI-update mechanism (querying windows for
1525 // menu/toolbar/control state information)
1526 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1527 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1530 // Raise the window to the top of the Z order
1531 void wxWindowMac::Raise()
1536 // Lower the window to the bottom of the Z order
1537 void wxWindowMac::Lower()
1542 // static wxWindow *gs_lastWhich = NULL;
1544 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1546 // first trigger a set cursor event
1548 wxPoint clientorigin
= GetClientAreaOrigin() ;
1549 wxSize clientsize
= GetClientSize() ;
1551 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1553 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1555 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1556 if ( processedEvtSetCursor
&& event
.HasCursor() )
1558 cursor
= event
.GetCursor() ;
1562 // the test for processedEvtSetCursor is here to prevent using m_cursor
1563 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1564 // it - this is a way to say that our cursor shouldn't be used for this
1566 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1569 if ( !wxIsBusy() && !GetParent() )
1570 cursor
= *wxSTANDARD_CURSOR
;
1574 cursor
.MacInstall() ;
1577 return cursor
.Ok() ;
1580 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1584 return m_tooltip
->GetTip() ;
1587 return wxEmptyString
;
1590 void wxWindowMac::ClearBackground()
1596 void wxWindowMac::Update()
1598 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1603 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1605 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1609 if ( iter
->IsTopLevel() )
1611 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1615 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1620 iter
= iter
->GetParent() ;
1626 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1628 MacUpdateClippedRects() ;
1630 return m_cachedClippedClientRect
;
1633 const wxRect
& wxWindowMac::MacGetClippedRect() const
1635 MacUpdateClippedRects() ;
1637 return m_cachedClippedRect
;
1640 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1642 MacUpdateClippedRects() ;
1644 return m_cachedClippedRectWithOuterStructure
;
1647 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1649 static wxRegion emptyrgn
;
1651 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1653 MacUpdateClippedRects() ;
1654 if ( includeOuterStructures
)
1655 return m_cachedClippedRegionWithOuterStructure
;
1657 return m_cachedClippedRegion
;
1665 void wxWindowMac::MacUpdateClippedRects() const
1667 #if wxOSX_USE_CARBON
1668 if ( m_cachedClippedRectValid
)
1671 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1672 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1673 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1674 // to add focus borders everywhere
1676 Rect rIncludingOuterStructures
;
1680 m_peer
->GetSize( tw
, th
);
1681 m_peer
->GetPosition( tx
, ty
);
1683 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1685 r
.left
-= MacGetLeftBorderSize() ;
1686 r
.top
-= MacGetTopBorderSize() ;
1687 r
.bottom
+= MacGetBottomBorderSize() ;
1688 r
.right
+= MacGetRightBorderSize() ;
1695 rIncludingOuterStructures
= r
;
1696 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1698 wxRect cl
= GetClientRect() ;
1699 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1703 const wxWindow
* child
= (wxWindow
*) this ;
1704 const wxWindow
* parent
= NULL
;
1706 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1708 if ( parent
->MacIsChildOfClientArea(child
) )
1710 size
= parent
->GetClientSize() ;
1711 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1717 // this will be true for scrollbars, toolbars etc.
1718 size
= parent
->GetSize() ;
1719 y
= parent
->MacGetTopBorderSize() ;
1720 x
= parent
->MacGetLeftBorderSize() ;
1721 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1722 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1725 parent
->MacWindowToRootWindow( &x
, &y
) ;
1726 MacRootWindowToWindow( &x
, &y
) ;
1728 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1730 // the wxwindow and client rects will always be clipped
1731 SectRect( &r
, &rparent
, &r
) ;
1732 SectRect( &rClient
, &rparent
, &rClient
) ;
1734 // the structure only at 'hard' borders
1735 if ( parent
->MacClipChildren() ||
1736 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1738 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1744 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1745 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1746 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1747 m_cachedClippedRectWithOuterStructure
= wxRect(
1748 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1749 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1750 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1752 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1753 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1754 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1756 m_cachedClippedRectValid
= true ;
1761 This function must not change the updatergn !
1763 bool wxWindowMac::MacDoRedraw( long time
)
1765 bool handled
= false ;
1767 wxRegion formerUpdateRgn
= m_updateRegion
;
1768 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1770 wxSize sz
= GetClientSize() ;
1771 wxPoint origin
= GetClientAreaOrigin() ;
1773 clientUpdateRgn
.Intersect(origin
.x
, origin
.y
, origin
.x
+ sz
.x
, origin
.y
+ sz
.y
);
1775 // first send an erase event to the entire update area
1777 // for the toplevel window this really is the entire area
1778 // for all the others only their client area, otherwise they
1779 // might be drawing with full alpha and eg put blue into
1780 // the grow-box area of a scrolled window (scroll sample)
1781 wxDC
* dc
= new wxWindowDC(this);
1783 dc
->SetDeviceClippingRegion(formerUpdateRgn
);
1785 dc
->SetDeviceClippingRegion(clientUpdateRgn
);
1787 wxEraseEvent
eevent( GetId(), dc
);
1788 eevent
.SetEventObject( this );
1789 HandleWindowEvent( eevent
);
1795 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1796 clientUpdateRgn
.Offset( -origin
.x
, -origin
.y
);
1797 m_updateRegion
= clientUpdateRgn
;
1799 if ( !m_updateRegion
.Empty() )
1801 // paint the window itself
1803 wxPaintEvent
event(GetId());
1804 event
.SetTimestamp(time
);
1805 event
.SetEventObject(this);
1806 handled
= HandleWindowEvent(event
);
1809 m_updateRegion
= formerUpdateRgn
;
1813 void wxWindowMac::MacPaintChildrenBorders()
1815 // now we cannot rely on having its borders drawn by a window itself, as it does not
1816 // get the updateRgn wide enough to always do so, so we do it from the parent
1817 // this would also be the place to draw any custom backgrounds for native controls
1818 // in Composited windowing
1819 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1823 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1825 child
= node
->GetData();
1828 if (child
== m_vScrollBar
)
1830 if (child
== m_hScrollBar
)
1832 if (child
->IsTopLevel())
1834 if (!child
->IsShown())
1837 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1839 child
->GetPosition( &x
, &y
);
1840 child
->GetSize( &w
, &h
);
1842 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
1844 // paint custom borders
1845 wxNcPaintEvent
eventNc( child
->GetId() );
1846 eventNc
.SetEventObject( child
);
1847 if ( !child
->HandleWindowEvent( eventNc
) )
1849 child
->MacPaintBorders(0, 0) ;
1856 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1858 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1859 return tlw
? tlw
->GetWXWindow() : NULL
;
1862 bool wxWindowMac::MacHasScrollBarCorner() const
1864 /* Returns whether the scroll bars in a wxScrolledWindow should be
1865 * shortened. Scroll bars should be shortened if either:
1867 * - both scroll bars are visible, or
1869 * - there is a resize box in the parent frame's corner and this
1870 * window shares the bottom and right edge with the parent
1874 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1877 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1878 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1880 // Both scroll bars visible
1885 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1887 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1889 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1892 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1894 // Parent frame has resize handle
1895 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1897 // Note: allow for some wiggle room here as wxMac's
1898 // window rect calculations seem to be imprecise
1899 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1900 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1902 // Parent frame has resize handle and shares
1903 // right bottom corner
1908 // Parent frame has resize handle but doesn't
1909 // share right bottom corner
1915 // Parent frame doesn't have resize handle
1921 // No parent frame found
1926 void wxWindowMac::MacCreateScrollBars( long style
)
1928 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1930 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1932 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1933 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1935 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
1938 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
1940 GetClientSize( &width
, &height
) ;
1942 wxPoint
vPoint(width
- scrlsize
, 0) ;
1943 wxSize
vSize(scrlsize
, height
- adjust
) ;
1944 wxPoint
hPoint(0, height
- scrlsize
) ;
1945 wxSize
hSize(width
- adjust
, scrlsize
) ;
1947 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
1948 if ( style
& wxVSCROLL
)
1950 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
1951 m_vScrollBar
->SetMinSize( wxDefaultSize
);
1954 if ( style
& wxHSCROLL
)
1956 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
1957 m_hScrollBar
->SetMinSize( wxDefaultSize
);
1961 // because the create does not take into account the client area origin
1962 // we might have a real position shift
1963 MacRepositionScrollBars() ;
1966 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
1968 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
1973 void wxWindowMac::MacRepositionScrollBars()
1975 if ( !m_hScrollBar
&& !m_vScrollBar
)
1978 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1979 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
1981 // get real client area
1983 GetSize( &width
, &height
);
1985 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1986 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1988 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
1989 wxSize
vSize( scrlsize
, height
- adjust
) ;
1990 wxPoint
hPoint( 0 , height
- scrlsize
) ;
1991 wxSize
hSize( width
- adjust
, scrlsize
) ;
1994 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1996 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1999 bool wxWindowMac::AcceptsFocus() const
2001 if ( MacIsUserPane() )
2002 return wxWindowBase::AcceptsFocus();
2004 return m_peer
->CanFocus();
2007 void wxWindowMac::MacSuperChangedPosition()
2009 // only window-absolute structures have to be moved i.e. controls
2011 m_cachedClippedRectValid
= false ;
2014 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2017 child
= node
->GetData();
2018 child
->MacSuperChangedPosition() ;
2020 node
= node
->GetNext();
2024 void wxWindowMac::MacTopLevelWindowChangedPosition()
2026 // only screen-absolute structures have to be moved i.e. glcanvas
2029 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2032 child
= node
->GetData();
2033 child
->MacTopLevelWindowChangedPosition() ;
2035 node
= node
->GetNext();
2039 long wxWindowMac::MacGetLeftBorderSize() const
2046 if ( m_peer
&& m_peer
->NeedsFrame() )
2048 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2050 #if wxOSX_USE_COCOA_OR_CARBON
2051 // this metric is only the 'outset' outside the simple frame rect
2052 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2058 else if (HasFlag(wxSIMPLE_BORDER
))
2060 #if wxOSX_USE_COCOA_OR_CARBON
2061 // this metric is only the 'outset' outside the simple frame rect
2062 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2073 long wxWindowMac::MacGetRightBorderSize() const
2075 // they are all symmetric in mac themes
2076 return MacGetLeftBorderSize() ;
2079 long wxWindowMac::MacGetTopBorderSize() const
2081 // they are all symmetric in mac themes
2082 return MacGetLeftBorderSize() ;
2085 long wxWindowMac::MacGetBottomBorderSize() const
2087 // they are all symmetric in mac themes
2088 return MacGetLeftBorderSize() ;
2091 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2093 return style
& ~wxBORDER_MASK
;
2096 // Find the wxWindowMac at the current mouse position, returning the mouse
2098 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2100 pt
= wxGetMousePosition();
2101 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2103 return (wxWindow
*) found
;
2106 // Get the current mouse position.
2107 wxPoint
wxGetMousePosition()
2111 wxGetMousePosition( &x
, &y
);
2113 return wxPoint(x
, y
);
2116 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2118 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2120 // copied from wxGTK : CS
2121 // VZ: shouldn't we move this to base class then?
2123 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2126 // (a) it's a command event and so is propagated to the parent
2127 // (b) under MSW it can be generated from kbd too
2128 // (c) it uses screen coords (because of (a))
2129 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2131 this->ClientToScreen(event
.GetPosition()));
2132 evtCtx
.SetEventObject(this);
2133 if ( ! HandleWindowEvent(evtCtx
) )
2142 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2146 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2150 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2151 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2156 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2161 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2163 #if wxOSX_USE_COCOA_OR_CARBON
2164 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2167 return eventNotHandledErr
;
2173 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2175 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2176 if ( !wxWindowBase::Reparent(newParent
) )
2179 m_peer
->RemoveFromParent();
2180 m_peer
->Embed( GetParent()->GetPeer() );
2184 bool wxWindowMac::SetTransparent(wxByte alpha
)
2186 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2188 if ( alpha
!= m_macAlpha
)
2190 m_macAlpha
= alpha
;
2197 bool wxWindowMac::CanSetTransparent()
2202 wxByte
wxWindowMac::GetTransparent() const
2207 bool wxWindowMac::IsShownOnScreen() const
2209 if ( m_peer
&& m_peer
->IsOk() )
2211 bool peerVis
= m_peer
->IsVisible();
2212 bool wxVis
= wxWindowBase::IsShownOnScreen();
2213 if( peerVis
!= wxVis
)
2215 // CS : put a breakpoint here to investigate differences
2216 // between native an wx visibilities
2217 // the only place where I've encountered them until now
2218 // are the hiding/showing sequences where the vis-changed event is
2219 // first sent to the innermost control, while wx does things
2220 // from the outmost control
2221 wxVis
= wxWindowBase::IsShownOnScreen();
2225 return m_peer
->IsVisible();
2227 return wxWindowBase::IsShownOnScreen();
2230 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2232 bool handled
= HandleWindowEvent( event
) ;
2233 if ( handled
&& event
.GetSkipped() )
2237 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2239 wxWindow
*ancestor
= this;
2242 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2245 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2247 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2248 handled
= handler
->ProcessEvent( command_event
);
2252 // accelerators can also be used with buttons, try them too
2253 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2254 handled
= handler
->ProcessEvent( command_event
);
2260 if (ancestor
->IsTopLevel())
2263 ancestor
= ancestor
->GetParent();
2266 #endif // wxUSE_ACCEL
2275 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2277 static MacControlMap wxWinMacControlList
;
2279 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2281 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2283 return impl
->GetWXPeer();
2288 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2290 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2292 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2295 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2297 // adding NULL ControlRef is (first) surely a result of an error and
2298 // (secondly) breaks native event processing
2299 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2301 wxWinMacControlList
[inControl
] = impl
;
2304 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2306 // iterate over all the elements in the class
2307 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2308 // we should go on...
2314 MacControlMap::iterator it
;
2315 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2317 if ( it
->second
== impl
)
2319 wxWinMacControlList
.erase(it
);
2327 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2329 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2332 m_isRootControl
= isRootControl
;
2336 wxWidgetImpl::wxWidgetImpl()
2341 wxWidgetImpl::~wxWidgetImpl()
2345 void wxWidgetImpl::Init()
2347 m_isRootControl
= false;
2349 m_needsFocusRect
= false;
2350 m_needsFrame
= true;
2353 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2355 m_needsFocusRect
= needs
;
2358 bool wxWidgetImpl::NeedsFocusRect() const
2360 return m_needsFocusRect
;
2363 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2365 m_needsFrame
= needs
;
2368 bool wxWidgetImpl::NeedsFrame() const
2370 return m_needsFrame
;