summaryrefslogtreecommitdiff
path: root/support/dktools/WinprintChooserDialog.wxc
blob: d6bc73dc2be39c22aa4ea8bd2c053829a0cc0758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2013-xxxx
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)) {
#if VERSION_BEFORE_20140929
      cbChoosePrinter = new wxChoice(
        this, wxID_ANY, wxDefaultPosition, wxDefaultSize, nNames, pNames
      );
#else
      if ((dk3_um_t)DK3_I_MAX >= (dk3_um_t)nNames) {
        cbChoosePrinter = new wxChoice(
          this, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)nNames, pNames
        );
      }
#endif
      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);
  }
}