summaryrefslogtreecommitdiff
path: root/support/dktools/Dk4WxFrame.cpp
blob: 4d684ace056c75f126fee9a4e4240a6fbfd4bc26 (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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/*
Copyright (C) 2015-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	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: Dk4WxFrame.cpt
*/

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


#line 166 "Dk4WxFrame.cpt"


#ifndef	DK4CONF_H_INCLUDED
#include "dk4conf.h"
#endif

#ifndef	DK4WXFRAME_H_INCLUDED
#include "Dk4WxFrame.h"
#endif

#ifndef	DK4MPL_H_INCLUDED
#include "dk4mpl.h"
#endif

#ifndef	DK4MEM_H_INCLUDED
#include "dk4mem.h"
#endif

#ifndef	DK4STRD_H_INCLUDED
#include "dk4strd.h"
#endif

#ifndef	DK4PATHD_H_INCLUDED
#include "dk4pathd.h"
#endif

#ifndef	DK4STRX_H_INCLUDED
#include "dk4strx.h"
#endif

#ifndef	DK4RECWX_H_INCLUDED
#include "dk4recwx.h"
#endif




#line 202 "Dk4WxFrame.cpt"




/**	Protection for number of instances.
*/
wxCriticalSection	Dk4WxFrame::csInstances;



/**	Number of instances.
*/
int			Dk4WxFrame::iInstances = 0;



/**	Keywords to save and restore window size and position.
*/
static const wxChar * const	dk4wxframe_kw_size[] = {
/* 0 */
wxT("window.x"),

/* 1 */
wxT("window.y"),

/* 2 */
wxT("window.w"),

/* 3 */
wxT("window.h"),

/* 4 */
wxT("window.maximized"),

/* 5 */
wxT("window.iconized"),

NULL


#line 229 "Dk4WxFrame.cpt"
};



/**	Keywords to restore maximized and iconized state.
*/
static const wxChar * const	dk4wxframe_kw_restore[] = {
/* 0 */
wxT("window.restore-maximized"),

/* 1 */
wxT("window.restore-iconized"),

/* 2 */
wxT("window.restore-size"),

NULL


#line 241 "Dk4WxFrame.cpt"
};



/**	File name suffixes indicating to open file in web browser.
*/
static const wxChar * const	dk4wxframe_suffix_web[] = {
/* 0 */
wxT(".html"),

/* 1 */
wxT(".htm"),

NULL


#line 252 "Dk4WxFrame.cpt"
};



/**	Static text fragments, not localized.
*/
static const wxChar * const	dk4wxframe_kwnl_wx[] = {
/* 0 */
wxT("file://"),

NULL


#line 265 "Dk4WxFrame.cpt"
};



Dk4WxFrame::Dk4WxFrame(
  const wxString	&	 appName,
  Dk4WxApplicationHelper	*appHelper,
  Dk4WxHelpController		*helpController,
  int				 wxid
)
: wxFrame(NULL, wxid, appName)
{
  pAppHelp = appHelper;
  pHelp    = helpController;
  sAppName = appName;
  {
    wxCriticalSectionLocker	lock(csInstances);
    iInstances++;
  }
  Connect(wxid, wxEVT_CLOSE_WINDOW, wxCloseEventHandler(Dk4WxFrame::OnClose));
}



void
Dk4WxFrame::OnClose(wxCloseEvent & event)
{
  bool		doClose = true;
  bool		isFinal	= false;
  bool		savePos	= false;

  {
    wxCriticalSectionLocker	lock(csInstances);
    if (1 == iInstances) {
      isFinal = true;
    }
  }
  if (event.CanVeto()) {
    doClose = CanClose(isFinal);
  } else {
    (void)CanClose(isFinal);
  }
  if (doClose) {
    {
      wxCriticalSectionLocker	lock(csInstances);
      if (1 == iInstances--) { savePos = true; }
    }
    if (savePos) {
      SavePosition();
    }
    event.Skip();
  } else {
    event.Veto();
  }
}



bool
Dk4WxFrame::CanClose(bool WXUNUSED(isFinal))
{
  return true;
}


void
Dk4WxFrame::SavePosition(void)
{
  int	iv[6];
  

#line 335 "Dk4WxFrame.cpt"
  if (NULL != pAppHelp) {
    iv[4] = iv[5] = 0;
    if (IsIconized()) {
      iv[5] = 1;
      Iconize(false);
    }
    if (IsMaximized()) {
      iv[4] = 1;
      Maximize(false);
    }
    GetPosition(&(iv[0]), &(iv[1]));
    GetSize(&(iv[2]), &(iv[3]));
    

#line 348 "Dk4WxFrame.cpt"
    

#line 349 "Dk4WxFrame.cpt"
    

#line 350 "Dk4WxFrame.cpt"
    

#line 351 "Dk4WxFrame.cpt"
    

#line 352 "Dk4WxFrame.cpt"
    pAppHelp->SetMultiple(dk4wxframe_kw_size, iv, 6);
  }
  

#line 355 "Dk4WxFrame.cpt"
}



void
Dk4WxFrame::RestorePosition(void)
{
  int	iv[6];		/* Values stored in config */
  bool	bv[3];		/* Feature restore: maximized, iconized, position */
  int	x;		/* X position */
  int	y;		/* Y position */
  int	w;		/* Width */
  int	h;		/* Height */

  

#line 370 "Dk4WxFrame.cpt"

  /*	Restore position by default.
  */
  bv[2] = true;

  /* Initialize variables.
  */
  iv[0] = iv[1] = -1;
  iv[2] = iv[3] = iv[4] = iv[5] = 0;
  bv[0] = bv[1] = false;

  /*	Retrieve stored values if found.
  */
  if (NULL != pAppHelp) {
    pAppHelp->GetMultiple(dk4wxframe_kw_size, iv, 6);
    

#line 386 "Dk4WxFrame.cpt"
    

#line 387 "Dk4WxFrame.cpt"
    

#line 388 "Dk4WxFrame.cpt"
    

#line 389 "Dk4WxFrame.cpt"
    

#line 390 "Dk4WxFrame.cpt"
    

#line 391 "Dk4WxFrame.cpt"
    pAppHelp->GetMultiple(dk4wxframe_kw_restore, bv, 3);
    

#line 393 "Dk4WxFrame.cpt"
    

#line 394 "Dk4WxFrame.cpt"
    

#line 395 "Dk4WxFrame.cpt"
  }

  /*	Find size if not stored.
  */
  GetSize(&w, &h);
  x = iv[0];
  y = iv[1];
  

#line 403 "Dk4WxFrame.cpt"
  

#line 404 "Dk4WxFrame.cpt"
  

#line 405 "Dk4WxFrame.cpt"
  

#line 406 "Dk4WxFrame.cpt"

  /*	Correct size if size restoration wanted, increase if necessary.
  */
  if (bv[2]) {	

#line 410 "Dk4WxFrame.cpt"
    if (iv[2] > w) {
      w = iv[2];	

#line 412 "Dk4WxFrame.cpt"
    }
    if (iv[3] > h) {
      h = iv[3];	

#line 415 "Dk4WxFrame.cpt"
    }
  }

  /*	Correct values, no parts of window should be outside screen.
  */
  Dk4WxApplicationHelper::CorrectPosition(x, y, w, h);
  

#line 422 "Dk4WxFrame.cpt"
  

#line 423 "Dk4WxFrame.cpt"
  

#line 424 "Dk4WxFrame.cpt"
  

#line 425 "Dk4WxFrame.cpt"

  /*	Set position and optionally size.
  */
  if (bv[2]) {	

#line 429 "Dk4WxFrame.cpt"
    SetSize(x, y, w, h);
#if wxCHECK_VERSION(3,0,0)
    {
      int t1 = 0;
      int t2 = 0;
      GetSize(&t1, &t2);
      if ((t1 > w) || (t2 > h)) {	

#line 436 "Dk4WxFrame.cpt"
        if (t1 > w) {
	  w = w - (t1 - w);		

#line 438 "Dk4WxFrame.cpt"
	}
	if (t2 > h) {
	  h = h - (t2 - h);		

#line 441 "Dk4WxFrame.cpt"
	}				

#line 442 "Dk4WxFrame.cpt"
	SetSize(x, y, w, h);
	GetSize(&t1, &t2);
	

#line 445 "Dk4WxFrame.cpt"
	

#line 446 "Dk4WxFrame.cpt"
      }
    }
#endif
  } else {	

#line 450 "Dk4WxFrame.cpt"
    SetPosition( wxPoint(x,y) );
  }

  /*	Restore maximized or iconized state if required.
  */
  if (bv[0]) {	

#line 456 "Dk4WxFrame.cpt"
    Maximize(0 != iv[4]);
  }
#if TRACE_DEBUG
  else {	

#line 460 "Dk4WxFrame.cpt"
  }
#endif
  if (bv[1]) {	

#line 463 "Dk4WxFrame.cpt"
    Iconize(0 != iv[5]);
  }
#if TRACE_DEBUG
  else {	

#line 467 "Dk4WxFrame.cpt"
  }
#endif

  

#line 471 "Dk4WxFrame.cpt"
}



void
Dk4WxFrame::DisplayContents(void)
{
  if (NULL != pHelp) {
    pHelp->DisplayContents();
  }
}


    
void
Dk4WxFrame::DisplaySection(wxString const & name)
{
  if (NULL != pHelp) {
    pHelp->DisplaySection(name);
  }
}



void
Dk4WxFrame::DisplaySection(int number)
{
  if (NULL != pHelp) {
    pHelp->DisplaySection(number);
  }
}



bool
Dk4WxFrame::FindFileAndLaunch(dkChar const *fn, bool bIsHelp, bool bVerbose)
{
  wxChar	 bw[2 * DK4_MAX_PATH];		/* Full path in wxChar */
  wxChar	 b2[2 * DK4_MAX_PATH];
  dkChar	 b1[DK4_MAX_PATH];		/* Search result (full path) */
  wxChar const	*psuffix;			/* File name suffix */
  wxChar	*pmod;
  size_t	 szb1 = DK4_SIZEOF(b1,dkChar);	/* Size of b1 (num of dkChar) */
  size_t	 szb2 = DK4_SIZEOF(b2,wxChar);	/* Size of b2 (num of wxChar) */
  size_t	 szbw = DK4_SIZEOF(bw,wxChar);	/* Size of bw (num of wxChar) */
  int		 res;				/* Operation result */
  int		 de;				/* Destination encoding  */
  int		 se;				/* Source encoding */
  bool		 isweb;				/* Use web browser */
  bool		 done;				/* Successfully done */
  bool		 back;				/* Result */
  

#line 523 "Dk4WxFrame.cpt"
  back = false;
  if ((NULL != fn) && (NULL != pAppHelp)) {
    done = false;
    /*
    	Check for absolute path.
	Use absolute path unchanged.
	For a relative path do file search.
    */
    if (0 != dk4path_is_absolute(fn)) {			

#line 532 "Dk4WxFrame.cpt"
      if (0 != dk4str_cpy_s(b1, szb1, fn, NULL)) {	

#line 533 "Dk4WxFrame.cpt"
        done = true;
      }
#if	TRACE_DEBUG
      else {						

#line 537 "Dk4WxFrame.cpt"
      }
#endif
    }
    else {						

#line 541 "Dk4WxFrame.cpt"
      if (bIsHelp) {
        if (pAppHelp->FindHelpFile(b1, szb1, fn)) {	

#line 543 "Dk4WxFrame.cpt"
          done = true;	

#line 544 "Dk4WxFrame.cpt"
        }
#if	TRACE_DEBUG
        else {						

#line 547 "Dk4WxFrame.cpt"
        }
#endif
      }
      else {
        if (pAppHelp->FindDataFile(b1, szb1, fn)) {	

#line 552 "Dk4WxFrame.cpt"
          done = true;	

#line 553 "Dk4WxFrame.cpt"
        }
#if	TRACE_DEBUG
        else {						

#line 556 "Dk4WxFrame.cpt"
        }
#endif
      }
    }
    if (done) {
      done = false;
      de = pAppHelp->GetWxEncoding();
      se = pAppHelp->GetDkEncoding();
      res = dk4recwx_dkchar_to_wxchar(bw, szbw, de, b1, se, NULL);
      if (0 != res) {					

#line 566 "Dk4WxFrame.cpt"
        isweb = false;	

#line 567 "Dk4WxFrame.cpt"
	psuffix = dk4strx_get_path_suffix(bw, NULL);
	if (NULL != psuffix) {				

#line 569 "Dk4WxFrame.cpt"
	  if (0 <= dk4strx_array_index(dk4wxframe_suffix_web, psuffix, 0)) {
	    isweb = true;				

#line 571 "Dk4WxFrame.cpt"
	  }
	}
	if (isweb) {					

#line 574 "Dk4WxFrame.cpt"
	  if (::wxLaunchDefaultBrowser(bw)) {
	    done = true;				

#line 576 "Dk4WxFrame.cpt"
	    back = true;
	  }
	  else {					

#line 579 "Dk4WxFrame.cpt"
	    if (0 != dk4strx_cpy_s(b2, szb2, dk4wxframe_kwnl_wx[0], NULL)) {
	      

#line 581 "Dk4WxFrame.cpt"
	      if (0 != dk4strx_cat_s(b2, szb2, bw, NULL)) { 

#line 582 "Dk4WxFrame.cpt"
	        

#line 583 "Dk4WxFrame.cpt"
	        if (::wxLaunchDefaultBrowser(bw)) {	

#line 584 "Dk4WxFrame.cpt"
		  done = true;
		  back = true;
		}
		else {					

#line 588 "Dk4WxFrame.cpt"
		  pmod = &(b2[dk4strx_len(dk4wxframe_kwnl_wx[0])]);
		  while (wxT('\0') != *pmod) {
		    if (wxT('\\') == *pmod) { *pmod = wxT('/'); }
		    pmod++;
		  }			

#line 593 "Dk4WxFrame.cpt"
		  

#line 594 "Dk4WxFrame.cpt"
		  if (::wxLaunchDefaultBrowser(bw)) {
		    done = true;			

#line 596 "Dk4WxFrame.cpt"
		    back = true;
		  }
#if	TRACE_DEBUG
		  else {				

#line 600 "Dk4WxFrame.cpt"
		  }
#endif
		}
	      }
	      else {					

#line 605 "Dk4WxFrame.cpt"
	        /* ##### ERROR: BUG */
	      }
	    }
	    else {					

#line 609 "Dk4WxFrame.cpt"
	      /* ##### ERROR: BUG */
	    }
	  }
	}
	if (!(done)) {					

#line 614 "Dk4WxFrame.cpt"
#if	wxCHECK_VERSION(3,0,0)
	  if (::wxLaunchDefaultApplication(bw)) {	

#line 616 "Dk4WxFrame.cpt"
	    done = true;
	    back = true;
	  }
#if	TRACE_DEBUG
	  else {					

#line 621 "Dk4WxFrame.cpt"
	  }
#endif
#endif
	}
	if (!(done)) {
	  /* ERROR: Failed to start application */
	  if (bVerbose) {
	    wxString t;
	    t.Append(pAppHelp->GetBasicString(12));
	    t.Append(bw);
	    t.Append(pAppHelp->GetBasicString(13));
	    ::wxMessageBox(
	      t, pAppHelp->GetBasicString(11), (wxOK | wxCENTRE | wxICON_ERROR)
	    );
	  }
	}
      }
      else {						

#line 639 "Dk4WxFrame.cpt"
        /* ERROR: Recoding failed */
	if (bVerbose) {
          ::wxMessageBox(
      	    pAppHelp->GetBasicString(10), pAppHelp->GetBasicString(9),
	    (wxOK | wxCENTRE | wxICON_ERROR)
          );
	}
      }
    }
    else {						

#line 649 "Dk4WxFrame.cpt"
      /* ERROR: File not found */
      if (bVerbose) {
        ::wxMessageBox(
      	  pAppHelp->GetBasicString(10), pAppHelp->GetBasicString(9),
	  (wxOK | wxCENTRE | wxICON_ERROR)
        );
      }
    }
  }
#if	TRACE_DEBUG
  else {						

#line 660 "Dk4WxFrame.cpt"
  }
#endif
  

#line 663 "Dk4WxFrame.cpt"
  return back;
}