Make wxDumpWindow() public and available in wxMSW too

This function was defined in wxGTK and wxOSX, but not in wxMSW or the
other ports, but it can be useful there too, so make it public and
define it in common code.
This commit is contained in:
Vadim Zeitlin
2021-10-20 23:11:40 +01:00
parent 85503d1dcd
commit 9e5c8eef24
7 changed files with 58 additions and 45 deletions

View File

@@ -2100,6 +2100,9 @@ extern WXDLLIMPEXP_CORE wxWindow *wxGetActiveWindow();
// get the (first) top level parent window
WXDLLIMPEXP_CORE wxWindow* wxGetTopLevelParent(wxWindowBase *win);
// Return a string with platform-dependent description of the window.
extern WXDLLIMPEXP_CORE wxString wxDumpWindow(wxWindowBase* win);
#if wxUSE_ACCESSIBILITY
// ----------------------------------------------------------------------------
// accessible object for windows

View File

@@ -4251,5 +4251,22 @@ wxWindow* wxGetActiveWindow();
*/
wxWindow* wxGetTopLevelParent(wxWindow* window);
/**
Return a string with human-readable platform-specific description of
the window useful for diagnostic purposes.
The string returned from this function doesn't have any fixed form and can
vary between different wxWidgets ports and versions, but contains some
useful description of the window and uniquely identifies it. This can be
useful to include in debug or tracing messages.
@param window Window pointer which is allowed to be @NULL.
@header{wx/window.h}
@since 3.1.6
*/
wxString wxDumpWindow(wxWindow* window);
//@}

View File

@@ -3661,6 +3661,31 @@ wxWindow* wxGetTopLevelParent(wxWindowBase *win_)
return win;
}
wxString wxDumpWindow(wxWindowBase* win)
{
if ( !win )
return wxString::FromAscii("[no window]");
wxString s = wxString::Format("%s@%p (",
win->GetClassInfo()->GetClassName(), win);
wxString label = win->GetLabel();
if ( label.empty() )
label = win->GetName();
s += wxString::Format("\"%s\"", label);
// Under MSW the HWND can be useful to find the window in Spy++ or similar
// program, so include it in the dump as well.
#ifdef __WXMSW__
s += wxString::Format(", HWND=%p", win->GetHandle());
#endif // __WXMSW__
s += ")";
return s;
}
#if wxUSE_ACCESSIBILITY
// ----------------------------------------------------------------------------
// accessible object for windows

View File

@@ -309,26 +309,6 @@ static wxPoint gs_lastGesturePoint;
// the trace mask used for the focus debugging messages
#define TRACE_FOCUS wxT("focus")
#if wxUSE_LOG_TRACE
// Function used to dump a brief description of a window.
static
wxString wxDumpWindow(wxWindowGTK* win)
{
if ( !win )
return "(no window)";
wxString s = wxString::Format("%s(%p",
win->GetClassInfo()->GetClassName(), win);
wxString label = win->GetLabel();
if ( !label.empty() )
s += wxString::Format(", \"%s\"", label);
s += ")";
return s;
}
#endif // wxUSE_LOG_TRACE
// A handy function to run from under gdb to show information about the given
// GtkWidget. Right now it only shows its type, we could enhance it to show
// more information later but this is already pretty useful.

View File

@@ -51,9 +51,6 @@
// debugging helpers
// ----------------------------------------------------------------------------
// This one is defined in window_osx.cpp.
extern wxString wxDumpWindow(wxWindowMac* win);
// These functions are called from the code but are also useful in the debugger
// (especially wxDumpNSView(), as selectors can be printed out directly anyhow),
// so make them just static instead of putting them in an anonymous namespace

View File

@@ -181,28 +181,6 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow, wxWindow);
wxBEGIN_EVENT_TABLE(wxBlindPlateWindow, wxWindow)
wxEND_EVENT_TABLE()
// ----------------------------------------------------------------------------
// debug helpers
// ----------------------------------------------------------------------------
// Function used to dump a brief description of a window.
extern
wxString wxDumpWindow(wxWindowMac* win)
{
if ( !win )
return "(no window)";
wxString s = wxString::Format("%s(%p",
win->GetClassInfo()->GetClassName(), win);
wxString label = win->GetLabel();
if ( !label.empty() )
s += wxString::Format(", \"%s\"", label);
s += ")";
return s;
}
// ----------------------------------------------------------------------------
// constructors and such
// ----------------------------------------------------------------------------

View File

@@ -201,3 +201,16 @@ TEST_CASE("GUI::FindWindowAtPoint", "[guifuncs]")
INFO("Point over disabled child controls still corresponds to this child");
CHECK( GetLabelOfWindowAtPoint(parent, 31, 111) == btn3->GetLabel() );
}
TEST_CASE("wxWindow::Dump", "[window]")
{
CHECK_NOTHROW( wxDumpWindow(NULL) );
wxScopedPtr<wxButton>
button(new wxButton(wxTheApp->GetTopWindow(), wxID_ANY, "bloordyblop"));
const std::string s = wxDumpWindow(button.get()).utf8_string();
CHECK_THAT( s, Catch::Contains("wxButton") );
CHECK_THAT( s, Catch::Contains("bloordyblop") );
}