1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
57 #include "wx/popupwin.h"
60 #if wxUSE_DRAG_AND_DROP
64 #include "wx/graphics.h"
67 #include "wx/osx/uma.h"
69 #include "wx/osx/private.h"
71 #include <Carbon/Carbon.h>
74 #define MAC_SCROLLBAR_SIZE 15
75 #define MAC_SMALL_SCROLLBAR_SIZE 11
79 #ifdef __WXUNIVERSAL__
80 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
82 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
85 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
86 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
87 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
88 EVT_PAINT(wxWindowMac::OnPaint
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
92 #define wxMAC_DEBUG_REDRAW 0
93 #ifndef wxMAC_DEBUG_REDRAW
94 #define wxMAC_DEBUG_REDRAW 0
97 // ===========================================================================
99 // ===========================================================================
101 // ----------------------------------------------------------------------------
102 // constructors and such
103 // ----------------------------------------------------------------------------
105 wxWindowMac::wxWindowMac()
110 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
115 const wxString
& name
)
118 Create(parent
, id
, pos
, size
, style
, name
);
121 void wxWindowMac::Init()
125 m_cgContextRef
= NULL
;
127 // as all windows are created with WS_VISIBLE style...
130 m_hScrollBar
= NULL
;
131 m_vScrollBar
= NULL
;
132 m_hScrollBarAlwaysShown
= false;
133 m_vScrollBarAlwaysShown
= false;
135 m_macIsUserPane
= true;
136 m_clipChildren
= false ;
137 m_cachedClippedRectValid
= false ;
140 wxWindowMac::~wxWindowMac()
144 m_isBeingDeleted
= true;
146 MacInvalidateBorders() ;
148 #ifndef __WXUNIVERSAL__
149 // VS: make sure there's no wxFrame with last focus set to us:
150 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
152 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
155 if ( frame
->GetLastFocus() == this )
156 frame
->SetLastFocus((wxWindow
*)NULL
);
162 // destroy children before destroying this window itself
165 // wxRemoveMacControlAssociation( this ) ;
166 // If we delete an item, we should initialize the parent panel,
167 // because it could now be invalid.
168 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
171 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
172 tlw
->SetDefaultItem(NULL
);
175 if ( g_MacLastWindow
== this )
176 g_MacLastWindow
= NULL
;
178 #ifndef __WXUNIVERSAL__
179 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
182 if ( frame
->GetLastFocus() == this )
183 frame
->SetLastFocus( NULL
) ;
187 // delete our drop target if we've got one
188 #if wxUSE_DRAG_AND_DROP
189 if ( m_dropTarget
!= NULL
)
199 WXWidget
wxWindowMac::GetHandle() const
201 return (WXWidget
) m_peer
->GetWXWidget() ;
205 // TODO END move to window_osx.cpp
208 // ---------------------------------------------------------------------------
209 // Utility Routines to move between different coordinate systems
210 // ---------------------------------------------------------------------------
213 * Right now we have the following setup :
214 * a border that is not part of the native control is always outside the
215 * control's border (otherwise we loose all native intelligence, future ways
216 * may be to have a second embedding control responsible for drawing borders
217 * and backgrounds eventually)
218 * so all this border calculations have to be taken into account when calling
219 * native methods or getting native oriented data
220 * so we have three coordinate systems here
221 * wx client coordinates
222 * wx window coordinates (including window frames)
230 bool wxWindowMac::Create(wxWindowMac
*parent
,
235 const wxString
& name
)
237 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
239 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
242 m_windowVariant
= parent
->GetWindowVariant() ;
244 if ( m_macIsUserPane
)
246 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
247 MacPostControlCreate(pos
, size
) ;
250 #ifndef __WXUNIVERSAL__
251 // Don't give scrollbars to wxControls unless they ask for them
252 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
253 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
255 MacCreateScrollBars( style
) ;
259 wxWindowCreateEvent
event((wxWindow
*)this);
260 GetEventHandler()->AddPendingEvent(event
);
265 void wxWindowMac::MacChildAdded()
268 m_vScrollBar
->Raise() ;
270 m_hScrollBar
->Raise() ;
273 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
275 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
277 GetParent()->AddChild( this );
279 m_peer
->InstallEventHandler();
280 m_peer
->Embed(GetParent()->GetPeer());
282 GetParent()->MacChildAdded() ;
284 // adjust font, controlsize etc
285 DoSetWindowVariant( m_windowVariant
) ;
287 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
289 // for controls we want to use best size for wxDefaultSize params )
290 if ( !m_macIsUserPane
)
291 SetInitialSize(size
);
293 SetCursor( *wxSTANDARD_CURSOR
) ;
296 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
298 // Don't assert, in case we set the window variant before
299 // the window is created
300 // wxASSERT( m_peer->Ok() ) ;
302 m_windowVariant
= variant
;
304 if (m_peer
== NULL
|| !m_peer
->IsOk())
307 m_peer
->SetControlSize( variant
);
311 // we will get that from the settings later
312 // and make this NORMAL later, but first
313 // we have a few calculations that we must fix
317 case wxWINDOW_VARIANT_NORMAL
:
318 size
= kControlSizeNormal
;
321 case wxWINDOW_VARIANT_SMALL
:
322 size
= kControlSizeSmall
;
325 case wxWINDOW_VARIANT_MINI
:
326 // not always defined in the headers
330 case wxWINDOW_VARIANT_LARGE
:
331 size
= kControlSizeLarge
;
335 wxFAIL_MSG(_T("unexpected window variant"));
338 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
341 #if wxOSX_USE_COCOA_OR_CARBON
344 #if wxOSX_USE_ATSU_TEXT
346 ThemeFontID themeFont
= kThemeSystemFont
;
348 // we will get that from the settings later
349 // and make this NORMAL later, but first
350 // we have a few calculations that we must fix
354 case wxWINDOW_VARIANT_NORMAL
:
355 size
= kControlSizeNormal
;
356 themeFont
= kThemeSystemFont
;
359 case wxWINDOW_VARIANT_SMALL
:
360 size
= kControlSizeSmall
;
361 themeFont
= kThemeSmallSystemFont
;
364 case wxWINDOW_VARIANT_MINI
:
365 // not always defined in the headers
370 case wxWINDOW_VARIANT_LARGE
:
371 size
= kControlSizeLarge
;
372 themeFont
= kThemeSystemFont
;
376 wxFAIL_MSG(_T("unexpected window variant"));
380 font
.MacCreateFromThemeFont( themeFont
) ;
382 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
385 case wxWINDOW_VARIANT_NORMAL
:
386 themeFont
= kCTFontSystemFontType
;
389 case wxWINDOW_VARIANT_SMALL
:
390 themeFont
= kCTFontSmallSystemFontType
;
393 case wxWINDOW_VARIANT_MINI
:
394 themeFont
= kCTFontMiniSystemFontType
;
397 case wxWINDOW_VARIANT_LARGE
:
398 themeFont
= kCTFontSystemFontType
;
402 wxFAIL_MSG(_T("unexpected window variant"));
405 font
.MacCreateFromUIFont( themeFont
) ;
412 void wxWindowMac::MacUpdateControlFont()
415 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
417 // do not trigger refreshes upon invisible and possible partly created objects
418 if ( IsShownOnScreen() )
422 bool wxWindowMac::SetFont(const wxFont
& font
)
424 bool retval
= wxWindowBase::SetFont( font
);
426 MacUpdateControlFont() ;
431 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
433 bool retval
= wxWindowBase::SetForegroundColour( col
);
436 MacUpdateControlFont();
441 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
443 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
447 m_peer
->SetBackgroundColour( col
) ;
452 void wxWindowMac::SetFocus()
454 if ( !AcceptsFocus() )
457 wxWindow
* former
= FindFocus() ;
458 if ( former
== this )
464 void wxWindowMac::DoCaptureMouse()
466 wxApp::s_captureWindow
= (wxWindow
*) this ;
469 wxWindow
* wxWindowBase::GetCapture()
471 return wxApp::s_captureWindow
;
474 void wxWindowMac::DoReleaseMouse()
476 wxApp::s_captureWindow
= NULL
;
479 #if wxUSE_DRAG_AND_DROP
481 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
485 m_dropTarget
= pDropTarget
;
486 if ( m_dropTarget
!= NULL
)
494 // Old-style File Manager Drag & Drop
495 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
500 // From a wx position / size calculate the appropriate size of the native control
502 bool wxWindowMac::MacGetBoundsForControl(
506 int& w
, int& h
, bool adjustOrigin
) const
508 // the desired size, minus the border pixels gives the correct size of the control
512 w
= WidthDefault( size
.x
);
513 h
= HeightDefault( size
.y
);
515 x
+= MacGetLeftBorderSize() ;
516 y
+= MacGetTopBorderSize() ;
517 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
518 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
521 AdjustForParentClientOrigin( x
, y
) ;
523 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
524 if ( GetParent() && !GetParent()->IsTopLevel() )
526 x
-= GetParent()->MacGetLeftBorderSize() ;
527 y
-= GetParent()->MacGetTopBorderSize() ;
533 // Get window size (not client size)
534 void wxWindowMac::DoGetSize(int *x
, int *y
) const
537 m_peer
->GetSize( width
, height
);
540 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
542 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
545 // get the position of the bounds of this window in client coordinates of its parent
546 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
550 m_peer
->GetPosition( x1
, y1
) ;
552 // get the wx window position from the native one
553 x1
-= MacGetLeftBorderSize() ;
554 y1
-= MacGetTopBorderSize() ;
558 wxWindow
*parent
= GetParent();
561 // we must first adjust it to be in window coordinates of the parent,
562 // as otherwise it gets lost by the ClientAreaOrigin fix
563 x1
+= parent
->MacGetLeftBorderSize() ;
564 y1
+= parent
->MacGetTopBorderSize() ;
566 // and now to client coordinates
567 wxPoint
pt(parent
->GetClientAreaOrigin());
579 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
581 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
582 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
583 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
584 MacRootWindowToWindow( x
, y
) ;
586 wxPoint origin
= GetClientAreaOrigin() ;
593 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
595 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
596 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
598 wxPoint origin
= GetClientAreaOrigin() ;
604 MacWindowToRootWindow( x
, y
) ;
605 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
608 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
610 wxPoint origin
= GetClientAreaOrigin() ;
616 MacWindowToRootWindow( x
, y
) ;
619 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
630 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
633 pt
.x
-= MacGetLeftBorderSize() ;
634 pt
.y
-= MacGetTopBorderSize() ;
635 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
645 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
656 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
659 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
660 pt
.x
+= MacGetLeftBorderSize() ;
661 pt
.y
+= MacGetTopBorderSize() ;
671 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
673 wxSize sizeTotal
= size
;
675 int innerwidth
, innerheight
;
677 int outerwidth
, outerheight
;
679 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
680 m_peer
->GetSize( outerwidth
, outerheight
);
682 sizeTotal
.x
+= left
+ (outerwidth
-innerwidth
);
683 sizeTotal
.y
+= top
+ (outerheight
-innerheight
);
685 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
686 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
691 // Get size *available for subwindows* i.e. excluding menu bar etc.
692 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
698 m_peer
->GetContentArea( left
, top
, ww
, hh
);
700 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
701 hh
-= m_hScrollBar
->GetSize().y
;
703 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
704 ww
-= m_vScrollBar
->GetSize().x
;
712 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
714 if (m_cursor
.IsSameAs(cursor
))
719 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
724 if ( ! wxWindowBase::SetCursor( cursor
) )
728 wxASSERT_MSG( m_cursor
.Ok(),
729 wxT("cursor must be valid after call to the base version"));
731 wxWindowMac
*mouseWin
= 0 ;
734 wxNonOwnedWindow
*tlw
= MacGetTopLevelWindow() ;
735 WindowRef window
= (WindowRef
) ( tlw
? tlw
->GetWXWindow() : 0 ) ;
737 ControlPartCode part
;
740 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
742 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
746 GetGlobalMouse( &pt
);
749 ScreenToClient(&x
, &y
);
753 control
= FindControlUnderMouse( pt
, window
, &part
) ;
755 mouseWin
= wxFindWindowFromWXWidget( (WXWidget
) control
) ;
760 if ( mouseWin
== this && !wxIsBusy() )
761 m_cursor
.MacInstall() ;
767 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
769 #ifndef __WXUNIVERSAL__
770 menu
->SetInvokingWindow((wxWindow
*)this);
773 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
775 wxPoint mouse
= wxGetMousePosition();
781 ClientToScreen( &x
, &y
) ;
783 menu
->GetPeer()->PopUp(this, x
, y
);
784 menu
->SetInvokingWindow( NULL
);
787 // actually this shouldn't be called, because universal is having its own implementation
793 // ----------------------------------------------------------------------------
795 // ----------------------------------------------------------------------------
799 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
801 wxWindowBase::DoSetToolTip(tooltip
);
804 m_tooltip
->SetWindow(this);
809 void wxWindowMac::MacInvalidateBorders()
811 if ( m_peer
== NULL
)
814 bool vis
= IsShownOnScreen() ;
818 int outerBorder
= MacGetLeftBorderSize() ;
820 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
824 if ( outerBorder
== 0 )
827 // now we know that we have something to do at all
832 m_peer
->GetSize( tw
, th
);
833 m_peer
->GetPosition( tx
, ty
);
835 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
836 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
837 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
838 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
841 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
842 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
843 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
844 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
848 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
850 // this is never called for a toplevel window, so we know we have a parent
851 int former_x
, former_y
, former_w
, former_h
;
853 // Get true coordinates of former position
854 DoGetPosition( &former_x
, &former_y
) ;
855 DoGetSize( &former_w
, &former_h
) ;
857 wxWindow
*parent
= GetParent();
860 wxPoint
pt(parent
->GetClientAreaOrigin());
865 int actualWidth
= width
;
866 int actualHeight
= height
;
870 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
871 actualWidth
= m_minWidth
;
872 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
873 actualHeight
= m_minHeight
;
874 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
875 actualWidth
= m_maxWidth
;
876 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
877 actualHeight
= m_maxHeight
;
879 bool doMove
= false, doResize
= false ;
881 if ( actualX
!= former_x
|| actualY
!= former_y
)
884 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
887 if ( doMove
|| doResize
)
889 // as the borders are drawn outside the native control, we adjust now
891 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
892 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
893 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
895 if ( parent
&& !parent
->IsTopLevel() )
897 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
900 MacInvalidateBorders() ;
902 m_cachedClippedRectValid
= false ;
904 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
906 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
908 MacInvalidateBorders() ;
910 MacRepositionScrollBars() ;
913 wxPoint
point(actualX
, actualY
);
914 wxMoveEvent
event(point
, m_windowId
);
915 event
.SetEventObject(this);
916 HandleWindowEvent(event
) ;
921 MacRepositionScrollBars() ;
922 wxSize
size(actualWidth
, actualHeight
);
923 wxSizeEvent
event(size
, m_windowId
);
924 event
.SetEventObject(this);
925 HandleWindowEvent(event
);
930 wxSize
wxWindowMac::DoGetBestSize() const
932 if ( m_macIsUserPane
|| IsTopLevel() )
934 return wxWindowBase::DoGetBestSize() ;
940 m_peer
->GetBestRect(&r
);
942 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
949 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
954 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
961 // return wxWindowBase::DoGetBestSize() ;
965 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
966 MacGetRightBorderSize();
967 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
968 MacGetBottomBorderSize();
969 if ( bestHeight
< 10 )
972 return wxSize(bestWidth
, bestHeight
);
976 // set the size of the window: if the dimensions are positive, just use them,
977 // but if any of them is equal to -1, it means that we must find the value for
978 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
979 // which case -1 is a valid value for x and y)
981 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
982 // the width/height to best suit our contents, otherwise we reuse the current
984 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
986 // get the current size and position...
987 int currentX
, currentY
;
988 int currentW
, currentH
;
990 GetPosition(¤tX
, ¤tY
);
991 GetSize(¤tW
, ¤tH
);
993 // ... and don't do anything (avoiding flicker) if it's already ok
994 if ( x
== currentX
&& y
== currentY
&&
995 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
998 MacRepositionScrollBars() ; // we might have a real position shift
1003 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1005 if ( x
== wxDefaultCoord
)
1007 if ( y
== wxDefaultCoord
)
1011 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1013 wxSize size
= wxDefaultSize
;
1014 if ( width
== wxDefaultCoord
)
1016 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1018 size
= DoGetBestSize();
1023 // just take the current one
1028 if ( height
== wxDefaultCoord
)
1030 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1032 if ( size
.x
== wxDefaultCoord
)
1033 size
= DoGetBestSize();
1034 // else: already called DoGetBestSize() above
1040 // just take the current one
1045 DoMoveWindow( x
, y
, width
, height
);
1048 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1050 int left
,top
,width
,height
;
1051 m_peer
->GetContentArea( left
, top
, width
, height
);
1052 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1055 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1057 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1059 int currentclientwidth
, currentclientheight
;
1060 int currentwidth
, currentheight
;
1062 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1063 GetSize( ¤twidth
, ¤theight
) ;
1065 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1066 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1070 void wxWindowMac::SetLabel(const wxString
& title
)
1074 if ( m_peer
&& m_peer
->IsOk() )
1075 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1077 // do not trigger refreshes upon invisible and possible partly created objects
1078 if ( IsShownOnScreen() )
1082 wxString
wxWindowMac::GetLabel() const
1087 bool wxWindowMac::Show(bool show
)
1089 if ( !wxWindowBase::Show(show
) )
1093 m_peer
->SetVisibility( show
) ;
1098 void wxWindowMac::DoEnable(bool enable
)
1100 m_peer
->Enable( enable
) ;
1104 // status change notifications
1107 void wxWindowMac::MacVisibilityChanged()
1111 void wxWindowMac::MacHiliteChanged()
1115 void wxWindowMac::MacEnabledStateChanged()
1117 OnEnabled( m_peer
->IsEnabled() );
1121 // status queries on the inherited window's state
1124 bool wxWindowMac::MacIsReallyEnabled()
1126 return m_peer
->IsEnabled() ;
1129 bool wxWindowMac::MacIsReallyHilited()
1131 #if wxOSX_USE_CARBON
1132 return m_peer
->IsActive();
1134 return true; // TODO
1138 int wxWindowMac::GetCharHeight() const
1141 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1146 int wxWindowMac::GetCharWidth() const
1149 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1154 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1155 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1157 const wxFont
*fontToUse
= theFont
;
1161 tempFont
= GetFont();
1162 fontToUse
= &tempFont
;
1165 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1166 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1168 wxDouble h
, d
, e
, w
;
1169 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1173 if ( externalLeading
)
1174 *externalLeading
= (wxCoord
)(e
+0.5);
1176 *descent
= (wxCoord
)(d
+0.5);
1178 *x
= (wxCoord
)(w
+0.5);
1180 *y
= (wxCoord
)(h
+0.5);
1184 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1185 * we always intersect with the entire window, not only with the client area
1188 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1190 if ( m_peer
== NULL
)
1193 if ( !IsShownOnScreen() )
1196 m_peer
->SetNeedsDisplay( rect
) ;
1199 void wxWindowMac::DoFreeze()
1201 #if wxOSX_USE_CARBON
1202 if ( m_peer
&& m_peer
->IsOk() )
1203 m_peer
->SetDrawingEnabled( false ) ;
1207 void wxWindowMac::DoThaw()
1209 #if wxOSX_USE_CARBON
1210 if ( m_peer
&& m_peer
->IsOk() )
1212 m_peer
->SetDrawingEnabled( true ) ;
1213 m_peer
->InvalidateWithChildren() ;
1218 wxWindow
*wxGetActiveWindow()
1220 // actually this is a windows-only concept
1224 // Coordinates relative to the window
1225 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1227 // We really don't move the mouse programmatically under Mac.
1230 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1232 if ( MacGetTopLevelWindow() == NULL
)
1235 #if TARGET_API_MAC_OSX
1236 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1242 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1244 event
.GetDC()->Clear() ;
1246 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1248 // don't skip the event here, custom background means that the app
1249 // is drawing it itself in its OnPaint(), so don't draw it at all
1250 // now to avoid flicker
1258 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1263 int wxWindowMac::GetScrollPos(int orient
) const
1265 if ( orient
== wxHORIZONTAL
)
1268 return m_hScrollBar
->GetThumbPosition() ;
1273 return m_vScrollBar
->GetThumbPosition() ;
1279 // This now returns the whole range, not just the number
1280 // of positions that we can scroll.
1281 int wxWindowMac::GetScrollRange(int orient
) const
1283 if ( orient
== wxHORIZONTAL
)
1286 return m_hScrollBar
->GetRange() ;
1291 return m_vScrollBar
->GetRange() ;
1297 int wxWindowMac::GetScrollThumb(int orient
) const
1299 if ( orient
== wxHORIZONTAL
)
1302 return m_hScrollBar
->GetThumbSize() ;
1307 return m_vScrollBar
->GetThumbSize() ;
1313 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1315 if ( orient
== wxHORIZONTAL
)
1318 m_hScrollBar
->SetThumbPosition( pos
) ;
1323 m_vScrollBar
->SetThumbPosition( pos
) ;
1328 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1330 bool needVisibilityUpdate
= false;
1332 if ( m_hScrollBarAlwaysShown
!= hflag
)
1334 m_hScrollBarAlwaysShown
= hflag
;
1335 needVisibilityUpdate
= true;
1338 if ( m_vScrollBarAlwaysShown
!= vflag
)
1340 m_vScrollBarAlwaysShown
= vflag
;
1341 needVisibilityUpdate
= true;
1344 if ( needVisibilityUpdate
)
1345 DoUpdateScrollbarVisibility();
1349 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1350 // our own window origin is at leftOrigin/rightOrigin
1353 void wxWindowMac::MacPaintGrowBox()
1358 if ( MacHasScrollBarCorner() )
1360 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1361 wxASSERT( cgContext
) ;
1365 m_peer
->GetSize( tw
, th
);
1366 m_peer
->GetPosition( tx
, ty
);
1368 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1371 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1372 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1373 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1374 CGContextSaveGState( cgContext
);
1376 if ( m_backgroundColour
.Ok() )
1378 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1382 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1384 CGContextFillRect( cgContext
, cgrect
);
1385 CGContextRestoreGState( cgContext
);
1389 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1394 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1396 // back to the surrounding frame rectangle
1399 m_peer
->GetSize( tw
, th
);
1400 m_peer
->GetPosition( tx
, ty
);
1402 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1404 #if wxOSX_USE_COCOA_OR_CARBON
1406 InsetRect( &rect
, -1 , -1 ) ;
1409 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1410 rect
.bottom
- rect
.top
) ;
1412 HIThemeFrameDrawInfo info
;
1413 memset( &info
, 0 , sizeof(info
) ) ;
1417 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1418 info
.isFocused
= hasFocus
;
1420 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1421 wxASSERT( cgContext
) ;
1423 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1425 info
.kind
= kHIThemeFrameTextFieldSquare
;
1426 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1428 else if ( HasFlag(wxSIMPLE_BORDER
) )
1430 info
.kind
= kHIThemeFrameListBox
;
1431 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1433 else if ( hasFocus
)
1435 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1437 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1438 m_peer
->GetRect( &rect
) ;
1439 if ( MacHasScrollBarCorner() )
1441 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1442 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1443 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1444 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1445 HIThemeGrowBoxDrawInfo info
;
1446 memset( &info
, 0, sizeof(info
) ) ;
1448 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1449 info
.kind
= kHIThemeGrowBoxKindNone
;
1450 // contrary to the docs ...SizeSmall does not work
1451 info
.size
= kHIThemeGrowBoxSizeNormal
;
1452 info
.direction
= 0 ;
1453 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1457 #endif // wxOSX_USE_COCOA_OR_CARBON
1460 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1462 if ( child
== m_hScrollBar
)
1463 m_hScrollBar
= NULL
;
1464 if ( child
== m_vScrollBar
)
1465 m_vScrollBar
= NULL
;
1467 wxWindowBase::RemoveChild( child
) ;
1470 void wxWindowMac::DoUpdateScrollbarVisibility()
1472 bool triggerSizeEvent
= false;
1476 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1478 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1480 m_hScrollBar
->Show( showHScrollBar
);
1481 triggerSizeEvent
= true;
1487 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1489 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1491 m_vScrollBar
->Show( showVScrollBar
) ;
1492 triggerSizeEvent
= true;
1496 MacRepositionScrollBars() ;
1497 if ( triggerSizeEvent
)
1499 wxSizeEvent
event(GetSize(), m_windowId
);
1500 event
.SetEventObject(this);
1501 HandleWindowEvent(event
);
1505 // New function that will replace some of the above.
1506 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1507 int range
, bool refresh
)
1509 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1510 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1511 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1512 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1514 DoUpdateScrollbarVisibility();
1517 // Does a physical scroll
1518 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1520 if ( dx
== 0 && dy
== 0 )
1523 int width
, height
;
1524 GetClientSize( &width
, &height
) ;
1527 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1529 scrollrect
.Intersect( *rect
) ;
1530 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1531 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1533 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1538 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1540 child
= node
->GetData();
1543 if (child
== m_vScrollBar
)
1545 if (child
== m_hScrollBar
)
1547 if (child
->IsTopLevel())
1550 child
->GetPosition( &x
, &y
);
1551 child
->GetSize( &w
, &h
);
1554 wxRect
rc( x
, y
, w
, h
);
1555 if (rect
->Intersects( rc
))
1556 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1560 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1565 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1567 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1569 wxScrollWinEvent wevent
;
1570 wevent
.SetPosition(event
.GetPosition());
1571 wevent
.SetOrientation(event
.GetOrientation());
1572 wevent
.SetEventObject(this);
1574 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1575 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1576 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1577 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1578 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1579 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1580 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1581 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1582 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1583 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1584 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1585 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1586 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1587 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1588 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1589 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1591 HandleWindowEvent(wevent
);
1595 // Get the window with the focus
1596 wxWindow
*wxWindowBase::DoFindFocus()
1598 #if wxOSX_USE_CARBON
1599 ControlRef control
;
1600 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1601 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1607 void wxWindowMac::OnInternalIdle()
1609 // This calls the UI-update mechanism (querying windows for
1610 // menu/toolbar/control state information)
1611 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1612 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1615 // Raise the window to the top of the Z order
1616 void wxWindowMac::Raise()
1621 // Lower the window to the bottom of the Z order
1622 void wxWindowMac::Lower()
1627 // static wxWindow *gs_lastWhich = NULL;
1629 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1631 // first trigger a set cursor event
1633 wxPoint clientorigin
= GetClientAreaOrigin() ;
1634 wxSize clientsize
= GetClientSize() ;
1636 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1638 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1640 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1641 if ( processedEvtSetCursor
&& event
.HasCursor() )
1643 cursor
= event
.GetCursor() ;
1647 // the test for processedEvtSetCursor is here to prevent using m_cursor
1648 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1649 // it - this is a way to say that our cursor shouldn't be used for this
1651 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1654 if ( !wxIsBusy() && !GetParent() )
1655 cursor
= *wxSTANDARD_CURSOR
;
1659 cursor
.MacInstall() ;
1662 return cursor
.Ok() ;
1665 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1669 return m_tooltip
->GetTip() ;
1672 return wxEmptyString
;
1675 void wxWindowMac::ClearBackground()
1681 void wxWindowMac::Update()
1683 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1688 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1690 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1694 if ( iter
->IsTopLevel() )
1696 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1700 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1705 iter
= iter
->GetParent() ;
1711 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1713 MacUpdateClippedRects() ;
1715 return m_cachedClippedClientRect
;
1718 const wxRect
& wxWindowMac::MacGetClippedRect() const
1720 MacUpdateClippedRects() ;
1722 return m_cachedClippedRect
;
1725 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1727 MacUpdateClippedRects() ;
1729 return m_cachedClippedRectWithOuterStructure
;
1732 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1734 static wxRegion emptyrgn
;
1736 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1738 MacUpdateClippedRects() ;
1739 if ( includeOuterStructures
)
1740 return m_cachedClippedRegionWithOuterStructure
;
1742 return m_cachedClippedRegion
;
1750 void wxWindowMac::MacUpdateClippedRects() const
1752 #if wxOSX_USE_CARBON
1753 if ( m_cachedClippedRectValid
)
1756 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1757 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1758 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1759 // to add focus borders everywhere
1761 Rect rIncludingOuterStructures
;
1765 m_peer
->GetSize( tw
, th
);
1766 m_peer
->GetPosition( tx
, ty
);
1768 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1770 r
.left
-= MacGetLeftBorderSize() ;
1771 r
.top
-= MacGetTopBorderSize() ;
1772 r
.bottom
+= MacGetBottomBorderSize() ;
1773 r
.right
+= MacGetRightBorderSize() ;
1780 rIncludingOuterStructures
= r
;
1781 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1783 wxRect cl
= GetClientRect() ;
1784 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1788 const wxWindow
* child
= (wxWindow
*) this ;
1789 const wxWindow
* parent
= NULL
;
1791 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1793 if ( parent
->MacIsChildOfClientArea(child
) )
1795 size
= parent
->GetClientSize() ;
1796 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1802 // this will be true for scrollbars, toolbars etc.
1803 size
= parent
->GetSize() ;
1804 y
= parent
->MacGetTopBorderSize() ;
1805 x
= parent
->MacGetLeftBorderSize() ;
1806 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1807 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1810 parent
->MacWindowToRootWindow( &x
, &y
) ;
1811 MacRootWindowToWindow( &x
, &y
) ;
1813 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1815 // the wxwindow and client rects will always be clipped
1816 SectRect( &r
, &rparent
, &r
) ;
1817 SectRect( &rClient
, &rparent
, &rClient
) ;
1819 // the structure only at 'hard' borders
1820 if ( parent
->MacClipChildren() ||
1821 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1823 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1829 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1830 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1831 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1832 m_cachedClippedRectWithOuterStructure
= wxRect(
1833 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1834 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1835 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1837 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1838 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1839 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1841 m_cachedClippedRectValid
= true ;
1846 This function must not change the updatergn !
1848 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1850 bool handled
= false ;
1851 #if wxOSX_USE_CARBON
1853 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1854 GetRegionBounds( updatergn
, &updatebounds
) ;
1856 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1858 if ( !EmptyRgn(updatergn
) )
1860 RgnHandle newupdate
= NewRgn() ;
1861 wxSize point
= GetClientSize() ;
1862 wxPoint origin
= GetClientAreaOrigin() ;
1863 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1864 SectRgn( newupdate
, updatergn
, newupdate
) ;
1866 // first send an erase event to the entire update area
1868 // for the toplevel window this really is the entire area
1869 // for all the others only their client area, otherwise they
1870 // might be drawing with full alpha and eg put blue into
1871 // the grow-box area of a scrolled window (scroll sample)
1872 wxDC
* dc
= new wxWindowDC(this);
1874 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1876 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1878 wxEraseEvent
eevent( GetId(), dc
);
1879 eevent
.SetEventObject( this );
1880 HandleWindowEvent( eevent
);
1886 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1887 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1888 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1889 DisposeRgn( newupdate
) ;
1891 if ( !m_updateRegion
.Empty() )
1893 // paint the window itself
1896 event
.SetTimestamp(time
);
1897 event
.SetEventObject(this);
1898 HandleWindowEvent(event
);
1902 // now we cannot rely on having its borders drawn by a window itself, as it does not
1903 // get the updateRgn wide enough to always do so, so we do it from the parent
1904 // this would also be the place to draw any custom backgrounds for native controls
1905 // in Composited windowing
1906 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1910 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1912 child
= node
->GetData();
1915 if (child
== m_vScrollBar
)
1917 if (child
== m_hScrollBar
)
1919 if (child
->IsTopLevel())
1921 if (!child
->IsShown())
1924 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1926 child
->GetPosition( &x
, &y
);
1927 child
->GetSize( &w
, &h
);
1928 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1929 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1930 InsetRect( &childRect
, -10 , -10) ;
1932 if ( RectInRgn( &childRect
, updatergn
) )
1934 // paint custom borders
1935 wxNcPaintEvent
eventNc( child
->GetId() );
1936 eventNc
.SetEventObject( child
);
1937 if ( !child
->HandleWindowEvent( eventNc
) )
1939 child
->MacPaintBorders(0, 0) ;
1949 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1951 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1952 return tlw
? tlw
->GetWXWindow() : NULL
;
1955 bool wxWindowMac::MacHasScrollBarCorner() const
1957 /* Returns whether the scroll bars in a wxScrolledWindow should be
1958 * shortened. Scroll bars should be shortened if either:
1960 * - both scroll bars are visible, or
1962 * - there is a resize box in the parent frame's corner and this
1963 * window shares the bottom and right edge with the parent
1967 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1970 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1971 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1973 // Both scroll bars visible
1978 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1980 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1982 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1985 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1987 // Parent frame has resize handle
1988 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1990 // Note: allow for some wiggle room here as wxMac's
1991 // window rect calculations seem to be imprecise
1992 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1993 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1995 // Parent frame has resize handle and shares
1996 // right bottom corner
2001 // Parent frame has resize handle but doesn't
2002 // share right bottom corner
2008 // Parent frame doesn't have resize handle
2014 // No parent frame found
2019 void wxWindowMac::MacCreateScrollBars( long style
)
2021 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2023 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2025 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2026 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2028 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2031 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2033 GetClientSize( &width
, &height
) ;
2035 wxPoint
vPoint(width
- scrlsize
, 0) ;
2036 wxSize
vSize(scrlsize
, height
- adjust
) ;
2037 wxPoint
hPoint(0, height
- scrlsize
) ;
2038 wxSize
hSize(width
- adjust
, scrlsize
) ;
2040 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2041 if ( style
& wxVSCROLL
)
2043 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2044 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2047 if ( style
& wxHSCROLL
)
2049 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2050 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2054 // because the create does not take into account the client area origin
2055 // we might have a real position shift
2056 MacRepositionScrollBars() ;
2059 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2061 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2066 void wxWindowMac::MacRepositionScrollBars()
2068 if ( !m_hScrollBar
&& !m_vScrollBar
)
2071 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2072 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2074 // get real client area
2076 GetSize( &width
, &height
);
2078 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2079 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2081 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2082 wxSize
vSize( scrlsize
, height
- adjust
) ;
2083 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2084 wxSize
hSize( width
- adjust
, scrlsize
) ;
2087 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2089 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2092 bool wxWindowMac::AcceptsFocus() const
2094 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2097 void wxWindowMac::MacSuperChangedPosition()
2099 // only window-absolute structures have to be moved i.e. controls
2101 m_cachedClippedRectValid
= false ;
2104 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2107 child
= node
->GetData();
2108 child
->MacSuperChangedPosition() ;
2110 node
= node
->GetNext();
2114 void wxWindowMac::MacTopLevelWindowChangedPosition()
2116 // only screen-absolute structures have to be moved i.e. glcanvas
2119 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2122 child
= node
->GetData();
2123 child
->MacTopLevelWindowChangedPosition() ;
2125 node
= node
->GetNext();
2129 long wxWindowMac::MacGetLeftBorderSize() const
2136 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2138 #if wxOSX_USE_COCOA_OR_CARBON
2139 // this metric is only the 'outset' outside the simple frame rect
2140 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2146 else if (HasFlag(wxSIMPLE_BORDER
))
2148 #if wxOSX_USE_COCOA_OR_CARBON
2149 // this metric is only the 'outset' outside the simple frame rect
2150 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2160 long wxWindowMac::MacGetRightBorderSize() const
2162 // they are all symmetric in mac themes
2163 return MacGetLeftBorderSize() ;
2166 long wxWindowMac::MacGetTopBorderSize() const
2168 // they are all symmetric in mac themes
2169 return MacGetLeftBorderSize() ;
2172 long wxWindowMac::MacGetBottomBorderSize() const
2174 // they are all symmetric in mac themes
2175 return MacGetLeftBorderSize() ;
2178 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2180 return style
& ~wxBORDER_MASK
;
2183 // Find the wxWindowMac at the current mouse position, returning the mouse
2185 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2187 pt
= wxGetMousePosition();
2188 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2190 return (wxWindow
*) found
;
2193 // Get the current mouse position.
2194 wxPoint
wxGetMousePosition()
2198 wxGetMousePosition( &x
, &y
);
2200 return wxPoint(x
, y
);
2203 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2205 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2207 // copied from wxGTK : CS
2208 // VZ: shouldn't we move this to base class then?
2210 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2213 // (a) it's a command event and so is propagated to the parent
2214 // (b) under MSW it can be generated from kbd too
2215 // (c) it uses screen coords (because of (a))
2216 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2218 this->ClientToScreen(event
.GetPosition()));
2219 evtCtx
.SetEventObject(this);
2220 if ( ! HandleWindowEvent(evtCtx
) )
2229 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2231 #if wxOSX_USE_COCOA_OR_CARBON
2232 // for native controls: call their native paint method
2233 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2235 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2236 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2237 CallNextEventHandler(
2238 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2239 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2244 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
2245 wxInt16
WXUNUSED(controlpart
),
2246 bool WXUNUSED(mouseStillDown
))
2250 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2254 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2255 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2260 bool wxWindowMac::HandleClicked( double timestampsec
)
2265 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2267 #if wxOSX_USE_COCOA_OR_CARBON
2268 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2271 return eventNotHandledErr
;
2277 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2279 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2280 if ( !wxWindowBase::Reparent(newParent
) )
2283 m_peer
->RemoveFromParent();
2284 m_peer
->Embed( GetParent()->GetPeer() );
2288 bool wxWindowMac::SetTransparent(wxByte alpha
)
2290 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2292 if ( alpha
!= m_macAlpha
)
2294 m_macAlpha
= alpha
;
2301 bool wxWindowMac::CanSetTransparent()
2306 wxByte
wxWindowMac::GetTransparent() const
2311 bool wxWindowMac::IsShownOnScreen() const
2313 if ( m_peer
&& m_peer
->IsOk() )
2315 bool peerVis
= m_peer
->IsVisible();
2316 bool wxVis
= wxWindowBase::IsShownOnScreen();
2317 if( peerVis
!= wxVis
)
2319 // CS : put a breakpoint here to investigate differences
2320 // between native an wx visibilities
2321 // the only place where I've encountered them until now
2322 // are the hiding/showing sequences where the vis-changed event is
2323 // first sent to the innermost control, while wx does things
2324 // from the outmost control
2325 wxVis
= wxWindowBase::IsShownOnScreen();
2329 return m_peer
->IsVisible();
2331 return wxWindowBase::IsShownOnScreen();
2338 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2340 static MacControlMap wxWinMacControlList
;
2342 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2344 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2346 return impl
->GetWXPeer();
2351 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2353 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2355 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2358 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2360 // adding NULL ControlRef is (first) surely a result of an error and
2361 // (secondly) breaks native event processing
2362 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2364 wxWinMacControlList
[inControl
] = impl
;
2367 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2369 // iterate over all the elements in the class
2370 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2371 // we should go on...
2377 MacControlMap::iterator it
;
2378 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2380 if ( it
->second
== impl
)
2382 wxWinMacControlList
.erase(it
);
2390 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2392 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2395 m_isRootControl
= isRootControl
;
2399 wxWidgetImpl::wxWidgetImpl()
2404 wxWidgetImpl::~wxWidgetImpl()
2408 void wxWidgetImpl::Init()
2410 m_isRootControl
= false;
2412 m_needsFocusRect
= false;
2415 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2417 m_needsFocusRect
= needs
;
2420 bool wxWidgetImpl::NeedsFocusRect() const
2422 return m_needsFocusRect
;