summaryrefslogtreecommitdiff
path: root/support/dktools/DkWxProgressDialog.cpp
blob: 70fb55d5c936fa563dddad8d013f74101f2901a6 (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
	WARNING: This file was generated by dkct.
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: DkWxProgressDialog.wxc
*/

/*
Copyright (C) 2011-2017, Dirk Krause

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
  to endorse or promote products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**	@file DkWxProgressDialog.cpp The DkWxProgressDialog module.
*/


#line 142 "DkWxProgressDialog.wxc"

#include "dkwxtrace.h"



#line 146 "DkWxProgressDialog.wxc"

BEGIN_EVENT_TABLE(DkWxProgressDialog,wxDialog)
  EVT_IDLE(DkWxProgressDialog::OnIdle)
  EVT_BUTTON(wxID_CANCEL,	DkWxProgressDialog::OnCancel)
END_EVENT_TABLE()



/**	Default texts to use if the constructor has NULL pointer arguments.
*/
wxChar const * const dkwx_pd_def_texts[] = {
/* 0 */
wxT(""),

/* 1 */
wxT("Progress"),

/* 2 */
wxT("Cancel"),

/* 3 */
wxT("Push button to interrupt processing."),

/* 4 */
wxT("Cancel command scheduled... Wait, please!"),

NULL


#line 179 "DkWxProgressDialog.wxc"
};




#line 184 "DkWxProgressDialog.wxc"
DkWxProgressDialog::DkWxProgressDialog(
  DkWxFrame		*parent,
  DkWxCommunicator	*comm,
  wxTextCtrl		*tc,
  wxChar const		*title,
  wxChar const		*firstFileName,
  wxChar const		*buttonText,
  wxChar const		*buttonTip,
  wxChar const		*waitText
) : wxDialog(
  parent,
  wxID_ANY,
  ((title) ? title : dkwx_pd_def_texts[1]),
  wxDefaultPosition,
  wxDefaultSize,
  wxDEFAULT_DIALOG_STYLE
)
{
  

#line 203 "DkWxProgressDialog.wxc"
  pParent = parent;
  pLogTextField = tc;
  pComm = comm;
  sWaitPlease = ((waitText) ? waitText : dkwx_pd_def_texts[4]);
  dkctGUILayoutOK = false;
  sDialog = NULL;
  verticalSizer = NULL;
  sttFilename = NULL;
  gaugeProgress = NULL;
  sttWait = NULL;
  bCancel = NULL;
  sDialog = new wxBoxSizer(
    wxHORIZONTAL
  );
  if(!(sDialog)) {
    goto dkctGUILayoutFinished;
  }
  sDialog->Add(10, 10, 0);
  verticalSizer = new wxBoxSizer(
    wxVERTICAL
  );
  if(!(verticalSizer)) {
    goto dkctGUILayoutFinished;
  }
  verticalSizer->Add(10, 10, 0);
  sttFilename = new wxStaticText(
    this,
    wxID_ANY,
    ((firstFileName) ? firstFileName : dkwx_pd_def_texts[0]),
    wxDefaultPosition,
    wxDefaultSize,
    wxALIGN_CENTRE
  );
  if(!(sttFilename)) {
    goto dkctGUILayoutFinished;
  }
  verticalSizer->Add(
    sttFilename,
    1,
    wxALIGN_LEFT|wxGROW
  );
  verticalSizer->Add(10, 10, 0);
  gaugeProgress = new wxGauge(
    this,
    wxID_ANY,
    1000
  );
  if(!(gaugeProgress)) {
    goto dkctGUILayoutFinished;
  }
  verticalSizer->Add(
    gaugeProgress,
    0,
    wxALIGN_CENTER_HORIZONTAL|wxGROW
  );
  verticalSizer->Add(10, 10, 0);
  sttWait = new wxStaticText(
    this,
    wxID_ANY,
    ((waitText) ? waitText : dkwx_pd_def_texts[4]),
    wxDefaultPosition,
    wxDefaultSize,
    wxALIGN_LEFT
  );
  if(!(sttWait)) {
    goto dkctGUILayoutFinished;
  }
  verticalSizer->Add(
    sttWait,
    0,
    wxALIGN_LEFT
  );
  verticalSizer->Add(10, 10, 0);
  bCancel = new wxButton(
    this,
    wxID_CANCEL,
    ((buttonText) ? buttonText : dkwx_pd_def_texts[2])
  );
  if(!(bCancel)) {
    goto dkctGUILayoutFinished;
  }
  bCancel->SetToolTip(((buttonTip) ? buttonTip : dkwx_pd_def_texts[3]));
  verticalSizer->Add(
    bCancel,
    0,
    wxALIGN_CENTER_HORIZONTAL
  );
  verticalSizer->Add(10, 10, 0);
  sDialog->Add(
    verticalSizer,
    1,
    wxGROW
  );
  sDialog->Add(10, 10, 0);
  SetSizer(sDialog);
  dkctGUILayoutOK = true;
  dkctGUILayoutFinished:
  if(dkctGUILayoutOK) {
    sDialog->Fit(this);
    sDialog->SetSizeHints(this);
  }

#line 208 "DkWxProgressDialog.wxc"
  if(dkctGUILayoutOK) {
    if(sttWait) {
      sttWait->SetLabel(dkwx_pd_def_texts[0]);
    }
  }
  

#line 214 "DkWxProgressDialog.wxc"
}




#line 219 "DkWxProgressDialog.wxc"


void
DkWxProgressDialog::OnIdle(wxIdleEvent & event)
{
  int		canContinue = 1;
  int		res;
  

#line 227 "DkWxProgressDialog.wxc"
  if(pComm) {		

#line 228 "DkWxProgressDialog.wxc"
    res = pComm->getUpdates(this, sttFilename, gaugeProgress);
    

#line 230 "DkWxProgressDialog.wxc"
    if(res & DK_WX_COMMUNICATOR_STATUS_UPDATE) {	

#line 231 "DkWxProgressDialog.wxc"
      Refresh();
      Update();
    } else {						

#line 234 "DkWxProgressDialog.wxc"
    }
    if(res & DK_WX_COMMUNICATOR_STATUS_RUNNING) {	

#line 236 "DkWxProgressDialog.wxc"
      canContinue = 1;
    } else {						

#line 238 "DkWxProgressDialog.wxc"
      canContinue = 0;
    }
  } else {						

#line 241 "DkWxProgressDialog.wxc"
    canContinue = 0;
  }
  if(canContinue) {					

#line 244 "DkWxProgressDialog.wxc"
    event.RequestMore();
  } else {						

#line 246 "DkWxProgressDialog.wxc"
    canContinue = 1;
    if(pComm) {
      canContinue = pComm->getCanContinue();
      if(pLogTextField) {				

#line 250 "DkWxProgressDialog.wxc"
        pComm->getText(pLogTextField);
	if(pParent) {					

#line 252 "DkWxProgressDialog.wxc"
	  pParent->Refresh();
	} else {					

#line 254 "DkWxProgressDialog.wxc"
	  pLogTextField->Refresh();
	}
      }
    }
    if(IsModal()) {					

#line 259 "DkWxProgressDialog.wxc"
      EndModal((canContinue) ? wxID_OK : wxID_CANCEL);
    } else {						

#line 261 "DkWxProgressDialog.wxc"
      SetReturnCode((canContinue) ? wxID_OK : wxID_CANCEL);
      Show(false);
    }
  }
  event.Skip(); 

#line 266 "DkWxProgressDialog.wxc"
}



void
DkWxProgressDialog::OnCancel(wxCommandEvent & event)
{
  

#line 274 "DkWxProgressDialog.wxc"
  if(pComm) {
    pComm->setCanContinue(0);
  }
  if(sttWait) {
    sttWait->SetLabel(sWaitPlease);
  }
  if(bCancel) {
    bCancel->Enable(false);
    bCancel->SetToolTip(sWaitPlease);
  }
  Refresh();
  Update();
  

#line 287 "DkWxProgressDialog.wxc"
}



void
DkWxProgressDialog::chooseModalPosition()
{
  int	px	=	0;	/* Parent x position. */
  int	py	=	0;	/* Parent y position. */
  int	pw	=	0;	/* Parent width. */
  int	ph	=	0;	/* Parent height. */
  int	x	=	0;	/* X position. */
  int	y	=	0;	/* Y position. */
  int	w	=	0;	/* Width. */
  int	h	=	0;	/* Height. */
  

#line 303 "DkWxProgressDialog.wxc"
  /* Sceen size */
  wxSize	scsz	=	wxGetDisplaySize();
  pParent->GetPosition(&px, &py);
  pParent->GetSize(&pw, &ph);
  GetSize(&w, &h);
  x = px + (pw - w) / 2;
  y = py + (ph - h) / 2;
  if((x + w) > scsz.x) { x = scsz.x - w; }
  if((y + h) > scsz.y) { y = scsz.y - h; }
  if(x < 0) { x = 0; }
  if(y < 0) { y = 0; }
  SetSize(x, y, w, h);
  

#line 316 "DkWxProgressDialog.wxc"
}