Commit df494fc8 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

start toying with DIALOG_SHIM

parent 87aa22f1
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -38,7 +38,30 @@
#include <confirm.h>
#include <sch_text.h>

#include <dialog_edit_label.h>
#include <dialog_edit_label_base.h>
#include <dialog_helpers.h>

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;
+0 −41
Original line number Diff line number Diff line
/////////////////////////////////////////////////////////////////////////////
// Name:        dialog_edit_label.h
// Author:      jean-pierre Charras
// Modified by:
// Licence: GPL
/////////////////////////////////////////////////////////////////////////////

#ifndef _DIALOG_EDIT_LABEL_H_
#define _DIALOG_EDIT_LABEL_H_

#include <dialog_edit_label_base.h>


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_
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@
#include <boost/foreach.hpp>



/* Library editor wxConfig entry names. */
const wxString lastLibExportPathEntry( wxT( "LastLibraryExportPath" ) );
const wxString lastLibImportPathEntry( wxT( "LastLibraryImportPath" ) );
+70 −3
Original line number Diff line number Diff line
@@ -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 <common.h>             // 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:
 * <ul>
 * <li>class specific: static s_LastPos and static s_LastSize for retentative
 *     dialog window positioning, per class.
 * <li> invocation of SetFocus() to allow ESC key to work on Linux.
 * <li> future others...
 * </ul>
 * 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 T>
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<class T>
wxPoint DIALOG_SHIM<T>::s_LastPos( -1, -1 );

template<class T>
wxSize DIALOG_SHIM<T>::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>  BASE##_SHIM; \
 class DERRIVED : public BASE##_SHIM

#endif    // DIALOG_HELPERS_H_
+4 −3
Original line number Diff line number Diff line
@@ -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:
 * <p>
 * result is:  lower <= value <= upper
 */
@@ -60,7 +61,7 @@ template <typename T> 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;
}
Loading