1 //
2 // System.Web.UI.WebControls.Wizard
3 //
4 // Authors:
5 //  Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
8 //
9 
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 
31 
32 using System;
33 using System.Collections;
34 using System.Collections.Generic;
35 using System.ComponentModel;
36 using System.Web.UI;
37 
38 namespace System.Web.UI.WebControls
39 {
40 	[DefaultEventAttribute ("FinishButtonClick")]
41 	[BindableAttribute (false)]
42 	[DesignerAttribute ("System.Web.UI.Design.WebControls.WizardDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
43 	[ToolboxData ("<{0}:Wizard runat=\"server\"> <WizardSteps> <asp:WizardStep title=\"Step 1\" runat=\"server\"></asp:WizardStep> <asp:WizardStep title=\"Step 2\" runat=\"server\"></asp:WizardStep> </WizardSteps> </{0}:Wizard>")]
44 	public class Wizard: CompositeControl
45 	{
46 		public static readonly string CancelCommandName = "Cancel";
47 		public static readonly string MoveCompleteCommandName = "MoveComplete";
48 		public static readonly string MoveNextCommandName = "MoveNext";
49 		public static readonly string MovePreviousCommandName = "MovePrevious";
50 		public static readonly string MoveToCommandName = "Move";
51 		public static readonly string HeaderPlaceholderId = "headerPlaceholder";
52 		public static readonly string NavigationPlaceholderId = "navigationPlaceholder";
53 		public static readonly string SideBarPlaceholderId = "sideBarPlaceholder";
54 		public static readonly string WizardStepPlaceholderId = "wizardStepPlaceholder";
55 		protected static readonly string DataListID = "SideBarList";
56 
57 		static readonly string CancelButtonIDShort = "Cancel";
58 		protected static readonly string CancelButtonID = CancelButtonIDShort + "Button";
59 
60 		static readonly string CustomFinishButtonIDShort = "CustomFinish";
61 		protected static readonly string CustomFinishButtonID = CustomFinishButtonIDShort + "Button";
62 
63 		static readonly string CustomNextButtonIDShort = "CustomNext";
64 		protected static readonly string CustomNextButtonID = CustomNextButtonIDShort + "Button";
65 
66 		static readonly string CustomPreviousButtonIDShort = "CustomPrevious";
67 		protected static readonly string CustomPreviousButtonID = CustomPreviousButtonIDShort + "Button";
68 
69 		static readonly string FinishButtonIDShort = "Finish";
70 		protected static readonly string FinishButtonID = FinishButtonIDShort + "Button";
71 
72 		static readonly string FinishPreviousButtonIDShort = "FinishPrevious";
73 		protected static readonly string FinishPreviousButtonID = FinishPreviousButtonIDShort + "Button";
74 
75 		static readonly string SideBarButtonIDShort = "SideBar";
76 		protected static readonly string SideBarButtonID = SideBarButtonIDShort + "Button";
77 
78 		static readonly string StartNextButtonIDShort = "StartNext";
79 		protected static readonly string StartNextButtonID = StartNextButtonIDShort + "Button";
80 
81 		static readonly string StepNextButtonIDShort = "StepNext";
82 		protected static readonly string StepNextButtonID = StepNextButtonIDShort + "Button";
83 
84 		static readonly string StepPreviousButtonIDShort = "StepPrevious";
85 		protected static readonly string StepPreviousButtonID = StepPreviousButtonIDShort + "Button";
86 
87 		WizardStepCollection steps;
88 
89 		// View state
90 
91 		TableItemStyle stepStyle;
92 		TableItemStyle sideBarStyle;
93 		TableItemStyle headerStyle;
94 		TableItemStyle navigationStyle;
95 		Style sideBarButtonStyle;
96 
97 		Style cancelButtonStyle;
98 		Style finishCompleteButtonStyle;
99 		Style finishPreviousButtonStyle;
100 		Style startNextButtonStyle;
101 		Style stepNextButtonStyle;
102 		Style stepPreviousButtonStyle;
103 		Style navigationButtonStyle;
104 
105 		ITemplate finishNavigationTemplate;
106 		ITemplate startNavigationTemplate;
107 		ITemplate stepNavigationTemplate;
108 		ITemplate headerTemplate;
109 		ITemplate sideBarTemplate;
110 
111 		// Control state
112 
113 		int activeStepIndex = -1;
114 		bool inited = false;
115 		ArrayList history;
116 
117 		Table wizardTable;
118 		WizardHeaderCell _headerCell;
119 		TableCell _navigationCell;
120 		StartNavigationContainer _startNavContainer;
121 		StepNavigationContainer _stepNavContainer;
122 		FinishNavigationContainer _finishNavContainer;
123 		MultiView multiView;
124 		DataList stepDatalist;
125 		ArrayList styles = new ArrayList ();
126 		Hashtable customNavigation;
127 
128 		static readonly object ActiveStepChangedEvent = new object();
129 		static readonly object CancelButtonClickEvent = new object();
130 		static readonly object FinishButtonClickEvent = new object();
131 		static readonly object NextButtonClickEvent = new object();
132 		static readonly object PreviousButtonClickEvent = new object();
133 		static readonly object SideBarButtonClickEvent = new object();
134 
135 		public event EventHandler ActiveStepChanged {
136 			add { Events.AddHandler (ActiveStepChangedEvent, value); }
137 			remove { Events.RemoveHandler (ActiveStepChangedEvent, value); }
138 		}
139 
140 		public event EventHandler CancelButtonClick {
141 			add { Events.AddHandler (CancelButtonClickEvent, value); }
142 			remove { Events.RemoveHandler (CancelButtonClickEvent, value); }
143 		}
144 
145 		public event WizardNavigationEventHandler FinishButtonClick {
146 			add { Events.AddHandler (FinishButtonClickEvent, value); }
147 			remove { Events.RemoveHandler (FinishButtonClickEvent, value); }
148 		}
149 
150 		public event WizardNavigationEventHandler NextButtonClick {
151 			add { Events.AddHandler (NextButtonClickEvent, value); }
152 			remove { Events.RemoveHandler (NextButtonClickEvent, value); }
153 		}
154 
155 		public event WizardNavigationEventHandler PreviousButtonClick {
156 			add { Events.AddHandler (PreviousButtonClickEvent, value); }
157 			remove { Events.RemoveHandler (PreviousButtonClickEvent, value); }
158 		}
159 
160 		public event WizardNavigationEventHandler SideBarButtonClick {
161 			add { Events.AddHandler (SideBarButtonClickEvent, value); }
162 			remove { Events.RemoveHandler (SideBarButtonClickEvent, value); }
163 		}
164 
OnActiveStepChanged(object source, EventArgs e)165 		protected virtual void OnActiveStepChanged (object source, EventArgs e)
166 		{
167 			if (Events != null) {
168 				EventHandler eh = (EventHandler) Events [ActiveStepChangedEvent];
169 				if (eh != null) eh (source, e);
170 			}
171 		}
172 
OnCancelButtonClick(EventArgs e)173 		protected virtual void OnCancelButtonClick (EventArgs e)
174 		{
175 			if (Events != null) {
176 				EventHandler eh = (EventHandler) Events [CancelButtonClickEvent];
177 				if (eh != null) eh (this, e);
178 			}
179 		}
180 
OnFinishButtonClick(WizardNavigationEventArgs e)181 		protected virtual void OnFinishButtonClick (WizardNavigationEventArgs e)
182 		{
183 			if (Events != null) {
184 				WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [FinishButtonClickEvent];
185 				if (eh != null) eh (this, e);
186 			}
187 		}
188 
OnNextButtonClick(WizardNavigationEventArgs e)189 		protected virtual void OnNextButtonClick (WizardNavigationEventArgs e)
190 		{
191 			if (Events != null) {
192 				WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [NextButtonClickEvent];
193 				if (eh != null) eh (this, e);
194 			}
195 		}
196 
OnPreviousButtonClick(WizardNavigationEventArgs e)197 		protected virtual void OnPreviousButtonClick (WizardNavigationEventArgs e)
198 		{
199 			if (Events != null) {
200 				WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [PreviousButtonClickEvent];
201 				if (eh != null) eh (this, e);
202 			}
203 		}
204 
OnSideBarButtonClick(WizardNavigationEventArgs e)205 		protected virtual void OnSideBarButtonClick (WizardNavigationEventArgs e)
206 		{
207 			if (Events != null) {
208 				WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [SideBarButtonClickEvent];
209 				if (eh != null) eh (this, e);
210 			}
211 		}
212 
213 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
214 	    [BrowsableAttribute (false)]
215 		public WizardStepBase ActiveStep {
216 			get {
217 				int activeIndex = ActiveStepIndex;
218 				if (activeIndex < -1 || activeIndex >= WizardSteps.Count)
219 					throw new InvalidOperationException ("ActiveStepIndex has an invalid value.");
220 				if (activeIndex == -1)
221 					return null;
222 				return WizardSteps [activeIndex];
223 			}
224 		}
225 
226 	    [DefaultValueAttribute (-1)]
227 	    [ThemeableAttribute (false)]
228 	    public virtual int ActiveStepIndex {
229 		    get {
230 			    return activeStepIndex;
231 		    }
232 		    set {
233 			    if (value < -1 || (value > WizardSteps.Count && (inited || WizardSteps.Count > 0)))
234 				    throw new ArgumentOutOfRangeException ("The ActiveStepIndex must be less than WizardSteps.Count and at least -1");
235 			    if (inited && !AllowNavigationToStep (value))
236 				    return;
237 
238 			    if(activeStepIndex != value) {
239 				    activeStepIndex = value;
240 
241 				    if (inited) {
242 					    multiView.ActiveViewIndex = value;
243 					    if (stepDatalist != null) {
244 						    stepDatalist.SelectedIndex = value;
245 						    stepDatalist.DataBind ();
246 					    }
247 					    OnActiveStepChanged (this, EventArgs.Empty);
248 				    }
249 			    }
250 		    }
251 	    }
252 
253 	    [UrlPropertyAttribute]
254 	    [DefaultValueAttribute ("")]
255 	    [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
256 		public virtual string CancelButtonImageUrl {
257 			get {
258 				object v = ViewState ["CancelButtonImageUrl"];
259 				return v != null ? (string)v : string.Empty;
260 			}
261 			set {
262 				ViewState ["CancelButtonImageUrl"] = value;
263 			}
264 		}
265 
266 	    [DefaultValueAttribute (null)]
267 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
268 	    [NotifyParentPropertyAttribute (true)]
269 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
270 		public Style CancelButtonStyle {
271 			get {
272 				if (cancelButtonStyle == null) {
273 					cancelButtonStyle = new Style ();
274 					if (IsTrackingViewState)
275 						((IStateManager)cancelButtonStyle).TrackViewState ();
276 				}
277 				return cancelButtonStyle;
278 			}
279 		}
280 
281 	    [LocalizableAttribute (true)]
282 		public virtual string CancelButtonText {
283 			get {
284 				object v = ViewState ["CancelButtonText"];
285 				return v != null ? (string)v : "Cancel";
286 			}
287 			set {
288 				ViewState ["CancelButtonText"] = value;
289 			}
290 		}
291 
292 	    [DefaultValueAttribute (ButtonType.Button)]
293 		public virtual ButtonType CancelButtonType {
294 			get {
295 				object v = ViewState ["CancelButtonType"];
296 				return v != null ? (ButtonType)v : ButtonType.Button;
297 			}
298 			set {
299 				ViewState ["CancelButtonType"] = value;
300 			}
301 		}
302 
303 	    [UrlPropertyAttribute]
304 		    [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
305 		[DefaultValueAttribute ("")]
306 		[Themeable (false)]
307 		public virtual string CancelDestinationPageUrl {
308 			get {
309 				object v = ViewState ["CancelDestinationPageUrl"];
310 				return v != null ? (string)v : string.Empty;
311 			}
312 			set {
313 				ViewState ["CancelDestinationPageUrl"] = value;
314 			}
315 		}
316 
317 	    [DefaultValueAttribute (0)]
318 		public virtual int CellPadding {
319 			get {
320 				if (ControlStyleCreated)
321 					return ((TableStyle) ControlStyle).CellPadding;
322 				return 0;
323 			}
324 			set {
325 				((TableStyle) ControlStyle).CellPadding = value;
326 			}
327 		}
328 
329 	    [DefaultValueAttribute (0)]
330 		public virtual int CellSpacing {
331 			get {
332 				if (ControlStyleCreated)
333 					return ((TableStyle) ControlStyle).CellSpacing;
334 				return 0;
335 			}
336 			set {
337 				((TableStyle) ControlStyle).CellSpacing = value;
338 			}
339 		}
340 
341 	    [DefaultValueAttribute (false)]
342 	    [ThemeableAttribute (false)]
343 		public virtual bool DisplayCancelButton {
344 			get {
345 				object v = ViewState ["DisplayCancelButton"];
346 				return v != null ? (bool) v : false;
347 			}
348 			set {
349 				ViewState ["DisplayCancelButton"] = value;
350 			}
351 		}
352 
353 	    [DefaultValueAttribute (true)]
354 	    [ThemeableAttribute (false)]
355 		public virtual bool DisplaySideBar {
356 			get {
357 				object v = ViewState ["DisplaySideBar"];
358 				return v != null ? (bool) v : true;
359 			}
360 			set {
361 				ViewState ["DisplaySideBar"] = value;
362 				UpdateViews ();
363 			}
364 		}
365 
366 	    [UrlPropertyAttribute]
367 	    [DefaultValueAttribute ("")]
368 	    [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
369 		public virtual string FinishCompleteButtonImageUrl {
370 			get {
371 				object v = ViewState ["FinishCompleteButtonImageUrl"];
372 				return v != null ? (string)v : string.Empty;
373 			}
374 			set {
375 				ViewState ["FinishCompleteButtonImageUrl"] = value;
376 			}
377 		}
378 
379 	    [DefaultValueAttribute (null)]
380 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
381 	    [NotifyParentPropertyAttribute (true)]
382 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
383 		public Style FinishCompleteButtonStyle {
384 			get {
385 				if (finishCompleteButtonStyle == null) {
386 					finishCompleteButtonStyle = new Style ();
387 					if (IsTrackingViewState)
388 						((IStateManager)finishCompleteButtonStyle).TrackViewState ();
389 				}
390 				return finishCompleteButtonStyle;
391 			}
392 		}
393 
394 	    [LocalizableAttribute (true)]
395 		public virtual string FinishCompleteButtonText {
396 			get {
397 				object v = ViewState ["FinishCompleteButtonText"];
398 				return v != null ? (string)v : "Finish";
399 			}
400 			set {
401 				ViewState ["FinishCompleteButtonText"] = value;
402 			}
403 		}
404 
405 	    [DefaultValueAttribute (ButtonType.Button)]
406 		public virtual ButtonType FinishCompleteButtonType {
407 			get {
408 				object v = ViewState ["FinishCompleteButtonType"];
409 				return v != null ? (ButtonType)v : ButtonType.Button;
410 			}
411 			set {
412 				ViewState ["FinishCompleteButtonType"] = value;
413 			}
414 		}
415 
416 	    [UrlPropertyAttribute]
417 	    [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
418 	    [DefaultValueAttribute ("")]
419 		[Themeable (false)]
420 		public virtual string FinishDestinationPageUrl {
421 			get {
422 				object v = ViewState ["FinishDestinationPageUrl"];
423 				return v != null ? (string)v : string.Empty;
424 			}
425 			set {
426 				ViewState ["FinishDestinationPageUrl"] = value;
427 			}
428 		}
429 
430 		[DefaultValue (null)]
431 		[TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
432 		[PersistenceMode (PersistenceMode.InnerProperty)]
433 	    [Browsable (false)]
434 		public virtual ITemplate FinishNavigationTemplate {
435 			get { return finishNavigationTemplate; }
436 			set { finishNavigationTemplate = value; UpdateViews (); }
437 		}
438 
439 	    [UrlPropertyAttribute]
440 	    [DefaultValueAttribute ("")]
441 	    [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
442 		public virtual string FinishPreviousButtonImageUrl {
443 			get {
444 				object v = ViewState ["FinishPreviousButtonImageUrl"];
445 				return v != null ? (string)v : string.Empty;
446 			}
447 			set {
448 				ViewState ["FinishPreviousButtonImageUrl"] = value;
449 			}
450 		}
451 
452 	    [DefaultValueAttribute (null)]
453 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
454 	    [NotifyParentPropertyAttribute (true)]
455 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
456 		public Style FinishPreviousButtonStyle {
457 			get {
458 				if (finishPreviousButtonStyle == null) {
459 					finishPreviousButtonStyle = new Style ();
460 					if (IsTrackingViewState)
461 						((IStateManager)finishPreviousButtonStyle).TrackViewState ();
462 				}
463 				return finishPreviousButtonStyle;
464 			}
465 		}
466 
467 	    [LocalizableAttribute (true)]
468 		public virtual string FinishPreviousButtonText {
469 			get {
470 				object v = ViewState ["FinishPreviousButtonText"];
471 				return v != null ? (string)v : "Previous";
472 			}
473 			set {
474 				ViewState ["FinishPreviousButtonText"] = value;
475 			}
476 		}
477 
478 	    [DefaultValueAttribute (ButtonType.Button)]
479 		public virtual ButtonType FinishPreviousButtonType {
480 			get {
481 				object v = ViewState ["FinishPreviousButtonType"];
482 				return v != null ? (ButtonType)v : ButtonType.Button;
483 			}
484 			set {
485 				ViewState ["FinishPreviousButtonType"] = value;
486 			}
487 		}
488 
489 	    [DefaultValueAttribute (null)]
490 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
491 	    [NotifyParentPropertyAttribute (true)]
492 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
493 		public TableItemStyle HeaderStyle {
494 			get {
495 				if (headerStyle == null) {
496 					headerStyle = new TableItemStyle ();
497 					if (IsTrackingViewState)
498 						((IStateManager)headerStyle).TrackViewState ();
499 				}
500 				return headerStyle;
501 			}
502 		}
503 
504 		[DefaultValue (null)]
505 		[TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
506 		[PersistenceMode (PersistenceMode.InnerProperty)]
507 	    [Browsable (false)]
508 		public virtual ITemplate HeaderTemplate {
509 			get { return headerTemplate; }
510 			set { headerTemplate = value; UpdateViews (); }
511 		}
512 
513 	    [DefaultValueAttribute ("")]
514 	    [LocalizableAttribute (true)]
515 		public virtual string HeaderText {
516 			get {
517 				object v = ViewState ["HeaderText"];
518 				return v != null ? (string)v : string.Empty;
519 			}
520 			set {
521 				ViewState ["HeaderText"] = value;
522 			}
523 		}
524 	    [DefaultValue (null)]
525 	    [TemplateContainerAttribute(typeof(Wizard))]
526 		    [PersistenceModeAttribute(PersistenceMode.InnerProperty)]
527 		    [BrowsableAttribute(false)]
528 		    public virtual ITemplate LayoutTemplate { get; set; }
529 	    [DefaultValueAttribute (null)]
530 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
531 	    [NotifyParentPropertyAttribute (true)]
532 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
533 		public Style NavigationButtonStyle {
534 			get {
535 				if (navigationButtonStyle == null) {
536 					navigationButtonStyle = new Style ();
537 					if (IsTrackingViewState)
538 						((IStateManager)navigationButtonStyle).TrackViewState ();
539 				}
540 				return navigationButtonStyle;
541 			}
542 		}
543 
544 	    [DefaultValueAttribute (null)]
545 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
546 	    [NotifyParentPropertyAttribute (true)]
547 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
548 		public TableItemStyle NavigationStyle {
549 			get {
550 				if (navigationStyle == null) {
551 					navigationStyle = new TableItemStyle ();
552 					if (IsTrackingViewState)
553 						((IStateManager)navigationStyle).TrackViewState ();
554 				}
555 				return navigationStyle;
556 			}
557 		}
558 
559 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
560 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
561 	    [DefaultValueAttribute (null)]
562 	    [NotifyParentPropertyAttribute (true)]
563 		public TableItemStyle SideBarStyle {
564 			get {
565 				if (sideBarStyle == null) {
566 					sideBarStyle = new TableItemStyle ();
567 					if (IsTrackingViewState)
568 						((IStateManager)sideBarStyle).TrackViewState ();
569 				}
570 				return sideBarStyle;
571 			}
572 		}
573 
574 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
575 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
576 	    [DefaultValueAttribute (null)]
577 	    [NotifyParentPropertyAttribute (true)]
578 		public Style SideBarButtonStyle {
579 			get {
580 				if (sideBarButtonStyle == null) {
581 					sideBarButtonStyle = new Style ();
582 					if (IsTrackingViewState)
583 						((IStateManager)sideBarButtonStyle).TrackViewState ();
584 				}
585 				return sideBarButtonStyle;
586 			}
587 		}
588 
589 		[DefaultValue (null)]
590 		[TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
591 		[PersistenceMode (PersistenceMode.InnerProperty)]
592 		[Browsable (false)]
593 		public virtual ITemplate SideBarTemplate {
594 			get { return sideBarTemplate; }
595 			set { sideBarTemplate = value; UpdateViews (); }
596 		}
597 
598 		[Localizable (true)]
599 		public virtual string SkipLinkText
600 		{
601 			get
602 			{
603 				object v = ViewState ["SkipLinkText"];
604 				return v != null ? (string) v : "Skip Navigation Links.";
605 			}
606 			set
607 			{
608 				ViewState ["SkipLinkText"] = value;
609 			}
610 		}
611 
612 		[DefaultValue (null)]
613 		[TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
614 		[PersistenceMode (PersistenceMode.InnerProperty)]
615 	    [Browsable (false)]
616 		public virtual ITemplate StartNavigationTemplate {
617 			get { return startNavigationTemplate; }
618 			set { startNavigationTemplate = value; UpdateViews (); }
619 		}
620 
621 	    [UrlPropertyAttribute]
622 	    [DefaultValueAttribute ("")]
623 	    [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
624 		public virtual string StartNextButtonImageUrl {
625 			get {
626 				object v = ViewState ["StartNextButtonImageUrl"];
627 				return v != null ? (string)v : string.Empty;
628 			}
629 			set {
630 				ViewState ["StartNextButtonImageUrl"] = value;
631 			}
632 		}
633 
634 	    [DefaultValueAttribute (null)]
635 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
636 	    [NotifyParentPropertyAttribute (true)]
637 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
638 		public Style StartNextButtonStyle {
639 			get {
640 				if (startNextButtonStyle == null) {
641 					startNextButtonStyle = new Style ();
642 					if (IsTrackingViewState)
643 						((IStateManager)startNextButtonStyle).TrackViewState ();
644 				}
645 				return startNextButtonStyle;
646 			}
647 		}
648 
649 	    [LocalizableAttribute (true)]
650 		public virtual string StartNextButtonText {
651 			get {
652 				object v = ViewState ["StartNextButtonText"];
653 				return v != null ? (string)v : "Next";
654 			}
655 			set {
656 				ViewState ["StartNextButtonText"] = value;
657 			}
658 		}
659 
660 	    [DefaultValueAttribute (ButtonType.Button)]
661 		public virtual ButtonType StartNextButtonType {
662 			get {
663 				object v = ViewState ["StartNextButtonType"];
664 				return v != null ? (ButtonType)v : ButtonType.Button;
665 			}
666 			set {
667 				ViewState ["StartNextButtonType"] = value;
668 			}
669 		}
670 
671 		[DefaultValue (null)]
672 		[TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
673 		[PersistenceMode (PersistenceMode.InnerProperty)]
674 	    [Browsable (false)]
675 		public virtual ITemplate StepNavigationTemplate {
676 			get { return stepNavigationTemplate; }
677 			set { stepNavigationTemplate = value; UpdateViews (); }
678 		}
679 
680 	    [UrlPropertyAttribute]
681 	    [DefaultValueAttribute ("")]
682 	    [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
683 		public virtual string StepNextButtonImageUrl {
684 			get {
685 				object v = ViewState ["StepNextButtonImageUrl"];
686 				return v != null ? (string)v : string.Empty;
687 			}
688 			set {
689 				ViewState ["StepNextButtonImageUrl"] = value;
690 			}
691 		}
692 
693 	    [DefaultValueAttribute (null)]
694 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
695 	    [NotifyParentPropertyAttribute (true)]
696 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
697 		public Style StepNextButtonStyle {
698 			get {
699 				if (stepNextButtonStyle == null) {
700 					stepNextButtonStyle = new Style ();
701 					if (IsTrackingViewState)
702 						((IStateManager)stepNextButtonStyle).TrackViewState ();
703 				}
704 				return stepNextButtonStyle;
705 			}
706 		}
707 
708 	    [LocalizableAttribute (true)]
709 		public virtual string StepNextButtonText {
710 			get {
711 				object v = ViewState ["StepNextButtonText"];
712 				return v != null ? (string)v : "Next";
713 			}
714 			set {
715 				ViewState ["StepNextButtonText"] = value;
716 			}
717 		}
718 
719 	    [DefaultValueAttribute (ButtonType.Button)]
720 		public virtual ButtonType StepNextButtonType {
721 			get {
722 				object v = ViewState ["StepNextButtonType"];
723 				return v != null ? (ButtonType)v : ButtonType.Button;
724 			}
725 			set {
726 				ViewState ["StepNextButtonType"] = value;
727 			}
728 		}
729 
730 	    [UrlPropertyAttribute]
731 	    [DefaultValueAttribute ("")]
732 	    [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
733 		public virtual string StepPreviousButtonImageUrl {
734 			get {
735 				object v = ViewState ["StepPreviousButtonImageUrl"];
736 				return v != null ? (string)v : string.Empty;
737 			}
738 			set {
739 				ViewState ["StepPreviousButtonImageUrl"] = value;
740 			}
741 		}
742 
743 	    [DefaultValueAttribute (null)]
744 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
745 	    [NotifyParentPropertyAttribute (true)]
746 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
747 		public Style StepPreviousButtonStyle {
748 			get {
749 				if (stepPreviousButtonStyle == null) {
750 					stepPreviousButtonStyle = new Style ();
751 					if (IsTrackingViewState)
752 						((IStateManager)stepPreviousButtonStyle).TrackViewState ();
753 				}
754 				return stepPreviousButtonStyle;
755 			}
756 		}
757 
758 	    [LocalizableAttribute (true)]
759 		public virtual string StepPreviousButtonText {
760 			get {
761 				object v = ViewState ["StepPreviousButtonText"];
762 				return v != null ? (string)v : "Previous";
763 			}
764 			set {
765 				ViewState ["StepPreviousButtonText"] = value;
766 			}
767 		}
768 
769 	    [DefaultValueAttribute (ButtonType.Button)]
770 		public virtual ButtonType StepPreviousButtonType {
771 			get {
772 				object v = ViewState ["StepPreviousButtonType"];
773 				return v != null ? (ButtonType)v : ButtonType.Button;
774 			}
775 			set {
776 				ViewState ["StepPreviousButtonType"] = value;
777 			}
778 		}
779 
780 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
781 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
782 	    [DefaultValueAttribute (null)]
783 	    [NotifyParentPropertyAttribute (true)]
784 		public TableItemStyle StepStyle {
785 			get {
786 				if (stepStyle == null) {
787 					stepStyle = new TableItemStyle ();
788 					if (IsTrackingViewState)
789 						((IStateManager)stepStyle).TrackViewState ();
790 				}
791 				return stepStyle;
792 			}
793 		}
794 
795 	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
796 	    [EditorAttribute ("System.Web.UI.Design.WebControls.WizardStepCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
797 	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
798 	    [ThemeableAttribute (false)]
799 		public virtual WizardStepCollection WizardSteps {
800 			get {
801 				if (steps == null)
802 					steps = new WizardStepCollection (this);
803 				return steps;
804 			}
805 		}
806 
807 		protected virtual new HtmlTextWriterTag TagKey
808 		{
809 			get {
810 				return HtmlTextWriterTag.Table;
811 			}
812 		}
813 
814 		internal virtual ITemplate SideBarItemTemplate
815 		{
816 			get { return new SideBarButtonTemplate (this); }
817 		}
818 
GetHistory()819 		public ICollection GetHistory ()
820 		{
821 			if (history == null)
822 				history = new ArrayList ();
823 			return history;
824 		}
825 
MoveTo(WizardStepBase wizardStep)826 		public void MoveTo (WizardStepBase wizardStep)
827 		{
828 			if (wizardStep == null)
829 				throw new ArgumentNullException ("wizardStep");
830 
831 			int i = WizardSteps.IndexOf (wizardStep);
832 			if (i == -1)
833 				throw new ArgumentException ("The provided wizard step does not belong to this wizard.");
834 
835 			ActiveStepIndex = i;
836 		}
837 
GetStepType(WizardStepBase wizardStep, int index)838 		public WizardStepType GetStepType (WizardStepBase wizardStep, int index)
839 		{
840 			if (wizardStep.StepType == WizardStepType.Auto) {
841 				if ((index == WizardSteps.Count - 1) ||
842 						(WizardSteps.Count > 1 &&
843 						WizardSteps[WizardSteps.Count - 1].StepType == WizardStepType.Complete &&
844 						index == WizardSteps.Count - 2))
845 					return WizardStepType.Finish;
846 				else if (index == 0)
847 					return WizardStepType.Start;
848 				else
849 					return WizardStepType.Step;
850 			} else
851 				return wizardStep.StepType;
852 
853 		}
854 
AllowNavigationToStep(int index)855 		protected virtual bool AllowNavigationToStep (int index)
856 		{
857 			if ((index < 0 || index >= WizardSteps.Count) || history == null || !history.Contains (index))
858 				return true;
859 
860 			return WizardSteps [index].AllowReturn;
861 		}
862 
OnInit(EventArgs e)863 		protected internal override void OnInit (EventArgs e)
864 		{
865 			Page.RegisterRequiresControlState (this);
866 			base.OnInit (e);
867 
868 			if (ActiveStepIndex == -1)
869 				ActiveStepIndex = 0;
870 
871 			EnsureChildControls ();
872 
873 			inited = true;
874 		}
875 
CreateControlCollection()876 		protected override ControlCollection CreateControlCollection ()
877 		{
878 			ControlCollection col = new ControlCollection (this);
879 			col.SetReadonly (true);
880 			return col;
881 		}
882 
CreateChildControls()883 		protected internal override void CreateChildControls ()
884 		{
885 			CreateControlHierarchy ();
886 		}
MakeLayoutException(string phName, string phID, string condition = null)887 		InvalidOperationException MakeLayoutException (string phName, string phID, string condition = null)
888 		{
889 			return new InvalidOperationException (
890 				String.Format ("A {0} placeholder must be specified on Wizard '{1}'{2}. Specify a placeholder by setting a control's ID property to \"{3}\". The placeholder control must also specify runat=\"server\"",
891 					       phName, ID, condition, phID)
892 			);
893 		}
894 
CreateControlHierarchy_LayoutTemplate(ITemplate layoutTemplate)895 		void CreateControlHierarchy_LayoutTemplate (ITemplate layoutTemplate)
896 		{
897 			var layoutContainer = new WizardLayoutContainer ();
898 			ControlCollection controls = Controls;
899 
900 			controls.SetReadonly (false);
901 			controls.Add (layoutContainer);
902 			controls.SetReadonly (true);
903 
904 			layoutTemplate.InstantiateIn (layoutContainer);
905 
906 			WizardStepCollection steps = WizardSteps;
907 			bool doRender = steps != null && steps.Count > 0;
908 			Control container, placeHolder;
909 
910 			if (DisplaySideBar) {
911 				placeHolder = layoutContainer.FindControl (SideBarPlaceholderId);
912 				if (placeHolder == null)
913 					throw MakeLayoutException ("sidebar", SideBarPlaceholderId, " when DisplaySideBar is set to true");
914 
915 				container = new Control ();
916 				CreateSideBar (container);
917 				ReplacePlaceHolder (layoutContainer, placeHolder, container);
918 			}
919 
920 			ITemplate headerTemplate = HeaderTemplate;
921 			if (headerTemplate != null) {
922 				placeHolder = layoutContainer.FindControl (HeaderPlaceholderId);
923 				if (placeHolder == null)
924 					throw MakeLayoutException ("header", HeaderPlaceholderId, " when HeaderTemplate is set");
925 
926 				container = new Control ();
927 				headerTemplate.InstantiateIn (container);
928 				ReplacePlaceHolder (layoutContainer, placeHolder, container);
929 			}
930 
931 			placeHolder = layoutContainer.FindControl (WizardStepPlaceholderId);
932 			if (placeHolder == null)
933 				throw MakeLayoutException ("step", WizardStepPlaceholderId);
934 
935 			customNavigation = null;
936 			multiView = new MultiView ();
937 			foreach (View v in steps) {
938 				if (v is TemplatedWizardStep)
939 					InstantiateTemplateStep ((TemplatedWizardStep) v);
940 				multiView.Views.Add (v);
941 			}
942 			multiView.ActiveViewIndex = ActiveStepIndex;
943 			ReplacePlaceHolder (layoutContainer, placeHolder, multiView);
944 
945 			placeHolder = layoutContainer.FindControl (NavigationPlaceholderId);
946 			if (placeHolder == null)
947 				throw MakeLayoutException ("navigation", NavigationPlaceholderId);
948 
949 
950 			var contentTable = new Table ();
951 			contentTable.CellSpacing = 5;
952 			contentTable.CellPadding = 5;
953 			var row = new TableRow ();
954 			var cell = new TableCell ();
955 			cell.HorizontalAlign = HorizontalAlign.Right;
956 
957 			container = new Control ();
958 			CreateButtonBar (container);
959 
960 			row.Cells.Add (cell);
961 			contentTable.Rows.Add (row);
962 			ReplacePlaceHolder (layoutContainer, placeHolder, container);
963 
964 			layoutContainer.Visible = doRender;
965 		}
966 
ReplacePlaceHolder(WebControl container, Control placeHolder, Control replacement)967 		void ReplacePlaceHolder (WebControl container, Control placeHolder, Control replacement)
968 		{
969 			ControlCollection controls = container.Controls;
970 			int index = controls.IndexOf (placeHolder);
971 			controls.Remove (placeHolder);
972 			controls.AddAt (index, replacement);
973 		}
CreateControlHierarchy()974 		protected virtual void CreateControlHierarchy ()
975 		{
976 			ITemplate layoutTemplate = LayoutTemplate;
977 			if (layoutTemplate != null) {
978 				CreateControlHierarchy_LayoutTemplate (layoutTemplate);
979 				return;
980 			}
981 			styles.Clear ();
982 
983 			wizardTable = new ContainedTable (this);
984 
985 			Table contentTable = wizardTable;
986 
987 			if (DisplaySideBar) {
988 				contentTable = new Table ();
989 				contentTable.CellPadding = 0;
990 				contentTable.CellSpacing = 0;
991 				contentTable.Height = new Unit ("100%");
992 				contentTable.Width = new Unit ("100%");
993 
994 				TableRow row = new TableRow ();
995 
996 				TableCellNamingContainer sideBarCell = new TableCellNamingContainer (SkipLinkText, ClientID);
997 				sideBarCell.ID = "SideBarContainer";
998 				sideBarCell.ControlStyle.Height = Unit.Percentage (100);
999 				CreateSideBar (sideBarCell);
1000 				row.Cells.Add (sideBarCell);
1001 
1002 				TableCell contentCell = new TableCell ();
1003 				contentCell.Controls.Add (contentTable);
1004 				contentCell.Height = new Unit ("100%");
1005 				row.Cells.Add (contentCell);
1006 
1007 				wizardTable.Rows.Add (row);
1008 			}
1009 
1010 			AddHeaderRow (contentTable);
1011 
1012 			TableRow viewRow = new TableRow ();
1013 			TableCell viewCell = new TableCell ();
1014 
1015 			customNavigation = null;
1016 			multiView = new MultiView ();
1017 			foreach (View v in WizardSteps) {
1018 				if (v is TemplatedWizardStep)
1019 					InstantiateTemplateStep ((TemplatedWizardStep) v);
1020 				multiView.Views.Add (v);
1021 			}
1022 			multiView.ActiveViewIndex = ActiveStepIndex;
1023 
1024 			RegisterApplyStyle (viewCell, StepStyle);
1025 			viewCell.Controls.Add (multiView);
1026 			viewRow.Cells.Add (viewCell);
1027 			viewRow.Height = new Unit ("100%");
1028 			contentTable.Rows.Add (viewRow);
1029 
1030 			TableRow buttonRow = new TableRow ();
1031 			_navigationCell = new TableCell ();
1032 			_navigationCell.HorizontalAlign = HorizontalAlign.Right;
1033 			RegisterApplyStyle (_navigationCell, NavigationStyle);
1034 			CreateButtonBar (_navigationCell);
1035 			buttonRow.Cells.Add (_navigationCell);
1036 			contentTable.Rows.Add (buttonRow);
1037 
1038 			Controls.SetReadonly (false);
1039 			Controls.Add (wizardTable);
1040 			Controls.SetReadonly (true);
1041 		}
1042 
InstantiateTemplateStep(TemplatedWizardStep step)1043 		internal virtual void InstantiateTemplateStep(TemplatedWizardStep step)
1044 		{
1045 			BaseWizardContainer contentTemplateContainer = new BaseWizardContainer ();
1046 
1047 			if (step.ContentTemplate != null)
1048 				step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1049 
1050 			step.ContentTemplateContainer = contentTemplateContainer;
1051 			step.Controls.Clear ();
1052 			step.Controls.Add (contentTemplateContainer);
1053 
1054 			BaseWizardNavigationContainer customNavigationTemplateContainer = new BaseWizardNavigationContainer ();
1055 
1056 			if (step.CustomNavigationTemplate != null) {
1057 				step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1058 				RegisterCustomNavigation (step, customNavigationTemplateContainer);
1059 			}
1060 			step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1061 		}
1062 
RegisterCustomNavigation(TemplatedWizardStep step, BaseWizardNavigationContainer customNavigationTemplateContainer)1063 		internal void RegisterCustomNavigation (TemplatedWizardStep step, BaseWizardNavigationContainer customNavigationTemplateContainer)
1064 		{
1065 			if (customNavigation == null)
1066 				customNavigation = new Hashtable ();
1067 			customNavigation [step] = customNavigationTemplateContainer;
1068 		}
1069 
CreateButtonBar(Control container)1070 		void CreateButtonBar (Control container)
1071 		{
1072 			if(customNavigation != null && customNavigation.Values.Count > 0 ) {
1073 				int i = 0;
1074 				foreach (Control customNavigationTemplateContainer in customNavigation.Values) {
1075 					customNavigationTemplateContainer.ID = "CustomNavigationTemplateContainerID" + i++;
1076 					container.Controls.Add (customNavigationTemplateContainer);
1077 				}
1078 			}
1079 
1080 			//
1081 			// StartNavContainer
1082 			//
1083 			_startNavContainer = new StartNavigationContainer (this);
1084 			_startNavContainer.ID = "StartNavigationTemplateContainerID";
1085 			if (startNavigationTemplate != null)
1086 				startNavigationTemplate.InstantiateIn (_startNavContainer);
1087 			else {
1088 				TableRow row;
1089 				AddNavButtonsTable (_startNavContainer, out row);
1090 				AddButtonCell (row, CreateButtonSet (StartNextButtonIDShort, MoveNextCommandName));
1091 				AddButtonCell (row, CreateButtonSet (CancelButtonIDShort, CancelCommandName, false));
1092 				_startNavContainer.ConfirmDefaultTemplate ();
1093 			}
1094 			container.Controls.Add (_startNavContainer);
1095 
1096 			//
1097 			// StepNavContainer
1098 			//
1099 			_stepNavContainer = new StepNavigationContainer (this);
1100 			_stepNavContainer.ID = "StepNavigationTemplateContainerID";
1101 			if (stepNavigationTemplate != null)
1102 				stepNavigationTemplate.InstantiateIn (_stepNavContainer);
1103 			else {
1104 				TableRow row;
1105 				AddNavButtonsTable (_stepNavContainer, out row);
1106 				AddButtonCell (row, CreateButtonSet (StepPreviousButtonIDShort, MovePreviousCommandName, false));
1107 				AddButtonCell (row, CreateButtonSet (StepNextButtonIDShort, MoveNextCommandName));
1108 				AddButtonCell (row, CreateButtonSet (CancelButtonIDShort, CancelCommandName, false));
1109 				_stepNavContainer.ConfirmDefaultTemplate ();
1110 			}
1111 			container.Controls.Add (_stepNavContainer);
1112 
1113 			//
1114 			// StepNavContainer
1115 			//
1116 			_finishNavContainer = new FinishNavigationContainer (this);
1117 			_finishNavContainer.ID = "FinishNavigationTemplateContainerID";
1118 			if (finishNavigationTemplate != null)
1119 				finishNavigationTemplate.InstantiateIn (_finishNavContainer);
1120 			else {
1121 				TableRow row;
1122 				AddNavButtonsTable (_finishNavContainer, out row);
1123 				AddButtonCell (row, CreateButtonSet (FinishPreviousButtonIDShort, MovePreviousCommandName, false));
1124 				AddButtonCell (row, CreateButtonSet (FinishButtonIDShort, MoveCompleteCommandName));
1125 				AddButtonCell (row, CreateButtonSet (CancelButtonIDShort, CancelCommandName, false));
1126 				_finishNavContainer.ConfirmDefaultTemplate ();
1127 			}
1128 			container.Controls.Add (_finishNavContainer);
1129 		}
1130 
AddNavButtonsTable(BaseWizardNavigationContainer container, out TableRow row)1131 		static void AddNavButtonsTable (BaseWizardNavigationContainer container, out TableRow row)
1132 		{
1133 			Table t = new Table ();
1134 			t.CellPadding = 5;
1135 			t.CellSpacing = 5;
1136 			row = new TableRow ();
1137 			t.Rows.Add (row);
1138 			container.Controls.Add (t);
1139 		}
1140 
CreateButtonSet(string id, string command)1141 		Control [] CreateButtonSet (string id, string command)
1142 		{
1143 			return CreateButtonSet (id, command, true, null);
1144 		}
1145 
CreateButtonSet(string id, string command, bool causesValidation)1146 		Control [] CreateButtonSet (string id, string command, bool causesValidation)
1147 		{
1148 			return CreateButtonSet (id, command, causesValidation, null);
1149 		}
1150 
CreateButtonSet(string id, string command, bool causesValidation, string validationGroup)1151 		internal Control [] CreateButtonSet (string id, string command, bool causesValidation, string validationGroup)
1152 		{
1153 			return new Control [] {
1154 				CreateButton ( id + ButtonType.Button,  command, ButtonType.Button, causesValidation, validationGroup),
1155 				CreateButton ( id + ButtonType.Image,  command, ButtonType.Image, causesValidation, validationGroup),
1156 				CreateButton ( id + ButtonType.Link,  command, ButtonType.Link, causesValidation, validationGroup)
1157 				};
1158 		}
1159 
CreateButton(string id, string command, ButtonType type, bool causesValidation, string validationGroup)1160 		Control CreateButton (string id, string command, ButtonType type, bool causesValidation, string validationGroup)
1161 		{
1162 			WebControl b;
1163 			switch (type) {
1164 			case ButtonType.Button:
1165 				b = CreateStandardButton ();
1166 				break;
1167 			case ButtonType.Image:
1168 				b = CreateImageButton (null);
1169 				break;
1170 			case ButtonType.Link:
1171 				b = CreateLinkButton ();
1172 				break;
1173 			default:
1174 				throw new ArgumentOutOfRangeException ("type");
1175 			}
1176 
1177 			b.ID = id;
1178 			b.EnableTheming = false;
1179 			((IButtonControl) b).CommandName = command;
1180 			((IButtonControl) b).CausesValidation = causesValidation;
1181 			if(!String.IsNullOrEmpty(validationGroup))
1182 				((IButtonControl) b).ValidationGroup = validationGroup;
1183 
1184 			RegisterApplyStyle (b, NavigationButtonStyle);
1185 
1186 			return b;
1187 		}
1188 
CreateStandardButton()1189 		WebControl CreateStandardButton () {
1190 			Button btn = new Button ();
1191 			return btn;
1192 		}
1193 
CreateImageButton(string imageUrl)1194 		WebControl CreateImageButton (string imageUrl) {
1195 			ImageButton img = new ImageButton ();
1196 			img.ImageUrl = imageUrl;
1197 			return img;
1198 		}
1199 
CreateLinkButton()1200 		WebControl CreateLinkButton () {
1201 			LinkButton link = new LinkButton ();
1202 			return link;
1203 		}
1204 
AddButtonCell(TableRow row, params Control[] controls)1205 		void AddButtonCell (TableRow row, params Control[] controls)
1206 		{
1207 			TableCell cell = new TableCell ();
1208 			cell.HorizontalAlign = HorizontalAlign.Right;
1209 			for (int i = 0; i < controls.Length; i++)
1210 				cell.Controls.Add (controls [i]);
1211 			row.Cells.Add (cell);
1212 		}
1213 
CreateSideBar(Control container)1214 		void CreateSideBar (Control container)
1215 		{
1216 			WebControl wctl = container as WebControl;
1217 			if (wctl != null)
1218 				RegisterApplyStyle (wctl, SideBarStyle);
1219 
1220 			if (sideBarTemplate != null) {
1221 				sideBarTemplate.InstantiateIn (container);
1222 				stepDatalist = container.FindControl (DataListID) as DataList;
1223 				if (stepDatalist == null)
1224 					throw new InvalidOperationException ("The side bar template must contain a DataList control with id '" + DataListID + "'.");
1225 				stepDatalist.ItemDataBound += new DataListItemEventHandler(StepDatalistItemDataBound);
1226 			} else {
1227 				stepDatalist = new DataList ();
1228 				stepDatalist.ID = DataListID;
1229 				stepDatalist.SelectedItemStyle.Font.Bold = true;
1230 				stepDatalist.ItemTemplate = SideBarItemTemplate;
1231 				container.Controls.Add (stepDatalist);
1232 			}
1233 
1234 			stepDatalist.ItemCommand += new DataListCommandEventHandler (StepDatalistItemCommand);
1235 			stepDatalist.CellSpacing = 0;
1236 			stepDatalist.DataSource = WizardSteps;
1237 			stepDatalist.SelectedIndex = ActiveStepIndex;
1238 			stepDatalist.DataBind ();
1239 		}
1240 
StepDatalistItemCommand(object sender, DataListCommandEventArgs e)1241 		void StepDatalistItemCommand (object sender, DataListCommandEventArgs e)
1242 		{
1243 			WizardNavigationEventArgs arg = new WizardNavigationEventArgs (ActiveStepIndex, Convert.ToInt32 (e.CommandArgument));
1244 			OnSideBarButtonClick (arg);
1245 
1246 			if (!arg.Cancel)
1247 				ActiveStepIndex = arg.NextStepIndex;
1248 		}
1249 
StepDatalistItemDataBound(object sender, DataListItemEventArgs e)1250 		void StepDatalistItemDataBound (object sender, DataListItemEventArgs e)
1251 		{
1252 			if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem) {
1253 				IButtonControl button = (IButtonControl) e.Item.FindControl (SideBarButtonID);
1254 				if (button == null)
1255 					throw new InvalidOperationException ("SideBarList control must contain an IButtonControl with ID " + SideBarButtonID + " in every item template, this maybe include ItemTemplate, EditItemTemplate, SelectedItemTemplate or AlternatingItemTemplate if they exist.");
1256 
1257 				WizardStepBase step = (WizardStepBase) e.Item.DataItem;
1258 
1259 				if (button is Button)
1260 					((Button) button).UseSubmitBehavior = false;
1261 
1262 				button.CommandName = Wizard.MoveToCommandName;
1263 				button.CommandArgument = WizardSteps.IndexOf (step).ToString ();
1264 				button.Text = step.Name;
1265 				if (step.StepType == WizardStepType.Complete && button is WebControl)
1266 					((WebControl) button).Enabled = false;
1267 			}
1268 		}
1269 
AddHeaderRow(Table table)1270 		void AddHeaderRow (Table table)
1271 		{
1272 			TableRow row = new TableRow ();
1273 			_headerCell = new WizardHeaderCell ();
1274 			_headerCell.ID = "HeaderContainer";
1275 			RegisterApplyStyle (_headerCell, HeaderStyle);
1276 			if (headerTemplate != null) {
1277 				headerTemplate.InstantiateIn (_headerCell);
1278 				_headerCell.ConfirmInitState ();
1279 			}
1280 			row.Cells.Add (_headerCell);
1281 			table.Rows.Add (row);
1282 		}
1283 
RegisterApplyStyle(WebControl control, Style style)1284 		internal void RegisterApplyStyle (WebControl control, Style style)
1285 		{
1286 			styles.Add (new object [] { control, style });
1287 		}
1288 
CreateControlStyle()1289 		protected override Style CreateControlStyle ()
1290 		{
1291 			TableStyle style = new TableStyle ();
1292 			style.CellPadding = 0;
1293 			style.CellSpacing = 0;
1294 			return style;
1295 		}
1296 
GetDesignModeState()1297 		protected override IDictionary GetDesignModeState ()
1298 		{
1299 			throw new NotImplementedException ();
1300 		}
1301 
LoadControlState(object state)1302 		protected internal override void LoadControlState (object state)
1303 		{
1304 			if (state == null) return;
1305 			object[] controlState = (object[]) state;
1306 			base.LoadControlState (controlState[0]);
1307 			activeStepIndex = (int) controlState[1];
1308 			history = (ArrayList) controlState[2];
1309 		}
1310 
SaveControlState()1311 		protected internal override object SaveControlState ()
1312 		{
1313 			if (GetHistory ().Count == 0 || (int) history [0] != ActiveStepIndex)
1314 				history.Insert (0, ActiveStepIndex);
1315 
1316 			object bstate = base.SaveControlState ();
1317 			return new object[] {
1318 				bstate, activeStepIndex, history
1319 			};
1320 		}
1321 
LoadViewState(object savedState)1322 		protected override void LoadViewState (object savedState)
1323 		{
1324 			if (savedState == null) {
1325 				base.LoadViewState (null);
1326 				return;
1327 			}
1328 
1329 			object[] states = (object[]) savedState;
1330 			base.LoadViewState (states [0]);
1331 
1332 			if (states[1] != null) ((IStateManager)StepStyle).LoadViewState (states[1]);
1333 			if (states[2] != null) ((IStateManager)SideBarStyle).LoadViewState (states[2]);
1334 			if (states[3] != null) ((IStateManager)HeaderStyle).LoadViewState (states[3]);
1335 			if (states[4] != null) ((IStateManager)NavigationStyle).LoadViewState (states[4]);
1336 			if (states[5] != null) ((IStateManager)SideBarButtonStyle).LoadViewState (states[5]);
1337 			if (states[6] != null) ((IStateManager)CancelButtonStyle).LoadViewState (states[6]);
1338 			if (states[7] != null) ((IStateManager)FinishCompleteButtonStyle).LoadViewState (states[7]);
1339 			if (states[8] != null) ((IStateManager)FinishPreviousButtonStyle).LoadViewState (states[8]);
1340 			if (states[9] != null) ((IStateManager)StartNextButtonStyle).LoadViewState (states[9]);
1341 			if (states[10] != null) ((IStateManager)StepNextButtonStyle).LoadViewState (states[10]);
1342 			if (states[11] != null) ((IStateManager)StepPreviousButtonStyle).LoadViewState (states[11]);
1343 			if (states[12] != null) ((IStateManager)NavigationButtonStyle).LoadViewState (states[12]);
1344 			if (states [13] != null)
1345 				ControlStyle.LoadViewState (states [13]);
1346 		}
1347 
SaveViewState()1348 		protected override object SaveViewState ()
1349 		{
1350 			object [] state = new object [14];
1351 			state [0] = base.SaveViewState ();
1352 
1353 			if (stepStyle != null) state [1] = ((IStateManager)stepStyle).SaveViewState ();
1354 			if (sideBarStyle != null) state [2] = ((IStateManager)sideBarStyle).SaveViewState ();
1355 			if (headerStyle != null) state [3] = ((IStateManager)headerStyle).SaveViewState ();
1356 			if (navigationStyle != null) state [4] = ((IStateManager)navigationStyle).SaveViewState ();
1357 			if (sideBarButtonStyle != null) state [5] = ((IStateManager)sideBarButtonStyle).SaveViewState ();
1358 			if (cancelButtonStyle != null) state [6] = ((IStateManager)cancelButtonStyle).SaveViewState ();
1359 			if (finishCompleteButtonStyle != null) state [7] = ((IStateManager)finishCompleteButtonStyle).SaveViewState ();
1360 			if (finishPreviousButtonStyle != null) state [8] = ((IStateManager)finishPreviousButtonStyle).SaveViewState ();
1361 			if (startNextButtonStyle != null) state [9] = ((IStateManager)startNextButtonStyle).SaveViewState ();
1362 			if (stepNextButtonStyle != null) state [10] = ((IStateManager)stepNextButtonStyle).SaveViewState ();
1363 			if (stepPreviousButtonStyle != null) state [11] = ((IStateManager)stepPreviousButtonStyle).SaveViewState ();
1364 			if (navigationButtonStyle != null) state [12] = ((IStateManager)navigationButtonStyle).SaveViewState ();
1365 			if (ControlStyleCreated)
1366 				state [13] = ControlStyle.SaveViewState ();
1367 
1368 			for (int n=0; n<state.Length; n++)
1369 				if (state [n] != null) return state;
1370 			return null;
1371 		}
1372 
TrackViewState()1373 		protected override void TrackViewState ()
1374 		{
1375 			base.TrackViewState();
1376 			if (stepStyle != null) ((IStateManager)stepStyle).TrackViewState();
1377 			if (sideBarStyle != null) ((IStateManager)sideBarStyle).TrackViewState();
1378 			if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
1379 			if (navigationStyle != null) ((IStateManager)navigationStyle).TrackViewState();
1380 			if (sideBarButtonStyle != null) ((IStateManager)sideBarButtonStyle).TrackViewState();
1381 			if (cancelButtonStyle != null) ((IStateManager)cancelButtonStyle).TrackViewState();
1382 			if (finishCompleteButtonStyle != null) ((IStateManager)finishCompleteButtonStyle).TrackViewState();
1383 			if (finishPreviousButtonStyle != null) ((IStateManager)finishPreviousButtonStyle).TrackViewState();
1384 			if (startNextButtonStyle != null) ((IStateManager)startNextButtonStyle).TrackViewState();
1385 			if (stepNextButtonStyle != null) ((IStateManager)stepNextButtonStyle).TrackViewState();
1386 			if (stepPreviousButtonStyle != null) ((IStateManager)stepPreviousButtonStyle).TrackViewState();
1387 			if (navigationButtonStyle != null) ((IStateManager)navigationButtonStyle).TrackViewState();
1388 			if (ControlStyleCreated)
1389 				ControlStyle.TrackViewState ();
1390 		}
1391 
RegisterCommandEvents(IButtonControl button)1392 		protected internal void RegisterCommandEvents (IButtonControl button)
1393 		{
1394 			button.Command += ProcessCommand;
1395 		}
1396 
ProcessCommand(object sender, CommandEventArgs args)1397 		void ProcessCommand (object sender, CommandEventArgs args)
1398 		{
1399 			Control c = sender as Control;
1400 			if (c != null) {
1401 				switch (c.ID) {
1402 					case "CancelButton":
1403 						ProcessEvent ("Cancel", null);
1404 						return;
1405 					case "FinishButton":
1406 						ProcessEvent ("MoveComplete", null);
1407 						return;
1408 					case "StepPreviousButton":
1409 					case "FinishPreviousButton":
1410 						ProcessEvent ("MovePrevious", null);
1411 						return;
1412 					case "StartNextButton":
1413 					case "StepNextButton":
1414 						ProcessEvent ("MoveNext", null);
1415 						return;
1416 				}
1417 			}
1418 			ProcessEvent (args.CommandName, args.CommandArgument as string);
1419 		}
1420 
OnBubbleEvent(object source, EventArgs e)1421 		protected override bool OnBubbleEvent (object source, EventArgs e)
1422 		{
1423 			CommandEventArgs args = e as CommandEventArgs;
1424 			if (args != null) {
1425 				ProcessEvent (args.CommandName, args.CommandArgument as string);
1426 				return true;
1427 			}
1428 			return base.OnBubbleEvent (source, e);
1429 		}
1430 
ProcessEvent(string commandName, string commandArg)1431 		void ProcessEvent (string commandName, string commandArg)
1432 		{
1433 			switch (commandName) {
1434 				case "Cancel":
1435 					if (CancelDestinationPageUrl.Length > 0)
1436 						Context.Response.Redirect (CancelDestinationPageUrl);
1437 					else
1438 						OnCancelButtonClick (EventArgs.Empty);
1439 					break;
1440 
1441 				case "MoveComplete":
1442 					int next = -1;
1443 					for (int n=0; n<WizardSteps.Count; n++) {
1444 						if (WizardSteps [n].StepType == WizardStepType.Complete) {
1445 							next = n;
1446 							break;
1447 						}
1448 					}
1449 
1450 					if (next == -1 && ActiveStepIndex == WizardSteps.Count - 1)
1451 						next = ActiveStepIndex;
1452 
1453 					WizardNavigationEventArgs navArgs = new WizardNavigationEventArgs (ActiveStepIndex, next);
1454 					OnFinishButtonClick (navArgs);
1455 
1456 					if (FinishDestinationPageUrl.Length > 0) {
1457 						Context.Response.Redirect (FinishDestinationPageUrl);
1458 						return;
1459 					}
1460 
1461 					if (next != -1 && !navArgs.Cancel)
1462 						ActiveStepIndex = next;
1463 
1464 					break;
1465 
1466 				case "MoveNext":
1467 					if (ActiveStepIndex < WizardSteps.Count - 1) {
1468 						WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex + 1);
1469 						int curStep = ActiveStepIndex;
1470 						OnNextButtonClick (args);
1471 						if (!args.Cancel && curStep == activeStepIndex)
1472 							ActiveStepIndex++;
1473 					}
1474 					break;
1475 
1476 				case "MovePrevious":
1477 					if (ActiveStepIndex > 0) {
1478 						WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex - 1);
1479 						int curStep = ActiveStepIndex;
1480 						OnPreviousButtonClick (args);
1481 						if (!args.Cancel) {
1482 							if (curStep == activeStepIndex)
1483 								ActiveStepIndex--;
1484 							if (history != null && activeStepIndex < curStep)
1485 								history.Remove (curStep);
1486 						}
1487 					}
1488 					break;
1489 
1490 				case "Move":
1491 					int newb = int.Parse (commandArg);
1492 					ActiveStepIndex = newb;
1493 					break;
1494 			}
1495 		}
1496 
UpdateViews()1497 		internal void UpdateViews ()
1498 		{
1499 			ChildControlsCreated = false;
1500 		}
1501 
Render(HtmlTextWriter writer)1502 		protected internal override void Render (HtmlTextWriter writer)
1503 		{
1504 			PrepareControlHierarchy ();
1505 			if (LayoutTemplate == null)
1506 				wizardTable.Render (writer);
1507 			else
1508 				RenderChildren (writer);
1509 		}
1510 
PrepareControlHierarchy()1511 		void PrepareControlHierarchy ()
1512 		{
1513 			if (LayoutTemplate == null) {
1514 				// header
1515 				if (!_headerCell.Initialized) {
1516 					if (String.IsNullOrEmpty (HeaderText))
1517 						_headerCell.Parent.Visible = false;
1518 					else
1519 						_headerCell.Text = HeaderText;
1520 				}
1521 
1522 				if (ActiveStep.StepType == WizardStepType.Complete)
1523 					_headerCell.Parent.Visible = false;
1524 			} else {
1525 				WizardStepCollection steps = WizardSteps;
1526 
1527 				if (steps == null || steps.Count == 0)
1528 					return;
1529 			}
1530 
1531 			// sidebar
1532 			if (stepDatalist != null) {
1533 				stepDatalist.SelectedIndex = ActiveStepIndex;
1534 				stepDatalist.DataBind ();
1535 
1536 				if (ActiveStep.StepType == WizardStepType.Complete)
1537 					stepDatalist.NamingContainer.Visible = false;
1538 			}
1539 
1540 			// content
1541 			TemplatedWizardStep templateStep = ActiveStep as TemplatedWizardStep;
1542 			if (templateStep != null) {
1543 				BaseWizardContainer contentContainer = templateStep.ContentTemplateContainer as BaseWizardContainer;
1544 				if (contentContainer != null)
1545 					contentContainer.PrepareControlHierarchy ();
1546 			}
1547 
1548 			// navigation
1549 			if (customNavigation != null) {
1550 				foreach (Control c in customNavigation.Values)
1551 					c.Visible = false;
1552 			}
1553 			_startNavContainer.Visible = false;
1554 			_stepNavContainer.Visible = false;
1555 			_finishNavContainer.Visible = false;
1556 
1557 			BaseWizardNavigationContainer currentNavContainer = GetCurrentNavContainer ();
1558 			if (currentNavContainer == null) {
1559 				if (_navigationCell != null)
1560 					_navigationCell.Parent.Visible = false;
1561 			} else {
1562 				currentNavContainer.Visible = true;
1563 				currentNavContainer.PrepareControlHierarchy ();
1564 				if (_navigationCell != null && !currentNavContainer.Visible)
1565 					_navigationCell.Parent.Visible = false;
1566 			}
1567 
1568 			foreach (object [] styleDef in styles)
1569 				((WebControl) styleDef [0]).ApplyStyle ((Style) styleDef [1]);
1570 		}
1571 
GetCurrentNavContainer()1572 		BaseWizardNavigationContainer GetCurrentNavContainer ()
1573 		{
1574 			if (customNavigation != null && customNavigation [ActiveStep] != null) {
1575 				return (BaseWizardNavigationContainer) customNavigation [ActiveStep];
1576 			}
1577 			else {
1578 				WizardStepType stepType = GetStepType (ActiveStep, ActiveStepIndex);
1579 				switch (stepType) {
1580 				case WizardStepType.Start:
1581 					return _startNavContainer;
1582 				case WizardStepType.Step:
1583 					return _stepNavContainer;
1584 				case WizardStepType.Finish:
1585 					return _finishNavContainer;
1586 				default:
1587 					return null;
1588 				}
1589 			}
1590 		}
1591 
1592 		sealed class TableCellNamingContainer : TableCell, INamingContainer, INonBindingContainer
1593 		{
1594 			string skipLinkText;
1595 			string clientId;
1596 			bool haveSkipLink;
1597 
RenderChildren(HtmlTextWriter writer)1598 			protected internal override void RenderChildren (HtmlTextWriter writer)
1599 			{
1600 				if (haveSkipLink) {
1601 					// <a href="#ID_SkipLink">
1602 					writer.AddAttribute (HtmlTextWriterAttribute.Href, "#" + clientId + "_SkipLink");
1603 					writer.RenderBeginTag (HtmlTextWriterTag.A);
1604 
1605 					// <img alt="" height="0" width="0" src="" style="border-width:0px;"/>
1606 					writer.AddAttribute (HtmlTextWriterAttribute.Alt, skipLinkText);
1607 					writer.AddAttribute (HtmlTextWriterAttribute.Height, "0");
1608 					writer.AddAttribute (HtmlTextWriterAttribute.Width, "0");
1609 
1610 					Page page = Page;
1611 					ClientScriptManager csm;
1612 
1613 					if (page != null)
1614 						csm = page.ClientScript;
1615 					else
1616 						csm = new ClientScriptManager (null);
1617 					writer.AddAttribute (HtmlTextWriterAttribute.Src, csm.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif"));
1618 					writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, "0px");
1619 					writer.RenderBeginTag (HtmlTextWriterTag.Img);
1620 					writer.RenderEndTag ();
1621 
1622 					writer.RenderEndTag (); // </a>
1623 				}
1624 
1625 				base.RenderChildren (writer);
1626 
1627 				if (haveSkipLink) {
1628 					writer.AddAttribute (HtmlTextWriterAttribute.Id, "SkipLink");
1629 					writer.RenderBeginTag (HtmlTextWriterTag.A);
1630 					writer.RenderEndTag ();
1631 				}
1632 			}
1633 
TableCellNamingContainer(string skipLinkText, string clientId)1634 			public TableCellNamingContainer (string skipLinkText, string clientId)
1635 			{
1636 				this.skipLinkText = skipLinkText;
1637 				this.clientId = clientId;
1638 				this.haveSkipLink = !String.IsNullOrEmpty (skipLinkText);
1639 			}
1640 		}
1641 
1642 		sealed class SideBarButtonTemplate: ITemplate
1643 		{
1644 			Wizard wizard;
1645 
SideBarButtonTemplate(Wizard wizard)1646 			public SideBarButtonTemplate (Wizard wizard)
1647 			{
1648 				this.wizard = wizard;
1649 			}
1650 
InstantiateIn(Control control)1651 			public void InstantiateIn (Control control)
1652 			{
1653 				LinkButton b = new LinkButton ();
1654 				wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1655 				control.Controls.Add (b);
1656 				control.DataBinding += Bound;
1657 			}
1658 
Bound(object s, EventArgs args)1659 			void Bound (object s, EventArgs args)
1660 			{
1661 				WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1662 				if (step != null) {
1663 					DataListItem c = (DataListItem) s;
1664 					LinkButton b = (LinkButton) c.Controls[0];
1665 					b.ID = SideBarButtonID;
1666 					b.CommandName = Wizard.MoveToCommandName;
1667 					b.CommandArgument = wizard.WizardSteps.IndexOf (step).ToString ();
1668 					b.Text = step.Name;
1669 					if (step.StepType == WizardStepType.Complete)
1670 						b.Enabled = false;
1671 				}
1672 			}
1673 		}
1674 
1675 		class WizardHeaderCell : TableCell, INamingContainer, INonBindingContainer
1676 		{
1677 			bool _initialized;
1678 
1679 			public bool Initialized {
1680 				get { return _initialized; }
1681 			}
1682 
WizardHeaderCell()1683 			public WizardHeaderCell ()
1684 			{
1685 			}
1686 
ConfirmInitState()1687 			public void ConfirmInitState ()
1688 			{
1689 				_initialized = true;
1690 			}
1691 		}
1692 
1693 		internal abstract class DefaultNavigationContainer : BaseWizardNavigationContainer
1694 		{
1695 			bool _isDefault;
1696 			Wizard _wizard;
1697 
1698 			protected Wizard Wizard {
1699 				get { return _wizard; }
1700 			}
1701 
DefaultNavigationContainer(Wizard wizard)1702 			protected DefaultNavigationContainer (Wizard wizard)
1703 			{
1704 				_wizard = wizard;
1705 			}
1706 
PrepareControlHierarchy()1707 			public override sealed void PrepareControlHierarchy ()
1708 			{
1709 				if (_isDefault)
1710 					UpdateState ();
1711 			}
1712 
UpdateState()1713 			protected abstract void UpdateState ();
1714 
ConfirmDefaultTemplate()1715 			public void ConfirmDefaultTemplate ()
1716 			{
1717 				_isDefault = true;
1718 			}
1719 
UpdateNavButtonState(string id, string text, string image, Style style)1720 			protected void UpdateNavButtonState (string id, string text, string image, Style style)
1721 			{
1722 				WebControl b = (WebControl) FindControl (id);
1723 				foreach (Control c in b.Parent.Controls)
1724 					c.Visible = b == c;
1725 
1726 				((IButtonControl) b).Text = text;
1727 				ImageButton imgbtn = b as ImageButton;
1728 				if (imgbtn != null)
1729 					imgbtn.ImageUrl = image;
1730 
1731 				b.ApplyStyle (style);
1732 			}
1733 		}
1734 
1735 		sealed class StartNavigationContainer : DefaultNavigationContainer
1736 		{
StartNavigationContainer(Wizard wizard)1737 			public StartNavigationContainer (Wizard wizard)
1738 				: base (wizard)
1739 			{
1740 			}
1741 
UpdateState()1742 			protected override void UpdateState ()
1743 			{
1744 				bool visible = false;
1745 
1746 				// next
1747 				if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex + 1)) {
1748 					visible = true;
1749 					UpdateNavButtonState (Wizard.StartNextButtonIDShort + Wizard.StartNextButtonType, Wizard.StartNextButtonText, Wizard.StartNextButtonImageUrl, Wizard.StartNextButtonStyle);
1750 				} else
1751 					((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1752 
1753 				// cancel
1754 				if (Wizard.DisplayCancelButton) {
1755 					visible = true;
1756 					UpdateNavButtonState (Wizard.CancelButtonIDShort + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1757 				} else
1758 					((Table) Controls [0]).Rows [0].Cells [1].Visible = false;
1759 
1760 				Visible = visible;
1761 			}
1762 		}
1763 
1764 		sealed class StepNavigationContainer : DefaultNavigationContainer
1765 		{
StepNavigationContainer(Wizard wizard)1766 			public StepNavigationContainer (Wizard wizard)
1767 				: base (wizard)
1768 			{
1769 			}
1770 
UpdateState()1771 			protected override void UpdateState ()
1772 			{
1773 				bool visible = false;
1774 				// previous
1775 				if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex - 1)) {
1776 					visible = true;
1777 					UpdateNavButtonState (Wizard.StepPreviousButtonIDShort + Wizard.StepPreviousButtonType, Wizard.StepPreviousButtonText, Wizard.StepPreviousButtonImageUrl, Wizard.StepPreviousButtonStyle);
1778 				} else
1779 					((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1780 
1781 				// next
1782 				if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex + 1)) {
1783 					visible = true;
1784 					UpdateNavButtonState (Wizard.StepNextButtonIDShort + Wizard.StepNextButtonType, Wizard.StepNextButtonText, Wizard.StepNextButtonImageUrl, Wizard.StepNextButtonStyle);
1785 				} else
1786 					((Table) Controls [0]).Rows [0].Cells [1].Visible = false;
1787 
1788 				// cancel
1789 				if (Wizard.DisplayCancelButton) {
1790 					visible = true;
1791 					UpdateNavButtonState (Wizard.CancelButtonIDShort + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1792 				} else
1793 					((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
1794 
1795 				Visible = visible;
1796 			}
1797 		}
1798 
1799 		sealed class FinishNavigationContainer : DefaultNavigationContainer
1800 		{
FinishNavigationContainer(Wizard wizard)1801 			public FinishNavigationContainer (Wizard wizard)
1802 				: base (wizard)
1803 			{
1804 			}
1805 
UpdateState()1806 			protected override void UpdateState ()
1807 			{
1808 				// previous
1809 				int previous = Wizard.ActiveStepIndex - 1;
1810 				if (previous >= 0 && Wizard.AllowNavigationToStep (previous)) {
1811 					UpdateNavButtonState (Wizard.FinishPreviousButtonIDShort + Wizard.FinishPreviousButtonType, Wizard.FinishPreviousButtonText, Wizard.FinishPreviousButtonImageUrl, Wizard.FinishPreviousButtonStyle);
1812 				} else
1813 					((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1814 
1815 				// finish
1816 				UpdateNavButtonState (Wizard.FinishButtonIDShort + Wizard.FinishCompleteButtonType, Wizard.FinishCompleteButtonText, Wizard.FinishCompleteButtonImageUrl, Wizard.FinishCompleteButtonStyle);
1817 
1818 				// cancel
1819 				if (Wizard.DisplayCancelButton) {
1820 					UpdateNavButtonState (Wizard.CancelButtonIDShort + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1821 				} else
1822 					((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
1823 			}
1824 		}
1825 
1826 		internal class BaseWizardContainer : Table, INamingContainer, INonBindingContainer
1827 		{
1828 			public TableCell InnerCell {
1829 				get { return Rows [0].Cells [0]; }
1830 			}
1831 
BaseWizardContainer()1832 			internal BaseWizardContainer ()
1833 			{
1834 				InitTable ();
1835 			}
1836 
InitTable()1837 			void InitTable () {
1838 				TableRow row = new TableRow ();
1839 				TableCell cell = new TableCell ();
1840 
1841 				cell.ControlStyle.Width = Unit.Percentage (100);
1842 				cell.ControlStyle.Height = Unit.Percentage (100);
1843 
1844 				row.Cells.Add (cell);
1845 
1846 				this.ControlStyle.Width = Unit.Percentage (100);
1847 				this.ControlStyle.Height = Unit.Percentage (100);
1848 				this.CellPadding = 0;
1849 				this.CellSpacing = 0;
1850 
1851 				this.Rows.Add (row);
1852 			}
1853 
PrepareControlHierarchy()1854 			public virtual void PrepareControlHierarchy ()
1855 			{
1856 			}
1857 		}
1858 
1859 		internal class BaseWizardNavigationContainer : Control, INamingContainer, INonBindingContainer
1860 		{
BaseWizardNavigationContainer()1861 			internal BaseWizardNavigationContainer ()
1862 			{
1863 			}
1864 
PrepareControlHierarchy()1865 			public virtual void PrepareControlHierarchy ()
1866 			{
1867 			}
1868 		}
1869 
1870 		internal abstract class DefaultContentContainer : BaseWizardContainer
1871 		{
1872 			bool _isDefault;
1873 			Wizard _wizard;
1874 
1875 			protected bool IsDefaultTemplate {
1876 				get { return _isDefault; }
1877 			}
1878 
1879 			protected Wizard Wizard {
1880 				get { return _wizard; }
1881 			}
1882 
DefaultContentContainer(Wizard wizard)1883 			protected DefaultContentContainer (Wizard wizard)
1884 			{
1885 				_wizard = wizard;
1886 			}
1887 
PrepareControlHierarchy()1888 			public override sealed void PrepareControlHierarchy ()
1889 			{
1890 				if (_isDefault)
1891 					UpdateState ();
1892 			}
1893 
UpdateState()1894 			protected abstract void UpdateState ();
1895 
ConfirmDefaultTemplate()1896 			public void ConfirmDefaultTemplate ()
1897 			{
1898 				_isDefault = true;
1899 			}
1900 		}
1901 	}
1902 }
1903 
1904