From af81408a3e1354eb73177c2c158091588f9efdc5 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 13 Jun 2007 22:55:58 +0000 Subject: [PATCH] fixes for popupwin git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46459 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/carbon/popupwin.h | 8 ++ include/wx/mac/carbon/private.h | 10 ++ src/mac/carbon/dcclient.cpp | 4 +- src/mac/carbon/popupwin.cpp | 157 +++++++++++++++++++++---------- src/mac/carbon/toplevel.cpp | 33 +++---- src/mac/carbon/window.cpp | 16 +++- 6 files changed, 153 insertions(+), 75 deletions(-) diff --git a/include/wx/mac/carbon/popupwin.h b/include/wx/mac/carbon/popupwin.h index b3ec56577d..c1590abc73 100755 --- a/include/wx/mac/carbon/popupwin.h +++ b/include/wx/mac/carbon/popupwin.h @@ -20,6 +20,7 @@ class WXDLLEXPORT wxPopupWindow : public wxPopupWindowBase { public: wxPopupWindow() { } + ~wxPopupWindow(); wxPopupWindow(wxWindow *parent, int flags = wxBORDER_NONE) { (void)Create(parent, flags); } @@ -28,9 +29,16 @@ public: virtual bool Show(bool show = true); + WXWindow MacGetPopupWindowRef() const ; + protected: // popups handle the position like wxTopLevelWindow, not wxWindow virtual void DoGetPosition(int *x, int *y) const; + virtual void DoMoveWindow(int x, int y, int width, int height); + virtual void DoGetSize( int *width, int *height ) const; + virtual void DoGetClientSize( int *width, int *height ) const; + + WXWindow m_popupWindowRef ; DECLARE_DYNAMIC_CLASS_NO_COPY(wxPopupWindow) }; diff --git a/include/wx/mac/carbon/private.h b/include/wx/mac/carbon/private.h index 71abe3593f..a15f04437a 100644 --- a/include/wx/mac/carbon/private.h +++ b/include/wx/mac/carbon/private.h @@ -1292,6 +1292,16 @@ private : // toplevel.cpp +class wxMacDeferredWindowDeleter : public wxObject +{ +public : + wxMacDeferredWindowDeleter( WindowRef windowRef ); + virtual ~wxMacDeferredWindowDeleter(); + +protected : + WindowRef m_macWindow ; +} ; + ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow, const Point& location , WindowRef window , ControlPartCode *outPart ); #ifndef __LP64__ diff --git a/src/mac/carbon/dcclient.cpp b/src/mac/carbon/dcclient.cpp index f50ec02f4c..a9475a34d5 100644 --- a/src/mac/carbon/dcclient.cpp +++ b/src/mac/carbon/dcclient.cpp @@ -120,7 +120,7 @@ wxWindowDC::wxWindowDC() wxWindowDC::wxWindowDC(wxWindow *window) { m_window = window ; - wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; + WindowRef rootwindow = (WindowRef) window->MacGetTopLevelWindowRef() ; if (!rootwindow) return; @@ -152,7 +152,7 @@ wxWindowDC::wxWindowDC(wxWindow *window) window->MacWindowToRootWindow( &x , &y ) ; m_macLocalOrigin.x = x ; m_macLocalOrigin.y = y ; - m_macPort = UMAGetWindowPort( (WindowRef) rootwindow->MacGetWindowRef() ) ; + m_macPort = UMAGetWindowPort( rootwindow ) ; CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; diff --git a/src/mac/carbon/popupwin.cpp b/src/mac/carbon/popupwin.cpp index bd4fe547fa..f8699cc8eb 100755 --- a/src/mac/carbon/popupwin.cpp +++ b/src/mac/carbon/popupwin.cpp @@ -13,7 +13,7 @@ // declarations // ============================================================================ -// CAUTION : This is not functional yet +// CAUTION : This is only experimental stuff right now // ---------------------------------------------------------------------------- // headers @@ -32,6 +32,7 @@ #endif //WX_PRECOMP #include "wx/popupwin.h" +#include "wx/tooltip.h" #include "wx/mac/private.h" @@ -39,79 +40,131 @@ // implementation // ============================================================================ +wxPopupWindow::~wxPopupWindow() +{ + if ( m_popupWindowRef ) + { +#if wxUSE_TOOLTIPS + wxToolTip::NotifyWindowDelete(m_popupWindowRef) ; +#endif + wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_popupWindowRef ) ) ; + } +} + bool wxPopupWindow::Create(wxWindow *parent, int flags) { + m_macIsUserPane = false ; + // popup windows are created hidden by default Hide(); - return wxPopupWindowBase::Create(parent) && - wxWindow::Create(parent, wxID_ANY, - wxDefaultPosition, wxDefaultSize, - flags | wxPOPUP_WINDOW); -} + if ( ! wxPopupWindowBase::Create(parent) ) + return false; -void wxPopupWindow::DoGetPosition(int *x, int *y) const -{ - // the position of a "top level" window such as this should be in - // screen coordinates, not in the client ones which MSW gives us - // (because we are a child window) - wxPopupWindowBase::DoGetPosition(x, y); + WindowClass wclass = kHelpWindowClass; + WindowAttributes attr = kWindowCompositingAttribute ; + WindowRef parentWindow =(WindowRef) parent->MacGetTopLevelWindowRef(); - GetParent()->ClientToScreen(x, y); -} - -/* -WXDWORD wxPopupWindow::MSWGetStyle(long flags, WXDWORD *exstyle) const -{ - // we only honour the border flags, the others don't make sense for us - WXDWORD style = wxWindow::MSWGetStyle(flags & wxBORDER_MASK, exstyle); - - if ( exstyle ) + Rect bounds = { 0,0,0,0 }; + OSStatus err = ::CreateNewWindow( wclass , attr , &bounds , (WindowRef*)&m_popupWindowRef ) ; + if ( err == noErr ) { - // a popup window floats on top of everything - *exstyle |= WS_EX_TOPMOST | WS_EX_TOOLWINDOW; +// SetWindowGroup( (WindowRef) m_popupWindowRef, GetWindowGroup(parentWindow)); // Put them in the same group so that their window layers are consistent + } + + m_peer = new wxMacControl(this , true /*isRootControl*/) ; + + HIViewFindByID( HIViewGetRoot( (WindowRef) m_popupWindowRef ) , kHIViewWindowContentID , + m_peer->GetControlRefAddr() ) ; + if ( !m_peer->Ok() ) + { + // compatibility mode fallback + GetRootControl( (WindowRef) m_popupWindowRef , m_peer->GetControlRefAddr() ) ; + if ( !m_peer->Ok() ) + CreateRootControl( (WindowRef) m_popupWindowRef , m_peer->GetControlRefAddr() ) ; } - return style; + // the root control level handler + MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; + + // the frame window event handler + InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_popupWindowRef)) ) ; + // MacInstallTopLevelWindowEventHandler() ; + + if ( parent ) + parent->AddChild(this); + + return true; } -WXHWND wxPopupWindow::MSWGetParent() const +void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height) { - // we must be a child of the desktop to be able to extend beyond the parent - // window client area (like the comboboxes drop downs do) - // - // NB: alternative implementation would be to use WS_POPUP instead of - // WS_CHILD but then showing a popup would deactivate the parent which - // is ugly and working around this, although possible, is even more - // ugly - // GetDesktopWindow() is not always supported on WinCE, and if - // it is, it often returns NULL. -#ifdef __WXWINCE__ - return 0; -#else - return (WXHWND)::GetDesktopWindow(); -#endif + Rect bounds = { y , x , y + height , x + width } ; + verify_noerr(SetWindowBounds( (WindowRef) m_popupWindowRef, kWindowStructureRgn , &bounds )) ; + wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified +} + +void wxPopupWindow::DoGetPosition( int *x, int *y ) const +{ + Rect bounds ; + + verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowStructureRgn , &bounds )) ; + + if (x) + *x = bounds.left ; + if (y) + *y = bounds.top ; +} + +void wxPopupWindow::DoGetSize( int *width, int *height ) const +{ + Rect bounds ; + + verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowStructureRgn , &bounds )) ; + + if (width) + *width = bounds.right - bounds.left ; + if (height) + *height = bounds.bottom - bounds.top ; +} + +void wxPopupWindow::DoGetClientSize( int *width, int *height ) const +{ + Rect bounds ; + + verify_noerr(GetWindowBounds((WindowRef) m_popupWindowRef, kWindowContentRgn , &bounds )) ; + + if (width) + *width = bounds.right - bounds.left ; + if (height) + *height = bounds.bottom - bounds.top ; } -*/ bool wxPopupWindow::Show(bool show) { if ( !wxWindowMac::Show(show) ) return false; -/* - if ( show ) - { - // raise to top of z order - if (!::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)) - { - wxLogLastError(_T("SetWindowPos")); - } - // and set it as the foreground window so the mouse can be captured - ::SetForegroundWindow(GetHwnd()); + if (show) + { + ::ShowWindow( (WindowRef)m_popupWindowRef ); + ::SelectWindow( (WindowRef)m_popupWindowRef ) ; + + // because apps expect a size event to occur at this moment + wxSizeEvent event(GetSize() , m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); + } + else + { + ::HideWindow( (WindowRef)m_popupWindowRef ); } -*/ return true; } +WXWindow wxPopupWindow::MacGetPopupWindowRef() const +{ + return m_popupWindowRef; +} + #endif // #if wxUSE_POPUPWIN diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 58751646f0..706b65eaee 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -76,7 +76,6 @@ static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase) END_EVENT_TABLE() - // --------------------------------------------------------------------------- // Carbon Events // --------------------------------------------------------------------------- @@ -909,22 +908,15 @@ void wxTopLevelWindowMac::Init() m_macFullScreenData = NULL ; } -class wxMacDeferredWindowDeleter : public wxObject +wxMacDeferredWindowDeleter::wxMacDeferredWindowDeleter( WindowRef windowRef ) { -public : - wxMacDeferredWindowDeleter( WindowRef windowRef ) - { - m_macWindow = windowRef ; - } + m_macWindow = windowRef ; +} - virtual ~wxMacDeferredWindowDeleter() - { - UMADisposeWindow( (WindowRef) m_macWindow ) ; - } - -protected : - WindowRef m_macWindow ; -} ; +wxMacDeferredWindowDeleter::~wxMacDeferredWindowDeleter() +{ + UMADisposeWindow( (WindowRef) m_macWindow ) ; +} bool wxTopLevelWindowMac::Create(wxWindow *parent, wxWindowID id, @@ -1064,16 +1056,19 @@ void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) } } +void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref) +{ + InstallWindowEventHandler(window, GetwxMacTopLevelEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, ref, handler ); +} + void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() { if ( m_macEventHandler != NULL ) { verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; } - - InstallWindowEventHandler( - MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), - GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler ); + wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow),(EventHandlerRef *)&m_macEventHandler,this); } void wxTopLevelWindowMac::MacCreateRealWindow( diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 16be561e98..fb8653e2c8 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -53,6 +53,10 @@ #include "wx/caret.h" #endif +#if wxUSE_POPUPWIN + #include "wx/popupwin.h" +#endif + #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" #endif @@ -3142,8 +3146,16 @@ WXWindow wxWindowMac::MacGetTopLevelWindowRef() const while ( iter ) { if ( iter->IsTopLevel() ) - return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ; - + { + wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow); + if ( toplevel ) + return toplevel->MacGetWindowRef(); +#if wxUSE_POPUPWIN + wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow); + if ( popupwin ) + return popupwin->MacGetPopupWindowRef(); +#endif + } iter = iter->GetParent() ; }