Browse Source

Fix status bar field position assertion when opening page layout editor.

Our KISTATUSBAR object was making the invalid assumption that all of the
optional panes were available.  This is not the case with the page layout
editor which caused assertions in the wxStatusBar code when attempting to
get status bar pane information that was not in the status bar.  Add checks
to ensure we don't attempt to access invalid pane ordinals.

Fixes KICAD-10XP
master
Wayne Stambaugh 3 weeks ago
parent
commit
20b1314fc8
  1. 98
      common/widgets/kistatusbar.cpp
  2. 7
      pagelayout_editor/pl_editor_frame.cpp

98
common/widgets/kistatusbar.cpp

@ -227,56 +227,76 @@ void KISTATUSBAR::layoutControls()
constexpr int padding = 5;
wxRect r;
GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_LABEL ), r );
int x = r.GetLeft();
int y = r.GetTop();
int textHeight = KIUI::GetTextSize( wxT( "bp" ), this ).y;
int sbField = m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_LABEL );
if( r.GetHeight() > textHeight )
y += ( r.GetHeight() - textHeight ) / 2;
m_backgroundTxt->SetPosition( { x, y } );
m_backgroundTxt->SetSize( r.GetWidth(), textHeight );
updateBackgroundText();
if( sbField >= 0 && sbField < GetFieldsCount() )
{
GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_LABEL ), r );
int x = r.GetLeft();
int y = r.GetTop();
int textHeight = KIUI::GetTextSize( wxT( "bp" ), this ).y;
GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_GAUGE ), r );
x = r.GetLeft();
y = r.GetTop();
int w = r.GetWidth();
int h = r.GetHeight();
wxSize buttonSize( 0, 0 );
if( r.GetHeight() > textHeight )
y += ( r.GetHeight() - textHeight ) / 2;
if( m_backgroundStopButton )
{
buttonSize = m_backgroundStopButton->GetEffectiveMinSize();
m_backgroundStopButton->SetPosition( { x + w - buttonSize.GetWidth(), y } );
m_backgroundStopButton->SetSize( buttonSize.GetWidth(), h );
buttonSize.x += padding;
m_backgroundTxt->SetPosition( { x, y } );
m_backgroundTxt->SetSize( r.GetWidth(), textHeight );
updateBackgroundText();
}
m_backgroundProgressBar->SetPosition( { x + padding, y } );
m_backgroundProgressBar->SetSize( w - buttonSize.GetWidth() - padding, h );
sbField = m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_GAUGE );
if( m_notificationsButton )
if( sbField >= 0 && sbField < GetFieldsCount() )
{
GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::NOTIFICATION ), r );
x = r.GetLeft();
y = r.GetTop();
h = r.GetHeight();
buttonSize = m_notificationsButton->GetEffectiveMinSize();
m_notificationsButton->SetPosition( { x, y } );
m_notificationsButton->SetSize( buttonSize.GetWidth() + 6, h );
GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_GAUGE ), r );
int x = r.GetLeft();
int y = r.GetTop();
int w = r.GetWidth();
int h = r.GetHeight();
wxSize buttonSize( 0, 0 );
if( m_backgroundStopButton )
{
buttonSize = m_backgroundStopButton->GetEffectiveMinSize();
m_backgroundStopButton->SetPosition( { x + w - buttonSize.GetWidth(), y } );
m_backgroundStopButton->SetSize( buttonSize.GetWidth(), h );
buttonSize.x += padding;
}
m_backgroundProgressBar->SetPosition( { x + padding, y } );
m_backgroundProgressBar->SetSize( w - buttonSize.GetWidth() - padding, h );
if( m_notificationsButton )
{
sbField = m_normalFieldsCount + *fieldIndex( FIELD::NOTIFICATION );
if( sbField >= 0 && sbField < GetFieldsCount() )
{
GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::NOTIFICATION ), r );
x = r.GetLeft();
y = r.GetTop();
h = r.GetHeight();
buttonSize = m_notificationsButton->GetEffectiveMinSize();
m_notificationsButton->SetPosition( { x, y } );
m_notificationsButton->SetSize( buttonSize.GetWidth() + 6, h );
}
}
}
if( m_warningButton )
{
GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::WARNING ), r );
x = r.GetLeft();
y = r.GetTop();
h = r.GetHeight();
buttonSize = m_warningButton->GetEffectiveMinSize();
m_warningButton->SetPosition( { x, y } );
m_warningButton->SetSize( buttonSize.GetWidth() + 6, h );
sbField = m_normalFieldsCount + *fieldIndex( FIELD::WARNING );
if( sbField >= 0 && sbField < GetFieldsCount() )
{
GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::WARNING ), r );
int x = r.GetLeft();
int y = r.GetTop();
int h = r.GetHeight();
wxSize buttonSize = m_warningButton->GetEffectiveMinSize();
m_warningButton->SetPosition( { x, y } );
m_warningButton->SetSize( buttonSize.GetWidth() + 6, h );
}
}
}

7
pagelayout_editor/pl_editor_frame.cpp

@ -144,8 +144,8 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
configureToolbars();
RecreateToolbars();
wxWindow* stsbar = GetStatusBar();
int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
wxStatusBar* stsbar = GetStatusBar();
int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
int dims[] = {
@ -177,7 +177,8 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x + spacer
};
SetStatusWidths( arrayDim( dims ), dims );
if( stsbar )
stsbar->SetFieldsCount( arrayDim( dims ), dims );
m_auimgr.SetManagedWindow( this );

Loading…
Cancel
Save