1%%	options
2
3copyright owner	=	Dirk Krause
4copyright year	=	2013-xxxx
5SPDX-License-Identifier:	BSD-3-Clause
6
7%%	wx-gui
8
9type		=	dialog
10contents	=	sDialog
11# title		=	sTexts[30]
12
13[wxBoxSizer sDialog]
14direction 	= 	horizontal
15contents	=	$stretch(10)
16contents	=	verticalSizer
17contents	=	$stretch(10)
18
19[wxBoxSizer verticalSizer]
20direction	=	vertical
21grow		=	yes
22contents	=	$stretch(10)
23contents	=	sContents
24contents	=	$stretch(10)
25contents	=	sButtons	centered
26contents	=	$stretch(10)
27
28[wxGridBagSizer sContents]
29grid		=	5 5
30contents	=	lChoosePrinter		 0  0  1  1
31# contents	=	cbChoosePrinter		 0 +1  2  1
32
33[wxStaticText lChoosePrinter]
34text		=	sTexts[31]
35
36# [wxChoice cbChoosePrinter]
37# choices		=	2 pNames
38# tip		=	sTexts[36]
39
40[wxStdDialogButtonSizer sButtons]
41contents	=	bOK
42contents	=	bCancel
43
44[wxButton bOK]
45id		=	wxID_OK
46text		=	sTexts[32]
47tip		=	sTexts[33]
48
49[wxButton bCancel]
50id		=	wxID_CANCEL
51text		=	sTexts[34]
52tip		=	sTexts[35]
53
54
55
56%%	header start
57
58%%	class start
59/**	Dialog to choose a printer.
60*/
61class WinprintChooserDialog : public wxDialog
62{
63  private:
64    /**	Event table.
65    */
66#if	wxCHECK_VERSION(3,0,0)
67    wxDECLARE_EVENT_TABLE();
68#else
69    DECLARE_EVENT_TABLE()
70#endif
71
72%%	class end
73
74  protected:
75
76    /**	Localized texts.
77    */
78    wxChar const * const	*sTexts;
79
80    /**	Choice box containing the printer names.
81    */
82    wxChoice			*cbChoosePrinter;
83
84    /**	Printer names.
85    */
86    wxString const		*pNames;
87
88    /**	Number of printer names available.
89    */
90    size_t			 nNames;
91
92  public:
93
94    /**	Constructor.
95    	@param	parent			Parent frame.
96	@param	title			Dialog title.
97	@param	messageTexts		Localized texts used in dialog.
98	@param	printerNames		Printer names array.
99	@param	numberOfPrinters	Number of printers found.
100    */
101    WinprintChooserDialog(
102      DkWxFrame			*parent,
103      wxChar const		*title,
104      wxChar const * const	*messageTexts,
105      wxString const		*printerNames,
106      size_t			 numberOfPrinters
107    );
108
109    /**	Set the current printer selection.
110    	@param	i	Index of the new selection.
111    */
112    void
113    setCurrentPrinter(int i);
114
115    /**	Get current printer selection.
116    	@return	Index of the current selection.
117    */
118    int
119    getCurrentPrinter(void);
120
121    /**	Handler for OK button.
122    	@param	event	Event to process.
123    */
124    void
125    OnOK(wxCommandEvent & event);
126
127    /**	Handler for Cancel button.
128    	@param	event	Event to process.
129    */
130    void
131    OnCancel(wxCommandEvent & event);
132
133};
134
135%%	header end
136
137%%	module start
138
139
140#include "dk3conf.h"
141#include <winprint/winprint.h>
142
143
144
145$!trace-include
146
147
148/**	Event table.
149*/
150
151#if	wxCHECK_VERSION(3,0,0)
152wxBEGIN_EVENT_TABLE(WinprintChooserDialog,wxDialog)
153#else
154BEGIN_EVENT_TABLE(WinprintChooserDialog,wxDialog)
155#endif
156  EVT_BUTTON(wxID_OK,		WinprintChooserDialog::OnOK)
157  EVT_BUTTON(wxID_CANCEL,	WinprintChooserDialog::OnCancel)
158#if	wxCHECK_VERSION(3,0,0)
159wxEND_EVENT_TABLE()
160#else
161END_EVENT_TABLE()
162#endif
163
164
165%%	constructor start
166WinprintChooserDialog::WinprintChooserDialog(
167      DkWxFrame		*parent,
168      wxChar const		*title,
169      wxChar const * const	*messageTexts,
170      wxString const		*printerNames,
171      size_t			 numberOfPrinters
172) : wxDialog(
173  parent,
174  wxID_ANY,
175  title,
176  wxDefaultPosition,
177  wxDefaultSize,
178  wxDEFAULT_DIALOG_STYLE
179)
180{
181  sTexts = messageTexts;
182  cbChoosePrinter = NULL;
183  pNames = printerNames;
184  nNames = numberOfPrinters;
185%%	constructor end
186  if(dkctGUILayoutOK) {
187    if((pNames) && (nNames > 0)) {
188#if VERSION_BEFORE_20140929
189      cbChoosePrinter = new wxChoice(
190        this, wxID_ANY, wxDefaultPosition, wxDefaultSize, nNames, pNames
191      );
192#else
193      if ((dk3_um_t)DK3_I_MAX >= (dk3_um_t)nNames) {
194        cbChoosePrinter = new wxChoice(
195          this, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)nNames, pNames
196        );
197      }
198#endif
199      if(cbChoosePrinter) {
200        cbChoosePrinter->SetToolTip(sTexts[36]);
201	sContents->Add( cbChoosePrinter, wxGBPosition(0, 1), wxGBSpan(2, 1));
202	sDialog->Fit(this);
203	sDialog->SetSizeHints(this);
204      }
205    }
206  }
207}
208
209%%	module end
210
211
212void
213WinprintChooserDialog::setCurrentPrinter(int i)
214{
215  unsigned		count;	/* Number of printers in chooser. */
216  int			val;	/* Corrected index. */
217  if(cbChoosePrinter) {
218    count = cbChoosePrinter->GetCount();
219    val = i;
220    if(i > ((int)count - 1)) {
221      val = (int)count - 1;
222    }
223    if(val < 0) {
224      val = 0;
225    }
226    cbChoosePrinter->SetSelection(val);
227  }
228}
229
230
231
232int
233WinprintChooserDialog::getCurrentPrinter(void)
234{
235  int		 back = wxNOT_FOUND;
236  if(cbChoosePrinter) {
237    back = cbChoosePrinter->GetSelection();
238  }
239  return back;
240}
241
242
243
244void
245WinprintChooserDialog::OnOK(wxCommandEvent & event)
246{
247  if(IsModal()) {
248    EndModal(wxID_OK);
249  } else {
250    SetReturnCode(wxID_OK);
251    Show(false);
252  }
253}
254
255
256
257void
258WinprintChooserDialog::OnCancel(wxCommandEvent & event)
259{
260  if(IsModal()) {
261    EndModal(wxID_CANCEL);
262  } else {
263    SetReturnCode(wxID_CANCEL);
264    Show(false);
265  }
266}
267
268
269