]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/popupwin.cpp
include fixed for non-precomp
[wxWidgets.git] / src / mac / carbon / popupwin.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/popupwin.cpp
3 // Purpose: implements wxPopupWindow for wxMac
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) 2006 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // CAUTION : This is only experimental stuff right now
17
18 // ----------------------------------------------------------------------------
19 // headers
20 // ----------------------------------------------------------------------------
21
22 // For compilers that support precompilation, includes "wx.h".
23 #include "wx/wxprec.h"
24
25 #ifdef __BORLANDC__
26 #pragma hdrstop
27 #endif
28
29 #if wxUSE_POPUPWIN
30
31 #ifndef WX_PRECOMP
32 #endif //WX_PRECOMP
33
34 #include "wx/popupwin.h"
35 #include "wx/tooltip.h"
36
37 #include "wx/mac/private.h"
38
39 // ============================================================================
40 // implementation
41 // ============================================================================
42
43 wxPopupWindow::~wxPopupWindow()
44 {
45 if ( m_popupWindowRef )
46 {
47 #if wxUSE_TOOLTIPS
48 wxToolTip::NotifyWindowDelete(m_popupWindowRef) ;
49 #endif
50 wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_popupWindowRef ) ) ;
51 }
52 }
53
54 bool wxPopupWindow::Create(wxWindow *parent, int WXUNUSED(flags))
55 {
56 m_macIsUserPane = false ;
57
58 // popup windows are created hidden by default
59 Hide();
60
61 if ( ! wxPopupWindowBase::Create(parent) )
62 return false;
63
64 WindowClass wclass = kHelpWindowClass;
65 WindowAttributes attr = kWindowCompositingAttribute ;
66
67 Rect bounds = { 0,0,0,0 };
68 OSStatus err = ::CreateNewWindow( wclass , attr , &bounds , (WindowRef*)&m_popupWindowRef ) ;
69 if ( err == noErr )
70 {
71 #if 0
72 WindowRef parentWindow =(WindowRef) parent->MacGetTopLevelWindowRef();
73 SetWindowGroup( (WindowRef) m_popupWindowRef, GetWindowGroup(parentWindow)); // Put them in the same group so that their window layers are consistent
74 #endif
75 }
76
77 m_peer = new wxMacControl(this , true /*isRootControl*/) ;
78
79 HIViewFindByID( HIViewGetRoot( (WindowRef) m_popupWindowRef ) , kHIViewWindowContentID ,
80 m_peer->GetControlRefAddr() ) ;
81 if ( !m_peer->Ok() )
82 {
83 // compatibility mode fallback
84 GetRootControl( (WindowRef) m_popupWindowRef , m_peer->GetControlRefAddr() ) ;
85 if ( !m_peer->Ok() )
86 CreateRootControl( (WindowRef) m_popupWindowRef , m_peer->GetControlRefAddr() ) ;
87 }
88
89 // the root control level handler
90 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ;
91
92 // the frame window event handler
93 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_popupWindowRef)) ) ;
94 // MacInstallTopLevelWindowEventHandler() ;
95
96 if ( parent )
97 parent->AddChild(this);
98
99 return true;
100 }
101
102 void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height)
103 {
104 Rect bounds = { y , x , y + height , x + width } ;
105 verify_noerr(SetWindowBounds( (WindowRef) m_popupWindowRef, kWindowStructureRgn , &bounds )) ;
106 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
107 }
108
109 void wxPopupWindow::DoGetPosition( int *x, int *y ) const
110 {
111 Rect bounds ;
112
113 verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowStructureRgn , &bounds )) ;
114
115 if (x)
116 *x = bounds.left ;
117 if (y)
118 *y = bounds.top ;
119 }
120
121 void wxPopupWindow::DoGetSize( int *width, int *height ) const
122 {
123 Rect bounds ;
124
125 verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowStructureRgn , &bounds )) ;
126
127 if (width)
128 *width = bounds.right - bounds.left ;
129 if (height)
130 *height = bounds.bottom - bounds.top ;
131 }
132
133 void wxPopupWindow::DoGetClientSize( int *width, int *height ) const
134 {
135 Rect bounds ;
136
137 verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowContentRgn , &bounds )) ;
138
139 if (width)
140 *width = bounds.right - bounds.left ;
141 if (height)
142 *height = bounds.bottom - bounds.top ;
143 }
144
145 bool wxPopupWindow::Show(bool show)
146 {
147 if ( !wxWindowMac::Show(show) )
148 return false;
149
150 if ( show )
151 {
152 ::ShowWindow( (WindowRef)m_popupWindowRef );
153 ::SelectWindow( (WindowRef)m_popupWindowRef ) ;
154
155 // because apps expect a size event to occur at this moment
156 wxSizeEvent event(GetSize() , m_windowId);
157 event.SetEventObject(this);
158 HandleWindowEvent(event);
159 }
160 else
161 {
162 ::HideWindow( (WindowRef)m_popupWindowRef );
163 }
164 return true;
165 }
166
167 WXWindow wxPopupWindow::MacGetPopupWindowRef() const
168 {
169 return m_popupWindowRef;
170 }
171
172 #endif // #if wxUSE_POPUPWIN