From 6aabb9bc38aa7919e6f926fef4c2de0762cd3481 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sun, 17 Nov 2013 00:04:20 -0600 Subject: [PATCH] EDA_LIST_DIALOG_BASE is used multiple times for different numbers of columns. DIALOG_SHIM would resize each separate usage to the same size. DIALOG_SHIM now supports and alternate m_hash_key in lieu of the class name, optionally. --- common/dialog_shim.cpp | 16 +++++++++++++--- common/dialogs/dialog_get_component_base.cpp | 4 +++- common/dialogs/dialog_get_component_base.fbp | 4 +++- common/dialogs/dialog_get_component_base.h | 6 ++++-- common/dialogs/dialog_list_selector_base.cpp | 11 +++++------ common/dialogs/dialog_list_selector_base.fbp | 16 +++++++++------- common/dialogs/dialog_list_selector_base.h | 16 ++++++++-------- common/displlst.cpp | 13 +++++++++---- include/dialog_shim.h | 7 ++++++- 9 files changed, 60 insertions(+), 33 deletions(-) diff --git a/common/dialog_shim.cpp b/common/dialog_shim.cpp index 47066e77c7..1d50a08908 100644 --- a/common/dialog_shim.cpp +++ b/common/dialog_shim.cpp @@ -46,7 +46,17 @@ static RECT_MAP class_map; bool DIALOG_SHIM::Show( bool show ) { bool ret; - const char* classname = typeid(*this).name(); + const char* hash_key; + + if( m_hash_key.size() ) + { + // a special case like EDA_LIST_DIALOG, which has multiple uses. + hash_key = m_hash_key.c_str(); + } + else + { + hash_key = typeid(*this).name(); + } // Show or hide the window. If hiding, save current position and size. // If showing, use previous position and size. @@ -55,7 +65,7 @@ bool DIALOG_SHIM::Show( bool show ) ret = wxDialog::Show( show ); // classname is key, returns a zeroed out default EDA_RECT if none existed before. - EDA_RECT r = class_map[ classname ]; + EDA_RECT r = class_map[ hash_key ]; if( r.GetSize().x != 0 && r.GetSize().y != 0 ) SetSize( r.GetPosition().x, r.GetPosition().y, r.GetSize().x, r.GetSize().y, 0 ); @@ -64,7 +74,7 @@ bool DIALOG_SHIM::Show( bool show ) { // Save the dialog's position & size before hiding, using classname as key EDA_RECT r( wxDialog::GetPosition(), wxDialog::GetSize() ); - class_map[ classname ] = r; + class_map[ hash_key ] = r; ret = wxDialog::Show( show ); } diff --git a/common/dialogs/dialog_get_component_base.cpp b/common/dialogs/dialog_get_component_base.cpp index 452a27a065..8e8810c5d0 100644 --- a/common/dialogs/dialog_get_component_base.cpp +++ b/common/dialogs/dialog_get_component_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 10 2012) +// C++ code generated with wxFormBuilder (version Nov 5 2013) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -24,6 +24,7 @@ DIALOG_GET_COMPONENT_BASE::DIALOG_GET_COMPONENT_BASE( wxWindow* parent, wxWindow bSizerLeft->Add( m_staticTextName, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_textCmpNameCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_textCmpNameCtrl->SetMaxLength( 0 ); bSizerLeft->Add( m_textCmpNameCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_staticTextHistory = new wxStaticText( this, wxID_ANY, _("History list:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -63,6 +64,7 @@ DIALOG_GET_COMPONENT_BASE::DIALOG_GET_COMPONENT_BASE( wxWindow* parent, wxWindow this->SetSizer( bSizerMain ); this->Layout(); + bSizerMain->Fit( this ); this->Centre( wxBOTH ); diff --git a/common/dialogs/dialog_get_component_base.fbp b/common/dialogs/dialog_get_component_base.fbp index a39d3372e4..10a950c93f 100644 --- a/common/dialogs/dialog_get_component_base.fbp +++ b/common/dialogs/dialog_get_component_base.fbp @@ -20,8 +20,10 @@ . 1 + 1 1 1 + UI 0 0 @@ -42,7 +44,7 @@ DIALOG_GET_COMPONENT_BASE - 375,210 + -1,-1 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER DIALOG_SHIM; dialog_shim.h diff --git a/common/dialogs/dialog_get_component_base.h b/common/dialogs/dialog_get_component_base.h index e40fc7a99c..a0a39d5b27 100644 --- a/common/dialogs/dialog_get_component_base.h +++ b/common/dialogs/dialog_get_component_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 10 2012) +// C++ code generated with wxFormBuilder (version Nov 5 2013) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -11,6 +11,8 @@ #include #include #include +class DIALOG_SHIM; + #include "dialog_shim.h" #include #include @@ -57,7 +59,7 @@ class DIALOG_GET_COMPONENT_BASE : public DIALOG_SHIM public: - DIALOG_GET_COMPONENT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 375,210 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + DIALOG_GET_COMPONENT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_GET_COMPONENT_BASE(); }; diff --git a/common/dialogs/dialog_list_selector_base.cpp b/common/dialogs/dialog_list_selector_base.cpp index a4574c9bcf..9fec346120 100644 --- a/common/dialogs/dialog_list_selector_base.cpp +++ b/common/dialogs/dialog_list_selector_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 8 2012) +// C++ code generated with wxFormBuilder (version Nov 5 2013) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -29,10 +29,8 @@ EDA_LIST_DIALOG_BASE::EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id, con m_staticText2->Wrap( -1 ); bSizerMain->Add( m_staticText2, 0, wxRIGHT|wxLEFT, 5 ); - m_listBox = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxVSCROLL ); - m_listBox->SetMinSize( wxSize( 300,200 ) ); - - bSizerMain->Add( m_listBox, 1, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); + m_listBox = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL|wxALWAYS_SHOW_SB|wxVSCROLL ); + bSizerMain->Add( m_listBox, 3, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); m_staticTextMsg = new wxStaticText( this, wxID_ANY, _("Messages:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextMsg->Wrap( -1 ); @@ -41,7 +39,7 @@ EDA_LIST_DIALOG_BASE::EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id, con m_messages = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY ); m_messages->SetMinSize( wxSize( -1,80 ) ); - bSizerMain->Add( m_messages, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + bSizerMain->Add( m_messages, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizerOK = new wxButton( this, wxID_OK ); @@ -55,6 +53,7 @@ EDA_LIST_DIALOG_BASE::EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id, con this->SetSizer( bSizerMain ); this->Layout(); + bSizerMain->Fit( this ); this->Centre( wxBOTH ); diff --git a/common/dialogs/dialog_list_selector_base.fbp b/common/dialogs/dialog_list_selector_base.fbp index 74591b43d2..dc016cc11b 100644 --- a/common/dialogs/dialog_list_selector_base.fbp +++ b/common/dialogs/dialog_list_selector_base.fbp @@ -20,8 +20,10 @@ . 1 + 1 1 1 + UI 0 0 @@ -32,7 +34,7 @@ 1 1 - impl_virtual + decl_pure_virtual @@ -42,7 +44,7 @@ EDA_LIST_DIALOG_BASE - 329,398 + -1,-1 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER DIALOG_SHIM; dialog_shim.h @@ -351,7 +353,7 @@ 5 wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND - 1 + 3 1 1 @@ -385,7 +387,7 @@ 0 - 300,200 + -1,-1 1 m_listBox 1 @@ -397,7 +399,7 @@ Resizable 1 - wxLC_REPORT + wxLC_REPORT|wxLC_SINGLE_SEL 0 @@ -407,7 +409,7 @@ - wxVSCROLL + wxALWAYS_SHOW_SB|wxVSCROLL @@ -539,7 +541,7 @@ 5 wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT - 0 + 1 1 1 diff --git a/common/dialogs/dialog_list_selector_base.h b/common/dialogs/dialog_list_selector_base.h index 7f6c6239f7..162e43785d 100644 --- a/common/dialogs/dialog_list_selector_base.h +++ b/common/dialogs/dialog_list_selector_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 8 2012) +// C++ code generated with wxFormBuilder (version Nov 5 2013) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -48,17 +48,17 @@ class EDA_LIST_DIALOG_BASE : public DIALOG_SHIM wxButton* m_sdbSizerCancel; // Virtual event handlers, overide them in your derived class - virtual void onClose( wxCloseEvent& event ) { event.Skip(); } - virtual void textChangeInFilterBox( wxCommandEvent& event ) { event.Skip(); } - virtual void onListItemActivated( wxListEvent& event ) { event.Skip(); } - virtual void onListItemSelected( wxListEvent& event ) { event.Skip(); } - virtual void onCancelClick( wxCommandEvent& event ) { event.Skip(); } - virtual void onOkClick( wxCommandEvent& event ) { event.Skip(); } + virtual void onClose( wxCloseEvent& event ) = 0; + virtual void textChangeInFilterBox( wxCommandEvent& event ) = 0; + virtual void onListItemActivated( wxListEvent& event ) = 0; + virtual void onListItemSelected( wxListEvent& event ) = 0; + virtual void onCancelClick( wxCommandEvent& event ) = 0; + virtual void onOkClick( wxCommandEvent& event ) = 0; public: - EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 329,398 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~EDA_LIST_DIALOG_BASE(); }; diff --git a/common/displlst.cpp b/common/displlst.cpp index 5dcaca5f52..3cc2097e9b 100644 --- a/common/displlst.cpp +++ b/common/displlst.cpp @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -48,7 +49,6 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl wxListItem column; column.SetId( i ); column.SetText( aItemHeaders.Item( i ) ); - column.SetWidth( 300 / aItemHeaders.Count() ); m_listBox->InsertColumn( i, column ); } @@ -66,6 +66,13 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl } } + // DIALOG_SHIM needs a unique hash_key because classname is not sufficient + // because so many dialogs share this same class. + m_hash_key = TO_UTF8( aTitle ); + + for( unsigned i = 0; i < aItemHeaders.Count(); i++ ) + m_listBox->SetColumnWidth( i, wxLIST_AUTOSIZE ); + if( m_callBackFct == NULL ) { m_messages->Show( false ); @@ -74,9 +81,7 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl m_filterBox->SetFocus(); - GetSizer()->Fit( this ); - GetSizer()->SetSizeHints( this ); - Centre(); + Layout(); } diff --git a/include/dialog_shim.h b/include/dialog_shim.h index 8cd8025981..56e30253fb 100644 --- a/include/dialog_shim.h +++ b/include/dialog_shim.h @@ -52,15 +52,20 @@ public: const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE, - const wxString& name = wxDialogNameStr ); + const wxString& name = wxDialogNameStr + ); bool Show( bool show ); // overload wxDialog::Show +protected: + std::string m_hash_key; // alternate for class_map when classname re-used. #if DLGSHIM_USE_SETFOCUS private: void onInit( wxInitDialogEvent& aEvent ); #endif + + }; #endif // DIALOG_SHIM_