diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 2407bb60b3..08da96ed50 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -404,6 +404,9 @@ set( COMMON_DLG_SRCS dialogs/panel_plugin_settings.cpp dialogs/panel_plugin_settings_base.cpp dialogs/panel_setup_netclasses.cpp + dialogs/panel_printer_list.cpp + dialogs/panel_printer_list_base.cpp + dialogs/panel_setup_netclasses_base.cpp dialogs/panel_setup_severities.cpp dialogs/panel_text_variables.cpp diff --git a/common/dialogs/dialog_print_generic.cpp b/common/dialogs/dialog_print_generic.cpp index 07cb214ae9..94a1dcd74a 100644 --- a/common/dialogs/dialog_print_generic.cpp +++ b/common/dialogs/dialog_print_generic.cpp @@ -27,6 +27,8 @@ #include #include +#include + // Define min and max reasonable values for print scale static constexpr double MIN_SCALE = 0.01; static constexpr double MAX_SCALE = 100.0; @@ -93,6 +95,9 @@ DIALOG_PRINT_GENERIC::DIALOG_PRINT_GENERIC( EDA_DRAW_FRAME* aParent, PRINTOUT_SE m_scaleValidator.SetRange( 0.0, MAX_SCALE ); m_scaleCustomText->SetValidator( m_scaleValidator ); + // Show m_panelPrinters only if there are printers to list: + m_panelPrinters->Show( m_panelPrinters->AsPrintersAvailable() ); + SetupStandardButtons( { { wxID_OK, _( "Print" ) }, { wxID_APPLY, _( "Print Preview" ) }, { wxID_CANCEL, _( "Close" ) } } ); @@ -245,6 +250,13 @@ void DIALOG_PRINT_GENERIC::onPrintPreview( wxCommandEvent& event ) return; } + wxString selectedPrinterName; + + if( m_panelPrinters ) + selectedPrinterName = m_panelPrinters->GetSelectedPrinterName(); + + s_PrintData->SetPrinterName( selectedPrinterName ); + // Pass two printout objects: for preview, and possible printing. wxString title = _( "Print Preview" ); wxPrintPreview* preview = @@ -296,6 +308,13 @@ void DIALOG_PRINT_GENERIC::onPrintButtonClick( wxCommandEvent& event ) return; } + wxString selectedPrinterName; + + if( m_panelPrinters ) + selectedPrinterName = m_panelPrinters->GetSelectedPrinterName(); + + s_PrintData->SetPrinterName( selectedPrinterName ); + wxPrintDialogData printDialogData( *s_PrintData ); printDialogData.SetMaxPage( m_settings->m_pageCount ); diff --git a/common/dialogs/dialog_print_generic_base.cpp b/common/dialogs/dialog_print_generic_base.cpp index 903730f44f..0d7f66a7b9 100644 --- a/common/dialogs/dialog_print_generic_base.cpp +++ b/common/dialogs/dialog_print_generic_base.cpp @@ -5,6 +5,8 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// +#include "dialogs/panel_printer_list.h" + #include "dialog_print_generic_base.h" /////////////////////////////////////////////////////////////////////////// @@ -16,6 +18,15 @@ DIALOG_PRINT_GENERIC_BASE::DIALOG_PRINT_GENERIC_BASE( wxWindow* parent, wxWindow wxBoxSizer* bMainSizer; bMainSizer = new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* bSizerPanelPrinters; + bSizerPanelPrinters = new wxBoxSizer( wxVERTICAL ); + + m_panelPrinters = new PANEL_PRINTER_LIST( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + bSizerPanelPrinters->Add( m_panelPrinters, 1, wxEXPAND | wxALL, 5 ); + + + bMainSizer->Add( bSizerPanelPrinters, 0, wxEXPAND, 5 ); + m_bUpperSizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* bRightCol; diff --git a/common/dialogs/dialog_print_generic_base.fbp b/common/dialogs/dialog_print_generic_base.fbp index d400fe51ac..644bce3f0a 100644 --- a/common/dialogs/dialog_print_generic_base.fbp +++ b/common/dialogs/dialog_print_generic_base.fbp @@ -65,6 +65,75 @@ bMainSizer wxVERTICAL none + + 5 + wxEXPAND + 0 + + + bSizerPanelPrinters + wxVERTICAL + none + + 5 + wxEXPAND | wxALL + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_panelPrinters + 1 + + + protected + 1 + + Resizable + 1 + + PANEL_PRINTER_LIST; dialogs/panel_printer_list.h; forward_declare + 0 + + + + wxTAB_TRAVERSAL + + + + 5 wxEXPAND|wxALL diff --git a/common/dialogs/dialog_print_generic_base.h b/common/dialogs/dialog_print_generic_base.h index 829165e4b2..15facc095d 100644 --- a/common/dialogs/dialog_print_generic_base.h +++ b/common/dialogs/dialog_print_generic_base.h @@ -10,17 +10,20 @@ #include #include #include +class PANEL_PRINTER_LIST; + #include "dialog_shim.h" -#include -#include +#include #include #include #include #include +#include +#include +#include #include #include #include -#include #include #include #include @@ -46,6 +49,7 @@ class DIALOG_PRINT_GENERIC_BASE : public DIALOG_SHIM wxID_PRINT_OPTIONS, }; + PANEL_PRINTER_LIST* m_panelPrinters; wxBoxSizer* m_bUpperSizer; wxStaticBoxSizer* m_sbOptionsSizer; wxGridBagSizer* m_gbOptionsSizer; diff --git a/common/dialogs/panel_printer_list.cpp b/common/dialogs/panel_printer_list.cpp new file mode 100644 index 0000000000..5c4f6d3408 --- /dev/null +++ b/common/dialogs/panel_printer_list.cpp @@ -0,0 +1,194 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) KiCad Developers, see AUTHORS.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 3 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, see . + */ + +#include + +// Define CUPS_LIST_PRINTERS to allow printer selection in PANEL_PRINTER_LIST +// on Unices. It needs cups and cups dev files +// Currently not tested and not finished for cups, so disable it +// However the code (from wxWidgets forum) is kept here, just in case +//#define CUPS_LIST_PRINTERS + +#ifdef __WXMSW__ + #include +#elif defined( CUPS_LIST_PRINTERS ) + #include +#endif + +// GetPrinterList code comes from samples on: +// https://forums.wxwidgets.org/viewtopic.php?t=13251 +// https://forums.wxwidgets.org/viewtopic.php?t=43930 +static bool GetPrinterList(wxArrayString &aPrinterList, wxString &aDefaultPrinterName) +{ + aPrinterList.Empty(); + aDefaultPrinterName.Empty(); + +#ifdef __WXMSW__ + DWORD dwSize, dwPrinters; + BYTE *pBuffer; + + DWORD szz = 255; + WCHAR c[256]; + GetDefaultPrinter(&c[0], &szz); + aDefaultPrinterName = c; + + ::EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &dwSize, &dwPrinters); + + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER || dwSize == 0) + return false; + + pBuffer = new BYTE[dwSize]; + ::EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, pBuffer, dwSize, &dwSize, &dwPrinters); + + if (dwPrinters != 0) + { + PRINTER_INFO_5 *pPrnInfo = (PRINTER_INFO_5 *)pBuffer; + + for (UINT i = 0; i < dwPrinters; i++) + { + aPrinterList.Add(pPrnInfo->pPrinterName); + pPrnInfo++; + } + } + if (pBuffer) + { + delete[] pBuffer; + pBuffer = NULL; + } + + return true; +#elif defined( CUPS_LIST_PRINTERS ) + cups_dest_t* dests; + int num_dests = cupsGetDests(&dests); + + for (int i = 0; i < num_dests; i++) + { + wxString sz; + + if (dests[i].instance) + sz = wxString::Format("%s%s", dests[i].name, dests[i].instance); + else + sz = wxString::Format("%s", dests[i].name); + + if (dests[i].is_default) + aDefaultPrinterName = sz; + + aPrinterList.Add(sz); + } + + //free memory from cups data + cupsFreeDests(num_dests, dests); + + if(aPrinterList.GetCount()) + return true; + + return false; +#else + return false; +#endif +} + + +wxString PANEL_PRINTER_LIST::m_selectedPrinterName; + +PANEL_PRINTER_LIST::PANEL_PRINTER_LIST( wxWindow* aParent, wxWindowID id, + const wxPoint& pos, const wxSize& size, long style, + const wxString& name ): + PANEL_PRINTER_LIST_BASE( aParent, id, pos, size, style, name ) +{ + + GetPrinterList( m_printer_list, m_defaultPrinterName); + + if( m_printer_list.size() ) + { + m_choicePrinter->Append( m_printer_list ); + m_stPrinterState->SetLabel( wxEmptyString ); + + bool selected = false; + + if( !m_selectedPrinterName.IsEmpty() ) + { + for( size_t ii = 0; ii < m_printer_list.GetCount(); ii++ ) + { + if( m_selectedPrinterName == m_printer_list[ii] ) + { + m_choicePrinter->SetSelection( ii ); + selected = true; + break; + } + } + } + + if( !selected ) + { + for( size_t ii = 0; ii < m_printer_list.GetCount(); ii++ ) + { + if( m_defaultPrinterName == m_printer_list[ii] ) + { + m_choicePrinter->SetSelection( ii ); + m_selectedPrinterName = m_defaultPrinterName; + break; + } + } + } + + if( m_selectedPrinterName == m_defaultPrinterName ) + m_stPrinterState->SetLabel( _( "Default printer" ) ); + } +} + + +PANEL_PRINTER_LIST::~PANEL_PRINTER_LIST() +{ +} + + +bool PANEL_PRINTER_LIST::AsPrintersAvailable() +{ + return m_choicePrinter->GetCount() > 0; +} + + +void PANEL_PRINTER_LIST::onPrinterChoice( wxCommandEvent& event ) +{ + int select = m_choicePrinter->GetSelection(); + + if( m_choicePrinter->GetString( select ) == m_defaultPrinterName ) + m_stPrinterState->SetLabel( _( "Default printer" ) ); + else + m_stPrinterState->SetLabel( wxEmptyString ); + + m_selectedPrinterName = m_choicePrinter->GetString( select ); +} + + +wxString PANEL_PRINTER_LIST::GetSelectedPrinterName() +{ + if( AsPrintersAvailable() ) + { + int select = m_choicePrinter->GetSelection(); + m_selectedPrinterName = m_choicePrinter->GetString( select ); + } + else + m_selectedPrinterName.Empty(); + + return m_selectedPrinterName; +} diff --git a/common/dialogs/panel_printer_list_base.cpp b/common/dialogs/panel_printer_list_base.cpp new file mode 100644 index 0000000000..9126815a62 --- /dev/null +++ b/common/dialogs/panel_printer_list_base.cpp @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-282-g1fa54006) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "panel_printer_list_base.h" + +/////////////////////////////////////////////////////////////////////////// + +PANEL_PRINTER_LIST_BASE::PANEL_PRINTER_LIST_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name ) +{ + wxBoxSizer* bSizerMain; + bSizerMain = new wxBoxSizer( wxVERTICAL ); + + m_sbSizerPrinters = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Printers") ), wxVERTICAL ); + + wxArrayString m_choicePrinterChoices; + m_choicePrinter = new wxChoice( m_sbSizerPrinters->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choicePrinterChoices, 0 ); + m_choicePrinter->SetSelection( 0 ); + m_sbSizerPrinters->Add( m_choicePrinter, 0, wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 5 ); + + wxBoxSizer* bSizerPrinterState; + bSizerPrinterState = new wxBoxSizer( wxHORIZONTAL ); + + m_staticTextPrn = new wxStaticText( m_sbSizerPrinters->GetStaticBox(), wxID_ANY, _("Info:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextPrn->Wrap( -1 ); + bSizerPrinterState->Add( m_staticTextPrn, 0, wxALL, 5 ); + + + bSizerPrinterState->Add( 0, 0, 0, wxRIGHT|wxLEFT, 5 ); + + m_stPrinterState = new wxStaticText( m_sbSizerPrinters->GetStaticBox(), wxID_ANY, _("dummy"), wxDefaultPosition, wxDefaultSize, 0 ); + m_stPrinterState->Wrap( -1 ); + bSizerPrinterState->Add( m_stPrinterState, 0, wxALL, 5 ); + + + m_sbSizerPrinters->Add( bSizerPrinterState, 0, wxEXPAND, 5 ); + + + bSizerMain->Add( m_sbSizerPrinters, 0, wxEXPAND, 5 ); + + + this->SetSizer( bSizerMain ); + this->Layout(); + + // Connect Events + m_choicePrinter->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_PRINTER_LIST_BASE::onPrinterChoice ), NULL, this ); +} + +PANEL_PRINTER_LIST_BASE::~PANEL_PRINTER_LIST_BASE() +{ + // Disconnect Events + m_choicePrinter->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_PRINTER_LIST_BASE::onPrinterChoice ), NULL, this ); + +} diff --git a/common/dialogs/panel_printer_list_base.fbp b/common/dialogs/panel_printer_list_base.fbp new file mode 100644 index 0000000000..1ac83e6d12 --- /dev/null +++ b/common/dialogs/panel_printer_list_base.fbp @@ -0,0 +1,289 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + panel_printer_list_base + 1000 + none + + + 1 + panel_printer_list + + . + + 1 + 1 + 1 + 1 + UI + 0 + 1 + 0 + + 0 + wxAUI_MGR_DEFAULT + + + 1 + 0 + 1 + impl_virtual + + + 0 + wxID_ANY + + + PANEL_PRINTER_LIST_BASE + + 378,136 + ; ; forward_declare + + 0 + + + wxTAB_TRAVERSAL + + + bSizerMain + wxVERTICAL + none + + 5 + wxEXPAND + 0 + + wxID_ANY + Printers + + m_sbSizerPrinters + wxVERTICAL + 1 + protected + + 5 + wxEXPAND|wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_choicePrinter + 1 + + + protected + 1 + + Resizable + 0 + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + onPrinterChoice + + + + 5 + wxEXPAND + 0 + + + bSizerPrinterState + wxHORIZONTAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + Info: + 0 + + 0 + + + 0 + + 1 + m_staticTextPrn + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxRIGHT|wxLEFT + 0 + + 0 + protected + 0 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + dummy + 0 + + 0 + + + 0 + + 1 + m_stPrinterState + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + + + + + + + diff --git a/common/dialogs/panel_printer_list_base.h b/common/dialogs/panel_printer_list_base.h new file mode 100644 index 0000000000..f1c6700c03 --- /dev/null +++ b/common/dialogs/panel_printer_list_base.h @@ -0,0 +1,50 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-282-g1fa54006) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +/// Class PANEL_PRINTER_LIST_BASE +/////////////////////////////////////////////////////////////////////////////// +class PANEL_PRINTER_LIST_BASE : public wxPanel +{ + private: + + protected: + wxStaticBoxSizer* m_sbSizerPrinters; + wxChoice* m_choicePrinter; + wxStaticText* m_staticTextPrn; + wxStaticText* m_stPrinterState; + + // Virtual event handlers, override them in your derived class + virtual void onPrinterChoice( wxCommandEvent& event ) { event.Skip(); } + + + public: + + PANEL_PRINTER_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 378,109 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + + ~PANEL_PRINTER_LIST_BASE(); + +}; + diff --git a/eeschema/printing/dialog_print.cpp b/eeschema/printing/dialog_print.cpp index e8184ac49b..d5e437c777 100644 --- a/eeschema/printing/dialog_print.cpp +++ b/eeschema/printing/dialog_print.cpp @@ -32,6 +32,12 @@ #include #include #include "dialog_print.h" + + +#include + +#include + #include "sch_printout.h" @@ -91,22 +97,27 @@ DIALOG_PRINT::DIALOG_PRINT( SCH_EDIT_FRAME* aParent ) : wxASSERT( aParent ); m_useCairo = ADVANCED_CFG::GetCfg().m_EnableEeschemaPrintCairo; + // Show m_panelPrinters only if there are printers to list: + m_panelPrinters->Show( m_panelPrinters->AsPrintersAvailable() ); + SetupStandardButtons( { { wxID_OK, _( "Print" ) }, { wxID_APPLY, _( "Print Preview" ) }, { wxID_CANCEL, _( "Close" ) } } ); #ifdef __WXMAC__ // Problems with modal on wx-2.9 - Anyway preview is standard for OSX - m_sdbSizer1Apply->Hide(); + m_sdbSizerApply->Hide(); #endif #if defined(__WXGTK__) // Preview using Cairo does not work on GTK, // but this platform provide native print preview if( m_useCairo ) - m_sdbSizer1Apply->Hide(); + m_sdbSizerApply->Hide(); #endif - m_sdbSizer1OK->SetFocus(); + m_sdbSizerOK->SetFocus(); + + Layout(); finishDialogSettings(); } @@ -236,12 +247,20 @@ void DIALOG_PRINT::OnPageSetup( wxCommandEvent& event ) void DIALOG_PRINT::OnPrintPreview( wxCommandEvent& event ) { SavePrintOptions(); + wxPrintData& prn_data = m_parent->GetPageSetupData().GetPrintData(); + + wxString selectedPrinterName; + + if( m_panelPrinters ) + selectedPrinterName = m_panelPrinters->GetSelectedPrinterName(); + + prn_data.SetPrinterName( selectedPrinterName ); // Pass two printout objects: for preview, and possible printing. wxString title = _( "Preview" ); wxPrintPreview* preview = new wxPrintPreview( new SCH_PRINTOUT( m_parent, title, m_useCairo ), new SCH_PRINTOUT( m_parent, title, m_useCairo ), - &m_parent->GetPageSetupData().GetPrintData() ); + &prn_data ); preview->SetZoom( 100 ); @@ -284,7 +303,7 @@ bool DIALOG_PRINT::TransferDataFromWindow() int sheet_count = m_parent->Schematic().Root().CountSheets(); - wxPrintData data = m_parent->GetPageSetupData().GetPrintData(); + wxPrintData& data = m_parent->GetPageSetupData().GetPrintData(); #if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 2, 3 ) // In GTK, the default bottom margin is bigger by 0.31 inches for @@ -346,6 +365,12 @@ bool DIALOG_PRINT::TransferDataFromWindow() } #endif + wxString selectedPrinterName; + + if( m_panelPrinters ) + selectedPrinterName = m_panelPrinters->GetSelectedPrinterName(); + data.SetPrinterName( selectedPrinterName ); + wxPrintDialogData printDialogData( data ); printDialogData.SetMaxPage( sheet_count ); diff --git a/eeschema/printing/dialog_print_base.cpp b/eeschema/printing/dialog_print_base.cpp index 8007317f54..87d77674c7 100644 --- a/eeschema/printing/dialog_print_base.cpp +++ b/eeschema/printing/dialog_print_base.cpp @@ -5,6 +5,8 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// +#include "dialogs/panel_printer_list.h" + #include "dialog_print_base.h" /////////////////////////////////////////////////////////////////////////// @@ -16,6 +18,15 @@ DIALOG_PRINT_BASE::DIALOG_PRINT_BASE( wxWindow* parent, wxWindowID id, const wxS wxBoxSizer* bMainSizer; bMainSizer = new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* bSizerPrintersPanel; + bSizerPrintersPanel = new wxBoxSizer( wxVERTICAL ); + + m_panelPrinters = new PANEL_PRINTER_LIST( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + bSizerPrintersPanel->Add( m_panelPrinters, 1, wxEXPAND | wxALL, 5 ); + + + bMainSizer->Add( bSizerPrintersPanel, 0, wxEXPAND, 5 ); + wxBoxSizer* bleftSizer; bleftSizer = new wxBoxSizer( wxVERTICAL ); @@ -51,18 +62,18 @@ DIALOG_PRINT_BASE::DIALOG_PRINT_BASE( wxWindow* parent, wxWindowID id, const wxS m_checkUseColorTheme->SetValue(true); bleftSizer->Add( m_checkUseColorTheme, 0, wxTOP|wxBOTTOM|wxRIGHT, 5 ); - wxBoxSizer* bSizer4; - bSizer4 = new wxBoxSizer( wxHORIZONTAL ); + wxBoxSizer* bSizerTheme; + bSizerTheme = new wxBoxSizer( wxHORIZONTAL ); wxArrayString m_colorThemeChoices; m_colorTheme = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_colorThemeChoices, 0 ); m_colorTheme->SetSelection( 0 ); m_colorTheme->Enable( false ); - bSizer4->Add( m_colorTheme, 1, wxEXPAND|wxLEFT, 20 ); + bSizerTheme->Add( m_colorTheme, 1, wxEXPAND|wxLEFT, 20 ); - bleftSizer->Add( bSizer4, 1, wxEXPAND, 5 ); + bleftSizer->Add( bSizerTheme, 0, wxEXPAND, 5 ); bMainSizer->Add( bleftSizer, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 10 ); @@ -76,16 +87,16 @@ DIALOG_PRINT_BASE::DIALOG_PRINT_BASE( wxWindow* parent, wxWindowID id, const wxS bbuttonsSizer->Add( 20, 0, 1, wxEXPAND, 5 ); - m_sdbSizer1 = new wxStdDialogButtonSizer(); - m_sdbSizer1OK = new wxButton( this, wxID_OK ); - m_sdbSizer1->AddButton( m_sdbSizer1OK ); - m_sdbSizer1Apply = new wxButton( this, wxID_APPLY ); - m_sdbSizer1->AddButton( m_sdbSizer1Apply ); - m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL ); - m_sdbSizer1->AddButton( m_sdbSizer1Cancel ); - m_sdbSizer1->Realize(); + 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(); - bbuttonsSizer->Add( m_sdbSizer1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + bbuttonsSizer->Add( m_sdbSizer, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); bMainSizer->Add( bbuttonsSizer, 0, wxEXPAND|wxLEFT, 10 ); @@ -100,7 +111,7 @@ DIALOG_PRINT_BASE::DIALOG_PRINT_BASE( wxWindow* parent, wxWindowID id, const wxS m_colorPrint->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnOutputChoice ), NULL, this ); m_checkUseColorTheme->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnUseColorThemeChecked ), NULL, this ); m_buttonPageSetup->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnPageSetup ), NULL, this ); - m_sdbSizer1Apply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnPrintPreview ), NULL, this ); + m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnPrintPreview ), NULL, this ); } DIALOG_PRINT_BASE::~DIALOG_PRINT_BASE() @@ -110,6 +121,6 @@ DIALOG_PRINT_BASE::~DIALOG_PRINT_BASE() m_colorPrint->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnOutputChoice ), NULL, this ); m_checkUseColorTheme->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnUseColorThemeChecked ), NULL, this ); m_buttonPageSetup->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnPageSetup ), NULL, this ); - m_sdbSizer1Apply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnPrintPreview ), NULL, this ); + m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PRINT_BASE::OnPrintPreview ), NULL, this ); } diff --git a/eeschema/printing/dialog_print_base.fbp b/eeschema/printing/dialog_print_base.fbp index a50dac2906..3bc96d14ef 100644 --- a/eeschema/printing/dialog_print_base.fbp +++ b/eeschema/printing/dialog_print_base.fbp @@ -65,6 +65,75 @@ bMainSizer wxVERTICAL none + + 5 + wxEXPAND + 0 + + + bSizerPrintersPanel + wxVERTICAL + none + + 5 + wxEXPAND | wxALL + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_panelPrinters + 1 + + + protected + 1 + + Resizable + 1 + + PANEL_PRINTER_LIST; dialogs/panel_printer_list.h; forward_declare + 0 + + + + wxTAB_TRAVERSAL + + + + 10 wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT @@ -422,10 +491,10 @@ 5 wxEXPAND - 1 + 0 - bSizer4 + bSizerTheme wxHORIZONTAL none @@ -605,7 +674,7 @@ 0 0 - m_sdbSizer1 + m_sdbSizer protected OnPrintPreview diff --git a/eeschema/printing/dialog_print_base.h b/eeschema/printing/dialog_print_base.h index 45e83e1e56..417920a4f1 100644 --- a/eeschema/printing/dialog_print_base.h +++ b/eeschema/printing/dialog_print_base.h @@ -10,16 +10,19 @@ #include #include #include +class PANEL_PRINTER_LIST; + #include "dialog_shim.h" -#include -#include +#include #include #include #include #include +#include +#include +#include #include #include -#include #include #include #include @@ -36,6 +39,7 @@ class DIALOG_PRINT_BASE : public DIALOG_SHIM private: protected: + PANEL_PRINTER_LIST* m_panelPrinters; wxCheckBox* m_checkReference; wxStaticText* m_staticText1; wxChoice* m_colorPrint; @@ -43,10 +47,10 @@ class DIALOG_PRINT_BASE : public DIALOG_SHIM wxCheckBox* m_checkUseColorTheme; wxChoice* m_colorTheme; wxButton* m_buttonPageSetup; - wxStdDialogButtonSizer* m_sdbSizer1; - wxButton* m_sdbSizer1OK; - wxButton* m_sdbSizer1Apply; - wxButton* m_sdbSizer1Cancel; + wxStdDialogButtonSizer* m_sdbSizer; + wxButton* m_sdbSizerOK; + wxButton* m_sdbSizerApply; + wxButton* m_sdbSizerCancel; // Virtual event handlers, override them in your derived class virtual void OnCloseWindow( wxCloseEvent& event ) { event.Skip(); } diff --git a/include/dialogs/panel_printer_list.h b/include/dialogs/panel_printer_list.h new file mode 100644 index 0000000000..17e0a44b32 --- /dev/null +++ b/include/dialogs/panel_printer_list.h @@ -0,0 +1,57 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2023 jean-pierre.charras + * Copyright (C) Kicad Developers, see AUTHORS.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 3 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, see . + */ + +#ifndef PANEL_PRINTER_LIST_H +#define PANEL_PRINTER_LIST_H + +#include + + +class PANEL_PRINTER_LIST : public PANEL_PRINTER_LIST_BASE +{ +public: + PANEL_PRINTER_LIST( wxWindow* aParent, wxWindowID id = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxSize( 378,109 ), long style = wxTAB_TRAVERSAL, + const wxString& name = wxEmptyString ); + + ~PANEL_PRINTER_LIST(); + + /// @return the selected printer name or a empty name + /// for the default printer + wxString GetSelectedPrinterName(); + + /// @return false if no printer in list + bool AsPrintersAvailable(); + +private: + void onPrinterChoice( wxCommandEvent& event ) override; + + // The printer name selected in this dialog + // static to store the choice during a session + static wxString m_selectedPrinterName; + // The default printer name selected by the OS + wxString m_defaultPrinterName; + // The list of available printer names + wxArrayString m_printer_list; +}; + +#endif