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.
This commit is contained in:
Artur Wieczorek
2015-12-14 21:50:27 +01:00
parent dd29ecf840
commit 0a917b86b7
2 changed files with 24 additions and 0 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;
} }