Merge branch 'toolbar_change_placing' of https://github.com/a-wi/wxWidgets

Fix several problems related to SetToolPacking() in wxMSW.
This commit is contained in:
Vadim Zeitlin
2015-12-17 02:09:21 +01:00
2 changed files with 37 additions and 10 deletions

View File

@@ -136,6 +136,8 @@ protected:
// get the Windows toolbar style of this control // get the Windows toolbar style of this control
long GetMSWToolbarStyle() const; long GetMSWToolbarStyle() const;
// set native toolbar padding
void MSWSetPadding(WXWORD padding);
// the big bitmap containing all bitmaps of the toolbar buttons // the big bitmap containing all bitmaps of the toolbar buttons
WXHBITMAP m_hBitmap; WXHBITMAP m_hBitmap;

View File

@@ -377,6 +377,15 @@ bool wxToolBar::Create(wxWindow *parent,
return true; 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) bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size)
{ {
if ( !MSWCreateControl(TOOLBARCLASSNAME, wxEmptyString, pos, 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); ::SendMessage(GetHwnd(), TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS);
#endif #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; return true;
} }
@@ -913,10 +935,11 @@ bool wxToolBar::Realize()
} }
// Set separator width/height to fit the control width/height // 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). // (height is not used but it is set for the sake of consistency).
{ {
const wxSize sizeControl = tool->GetControl()->GetSize(); const wxSize sizeControl = tool->GetControl()->GetSize();
button.iBitmap = IsVertical() ? sizeControl.y : sizeControl.x; button.iBitmap = m_toolPacking + (IsVertical() ? sizeControl.y : sizeControl.x);
} }
wxFALLTHROUGH; wxFALLTHROUGH;
@@ -1117,14 +1140,15 @@ bool wxToolBar::Realize()
staticText->Show(); 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 ) 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); 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 // the max index is the "real" number of buttons - i.e. counting even the
@@ -1608,13 +1632,14 @@ void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
void wxToolBar::SetToolPacking(int packing) void wxToolBar::SetToolPacking(int packing)
{ {
m_toolPacking = packing; if ( packing > 0 && packing != m_toolPacking )
if (m_toolPacking > 0 && GetHWND())
{ {
if (IsVertical()) m_toolPacking = packing;
::SendMessage(GetHWND(), TB_SETPADDING, 0, MAKELPARAM(0, m_toolPacking)); if ( GetHwnd() )
else {
::SendMessage(GetHWND(), TB_SETPADDING, 0, MAKELPARAM(m_toolPacking, 0)); MSWSetPadding(packing);
Realize();
}
} }
} }