summaryrefslogtreecommitdiff
path: root/support/dktools/WxpqdicApp.cpt
blob: bef55e979e85dd13ed7528072ee914f0e538b1ab (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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
%%	options

copyright owner	=	Dirk Krause

copyright year	=	2016-xxxx

license		=	bsd



%%	header

/**	@file	WxpqdicApp.h	The WxpqdicApp class.
*/



/**	Application class, derived from wxApp, one instance per program.
*/
class WxpqdicApp : public wxApp
{
  protected:

    /**	Helper object.
    */
    Dk4WxApplicationHelper	 *pAh;

    /**	Controller fr online help.
    */
    Dk4WxHelpController		 *pHc;

    /*	__CHANGE__ 009:	Add further members here.
    */

    /**	Error report if the initialization of socket subsystem fails.
    */
    dk4_er_t			 sockerr;

    /**	Flag: Socket subsystem initialized successfully.
    */
    bool			 bSocketsInitialized;

  protected:

    /**	Show error message if there is not enough memory.
    */
    void
    ShowMemoryErrorMessage(void);

  public:

    /**	Application initialization.
    	@return	true on success, false on error.
    */
    virtual
    bool
    OnInit();

    /**	Application shutdown.
    	@return	0 on success, any other value indicates an error.
    */
    virtual
    int
    OnExit();
};



/**	Declaration as the wxApp object.
*/
DECLARE_APP(WxpqdicApp)



%%	module

#include "wxpqdic.h"



$!trace-include



/**	Localized wxChar texts.
*/
static wxChar const *	wxpqdic_texts[] = {
$!string-table	macro=wxT
#
#   0:	Menu "File"
#
File
#
#   1:	Menu item "File/Quit"
#
Quit
#
#   2:	Tool tip text for menu item "File/Exit"
#
Exit the application
#
#   3:	Menu "Help"
#
Help
#
#   4:	Menu item "Help/About"
#
About
#
#   5:	Tooltip text for menu item "Help/About"
#
Show version information
#
#   6:	Menu item "Help/Contents"
#
Contents
#
#   7:	Tooltip text for menu item "Help/Contents"
#
Open table of contents
#
#   8:	Initial status text
#
Ready
#
#   9:	Copyright notice.
#
Copyright (c) 
#
#  10:	Dialog box title "About ..."
#
About 
#
#  11:	This program uses the following libraries
#
This program uses the following libraries:
#
#  12:	See
#
See:
#
#  13:	Label text "Limit:"
#
Limit: 
#
#  14:	Limit value "unlimited"
#
unlimited
#
#  15:	Label text "Used:"
#
Used: 
#
#  16:	Dummy label text to initialize number of used pages
#
00000000
#
#  17:	Label text "Personal print account:"
#
Personal print account: 
#
#  18:	Label text "Printing allowed:"
#
Printing allowed: 
#
#  19 20:	Result text values
#
YES
NO
#
#  21:	Label text "Waiting for response from server."
#
Waiting for response from server.
#
#  22:	Menu "View"
#
View
#
#  23:	Menu item: View -> Update
#
Update
#
#  24:	Tool tip text for menu item: View -> Update
#
Update information in Window
#
#  25:	Toolbar button text "Update"
#
Update
#
#  26:	Toolbar button text "Exit"
#
Exit
#
#  27:	Information: unknown
#
unknown
#
#  28:	Error: Failed to send request
#
Failed to send request!
#
#  29:	Error: No response from server!
#
No response from server!
#
#  30 31
#
Command line
Failed to parse command line, illegal options used!
#
#  32 33
#
Insufficient memory
A memory allocation failed due to insufficient memory!
#
#  34 35
#
Illegal host name
Failed to convert host name to portable string!
#
#  36 37
#
Missing host name
No host name specified! Please use\n-h host\nto specify the remote host.
#
#  38 39
#
Illegal queue name
Failed to convert queue name to 8 bit character string!
#
#  40 41
#
Missing queue name
No queue name specified! Please use\n-q queue\n to specify the queue name.
#
#  42 43 44
#
Illegal remote port
Remote port number out of 16 bit range!
Remote port number 0 can not be used!
#
#  45 46
#
Illegal user name
Failed to convert user name to 8 bit character string!
#
#  47 48
#
No user name
User name not found!
#
#  49 50 51
#
Illegal local port
Local port number out of 16 bit range!
Local port number 0 can not be used!
#
#  52 53
#
Bug
Failed to construct request string!
#
#  54 55
#
Numeric overflow
A numeric overflow occured in size calculation!
#
#  56 57
#
Network error
Failed to create communication socket!
#
#  58 59
#
Error
An unknown error occured during setup!
$!end
};



/**	Non-localized wxChar texts.
*/
static wxChar const *	wxpqdic_nl_wx[] = {
$!string-table	macro=wxT
#
#   0:	Program name.
#
wxpqdic
#
#   1:	Program version.
#
4.3.0
#
#   2:	Copyright owner name.
#
Dirk Krause
#
#   3:	Software vendor name.
#						if necessary. Must be one
#						string without spaces.
#
DKrause
#
#   4:	Resource name of Windows icon
#
aaaaa
#
#   5:	UNUSED (previously Windows chm help file name)
#

#
#   6:	UNUSED (previously non-Windows htb help file name)
#

#
#   7:	Space
#
 
#
#   8:	Newline
#
\n
#
#   9 10 11 12 13 14 15:	List of libraries used.
#
DK tools, wxWidgets, libpng, libjpeg, libtiff, zlib.
http://dktools.sourceforge.net
http://www.wxwidgets.org
http://www.libpng.org/pub/png/libpng.html
http://www.ijg.org
http://www.remotesensing.org/libtiff
http://www.zlib.net
#
# 16 17
#
UTF-8
utf8
#
# 18 19
#
Error
Not enough memory (RAM)!
$!end
};



/**	Non-localized dkChar texts.
*/
static dkChar const *	wxpqdic_nl_dk[] = {
$!string-table	macro=dkT
#
#   0:	Program group name.
#
dktools
#
#   1:	String table name.
#
wxpqdc.str
#
#   2:	CHM help file name
#
wxpqdic.chm
#
#   3:	HTB help file name
#
wxpqdic.htb
$!end
};



/**	Implementation of the wxApp functionality.
*/
IMPLEMENT_APP(WxpqdicApp)


bool
WxpqdicApp::OnInit()
{
  WxpqdicFrame		*frame		= NULL;
  wxChar const * const	*localizedTexts	= NULL;
  wxPNGHandler		*phPng		= NULL;
  wxXPMHandler		*phXpm		= NULL;
  wxICOHandler		*phIco		= NULL;
  wxArchiveFSHandler	*phArchiveFS	= NULL;
  bool			 back		= false;

  $!trace-init	c:\\temp\\wxpqdic.deb
  $? "+ OnInit"

  /* Initialize members.
  */
  pAh = NULL;
  pHc = NULL;

  /*	__CHANGE__ 009:	Initialize further members here.
  */
  bSocketsInitialized = false;

  /* Set up application helper object.
  */
  pAh = new Dk4WxApplicationHelper();
  if (NULL == pAh) {
    ShowMemoryErrorMessage();
    goto finished;
  }
  if (!(pAh->Initialize(argv[0], wxpqdic_nl_wx[3], wxpqdic_nl_dk[0])))
  { $? "! pAh failed"
    goto finished;
  }

  /* Add image and file system handlers for online help.
  */
  phPng = new wxPNGHandler();
  if (NULL != phPng) {
    wxImage::AddHandler(phPng);
  } else {
    ShowMemoryErrorMessage();
    goto finished;
  }
  phXpm = new wxXPMHandler();
  if (NULL != phXpm) {
    wxImage::AddHandler(phXpm);
  } else {
    ShowMemoryErrorMessage();
    goto finished;
  }
  phIco = new wxICOHandler();
  if (NULL != phIco) {
    wxImage::AddHandler(phIco);
  } else {
    ShowMemoryErrorMessage();
    goto finished;
  }
  phArchiveFS = new wxArchiveFSHandler();
  if (NULL != phArchiveFS) {
    wxFileSystem::AddHandler(phArchiveFS);
  } else {
    ShowMemoryErrorMessage();
    goto finished;
  }

  /* Set up help controller.
  */
  pHc = new Dk4WxHelpController();
  if (NULL == pHc) {
    ShowMemoryErrorMessage();
    goto finished;
  }
  if (!(pHc->Initialize(pAh, wxpqdic_nl_dk[2], wxpqdic_nl_dk[3])))
  { $? "! pHc failed"
    goto finished;
  }

  /* Attempt to get localized texts in the users preferred language.
  */
  localizedTexts = pAh->GetStringTable(wxpqdic_nl_dk[1], wxpqdic_texts);
  if(!(localizedTexts)) { localizedTexts = wxpqdic_texts; }

  /* Initialize socket sub system.
  */
  dk4error_init(&sockerr);
  if (DK4_SOCKET_RESULT_SUCCESS == dk4socket_up(&sockerr)) {
    bSocketsInitialized = true;
  }

  /* Create and show frame.
  */
  frame = new WxpqdicFrame(
    WxpqdicFrame_MainWindow,
    pAh,
    pHc,
    argc,
    argv,
    localizedTexts,
    wxpqdic_nl_wx,
    wxpqdic_nl_dk,
    bSocketsInitialized,
    &sockerr
  );
  if(!(frame)) {
    ShowMemoryErrorMessage();
    goto finished;
  }

  /* Show frame and indicate success.
  */
  frame->Show();
  frame->RestorePosition();
  back = true;

  /* Release resources if initialization failed.
  */
  finished:
  if(!(back)) {
    if (NULL != pHc) {
      pHc->Cleanup();
      delete(pHc);
      pHc = NULL;
    }
    if (NULL != pAh) {
      pAh->Cleanup();
      delete(pAh);
      pAh = NULL;
    }
  }
  $? "- OnInit %d", ((back) ? 1 : 0)
#if 0
  if(!(back)) {
    $!trace-end
  }
#endif
  return back;
}



int
WxpqdicApp::OnExit()
{
  int			 back = 0;
  $? "+ OnExit"
  /*	__CHANGE__ 009:	Release resources allocated by further members.
  */
  if (bSocketsInitialized) {
    dk4socket_down(NULL);
  }

  /* Release resources. */
  if (NULL != pHc) {
    pHc->Cleanup();
    delete(pHc);
    pHc = NULL;
  }
  if (NULL != pAh) {
    pAh->Cleanup();
    delete(pAh);
    pAh = NULL;
  }
  $? "- OnExit %d", back
  $!trace-end
  return back;
}



void
WxpqdicApp::ShowMemoryErrorMessage(void)
{
  const wxChar	*s_title	= NULL;
  const wxChar	*s_text		= NULL;

  if (NULL != pAh) {
    s_title = pAh->GetBasicString(6);
    s_text  = pAh->GetBasicString(7);
  }
  if (NULL == s_title) {
    s_title = wxpqdic_nl_wx[18];
  }
  if (NULL == s_text) {
    s_text  = wxpqdic_nl_wx[19];
  }
  wxMessageBox(s_text, s_title, (wxOK | wxCENTRE | wxICON_ERROR));
}