fixes for popupwin

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46459 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2007-06-13 22:55:58 +00:00
parent 56a25b3eb8
commit af81408a3e
6 changed files with 153 additions and 75 deletions

View File

@@ -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)
};

View File

@@ -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__

View File

@@ -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 ) ;

View File

@@ -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
}
return style;
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() ) ;
}
// 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

View File

@@ -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(

View File

@@ -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() ;
}