2
// <copyright see="prj:///doc/copyright.txt"/>
3
// <license see="prj:///doc/license.txt"/>
4
// <owner name="Oakland Software Incorporated" email="general@oaklandsoftware.com"/>
5
// <version>$Revision$</version>
10
using System.Threading;
11
using System.Windows.Forms;
15
namespace NoGoop.ObjBrowser.Dialogs
17
internal class ProgressDialog : Dialog
19
protected ProgressBar _progress;
20
protected RichTextBox _textBox;
21
protected Label _label;
25
protected String _title;
26
protected String _bodyText;
27
protected int _maxValue;
28
protected bool _hasProgressText;
29
protected bool _final;
31
protected Cursor _saveCursor;
33
// Indicates this should be considered finished when the
34
// end is reached on this progress bar. If this is false,
35
// the progress dialog is still kept up because it expects
37
internal const bool FINAL = true;
39
internal const bool HAS_PROGRESS_TEXT = true;
41
// Used for the maxValue
42
internal const int NO_PROGRESS_BAR = -1;
44
public ProgressDialog() : base(!INCLUDE_BUTTONS)
52
StartPosition = FormStartPosition.Manual;
55
This does not seem to work
58
Parent = ObjectBrowser.ObjBrowser;
59
StartPosition = FormStartPosition.CenterParent;
62
// Have to manually compute location based on parent's location
63
if (ObjectBrowserForm.Instance != null) {
64
Size parentSize = ObjectBrowserForm.Instance.Size;
65
Point loc = ObjectBrowserForm.Instance.DesktopLocation;
67
Point ourLoc = new Point();
68
ourLoc.Y = loc.Y + (int)((parentSize.Height - Size.Height) / 2);
69
ourLoc.X = loc.X + (int)((parentSize.Width - Size.Width) / 2);
72
DesktopLocation = ourLoc;
76
public void Setup(String title,
82
TraceUtil.WriteLineInfo(this, "Progress Setup "
83
+ bodyText + " max: " + maxValue);
85
// When transitioning from phase to phase, if this is the
86
// last phase, the maxValue might be zero
87
if (maxValue == 0 && final)
89
TraceUtil.WriteLineInfo(this, "Setup final close");
97
_hasProgressText = hasProgressText;
100
// We are resetting, use the existing controls
101
if (Controls.Count > 0)
104
_textBox.Text = _bodyText;
106
_progress.Maximum = _maxValue;
109
TraceUtil.WriteLineInfo(this, "Using existing controls");
115
if (_hasProgressText)
117
_label = new Label();
118
_label.Dock = DockStyle.Bottom;
120
// Give space for two lines incase it wraps
122
Controls.Add(_label);
125
if (_maxValue != NO_PROGRESS_BAR)
127
_progress = new ProgressBar();
128
_progress.Maximum = _maxValue;
129
_progress.Dock = DockStyle.Top;
130
Controls.Add(_progress);
134
_textBox = Utils.MakeDescText(_bodyText, this);
135
_textBox.Dock = DockStyle.Top;
136
Controls.Add(_textBox);
140
internal void UpdateProgress(int increment)
142
_progress.Value += increment;
144
TraceUtil.WriteLineVerbose(this,
145
Thread.CurrentThread.Name
146
+ " Update progress: "
150
if (_progress.Value >= _progress.Maximum &&
153
TraceUtil.WriteLineInfo(this, Thread.CurrentThread.Name
154
+ " Update progress done");
159
internal void UpdateProgressText(String text)
165
internal void Finished()
169
TraceUtil.WriteLineInfo(this, "Finished - enter");
171
Cursor.Current = _saveCursor;
174
TraceUtil.WriteLineInfo
175
(this, "Finished - doing close");
183
TraceUtil.WriteLineWarning
184
(this, "Finished - exception on close " + ex);
186
TraceUtil.WriteLineInfo
187
(this, "Finished - after close");
191
internal void ShowIfNotDone()
193
TraceUtil.WriteLineInfo(this, "Progress - Show if not done");
197
TraceUtil.WriteLineInfo(this, "Progress - Showing");
199
// Set hourglass cursor
200
_saveCursor = Cursor.Current;
201
Cursor.Current = Cursors.WaitCursor;
204
// Setup and add the controls on the same thread
205
// as the one we show it
206
TraceUtil.WriteLineInfo(this, "Progress ShowThread - setup complete");
210
// Make sure text and all associated with the dialog
212
Application.DoEvents();