Merge branch 'msw-popup'

Reimplement wxPopupWindow using WS_POPUP instead of WS_CHILD window in
wxMSW as the new approach allows using the controls inside the popup
normally, unlike the old one.

See https://github.com/wxWidgets/wxWidgets/pull/986

Closes #18243.
This commit is contained in:
Vadim Zeitlin
2018-10-27 15:08:22 +02:00
8 changed files with 225 additions and 133 deletions

View File

@@ -18,25 +18,28 @@
class WXDLLIMPEXP_CORE wxPopupWindow : public wxPopupWindowBase
{
public:
wxPopupWindow() { }
wxPopupWindow() { m_owner = NULL; }
wxPopupWindow(wxWindow *parent, int flags = wxBORDER_NONE)
{ (void)Create(parent, flags); }
bool Create(wxWindow *parent, int flags = wxBORDER_NONE);
virtual void SetFocus() wxOVERRIDE;
virtual bool Show(bool show = true) wxOVERRIDE;
// return the style to be used for the popup windows
virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const wxOVERRIDE;
// get the HWND to be used as parent of this window with CreateWindow()
virtual WXHWND MSWGetParent() const wxOVERRIDE;
protected:
// Implementation only from now on.
// Return the top level window parent of this popup or null.
wxWindow* MSWGetOwner() const { return m_owner; }
private:
wxWindow* m_owner;
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxPopupWindow);
};
#endif // _WX_MSW_POPUPWIN_H_

View File

@@ -76,24 +76,16 @@ public:
// when the user clicks mouse outside it or if it loses focus in any other way
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_FWD_CORE wxPopupWindowHandler;
class WXDLLIMPEXP_FWD_CORE wxPopupFocusHandler;
class WXDLLIMPEXP_CORE wxPopupTransientWindow : public wxPopupWindow
// Define the public API of wxPopupTransientWindow:
class WXDLLIMPEXP_CORE wxPopupTransientWindowBase : public wxPopupWindow
{
public:
// ctors
wxPopupTransientWindow() { Init(); }
wxPopupTransientWindow(wxWindow *parent, int style = wxBORDER_NONE);
virtual ~wxPopupTransientWindow();
// popup the window (this will show it too) and keep focus at winFocus
// (or itself if it's NULL), dismiss the popup if we lose focus
virtual void Popup(wxWindow *focus = NULL);
virtual void Popup(wxWindow *focus = NULL) = 0;
// hide the window
virtual void Dismiss();
virtual void Dismiss() = 0;
// can the window be dismissed now?
//
@@ -104,24 +96,74 @@ public:
// called when a mouse is pressed while the popup is shown: return true
// from here to prevent its normal processing by the popup (which consists
// in dismissing it if the mouse is clicked outside it)
virtual bool ProcessLeftDown(wxMouseEvent& event);
// Overridden to grab the input on some plaforms
virtual bool Show( bool show = true ) wxOVERRIDE;
virtual bool ProcessLeftDown(wxMouseEvent& WXUNUSED(event))
{ return false; }
// Override to implement delayed destruction of this window.
virtual bool Destroy() wxOVERRIDE;
protected:
// common part of all ctors
void Init();
// this is called when the popup is disappeared because of anything
// else but direct call to Dismiss()
virtual void OnDismiss();
virtual void OnDismiss() { }
// dismiss and notify the derived class
void DismissAndNotify();
void DismissAndNotify()
{
Dismiss();
OnDismiss();
}
};
#ifdef __WXMSW__
class WXDLLIMPEXP_CORE wxPopupTransientWindow : public wxPopupTransientWindowBase
{
public:
// ctors
wxPopupTransientWindow() { }
wxPopupTransientWindow(wxWindow *parent, int style = wxBORDER_NONE)
{ Create(parent, style); }
// Implement base class pure virtuals.
virtual void Popup(wxWindow *focus = NULL) wxOVERRIDE;
virtual void Dismiss() wxOVERRIDE;
// Override to handle WM_NCACTIVATE.
virtual bool MSWHandleMessage(WXLRESULT *result,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam) wxOVERRIDE;
private:
wxDECLARE_DYNAMIC_CLASS(wxPopupTransientWindow);
wxDECLARE_NO_COPY_CLASS(wxPopupTransientWindow);
};
#else // !__WXMSW__
class WXDLLIMPEXP_FWD_CORE wxPopupWindowHandler;
class WXDLLIMPEXP_FWD_CORE wxPopupFocusHandler;
class WXDLLIMPEXP_CORE wxPopupTransientWindow : public wxPopupTransientWindowBase
{
public:
// ctors
wxPopupTransientWindow() { Init(); }
wxPopupTransientWindow(wxWindow *parent, int style = wxBORDER_NONE);
virtual ~wxPopupTransientWindow();
// Implement base class pure virtuals.
virtual void Popup(wxWindow *focus = NULL) wxOVERRIDE;
virtual void Dismiss() wxOVERRIDE;
// Overridden to grab the input on some plaforms
virtual bool Show( bool show = true ) wxOVERRIDE;
protected:
// common part of all ctors
void Init();
// remove our event handlers
void PopHandlers();
@@ -129,7 +171,7 @@ protected:
// get alerted when child gets deleted from under us
void OnDestroy(wxWindowDestroyEvent& event);
#if defined(__WXMSW__) ||(defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON)
#if defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON
// Check if the mouse needs to be captured or released: we must release
// when it's inside our window if we want the embedded controls to work.
void OnIdle(wxIdleEvent& event);
@@ -154,6 +196,8 @@ protected:
wxDECLARE_NO_COPY_CLASS(wxPopupTransientWindow);
};
#endif // __WXMSW__/!__WXMSW__
#if wxUSE_COMBOBOX && defined(__WXUNIVERSAL__)
// ----------------------------------------------------------------------------