Merge branch 'toolbar-bottom'
Fix handling of toolbars using both wxTB_HORIZONTAL and wxTB_BOTTOM (or both wxTB_VERTICAL and wxTB_RIGHT) styles. See https://github.com/wxWidgets/wxWidgets/pull/1840 Closes #18769.
This commit is contained in:
@@ -482,6 +482,10 @@ public:
|
||||
// return true if this is a vertical toolbar, otherwise false
|
||||
bool IsVertical() const;
|
||||
|
||||
// returns one of wxTB_TOP, wxTB_BOTTOM, wxTB_LEFT, wxTB_RIGHT
|
||||
// indicating where the toolbar is placed in the associated frame
|
||||
int GetDirection() const;
|
||||
|
||||
// these methods allow to access tools by their index in the toolbar
|
||||
size_t GetToolsCount() const { return m_tools.GetCount(); }
|
||||
wxToolBarToolBase *GetToolByPos(int pos) { return m_tools[pos]; }
|
||||
|
@@ -628,6 +628,24 @@ bool wxToolBarBase::IsVertical() const
|
||||
return HasFlag(wxTB_LEFT | wxTB_RIGHT);
|
||||
}
|
||||
|
||||
// wxTB_HORIZONTAL is same as wxTB_TOP and wxTB_VERTICAL is same as wxTB_LEFT,
|
||||
// so a toolbar created with wxTB_HORIZONTAL | wxTB_BOTTOM style can have set both
|
||||
// wxTB_TOP and wxTB_BOTTOM, similarly wxTB_VERTICAL | wxTB_RIGHT == wxTB_LEFT | wxTB_RIGHT.
|
||||
// GetDirection() makes things less confusing and returns just one of wxTB_TOP, wxTB_BOTTOM,
|
||||
// wxTB_LEFT, wxTB_RIGHT indicating where the toolbar is placed in the associated frame.
|
||||
int wxToolBarBase::GetDirection() const
|
||||
{
|
||||
if ( HasFlag(wxTB_BOTTOM) )
|
||||
return wxTB_BOTTOM;
|
||||
|
||||
if ( HasFlag(wxTB_RIGHT) )
|
||||
return wxTB_RIGHT;
|
||||
|
||||
if ( HasFlag(wxTB_LEFT) )
|
||||
return wxTB_LEFT;
|
||||
|
||||
return wxTB_TOP;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event processing
|
||||
|
@@ -315,24 +315,25 @@ void wxFrame::PositionStatusBar()
|
||||
int x = 0;
|
||||
#if wxUSE_TOOLBAR
|
||||
wxToolBar * const toolbar = GetToolBar();
|
||||
if ( toolbar && !toolbar->HasFlag(wxTB_TOP) )
|
||||
if ( toolbar )
|
||||
{
|
||||
const wxSize sizeTB = toolbar->GetSize();
|
||||
const int directionTB = toolbar->GetDirection();
|
||||
|
||||
if ( toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT) )
|
||||
if ( toolbar->IsVertical() )
|
||||
{
|
||||
if ( toolbar->HasFlag(wxTB_LEFT) )
|
||||
if ( directionTB == wxTB_LEFT )
|
||||
x -= sizeTB.x;
|
||||
|
||||
w += sizeTB.x;
|
||||
}
|
||||
else // wxTB_BOTTOM
|
||||
else if ( directionTB == wxTB_BOTTOM )
|
||||
{
|
||||
// we need to position the status bar below the toolbar
|
||||
h += sizeTB.y;
|
||||
}
|
||||
}
|
||||
//else: no adjustments necessary for the toolbar on top
|
||||
}
|
||||
#endif // wxUSE_TOOLBAR
|
||||
|
||||
// GetSize returns the height of the clientSize in which the statusbar
|
||||
@@ -932,12 +933,13 @@ wxPoint wxFrame::GetClientAreaOrigin() const
|
||||
if ( toolbar && toolbar->IsShown() )
|
||||
{
|
||||
const wxSize sizeTB = toolbar->GetSize();
|
||||
const int directionTB = toolbar->GetDirection();
|
||||
|
||||
if ( toolbar->HasFlag(wxTB_TOP) )
|
||||
if ( directionTB == wxTB_TOP )
|
||||
{
|
||||
pt.y += sizeTB.y;
|
||||
}
|
||||
else if ( toolbar->HasFlag(wxTB_LEFT) )
|
||||
else if ( directionTB == wxTB_LEFT )
|
||||
{
|
||||
pt.x += sizeTB.x;
|
||||
}
|
||||
|
@@ -59,14 +59,15 @@ wxPoint wxFrame::GetClientAreaOrigin() const
|
||||
wxToolBar *toolbar = GetToolBar();
|
||||
if ( toolbar && toolbar->IsShown() )
|
||||
{
|
||||
const int direction = toolbar->GetDirection();
|
||||
int w, h;
|
||||
toolbar->GetSize(&w, &h);
|
||||
|
||||
if ( toolbar->HasFlag(wxTB_LEFT) )
|
||||
if ( direction == wxTB_LEFT )
|
||||
{
|
||||
pt.x += w;
|
||||
}
|
||||
else if ( toolbar->HasFlag(wxTB_TOP) )
|
||||
else if ( direction == wxTB_TOP )
|
||||
{
|
||||
#if !wxOSX_USE_NATIVE_TOOLBAR
|
||||
pt.y += h;
|
||||
@@ -338,18 +339,20 @@ void wxFrame::PositionToolBar()
|
||||
|
||||
if (GetToolBar())
|
||||
{
|
||||
const int direction = GetToolBar()->GetDirection();
|
||||
int tx, ty, tw, th;
|
||||
|
||||
tx = ty = 0 ;
|
||||
GetToolBar()->GetSize(&tw, &th);
|
||||
if (GetToolBar()->HasFlag(wxTB_LEFT))
|
||||
|
||||
if (direction == wxTB_LEFT)
|
||||
{
|
||||
// Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
|
||||
// means, pretend we don't have toolbar/status bar, so we
|
||||
// have the original client size.
|
||||
GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
|
||||
}
|
||||
else if (GetToolBar()->HasFlag(wxTB_RIGHT))
|
||||
else if (direction == wxTB_RIGHT)
|
||||
{
|
||||
// Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
|
||||
// means, pretend we don't have toolbar/status bar, so we
|
||||
@@ -357,7 +360,7 @@ void wxFrame::PositionToolBar()
|
||||
tx = cw - tw;
|
||||
GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
|
||||
}
|
||||
else if (GetToolBar()->HasFlag(wxTB_BOTTOM))
|
||||
else if (direction == wxTB_BOTTOM)
|
||||
{
|
||||
tx = 0;
|
||||
ty = ch - th;
|
||||
|
@@ -1670,6 +1670,7 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
const int direction = GetDirection();
|
||||
int w, h;
|
||||
GetSize( &w, &h );
|
||||
|
||||
@@ -1688,13 +1689,14 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
|
||||
}
|
||||
|
||||
dc.SetPen( wxPen( wxColour( 0x51,0x51,0x51 ) ) );
|
||||
if ( HasFlag(wxTB_LEFT) )
|
||||
dc.DrawLine(w-1, 0, w-1, h);
|
||||
else if ( HasFlag(wxTB_RIGHT) )
|
||||
|
||||
if ( direction == wxTB_RIGHT )
|
||||
dc.DrawLine(0, 0, 0, h);
|
||||
else if ( HasFlag(wxTB_BOTTOM) )
|
||||
else if ( direction == wxTB_LEFT )
|
||||
dc.DrawLine(w-1, 0, w-1, h);
|
||||
else if ( direction == wxTB_BOTTOM )
|
||||
dc.DrawLine(0, 0, w, 0);
|
||||
else if ( HasFlag(wxTB_TOP) )
|
||||
else if ( direction == wxTB_TOP )
|
||||
dc.DrawLine(0, h-1, w, h-1);
|
||||
}
|
||||
event.Skip();
|
||||
|
Reference in New Issue
Block a user