From dddd1f21c165da8c9e8cd62a7007e99a4fcab7b3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 26 Nov 2005 13:09:23 +0000 Subject: [PATCH] added helper for visual sizers debugging git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36252 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/wincmn.cpp | 74 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 763d5206d6..05f22c324f 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2249,12 +2249,82 @@ void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) UpdateWindowUI(wxUPDATE_UI_RECURSE); } -// process Ctrl-Alt-mclick +// methods for drawing the sizers in a visible way +#ifdef __WXDEBUG__ + +static void DrawSizers(wxWindowBase *win); + +static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill = false) +{ + wxClientDC dc((wxWindow *)win); + dc.SetPen(*wxRED_PEN); + dc.SetBrush(fill ? wxBrush(*wxRED, wxCROSSDIAG_HATCH): *wxTRANSPARENT_BRUSH); + dc.DrawRectangle(rect.Deflate(1, 1)); +} + +static void DrawSizer(wxWindowBase *win, wxSizer *sizer) +{ + const wxSizerItemList& items = sizer->GetChildren(); + for ( wxSizerItemList::const_iterator i = items.begin(), + end = items.end(); + i != end; + ++i ) + { + wxSizerItem *item = *i; + if ( item->IsSizer() ) + { + DrawBorder(win, item->GetRect().Deflate(2)); + DrawSizer(win, item->GetSizer()); + } + else if ( item->IsSpacer() ) + { + DrawBorder(win, item->GetRect().Deflate(2), true); + } + else if ( item->IsWindow() ) + { + DrawSizers(item->GetWindow()); + } + } +} + +static void DrawSizers(wxWindowBase *win) +{ + wxSizer *sizer = win->GetSizer(); + if ( sizer ) + { + DrawBorder(win, win->GetClientSize()); + DrawSizer(win, sizer); + } + else // no sizer, still recurse into the children + { + const wxWindowList& children = win->GetChildren(); + for ( wxWindowList::const_iterator i = children.begin(), + end = children.end(); + i != end; + ++i ) + { + DrawSizers(*i); + } + } +} + +#endif // __WXDEBUG__ + +// process special middle clicks void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) { -#if wxUSE_MSGDLG if ( event.ControlDown() && event.AltDown() ) { +#ifdef __WXDEBUG__ + // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds + if ( event.ShiftDown() ) + { + DrawSizers(this); + return; + } +#endif // __WXDEBUG__ + +#if wxUSE_MSGDLG // don't translate these strings wxString port; -- 2.45.2