]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/popupwin.cpp
fix compilation after r50329
[wxWidgets.git] / src / mac / carbon / popupwin.cpp
CommitLineData
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
43wxPopupWindow::~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
b733a017 54bool wxPopupWindow::Create(wxWindow *parent, int WXUNUSED(flags))
14cd0443 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 ;
6239ee05
SC
66
67 Rect bounds = { 0,0,0,0 };
68 OSStatus err = ::CreateNewWindow( wclass , attr , &bounds , (WindowRef*)&m_popupWindowRef ) ;
69 if ( err == noErr )
70 {
b733a017
VZ
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
14cd0443
SC
75}
76
6239ee05
SC
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() )
14cd0443 82{
6239ee05
SC
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() ) ;
14cd0443 91
6239ee05
SC
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;
14cd0443
SC
100}
101
6239ee05 102void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height)
14cd0443 103{
6239ee05
SC
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}
14cd0443 108
6239ee05 109void wxPopupWindow::DoGetPosition( int *x, int *y ) const
14cd0443 110 {
6239ee05
SC
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 ;
14cd0443
SC
119 }
120
6239ee05
SC
121void 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 ;
14cd0443
SC
131}
132
6239ee05 133void wxPopupWindow::DoGetClientSize( int *width, int *height ) const
14cd0443 134{
6239ee05
SC
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 ;
14cd0443 143}
14cd0443
SC
144
145bool wxPopupWindow::Show(bool show)
146{
147 if ( !wxWindowMac::Show(show) )
148 return false;
6239ee05 149
14cd0443
SC
150 if ( show )
151 {
6239ee05
SC
152 ::ShowWindow( (WindowRef)m_popupWindowRef );
153 ::SelectWindow( (WindowRef)m_popupWindowRef ) ;
14cd0443 154
6239ee05
SC
155 // because apps expect a size event to occur at this moment
156 wxSizeEvent event(GetSize() , m_windowId);
157 event.SetEventObject(this);
937013e0 158 HandleWindowEvent(event);
6239ee05
SC
159 }
160 else
161 {
162 ::HideWindow( (WindowRef)m_popupWindowRef );
14cd0443 163 }
14cd0443
SC
164 return true;
165}
166
6239ee05
SC
167WXWindow wxPopupWindow::MacGetPopupWindowRef() const
168{
169 return m_popupWindowRef;
170}
171
14cd0443 172#endif // #if wxUSE_POPUPWIN