diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index ffda22832c..f57897eac8 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -38,7 +38,30 @@ #include #include -#include +#include +#include + +class SCH_EDIT_FRAME; +class SCH_TEXT; + + +DIALOG_EXTEND_WITH_SHIM( DialogLabelEditor, DialogLabelEditor_Base ) +{ +public: + DialogLabelEditor( SCH_EDIT_FRAME* parent, SCH_TEXT* aTextItem ); + +private: + void InitDialog( ); + virtual void OnEnterKey( wxCommandEvent& aEvent ); + virtual void OnOkClick( wxCommandEvent& aEvent ); + virtual void OnCancelClick( wxCommandEvent& aEvent ); + void TextPropertiesAccept( wxCommandEvent& aEvent ); + + SCH_EDIT_FRAME* m_Parent; + SCH_TEXT* m_CurrentText; + wxTextCtrl* m_textLabel; +}; + /* Edit the properties of the text (Label, Global label, graphic text).. ) @@ -56,7 +79,7 @@ void SCH_EDIT_FRAME::EditSchematicText( SCH_TEXT* aTextItem ) DialogLabelEditor::DialogLabelEditor( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTextItem ) : - DialogLabelEditor_Base( aParent ) + DialogLabelEditor_Base_SHIM( aParent ) { m_Parent = aParent; m_CurrentText = aTextItem; diff --git a/eeschema/dialogs/dialog_edit_label.h b/eeschema/dialogs/dialog_edit_label.h deleted file mode 100644 index 505038875e..0000000000 --- a/eeschema/dialogs/dialog_edit_label.h +++ /dev/null @@ -1,41 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: dialog_edit_label.h -// Author: jean-pierre Charras -// Modified by: -// Licence: GPL -///////////////////////////////////////////////////////////////////////////// - -#ifndef _DIALOG_EDIT_LABEL_H_ -#define _DIALOG_EDIT_LABEL_H_ - -#include - - -class SCH_EDIT_FRAME; -class SCH_TEXT; - - -class DialogLabelEditor : public DialogLabelEditor_Base -{ -private: - SCH_EDIT_FRAME* m_Parent; - SCH_TEXT* m_CurrentText; - wxTextCtrl* m_textLabel; - -public: - DialogLabelEditor( SCH_EDIT_FRAME* parent, SCH_TEXT* aTextItem ); - ~DialogLabelEditor(){}; - - -public: - -private: - void InitDialog( ); - virtual void OnEnterKey( wxCommandEvent& aEvent ); - virtual void OnOkClick( wxCommandEvent& aEvent ); - virtual void OnCancelClick( wxCommandEvent& aEvent ); - void TextPropertiesAccept( wxCommandEvent& aEvent ); -}; - - -#endif // _DIALOG_EDIT_LABEL_H_ diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index 1a6e875ea8..80de764c44 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -55,6 +55,7 @@ #include + /* Library editor wxConfig entry names. */ const wxString lastLibExportPathEntry( wxT( "LastLibraryExportPath" ) ); const wxString lastLibImportPathEntry( wxT( "LastLibraryImportPath" ) ); diff --git a/include/dialog_helpers.h b/include/dialog_helpers.h index a560c6a146..720fa2b498 100644 --- a/include/dialog_helpers.h +++ b/include/dialog_helpers.h @@ -4,8 +4,8 @@ * @note Due to use of wxFormBuilder to create dialogs many of them should be removed. */ -#ifndef _DIALOG_HELPERS_H_ -#define _DIALOG_HELPERS_H_ +#ifndef DIALOG_HELPERS_H_ +#define DIALOG_HELPERS_H_ #include // EDA_UNITS_T @@ -183,4 +183,71 @@ public: }; -#endif // _DIALOG_HELPERS_H_ +/** + * Template DIALOG_SHIM + * is a way to have a common way of handling KiCad dialog windows: + *
    + *
  • class specific: static s_LastPos and static s_LastSize for retentative + * dialog window positioning, per class. + *
  • invocation of SetFocus() to allow ESC key to work on Linux. + *
  • future others... + *
+ * by wedging in a class (a SHIM) between the wxFormbuilder coded base class and + * our derived dialog classes. Use it via the macro named DIALOG_EXTEND_WITH_SHIM + * and be sure to code your constructor to invoke *_SHIM() base class constructor, + * not the one from wxFormbuilder. + * @author Dick Hollenbeck + */ +template +class DIALOG_SHIM : public T +{ +public: + + DIALOG_SHIM( wxFrame* aParent ) : + T( aParent ) + { + wxDialog::SetFocus(); + } + + // overload wxDialog::Show + bool Show( bool show ) + { + bool ret; + + if( show ) + { + ret = wxDialog::Show( show ); + if( s_LastPos.x != -1 ) + wxDialog::SetSize( s_LastPos.x, s_LastPos.y, s_LastSize.x, s_LastSize.y, 0 ); + } + else + { + // Save the dialog's position before hiding + s_LastPos = wxDialog::GetPosition(); + s_LastSize = wxDialog::GetSize(); + ret = wxDialog::Show( show ); + } + return ret; + } + +private: + static wxPoint s_LastPos; + static wxSize s_LastSize; +}; + +template +wxPoint DIALOG_SHIM::s_LastPos( -1, -1 ); + +template +wxSize DIALOG_SHIM::s_LastSize( 0, 0 ); + +/** + * Macro DIALOG_EXTEND_WITH_SHIM + * instantiates the template DIALOG_SHIM<> and thereby declares a shim class. + * @author Dick Hollenbeck + */ +#define DIALOG_EXTEND_WITH_SHIM( DERRIVED, BASE ) \ + typedef DIALOG_SHIM BASE##_SHIM; \ + class DERRIVED : public BASE##_SHIM + +#endif // DIALOG_HELPERS_H_ diff --git a/include/fctsys.h b/include/fctsys.h index 148340bf45..648baa5926 100644 --- a/include/fctsys.h +++ b/include/fctsys.h @@ -50,8 +50,9 @@ * Function Clamp * limits @a value within the range @a lower <= @a value <= @a upper. It will work * on temporary expressions, since they are evaluated only once, and it should work - * on most if not all numeric types. The arguments are accepted in this order so you - * can remember the expression as a memory aid: + * on most if not all numeric types, string types, or any type for which "operator < ()" + * is present. The arguments are accepted in this order so you can remember the + * expression as a memory aid: *

* result is: lower <= value <= upper */ @@ -60,7 +61,7 @@ template inline const T& Clamp( const T& lower, const T& value, con wxASSERT( lower <= upper ); if( value < lower ) return lower; - else if( value > upper ) + else if( upper < value ) return upper; return value; } diff --git a/pcbnew/dialogs/dialog_pcb_text_properties.cpp b/pcbnew/dialogs/dialog_pcb_text_properties.cpp index ae70e82fae..26e7a9ed68 100644 --- a/pcbnew/dialogs/dialog_pcb_text_properties.cpp +++ b/pcbnew/dialogs/dialog_pcb_text_properties.cpp @@ -38,7 +38,35 @@ #include #include -#include +#include +#include +#include + + +class PCB_EDIT_FRAME; +class TEXTE_PCB; + + +/// Implement DIALOG_PCB_TEXT_PROPERTIES_BASE with interposing +/// DIALOG_PCB_TEXT_PROPERTIES_BASE_SHIM class +DIALOG_EXTEND_WITH_SHIM( DIALOG_PCB_TEXT_PROPERTIES, DIALOG_PCB_TEXT_PROPERTIES_BASE ) +{ +public: + DIALOG_PCB_TEXT_PROPERTIES( PCB_EDIT_FRAME* parent, TEXTE_PCB* passedTextPCB, wxDC* DC ); + +private: + PCB_EDIT_FRAME* m_Parent; + wxDC* m_DC; + TEXTE_PCB* m_SelectedPCBText; + std::vector layerList; + + void MyInit(); + + // Handlers for DIALOG_PCB_TEXT_PROPERTIES_BASE events. + void OnClose( wxCloseEvent& event ); + void OnCancelClick( wxCommandEvent& event ); + void OnOkClick( wxCommandEvent& event ); +}; /** @@ -50,7 +78,7 @@ DIALOG_PCB_TEXT_PROPERTIES::DIALOG_PCB_TEXT_PROPERTIES( PCB_EDIT_FRAME* parent, TEXTE_PCB* passedTextPCB, wxDC* DC ) - : DIALOG_PCB_TEXT_PROPERTIES_BASE( parent ) + : DIALOG_PCB_TEXT_PROPERTIES_BASE_SHIM( parent ) { m_Parent = parent; m_DC = DC; @@ -78,8 +106,6 @@ void PCB_EDIT_FRAME::InstallTextPCBOptionsFrame( TEXTE_PCB* TextPCB, wxDC* DC ) void DIALOG_PCB_TEXT_PROPERTIES::MyInit() { - SetFocus(); - // Put units symbols to text labels where appropriate AddUnitSymbol( *m_SizeXLabel ); AddUnitSymbol( *m_SizeYLabel ); diff --git a/pcbnew/dialogs/dialog_pcb_text_properties.h b/pcbnew/dialogs/dialog_pcb_text_properties.h deleted file mode 100644 index 236454ca92..0000000000 --- a/pcbnew/dialogs/dialog_pcb_text_properties.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef DIALOG_PCB_TEXT_PROPERTIES_H -#define DIALOG_PCB_TEXT_PROPERTIES_H - -#include -#include -#include - -class PCB_EDIT_FRAME; -class TEXTE_PCB; - -/** Implementing DIALOG_PCB_TEXT_PROPERTIES_BASE */ -class DIALOG_PCB_TEXT_PROPERTIES : public DIALOG_PCB_TEXT_PROPERTIES_BASE -{ -private: - PCB_EDIT_FRAME* m_Parent; - wxDC* m_DC; - TEXTE_PCB* m_SelectedPCBText; - std::vector layerList; - - void MyInit(); - -protected: - // Handlers for DIALOG_PCB_TEXT_PROPERTIES_BASE events. - void OnClose( wxCloseEvent& event ); - void OnCancelClick( wxCommandEvent& event ); - void OnOkClick( wxCommandEvent& event ); - -public: - DIALOG_PCB_TEXT_PROPERTIES( PCB_EDIT_FRAME* parent, TEXTE_PCB* passedTextPCB, wxDC* DC ); -}; - -#endif // DIALOG_PCB_TEXT_PROPERTIES_H