From 0a917b86b72568d1ac240f5c4e52954c0dd1b893 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 14 Dec 2015 21:50:27 +0100 Subject: [PATCH] Initialize padding while creating a toolbar. If padding value (stored in m_toolPacking) has been assigned prior to creating the toolbar (with SetToolPacking) then apply this padding to just created toolbar. Otherwise initialize this variable with current padding retrieved from the toolbar to let GetToolPacking return proper padding value. Implemented new method MSWSetPadding() to set padding for native toolbar. --- include/wx/msw/toolbar.h | 2 ++ src/msw/toolbar.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/wx/msw/toolbar.h b/include/wx/msw/toolbar.h index dfd59adc8f..772e99aa12 100644 --- a/include/wx/msw/toolbar.h +++ b/include/wx/msw/toolbar.h @@ -136,6 +136,8 @@ protected: // get the Windows toolbar style of this control long GetMSWToolbarStyle() const; + // set native toolbar padding + void MSWSetPadding(WXWORD padding); // the big bitmap containing all bitmaps of the toolbar buttons WXHBITMAP m_hBitmap; diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 4f781c9afc..fa97401829 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -377,6 +377,15 @@ bool wxToolBar::Create(wxWindow *parent, return true; } +void wxToolBar::MSWSetPadding(WXWORD padding) +{ + DWORD curPadding = ::SendMessage(GetHwnd(), TB_GETPADDING, 0, 0); + // Preserve orthogonal padding + DWORD newPadding = IsVertical() ? MAKELPARAM(LOWORD(curPadding), padding) + : MAKELPARAM(padding, HIWORD(curPadding)); + ::SendMessage(GetHwnd(), TB_SETPADDING, 0, newPadding); +} + bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size) { if ( !MSWCreateControl(TOOLBARCLASSNAME, wxEmptyString, pos, size) ) @@ -389,6 +398,19 @@ bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size) ::SendMessage(GetHwnd(), TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS); #endif + // Retrieve or apply/restore tool packing value. + if ( m_toolPacking <= 0 ) + { + // Retrieve packing value if it hasn't been yet set with SetToolPacking. + DWORD padding = ::SendMessage(GetHwnd(), TB_GETPADDING, 0, 0); + m_toolPacking = IsVertical() ? HIWORD(padding) : LOWORD(padding); + } + else + { + // Apply packing value if it has been already set with SetToolPacking. + MSWSetPadding(m_toolPacking); + } + return true; }