File: WizardForm.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (413 lines) | stat: -rw-r--r-- 16,784 bytes parent folder | download
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
//------------------------------------------------------------------------------
// <copyright file="WizardForm.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner       [....]
// @backupOwner [....]
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Design;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace System.Web.UI.Design.WebControls.Util
{
    /// <devdoc>
    /// Represents a wizard used to guide users through configuration processes.
    /// </devdoc>
    internal abstract class WizardForm : TaskFormBase
    {

        private System.Windows.Forms.Button _nextButton;
        private System.Windows.Forms.Button _previousButton;
        private System.Windows.Forms.Button _cancelButton;
        private System.Windows.Forms.Button _finishButton;
        private System.Windows.Forms.TableLayoutPanel _wizardButtonsTableLayoutPanel;
        private System.Windows.Forms.Label _dummyLabel1;
        private System.Windows.Forms.Label _dummyLabel2;
        private System.Windows.Forms.Label _dummyLabel3;

        System.Collections.Generic.Stack<WizardPanel> _panelHistory;
        private WizardPanel _initialPanel;

        /// <devdoc>
        /// Creates a new WizardForm with a given service provider.
        /// </devdoc>
        public WizardForm(IServiceProvider serviceProvider)
            : base(serviceProvider)
        {
            _panelHistory = new System.Collections.Generic.Stack<WizardPanel>();

            InitializeComponent();
            InitializeUI();
        }

        /// <devdoc>
        /// The Finish button of the wizard.
        /// </devdoc>
        public System.Windows.Forms.Button FinishButton
        {
            get
            {
                return _finishButton;
            }
        }

        /// <devdoc>
        /// The Next button of the wizard.
        /// </devdoc>
        public System.Windows.Forms.Button NextButton
        {
            get
            {
                return _nextButton;
            }
        }

        /// <devdoc>
        /// The Back button of the wizard.
        /// </devdoc>
        public System.Windows.Forms.Button PreviousButton
        {
            get
            {
                return _previousButton;
            }
        }

        #region Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {

            this._wizardButtonsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
            this._previousButton = new System.Windows.Forms.Button();
            this._nextButton = new System.Windows.Forms.Button();
            this._dummyLabel2 = new System.Windows.Forms.Label();
            this._finishButton = new System.Windows.Forms.Button();
            this._dummyLabel3 = new System.Windows.Forms.Label();
            this._cancelButton = new System.Windows.Forms.Button();
            this._dummyLabel1 = new System.Windows.Forms.Label();
            this._wizardButtonsTableLayoutPanel.SuspendLayout();
            this.SuspendLayout();

            // 
            // _wizardButtonsTableLayoutPanel
            // 
            this._wizardButtonsTableLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this._wizardButtonsTableLayoutPanel.AutoSize = true;
            this._wizardButtonsTableLayoutPanel.ColumnCount = 7;
            this._wizardButtonsTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
            this._wizardButtonsTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 3F));
            this._wizardButtonsTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
            this._wizardButtonsTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 7F));
            this._wizardButtonsTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
            this._wizardButtonsTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 7F));
            this._wizardButtonsTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
            this._wizardButtonsTableLayoutPanel.Controls.Add(this._previousButton);
            this._wizardButtonsTableLayoutPanel.Controls.Add(this._dummyLabel1);
            this._wizardButtonsTableLayoutPanel.Controls.Add(this._nextButton);
            this._wizardButtonsTableLayoutPanel.Controls.Add(this._dummyLabel2);
            this._wizardButtonsTableLayoutPanel.Controls.Add(this._finishButton);
            this._wizardButtonsTableLayoutPanel.Controls.Add(this._dummyLabel3);
            this._wizardButtonsTableLayoutPanel.Controls.Add(this._cancelButton);
            this._wizardButtonsTableLayoutPanel.Location = new System.Drawing.Point(205, 394);
            this._wizardButtonsTableLayoutPanel.Name = "_wizardButtonsTableLayoutPanel";
            this._wizardButtonsTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
            this._wizardButtonsTableLayoutPanel.Size = new System.Drawing.Size(317, 20);
            this._wizardButtonsTableLayoutPanel.TabIndex = 100;            
            // 
            // _previousButton
            // 
            this._previousButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
            this._previousButton.AutoSize = true;
            this._previousButton.Enabled = false;
            this._previousButton.Location = new System.Drawing.Point(0, 0);
            this._previousButton.Margin = new System.Windows.Forms.Padding(0);
            this._previousButton.MinimumSize = new System.Drawing.Size(75, 23);
            this._previousButton.Name = "_previousButton";
            this._previousButton.TabIndex = 10;
            this._previousButton.Click += new System.EventHandler(this.OnPreviousButtonClick);
            // 
            // _dummyLabel1
            // 
            this._dummyLabel1.Location = new System.Drawing.Point(75, 0);
            this._dummyLabel1.Margin = new System.Windows.Forms.Padding(0);
            this._dummyLabel1.Name = "_dummyLabel1";
            this._dummyLabel1.Size = new System.Drawing.Size(3, 0);
            this._dummyLabel1.TabIndex = 20;
            // 
            // _nextButton
            // 
            this._nextButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
            this._nextButton.AutoSize = true;
            this._nextButton.Location = new System.Drawing.Point(78, 0);
            this._nextButton.Margin = new System.Windows.Forms.Padding(0);
            this._nextButton.MinimumSize = new System.Drawing.Size(75, 23);
            this._nextButton.Name = "_nextButton";
            this._nextButton.TabIndex = 30;
            this._nextButton.Click += new System.EventHandler(this.OnNextButtonClick);
            // 
            // _dummyLabel2
            // 
            this._dummyLabel2.Location = new System.Drawing.Point(153, 0);
            this._dummyLabel2.Margin = new System.Windows.Forms.Padding(0);
            this._dummyLabel2.Name = "_dummyLabel2";
            this._dummyLabel2.Size = new System.Drawing.Size(7, 0);
            this._dummyLabel2.TabIndex = 40;
            // 
            // _finishButton
            // 
            this._finishButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
            this._finishButton.AutoSize = true;
            this._finishButton.Enabled = false;
            this._finishButton.Location = new System.Drawing.Point(160, 0);
            this._finishButton.Margin = new System.Windows.Forms.Padding(0);
            this._finishButton.MinimumSize = new System.Drawing.Size(75, 23);
            this._finishButton.Name = "_finishButton";
            this._finishButton.TabIndex = 50;
            this._finishButton.Click += new System.EventHandler(this.OnFinishButtonClick);
            // 
            // _dummyLabel3
            // 
            this._dummyLabel3.Location = new System.Drawing.Point(235, 0);
            this._dummyLabel3.Margin = new System.Windows.Forms.Padding(0);
            this._dummyLabel3.Name = "_dummyLabel3";
            this._dummyLabel3.Size = new System.Drawing.Size(7, 0);
            this._dummyLabel3.TabIndex = 60;
            // 
            // _cancelButton
            // 
            this._cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
            this._cancelButton.AutoSize = true;
            this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this._cancelButton.Location = new System.Drawing.Point(242, 0);
            this._cancelButton.Margin = new System.Windows.Forms.Padding(0);
            this._cancelButton.MinimumSize = new System.Drawing.Size(75, 23);
            this._cancelButton.Name = "_cancelButton";
            this._cancelButton.TabIndex = 70;
            this._cancelButton.Click += new System.EventHandler(this.OnCancelButtonClick);
            // 
            // TaskForm
            // 
            this.AcceptButton = this._nextButton;
            this.CancelButton = this._cancelButton;
            this.Controls.Add(this._wizardButtonsTableLayoutPanel);
            
            this._wizardButtonsTableLayoutPanel.ResumeLayout(false);
            this._wizardButtonsTableLayoutPanel.PerformLayout();

            InitializeForm();

            this.ResumeLayout(false);
            this.PerformLayout();
        }
        #endregion

        /// <devdoc>
        /// Called after InitializeComponent to perform additional actions that
        /// are not supported by the designer.
        /// </devdoc>
        private void InitializeUI()
        {
            _cancelButton.Text = Strings.CancelButton;
            _cancelButton.AccessibleName = Strings.CancelButtonAccessibleName;
            _nextButton.Text = Strings.Wizard_NextButton;
            _nextButton.AccessibleName = Strings.Wizard_NextButtonAccessibleName;
            _previousButton.Text = Strings.Wizard_PreviousButton;
            _previousButton.AccessibleName = Strings.Wizard_PreviousButtonAccessibleName;
            _finishButton.Text = Strings.Wizard_FinishButton;
            _finishButton.AccessibleName = Strings.Wizard_FinishButtonAccessibleName;
        }

        /// <devdoc>
        /// Goes to the next panel in the wizard.
        /// </devdoc>
        public void NextPanel()
        {
            WizardPanel currentPanel = _panelHistory.Peek();
            if (currentPanel.OnNext())
            {
                currentPanel.Hide();
                WizardPanel nextPanel = currentPanel.NextPanel;
                if (nextPanel != null)
                {
                    RegisterPanel(nextPanel);
                    _panelHistory.Push(nextPanel);
                    OnPanelChanging(new WizardPanelChangingEventArgs(currentPanel));
                    ShowPanel(nextPanel);
                }
            }
        }

        /// <devdoc>
        /// Click event handler for the Cancel button.
        /// </devdoc>
        protected virtual void OnCancelButtonClick(object sender, System.EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        /// <devdoc>
        /// Raises the InitialActivated event.
        /// </devdoc>
        protected override void OnInitialActivated(EventArgs e)
        {
            base.OnInitialActivated(e);

            if (_initialPanel != null)
            {
                RegisterPanel(_initialPanel);
                _panelHistory.Push(_initialPanel);
                ShowPanel(_initialPanel);
            }
        }

        /// <devdoc>
        /// Click event handler for the Finish button.
        /// </devdoc>
        protected virtual void OnFinishButtonClick(object sender, System.EventArgs e)
        {
            WizardPanel currentPanel = _panelHistory.Peek();
            if (currentPanel.OnNext())
            {
                // Call OnComplete for every panel on the stack
                WizardPanel[] panels = _panelHistory.ToArray();
                Array.Reverse(panels);
                foreach (WizardPanel panel in panels)
                {
                    panel.OnComplete();
                }

                DialogResult = DialogResult.OK;
                Close();
            }
        }

        /// <devdoc>
        /// Click event handler for the Next button.
        /// </devdoc>
        protected virtual void OnNextButtonClick(object sender, System.EventArgs e)
        {
            NextPanel();
        }

        /// <devdoc>
        /// Called when a panel is about to change.
        /// </devdoc>
        protected virtual void OnPanelChanging(WizardPanelChangingEventArgs e)
        {
        }

        /// <devdoc>
        /// Click event handler for the Previous button.
        /// </devdoc>
        protected virtual void OnPreviousButtonClick(object sender, System.EventArgs e)
        {
            PreviousPanel();
        }

        /// <devdoc>
        /// Goes to the back panel in the wizard.
        /// </devdoc>
        public void PreviousPanel()
        {
            if (_panelHistory.Count > 1)
            {
                WizardPanel currentPanel = _panelHistory.Pop();
                WizardPanel backPanel = _panelHistory.Peek();
                currentPanel.OnPrevious();
                currentPanel.Hide();
                OnPanelChanging(new WizardPanelChangingEventArgs(currentPanel));
                ShowPanel(backPanel);
            }
        }

        /// <devdoc>
        /// Registers a panel for use in this wizard.
        /// </devdoc>
        internal void RegisterPanel(WizardPanel panel)
        {
            if (!TaskPanel.Controls.Contains(panel))
            {
                panel.Dock = DockStyle.Fill;
                panel.SetParentWizard(this);
                panel.Hide();
                TaskPanel.Controls.Add(panel);
            }
        }

        /// <devdoc>
        /// Initializes a WizardForm to use an ordered array of panels.
        /// </devdoc>
        protected void SetPanels(WizardPanel[] panels)
        {
            if ((panels != null) && (panels.Length > 0))
            {
                RegisterPanel(panels[0]);
                _initialPanel = panels[0];

                for (int i = 0; i < panels.Length - 1; i++)
                {
                    RegisterPanel(panels[i + 1]);
                    panels[i].NextPanel = panels[i + 1];
                }
            }
        }

        /// <devdoc>
        /// Shows the panel specified by the given index.
        /// </devdoc>
        private void ShowPanel(WizardPanel panel)
        {
            if (_panelHistory.Count == 1)
            {
                // If we're on the first panel, disable the back button
                PreviousButton.Enabled = false;
            }
            else
            {
                // Otherwise, enable it
                PreviousButton.Enabled = true;
            }

            if (panel.NextPanel == null)
            {
                // If we're on the last panel, change the button text
                NextButton.Enabled = false;
            }
            else
            {
                NextButton.Enabled = true;
            }

            // Show the specified panel
            panel.Show();

            // Set the description and caption of the task bar
            AccessibleDescription = panel.Caption;
            CaptionLabel.Text = panel.Caption;

            if (IsHandleCreated)
            {
                // Refresh the screen
                Invalidate();
            }

            // Focus the newly shown panel
            panel.Focus();
        }
    }
}