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() ;
204 // TODO END move to window_osx.cpp
207 // ---------------------------------------------------------------------------
208 // Utility Routines to move between different coordinate systems
209 // ---------------------------------------------------------------------------
212 * Right now we have the following setup :
213 * a border that is not part of the native control is always outside the
214 * control's border (otherwise we loose all native intelligence, future ways
215 * may be to have a second embedding control responsible for drawing borders
216 * and backgrounds eventually)
217 * so all this border calculations have to be taken into account when calling
218 * native methods or getting native oriented data
219 * so we have three coordinate systems here
220 * wx client coordinates
221 * wx window coordinates (including window frames)
229 bool wxWindowMac::Create(wxWindowMac
*parent
,
234 const wxString
& name
)
236 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
238 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
241 m_windowVariant
= parent
->GetWindowVariant() ;
243 if ( m_macIsUserPane
)
245 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
246 MacPostControlCreate(pos
, size
) ;
249 #ifndef __WXUNIVERSAL__
250 // Don't give scrollbars to wxControls unless they ask for them
251 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
252 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
254 MacCreateScrollBars( style
) ;
258 wxWindowCreateEvent
event((wxWindow
*)this);
259 GetEventHandler()->AddPendingEvent(event
);
264 void wxWindowMac::MacChildAdded()
267 m_vScrollBar
->Raise() ;
269 m_hScrollBar
->Raise() ;
272 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
274 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
276 GetParent()->AddChild( this );
278 m_peer
->InstallEventHandler();
279 m_peer
->Embed(GetParent()->GetPeer());
281 GetParent()->MacChildAdded() ;
283 // adjust font, controlsize etc
284 DoSetWindowVariant( m_windowVariant
) ;
286 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
288 // for controls we want to use best size for wxDefaultSize params )
289 if ( !m_macIsUserPane
)
290 SetInitialSize(size
);
292 SetCursor( *wxSTANDARD_CURSOR
) ;
295 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
297 // Don't assert, in case we set the window variant before
298 // the window is created
299 // wxASSERT( m_peer->Ok() ) ;
301 m_windowVariant
= variant
;
303 if (m_peer
== NULL
|| !m_peer
->IsOk())
306 m_peer
->SetControlSize( variant
);
310 // we will get that from the settings later
311 // and make this NORMAL later, but first
312 // we have a few calculations that we must fix
316 case wxWINDOW_VARIANT_NORMAL
:
317 size
= kControlSizeNormal
;
320 case wxWINDOW_VARIANT_SMALL
:
321 size
= kControlSizeSmall
;
324 case wxWINDOW_VARIANT_MINI
:
325 // not always defined in the headers
329 case wxWINDOW_VARIANT_LARGE
:
330 size
= kControlSizeLarge
;
334 wxFAIL_MSG(_T("unexpected window variant"));
337 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
342 wxOSXSystemFont systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
346 case wxWINDOW_VARIANT_NORMAL
:
347 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
350 case wxWINDOW_VARIANT_SMALL
:
351 systemFont
= wxOSX_SYSTEM_FONT_SMALL
;
354 case wxWINDOW_VARIANT_MINI
:
355 systemFont
= wxOSX_SYSTEM_FONT_MINI
;
358 case wxWINDOW_VARIANT_LARGE
:
359 systemFont
= wxOSX_SYSTEM_FONT_NORMAL
;
363 wxFAIL_MSG(_T("unexpected window variant"));
367 font
.CreateSystemFont( systemFont
) ;
372 void wxWindowMac::MacUpdateControlFont()
375 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
377 // do not trigger refreshes upon invisible and possible partly created objects
378 if ( IsShownOnScreen() )
382 bool wxWindowMac::SetFont(const wxFont
& font
)
384 bool retval
= wxWindowBase::SetFont( font
);
386 MacUpdateControlFont() ;
391 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
393 bool retval
= wxWindowBase::SetForegroundColour( col
);
396 MacUpdateControlFont();
401 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
403 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
407 m_peer
->SetBackgroundColour( col
) ;
412 void wxWindowMac::SetFocus()
414 if ( !AcceptsFocus() )
417 wxWindow
* former
= FindFocus() ;
418 if ( former
== this )
424 void wxWindowMac::DoCaptureMouse()
426 wxApp::s_captureWindow
= (wxWindow
*) this ;
427 m_peer
->CaptureMouse() ;
430 wxWindow
* wxWindowBase::GetCapture()
432 return wxApp::s_captureWindow
;
435 void wxWindowMac::DoReleaseMouse()
437 wxApp::s_captureWindow
= NULL
;
439 m_peer
->ReleaseMouse() ;
442 #if wxUSE_DRAG_AND_DROP
444 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
448 m_dropTarget
= pDropTarget
;
449 if ( m_dropTarget
!= NULL
)
457 // Old-style File Manager Drag & Drop
458 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
463 // From a wx position / size calculate the appropriate size of the native control
465 bool wxWindowMac::MacGetBoundsForControl(
469 int& w
, int& h
, bool adjustOrigin
) const
471 // the desired size, minus the border pixels gives the correct size of the control
475 w
= WidthDefault( size
.x
);
476 h
= HeightDefault( size
.y
);
478 x
+= MacGetLeftBorderSize() ;
479 y
+= MacGetTopBorderSize() ;
480 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
481 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
484 AdjustForParentClientOrigin( x
, y
) ;
486 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
487 if ( GetParent() && !GetParent()->IsTopLevel() )
489 x
-= GetParent()->MacGetLeftBorderSize() ;
490 y
-= GetParent()->MacGetTopBorderSize() ;
496 // Get window size (not client size)
497 void wxWindowMac::DoGetSize(int *x
, int *y
) const
500 m_peer
->GetSize( width
, height
);
503 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
505 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
508 // get the position of the bounds of this window in client coordinates of its parent
509 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
513 m_peer
->GetPosition( x1
, y1
) ;
515 // get the wx window position from the native one
516 x1
-= MacGetLeftBorderSize() ;
517 y1
-= MacGetTopBorderSize() ;
521 wxWindow
*parent
= GetParent();
524 // we must first adjust it to be in window coordinates of the parent,
525 // as otherwise it gets lost by the ClientAreaOrigin fix
526 x1
+= parent
->MacGetLeftBorderSize() ;
527 y1
+= parent
->MacGetTopBorderSize() ;
529 // and now to client coordinates
530 wxPoint
pt(parent
->GetClientAreaOrigin());
542 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
544 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
545 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
546 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
547 MacRootWindowToWindow( x
, y
) ;
549 wxPoint origin
= GetClientAreaOrigin() ;
556 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
558 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
559 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
561 wxPoint origin
= GetClientAreaOrigin() ;
567 MacWindowToRootWindow( x
, y
) ;
568 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
571 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
573 wxPoint origin
= GetClientAreaOrigin() ;
579 MacWindowToRootWindow( x
, y
) ;
582 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
593 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
596 pt
.x
-= MacGetLeftBorderSize() ;
597 pt
.y
-= MacGetTopBorderSize() ;
598 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
608 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
619 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
622 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
623 pt
.x
+= MacGetLeftBorderSize() ;
624 pt
.y
+= MacGetTopBorderSize() ;
634 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
636 wxSize sizeTotal
= size
;
638 int innerwidth
, innerheight
;
640 int outerwidth
, outerheight
;
642 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
643 m_peer
->GetSize( outerwidth
, outerheight
);
645 sizeTotal
.x
+= outerwidth
-innerwidth
;
646 sizeTotal
.y
+= outerheight
-innerheight
;
648 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
649 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
654 // Get size *available for subwindows* i.e. excluding menu bar etc.
655 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
661 m_peer
->GetContentArea( left
, top
, ww
, hh
);
663 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
664 hh
-= m_hScrollBar
->GetSize().y
;
666 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
667 ww
-= m_vScrollBar
->GetSize().x
;
675 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
677 if (m_cursor
.IsSameAs(cursor
))
682 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
687 if ( ! wxWindowBase::SetCursor( cursor
) )
691 wxASSERT_MSG( m_cursor
.Ok(),
692 wxT("cursor must be valid after call to the base version"));
694 if ( GetPeer() != NULL
)
695 GetPeer()->SetCursor( m_cursor
);
701 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
703 #ifndef __WXUNIVERSAL__
704 menu
->SetInvokingWindow((wxWindow
*)this);
707 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
709 wxPoint mouse
= wxGetMousePosition();
715 ClientToScreen( &x
, &y
) ;
717 menu
->GetPeer()->PopUp(this, x
, y
);
718 menu
->SetInvokingWindow( NULL
);
721 // actually this shouldn't be called, because universal is having its own implementation
727 // ----------------------------------------------------------------------------
729 // ----------------------------------------------------------------------------
733 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
735 wxWindowBase::DoSetToolTip(tooltip
);
738 m_tooltip
->SetWindow(this);
743 void wxWindowMac::MacInvalidateBorders()
745 if ( m_peer
== NULL
)
748 bool vis
= IsShownOnScreen() ;
752 int outerBorder
= MacGetLeftBorderSize() ;
754 if ( m_peer
->NeedsFocusRect() )
757 if ( outerBorder
== 0 )
760 // now we know that we have something to do at all
764 m_peer
->GetSize( tw
, th
);
765 m_peer
->GetPosition( tx
, ty
);
767 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
768 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
769 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
770 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
773 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
774 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
775 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
776 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
780 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
782 // this is never called for a toplevel window, so we know we have a parent
783 int former_x
, former_y
, former_w
, former_h
;
785 // Get true coordinates of former position
786 DoGetPosition( &former_x
, &former_y
) ;
787 DoGetSize( &former_w
, &former_h
) ;
789 wxWindow
*parent
= GetParent();
792 wxPoint
pt(parent
->GetClientAreaOrigin());
797 int actualWidth
= width
;
798 int actualHeight
= height
;
802 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
803 actualWidth
= m_minWidth
;
804 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
805 actualHeight
= m_minHeight
;
806 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
807 actualWidth
= m_maxWidth
;
808 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
809 actualHeight
= m_maxHeight
;
811 bool doMove
= false, doResize
= false ;
813 if ( actualX
!= former_x
|| actualY
!= former_y
)
816 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
819 if ( doMove
|| doResize
)
821 // as the borders are drawn outside the native control, we adjust now
823 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
824 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
825 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
827 if ( parent
&& !parent
->IsTopLevel() )
829 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
832 MacInvalidateBorders() ;
834 m_cachedClippedRectValid
= false ;
836 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
838 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
840 MacInvalidateBorders() ;
842 MacRepositionScrollBars() ;
845 wxPoint
point(actualX
, actualY
);
846 wxMoveEvent
event(point
, m_windowId
);
847 event
.SetEventObject(this);
848 HandleWindowEvent(event
) ;
853 MacRepositionScrollBars() ;
854 wxSize
size(actualWidth
, actualHeight
);
855 wxSizeEvent
event(size
, m_windowId
);
856 event
.SetEventObject(this);
857 HandleWindowEvent(event
);
862 wxSize
wxWindowMac::DoGetBestSize() const
864 if ( m_macIsUserPane
|| IsTopLevel() )
866 return wxWindowBase::DoGetBestSize() ;
872 m_peer
->GetBestRect(&r
);
874 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
881 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
886 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
893 // return wxWindowBase::DoGetBestSize() ;
897 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
898 MacGetRightBorderSize();
899 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
900 MacGetBottomBorderSize();
901 if ( bestHeight
< 10 )
904 return wxSize(bestWidth
, bestHeight
);
908 // set the size of the window: if the dimensions are positive, just use them,
909 // but if any of them is equal to -1, it means that we must find the value for
910 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
911 // which case -1 is a valid value for x and y)
913 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
914 // the width/height to best suit our contents, otherwise we reuse the current
916 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
918 // get the current size and position...
919 int currentX
, currentY
;
920 int currentW
, currentH
;
922 GetPosition(¤tX
, ¤tY
);
923 GetSize(¤tW
, ¤tH
);
925 // ... and don't do anything (avoiding flicker) if it's already ok
926 if ( x
== currentX
&& y
== currentY
&&
927 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
930 MacRepositionScrollBars() ; // we might have a real position shift
932 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
934 wxSizeEvent
event( wxSize(width
,height
), GetId() );
935 event
.SetEventObject( this );
936 HandleWindowEvent( event
);
942 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
944 if ( x
== wxDefaultCoord
)
946 if ( y
== wxDefaultCoord
)
950 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
952 wxSize size
= wxDefaultSize
;
953 if ( width
== wxDefaultCoord
)
955 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
957 size
= DoGetBestSize();
962 // just take the current one
967 if ( height
== wxDefaultCoord
)
969 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
971 if ( size
.x
== wxDefaultCoord
)
972 size
= DoGetBestSize();
973 // else: already called DoGetBestSize() above
979 // just take the current one
984 DoMoveWindow( x
, y
, width
, height
);
987 wxPoint
wxWindowMac::GetClientAreaOrigin() const
989 int left
,top
,width
,height
;
990 m_peer
->GetContentArea( left
, top
, width
, height
);
991 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
994 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
996 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
998 int currentclientwidth
, currentclientheight
;
999 int currentwidth
, currentheight
;
1001 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1002 GetSize( ¤twidth
, ¤theight
) ;
1004 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1005 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1009 void wxWindowMac::SetLabel(const wxString
& title
)
1013 if ( m_peer
&& m_peer
->IsOk() && !(IsKindOf( CLASSINFO(wxButton
) ) && GetId() == wxID_HELP
) )
1014 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1016 // do not trigger refreshes upon invisible and possible partly created objects
1017 if ( IsShownOnScreen() )
1021 wxString
wxWindowMac::GetLabel() const
1026 bool wxWindowMac::Show(bool show
)
1028 if ( !wxWindowBase::Show(show
) )
1032 m_peer
->SetVisibility( show
) ;
1037 void wxWindowMac::DoEnable(bool enable
)
1039 m_peer
->Enable( enable
) ;
1043 // status change notifications
1046 void wxWindowMac::MacVisibilityChanged()
1050 void wxWindowMac::MacHiliteChanged()
1054 void wxWindowMac::MacEnabledStateChanged()
1056 OnEnabled( m_peer
->IsEnabled() );
1060 // status queries on the inherited window's state
1063 bool wxWindowMac::MacIsReallyEnabled()
1065 return m_peer
->IsEnabled() ;
1068 bool wxWindowMac::MacIsReallyHilited()
1070 #if wxOSX_USE_CARBON
1071 return m_peer
->IsActive();
1073 return true; // TODO
1077 int wxWindowMac::GetCharHeight() const
1080 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1085 int wxWindowMac::GetCharWidth() const
1088 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1093 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1094 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1096 const wxFont
*fontToUse
= theFont
;
1100 tempFont
= GetFont();
1101 fontToUse
= &tempFont
;
1104 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1105 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1107 wxDouble h
, d
, e
, w
;
1108 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1112 if ( externalLeading
)
1113 *externalLeading
= (wxCoord
)(e
+0.5);
1115 *descent
= (wxCoord
)(d
+0.5);
1117 *x
= (wxCoord
)(w
+0.5);
1119 *y
= (wxCoord
)(h
+0.5);
1123 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1124 * we always intersect with the entire window, not only with the client area
1127 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1129 if ( m_peer
== NULL
)
1132 if ( !IsShownOnScreen() )
1135 m_peer
->SetNeedsDisplay( rect
) ;
1138 void wxWindowMac::DoFreeze()
1140 #if wxOSX_USE_CARBON
1141 if ( m_peer
&& m_peer
->IsOk() )
1142 m_peer
->SetDrawingEnabled( false ) ;
1146 void wxWindowMac::DoThaw()
1148 #if wxOSX_USE_CARBON
1149 if ( m_peer
&& m_peer
->IsOk() )
1151 m_peer
->SetDrawingEnabled( true ) ;
1152 m_peer
->InvalidateWithChildren() ;
1157 wxWindow
*wxGetActiveWindow()
1159 // actually this is a windows-only concept
1163 // Coordinates relative to the window
1164 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1166 // We really don't move the mouse programmatically under Mac.
1169 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1171 if ( MacGetTopLevelWindow() == NULL
)
1174 #if TARGET_API_MAC_OSX
1175 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1181 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1183 event
.GetDC()->Clear() ;
1185 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1187 // don't skip the event here, custom background means that the app
1188 // is drawing it itself in its OnPaint(), so don't draw it at all
1189 // now to avoid flicker
1197 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1202 int wxWindowMac::GetScrollPos(int orient
) const
1204 if ( orient
== wxHORIZONTAL
)
1207 return m_hScrollBar
->GetThumbPosition() ;
1212 return m_vScrollBar
->GetThumbPosition() ;
1218 // This now returns the whole range, not just the number
1219 // of positions that we can scroll.
1220 int wxWindowMac::GetScrollRange(int orient
) const
1222 if ( orient
== wxHORIZONTAL
)
1225 return m_hScrollBar
->GetRange() ;
1230 return m_vScrollBar
->GetRange() ;
1236 int wxWindowMac::GetScrollThumb(int orient
) const
1238 if ( orient
== wxHORIZONTAL
)
1241 return m_hScrollBar
->GetThumbSize() ;
1246 return m_vScrollBar
->GetThumbSize() ;
1252 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1254 if ( orient
== wxHORIZONTAL
)
1257 m_hScrollBar
->SetThumbPosition( pos
) ;
1262 m_vScrollBar
->SetThumbPosition( pos
) ;
1267 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1269 bool needVisibilityUpdate
= false;
1271 if ( m_hScrollBarAlwaysShown
!= hflag
)
1273 m_hScrollBarAlwaysShown
= hflag
;
1274 needVisibilityUpdate
= true;
1277 if ( m_vScrollBarAlwaysShown
!= vflag
)
1279 m_vScrollBarAlwaysShown
= vflag
;
1280 needVisibilityUpdate
= true;
1283 if ( needVisibilityUpdate
)
1284 DoUpdateScrollbarVisibility();
1288 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1289 // our own window origin is at leftOrigin/rightOrigin
1292 void wxWindowMac::MacPaintGrowBox()
1297 if ( MacHasScrollBarCorner() )
1299 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1300 wxASSERT( cgContext
) ;
1304 m_peer
->GetSize( tw
, th
);
1305 m_peer
->GetPosition( tx
, ty
);
1307 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1310 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1311 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1312 CGContextSaveGState( cgContext
);
1314 if ( m_backgroundColour
.Ok() )
1316 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1320 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1322 CGContextFillRect( cgContext
, cgrect
);
1323 CGContextRestoreGState( cgContext
);
1327 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1332 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1334 // back to the surrounding frame rectangle
1337 m_peer
->GetSize( tw
, th
);
1338 m_peer
->GetPosition( tx
, ty
);
1340 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1342 #if wxOSX_USE_COCOA_OR_CARBON
1344 InsetRect( &rect
, -1 , -1 ) ;
1347 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1348 rect
.bottom
- rect
.top
) ;
1350 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1351 wxASSERT( cgContext
) ;
1353 if ( m_peer
->NeedsFrame() )
1355 HIThemeFrameDrawInfo info
;
1356 memset( &info
, 0 , sizeof(info
) ) ;
1360 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1361 info
.isFocused
= hasFocus
;
1363 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1365 info
.kind
= kHIThemeFrameTextFieldSquare
;
1366 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1368 else if ( HasFlag(wxSIMPLE_BORDER
) )
1370 info
.kind
= kHIThemeFrameListBox
;
1371 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1377 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1380 #endif // wxOSX_USE_COCOA_OR_CARBON
1383 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1385 if ( child
== m_hScrollBar
)
1386 m_hScrollBar
= NULL
;
1387 if ( child
== m_vScrollBar
)
1388 m_vScrollBar
= NULL
;
1390 wxWindowBase::RemoveChild( child
) ;
1393 void wxWindowMac::DoUpdateScrollbarVisibility()
1395 bool triggerSizeEvent
= false;
1399 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1401 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1403 m_hScrollBar
->Show( showHScrollBar
);
1404 triggerSizeEvent
= true;
1410 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1412 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1414 m_vScrollBar
->Show( showVScrollBar
) ;
1415 triggerSizeEvent
= true;
1419 MacRepositionScrollBars() ;
1420 if ( triggerSizeEvent
)
1422 wxSizeEvent
event(GetSize(), m_windowId
);
1423 event
.SetEventObject(this);
1424 HandleWindowEvent(event
);
1428 // New function that will replace some of the above.
1429 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1430 int range
, bool refresh
)
1432 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1433 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1434 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1435 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1437 DoUpdateScrollbarVisibility();
1440 // Does a physical scroll
1441 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1443 if ( dx
== 0 && dy
== 0 )
1446 int width
, height
;
1447 GetClientSize( &width
, &height
) ;
1450 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1452 scrollrect
.Intersect( *rect
) ;
1453 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1454 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1456 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1461 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1463 child
= node
->GetData();
1466 if (child
== m_vScrollBar
)
1468 if (child
== m_hScrollBar
)
1470 if (child
->IsTopLevel())
1473 child
->GetPosition( &x
, &y
);
1474 child
->GetSize( &w
, &h
);
1477 wxRect
rc( x
, y
, w
, h
);
1478 if (rect
->Intersects( rc
))
1479 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1483 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1488 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1490 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1492 wxScrollWinEvent wevent
;
1493 wevent
.SetPosition(event
.GetPosition());
1494 wevent
.SetOrientation(event
.GetOrientation());
1495 wevent
.SetEventObject(this);
1497 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1498 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1499 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1500 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1501 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1502 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1503 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1504 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1505 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1506 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1507 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1508 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1509 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1510 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1511 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1512 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1514 HandleWindowEvent(wevent
);
1518 // Get the window with the focus
1519 wxWindow
*wxWindowBase::DoFindFocus()
1521 #if wxOSX_USE_CARBON
1522 ControlRef control
;
1523 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1524 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1530 void wxWindowMac::OnInternalIdle()
1532 // This calls the UI-update mechanism (querying windows for
1533 // menu/toolbar/control state information)
1534 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1535 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1538 // Raise the window to the top of the Z order
1539 void wxWindowMac::Raise()
1544 // Lower the window to the bottom of the Z order
1545 void wxWindowMac::Lower()
1550 // static wxWindow *gs_lastWhich = NULL;
1552 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1554 // first trigger a set cursor event
1556 wxPoint clientorigin
= GetClientAreaOrigin() ;
1557 wxSize clientsize
= GetClientSize() ;
1559 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1561 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1563 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1564 if ( processedEvtSetCursor
&& event
.HasCursor() )
1566 cursor
= event
.GetCursor() ;
1570 // the test for processedEvtSetCursor is here to prevent using m_cursor
1571 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1572 // it - this is a way to say that our cursor shouldn't be used for this
1574 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1577 if ( !wxIsBusy() && !GetParent() )
1578 cursor
= *wxSTANDARD_CURSOR
;
1582 cursor
.MacInstall() ;
1585 return cursor
.Ok() ;
1588 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1592 return m_tooltip
->GetTip() ;
1595 return wxEmptyString
;
1598 void wxWindowMac::ClearBackground()
1604 void wxWindowMac::Update()
1606 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1611 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1613 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1617 if ( iter
->IsTopLevel() )
1619 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1623 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1628 iter
= iter
->GetParent() ;
1634 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1636 MacUpdateClippedRects() ;
1638 return m_cachedClippedClientRect
;
1641 const wxRect
& wxWindowMac::MacGetClippedRect() const
1643 MacUpdateClippedRects() ;
1645 return m_cachedClippedRect
;
1648 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1650 MacUpdateClippedRects() ;
1652 return m_cachedClippedRectWithOuterStructure
;
1655 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1657 static wxRegion emptyrgn
;
1659 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1661 MacUpdateClippedRects() ;
1662 if ( includeOuterStructures
)
1663 return m_cachedClippedRegionWithOuterStructure
;
1665 return m_cachedClippedRegion
;
1673 void wxWindowMac::MacUpdateClippedRects() const
1675 #if wxOSX_USE_CARBON
1676 if ( m_cachedClippedRectValid
)
1679 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1680 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1681 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1682 // to add focus borders everywhere
1684 Rect rIncludingOuterStructures
;
1688 m_peer
->GetSize( tw
, th
);
1689 m_peer
->GetPosition( tx
, ty
);
1691 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1693 r
.left
-= MacGetLeftBorderSize() ;
1694 r
.top
-= MacGetTopBorderSize() ;
1695 r
.bottom
+= MacGetBottomBorderSize() ;
1696 r
.right
+= MacGetRightBorderSize() ;
1703 rIncludingOuterStructures
= r
;
1704 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1706 wxRect cl
= GetClientRect() ;
1707 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1711 const wxWindow
* child
= (wxWindow
*) this ;
1712 const wxWindow
* parent
= NULL
;
1714 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1716 if ( parent
->MacIsChildOfClientArea(child
) )
1718 size
= parent
->GetClientSize() ;
1719 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1725 // this will be true for scrollbars, toolbars etc.
1726 size
= parent
->GetSize() ;
1727 y
= parent
->MacGetTopBorderSize() ;
1728 x
= parent
->MacGetLeftBorderSize() ;
1729 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1730 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1733 parent
->MacWindowToRootWindow( &x
, &y
) ;
1734 MacRootWindowToWindow( &x
, &y
) ;
1736 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1738 // the wxwindow and client rects will always be clipped
1739 SectRect( &r
, &rparent
, &r
) ;
1740 SectRect( &rClient
, &rparent
, &rClient
) ;
1742 // the structure only at 'hard' borders
1743 if ( parent
->MacClipChildren() ||
1744 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1746 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1752 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1753 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1754 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1755 m_cachedClippedRectWithOuterStructure
= wxRect(
1756 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1757 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1758 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1760 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1761 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1762 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1764 m_cachedClippedRectValid
= true ;
1769 This function must not change the updatergn !
1771 bool wxWindowMac::MacDoRedraw( long time
)
1773 bool handled
= false ;
1775 wxRegion formerUpdateRgn
= m_updateRegion
;
1776 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1778 wxSize sz
= GetClientSize() ;
1779 wxPoint origin
= GetClientAreaOrigin() ;
1781 clientUpdateRgn
.Intersect(origin
.x
, origin
.y
, origin
.x
+ sz
.x
, origin
.y
+ sz
.y
);
1783 // first send an erase event to the entire update area
1785 // for the toplevel window this really is the entire area
1786 // for all the others only their client area, otherwise they
1787 // might be drawing with full alpha and eg put blue into
1788 // the grow-box area of a scrolled window (scroll sample)
1789 wxDC
* dc
= new wxWindowDC(this);
1791 dc
->SetDeviceClippingRegion(formerUpdateRgn
);
1793 dc
->SetDeviceClippingRegion(clientUpdateRgn
);
1795 wxEraseEvent
eevent( GetId(), dc
);
1796 eevent
.SetEventObject( this );
1797 HandleWindowEvent( eevent
);
1803 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1804 clientUpdateRgn
.Offset( -origin
.x
, -origin
.y
);
1805 m_updateRegion
= clientUpdateRgn
;
1807 if ( !m_updateRegion
.Empty() )
1809 // paint the window itself
1811 wxPaintEvent
event(GetId());
1812 event
.SetTimestamp(time
);
1813 event
.SetEventObject(this);
1814 handled
= HandleWindowEvent(event
);
1817 m_updateRegion
= formerUpdateRgn
;
1821 void wxWindowMac::MacPaintChildrenBorders()
1823 // now we cannot rely on having its borders drawn by a window itself, as it does not
1824 // get the updateRgn wide enough to always do so, so we do it from the parent
1825 // this would also be the place to draw any custom backgrounds for native controls
1826 // in Composited windowing
1827 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1831 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1833 child
= node
->GetData();
1836 if (child
== m_vScrollBar
)
1838 if (child
== m_hScrollBar
)
1840 if (child
->IsTopLevel())
1842 if (!child
->IsShown())
1845 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1847 child
->GetPosition( &x
, &y
);
1848 child
->GetSize( &w
, &h
);
1850 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
1852 // paint custom borders
1853 wxNcPaintEvent
eventNc( child
->GetId() );
1854 eventNc
.SetEventObject( child
);
1855 if ( !child
->HandleWindowEvent( eventNc
) )
1857 child
->MacPaintBorders(0, 0) ;
1864 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1866 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1867 return tlw
? tlw
->GetWXWindow() : NULL
;
1870 bool wxWindowMac::MacHasScrollBarCorner() const
1872 /* Returns whether the scroll bars in a wxScrolledWindow should be
1873 * shortened. Scroll bars should be shortened if either:
1875 * - both scroll bars are visible, or
1877 * - there is a resize box in the parent frame's corner and this
1878 * window shares the bottom and right edge with the parent
1882 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1885 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1886 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1888 // Both scroll bars visible
1893 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1895 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1897 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1900 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1902 // Parent frame has resize handle
1903 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1905 // Note: allow for some wiggle room here as wxMac's
1906 // window rect calculations seem to be imprecise
1907 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1908 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1910 // Parent frame has resize handle and shares
1911 // right bottom corner
1916 // Parent frame has resize handle but doesn't
1917 // share right bottom corner
1923 // Parent frame doesn't have resize handle
1929 // No parent frame found
1934 void wxWindowMac::MacCreateScrollBars( long style
)
1936 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1938 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1940 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1941 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1943 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
1946 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
1948 GetClientSize( &width
, &height
) ;
1950 wxPoint
vPoint(width
- scrlsize
, 0) ;
1951 wxSize
vSize(scrlsize
, height
- adjust
) ;
1952 wxPoint
hPoint(0, height
- scrlsize
) ;
1953 wxSize
hSize(width
- adjust
, scrlsize
) ;
1955 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
1956 if ( style
& wxVSCROLL
)
1958 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
1959 m_vScrollBar
->SetMinSize( wxDefaultSize
);
1962 if ( style
& wxHSCROLL
)
1964 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
1965 m_hScrollBar
->SetMinSize( wxDefaultSize
);
1969 // because the create does not take into account the client area origin
1970 // we might have a real position shift
1971 MacRepositionScrollBars() ;
1974 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
1976 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
1981 void wxWindowMac::MacRepositionScrollBars()
1983 if ( !m_hScrollBar
&& !m_vScrollBar
)
1986 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1987 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
1989 // get real client area
1991 GetSize( &width
, &height
);
1993 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1994 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1996 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
1997 wxSize
vSize( scrlsize
, height
- adjust
) ;
1998 wxPoint
hPoint( 0 , height
- scrlsize
) ;
1999 wxSize
hSize( width
- adjust
, scrlsize
) ;
2002 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2004 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2007 bool wxWindowMac::AcceptsFocus() const
2009 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2012 void wxWindowMac::MacSuperChangedPosition()
2014 // only window-absolute structures have to be moved i.e. controls
2016 m_cachedClippedRectValid
= false ;
2019 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2022 child
= node
->GetData();
2023 child
->MacSuperChangedPosition() ;
2025 node
= node
->GetNext();
2029 void wxWindowMac::MacTopLevelWindowChangedPosition()
2031 // only screen-absolute structures have to be moved i.e. glcanvas
2034 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2037 child
= node
->GetData();
2038 child
->MacTopLevelWindowChangedPosition() ;
2040 node
= node
->GetNext();
2044 long wxWindowMac::MacGetLeftBorderSize() const
2051 if ( m_peer
&& m_peer
->NeedsFrame() )
2053 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2055 #if wxOSX_USE_COCOA_OR_CARBON
2056 // this metric is only the 'outset' outside the simple frame rect
2057 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2063 else if (HasFlag(wxSIMPLE_BORDER
))
2065 #if wxOSX_USE_COCOA_OR_CARBON
2066 // this metric is only the 'outset' outside the simple frame rect
2067 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2078 long wxWindowMac::MacGetRightBorderSize() const
2080 // they are all symmetric in mac themes
2081 return MacGetLeftBorderSize() ;
2084 long wxWindowMac::MacGetTopBorderSize() const
2086 // they are all symmetric in mac themes
2087 return MacGetLeftBorderSize() ;
2090 long wxWindowMac::MacGetBottomBorderSize() const
2092 // they are all symmetric in mac themes
2093 return MacGetLeftBorderSize() ;
2096 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2098 return style
& ~wxBORDER_MASK
;
2101 // Find the wxWindowMac at the current mouse position, returning the mouse
2103 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2105 pt
= wxGetMousePosition();
2106 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2108 return (wxWindow
*) found
;
2111 // Get the current mouse position.
2112 wxPoint
wxGetMousePosition()
2116 wxGetMousePosition( &x
, &y
);
2118 return wxPoint(x
, y
);
2121 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2123 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2125 // copied from wxGTK : CS
2126 // VZ: shouldn't we move this to base class then?
2128 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2131 // (a) it's a command event and so is propagated to the parent
2132 // (b) under MSW it can be generated from kbd too
2133 // (c) it uses screen coords (because of (a))
2134 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2136 this->ClientToScreen(event
.GetPosition()));
2137 evtCtx
.SetEventObject(this);
2138 if ( ! HandleWindowEvent(evtCtx
) )
2147 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2151 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2155 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2156 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2161 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2166 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2168 #if wxOSX_USE_COCOA_OR_CARBON
2169 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2172 return eventNotHandledErr
;
2178 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2180 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2181 if ( !wxWindowBase::Reparent(newParent
) )
2184 m_peer
->RemoveFromParent();
2185 m_peer
->Embed( GetParent()->GetPeer() );
2189 bool wxWindowMac::SetTransparent(wxByte alpha
)
2191 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2193 if ( alpha
!= m_macAlpha
)
2195 m_macAlpha
= alpha
;
2202 bool wxWindowMac::CanSetTransparent()
2207 wxByte
wxWindowMac::GetTransparent() const
2212 bool wxWindowMac::IsShownOnScreen() const
2214 if ( m_peer
&& m_peer
->IsOk() )
2216 bool peerVis
= m_peer
->IsVisible();
2217 bool wxVis
= wxWindowBase::IsShownOnScreen();
2218 if( peerVis
!= wxVis
)
2220 // CS : put a breakpoint here to investigate differences
2221 // between native an wx visibilities
2222 // the only place where I've encountered them until now
2223 // are the hiding/showing sequences where the vis-changed event is
2224 // first sent to the innermost control, while wx does things
2225 // from the outmost control
2226 wxVis
= wxWindowBase::IsShownOnScreen();
2230 return m_peer
->IsVisible();
2232 return wxWindowBase::IsShownOnScreen();
2235 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2237 bool handled
= HandleWindowEvent( event
) ;
2238 if ( handled
&& event
.GetSkipped() )
2242 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2244 wxWindow
*ancestor
= this;
2247 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2250 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2252 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2253 handled
= handler
->ProcessEvent( command_event
);
2257 // accelerators can also be used with buttons, try them too
2258 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2259 handled
= handler
->ProcessEvent( command_event
);
2265 if (ancestor
->IsTopLevel())
2268 ancestor
= ancestor
->GetParent();
2271 #endif // wxUSE_ACCEL
2280 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2282 static MacControlMap wxWinMacControlList
;
2284 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2286 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2288 return impl
->GetWXPeer();
2293 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2295 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2297 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2300 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2302 // adding NULL ControlRef is (first) surely a result of an error and
2303 // (secondly) breaks native event processing
2304 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2306 wxWinMacControlList
[inControl
] = impl
;
2309 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2311 // iterate over all the elements in the class
2312 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2313 // we should go on...
2319 MacControlMap::iterator it
;
2320 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2322 if ( it
->second
== impl
)
2324 wxWinMacControlList
.erase(it
);
2332 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2334 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2337 m_isRootControl
= isRootControl
;
2341 wxWidgetImpl::wxWidgetImpl()
2346 wxWidgetImpl::~wxWidgetImpl()
2350 void wxWidgetImpl::Init()
2352 m_isRootControl
= false;
2354 m_needsFocusRect
= false;
2355 m_needsFrame
= true;
2358 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2360 m_needsFocusRect
= needs
;
2363 bool wxWidgetImpl::NeedsFocusRect() const
2365 return m_needsFocusRect
;
2368 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2370 m_needsFrame
= needs
;
2373 bool wxWidgetImpl::NeedsFrame() const
2375 return m_needsFrame
;