summaryrefslogtreecommitdiff
path: root/support/dktools/Dk4WxProgressControllerBase.h
blob: f73165ff4209222f392ec34b6bc53cd89c4e1acf (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
/**	@file	Dk4WxProgressControllerBase.h	Progress controller base class.
*/
#ifndef DK4WXPROGRESSCONTROLLERBASE_H_INCLUDED
#define	DK4WXPROGRESSCONTROLLERBASE_H_INCLUDED 1

/**	Base class for progress controllers interface to worker thread.
*/
class Dk4WxProgressControllerWorkerBase
{

  public:

  /*
	While the worker thread is running, it can
	- check whether the worker thread is allowed to continue,
	- set a new gauge value for the progress bar in the progress dialog,
	- indicate that the main thread should show a dialog box after
	  the worker thread has finished,
	- indicate end of processing immediately before finishing.
  */

  /**	Check whether worker thread is allowed to continue processing.
	@return	True if worker thread can continue normally, false
	if worker thread should abort.
  */
  virtual
  bool
  CanContinue(void) = 0;

  /**	Set gauge value for progress dialog.
	@param	value	New value for gauge.
  */
  virtual
  void
  SetGauge(int value) = 0;

  /**	Indicate that a dialog box should be shown by the main thread
	after the worker thread has finished.
	@param	title	Message box title.
	@param	msg	Message box text.
	@param	st	Message box style.
  */
  virtual
  void
  SetDialogData(
    const wxString &	title,
    const wxString &	msg,
    int			st = wxID_OK
  ) = 0;

  /**	End processing.
	Called from worker thread immediately before finished.
	Note: If you want to call SetGaugeValue() or SetDialogData(),
	call these functions before EndProcessing().
	@param	success	Flag: Successful processing.
  */
  virtual
  void
  EndProcessing(bool success = true) = 0;

};


/**	Progress controllers interface to event processing (main) thread.
*/
class Dk4WxProgressControllerOwnerBase
{
  public:

  /*
	Before the worker thread is started either the main
	thread or the worker thread should indicate start of processing.
  */

  /**	Start processing. Optionally called from worker thread
	or main thread.
	Must be called if a controller is used multiple times.
  */
  virtual
  void
  StartProcessing(void) = 0;

  /*
	While the worker thread is running, the main thread (event thread) can
	- check whether the worker thread finished processing,
	- retrieve the current gauge value,
	- abort processing on behalf of the progress dialogs cancel button.
  */

  /**	Check whether the worker thread is finished.
	@return	True if the worker thread is finished, false while running.
  */
  virtual
  bool
  IsFinished(void) = 0;

  /**	Retrieve gauge value.
	@return	Current value for progress gauge.
  */
  virtual
  int
  GetGauge(void) = 0;

  /**	Abort processing. Called from the progress dialogs Cancel button.
  */
  virtual
  void
  AbortProcessing(void) = 0;

  /*
	After the worker thread finished processing, the event thread can:
	- check whether the worker thread finished successfully,
	- check whether a dialog box should show a processing summary.
  */

  /**	Check whether the worker thread finished successfully.
	@return	True to indicate success, false otherwise.
  */
  virtual
  bool
  GetSuccess(void) = 0;

  /**	Check whether a dialog should be shown.
	@param	title	Result variable for message box title.
	@param	msg	Result variable for message text.
	@param	style	Result variable for dialog box style.
	@return	True to show a dialog, false otherwise.
  */
  virtual
  bool
  GetDialogData(wxString & title, wxString & msg, int & style) = 0;

};

#endif