Commit 31a84b84 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

Add include/dialog_shim.h and common/dialog_shim.cpp for use by...

Add include/dialog_shim.h and common/dialog_shim.cpp for use by wxformbuilder's "subclass a wxDialog" support.
This works, but in my version of wxformbuilder there is a bug which does not properly show the 
subclass property, even though it is still in play.  This happens after saving then loading the *.fbp file.
So it is a nuisance bug, but does not affect functionality.
parent fda20d28
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ set(COMMON_SRCS
    confirm.cpp
    confirm.cpp
    copy_to_clipboard.cpp
    copy_to_clipboard.cpp
    dcsvg.cpp
    dcsvg.cpp
    dialog_shim.cpp
    displlst.cpp
    displlst.cpp
    dlist.cpp
    dlist.cpp
    drawframe.cpp
    drawframe.cpp

common/dialog_shim.cpp

0 → 100644
+90 −0
Original line number Original line Diff line number Diff line

/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include <dialog_shim.h>


DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
        const wxPoint& pos, const wxSize& size, long style, const wxString& name ) :
    wxDialog( aParent, id, title, pos, size, style, name )
{
    // linux wxGTK needed this at one time to allow the ESCAPE key to close a wxDialog window.
    SetFocus();
}


// our hashtable is an implementation secret, don't need or want it in a header file
#include <hashtables.h>
#include <base_struct.h>        // EDA_RECT
#include <typeinfo>


/// hashtable with key: C string and value: EDA_RECT.
/// The key is the classname of the derived wxformbuilder dialog
WX_DECLARE_HASH_MAP( char*, EDA_RECT, wxStringHash, wxStringEqual, RECT_MAP );
static RECT_MAP class_map;

bool DIALOG_SHIM::Show( bool show )
{
    bool        ret;
    const char* classname = typeid(*this).name();

    // Show or hide the window.  If hiding, save current position and size.
    // If showing, use previous position and size.
    if( 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 ];

        if( r.GetSize().x != 0 && r.GetSize().y != 0 )
            SetSize( r.GetPosition().x, r.GetPosition().y, r.GetSize().x, r.GetSize().y, 0 );
    }
    else
    {
        // Save the dialog's position & size before hiding, using classname as key
        EDA_RECT  r( wxDialog::GetPosition(), wxDialog::GetSize() );
        class_map[ classname ] = r;

        ret = wxDialog::Show( show );
    }
    return ret;
}

/*
const wxSize& DIALOG_SHIM::GetLastSize()
{
    const char* classname = typeid(*this).name();
    return class_map[ classname ].GetSize();
}


const wxPoint& DIALOG_SHIM::GetLastPosition()
{
    const char* classname = typeid(*this).name();
    return class_map[ classname ].GetPosition();
}
*/
+2 −30
Original line number Original line Diff line number Diff line
@@ -7,11 +7,6 @@


#include <dialog_lib_edit_pin.h>
#include <dialog_lib_edit_pin.h>


// dialog should remember its previous screen position and size
// Not also if the defaut size is > s_LastSize, default size is used
wxPoint DIALOG_LIB_EDIT_PIN::s_LastPos( -1, -1 );
wxSize  DIALOG_LIB_EDIT_PIN::s_LastSize;

DIALOG_LIB_EDIT_PIN::DIALOG_LIB_EDIT_PIN( wxWindow* parent, LIB_PIN* aPin ) :
DIALOG_LIB_EDIT_PIN::DIALOG_LIB_EDIT_PIN( wxWindow* parent, LIB_PIN* aPin ) :
    DIALOG_LIB_EDIT_PIN_BASE( parent )
    DIALOG_LIB_EDIT_PIN_BASE( parent )
{
{
@@ -25,31 +20,17 @@ DIALOG_LIB_EDIT_PIN::DIALOG_LIB_EDIT_PIN( wxWindow* parent, LIB_PIN* aPin ) :


    m_panelShowPin->SetBackgroundColour( MakeColour( g_DrawBgColor ) );
    m_panelShowPin->SetBackgroundColour( MakeColour( g_DrawBgColor ) );


    /* Required to make escape key work correctly in wxGTK. */
    SetFocus();
    // Set tab order
    // Set tab order
    m_textPadName->MoveAfterInTabOrder(m_textPinName);
    m_textPadName->MoveAfterInTabOrder(m_textPinName);
    m_sdbSizerButtonsOK->SetDefault();
    m_sdbSizerButtonsOK->SetDefault();
}
}



DIALOG_LIB_EDIT_PIN::~DIALOG_LIB_EDIT_PIN()
DIALOG_LIB_EDIT_PIN::~DIALOG_LIB_EDIT_PIN()
{
{
    delete m_dummyPin;
    delete m_dummyPin;
}
}


void DIALOG_LIB_EDIT_PIN::SetLastSizeAndPosition()
{
    if( s_LastPos.x != -1 )
    {
        wxSize defaultSize = GetSize();
        if(  s_LastSize.x < defaultSize.x )
            s_LastSize.x = defaultSize.x;
        SetSize( s_LastSize );
        SetPosition( s_LastPos );
    }
    else
        Center();
}


/*
/*
 * Draw (on m_panelShowPin) the pin currently edited
 * Draw (on m_panelShowPin) the pin currently edited
@@ -92,25 +73,16 @@ void DIALOG_LIB_EDIT_PIN::OnPaintShowPanel( wxPaintEvent& event )


void DIALOG_LIB_EDIT_PIN::OnCloseDialog( wxCloseEvent& event )
void DIALOG_LIB_EDIT_PIN::OnCloseDialog( wxCloseEvent& event )
{
{
    // Save the dialog's position
    s_LastPos  = GetPosition();
    s_LastSize = GetSize();
    EndModal( wxID_CANCEL );
    EndModal( wxID_CANCEL );
}
}


void DIALOG_LIB_EDIT_PIN::OnCancelButtonClick( wxCommandEvent& event )
void DIALOG_LIB_EDIT_PIN::OnCancelButtonClick( wxCommandEvent& event )
{
{
    // Save the dialog's position
    s_LastPos  = GetPosition();
    s_LastSize = GetSize();
    EndModal( wxID_CANCEL );
    EndModal( wxID_CANCEL );
}
}


void DIALOG_LIB_EDIT_PIN::OnOKButtonClick( wxCommandEvent& event )
void DIALOG_LIB_EDIT_PIN::OnOKButtonClick( wxCommandEvent& event )
{
{
    // Save the dialog's position
    s_LastPos  = GetPosition();
    s_LastSize = GetSize();
    EndModal( wxID_OK );
    EndModal( wxID_OK );
}
}


+0 −4
Original line number Original line Diff line number Diff line
@@ -13,9 +13,6 @@
/** Implementing DIALOG_LIB_EDIT_PIN_BASE */
/** Implementing DIALOG_LIB_EDIT_PIN_BASE */
class DIALOG_LIB_EDIT_PIN : public DIALOG_LIB_EDIT_PIN_BASE
class DIALOG_LIB_EDIT_PIN : public DIALOG_LIB_EDIT_PIN_BASE
{
{
    static wxSize	s_LastSize;		        ///< last position and size
    static wxPoint	s_LastPos;

    LIB_PIN * m_dummyPin;       // a working copy used to show changes
    LIB_PIN * m_dummyPin;       // a working copy used to show changes


public:
public:
@@ -23,7 +20,6 @@ public:
    DIALOG_LIB_EDIT_PIN( wxWindow* parent, LIB_PIN* aPin );
    DIALOG_LIB_EDIT_PIN( wxWindow* parent, LIB_PIN* aPin );
    ~DIALOG_LIB_EDIT_PIN();
    ~DIALOG_LIB_EDIT_PIN();


    void SetLastSizeAndPosition();
    void OnCloseDialog( wxCloseEvent& event );
    void OnCloseDialog( wxCloseEvent& event );
    void OnCancelButtonClick( wxCommandEvent& event );
    void OnCancelButtonClick( wxCommandEvent& event );
    void OnOKButtonClick( wxCommandEvent& event );
    void OnOKButtonClick( wxCommandEvent& event );
+216 −207
Original line number Original line Diff line number Diff line
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 30 2011)
// C++ code generated with wxFormBuilder (version Mar 19 2012)
// http://www.wxformbuilder.org/
// http://www.wxformbuilder.org/
//
//
// PLEASE DO "NOT" EDIT THIS FILE!
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////


#include "wx/bmpcbox.h"

#include "dialog_lib_edit_pin_base.h"
#include "dialog_lib_edit_pin_base.h"


///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////


DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	
@@ -34,7 +32,7 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
	m_staticTextPinName->Wrap( -1 );
	m_staticTextPinName->Wrap( -1 );
	fgSizerPins->Add( m_staticTextPinName, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
	fgSizerPins->Add( m_staticTextPinName, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
	
	
	m_textPinName = new wxTextCtrl( this, ID_M_TEXTPINNAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_textPinName = new wxTextCtrl( this, ID_M_TEXTPINNAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB );
	fgSizerPins->Add( m_textPinName, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP|wxBOTTOM, 3 );
	fgSizerPins->Add( m_textPinName, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP|wxBOTTOM, 3 );
	
	
	m_staticTextPadName = new wxStaticText( this, ID_M_STATICTEXTPADNAME, _("Pin n&umber:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticTextPadName = new wxStaticText( this, ID_M_STATICTEXTPADNAME, _("Pin n&umber:"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -43,7 +41,7 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
	
	
	fgSizerPins->Add( m_staticTextPadName, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
	fgSizerPins->Add( m_staticTextPadName, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
	
	
	m_textPadName = new wxTextCtrl( this, ID_M_TEXTPADNAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_textPadName = new wxTextCtrl( this, ID_M_TEXTPADNAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB );
	fgSizerPins->Add( m_textPadName, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP|wxBOTTOM, 3 );
	fgSizerPins->Add( m_textPadName, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP|wxBOTTOM, 3 );
	
	
	m_staticTextOrient = new wxStaticText( this, wxID_ANY, _("&Orientation:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticTextOrient = new wxStaticText( this, wxID_ANY, _("&Orientation:"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -69,6 +67,7 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
	m_choiceStyle = new wxBitmapComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); 
	m_choiceStyle = new wxBitmapComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); 
	fgSizerPins->Add( m_choiceStyle, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 );
	fgSizerPins->Add( m_choiceStyle, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 );
	
	
	
	bLeftSizer->Add( fgSizerPins, 0, wxALL|wxEXPAND, 5 );
	bLeftSizer->Add( fgSizerPins, 0, wxALL|wxEXPAND, 5 );
	
	
	wxBoxSizer* boarderSizer;
	wxBoxSizer* boarderSizer;
@@ -83,6 +82,7 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
	m_checkApplyToAllConversions = new wxCheckBox( this, wxID_ANY, _("Shared by all body &styles (DeMorgan)"), wxDefaultPosition, wxDefaultSize, 0 );
	m_checkApplyToAllConversions = new wxCheckBox( this, wxID_ANY, _("Shared by all body &styles (DeMorgan)"), wxDefaultPosition, wxDefaultSize, 0 );
	sbSizerPinSharing->Add( m_checkApplyToAllConversions, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
	sbSizerPinSharing->Add( m_checkApplyToAllConversions, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
	
	
	
	boarderSizer->Add( sbSizerPinSharing, 0, wxEXPAND|wxALL, 5 );
	boarderSizer->Add( sbSizerPinSharing, 0, wxEXPAND|wxALL, 5 );
	
	
	wxStaticBoxSizer* sbSizerSchematicProperties;
	wxStaticBoxSizer* sbSizerSchematicProperties;
@@ -92,10 +92,13 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
	m_checkShow->SetValue(true); 
	m_checkShow->SetValue(true); 
	sbSizerSchematicProperties->Add( m_checkShow, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
	sbSizerSchematicProperties->Add( m_checkShow, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
	
	
	
	boarderSizer->Add( sbSizerSchematicProperties, 0, wxEXPAND|wxALL, 5 );
	boarderSizer->Add( sbSizerSchematicProperties, 0, wxEXPAND|wxALL, 5 );
	
	
	
	bLeftSizer->Add( boarderSizer, 0, wxEXPAND|wxTOP|wxBOTTOM, 12 );
	bLeftSizer->Add( boarderSizer, 0, wxEXPAND|wxTOP|wxBOTTOM, 12 );
	
	
	
	bUpperSizer->Add( bLeftSizer, 1, wxEXPAND, 5 );
	bUpperSizer->Add( bLeftSizer, 1, wxEXPAND, 5 );
	
	
	wxBoxSizer* bRightSizer;
	wxBoxSizer* bRightSizer;
@@ -140,6 +143,7 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
	m_staticLengthUnits->Wrap( -1 );
	m_staticLengthUnits->Wrap( -1 );
	fgSizerTextsSizes->Add( m_staticLengthUnits, 0, wxALL, 5 );
	fgSizerTextsSizes->Add( m_staticLengthUnits, 0, wxALL, 5 );
	
	
	
	bRightSizer->Add( fgSizerTextsSizes, 0, wxALL|wxEXPAND, 5 );
	bRightSizer->Add( fgSizerTextsSizes, 0, wxALL|wxEXPAND, 5 );
	
	
	m_panelShowPin = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
	m_panelShowPin = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
@@ -147,8 +151,10 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
	
	
	bRightSizer->Add( m_panelShowPin, 1, wxEXPAND | wxALL, 5 );
	bRightSizer->Add( m_panelShowPin, 1, wxEXPAND | wxALL, 5 );
	
	
	
	bUpperSizer->Add( bRightSizer, 1, wxEXPAND|wxRIGHT, 5 );
	bUpperSizer->Add( bRightSizer, 1, wxEXPAND|wxRIGHT, 5 );
	
	
	
	mainSizer->Add( bUpperSizer, 1, wxEXPAND, 5 );
	mainSizer->Add( bUpperSizer, 1, wxEXPAND, 5 );
	
	
	m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
	m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
@@ -160,10 +166,13 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
	m_sdbSizerButtonsCancel = new wxButton( this, wxID_CANCEL );
	m_sdbSizerButtonsCancel = new wxButton( this, wxID_CANCEL );
	m_sdbSizerButtons->AddButton( m_sdbSizerButtonsCancel );
	m_sdbSizerButtons->AddButton( m_sdbSizerButtonsCancel );
	m_sdbSizerButtons->Realize();
	m_sdbSizerButtons->Realize();
	
	mainSizer->Add( m_sdbSizerButtons, 0, wxALL|wxALIGN_RIGHT, 5 );
	mainSizer->Add( m_sdbSizerButtons, 0, wxALL|wxALIGN_RIGHT, 5 );
	
	
	
	this->SetSizer( mainSizer );
	this->SetSizer( mainSizer );
	this->Layout();
	this->Layout();
	mainSizer->Fit( this );
	
	
	this->Centre( wxBOTH );
	this->Centre( wxBOTH );
	
	
Loading