1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/window_osx.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
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"
72 #define MAC_SCROLLBAR_SIZE 15
73 #define MAC_SMALL_SCROLLBAR_SIZE 11
77 #ifdef __WXUNIVERSAL__
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
85 #define wxMAC_DEBUG_REDRAW 0
86 #ifndef wxMAC_DEBUG_REDRAW
87 #define wxMAC_DEBUG_REDRAW 0
90 wxWidgetImplType
* kOSXNoWidgetImpl
= (wxWidgetImplType
*) -1L;
92 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
100 wxVector
<wxHotKeyRec
> s_hotkeys
;
104 // ===========================================================================
106 // ===========================================================================
108 // the grow box has to be implemented as an inactive window, so that nothing can direct
111 class WXDLLIMPEXP_CORE wxBlindPlateWindow
: public wxWindow
114 wxBlindPlateWindow() { Init(); }
116 // Old-style constructor (no default values for coordinates to avoid
117 // ambiguity with the new one)
118 wxBlindPlateWindow(wxWindow
*parent
,
119 int x
, int y
, int width
, int height
,
120 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
121 const wxString
& name
= wxPanelNameStr
)
125 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), style
, name
);
129 wxBlindPlateWindow(wxWindow
*parent
,
130 wxWindowID winid
= wxID_ANY
,
131 const wxPoint
& pos
= wxDefaultPosition
,
132 const wxSize
& size
= wxDefaultSize
,
133 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
134 const wxString
& name
= wxPanelNameStr
)
138 Create(parent
, winid
, pos
, size
, style
, name
);
142 bool Create(wxWindow
*parent
,
143 wxWindowID winid
= wxID_ANY
,
144 const wxPoint
& pos
= wxDefaultPosition
,
145 const wxSize
& size
= wxDefaultSize
,
146 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
147 const wxString
& name
= wxPanelNameStr
)
149 if ( !wxWindow::Create(parent
, winid
, pos
, size
, style
, name
) )
152 // so that non-solid background renders correctly under GTK+:
153 SetThemeEnabled(true);
157 virtual ~wxBlindPlateWindow();
159 virtual bool AcceptsFocus() const
165 // common part of all ctors
170 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow
)
171 DECLARE_EVENT_TABLE()
174 wxBlindPlateWindow::~wxBlindPlateWindow()
178 IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow
, wxWindow
)
180 BEGIN_EVENT_TABLE(wxBlindPlateWindow
, wxWindow
)
184 // ----------------------------------------------------------------------------
185 // constructors and such
186 // ----------------------------------------------------------------------------
188 wxWindowMac::wxWindowMac()
193 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
198 const wxString
& name
)
201 Create(parent
, id
, pos
, size
, style
, name
);
204 void wxWindowMac::Init()
208 m_cgContextRef
= NULL
;
210 // as all windows are created with WS_VISIBLE style...
213 m_hScrollBar
= NULL
;
214 m_vScrollBar
= NULL
;
215 m_hScrollBarAlwaysShown
= false;
216 m_vScrollBarAlwaysShown
= false;
219 m_clipChildren
= false ;
220 m_cachedClippedRectValid
= false ;
221 m_isNativeWindowWrapper
= false;
224 wxWindowMac::~wxWindowMac()
228 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
229 for ( int i
= s_hotkeys
.size()-1; i
>=0; -- i
)
231 if ( s_hotkeys
[i
].window
== this )
233 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
234 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
235 if ( UnregisterEventHotKey(ref
) != noErr
)
237 wxLogLastError(wxT("UnregisterHotKey"));
243 MacInvalidateBorders() ;
245 #ifndef __WXUNIVERSAL__
246 // VS: make sure there's no wxFrame with last focus set to us:
247 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
249 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
252 if ( frame
->GetLastFocus() == this )
253 frame
->SetLastFocus(NULL
);
259 // destroy children before destroying this window itself
262 // wxRemoveMacControlAssociation( this ) ;
263 // If we delete an item, we should initialize the parent panel,
264 // because it could now be invalid.
265 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
268 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
269 tlw
->SetDefaultItem(NULL
);
272 if ( g_MacLastWindow
== this )
273 g_MacLastWindow
= NULL
;
275 #ifndef __WXUNIVERSAL__
276 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
279 if ( frame
->GetLastFocus() == this )
280 frame
->SetLastFocus( NULL
) ;
284 // delete our drop target if we've got one
285 #if wxUSE_DRAG_AND_DROP
286 wxDELETE(m_dropTarget
);
292 WXWidget
wxWindowMac::GetHandle() const
295 return (WXWidget
) GetPeer()->GetWXWidget() ;
299 wxOSXWidgetImpl
* wxWindowMac::GetPeer() const
301 return m_peer
== kOSXNoWidgetImpl
? NULL
: m_peer
;
304 bool wxWindowMac::ShouldCreatePeer() const
306 return m_peer
!= kOSXNoWidgetImpl
;
309 void wxWindowMac::DontCreatePeer()
311 m_peer
= kOSXNoWidgetImpl
;
314 void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl
* wrapper
)
316 wxOSXWidgetImpl
* inner
= GetPeer();
317 wxASSERT_MSG( inner
!= NULL
&& inner
->IsOk(), "missing or incomplete inner peer" );
318 wxASSERT_MSG( wrapper
!= NULL
&& wrapper
->IsOk(), "missing or incomplete wrapper" );
320 if ( !(inner
!= NULL
&& inner
->IsOk() && wrapper
!= NULL
&& wrapper
->IsOk()) )
323 inner
->RemoveFromParent();
324 wrapper
->InstallEventHandler();
325 wrapper
->Embed(inner
);
329 void wxWindowMac::SetPeer(wxOSXWidgetImpl
* peer
)
333 if ( !GetPeer()->IsRootControl() )
334 GetPeer()->RemoveFromParent();
340 if ( GetPeer() && !GetPeer()->IsRootControl())
342 wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
344 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
345 GetParent()->AddChild( this );
347 GetPeer()->InstallEventHandler();
348 GetPeer()->Embed(GetParent()->GetPeer());
350 GetParent()->MacChildAdded() ;
352 // adjust font, controlsize etc
353 GetPeer()->SetControlSize( m_windowVariant
);
355 // in case nothing has been set, use the variant default fonts
357 DoSetWindowVariant( m_windowVariant
);
359 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
361 // for controls we want to use best size for wxDefaultSize params )
362 if ( !GetPeer()->IsUserPane() )
363 SetInitialSize(GetMinSize());
365 SetCursor( *wxSTANDARD_CURSOR
) ;
369 #if WXWIN_COMPATIBILITY_2_8
371 bool wxWindowMac::MacIsUserPane()
373 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
378 bool wxWindowMac::MacIsUserPane() const
380 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
383 // ---------------------------------------------------------------------------
384 // Utility Routines to move between different coordinate systems
385 // ---------------------------------------------------------------------------
388 * Right now we have the following setup :
389 * a border that is not part of the native control is always outside the
390 * control's border (otherwise we lose all native intelligence, future ways
391 * may be to have a second embedding control responsible for drawing borders
392 * and backgrounds eventually)
393 * so all this border calculations have to be taken into account when calling
394 * native methods or getting native oriented data
395 * so we have three coordinate systems here
396 * wx client coordinates
397 * wx window coordinates (including window frames)
405 bool wxWindowMac::Create(wxWindowMac
*parent
,
410 const wxString
& name
)
412 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
414 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
417 m_windowVariant
= parent
->GetWindowVariant() ;
419 if ( m_peer
!= kOSXNoWidgetImpl
)
421 SetPeer(wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() ));
422 MacPostControlCreate(pos
, size
) ;
425 #ifndef __WXUNIVERSAL__
426 // Don't give scrollbars to wxControls unless they ask for them
427 if ( (! IsKindOf(CLASSINFO(wxControl
))
429 && ! IsKindOf(CLASSINFO(wxStatusBar
))
432 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
434 MacCreateScrollBars( style
) ;
438 wxWindowCreateEvent
event((wxWindow
*)this);
439 GetEventHandler()->AddPendingEvent(event
);
444 void wxWindowMac::MacChildAdded()
448 m_vScrollBar
->Raise() ;
450 m_hScrollBar
->Raise() ;
456 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
),
457 const wxSize
& WXUNUSED(size
))
459 // todo remove if refactoring works correctly
461 wxASSERT_MSG( GetPeer() != NULL
&& GetPeer()->IsOk() , wxT("No valid mac control") ) ;
463 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
464 GetParent()->AddChild( this );
466 GetPeer()->InstallEventHandler();
467 GetPeer()->Embed(GetParent()->GetPeer());
469 GetParent()->MacChildAdded() ;
471 // adjust font, controlsize etc
472 DoSetWindowVariant( m_windowVariant
) ;
474 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
476 // for controls we want to use best size for wxDefaultSize params )
477 if ( !GetPeer()->IsUserPane() )
478 SetInitialSize(size
);
480 SetCursor( *wxSTANDARD_CURSOR
) ;
484 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
486 // Don't assert, in case we set the window variant before
487 // the window is created
488 // wxASSERT( GetPeer()->IsOk() ) ;
490 m_windowVariant
= variant
;
492 if (GetPeer() == NULL
|| !GetPeer()->IsOk())
495 GetPeer()->SetControlSize( variant
);
499 case wxWINDOW_VARIANT_NORMAL
:
500 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
504 case wxWINDOW_VARIANT_SMALL
:
505 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
509 case wxWINDOW_VARIANT_MINI
:
510 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
514 case wxWINDOW_VARIANT_LARGE
:
515 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
520 wxFAIL_MSG(wxT("unexpected window variant"));
525 void wxWindowMac::MacUpdateControlFont()
528 GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
530 // do not trigger refreshes upon invisible and possible partly created objects
531 if ( IsShownOnScreen() )
535 bool wxWindowMac::SetFont(const wxFont
& font
)
537 bool retval
= wxWindowBase::SetFont( font
);
539 MacUpdateControlFont() ;
544 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
546 bool retval
= wxWindowBase::SetForegroundColour( col
);
549 MacUpdateControlFont();
554 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
556 if ( !wxWindowBase::SetBackgroundStyle(style
) )
560 GetPeer()->SetBackgroundStyle(style
);
564 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
568 if ( m_backgroundColour
.IsOk() )
569 m_growBox
->SetBackgroundColour(m_backgroundColour
);
571 m_growBox
->SetBackgroundColour(*wxWHITE
);
574 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
578 GetPeer()->SetBackgroundColour( col
) ;
583 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
585 while (w
&& !w
->IsTopLevel())
594 void wxWindowMac::SetFocus()
596 if ( !AcceptsFocus() )
599 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
602 wxWindow
* former
= FindFocus() ;
603 if ( former
== this )
606 GetPeer()->SetFocus() ;
609 void wxWindowMac::OSXSimulateFocusEvents()
611 wxWindow
* former
= FindFocus() ;
612 if ( former
!= NULL
&& former
!= this )
615 wxFocusEvent
event( wxEVT_KILL_FOCUS
, former
->GetId());
616 event
.SetEventObject(former
);
617 event
.SetWindow(this);
618 former
->HandleWindowEvent(event
) ;
622 wxFocusEvent
event(wxEVT_SET_FOCUS
, former
->GetId());
623 event
.SetEventObject(former
);
624 event
.SetWindow(this);
625 former
->HandleWindowEvent(event
);
630 void wxWindowMac::DoCaptureMouse()
632 wxApp::s_captureWindow
= (wxWindow
*) this ;
633 GetPeer()->CaptureMouse() ;
636 wxWindow
* wxWindowBase::GetCapture()
638 return wxApp::s_captureWindow
;
641 void wxWindowMac::DoReleaseMouse()
643 wxApp::s_captureWindow
= NULL
;
645 GetPeer()->ReleaseMouse() ;
648 #if wxUSE_DRAG_AND_DROP
650 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
654 m_dropTarget
= pDropTarget
;
656 GetPeer()->SetDropTarget(m_dropTarget
) ;
661 // Old-style File Manager Drag & Drop
662 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
667 // From a wx position / size calculate the appropriate size of the native control
669 bool wxWindowMac::MacGetBoundsForControl(
673 int& w
, int& h
, bool adjustOrigin
) const
675 // the desired size, minus the border pixels gives the correct size of the control
679 w
= WidthDefault( size
.x
);
680 h
= HeightDefault( size
.y
);
682 x
+= MacGetLeftBorderSize() ;
683 y
+= MacGetTopBorderSize() ;
684 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
685 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
688 AdjustForParentClientOrigin( x
, y
) ;
690 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
691 if ( GetParent() && !GetParent()->IsTopLevel() )
693 x
-= GetParent()->MacGetLeftBorderSize() ;
694 y
-= GetParent()->MacGetTopBorderSize() ;
700 // Get window size (not client size)
701 void wxWindowMac::DoGetSize(int *x
, int *y
) const
704 GetPeer()->GetSize( width
, height
);
707 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
709 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
712 // get the position of the bounds of this window in client coordinates of its parent
713 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
717 GetPeer()->GetPosition( x1
, y1
) ;
719 // get the wx window position from the native one
720 x1
-= MacGetLeftBorderSize() ;
721 y1
-= MacGetTopBorderSize() ;
725 wxWindow
*parent
= GetParent();
728 // we must first adjust it to be in window coordinates of the parent,
729 // as otherwise it gets lost by the ClientAreaOrigin fix
730 x1
+= parent
->MacGetLeftBorderSize() ;
731 y1
+= parent
->MacGetTopBorderSize() ;
733 // and now to client coordinates
734 wxPoint
pt(parent
->GetClientAreaOrigin());
746 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
748 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
749 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
750 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
751 MacRootWindowToWindow( x
, y
) ;
753 wxPoint origin
= GetClientAreaOrigin() ;
760 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
762 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
763 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
765 wxPoint origin
= GetClientAreaOrigin() ;
771 MacWindowToRootWindow( x
, y
) ;
772 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
775 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
777 wxPoint origin
= GetClientAreaOrigin() ;
783 MacWindowToRootWindow( x
, y
) ;
786 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
797 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
800 pt
.x
-= MacGetLeftBorderSize() ;
801 pt
.y
-= MacGetTopBorderSize() ;
802 wxWidgetImpl::Convert( &pt
, GetPeer() , top
->GetPeer() ) ;
812 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
823 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
826 wxWidgetImpl::Convert( &pt
, top
->GetPeer() , GetPeer() ) ;
827 pt
.x
+= MacGetLeftBorderSize() ;
828 pt
.y
+= MacGetTopBorderSize() ;
838 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
840 wxSize sizeTotal
= size
;
842 int innerwidth
, innerheight
;
844 int outerwidth
, outerheight
;
846 GetPeer()->GetContentArea( left
, top
, innerwidth
, innerheight
);
847 GetPeer()->GetSize( outerwidth
, outerheight
);
849 sizeTotal
.x
+= outerwidth
-innerwidth
;
850 sizeTotal
.y
+= outerheight
-innerheight
;
852 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
853 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
858 // Get size *available for subwindows* i.e. excluding menu bar etc.
859 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
865 GetPeer()->GetContentArea( left
, top
, ww
, hh
);
867 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
868 hh
-= m_hScrollBar
->GetSize().y
;
870 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
871 ww
-= m_vScrollBar
->GetSize().x
;
876 // we shouldn't return invalid width
885 // we shouldn't return invalid height
893 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
895 if (m_cursor
.IsSameAs(cursor
))
900 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
905 if ( ! wxWindowBase::SetCursor( cursor
) )
909 wxASSERT_MSG( m_cursor
.IsOk(),
910 wxT("cursor must be valid after call to the base version"));
912 if ( GetPeer() != NULL
)
913 GetPeer()->SetCursor( m_cursor
);
919 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
921 #ifndef __WXUNIVERSAL__
924 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
926 wxPoint mouse
= wxGetMousePosition();
932 ClientToScreen( &x
, &y
) ;
934 menu
->GetPeer()->PopUp(this, x
, y
);
937 // actually this shouldn't be called, because universal is having its own implementation
943 // ----------------------------------------------------------------------------
945 // ----------------------------------------------------------------------------
949 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
951 wxWindowBase::DoSetToolTip(tooltip
);
954 m_tooltip
->SetWindow(this);
957 GetPeer()->SetToolTip(tooltip
);
962 void wxWindowMac::MacInvalidateBorders()
964 if ( GetPeer() == NULL
)
967 bool vis
= IsShownOnScreen() ;
971 int outerBorder
= MacGetLeftBorderSize() ;
973 if ( GetPeer()->NeedsFocusRect() )
976 if ( outerBorder
== 0 )
979 // now we know that we have something to do at all
983 GetPeer()->GetSize( tw
, th
);
984 GetPeer()->GetPosition( tx
, ty
);
986 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
987 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
988 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
989 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
992 GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate
);
993 GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate
);
994 GetParent()->GetPeer()->SetNeedsDisplay(&topupdate
);
995 GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate
);
999 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1001 // this is never called for a toplevel window, so we know we have a parent
1002 int former_x
, former_y
, former_w
, former_h
;
1004 // Get true coordinates of former position
1005 DoGetPosition( &former_x
, &former_y
) ;
1006 DoGetSize( &former_w
, &former_h
) ;
1008 wxWindow
*parent
= GetParent();
1011 wxPoint
pt(parent
->GetClientAreaOrigin());
1016 int actualWidth
= width
;
1017 int actualHeight
= height
;
1022 // min and max sizes are only for sizers, not for explicit size setting
1023 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1024 actualWidth
= m_minWidth
;
1025 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1026 actualHeight
= m_minHeight
;
1027 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1028 actualWidth
= m_maxWidth
;
1029 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1030 actualHeight
= m_maxHeight
;
1033 bool doMove
= false, doResize
= false ;
1035 if ( actualX
!= former_x
|| actualY
!= former_y
)
1038 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1041 if ( doMove
|| doResize
)
1043 // as the borders are drawn outside the native control, we adjust now
1045 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1046 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1047 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1049 if ( parent
&& !parent
->IsTopLevel() )
1051 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
1054 MacInvalidateBorders() ;
1056 m_cachedClippedRectValid
= false ;
1058 GetPeer()->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
1060 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1062 MacInvalidateBorders() ;
1064 MacRepositionScrollBars() ;
1067 wxPoint
point(actualX
, actualY
);
1068 wxMoveEvent
event(point
, m_windowId
);
1069 event
.SetEventObject(this);
1070 HandleWindowEvent(event
) ;
1075 MacRepositionScrollBars() ;
1081 wxSize
wxWindowMac::DoGetBestSize() const
1083 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() || IsTopLevel() )
1085 return wxWindowBase::DoGetBestSize() ;
1091 GetPeer()->GetBestRect(&r
);
1093 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
1101 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1108 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1115 // return wxWindowBase::DoGetBestSize() ;
1119 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1120 MacGetRightBorderSize();
1121 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1122 MacGetBottomBorderSize();
1123 if ( bestHeight
< 10 )
1126 return wxSize(bestWidth
, bestHeight
);
1130 void wxWindowMac::SendSizeEvent(int flags
)
1132 MacOnInternalSize();
1133 wxWindowBase::SendSizeEvent(flags
);
1136 // set the size of the window: if the dimensions are positive, just use them,
1137 // but if any of them is equal to -1, it means that we must find the value for
1138 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1139 // which case -1 is a valid value for x and y)
1141 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1142 // the width/height to best suit our contents, otherwise we reuse the current
1144 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1146 // get the current size and position...
1147 int currentX
, currentY
;
1148 int currentW
, currentH
;
1150 GetPosition(¤tX
, ¤tY
);
1151 GetSize(¤tW
, ¤tH
);
1153 // ... and don't do anything (avoiding flicker) if it's already ok
1154 if ( x
== currentX
&& y
== currentY
&&
1155 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1158 MacRepositionScrollBars() ; // we might have a real position shift
1160 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1168 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1170 if ( x
== wxDefaultCoord
)
1172 if ( y
== wxDefaultCoord
)
1176 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1178 wxSize size
= wxDefaultSize
;
1179 if ( width
== wxDefaultCoord
)
1181 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1183 size
= DoGetBestSize();
1188 // just take the current one
1193 if ( height
== wxDefaultCoord
)
1195 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1197 if ( size
.x
== wxDefaultCoord
)
1198 size
= DoGetBestSize();
1199 // else: already called DoGetBestSize() above
1205 // just take the current one
1210 DoMoveWindow( x
, y
, width
, height
);
1213 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1215 int left
,top
,width
,height
;
1216 GetPeer()->GetContentArea( left
, top
, width
, height
);
1217 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1220 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1222 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1224 int currentclientwidth
, currentclientheight
;
1225 int currentwidth
, currentheight
;
1227 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1228 GetSize( ¤twidth
, ¤theight
) ;
1230 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1231 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1235 double wxWindowMac::GetContentScaleFactor() const
1237 return GetPeer()->GetContentScaleFactor();
1240 void wxWindowMac::SetLabel(const wxString
& title
)
1242 if ( title
== m_label
)
1247 InvalidateBestSize();
1249 if ( GetPeer() && GetPeer()->IsOk() )
1250 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1252 // do not trigger refreshes upon invisible and possible partly created objects
1253 if ( IsShownOnScreen() )
1257 wxString
wxWindowMac::GetLabel() const
1262 bool wxWindowMac::Show(bool show
)
1265 MacInvalidateBorders();
1267 if ( !wxWindowBase::Show(show
) )
1271 GetPeer()->SetVisibility( show
) ;
1274 MacInvalidateBorders();
1276 #ifdef __WXOSX_IPHONE__
1277 // only when there's no native event support
1278 if ( !IsTopLevel() )
1281 wxShowEvent
eventShow(GetId(), show
);
1282 eventShow
.SetEventObject(this);
1284 HandleWindowEvent(eventShow
);
1290 bool wxWindowMac::OSXShowWithEffect(bool show
,
1291 wxShowEffect effect
,
1294 if ( effect
== wxSHOW_EFFECT_NONE
||
1295 !GetPeer() || !GetPeer()->ShowWithEffect(show
, effect
, timeout
) )
1301 void wxWindowMac::DoEnable(bool enable
)
1303 GetPeer()->Enable( enable
) ;
1304 MacInvalidateBorders();
1308 // status change notifications
1311 void wxWindowMac::MacVisibilityChanged()
1315 void wxWindowMac::MacHiliteChanged()
1319 void wxWindowMac::MacEnabledStateChanged()
1324 // status queries on the inherited window's state
1327 bool wxWindowMac::MacIsReallyEnabled()
1329 return GetPeer()->IsEnabled() ;
1332 bool wxWindowMac::MacIsReallyHilited()
1334 #if wxOSX_USE_CARBON
1335 return GetPeer()->IsActive();
1337 return true; // TODO
1341 int wxWindowMac::GetCharHeight() const
1344 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1349 int wxWindowMac::GetCharWidth() const
1352 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1357 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1360 int *externalLeading
,
1361 const wxFont
*theFont
) const
1363 const wxFont
*fontToUse
= theFont
;
1367 tempFont
= GetFont();
1368 fontToUse
= &tempFont
;
1371 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1372 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1374 wxDouble h
, d
, e
, w
;
1375 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1379 if ( externalLeading
)
1380 *externalLeading
= (wxCoord
)(e
+0.5);
1382 *descent
= (wxCoord
)(d
+0.5);
1384 *x
= (wxCoord
)(w
+0.5);
1386 *y
= (wxCoord
)(h
+0.5);
1390 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1391 * we always intersect with the entire window, not only with the client area
1394 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1396 if ( GetPeer() == NULL
)
1399 if ( !IsShownOnScreen() )
1405 GetPeer()->SetNeedsDisplay( rect
) ;
1408 void wxWindowMac::DoFreeze()
1410 if ( GetPeer() && GetPeer()->IsOk() )
1411 GetPeer()->SetDrawingEnabled( false ) ;
1414 void wxWindowMac::DoThaw()
1416 if ( GetPeer() && GetPeer()->IsOk() )
1417 GetPeer()->SetDrawingEnabled( true ) ;
1420 wxWindow
*wxGetActiveWindow()
1422 // actually this is a windows-only concept
1426 // Coordinates relative to the window
1427 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1429 #if wxOSX_USE_COCOA_OR_CARBON
1432 DoClientToScreen(&x
, &y
);
1433 CGPoint cgpoint
= CGPointMake( x
, y
);
1434 CGWarpMouseCursorPosition( cgpoint
);
1436 // At least GTK sends a mouse moved event after WarpMouse
1437 wxMouseEvent
event(wxEVT_MOTION
);
1440 wxMouseState mState
= ::wxGetMouseState();
1442 event
.m_altDown
= mState
.AltDown();
1443 event
.m_controlDown
= mState
.ControlDown();
1444 event
.m_leftDown
= mState
.LeftIsDown();
1445 event
.m_middleDown
= mState
.MiddleIsDown();
1446 event
.m_rightDown
= mState
.RightIsDown();
1447 event
.m_metaDown
= mState
.MetaDown();
1448 event
.m_shiftDown
= mState
.ShiftDown();
1449 event
.SetId(GetId());
1450 event
.SetEventObject(this);
1451 GetEventHandler()->ProcessEvent(event
);
1455 int wxWindowMac::GetScrollPos(int orient
) const
1458 if ( orient
== wxHORIZONTAL
)
1461 return m_hScrollBar
->GetThumbPosition() ;
1466 return m_vScrollBar
->GetThumbPosition() ;
1472 // This now returns the whole range, not just the number
1473 // of positions that we can scroll.
1474 int wxWindowMac::GetScrollRange(int orient
) const
1477 if ( orient
== wxHORIZONTAL
)
1480 return m_hScrollBar
->GetRange() ;
1485 return m_vScrollBar
->GetRange() ;
1491 int wxWindowMac::GetScrollThumb(int orient
) const
1494 if ( orient
== wxHORIZONTAL
)
1497 return m_hScrollBar
->GetThumbSize() ;
1502 return m_vScrollBar
->GetThumbSize() ;
1508 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1511 if ( orient
== wxHORIZONTAL
)
1514 m_hScrollBar
->SetThumbPosition( pos
) ;
1519 m_vScrollBar
->SetThumbPosition( pos
) ;
1525 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1527 bool needVisibilityUpdate
= false;
1529 if ( m_hScrollBarAlwaysShown
!= hflag
)
1531 m_hScrollBarAlwaysShown
= hflag
;
1532 needVisibilityUpdate
= true;
1535 if ( m_vScrollBarAlwaysShown
!= vflag
)
1537 m_vScrollBarAlwaysShown
= vflag
;
1538 needVisibilityUpdate
= true;
1541 if ( needVisibilityUpdate
)
1542 DoUpdateScrollbarVisibility();
1546 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1547 // our own window origin is at leftOrigin/rightOrigin
1550 void wxWindowMac::MacPaintGrowBox()
1556 if ( MacHasScrollBarCorner() )
1559 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1560 wxASSERT( cgContext
) ;
1564 GetPeer()->GetSize( tw
, th
);
1565 GetPeer()->GetPosition( tx
, ty
);
1567 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1570 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1571 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1572 CGContextSaveGState( cgContext
);
1574 if ( m_backgroundColour
.IsOk() )
1576 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1580 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1582 CGContextFillRect( cgContext
, cgrect
);
1583 CGContextRestoreGState( cgContext
);
1587 if ( m_backgroundColour
.IsOk() )
1588 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1590 m_growBox
->SetBackgroundColour(*wxWHITE
);
1598 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1603 bool hasFocus
= GetPeer()->NeedsFocusRect() && HasFocus();
1605 // back to the surrounding frame rectangle
1608 GetPeer()->GetSize( tw
, th
);
1609 GetPeer()->GetPosition( tx
, ty
);
1611 #if wxOSX_USE_COCOA_OR_CARBON
1614 CGRect cgrect
= CGRectMake( tx
-1 , ty
-1 , tw
+2 ,
1617 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1618 wxASSERT( cgContext
) ;
1620 if ( GetPeer()->NeedsFrame() )
1622 HIThemeFrameDrawInfo info
;
1623 memset( &info
, 0 , sizeof(info
) ) ;
1627 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1628 info
.isFocused
= hasFocus
;
1630 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1632 info
.kind
= kHIThemeFrameTextFieldSquare
;
1633 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1635 else if ( HasFlag(wxSIMPLE_BORDER
) )
1637 info
.kind
= kHIThemeFrameListBox
;
1638 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1644 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1647 #endif // wxOSX_USE_COCOA_OR_CARBON
1650 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1653 if ( child
== m_hScrollBar
)
1654 m_hScrollBar
= NULL
;
1655 if ( child
== m_vScrollBar
)
1656 m_vScrollBar
= NULL
;
1657 if ( child
== m_growBox
)
1660 wxWindowBase::RemoveChild( child
) ;
1663 void wxWindowMac::DoUpdateScrollbarVisibility()
1666 bool triggerSizeEvent
= false;
1670 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1672 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1674 m_hScrollBar
->Show( showHScrollBar
);
1675 triggerSizeEvent
= true;
1681 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1683 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1685 m_vScrollBar
->Show( showVScrollBar
) ;
1686 triggerSizeEvent
= true;
1690 MacRepositionScrollBars() ;
1691 if ( triggerSizeEvent
)
1698 // New function that will replace some of the above.
1699 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1700 int range
, bool refresh
)
1703 // Updating scrollbars when window is being deleted is useless and
1704 // currently results in asserts in client-to-screen coordinates conversion
1705 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1706 if ( m_isBeingDeleted
)
1709 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1710 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1711 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1712 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1714 DoUpdateScrollbarVisibility();
1718 // Does a physical scroll
1719 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1721 if ( dx
== 0 && dy
== 0 )
1724 int width
, height
;
1725 GetClientSize( &width
, &height
) ;
1728 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1730 scrollrect
.Intersect( *rect
) ;
1731 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1732 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1734 GetPeer()->ScrollRect( &scrollrect
, dx
, dy
);
1739 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1741 child
= node
->GetData();
1745 if (child
->IsTopLevel())
1748 if ( !IsClientAreaChild(child
) )
1751 child
->GetPosition( &x
, &y
);
1752 child
->GetSize( &w
, &h
);
1755 wxRect
rc( x
, y
, w
, h
);
1756 if (rect
->Intersects( rc
))
1757 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1761 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1766 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1769 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1771 wxScrollWinEvent wevent
;
1772 wevent
.SetPosition(event
.GetPosition());
1773 wevent
.SetOrientation(event
.GetOrientation());
1774 wevent
.SetEventObject(this);
1776 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1777 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1778 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1779 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1780 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1781 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1782 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1783 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1784 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1785 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1786 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1787 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1788 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1789 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1790 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1791 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1793 HandleWindowEvent(wevent
);
1798 wxWindow
*wxWindowBase::DoFindFocus()
1800 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1803 // Raise the window to the top of the Z order
1804 void wxWindowMac::Raise()
1809 // Lower the window to the bottom of the Z order
1810 void wxWindowMac::Lower()
1815 // static wxWindow *gs_lastWhich = NULL;
1817 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1819 // first trigger a set cursor event
1821 wxPoint clientorigin
= GetClientAreaOrigin() ;
1822 wxSize clientsize
= GetClientSize() ;
1824 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1826 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1827 event
.SetId(GetId());
1828 event
.SetEventObject(this);
1830 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1831 if ( processedEvtSetCursor
&& event
.HasCursor() )
1833 cursor
= event
.GetCursor() ;
1837 // the test for processedEvtSetCursor is here to prevent using m_cursor
1838 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1839 // it - this is a way to say that our cursor shouldn't be used for this
1841 if ( !processedEvtSetCursor
&& m_cursor
.IsOk() )
1844 if ( !wxIsBusy() && !GetParent() )
1845 cursor
= *wxSTANDARD_CURSOR
;
1848 if ( cursor
.IsOk() )
1849 cursor
.MacInstall() ;
1852 return cursor
.IsOk() ;
1855 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1859 return m_tooltip
->GetTip() ;
1862 return wxEmptyString
;
1865 void wxWindowMac::ClearBackground()
1871 void wxWindowMac::Update()
1873 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1878 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1880 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1884 if ( iter
->IsTopLevel() )
1886 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1890 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1895 iter
= iter
->GetParent() ;
1901 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1903 MacUpdateClippedRects() ;
1905 return m_cachedClippedClientRect
;
1908 const wxRect
& wxWindowMac::MacGetClippedRect() const
1910 MacUpdateClippedRects() ;
1912 return m_cachedClippedRect
;
1915 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1917 MacUpdateClippedRects() ;
1919 return m_cachedClippedRectWithOuterStructure
;
1922 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1924 static wxRegion emptyrgn
;
1926 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1928 MacUpdateClippedRects() ;
1929 if ( includeOuterStructures
)
1930 return m_cachedClippedRegionWithOuterStructure
;
1932 return m_cachedClippedRegion
;
1940 void wxWindowMac::MacUpdateClippedRects() const
1942 #if wxOSX_USE_CARBON
1943 if ( m_cachedClippedRectValid
)
1946 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1947 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1948 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1949 // to add focus borders everywhere
1951 Rect rIncludingOuterStructures
;
1955 GetPeer()->GetSize( tw
, th
);
1956 GetPeer()->GetPosition( tx
, ty
);
1958 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1960 r
.left
-= MacGetLeftBorderSize() ;
1961 r
.top
-= MacGetTopBorderSize() ;
1962 r
.bottom
+= MacGetBottomBorderSize() ;
1963 r
.right
+= MacGetRightBorderSize() ;
1970 rIncludingOuterStructures
= r
;
1971 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1973 wxRect cl
= GetClientRect() ;
1974 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1978 const wxWindow
* child
= (wxWindow
*) this ;
1979 const wxWindow
* parent
= NULL
;
1981 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1983 if ( parent
->MacIsChildOfClientArea(child
) )
1985 size
= parent
->GetClientSize() ;
1986 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1992 // this will be true for scrollbars, toolbars etc.
1993 size
= parent
->GetSize() ;
1994 y
= parent
->MacGetTopBorderSize() ;
1995 x
= parent
->MacGetLeftBorderSize() ;
1996 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1997 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2000 parent
->MacWindowToRootWindow( &x
, &y
) ;
2001 MacRootWindowToWindow( &x
, &y
) ;
2003 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2005 // the wxwindow and client rects will always be clipped
2006 SectRect( &r
, &rparent
, &r
) ;
2007 SectRect( &rClient
, &rparent
, &rClient
) ;
2009 // the structure only at 'hard' borders
2010 if ( parent
->MacClipChildren() ||
2011 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2013 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2019 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2020 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2021 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2022 m_cachedClippedRectWithOuterStructure
= wxRect(
2023 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2024 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2025 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2027 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2028 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2029 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2031 m_cachedClippedRectValid
= true ;
2036 This function must not change the updatergn !
2038 bool wxWindowMac::MacDoRedraw( long time
)
2040 bool handled
= false ;
2042 wxRegion formerUpdateRgn
= m_updateRegion
;
2043 wxRegion clientUpdateRgn
= formerUpdateRgn
;
2045 const wxRect clientRect
= GetClientRect();
2047 clientUpdateRgn
.Intersect(clientRect
);
2049 // first send an erase event to the entire update area
2050 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
2053 case wxBG_STYLE_ERASE
:
2054 case wxBG_STYLE_SYSTEM
:
2055 case wxBG_STYLE_COLOUR
:
2057 // for the toplevel window this really is the entire area for
2058 // all the others only their client area, otherwise they might
2059 // be drawing with full alpha and eg put blue into the grow-box
2060 // area of a scrolled window (scroll sample)
2061 wxWindowDC
dc(this);
2063 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
2065 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
2067 if ( bgStyle
== wxBG_STYLE_ERASE
)
2069 wxEraseEvent
eevent( GetId(), &dc
);
2070 eevent
.SetEventObject( this );
2071 if ( ProcessWindowEvent( eevent
) )
2077 dc
.SetBackground(GetBackgroundColour());
2083 case wxBG_STYLE_PAINT
:
2084 case wxBG_STYLE_TRANSPARENT
:
2085 // nothing to do, user-defined EVT_PAINT handler will overwrite the
2086 // entire window client area
2090 wxFAIL_MSG( "unsupported background style" );
2093 // as this is a full window, shouldn't be necessary anymore
2094 // MacPaintGrowBox();
2096 // calculate a client-origin version of the update rgn and set
2097 // m_updateRegion to that
2098 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
2099 m_updateRegion
= clientUpdateRgn
;
2101 if ( !m_updateRegion
.Empty() )
2103 // paint the window itself
2105 wxPaintEvent
event(GetId());
2106 event
.SetTimestamp(time
);
2107 event
.SetEventObject(this);
2108 handled
= HandleWindowEvent(event
);
2111 m_updateRegion
= formerUpdateRgn
;
2113 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2115 top
->WindowWasPainted() ;
2120 void wxWindowMac::MacPaintChildrenBorders()
2122 // now we cannot rely on having its borders drawn by a window itself, as it does not
2123 // get the updateRgn wide enough to always do so, so we do it from the parent
2124 // this would also be the place to draw any custom backgrounds for native controls
2125 // in Composited windowing
2126 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2130 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2132 child
= node
->GetData();
2136 if (child
== m_vScrollBar
)
2138 if (child
== m_hScrollBar
)
2140 if (child
== m_growBox
)
2143 if (child
->IsTopLevel())
2145 if (!child
->IsShown())
2148 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2150 child
->GetPosition( &x
, &y
);
2151 child
->GetSize( &w
, &h
);
2153 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2155 // paint custom borders
2156 wxNcPaintEvent
eventNc( child
->GetId() );
2157 eventNc
.SetEventObject( child
);
2158 if ( !child
->HandleWindowEvent( eventNc
) )
2160 child
->MacPaintBorders(0, 0) ;
2167 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2169 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2170 return tlw
? tlw
->GetWXWindow() : NULL
;
2173 bool wxWindowMac::MacHasScrollBarCorner() const
2176 /* Returns whether the scroll bars in a wxScrolledWindow should be
2177 * shortened. Scroll bars should be shortened if either:
2179 * - both scroll bars are visible, or
2181 * - there is a resize box in the parent frame's corner and this
2182 * window shares the bottom and right edge with the parent
2186 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2189 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2190 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2192 // Both scroll bars visible
2197 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2199 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2201 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2204 // starting from 10.7 there are no resize indicators anymore
2205 if ( (frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
) && UMAGetSystemVersion() < 0x1070)
2207 // Parent frame has resize handle
2208 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2210 // Note: allow for some wiggle room here as wxMac's
2211 // window rect calculations seem to be imprecise
2212 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2213 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2215 // Parent frame has resize handle and shares
2216 // right bottom corner
2221 // Parent frame has resize handle but doesn't
2222 // share right bottom corner
2228 // Parent frame doesn't have resize handle
2234 // No parent frame found
2242 void wxWindowMac::MacCreateScrollBars( long style
)
2245 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2247 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2249 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2250 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2252 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2255 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2257 GetClientSize( &width
, &height
) ;
2259 wxPoint
vPoint(width
- scrlsize
, 0) ;
2260 wxSize
vSize(scrlsize
, height
- adjust
) ;
2261 wxPoint
hPoint(0, height
- scrlsize
) ;
2262 wxSize
hSize(width
- adjust
, scrlsize
) ;
2264 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2265 if ( style
& wxVSCROLL
)
2267 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2268 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2271 if ( style
& wxHSCROLL
)
2273 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2274 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2277 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2278 wxSize
gSize(scrlsize
, scrlsize
);
2279 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2282 // because the create does not take into account the client area origin
2283 // we might have a real position shift
2284 MacRepositionScrollBars() ;
2288 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2290 bool result
= ((child
== NULL
)
2292 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2299 void wxWindowMac::MacRepositionScrollBars()
2302 if ( !m_hScrollBar
&& !m_vScrollBar
)
2305 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2306 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2308 // get real client area
2310 GetSize( &width
, &height
);
2312 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2313 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2315 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2316 wxSize
vSize( scrlsize
, height
- adjust
) ;
2317 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2318 wxSize
hSize( width
- adjust
, scrlsize
) ;
2321 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2323 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2326 if ( MacHasScrollBarCorner() )
2328 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2329 if ( !m_growBox
->IsShown() )
2334 if ( m_growBox
->IsShown() )
2341 bool wxWindowMac::AcceptsFocus() const
2343 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() )
2344 return wxWindowBase::AcceptsFocus();
2346 return GetPeer()->CanFocus();
2349 void wxWindowMac::MacSuperChangedPosition()
2351 // only window-absolute structures have to be moved i.e. controls
2353 m_cachedClippedRectValid
= false ;
2356 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2359 child
= node
->GetData();
2360 child
->MacSuperChangedPosition() ;
2362 node
= node
->GetNext();
2366 void wxWindowMac::MacTopLevelWindowChangedPosition()
2368 // only screen-absolute structures have to be moved i.e. glcanvas
2371 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2374 child
= node
->GetData();
2375 child
->MacTopLevelWindowChangedPosition() ;
2377 node
= node
->GetNext();
2381 long wxWindowMac::MacGetWXBorderSize() const
2388 if ( GetPeer() && GetPeer()->NeedsFrame() )
2390 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2392 #if wxOSX_USE_COCOA_OR_CARBON
2393 // this metric is only the 'outset' outside the simple frame rect
2394 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2400 else if (HasFlag(wxSIMPLE_BORDER
))
2402 #if wxOSX_USE_COCOA_OR_CARBON
2403 // this metric is only the 'outset' outside the simple frame rect
2404 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2415 long wxWindowMac::MacGetLeftBorderSize() const
2417 // the wx borders are all symmetric in mac themes
2418 long border
= MacGetWXBorderSize() ;
2422 int left
, top
, right
, bottom
;
2423 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2431 long wxWindowMac::MacGetRightBorderSize() const
2433 // the wx borders are all symmetric in mac themes
2434 long border
= MacGetWXBorderSize() ;
2438 int left
, top
, right
, bottom
;
2439 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2446 long wxWindowMac::MacGetTopBorderSize() const
2448 // the wx borders are all symmetric in mac themes
2449 long border
= MacGetWXBorderSize() ;
2453 int left
, top
, right
, bottom
;
2454 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2461 long wxWindowMac::MacGetBottomBorderSize() const
2463 // the wx borders are all symmetric in mac themes
2464 long border
= MacGetWXBorderSize() ;
2468 int left
, top
, right
, bottom
;
2469 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2476 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2478 return style
& ~wxBORDER_MASK
;
2481 // Find the wxWindowMac at the current mouse position, returning the mouse
2483 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2485 pt
= wxGetMousePosition();
2486 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2488 return (wxWindow
*) found
;
2491 // Get the current mouse position.
2492 wxPoint
wxGetMousePosition()
2496 wxGetMousePosition( &x
, &y
);
2498 return wxPoint(x
, y
);
2501 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2503 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2505 // copied from wxGTK : CS
2506 // VZ: shouldn't we move this to base class then?
2508 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2511 // (a) it's a command event and so is propagated to the parent
2512 // (b) under MSW it can be generated from kbd too
2513 // (c) it uses screen coords (because of (a))
2514 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2516 this->ClientToScreen(event
.GetPosition()));
2517 evtCtx
.SetEventObject(this);
2518 if ( ! HandleWindowEvent(evtCtx
) )
2527 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2531 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2535 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2536 Rect bounds
= { static_cast<short>(y
), static_cast<short>(x
), static_cast<short>(y
+ h
), static_cast<short>(x
+ w
) };
2541 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2546 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2548 #if wxOSX_USE_COCOA_OR_CARBON
2549 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2552 return eventNotHandledErr
;
2558 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2560 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2561 if ( !wxWindowBase::Reparent(newParent
) )
2564 GetPeer()->RemoveFromParent();
2565 GetPeer()->Embed( GetParent()->GetPeer() );
2571 bool wxWindowMac::SetTransparent(wxByte alpha
)
2573 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2575 if ( alpha
!= m_macAlpha
)
2577 m_macAlpha
= alpha
;
2584 bool wxWindowMac::CanSetTransparent()
2589 wxByte
wxWindowMac::GetTransparent() const
2594 bool wxWindowMac::IsShownOnScreen() const
2596 if ( GetPeer() && GetPeer()->IsOk() )
2598 bool peerVis
= GetPeer()->IsVisible();
2599 bool wxVis
= wxWindowBase::IsShownOnScreen();
2600 if( peerVis
!= wxVis
)
2602 // CS : put a breakpoint here to investigate differences
2603 // between native an wx visibilities
2604 // the only place where I've encountered them until now
2605 // are the hiding/showing sequences where the vis-changed event is
2606 // first sent to the innermost control, while wx does things
2607 // from the outmost control
2608 wxVis
= wxWindowBase::IsShownOnScreen();
2612 return GetPeer()->IsVisible();
2614 return wxWindowBase::IsShownOnScreen();
2617 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
2620 wxHotKeyHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
2622 void* WXUNUSED(userData
))
2624 EventHotKeyID hotKeyId
;
2626 GetEventParameter( event
, kEventParamDirectObject
, typeEventHotKeyID
, NULL
, sizeof(hotKeyId
), NULL
, &hotKeyId
);
2628 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2630 if ( s_hotkeys
[i
].keyId
== static_cast<int>(hotKeyId
.id
) )
2632 unsigned char charCode
;
2635 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
2637 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
2638 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
2639 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
2641 UInt32 keymessage
= (keyCode
<< 8) + charCode
;
2643 wxKeyEvent
wxevent(wxEVT_HOTKEY
);
2644 wxevent
.SetId(hotKeyId
.id
);
2645 wxTheApp
->MacCreateKeyEvent( wxevent
, s_hotkeys
[i
].window
, keymessage
,
2646 modifiers
, when
, 0 ) ;
2648 s_hotkeys
[i
].window
->HandleWindowEvent(wxevent
);
2655 bool wxWindowMac::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
2657 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2659 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2661 wxLogLastError(wxT("hotkeyId already registered"));
2667 static bool installed
= false;
2670 EventTypeSpec eventType
;
2671 eventType
.eventClass
=kEventClassKeyboard
;
2672 eventType
.eventKind
=kEventHotKeyPressed
;
2674 InstallApplicationEventHandler(&wxHotKeyHandler
, 1, &eventType
, NULL
, NULL
);
2678 UInt32 mac_modifiers
=0;
2679 if ( modifiers
& wxMOD_ALT
)
2680 mac_modifiers
|= optionKey
;
2681 if ( modifiers
& wxMOD_SHIFT
)
2682 mac_modifiers
|= shiftKey
;
2683 if ( modifiers
& wxMOD_RAW_CONTROL
)
2684 mac_modifiers
|= controlKey
;
2685 if ( modifiers
& wxMOD_CONTROL
)
2686 mac_modifiers
|= cmdKey
;
2688 EventHotKeyRef hotKeyRef
;
2689 EventHotKeyID hotKeyIDmac
;
2691 hotKeyIDmac
.signature
= 'WXMC';
2692 hotKeyIDmac
.id
= hotkeyId
;
2694 if ( RegisterEventHotKey(wxCharCodeWXToOSX((wxKeyCode
)keycode
), mac_modifiers
, hotKeyIDmac
,
2695 GetApplicationEventTarget(), 0, &hotKeyRef
) != noErr
)
2697 wxLogLastError(wxT("RegisterHotKey"));
2708 s_hotkeys
.push_back(v
);
2714 bool wxWindowMac::UnregisterHotKey(int hotkeyId
)
2716 for ( int i
= ((int)s_hotkeys
.size())-1; i
>=0; -- i
)
2718 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2720 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
2721 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
2722 if ( UnregisterEventHotKey(ref
) != noErr
)
2724 wxLogLastError(wxT("UnregisterHotKey"));
2736 #endif // wxUSE_HOTKEY
2738 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2740 bool handled
= false;
2742 // moved the ordinary key event sending AFTER the accel evaluation
2745 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2747 wxWindow
*ancestor
= this;
2750 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2753 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2755 wxCommandEvent
command_event( wxEVT_MENU
, command
);
2756 handled
= handler
->ProcessEvent( command_event
);
2760 // accelerators can also be used with buttons, try them too
2761 command_event
.SetEventType(wxEVT_BUTTON
);
2762 handled
= handler
->ProcessEvent( command_event
);
2768 if (ancestor
->IsTopLevel())
2771 ancestor
= ancestor
->GetParent();
2774 #endif // wxUSE_ACCEL
2778 handled
= HandleWindowEvent( event
) ;
2779 if ( handled
&& event
.GetSkipped() )
2790 // we are maintaining a n:1 map from native controls (ControlRef / NSView*) to their wxWidgetImpl
2791 // n:1 because we might have an embedded view eg within a scrollview, both being part of the same impl
2792 // the impl is calling Associate with its newly created native control(s), e.g. in InstallHandler
2794 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2796 static MacControlMap wxWinMacControlList
;
2798 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2800 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2802 return impl
->GetWXPeer();
2807 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2809 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2811 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2814 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2816 // adding NULL ControlRef is (first) surely a result of an error and
2817 // (secondly) breaks native event processing
2818 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2820 wxWinMacControlList
[inControl
] = impl
;
2823 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2825 // iterate over all the elements in the class
2826 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2827 // we should go on...
2833 MacControlMap::iterator it
;
2834 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2836 if ( it
->second
== impl
)
2838 wxWinMacControlList
.erase(it
);
2846 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2848 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
, bool isUserPane
)
2851 m_isRootControl
= isRootControl
;
2852 m_isUserPane
= isUserPane
;
2854 m_shouldSendEvents
= true;
2857 wxWidgetImpl::wxWidgetImpl()
2862 wxWidgetImpl::~wxWidgetImpl()
2866 void wxWidgetImpl::Init()
2868 m_isRootControl
= false;
2870 m_needsFocusRect
= false;
2871 m_needsFrame
= true;
2874 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2876 m_needsFocusRect
= needs
;
2879 bool wxWidgetImpl::NeedsFocusRect() const
2881 return m_needsFocusRect
;
2884 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2886 m_needsFrame
= needs
;
2889 bool wxWidgetImpl::NeedsFrame() const
2891 return m_needsFrame
;
2894 void wxWidgetImpl::SetDrawingEnabled(bool WXUNUSED(enabled
))