From 0c17d223327cdd158c7c52a1da3406fd49eca472 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 9 Jun 2015 18:42:41 +0200 Subject: [PATCH] Refactor eeschema dialog_color_config.xx, using wxFormBuilder to create the base dialog --- eeschema/CMakeLists.txt | 3 +- eeschema/dialogs/dialog_color_config.cpp | 128 +++-------- eeschema/dialogs/dialog_color_config.h | 24 +- eeschema/dialogs/dialog_color_config_base.cpp | 55 +++++ eeschema/dialogs/dialog_color_config_base.fbp | 217 ++++++++++++++++++ eeschema/dialogs/dialog_color_config_base.h | 57 +++++ 6 files changed, 363 insertions(+), 121 deletions(-) create mode 100644 eeschema/dialogs/dialog_color_config_base.cpp create mode 100644 eeschema/dialogs/dialog_color_config_base.fbp create mode 100644 eeschema/dialogs/dialog_color_config_base.h diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index ca2c69e45c..0982735632 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -20,12 +20,13 @@ include_directories( set( EESCHEMA_DLGS - dialogs/dialog_color_config.cpp dialogs/dialog_annotate.cpp dialogs/dialog_annotate_base.cpp dialogs/dialog_bom.cpp dialogs/dialog_bom_base.cpp dialogs/dialog_bom_cfg_keywords.cpp + dialogs/dialog_color_config.cpp + dialogs/dialog_color_config_base.cpp dialogs/dialog_choose_component.cpp dialogs/dialog_choose_component_base.cpp dialogs/dialog_lib_edit_text.cpp diff --git a/eeschema/dialogs/dialog_color_config.cpp b/eeschema/dialogs/dialog_color_config.cpp index 94bf021a51..833747d000 100644 --- a/eeschema/dialogs/dialog_color_config.cpp +++ b/eeschema/dialogs/dialog_color_config.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2015 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 @@ -111,59 +111,31 @@ static EDA_COLOR_T currentColors[ LAYERSCH_ID_COUNT ]; DIALOG_COLOR_CONFIG::DIALOG_COLOR_CONFIG( EDA_DRAW_FRAME* aParent ) : - DIALOG_SHIM( aParent, wxID_ANY, _( "EESchema Colors" ), - wxDefaultPosition, wxDefaultSize, - wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ) + DIALOG_COLOR_CONFIG_BASE( aParent ) { m_parent = aParent; - SetExtraStyle( wxWS_EX_BLOCK_EVENTS ); - Init(); CreateControls(); GetSizer()->SetSizeHints( this ); } -DIALOG_COLOR_CONFIG::~DIALOG_COLOR_CONFIG() -{ -} - - -void DIALOG_COLOR_CONFIG::Init() -{ - m_outerBoxSizer = NULL; - m_mainBoxSizer = NULL; - m_columnBoxSizer = NULL; - m_rowBoxSizer = NULL; - m_bitmapButton = NULL; - m_SelBgColor = NULL; - m_line = NULL; - m_stdDialogButtonSizer = NULL; -} - - void DIALOG_COLOR_CONFIG::CreateControls() { - wxButton* button; wxStaticText* label; int buttonId = 1800; BUTTONINDEX* groups = buttonGroups; - - m_outerBoxSizer = new wxBoxSizer( wxVERTICAL ); - SetSizer( m_outerBoxSizer ); - - m_mainBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - m_outerBoxSizer->Add( m_mainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT, 5 ); + wxBoxSizer* columnBoxSizer = NULL; while( groups->m_Buttons != NULL ) { COLORBUTTON* buttons = groups->m_Buttons; - m_columnBoxSizer = new wxBoxSizer( wxVERTICAL ); - m_mainBoxSizer->Add( m_columnBoxSizer, 1, wxALIGN_TOP | wxLEFT | wxTOP, 5 ); - m_rowBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - m_columnBoxSizer->Add( m_rowBoxSizer, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); + columnBoxSizer = new wxBoxSizer( wxVERTICAL ); + m_mainBoxSizer->Add( columnBoxSizer, 1, wxALIGN_TOP | wxLEFT | wxTOP, 5 ); + wxBoxSizer* rowBoxSizer = new wxBoxSizer( wxHORIZONTAL ); + columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); // Add a text string to identify the column of color select buttons. label = new wxStaticText( this, wxID_ANY, groups->m_Name ); @@ -173,12 +145,12 @@ void DIALOG_COLOR_CONFIG::CreateControls() font.SetWeight( wxFONTWEIGHT_BOLD ); label->SetFont( font ); - m_rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); while( buttons->m_Layer >= 0 ) { - m_rowBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - m_columnBoxSizer->Add( m_rowBoxSizer, 0, wxGROW | wxALL, 0 ); + rowBoxSizer = new wxBoxSizer( wxHORIZONTAL ); + columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxALL, 0 ); wxMemoryDC iconDC; wxBitmap bitmap( BUTT_SIZE_X, BUTT_SIZE_Y ); @@ -192,24 +164,19 @@ void DIALOG_COLOR_CONFIG::CreateControls() wxBrush brush; ColorSetBrush( &brush, color ); - -#if wxCHECK_VERSION( 3, 0, 0 ) brush.SetStyle( wxBRUSHSTYLE_SOLID ); -#else - brush.SetStyle( wxSOLID ); -#endif - iconDC.SetBrush( brush ); iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y ); - m_bitmapButton = new wxBitmapButton( this, buttonId, bitmap, wxDefaultPosition, - wxSize( BUTT_SIZE_X+8, BUTT_SIZE_Y+6 ) ); - m_bitmapButton->SetClientData( (void*) buttons ); + wxBitmapButton* bitmapButton = new wxBitmapButton( + this, buttonId, bitmap, wxDefaultPosition, + wxSize( BUTT_SIZE_X+8, BUTT_SIZE_Y+6 ) ); + bitmapButton->SetClientData( (void*) buttons ); - m_rowBoxSizer->Add( m_bitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 ); + rowBoxSizer->Add( bitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 ); label = new wxStaticText( this, wxID_ANY, wxGetTranslation( buttons->m_Name ) ); - m_rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 ); + rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 ); buttonId += 1; buttons++; } @@ -220,53 +187,24 @@ void DIALOG_COLOR_CONFIG::CreateControls() Connect( 1800, buttonId - 1, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_CONFIG::SetColor ) ); - // Add a spacer to improve appearance. - m_columnBoxSizer->AddSpacer( 5 ); - - wxArrayString m_SelBgColorStrings; - m_SelBgColorStrings.Add( _( "White" ) ); - m_SelBgColorStrings.Add( _( "Black" ) ); + wxArrayString selBgColorStrings; + selBgColorStrings.Add( _( "White" ) ); + selBgColorStrings.Add( _( "Black" ) ); m_SelBgColor = new wxRadioBox( this, wxID_ANY, _( "Background Color" ), wxDefaultPosition, wxDefaultSize, - m_SelBgColorStrings, 1, wxRA_SPECIFY_COLS ); + selBgColorStrings, 1, wxRA_SPECIFY_COLS ); m_SelBgColor->SetSelection( ( m_parent->GetDrawBgColor() == BLACK ) ? 1 : 0 ); - m_columnBoxSizer->Add( m_SelBgColor, 1, wxGROW | wxRIGHT | wxTOP | wxBOTTOM, 5 ); + + if( columnBoxSizer ) + { + // Add a spacer to improve appearance. + columnBoxSizer->AddSpacer( 5 ); + columnBoxSizer->Add( m_SelBgColor, 1, wxGROW | wxRIGHT | wxTOP | wxBOTTOM, 5 ); + } currentColors[ LAYER_BACKGROUND ] = m_parent->GetDrawBgColor(); - - // Provide a line to separate all of the controls added so far from the - // "OK", "Cancel", and "Apply" buttons (which will be added after that - // line). - m_line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - m_outerBoxSizer->Add( m_line, 0, wxGROW | wxALL, 5 ); - - // Provide a StdDialogButtonSizer to accommodate the OK, Cancel, and Apply - // buttons; using that type of sizer results in those buttons being - // automatically located in positions appropriate for each (OS) version of - // KiCad. - m_stdDialogButtonSizer = new wxStdDialogButtonSizer; - m_outerBoxSizer->Add( m_stdDialogButtonSizer, 0, wxGROW | wxALL, 10 ); - - button = new wxButton( this, wxID_OK, _( "OK" ), wxDefaultPosition, wxDefaultSize, 0 ); - m_stdDialogButtonSizer->AddButton( button ); - - button = new wxButton( this, wxID_CANCEL, _( "Cancel" ), wxDefaultPosition, wxDefaultSize, 0 ); - m_stdDialogButtonSizer->AddButton( button ); - - button->SetFocus(); - - button = new wxButton( this, wxID_APPLY, _( "Apply" ), wxDefaultPosition, wxDefaultSize, 0 ); - m_stdDialogButtonSizer->AddButton( button ); - - Connect( wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_COLOR_CONFIG::OnOkClick ) ); - Connect( wxID_CANCEL, wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_COLOR_CONFIG::OnCancelClick ) ); - Connect( wxID_APPLY, wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_COLOR_CONFIG::OnApplyClick ) ); - - m_stdDialogButtonSizer->Realize(); +// button->SetFocus(); // Dialog now needs to be resized, but the associated command is found elsewhere. } @@ -299,11 +237,7 @@ void DIALOG_COLOR_CONFIG::SetColor( wxCommandEvent& event ) ColorSetBrush( &brush, color); -#if wxCHECK_VERSION( 3, 0, 0 ) brush.SetStyle( wxBRUSHSTYLE_SOLID ); -#else - brush.SetStyle( wxSOLID ); -#endif iconDC.SetBrush( brush ); iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y ); @@ -356,14 +290,10 @@ void DIALOG_COLOR_CONFIG::OnOkClick( wxCommandEvent& event ) m_parent->GetCanvas()->Refresh(); - EndModal( 1 ); + event.Skip(); } -void DIALOG_COLOR_CONFIG::OnCancelClick( wxCommandEvent& event ) -{ - EndModal( -1 ); -} void DIALOG_COLOR_CONFIG::OnApplyClick( wxCommandEvent& event ) diff --git a/eeschema/dialogs/dialog_color_config.h b/eeschema/dialogs/dialog_color_config.h index 0299c073fc..60c296e4b7 100644 --- a/eeschema/dialogs/dialog_color_config.h +++ b/eeschema/dialogs/dialog_color_config.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007 G. Harland - * Copyright (C) 1992-2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 1992-2015 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 @@ -25,8 +25,7 @@ #ifndef DIALOG_COLOR_CONFIG_H_ #define DIALOG_COLOR_CONFIG_H_ -#include -#include +#include class wxBoxSizer; @@ -38,40 +37,23 @@ class wxStdDialogButtonSizer; /* Derived class for the frame color settings. */ /***********************************************/ -class DIALOG_COLOR_CONFIG : public DIALOG_SHIM +class DIALOG_COLOR_CONFIG : public DIALOG_COLOR_CONFIG_BASE { private: EDA_DRAW_FRAME* m_parent; - wxBoxSizer* m_outerBoxSizer; - wxBoxSizer* m_mainBoxSizer; - wxBoxSizer* m_columnBoxSizer; - wxBoxSizer* m_rowBoxSizer; - wxBitmapButton* m_bitmapButton; wxRadioBox* m_SelBgColor; - wxStaticLine* m_line; - wxStdDialogButtonSizer* m_stdDialogButtonSizer; - - // Initializes member variables - void Init(); // Creates the controls and sizers void CreateControls(); - wxBitmap GetBitmapResource( const wxString& aName ); - wxIcon GetIconResource( const wxString& aName ); - static bool ShowToolTips(); - bool UpdateColorsSettings(); void SetColor( wxCommandEvent& aEvent ); void OnOkClick( wxCommandEvent& aEvent ); - void OnCancelClick( wxCommandEvent& aEvent ); void OnApplyClick( wxCommandEvent& aEvent ); public: // Constructors and destructor - DIALOG_COLOR_CONFIG(); DIALOG_COLOR_CONFIG( EDA_DRAW_FRAME* aParent ); - ~DIALOG_COLOR_CONFIG(); }; #endif // DIALOG_COLOR_CONFIG_H_ diff --git a/eeschema/dialogs/dialog_color_config_base.cpp b/eeschema/dialogs/dialog_color_config_base.cpp new file mode 100644 index 0000000000..df41683750 --- /dev/null +++ b/eeschema/dialogs/dialog_color_config_base.cpp @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jun 5 2014) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_color_config_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_COLOR_CONFIG_BASE::DIALOG_COLOR_CONFIG_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 ); + + wxBoxSizer* bmainSizer; + bmainSizer = new wxBoxSizer( wxVERTICAL ); + + m_mainBoxSizer = new wxBoxSizer( wxHORIZONTAL ); + + + bmainSizer->Add( m_mainBoxSizer, 1, wxEXPAND, 5 ); + + m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + bmainSizer->Add( m_staticline, 0, wxEXPAND | wxALL, 5 ); + + m_sdbSizer = new wxStdDialogButtonSizer(); + m_sdbSizerOK = new wxButton( this, wxID_OK ); + m_sdbSizer->AddButton( m_sdbSizerOK ); + m_sdbSizerApply = new wxButton( this, wxID_APPLY ); + m_sdbSizer->AddButton( m_sdbSizerApply ); + m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer->AddButton( m_sdbSizerCancel ); + m_sdbSizer->Realize(); + + bmainSizer->Add( m_sdbSizer, 0, wxALIGN_RIGHT|wxALL, 5 ); + + + this->SetSizer( bmainSizer ); + this->Layout(); + + this->Centre( wxBOTH ); + + // Connect Events + m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_CONFIG_BASE::OnApplyClick ), NULL, this ); + m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_CONFIG_BASE::OnOkClick ), NULL, this ); +} + +DIALOG_COLOR_CONFIG_BASE::~DIALOG_COLOR_CONFIG_BASE() +{ + // Disconnect Events + m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_CONFIG_BASE::OnApplyClick ), NULL, this ); + m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_CONFIG_BASE::OnOkClick ), NULL, this ); + +} diff --git a/eeschema/dialogs/dialog_color_config_base.fbp b/eeschema/dialogs/dialog_color_config_base.fbp new file mode 100644 index 0000000000..e54c0a3dba --- /dev/null +++ b/eeschema/dialogs/dialog_color_config_base.fbp @@ -0,0 +1,217 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_color_config_base + 1000 + none + 1 + dialog_color_config_base + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_COLOR_CONFIG_BASE + + 446,344 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + EESchema Colors + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bmainSizer + wxVERTICAL + none + + 5 + wxEXPAND + 1 + + + m_mainBoxSizer + wxHORIZONTAL + protected + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_RIGHT|wxALL + 0 + + 1 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer + protected + OnApplyClick + + + + + OnOkClick + + + + + + + + diff --git a/eeschema/dialogs/dialog_color_config_base.h b/eeschema/dialogs/dialog_color_config_base.h new file mode 100644 index 0000000000..dcb5d3c85f --- /dev/null +++ b/eeschema/dialogs/dialog_color_config_base.h @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jun 5 2014) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_COLOR_CONFIG_BASE_H__ +#define __DIALOG_COLOR_CONFIG_BASE_H__ + +#include +#include +#include +class DIALOG_SHIM; + +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_COLOR_CONFIG_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_COLOR_CONFIG_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxBoxSizer* m_mainBoxSizer; + wxStaticLine* m_staticline; + wxStdDialogButtonSizer* m_sdbSizer; + wxButton* m_sdbSizerOK; + wxButton* m_sdbSizerApply; + wxButton* m_sdbSizerCancel; + + // Virtual event handlers, overide them in your derived class + virtual void OnApplyClick( wxCommandEvent& event ) { event.Skip(); } + virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } + + + public: + + DIALOG_COLOR_CONFIG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("EESchema Colors"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 446,344 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_COLOR_CONFIG_BASE(); + +}; + +#endif //__DIALOG_COLOR_CONFIG_BASE_H__