From 0a917b86b72568d1ac240f5c4e52954c0dd1b893 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 14 Dec 2015 21:50:27 +0100 Subject: [PATCH 1/4] 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; } From 38f6cf13d572ef47696d3166f786775e18c01e60 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 14 Dec 2015 21:57:11 +0100 Subject: [PATCH 2/4] Refresh the toolbar after changing tool placing value. After changing padding for toolbar in SetToolPacking() there is necessary to refresh/recalculate the toolbar to reflect new padding. --- src/msw/toolbar.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index fa97401829..71d2367dd3 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1637,6 +1637,7 @@ void wxToolBar::SetToolPacking(int packing) ::SendMessage(GetHWND(), TB_SETPADDING, 0, MAKELPARAM(0, m_toolPacking)); else ::SendMessage(GetHWND(), TB_SETPADDING, 0, MAKELPARAM(m_toolPacking, 0)); + Realize(); } } From 8fdf4221dc0587ec1f4284b4f16661ebdf92e03f Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 14 Dec 2015 22:03:24 +0100 Subject: [PATCH 3/4] Fix setting tool spacing. Don't set orthogonal padding value to zero but preserve its current value (using MSWSetPadding method). This way vertical padding is not zeroed when horizontal padding is set and horizontal padding is not zeroed when vertical padding is set. --- src/msw/toolbar.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 71d2367dd3..3b444317a5 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1630,14 +1630,14 @@ void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) void wxToolBar::SetToolPacking(int packing) { - m_toolPacking = packing; - if (m_toolPacking > 0 && GetHWND()) + if ( packing > 0 && packing != m_toolPacking ) { - if (IsVertical()) - ::SendMessage(GetHWND(), TB_SETPADDING, 0, MAKELPARAM(0, m_toolPacking)); - else - ::SendMessage(GetHWND(), TB_SETPADDING, 0, MAKELPARAM(m_toolPacking, 0)); - Realize(); + m_toolPacking = packing; + if ( GetHwnd() ) + { + MSWSetPadding(packing); + Realize(); + } } } From 2dd87a93dfacbf2be275b2710d3a5dc12fac50ac Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 16 Dec 2015 21:41:12 +0100 Subject: [PATCH 4/4] Take into account tool placing value in contructing tools with controls. Tool padding value should be taken into account also in sizing custom made tools (with controls) to get the same visual appearance and behaviour for all tools (buttons). --- src/msw/toolbar.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 3b444317a5..7cdbd98573 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -935,10 +935,11 @@ bool wxToolBar::Realize() } // Set separator width/height to fit the control width/height + // taking into account tool padding value. // (height is not used but it is set for the sake of consistency). { const wxSize sizeControl = tool->GetControl()->GetSize(); - button.iBitmap = IsVertical() ? sizeControl.y : sizeControl.x; + button.iBitmap = m_toolPacking + (IsVertical() ? sizeControl.y : sizeControl.x); } wxFALLTHROUGH; @@ -1139,14 +1140,15 @@ bool wxToolBar::Realize() staticText->Show(); } - control->Move(r.left, r.top + (diff + 1) / 2); + // Take also into account tool padding value. + control->Move(r.left + m_toolPacking/2, r.top + (diff + 1) / 2); if ( staticText ) { - staticText->Move(r.left + (size.x - staticTextSize.x)/2, + staticText->Move(r.left + m_toolPacking/2 + (size.x - staticTextSize.x)/2, r.bottom - staticTextSize.y); } - m_totalFixedSize += size.x; + m_totalFixedSize += r.right - r.left; } // the max index is the "real" number of buttons - i.e. counting even the