1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/popupwin.cpp
3 // Purpose: implements wxPopupWindow for wxMac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2006 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // CAUTION : This is only experimental stuff right now
18 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
22 // For compilers that support precompilation, includes "wx.h".
23 #include "wx/wxprec.h"
34 #include "wx/popupwin.h"
35 #include "wx/tooltip.h"
37 #include "wx/mac/private.h"
39 // ============================================================================
41 // ============================================================================
43 wxPopupWindow::~wxPopupWindow()
45 if ( m_popupWindowRef
)
48 wxToolTip::NotifyWindowDelete(m_popupWindowRef
) ;
50 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_popupWindowRef
) ) ;
54 bool wxPopupWindow::Create(wxWindow
*parent
, int flags
)
56 m_macIsUserPane
= false ;
58 // popup windows are created hidden by default
61 if ( ! wxPopupWindowBase::Create(parent
) )
64 WindowClass wclass
= kHelpWindowClass
;
65 WindowAttributes attr
= kWindowCompositingAttribute
;
66 WindowRef parentWindow
=(WindowRef
) parent
->MacGetTopLevelWindowRef();
68 Rect bounds
= { 0,0,0,0 };
69 OSStatus err
= ::CreateNewWindow( wclass
, attr
, &bounds
, (WindowRef
*)&m_popupWindowRef
) ;
72 // SetWindowGroup( (WindowRef) m_popupWindowRef, GetWindowGroup(parentWindow)); // Put them in the same group so that their window layers are consistent
75 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
77 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_popupWindowRef
) , kHIViewWindowContentID
,
78 m_peer
->GetControlRefAddr() ) ;
81 // compatibility mode fallback
82 GetRootControl( (WindowRef
) m_popupWindowRef
, m_peer
->GetControlRefAddr() ) ;
84 CreateRootControl( (WindowRef
) m_popupWindowRef
, m_peer
->GetControlRefAddr() ) ;
87 // the root control level handler
88 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
90 // the frame window event handler
91 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_popupWindowRef
)) ) ;
92 // MacInstallTopLevelWindowEventHandler() ;
95 parent
->AddChild(this);
100 void wxPopupWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
102 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
103 verify_noerr(SetWindowBounds( (WindowRef
) m_popupWindowRef
, kWindowStructureRgn
, &bounds
)) ;
104 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
107 void wxPopupWindow::DoGetPosition( int *x
, int *y
) const
111 verify_noerr(GetWindowBounds((WindowRef
) m_popupWindowRef
, kWindowStructureRgn
, &bounds
)) ;
119 void wxPopupWindow::DoGetSize( int *width
, int *height
) const
123 verify_noerr(GetWindowBounds((WindowRef
) m_popupWindowRef
, kWindowStructureRgn
, &bounds
)) ;
126 *width
= bounds
.right
- bounds
.left
;
128 *height
= bounds
.bottom
- bounds
.top
;
131 void wxPopupWindow::DoGetClientSize( int *width
, int *height
) const
135 verify_noerr(GetWindowBounds((WindowRef
) m_popupWindowRef
, kWindowContentRgn
, &bounds
)) ;
138 *width
= bounds
.right
- bounds
.left
;
140 *height
= bounds
.bottom
- bounds
.top
;
143 bool wxPopupWindow::Show(bool show
)
145 if ( !wxWindowMac::Show(show
) )
150 ::ShowWindow( (WindowRef
)m_popupWindowRef
);
151 ::SelectWindow( (WindowRef
)m_popupWindowRef
) ;
153 // because apps expect a size event to occur at this moment
154 wxSizeEvent
event(GetSize() , m_windowId
);
155 event
.SetEventObject(this);
156 GetEventHandler()->ProcessEvent(event
);
160 ::HideWindow( (WindowRef
)m_popupWindowRef
);
165 WXWindow
wxPopupWindow::MacGetPopupWindowRef() const
167 return m_popupWindowRef
;
170 #endif // #if wxUSE_POPUPWIN