Closing tabs with middle button click I could not find a way to make tab close button work in wxWidgets..

This commit is contained in:
Maciej Suminski 2016-08-11 14:42:07 +02:00
parent fccf71aadd
commit 2f8f92cf0a
5 changed files with 100 additions and 52 deletions

View File

@ -134,8 +134,6 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
m_toolBar->Realize();
m_plotNotebook->SetPageText(0, _("Welcome!") );
//relayout();
}
@ -171,12 +169,6 @@ void SIM_PLOT_FRAME::StartSimulation()
m_simulator->LoadNetlist( formatter.GetString() );
m_simulator->Run();
if ( m_welcomePanel )
{
m_plotNotebook->DeletePage( 0 );
m_welcomePanel = nullptr;
}
Layout();
}
@ -198,6 +190,12 @@ SIM_PLOT_PANEL* SIM_PLOT_FRAME::NewPlotPanel( SIM_TYPE aSimType )
{
SIM_PLOT_PANEL* plot = new SIM_PLOT_PANEL( aSimType, m_plotNotebook, wxID_ANY );
if( m_welcomePanel )
{
m_plotNotebook->DeletePage( 0 );
m_welcomePanel = nullptr;
}
m_plotNotebook->AddPage( plot, wxString::Format( wxT( "Plot%u" ),
(unsigned int) m_plotNotebook->GetPageCount() + 1 ), true );
@ -286,7 +284,7 @@ void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const
// Create a new plot if the current one displays a different type
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
if( plotPanel == nullptr || plotPanel->GetType() != simType )
if( !plotPanel || plotPanel->GetType() != simType )
plotPanel = NewPlotPanel( simType );
TRACE_DESC descriptor( *m_exporter, aName, aType, aParam );
@ -314,6 +312,7 @@ void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const
}
}
void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName )
{
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
@ -440,7 +439,7 @@ void SIM_PLOT_FRAME::updateTuners()
m_tuneSizer->Clear();
for( auto tuner : m_plots[plotPanel].m_tuners )
for( auto& tuner : m_plots[plotPanel].m_tuners )
{
m_tuneSizer->Add( tuner );
tuner->Show();
@ -598,7 +597,27 @@ void SIM_PLOT_FRAME::menuShowCoordsUpdate( wxUpdateUIEvent& event )
}
#endif
void SIM_PLOT_FRAME::onPlotChanged( wxNotebookEvent& event )
void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
{
int idx = event.GetSelection();
if( idx == wxNOT_FOUND )
return;
SIM_PLOT_PANEL* plotPanel = dynamic_cast<SIM_PLOT_PANEL*>( m_plotNotebook->GetPage( idx ) );
if( !plotPanel )
return;
m_plots.erase( plotPanel );
updateSignalList();
updateTuners();
updateCursors();
}
void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event )
{
updateSignalList();
updateTuners();
@ -697,13 +716,17 @@ void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent )
void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event )
{
wxSize size = m_cursors->GetClientSize();
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
m_cursors->ClearAll();
const long SIGNAL_COL = m_cursors->AppendColumn( wxT( "Signal" ), wxLIST_FORMAT_LEFT, size.x / 2 );
const long X_COL = m_cursors->AppendColumn( CurrentPlot()->GetLabelX(), wxLIST_FORMAT_LEFT, size.x / 4 );
if( !plotPanel )
return;
wxString labelY1 = CurrentPlot()->GetLabelY1();
wxString labelY2 = CurrentPlot()->GetLabelY2();
const long SIGNAL_COL = m_cursors->AppendColumn( wxT( "Signal" ), wxLIST_FORMAT_LEFT, size.x / 2 );
const long X_COL = m_cursors->AppendColumn( plotPanel->GetLabelX(), wxLIST_FORMAT_LEFT, size.x / 4 );
wxString labelY1 = plotPanel->GetLabelY1();
wxString labelY2 = plotPanel->GetLabelY2();
wxString labelY;
if( !labelY2.IsEmpty() )
@ -714,7 +737,7 @@ void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event )
const long Y_COL = m_cursors->AppendColumn( labelY, wxLIST_FORMAT_LEFT, size.x / 4 );
// Update cursor values
for( const auto& trace : CurrentPlot()->GetTraces() )
for( const auto& trace : plotPanel->GetTraces() )
{
if( CURSOR* cursor = trace.second->GetCursor() )
{
@ -746,7 +769,7 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent )
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
if( plotPanel == nullptr || plotPanel->GetType() != simType )
if( !plotPanel || plotPanel->GetType() != simType )
plotPanel = NewPlotPanel( simType );
// If there are any signals plotted, update them
@ -784,7 +807,7 @@ void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent )
// Apply tuned values
if( SIM_PLOT_PANEL* plotPanel = CurrentPlot() )
{
for( auto tuner : m_plots[plotPanel].m_tuners )
for( auto& tuner : m_plots[plotPanel].m_tuners )
{
/// @todo no ngspice hardcoding
std::string command( "alter @" + tuner->GetSpiceName()
@ -807,6 +830,13 @@ void SIM_PLOT_FRAME::onSimReport( wxCommandEvent& aEvent )
}
SIM_PLOT_FRAME::PLOT_INFO::~PLOT_INFO()
{
for( auto& t : m_tuners )
t->Destroy();
}
SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU( const wxString& aSignal,
SIM_PLOT_FRAME* aPlotFrame )
: m_signal( aSignal ), m_plotFrame( aPlotFrame )

View File

@ -200,7 +200,8 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
//void menuShowCoordsUpdate( wxUpdateUIEvent& event ) override;
// Event handlers
void onPlotChanged( wxNotebookEvent& event ) override;
void onPlotChanged( wxAuiNotebookEvent& event ) override;
void onPlotClose( wxAuiNotebookEvent& event ) override;
void onSignalDblClick( wxCommandEvent& event ) override;
void onSignalRClick( wxMouseEvent& event ) override;
@ -232,9 +233,15 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
typedef std::list<TUNER_SLIDER*> TUNER_LIST;
struct PLOT_INFO
class PLOT_INFO
{
public:
~PLOT_INFO();
///> List of component value tuners
TUNER_LIST m_tuners;
///> Map of the traces displayed on the plot
TRACE_MAP m_traces;
};

View File

@ -122,7 +122,7 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
m_plotPanel = new wxPanel( m_splitterConsole, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_sizer5 = new wxBoxSizer( wxHORIZONTAL );
m_plotNotebook = new wxNotebook( m_plotPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_plotNotebook = new wxAuiNotebook( m_plotPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_MIDDLE_CLICK_CLOSE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TOP );
m_welcomePanel = new wxPanel( m_plotNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_sizer8 = new wxBoxSizer( wxVERTICAL );
@ -155,9 +155,9 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
m_welcomePanel->SetSizer( m_sizer8 );
m_welcomePanel->Layout();
m_sizer8->Fit( m_welcomePanel );
m_plotNotebook->AddPage( m_welcomePanel, _("a page"), false );
m_plotNotebook->AddPage( m_welcomePanel, _("a page"), false, wxNullBitmap );
m_sizer5->Add( m_plotNotebook, 3, wxEXPAND | wxALL, 5 );
m_sizer5->Add( m_plotNotebook, 1, wxEXPAND | wxALL, 5 );
m_plotPanel->SetSizer( m_sizer5 );
@ -245,7 +245,8 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
this->Connect( m_showGrid->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridUpdate ) );
this->Connect( m_showLegend->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegend ) );
this->Connect( m_showLegend->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegendUpdate ) );
m_plotNotebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this );
m_plotNotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this );
m_plotNotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClose ), NULL, this );
m_signals->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), NULL, this );
m_signals->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( SIM_PLOT_FRAME_BASE::onSignalRClick ), NULL, this );
}
@ -271,7 +272,8 @@ SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE()
this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridUpdate ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegend ) );
this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegendUpdate ) );
m_plotNotebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this );
m_plotNotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this );
m_plotNotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClose ), NULL, this );
m_signals->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), NULL, this );
m_signals->Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( SIM_PLOT_FRAME_BASE::onSignalRClick ), NULL, this );

View File

@ -240,7 +240,7 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="wxMenu" expanded="1">
<object class="wxMenu" expanded="0">
<property name="label">Simulation</property>
<property name="name">m_simulationMenu</property>
<property name="permission">protected</property>
@ -328,7 +328,7 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="wxMenu" expanded="1">
<object class="wxMenu" expanded="0">
<property name="label">View</property>
<property name="name">m_viewMenu</property>
<property name="permission">protected</property>
@ -418,11 +418,11 @@
<property name="name">m_sizer1</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">protected</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxToolBar" expanded="1">
<object class="wxToolBar" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -834,16 +834,16 @@
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="0">
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">m_sizer5</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">protected</property>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">3</property>
<object class="wxNotebook" expanded="0">
<property name="proportion">1</property>
<object class="wxAuiNotebook" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -854,7 +854,6 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmapsize"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
@ -877,7 +876,7 @@
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">-1,-1</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_plotNotebook</property>
<property name="pane_border">1</property>
@ -889,13 +888,24 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="style">wxAUI_NB_MIDDLE_CLICK_CLOSE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TOP</property>
<property name="subclass"></property>
<property name="tab_ctrl_height">-1</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="uniform_bitmap_size"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnAuiNotebookAllowDND"></event>
<event name="OnAuiNotebookBeginDrag"></event>
<event name="OnAuiNotebookButton"></event>
<event name="OnAuiNotebookDragMotion"></event>
<event name="OnAuiNotebookEndDrag"></event>
<event name="OnAuiNotebookPageChanged">onPlotChanged</event>
<event name="OnAuiNotebookPageChanging"></event>
<event name="OnAuiNotebookPageClose">onPlotClose</event>
<event name="OnAuiNotebookPageClosed"></event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
@ -912,8 +922,6 @@
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnNotebookPageChanged">onPlotChanged</event>
<event name="OnNotebookPageChanging"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
@ -921,7 +929,7 @@
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="notebookpage" expanded="0">
<object class="auinotebookpage" expanded="1">
<property name="bitmap"></property>
<property name="label">a page</property>
<property name="select">0</property>
@ -1146,8 +1154,8 @@
</object>
</object>
</object>
<object class="splitteritem" expanded="1">
<object class="wxPanel" expanded="1">
<object class="splitteritem" expanded="0">
<object class="wxPanel" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1221,7 +1229,7 @@
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="1">
<object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property>
<property name="name">m_sizer13</property>
<property name="orient">wxVERTICAL</property>
@ -1325,8 +1333,8 @@
</object>
</object>
</object>
<object class="splitteritem" expanded="1">
<object class="wxPanel" expanded="1">
<object class="splitteritem" expanded="0">
<object class="wxPanel" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -1400,16 +1408,16 @@
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="1">
<object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property>
<property name="name">m_sideSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">protected</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxStaticBoxSizer" expanded="1">
<object class="wxStaticBoxSizer" expanded="0">
<property name="id">wxID_ANY</property>
<property name="label">Signals</property>
<property name="minimum_size"></property>
@ -1508,11 +1516,11 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxStaticBoxSizer" expanded="1">
<object class="wxStaticBoxSizer" expanded="0">
<property name="id">wxID_ANY</property>
<property name="label">Cursors</property>
<property name="minimum_size"></property>

View File

@ -27,7 +27,7 @@ class KIWAY_PLAYER;
#include <wx/stattext.h>
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/notebook.h>
#include <wx/aui/auibook.h>
#include <wx/textctrl.h>
#include <wx/splitter.h>
#include <wx/listbox.h>
@ -58,7 +58,7 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER
wxSplitterWindow* m_splitterConsole;
wxPanel* m_plotPanel;
wxBoxSizer* m_sizer5;
wxNotebook* m_plotNotebook;
wxAuiNotebook* m_plotNotebook;
wxPanel* m_welcomePanel;
wxBoxSizer* m_sizer8;
wxStaticText* m_staticText2;
@ -86,7 +86,8 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER
virtual void menuShowGridUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void menuShowLegend( wxCommandEvent& event ) { event.Skip(); }
virtual void menuShowLegendUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onPlotChanged( wxNotebookEvent& event ) { event.Skip(); }
virtual void onPlotChanged( wxAuiNotebookEvent& event ) { event.Skip(); }
virtual void onPlotClose( wxAuiNotebookEvent& event ) { event.Skip(); }
virtual void onSignalDblClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onSignalRClick( wxMouseEvent& event ) { event.Skip(); }