%% options copyright owner = Dirk Krause copyright year = 2013 license = bsd %% wx-gui type = dialog contents = sDialog # title = sTexts[30] [wxBoxSizer sDialog] direction = horizontal contents = $stretch(10) contents = verticalSizer contents = $stretch(10) [wxBoxSizer verticalSizer] direction = vertical grow = yes contents = $stretch(10) contents = sContents contents = $stretch(10) contents = sButtons centered contents = $stretch(10) [wxGridBagSizer sContents] grid = 5 5 contents = lChoosePrinter 0 0 1 1 # contents = cbChoosePrinter 0 +1 2 1 [wxStaticText lChoosePrinter] text = sTexts[31] # [wxChoice cbChoosePrinter] # choices = 2 pNames # tip = sTexts[36] [wxStdDialogButtonSizer sButtons] contents = bOK contents = bCancel [wxButton bOK] id = wxID_OK text = sTexts[32] tip = sTexts[33] [wxButton bCancel] id = wxID_CANCEL text = sTexts[34] tip = sTexts[35] %% header start %% class start /** Dialog to choose a printer. */ class WinprintChooserDialog : public wxDialog { private: /** Event table. */ DECLARE_EVENT_TABLE() %% class end protected: /** Localized texts. */ wxChar const * const *sTexts; /** Choice box containing the printer names. */ wxChoice *cbChoosePrinter; /** Printer names. */ wxString const *pNames; /** Number of printer names available. */ size_t nNames; public: /** Constructor. @param parent Parent frame. @param title Dialog title. @param messageTexts Localized texts used in dialog. @param printerNames Printer names array. @param numberOfPrinters Number of printers found. */ WinprintChooserDialog( DkWxFrame *parent, wxChar const *title, wxChar const * const *messageTexts, wxString const *printerNames, size_t numberOfPrinters ); /** Set the current printer selection. @param i Index of the new selection. */ void setCurrentPrinter(int i); /** Get current printer selection. @return Index of the current selection. */ int getCurrentPrinter(void); /** Handler for OK button. @param event Event to process. */ void OnOK(wxCommandEvent & event); /** Handler for Cancel button. @param event Event to process. */ void OnCancel(wxCommandEvent & event); }; %% header end %% module start #include "winprint.h" $!trace-include /** Event table. */ BEGIN_EVENT_TABLE(WinprintChooserDialog, wxDialog) EVT_BUTTON(wxID_OK, WinprintChooserDialog::OnOK) EVT_BUTTON(wxID_CANCEL, WinprintChooserDialog::OnCancel) END_EVENT_TABLE() %% constructor start WinprintChooserDialog::WinprintChooserDialog( DkWxFrame *parent, wxChar const *title, wxChar const * const *messageTexts, wxString const *printerNames, size_t numberOfPrinters ) : wxDialog( parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ) { sTexts = messageTexts; cbChoosePrinter = NULL; pNames = printerNames; nNames = numberOfPrinters; %% constructor end if(dkctGUILayoutOK) { if((pNames) && (nNames > 0)) { cbChoosePrinter = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, nNames, pNames ); if(cbChoosePrinter) { cbChoosePrinter->SetToolTip(sTexts[36]); sContents->Add( cbChoosePrinter, wxGBPosition(0, 1), wxGBSpan(2, 1)); sDialog->Fit(this); sDialog->SetSizeHints(this); } } } } %% module end void WinprintChooserDialog::setCurrentPrinter(int i) { unsigned count; /* Number of printers in chooser. */ int val; /* Corrected index. */ if(cbChoosePrinter) { count = cbChoosePrinter->GetCount(); val = i; if(i > ((int)count - 1)) { val = (int)count - 1; } if(val < 0) { val = 0; } cbChoosePrinter->SetSelection(val); } } int WinprintChooserDialog::getCurrentPrinter(void) { int back = wxNOT_FOUND; if(cbChoosePrinter) { back = cbChoosePrinter->GetSelection(); } return back; } void WinprintChooserDialog::OnOK(wxCommandEvent & event) { if(IsModal()) { EndModal(wxID_OK); } else { SetReturnCode(wxID_OK); Show(false); } } void WinprintChooserDialog::OnCancel(wxCommandEvent & event) { if(IsModal()) { EndModal(wxID_CANCEL); } else { SetReturnCode(wxID_CANCEL); Show(false); } }