]>
Commit | Line | Data |
---|---|---|
14cd0443 SC |
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 | ||
6239ee05 | 16 | // CAUTION : This is only experimental stuff right now |
14cd0443 SC |
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" | |
6239ee05 | 35 | #include "wx/tooltip.h" |
14cd0443 SC |
36 | |
37 | #include "wx/mac/private.h" | |
38 | ||
39 | // ============================================================================ | |
40 | // implementation | |
41 | // ============================================================================ | |
42 | ||
6239ee05 SC |
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 | ||
14cd0443 SC |
54 | bool wxPopupWindow::Create(wxWindow *parent, int flags) |
55 | { | |
6239ee05 SC |
56 | m_macIsUserPane = false ; |
57 | ||
14cd0443 SC |
58 | // popup windows are created hidden by default |
59 | Hide(); | |
60 | ||
6239ee05 SC |
61 | if ( ! wxPopupWindowBase::Create(parent) ) |
62 | return false; | |
63 | ||
64 | WindowClass wclass = kHelpWindowClass; | |
65 | WindowAttributes attr = kWindowCompositingAttribute ; | |
66 | WindowRef parentWindow =(WindowRef) parent->MacGetTopLevelWindowRef(); | |
67 | ||
68 | Rect bounds = { 0,0,0,0 }; | |
69 | OSStatus err = ::CreateNewWindow( wclass , attr , &bounds , (WindowRef*)&m_popupWindowRef ) ; | |
70 | if ( err == noErr ) | |
71 | { | |
72 | // SetWindowGroup( (WindowRef) m_popupWindowRef, GetWindowGroup(parentWindow)); // Put them in the same group so that their window layers are consistent | |
14cd0443 SC |
73 | } |
74 | ||
6239ee05 SC |
75 | m_peer = new wxMacControl(this , true /*isRootControl*/) ; |
76 | ||
77 | HIViewFindByID( HIViewGetRoot( (WindowRef) m_popupWindowRef ) , kHIViewWindowContentID , | |
78 | m_peer->GetControlRefAddr() ) ; | |
79 | if ( !m_peer->Ok() ) | |
14cd0443 | 80 | { |
6239ee05 SC |
81 | // compatibility mode fallback |
82 | GetRootControl( (WindowRef) m_popupWindowRef , m_peer->GetControlRefAddr() ) ; | |
83 | if ( !m_peer->Ok() ) | |
84 | CreateRootControl( (WindowRef) m_popupWindowRef , m_peer->GetControlRefAddr() ) ; | |
85 | } | |
86 | ||
87 | // the root control level handler | |
88 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; | |
14cd0443 | 89 | |
6239ee05 SC |
90 | // the frame window event handler |
91 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_popupWindowRef)) ) ; | |
92 | // MacInstallTopLevelWindowEventHandler() ; | |
93 | ||
94 | if ( parent ) | |
95 | parent->AddChild(this); | |
96 | ||
97 | return true; | |
14cd0443 SC |
98 | } |
99 | ||
6239ee05 | 100 | void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height) |
14cd0443 | 101 | { |
6239ee05 SC |
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 | |
105 | } | |
14cd0443 | 106 | |
6239ee05 | 107 | void wxPopupWindow::DoGetPosition( int *x, int *y ) const |
14cd0443 | 108 | { |
6239ee05 SC |
109 | Rect bounds ; |
110 | ||
111 | verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowStructureRgn , &bounds )) ; | |
112 | ||
113 | if (x) | |
114 | *x = bounds.left ; | |
115 | if (y) | |
116 | *y = bounds.top ; | |
14cd0443 SC |
117 | } |
118 | ||
6239ee05 SC |
119 | void wxPopupWindow::DoGetSize( int *width, int *height ) const |
120 | { | |
121 | Rect bounds ; | |
122 | ||
123 | verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowStructureRgn , &bounds )) ; | |
124 | ||
125 | if (width) | |
126 | *width = bounds.right - bounds.left ; | |
127 | if (height) | |
128 | *height = bounds.bottom - bounds.top ; | |
14cd0443 SC |
129 | } |
130 | ||
6239ee05 | 131 | void wxPopupWindow::DoGetClientSize( int *width, int *height ) const |
14cd0443 | 132 | { |
6239ee05 SC |
133 | Rect bounds ; |
134 | ||
135 | verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowContentRgn , &bounds )) ; | |
136 | ||
137 | if (width) | |
138 | *width = bounds.right - bounds.left ; | |
139 | if (height) | |
140 | *height = bounds.bottom - bounds.top ; | |
14cd0443 | 141 | } |
14cd0443 SC |
142 | |
143 | bool wxPopupWindow::Show(bool show) | |
144 | { | |
145 | if ( !wxWindowMac::Show(show) ) | |
146 | return false; | |
6239ee05 | 147 | |
14cd0443 SC |
148 | if ( show ) |
149 | { | |
6239ee05 SC |
150 | ::ShowWindow( (WindowRef)m_popupWindowRef ); |
151 | ::SelectWindow( (WindowRef)m_popupWindowRef ) ; | |
14cd0443 | 152 | |
6239ee05 SC |
153 | // because apps expect a size event to occur at this moment |
154 | wxSizeEvent event(GetSize() , m_windowId); | |
155 | event.SetEventObject(this); | |
937013e0 | 156 | HandleWindowEvent(event); |
6239ee05 SC |
157 | } |
158 | else | |
159 | { | |
160 | ::HideWindow( (WindowRef)m_popupWindowRef ); | |
14cd0443 | 161 | } |
14cd0443 SC |
162 | return true; |
163 | } | |
164 | ||
6239ee05 SC |
165 | WXWindow wxPopupWindow::MacGetPopupWindowRef() const |
166 | { | |
167 | return m_popupWindowRef; | |
168 | } | |
169 | ||
14cd0443 | 170 | #endif // #if wxUSE_POPUPWIN |