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
);
308 #if wxOSX_USE_COCOA_OR_CARBON
313 ThemeFontID themeFont
= kThemeSystemFont
;
315 // we will get that from the settings later
316 // and make this NORMAL later, but first
317 // we have a few calculations that we must fix
321 case wxWINDOW_VARIANT_NORMAL
:
322 size
= kControlSizeNormal
;
323 themeFont
= kThemeSystemFont
;
326 case wxWINDOW_VARIANT_SMALL
:
327 size
= kControlSizeSmall
;
328 themeFont
= kThemeSmallSystemFont
;
331 case wxWINDOW_VARIANT_MINI
:
332 // not always defined in the headers
337 case wxWINDOW_VARIANT_LARGE
:
338 size
= kControlSizeLarge
;
339 themeFont
= kThemeSystemFont
;
343 wxFAIL_MSG(_T("unexpected window variant"));
347 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
348 font
.MacCreateFromThemeFont( themeFont
) ;
350 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
353 case wxWINDOW_VARIANT_NORMAL
:
354 themeFont
= kCTFontSystemFontType
;
357 case wxWINDOW_VARIANT_SMALL
:
358 themeFont
= kCTFontSmallSystemFontType
;
361 case wxWINDOW_VARIANT_MINI
:
362 themeFont
= kCTFontMiniSystemFontType
;
365 case wxWINDOW_VARIANT_LARGE
:
366 themeFont
= kCTFontSystemFontType
;
370 wxFAIL_MSG(_T("unexpected window variant"));
373 font
.MacCreateFromUIFont( themeFont
) ;
380 void wxWindowMac::MacUpdateControlFont()
383 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
385 // do not trigger refreshes upon invisible and possible partly created objects
386 if ( IsShownOnScreen() )
390 bool wxWindowMac::SetFont(const wxFont
& font
)
392 bool retval
= wxWindowBase::SetFont( font
);
394 MacUpdateControlFont() ;
399 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
401 bool retval
= wxWindowBase::SetForegroundColour( col
);
404 MacUpdateControlFont();
409 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
411 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
415 m_peer
->SetBackgroundColour( col
) ;
420 void wxWindowMac::SetFocus()
422 if ( !AcceptsFocus() )
425 wxWindow
* former
= FindFocus() ;
426 if ( former
== this )
432 void wxWindowMac::DoCaptureMouse()
434 wxApp::s_captureWindow
= (wxWindow
*) this ;
437 wxWindow
* wxWindowBase::GetCapture()
439 return wxApp::s_captureWindow
;
442 void wxWindowMac::DoReleaseMouse()
444 wxApp::s_captureWindow
= NULL
;
447 #if wxUSE_DRAG_AND_DROP
449 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
453 m_dropTarget
= pDropTarget
;
454 if ( m_dropTarget
!= NULL
)
462 // Old-style File Manager Drag & Drop
463 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
468 // From a wx position / size calculate the appropriate size of the native control
470 bool wxWindowMac::MacGetBoundsForControl(
474 int& w
, int& h
, bool adjustOrigin
) const
476 // the desired size, minus the border pixels gives the correct size of the control
480 w
= WidthDefault( size
.x
);
481 h
= HeightDefault( size
.y
);
483 x
+= MacGetLeftBorderSize() ;
484 y
+= MacGetTopBorderSize() ;
485 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
486 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
489 AdjustForParentClientOrigin( x
, y
) ;
491 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
492 if ( GetParent() && !GetParent()->IsTopLevel() )
494 x
-= GetParent()->MacGetLeftBorderSize() ;
495 y
-= GetParent()->MacGetTopBorderSize() ;
501 // Get window size (not client size)
502 void wxWindowMac::DoGetSize(int *x
, int *y
) const
505 m_peer
->GetSize( width
, height
);
508 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
510 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
513 // get the position of the bounds of this window in client coordinates of its parent
514 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
518 m_peer
->GetPosition( x1
, y1
) ;
520 // get the wx window position from the native one
521 x1
-= MacGetLeftBorderSize() ;
522 y1
-= MacGetTopBorderSize() ;
526 wxWindow
*parent
= GetParent();
529 // we must first adjust it to be in window coordinates of the parent,
530 // as otherwise it gets lost by the ClientAreaOrigin fix
531 x1
+= parent
->MacGetLeftBorderSize() ;
532 y1
+= parent
->MacGetTopBorderSize() ;
534 // and now to client coordinates
535 wxPoint
pt(parent
->GetClientAreaOrigin());
547 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
549 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
550 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
551 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
552 MacRootWindowToWindow( x
, y
) ;
554 wxPoint origin
= GetClientAreaOrigin() ;
561 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
563 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
564 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
566 wxPoint origin
= GetClientAreaOrigin() ;
572 MacWindowToRootWindow( x
, y
) ;
573 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
576 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
578 wxPoint origin
= GetClientAreaOrigin() ;
584 MacWindowToRootWindow( x
, y
) ;
587 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
598 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
601 pt
.x
-= MacGetLeftBorderSize() ;
602 pt
.y
-= MacGetTopBorderSize() ;
603 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
613 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
624 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
627 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
628 pt
.x
+= MacGetLeftBorderSize() ;
629 pt
.y
+= MacGetTopBorderSize() ;
639 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
641 wxSize sizeTotal
= size
;
643 int innerwidth
, innerheight
;
645 int outerwidth
, outerheight
;
647 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
648 m_peer
->GetSize( outerwidth
, outerheight
);
650 sizeTotal
.x
+= left
+ (outerwidth
-innerwidth
);
651 sizeTotal
.y
+= top
+ (outerheight
-innerheight
);
653 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
654 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
659 // Get size *available for subwindows* i.e. excluding menu bar etc.
660 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
666 m_peer
->GetContentArea( left
, top
, ww
, hh
);
668 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
669 hh
-= m_hScrollBar
->GetSize().y
;
671 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
672 ww
-= m_vScrollBar
->GetSize().x
;
680 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
682 if (m_cursor
.IsSameAs(cursor
))
687 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
692 if ( ! wxWindowBase::SetCursor( cursor
) )
696 wxASSERT_MSG( m_cursor
.Ok(),
697 wxT("cursor must be valid after call to the base version"));
699 wxWindowMac
*mouseWin
= 0 ;
702 wxNonOwnedWindow
*tlw
= MacGetTopLevelWindow() ;
703 WindowRef window
= (WindowRef
) ( tlw
? tlw
->GetWXWindow() : 0 ) ;
705 ControlPartCode part
;
708 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
710 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
714 GetGlobalMouse( &pt
);
717 ScreenToClient(&x
, &y
);
721 control
= FindControlUnderMouse( pt
, window
, &part
) ;
723 mouseWin
= wxFindWindowFromWXWidget( (WXWidget
) control
) ;
728 if ( mouseWin
== this && !wxIsBusy() )
729 m_cursor
.MacInstall() ;
735 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
737 #ifndef __WXUNIVERSAL__
738 menu
->SetInvokingWindow((wxWindow
*)this);
741 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
743 wxPoint mouse
= wxGetMousePosition();
749 ClientToScreen( &x
, &y
) ;
751 #ifdef __WXOSX_CARBON__
752 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
753 if ( HiWord(menuResult
) != 0 )
756 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
757 int id
= wxMacCommandToId( macid
);
758 wxMenuItem
* item
= NULL
;
760 item
= menu
->FindItem( id
, &realmenu
) ;
763 if (item
->IsCheckable())
764 item
->Check( !item
->IsChecked() ) ;
766 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
771 menu
->SetInvokingWindow( NULL
);
777 // actually this shouldn't be called, because universal is having its own implementation
783 // ----------------------------------------------------------------------------
785 // ----------------------------------------------------------------------------
789 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
791 wxWindowBase::DoSetToolTip(tooltip
);
794 m_tooltip
->SetWindow(this);
799 void wxWindowMac::MacInvalidateBorders()
801 if ( m_peer
== NULL
)
804 bool vis
= IsShownOnScreen() ;
808 int outerBorder
= MacGetLeftBorderSize() ;
810 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
814 if ( outerBorder
== 0 )
817 // now we know that we have something to do at all
822 m_peer
->GetSize( tw
, th
);
823 m_peer
->GetPosition( tx
, ty
);
825 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
826 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
827 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
828 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
831 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
832 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
833 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
834 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
838 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
840 // this is never called for a toplevel window, so we know we have a parent
841 int former_x
, former_y
, former_w
, former_h
;
843 // Get true coordinates of former position
844 DoGetPosition( &former_x
, &former_y
) ;
845 DoGetSize( &former_w
, &former_h
) ;
847 wxWindow
*parent
= GetParent();
850 wxPoint
pt(parent
->GetClientAreaOrigin());
855 int actualWidth
= width
;
856 int actualHeight
= height
;
860 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
861 actualWidth
= m_minWidth
;
862 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
863 actualHeight
= m_minHeight
;
864 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
865 actualWidth
= m_maxWidth
;
866 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
867 actualHeight
= m_maxHeight
;
869 bool doMove
= false, doResize
= false ;
871 if ( actualX
!= former_x
|| actualY
!= former_y
)
874 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
877 if ( doMove
|| doResize
)
879 // as the borders are drawn outside the native control, we adjust now
881 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
882 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
883 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
885 if ( parent
&& !parent
->IsTopLevel() )
887 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
890 MacInvalidateBorders() ;
892 m_cachedClippedRectValid
= false ;
894 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
896 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
898 MacInvalidateBorders() ;
900 MacRepositionScrollBars() ;
903 wxPoint
point(actualX
, actualY
);
904 wxMoveEvent
event(point
, m_windowId
);
905 event
.SetEventObject(this);
906 HandleWindowEvent(event
) ;
911 MacRepositionScrollBars() ;
912 wxSize
size(actualWidth
, actualHeight
);
913 wxSizeEvent
event(size
, m_windowId
);
914 event
.SetEventObject(this);
915 HandleWindowEvent(event
);
920 wxSize
wxWindowMac::DoGetBestSize() const
922 if ( m_macIsUserPane
|| IsTopLevel() )
924 return wxWindowBase::DoGetBestSize() ;
930 m_peer
->GetBestRect(&r
);
932 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
939 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
944 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
951 // return wxWindowBase::DoGetBestSize() ;
955 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
956 MacGetRightBorderSize();
957 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
958 MacGetBottomBorderSize();
959 if ( bestHeight
< 10 )
962 return wxSize(bestWidth
, bestHeight
);
966 // set the size of the window: if the dimensions are positive, just use them,
967 // but if any of them is equal to -1, it means that we must find the value for
968 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
969 // which case -1 is a valid value for x and y)
971 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
972 // the width/height to best suit our contents, otherwise we reuse the current
974 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
976 // get the current size and position...
977 int currentX
, currentY
;
978 int currentW
, currentH
;
980 GetPosition(¤tX
, ¤tY
);
981 GetSize(¤tW
, ¤tH
);
983 // ... and don't do anything (avoiding flicker) if it's already ok
984 if ( x
== currentX
&& y
== currentY
&&
985 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
988 MacRepositionScrollBars() ; // we might have a real position shift
993 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
995 if ( x
== wxDefaultCoord
)
997 if ( y
== wxDefaultCoord
)
1001 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1003 wxSize size
= wxDefaultSize
;
1004 if ( width
== wxDefaultCoord
)
1006 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1008 size
= DoGetBestSize();
1013 // just take the current one
1018 if ( height
== wxDefaultCoord
)
1020 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1022 if ( size
.x
== wxDefaultCoord
)
1023 size
= DoGetBestSize();
1024 // else: already called DoGetBestSize() above
1030 // just take the current one
1035 DoMoveWindow( x
, y
, width
, height
);
1038 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1040 int left
,top
,width
,height
;
1041 m_peer
->GetContentArea( left
, top
, width
, height
);
1042 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1045 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1047 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1049 int currentclientwidth
, currentclientheight
;
1050 int currentwidth
, currentheight
;
1052 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1053 GetSize( ¤twidth
, ¤theight
) ;
1055 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1056 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1060 void wxWindowMac::SetLabel(const wxString
& title
)
1064 if ( m_peer
&& m_peer
->IsOk() )
1065 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1067 // do not trigger refreshes upon invisible and possible partly created objects
1068 if ( IsShownOnScreen() )
1072 wxString
wxWindowMac::GetLabel() const
1077 bool wxWindowMac::Show(bool show
)
1079 if ( !wxWindowBase::Show(show
) )
1083 m_peer
->SetVisibility( show
) ;
1088 void wxWindowMac::DoEnable(bool enable
)
1090 m_peer
->Enable( enable
) ;
1094 // status change notifications
1097 void wxWindowMac::MacVisibilityChanged()
1101 void wxWindowMac::MacHiliteChanged()
1105 void wxWindowMac::MacEnabledStateChanged()
1107 OnEnabled( m_peer
->IsEnabled() );
1111 // status queries on the inherited window's state
1114 bool wxWindowMac::MacIsReallyEnabled()
1116 return m_peer
->IsEnabled() ;
1119 bool wxWindowMac::MacIsReallyHilited()
1121 #if wxOSX_USE_CARBON
1122 return m_peer
->IsActive();
1124 return true; // TODO
1128 int wxWindowMac::GetCharHeight() const
1131 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1136 int wxWindowMac::GetCharWidth() const
1139 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1144 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1145 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1147 const wxFont
*fontToUse
= theFont
;
1151 tempFont
= GetFont();
1152 fontToUse
= &tempFont
;
1155 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1156 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1158 wxDouble h
, d
, e
, w
;
1159 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1163 if ( externalLeading
)
1164 *externalLeading
= (wxCoord
)(e
+0.5);
1166 *descent
= (wxCoord
)(d
+0.5);
1168 *x
= (wxCoord
)(w
+0.5);
1170 *y
= (wxCoord
)(h
+0.5);
1174 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1175 * we always intersect with the entire window, not only with the client area
1178 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1180 if ( m_peer
== NULL
)
1183 if ( !IsShownOnScreen() )
1186 m_peer
->SetNeedsDisplay( rect
) ;
1189 void wxWindowMac::DoFreeze()
1191 #if wxOSX_USE_CARBON
1192 if ( m_peer
&& m_peer
->IsOk() )
1193 m_peer
->SetDrawingEnabled( false ) ;
1197 void wxWindowMac::DoThaw()
1199 #if wxOSX_USE_CARBON
1200 if ( m_peer
&& m_peer
->IsOk() )
1202 m_peer
->SetDrawingEnabled( true ) ;
1203 m_peer
->InvalidateWithChildren() ;
1208 wxWindow
*wxGetActiveWindow()
1210 // actually this is a windows-only concept
1214 // Coordinates relative to the window
1215 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1217 // We really don't move the mouse programmatically under Mac.
1220 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1222 if ( MacGetTopLevelWindow() == NULL
)
1225 #if TARGET_API_MAC_OSX
1226 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1232 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1234 event
.GetDC()->Clear() ;
1236 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1238 // don't skip the event here, custom background means that the app
1239 // is drawing it itself in its OnPaint(), so don't draw it at all
1240 // now to avoid flicker
1248 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1253 int wxWindowMac::GetScrollPos(int orient
) const
1255 if ( orient
== wxHORIZONTAL
)
1258 return m_hScrollBar
->GetThumbPosition() ;
1263 return m_vScrollBar
->GetThumbPosition() ;
1269 // This now returns the whole range, not just the number
1270 // of positions that we can scroll.
1271 int wxWindowMac::GetScrollRange(int orient
) const
1273 if ( orient
== wxHORIZONTAL
)
1276 return m_hScrollBar
->GetRange() ;
1281 return m_vScrollBar
->GetRange() ;
1287 int wxWindowMac::GetScrollThumb(int orient
) const
1289 if ( orient
== wxHORIZONTAL
)
1292 return m_hScrollBar
->GetThumbSize() ;
1297 return m_vScrollBar
->GetThumbSize() ;
1303 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1305 if ( orient
== wxHORIZONTAL
)
1308 m_hScrollBar
->SetThumbPosition( pos
) ;
1313 m_vScrollBar
->SetThumbPosition( pos
) ;
1318 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1320 bool needVisibilityUpdate
= false;
1322 if ( m_hScrollBarAlwaysShown
!= hflag
)
1324 m_hScrollBarAlwaysShown
= hflag
;
1325 needVisibilityUpdate
= true;
1328 if ( m_vScrollBarAlwaysShown
!= vflag
)
1330 m_vScrollBarAlwaysShown
= vflag
;
1331 needVisibilityUpdate
= true;
1334 if ( needVisibilityUpdate
)
1335 DoUpdateScrollbarVisibility();
1339 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1340 // our own window origin is at leftOrigin/rightOrigin
1343 void wxWindowMac::MacPaintGrowBox()
1348 if ( MacHasScrollBarCorner() )
1350 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1351 wxASSERT( cgContext
) ;
1355 m_peer
->GetSize( tw
, th
);
1356 m_peer
->GetPosition( tx
, ty
);
1358 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1361 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1362 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1363 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1364 CGContextSaveGState( cgContext
);
1366 if ( m_backgroundColour
.Ok() )
1368 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1372 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1374 CGContextFillRect( cgContext
, cgrect
);
1375 CGContextRestoreGState( cgContext
);
1379 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1384 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1386 // back to the surrounding frame rectangle
1389 m_peer
->GetSize( tw
, th
);
1390 m_peer
->GetPosition( tx
, ty
);
1392 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1394 #if wxOSX_USE_COCOA_OR_CARBON
1396 InsetRect( &rect
, -1 , -1 ) ;
1399 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1400 rect
.bottom
- rect
.top
) ;
1402 HIThemeFrameDrawInfo info
;
1403 memset( &info
, 0 , sizeof(info
) ) ;
1407 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1408 info
.isFocused
= hasFocus
;
1410 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1411 wxASSERT( cgContext
) ;
1413 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1415 info
.kind
= kHIThemeFrameTextFieldSquare
;
1416 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1418 else if ( HasFlag(wxSIMPLE_BORDER
) )
1420 info
.kind
= kHIThemeFrameListBox
;
1421 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1423 else if ( hasFocus
)
1425 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1427 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1428 m_peer
->GetRect( &rect
) ;
1429 if ( MacHasScrollBarCorner() )
1431 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1432 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1433 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1434 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1435 HIThemeGrowBoxDrawInfo info
;
1436 memset( &info
, 0, sizeof(info
) ) ;
1438 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1439 info
.kind
= kHIThemeGrowBoxKindNone
;
1440 // contrary to the docs ...SizeSmall does not work
1441 info
.size
= kHIThemeGrowBoxSizeNormal
;
1442 info
.direction
= 0 ;
1443 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1447 #endif // wxOSX_USE_COCOA_OR_CARBON
1450 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1452 if ( child
== m_hScrollBar
)
1453 m_hScrollBar
= NULL
;
1454 if ( child
== m_vScrollBar
)
1455 m_vScrollBar
= NULL
;
1457 wxWindowBase::RemoveChild( child
) ;
1460 void wxWindowMac::DoUpdateScrollbarVisibility()
1462 bool triggerSizeEvent
= false;
1466 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1468 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1470 m_hScrollBar
->Show( showHScrollBar
);
1471 triggerSizeEvent
= true;
1477 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1479 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1481 m_vScrollBar
->Show( showVScrollBar
) ;
1482 triggerSizeEvent
= true;
1486 MacRepositionScrollBars() ;
1487 if ( triggerSizeEvent
)
1489 wxSizeEvent
event(GetSize(), m_windowId
);
1490 event
.SetEventObject(this);
1491 HandleWindowEvent(event
);
1495 // New function that will replace some of the above.
1496 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1497 int range
, bool refresh
)
1499 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1500 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1501 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1502 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1504 DoUpdateScrollbarVisibility();
1507 // Does a physical scroll
1508 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1510 if ( dx
== 0 && dy
== 0 )
1513 int width
, height
;
1514 GetClientSize( &width
, &height
) ;
1517 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1519 scrollrect
.Intersect( *rect
) ;
1520 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1521 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1523 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1528 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1530 child
= node
->GetData();
1533 if (child
== m_vScrollBar
)
1535 if (child
== m_hScrollBar
)
1537 if (child
->IsTopLevel())
1540 child
->GetPosition( &x
, &y
);
1541 child
->GetSize( &w
, &h
);
1544 wxRect
rc( x
, y
, w
, h
);
1545 if (rect
->Intersects( rc
))
1546 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1550 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1555 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1557 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1559 wxScrollWinEvent wevent
;
1560 wevent
.SetPosition(event
.GetPosition());
1561 wevent
.SetOrientation(event
.GetOrientation());
1562 wevent
.SetEventObject(this);
1564 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1565 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1566 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1567 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1568 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1569 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1570 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1571 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1572 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1573 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1574 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1575 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1576 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1577 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1578 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1579 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1581 HandleWindowEvent(wevent
);
1585 // Get the window with the focus
1586 wxWindow
*wxWindowBase::DoFindFocus()
1588 #if wxOSX_USE_CARBON
1589 ControlRef control
;
1590 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1591 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1597 void wxWindowMac::OnInternalIdle()
1599 // This calls the UI-update mechanism (querying windows for
1600 // menu/toolbar/control state information)
1601 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1602 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1605 // Raise the window to the top of the Z order
1606 void wxWindowMac::Raise()
1611 // Lower the window to the bottom of the Z order
1612 void wxWindowMac::Lower()
1617 // static wxWindow *gs_lastWhich = NULL;
1619 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1621 // first trigger a set cursor event
1623 wxPoint clientorigin
= GetClientAreaOrigin() ;
1624 wxSize clientsize
= GetClientSize() ;
1626 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1628 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1630 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1631 if ( processedEvtSetCursor
&& event
.HasCursor() )
1633 cursor
= event
.GetCursor() ;
1637 // the test for processedEvtSetCursor is here to prevent using m_cursor
1638 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1639 // it - this is a way to say that our cursor shouldn't be used for this
1641 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1644 if ( !wxIsBusy() && !GetParent() )
1645 cursor
= *wxSTANDARD_CURSOR
;
1649 cursor
.MacInstall() ;
1652 return cursor
.Ok() ;
1655 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1659 return m_tooltip
->GetTip() ;
1662 return wxEmptyString
;
1665 void wxWindowMac::ClearBackground()
1671 void wxWindowMac::Update()
1673 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1678 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1680 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1684 if ( iter
->IsTopLevel() )
1686 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1690 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1695 iter
= iter
->GetParent() ;
1701 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1703 MacUpdateClippedRects() ;
1705 return m_cachedClippedClientRect
;
1708 const wxRect
& wxWindowMac::MacGetClippedRect() const
1710 MacUpdateClippedRects() ;
1712 return m_cachedClippedRect
;
1715 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1717 MacUpdateClippedRects() ;
1719 return m_cachedClippedRectWithOuterStructure
;
1722 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1724 static wxRegion emptyrgn
;
1726 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1728 MacUpdateClippedRects() ;
1729 if ( includeOuterStructures
)
1730 return m_cachedClippedRegionWithOuterStructure
;
1732 return m_cachedClippedRegion
;
1740 void wxWindowMac::MacUpdateClippedRects() const
1742 #if wxOSX_USE_CARBON
1743 if ( m_cachedClippedRectValid
)
1746 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1747 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1748 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1749 // to add focus borders everywhere
1751 Rect rIncludingOuterStructures
;
1755 m_peer
->GetSize( tw
, th
);
1756 m_peer
->GetPosition( tx
, ty
);
1758 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1760 r
.left
-= MacGetLeftBorderSize() ;
1761 r
.top
-= MacGetTopBorderSize() ;
1762 r
.bottom
+= MacGetBottomBorderSize() ;
1763 r
.right
+= MacGetRightBorderSize() ;
1770 rIncludingOuterStructures
= r
;
1771 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1773 wxRect cl
= GetClientRect() ;
1774 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1778 const wxWindow
* child
= (wxWindow
*) this ;
1779 const wxWindow
* parent
= NULL
;
1781 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1783 if ( parent
->MacIsChildOfClientArea(child
) )
1785 size
= parent
->GetClientSize() ;
1786 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1792 // this will be true for scrollbars, toolbars etc.
1793 size
= parent
->GetSize() ;
1794 y
= parent
->MacGetTopBorderSize() ;
1795 x
= parent
->MacGetLeftBorderSize() ;
1796 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1797 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1800 parent
->MacWindowToRootWindow( &x
, &y
) ;
1801 MacRootWindowToWindow( &x
, &y
) ;
1803 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1805 // the wxwindow and client rects will always be clipped
1806 SectRect( &r
, &rparent
, &r
) ;
1807 SectRect( &rClient
, &rparent
, &rClient
) ;
1809 // the structure only at 'hard' borders
1810 if ( parent
->MacClipChildren() ||
1811 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1813 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1819 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1820 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1821 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1822 m_cachedClippedRectWithOuterStructure
= wxRect(
1823 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1824 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1825 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1827 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1828 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1829 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1831 m_cachedClippedRectValid
= true ;
1836 This function must not change the updatergn !
1838 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1840 bool handled
= false ;
1841 #if wxOSX_USE_CARBON
1843 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1844 GetRegionBounds( updatergn
, &updatebounds
) ;
1846 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1848 if ( !EmptyRgn(updatergn
) )
1850 RgnHandle newupdate
= NewRgn() ;
1851 wxSize point
= GetClientSize() ;
1852 wxPoint origin
= GetClientAreaOrigin() ;
1853 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1854 SectRgn( newupdate
, updatergn
, newupdate
) ;
1856 // first send an erase event to the entire update area
1858 // for the toplevel window this really is the entire area
1859 // for all the others only their client area, otherwise they
1860 // might be drawing with full alpha and eg put blue into
1861 // the grow-box area of a scrolled window (scroll sample)
1862 wxDC
* dc
= new wxWindowDC(this);
1864 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1866 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1868 wxEraseEvent
eevent( GetId(), dc
);
1869 eevent
.SetEventObject( this );
1870 HandleWindowEvent( eevent
);
1876 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1877 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1878 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1879 DisposeRgn( newupdate
) ;
1881 if ( !m_updateRegion
.Empty() )
1883 // paint the window itself
1886 event
.SetTimestamp(time
);
1887 event
.SetEventObject(this);
1888 HandleWindowEvent(event
);
1892 // now we cannot rely on having its borders drawn by a window itself, as it does not
1893 // get the updateRgn wide enough to always do so, so we do it from the parent
1894 // this would also be the place to draw any custom backgrounds for native controls
1895 // in Composited windowing
1896 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1900 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1902 child
= node
->GetData();
1905 if (child
== m_vScrollBar
)
1907 if (child
== m_hScrollBar
)
1909 if (child
->IsTopLevel())
1911 if (!child
->IsShown())
1914 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1916 child
->GetPosition( &x
, &y
);
1917 child
->GetSize( &w
, &h
);
1918 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1919 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1920 InsetRect( &childRect
, -10 , -10) ;
1922 if ( RectInRgn( &childRect
, updatergn
) )
1924 // paint custom borders
1925 wxNcPaintEvent
eventNc( child
->GetId() );
1926 eventNc
.SetEventObject( child
);
1927 if ( !child
->HandleWindowEvent( eventNc
) )
1929 child
->MacPaintBorders(0, 0) ;
1939 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1941 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1942 return tlw
? tlw
->GetWXWindow() : NULL
;
1945 bool wxWindowMac::MacHasScrollBarCorner() const
1947 /* Returns whether the scroll bars in a wxScrolledWindow should be
1948 * shortened. Scroll bars should be shortened if either:
1950 * - both scroll bars are visible, or
1952 * - there is a resize box in the parent frame's corner and this
1953 * window shares the bottom and right edge with the parent
1957 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1960 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1961 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1963 // Both scroll bars visible
1968 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1970 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1972 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1975 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1977 // Parent frame has resize handle
1978 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1980 // Note: allow for some wiggle room here as wxMac's
1981 // window rect calculations seem to be imprecise
1982 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1983 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1985 // Parent frame has resize handle and shares
1986 // right bottom corner
1991 // Parent frame has resize handle but doesn't
1992 // share right bottom corner
1998 // Parent frame doesn't have resize handle
2004 // No parent frame found
2009 void wxWindowMac::MacCreateScrollBars( long style
)
2011 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2013 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2015 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2016 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2018 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2021 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2023 GetClientSize( &width
, &height
) ;
2025 wxPoint
vPoint(width
- scrlsize
, 0) ;
2026 wxSize
vSize(scrlsize
, height
- adjust
) ;
2027 wxPoint
hPoint(0, height
- scrlsize
) ;
2028 wxSize
hSize(width
- adjust
, scrlsize
) ;
2030 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2031 if ( style
& wxVSCROLL
)
2033 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2034 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2037 if ( style
& wxHSCROLL
)
2039 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2040 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2044 // because the create does not take into account the client area origin
2045 // we might have a real position shift
2046 MacRepositionScrollBars() ;
2049 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2051 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2056 void wxWindowMac::MacRepositionScrollBars()
2058 if ( !m_hScrollBar
&& !m_vScrollBar
)
2061 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2062 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2064 // get real client area
2066 GetSize( &width
, &height
);
2068 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2069 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2071 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2072 wxSize
vSize( scrlsize
, height
- adjust
) ;
2073 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2074 wxSize
hSize( width
- adjust
, scrlsize
) ;
2077 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2079 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2082 bool wxWindowMac::AcceptsFocus() const
2084 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2087 void wxWindowMac::MacSuperChangedPosition()
2089 // only window-absolute structures have to be moved i.e. controls
2091 m_cachedClippedRectValid
= false ;
2094 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2097 child
= node
->GetData();
2098 child
->MacSuperChangedPosition() ;
2100 node
= node
->GetNext();
2104 void wxWindowMac::MacTopLevelWindowChangedPosition()
2106 // only screen-absolute structures have to be moved i.e. glcanvas
2109 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2112 child
= node
->GetData();
2113 child
->MacTopLevelWindowChangedPosition() ;
2115 node
= node
->GetNext();
2119 long wxWindowMac::MacGetLeftBorderSize() const
2126 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2128 #if wxOSX_USE_COCOA_OR_CARBON
2129 // this metric is only the 'outset' outside the simple frame rect
2130 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2136 else if (HasFlag(wxSIMPLE_BORDER
))
2138 #if wxOSX_USE_COCOA_OR_CARBON
2139 // this metric is only the 'outset' outside the simple frame rect
2140 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2150 long wxWindowMac::MacGetRightBorderSize() const
2152 // they are all symmetric in mac themes
2153 return MacGetLeftBorderSize() ;
2156 long wxWindowMac::MacGetTopBorderSize() const
2158 // they are all symmetric in mac themes
2159 return MacGetLeftBorderSize() ;
2162 long wxWindowMac::MacGetBottomBorderSize() const
2164 // they are all symmetric in mac themes
2165 return MacGetLeftBorderSize() ;
2168 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2170 return style
& ~wxBORDER_MASK
;
2173 // Find the wxWindowMac at the current mouse position, returning the mouse
2175 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2177 pt
= wxGetMousePosition();
2178 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2180 return (wxWindow
*) found
;
2183 // Get the current mouse position.
2184 wxPoint
wxGetMousePosition()
2188 wxGetMousePosition( &x
, &y
);
2190 return wxPoint(x
, y
);
2193 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2195 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2197 // copied from wxGTK : CS
2198 // VZ: shouldn't we move this to base class then?
2200 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2203 // (a) it's a command event and so is propagated to the parent
2204 // (b) under MSW it can be generated from kbd too
2205 // (c) it uses screen coords (because of (a))
2206 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2208 this->ClientToScreen(event
.GetPosition()));
2209 evtCtx
.SetEventObject(this);
2210 if ( ! HandleWindowEvent(evtCtx
) )
2219 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2221 #if wxOSX_USE_COCOA_OR_CARBON
2222 // for native controls: call their native paint method
2223 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2225 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2226 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2227 CallNextEventHandler(
2228 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2229 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2234 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
2235 wxInt16
WXUNUSED(controlpart
),
2236 bool WXUNUSED(mouseStillDown
))
2240 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2244 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2245 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2250 bool wxWindowMac::HandleClicked( double timestampsec
)
2255 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2257 #if wxOSX_USE_COCOA_OR_CARBON
2258 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2261 return eventNotHandledErr
;
2267 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2269 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2270 if ( !wxWindowBase::Reparent(newParent
) )
2273 m_peer
->RemoveFromParent();
2274 m_peer
->Embed( GetParent()->GetPeer() );
2278 bool wxWindowMac::SetTransparent(wxByte alpha
)
2280 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2282 if ( alpha
!= m_macAlpha
)
2284 m_macAlpha
= alpha
;
2291 bool wxWindowMac::CanSetTransparent()
2296 wxByte
wxWindowMac::GetTransparent() const
2301 bool wxWindowMac::IsShownOnScreen() const
2303 if ( m_peer
&& m_peer
->IsOk() )
2305 bool peerVis
= m_peer
->IsVisible();
2306 bool wxVis
= wxWindowBase::IsShownOnScreen();
2307 if( peerVis
!= wxVis
)
2309 // CS : put a breakpoint here to investigate differences
2310 // between native an wx visibilities
2311 // the only place where I've encountered them until now
2312 // are the hiding/showing sequences where the vis-changed event is
2313 // first sent to the innermost control, while wx does things
2314 // from the outmost control
2315 wxVis
= wxWindowBase::IsShownOnScreen();
2319 return m_peer
->IsVisible();
2321 return wxWindowBase::IsShownOnScreen();
2328 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2330 static MacControlMap wxWinMacControlList
;
2332 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2334 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2336 return impl
->GetWXPeer();
2341 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2343 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2345 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2348 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2350 // adding NULL ControlRef is (first) surely a result of an error and
2351 // (secondly) breaks native event processing
2352 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2354 wxWinMacControlList
[inControl
] = impl
;
2357 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2359 // iterate over all the elements in the class
2360 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2361 // we should go on...
2367 MacControlMap::iterator it
;
2368 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2370 if ( it
->second
== impl
)
2372 wxWinMacControlList
.erase(it
);
2380 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2382 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2385 m_isRootControl
= isRootControl
;
2389 wxWidgetImpl::wxWidgetImpl()
2394 wxWidgetImpl::~wxWidgetImpl()
2398 void wxWidgetImpl::Init()
2400 m_isRootControl
= false;
2402 m_needsFocusRect
= false;
2405 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2407 m_needsFocusRect
= needs
;
2410 bool wxWidgetImpl::NeedsFocusRect() const
2412 return m_needsFocusRect
;