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 WXUNUSED(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 
; 
  67     Rect bounds 
= { 0,0,0,0 }; 
  68     OSStatus err 
= ::CreateNewWindow( wclass 
, attr 
, &bounds 
, (WindowRef
*)&m_popupWindowRef 
) ; 
  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 
  77     m_peer 
= new wxMacControl(this , true /*isRootControl*/) ; 
  79     HIViewFindByID( HIViewGetRoot( (WindowRef
) m_popupWindowRef 
) , kHIViewWindowContentID 
, 
  80         m_peer
->GetControlRefAddr() ) ; 
  83         // compatibility mode fallback 
  84         GetRootControl( (WindowRef
) m_popupWindowRef 
, m_peer
->GetControlRefAddr() ) ; 
  86             CreateRootControl( (WindowRef
) m_popupWindowRef 
, m_peer
->GetControlRefAddr() ) ; 
  89     // the root control level handler 
  90     MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ; 
  92     // the frame window event handler 
  93     InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_popupWindowRef
)) ) ; 
  94     // MacInstallTopLevelWindowEventHandler() ; 
  97         parent
->AddChild(this); 
 102 void wxPopupWindow::DoMoveWindow(int x
, int y
, int width
, int height
) 
 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 
 109 void wxPopupWindow::DoGetPosition( int *x
, int *y 
) const 
 113     verify_noerr(GetWindowBounds((WindowRef
) m_popupWindowRef
, kWindowStructureRgn 
, &bounds 
)) ; 
 121 void wxPopupWindow::DoGetSize( int *width
, int *height 
) const 
 125     verify_noerr(GetWindowBounds((WindowRef
) m_popupWindowRef
, kWindowStructureRgn 
, &bounds 
)) ; 
 128        *width 
= bounds
.right 
- bounds
.left 
; 
 130        *height 
= bounds
.bottom 
- bounds
.top 
; 
 133 void wxPopupWindow::DoGetClientSize( int *width
, int *height 
) const 
 137     verify_noerr(GetWindowBounds((WindowRef
) m_popupWindowRef
, kWindowContentRgn 
, &bounds 
)) ; 
 140        *width 
= bounds
.right 
- bounds
.left 
; 
 142        *height 
= bounds
.bottom 
- bounds
.top 
; 
 145 bool wxPopupWindow::Show(bool show
) 
 147     if ( !wxWindowMac::Show(show
) ) 
 152         ::ShowWindow( (WindowRef
)m_popupWindowRef 
); 
 153         ::SelectWindow( (WindowRef
)m_popupWindowRef 
) ; 
 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
); 
 162         ::HideWindow( (WindowRef
)m_popupWindowRef 
); 
 167 WXWindow 
wxPopupWindow::MacGetPopupWindowRef() const 
 169     return m_popupWindowRef
; 
 172 #endif // #if wxUSE_POPUPWIN