New test.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Wizard.cs
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 #if NET_2_0
32
33 using System;
34 using System.Collections;
35 using System.ComponentModel;
36
37 namespace System.Web.UI.WebControls
38 {
39         [DefaultEventAttribute ("FinishButtonClick")]
40         [BindableAttribute (false)]
41         [DesignerAttribute ("System.Web.UI.Design.WebControls.WizardDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42         [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>")]
43         public class Wizard: CompositeControl
44         {
45                 public static readonly string CancelCommandName = "Cancel";
46                 public static readonly string MoveCompleteCommandName = "MoveComplete";
47                 public static readonly string MoveNextCommandName = "MoveNext";
48                 public static readonly string MovePreviousCommandName = "MovePrevious";
49                 public static readonly string MoveToCommandName = "Move";
50                 
51                 protected static readonly string CancelButtonID = "CancelButton";
52                 protected static readonly string CustomFinishButtonID = "CustomFinishButton";
53                 protected static readonly string CustomNextButtonID = "CustomNextButton";
54                 protected static readonly string CustomPreviousButtonID = "CustomPreviousButton";
55                 protected static readonly string DataListID = "SideBarList";
56                 protected static readonly string FinishButtonID = "FinishButton";
57                 protected static readonly string FinishPreviousButtonID = "FinishPreviousButton";
58                 protected static readonly string SideBarButtonID = "SideBarButton";
59                 protected static readonly string StartNextButtonID = "StartNextButton";
60                 protected static readonly string StepNextButtonID = "StepNextButton";
61                 protected static readonly string StepPreviousButtonID = "StepPreviousButton";
62                 
63                 WizardStepCollection steps;
64                 
65                 // View state
66                 
67                 TableItemStyle stepStyle;
68                 TableItemStyle sideBarStyle;
69                 TableItemStyle headerStyle;
70                 TableItemStyle navigationStyle;
71                 Style sideBarButtonStyle;
72                 
73                 Style cancelButtonStyle;
74                 Style finishCompleteButtonStyle;
75                 Style finishPreviousButtonStyle;
76                 Style startNextButtonStyle;
77                 Style stepNextButtonStyle;
78                 Style stepPreviousButtonStyle;
79                 Style navigationButtonStyle;
80                 
81                 ITemplate finishNavigationTemplate;
82                 ITemplate startNavigationTemplate;
83                 ITemplate stepNavigationTemplate;
84                 ITemplate headerTemplate;
85                 ITemplate sideBarTemplate;
86                 
87                 // Control state
88                 
89                 int activeStepIndex;
90                 ArrayList history;
91
92                 Table wizardTable;
93                 MultiView multiView;
94                 DataList stepDatalist;
95                 ArrayList styles = new ArrayList ();
96                 SideBarButtonTemplate sideBarItemTemplate;
97                 
98                 private static readonly object ActiveStepChangedEvent = new object();
99                 private static readonly object CancelButtonClickEvent = new object();
100                 private static readonly object FinishButtonClickEvent = new object();
101                 private static readonly object NextButtonClickEvent = new object();
102                 private static readonly object PreviousButtonClickEvent = new object();
103                 private static readonly object SideBarButtonClickEvent = new object();
104                 
105                 public Wizard ()
106                 {
107                         sideBarItemTemplate = new SideBarButtonTemplate (this);
108                 }
109                 
110                 public event EventHandler ActiveStepChanged {
111                         add { Events.AddHandler (ActiveStepChangedEvent, value); }
112                         remove { Events.RemoveHandler (ActiveStepChangedEvent, value); }
113                 }
114                 
115                 public event EventHandler CancelButtonClick {
116                         add { Events.AddHandler (CancelButtonClickEvent, value); }
117                         remove { Events.RemoveHandler (CancelButtonClickEvent, value); }
118                 }
119                 
120                 public event WizardNavigationEventHandler FinishButtonClick {
121                         add { Events.AddHandler (FinishButtonClickEvent, value); }
122                         remove { Events.RemoveHandler (FinishButtonClickEvent, value); }
123                 }
124                 
125                 public event WizardNavigationEventHandler NextButtonClick {
126                         add { Events.AddHandler (NextButtonClickEvent, value); }
127                         remove { Events.RemoveHandler (NextButtonClickEvent, value); }
128                 }
129                 
130                 public event WizardNavigationEventHandler PreviousButtonClick {
131                         add { Events.AddHandler (PreviousButtonClickEvent, value); }
132                         remove { Events.RemoveHandler (PreviousButtonClickEvent, value); }
133                 }
134                 
135                 public event WizardNavigationEventHandler SideBarButtonClick {
136                         add { Events.AddHandler (SideBarButtonClickEvent, value); }
137                         remove { Events.RemoveHandler (SideBarButtonClickEvent, value); }
138                 }
139                 
140                 protected virtual void OnActiveStepChanged (object source, EventArgs e)
141                 {
142                         if (Events != null) {
143                                 EventHandler eh = (EventHandler) Events [ActiveStepChangedEvent];
144                                 if (eh != null) eh (source, e);
145                         }
146                 }
147                 
148                 protected virtual void OnCancelButtonClick (EventArgs e)
149                 {
150                         if (Events != null) {
151                                 EventHandler eh = (EventHandler) Events [CancelButtonClickEvent];
152                                 if (eh != null) eh (this, e);
153                         }
154                 }
155                 
156                 protected virtual void OnFinishButtonClick (WizardNavigationEventArgs e)
157                 {
158                         if (Events != null) {
159                                 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [FinishButtonClickEvent];
160                                 if (eh != null) eh (this, e);
161                         }
162                 }
163                 
164                 protected virtual void OnNextButtonClick (WizardNavigationEventArgs e)
165                 {
166                         if (Events != null) {
167                                 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [NextButtonClickEvent];
168                                 if (eh != null) eh (this, e);
169                         }
170                 }
171                 
172                 protected virtual void OnPreviousButtonClick (WizardNavigationEventArgs e)
173                 {
174                         if (Events != null) {
175                                 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [PreviousButtonClickEvent];
176                                 if (eh != null) eh (this, e);
177                         }
178                 }
179                 
180                 protected virtual void OnSideBarButtonClick (WizardNavigationEventArgs e)
181                 {
182                         if (Events != null) {
183                                 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [SideBarButtonClickEvent];
184                                 if (eh != null) eh (this, e);
185                         }
186                 }
187                 
188             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
189             [BrowsableAttribute (false)]
190                 public WizardStepBase ActiveStep {
191                         get {
192                                 if (ActiveStepIndex < -1 || ActiveStepIndex >= WizardSteps.Count)
193                                         throw new InvalidOperationException ("ActiveStepIndex has an invalid value.");
194                                 if (ActiveStepIndex == -1) return null;
195                                 return WizardSteps [activeStepIndex];
196                         }
197                 }
198                 
199             [DefaultValueAttribute (-1)]
200             [ThemeableAttribute (false)]
201                 public virtual int ActiveStepIndex {
202                         get {
203                                 if (WizardSteps.Count == 0)
204                                         return -1;
205
206                                 return activeStepIndex;
207                         }
208                         set {
209                                 if (!AllowNavigationToStep (value))
210                                         return;
211                                 if (activeStepIndex != value) {
212                                         if (history == null) history = new ArrayList ();
213                                         history.Insert (0, activeStepIndex);
214                                 }
215                                 activeStepIndex = value;
216                                 UpdateControls ();
217                                 OnActiveStepChanged (this, EventArgs.Empty);
218                         }
219                 }
220                 
221             [UrlPropertyAttribute]
222             [DefaultValueAttribute ("")]
223             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
224                 public virtual string CancelButtonImageUrl {
225                         get {
226                                 object v = ViewState ["CancelButtonImageUrl"];
227                                 return v != null ? (string)v : string.Empty;
228                         }
229                         set {
230                                 ViewState ["CancelButtonImageUrl"] = value;
231                                 UpdateControls ();
232                         }
233                 }
234                 
235             [DefaultValueAttribute (null)]
236             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
237             [NotifyParentPropertyAttribute (true)]
238             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
239                 public Style CancelButtonStyle {
240                         get {
241                                 if (cancelButtonStyle == null) {
242                                         cancelButtonStyle = new Style ();
243                                         if (IsTrackingViewState)
244                                                 ((IStateManager)cancelButtonStyle).TrackViewState ();
245                                 }
246                                 return cancelButtonStyle;
247                         }
248                 }
249                 
250             [LocalizableAttribute (true)]
251                 public virtual string CancelButtonText {
252                         get {
253                                 object v = ViewState ["CancelButtonText"];
254                                 return v != null ? (string)v : "Cancel";
255                         }
256                         set {
257                                 ViewState ["CancelButtonText"] = value;
258                                 UpdateControls ();
259                         }
260                 }
261                 
262             [DefaultValueAttribute (ButtonType.Button)]
263                 public virtual ButtonType CancelButtonType {
264                         get {
265                                 object v = ViewState ["CancelButtonType"];
266                                 return v != null ? (ButtonType)v : ButtonType.Button;
267                         }
268                         set {
269                                 ViewState ["CancelButtonType"] = value;
270                                 UpdateControls ();
271                         }
272                 }
273                 
274             [UrlPropertyAttribute]
275             [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
276             [DefaultValueAttribute ("")]
277                 public virtual string CancelDestinationPageUrl {
278                         get {
279                                 object v = ViewState ["CancelDestinationPageUrl"];
280                                 return v != null ? (string)v : string.Empty;
281                         }
282                         set {
283                                 ViewState ["CancelDestinationPageUrl"] = value;
284                         }
285                 }
286             
287             [DefaultValueAttribute (0)]
288                 public virtual int CellPadding {
289                         get {
290                                 object v = ViewState ["CellPadding"];
291                                 return v != null ? (int)v : 0;
292                         }
293                         set {
294                                 ViewState ["CellPadding"] = value;
295                                 UpdateControls ();
296                         }
297                 }
298                 
299             [DefaultValueAttribute (0)]
300                 public virtual int CellSpacing {
301                         get {
302                                 object v = ViewState ["CellSpacing"];
303                                 return v != null ? (int)v : 0;
304                         }
305                         set {
306                                 ViewState ["CellSpacing"] = value;
307                                 UpdateControls ();
308                         }
309                 }
310                 
311             [DefaultValueAttribute (false)]
312             [ThemeableAttribute (false)]
313                 public virtual bool DisplayCancelButton {
314                         get {
315                                 object v = ViewState ["DisplayCancelButton"];
316                                 return v != null ? (bool) v : false;
317                         }
318                         set {
319                                 ViewState ["DisplayCancelButton"] = value;
320                                 UpdateControls ();
321                         }
322                 }
323                 
324             [DefaultValueAttribute (true)]
325             [ThemeableAttribute (false)]
326                 public virtual bool DisplaySideBar {
327                         get {
328                                 object v = ViewState ["DisplaySideBar"];
329                                 return v != null ? (bool) v : true;
330                         }
331                         set {
332                                 ViewState ["DisplaySideBar"] = value;
333                                 UpdateControls ();
334                         }
335                 }
336                 
337             [UrlPropertyAttribute]
338             [DefaultValueAttribute ("")]
339             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
340                 public virtual string FinishCompleteButtonImageUrl {
341                         get {
342                                 object v = ViewState ["FinishCompleteButtonImageUrl"];
343                                 return v != null ? (string)v : string.Empty;
344                         }
345                         set {
346                                 ViewState ["FinishCompleteButtonImageUrl"] = value;
347                                 UpdateControls ();
348                         }
349                 }
350                 
351             [DefaultValueAttribute (null)]
352             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
353             [NotifyParentPropertyAttribute (true)]
354             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
355                 public Style FinishCompleteButtonStyle {
356                         get {
357                                 if (finishCompleteButtonStyle == null) {
358                                         finishCompleteButtonStyle = new Style ();
359                                         if (IsTrackingViewState)
360                                                 ((IStateManager)finishCompleteButtonStyle).TrackViewState ();
361                                 }
362                                 return finishCompleteButtonStyle;
363                         }
364                 }
365                 
366             [LocalizableAttribute (true)]
367                 public virtual string FinishCompleteButtonText {
368                         get {
369                                 object v = ViewState ["FinishCompleteButtonText"];
370                                 return v != null ? (string)v : "Finish";
371                         }
372                         set {
373                                 ViewState ["FinishCompleteButtonText"] = value;
374                                 UpdateControls ();
375                         }
376                 }
377                 
378             [DefaultValueAttribute (ButtonType.Button)]
379                 public virtual ButtonType FinishCompleteButtonType {
380                         get {
381                                 object v = ViewState ["FinishCompleteButtonType"];
382                                 return v != null ? (ButtonType)v : ButtonType.Button;
383                         }
384                         set {
385                                 ViewState ["FinishCompleteButtonType"] = value;
386                                 UpdateControls ();
387                         }
388                 }
389                 
390             [UrlPropertyAttribute]
391             [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
392             [DefaultValueAttribute ("")]
393                 public virtual string FinishDestinationPageUrl {
394                         get {
395                                 object v = ViewState ["FinishDestinationPageUrl"];
396                                 return v != null ? (string)v : string.Empty;
397                         }
398                         set {
399                                 ViewState ["FinishDestinationPageUrl"] = value;
400                         }
401                 }
402             
403                 [DefaultValue (null)]
404                 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
405                 [PersistenceMode (PersistenceMode.InnerProperty)]
406             [Browsable (false)]
407                 public virtual ITemplate FinishNavigationTemplate {
408                         get { return finishNavigationTemplate; }
409                         set { finishNavigationTemplate = value; UpdateControls (); }
410                 }
411                 
412             [UrlPropertyAttribute]
413             [DefaultValueAttribute ("")]
414             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
415                 public virtual string FinishPreviousButtonImageUrl {
416                         get {
417                                 object v = ViewState ["FinishPreviousButtonImageUrl"];
418                                 return v != null ? (string)v : string.Empty;
419                         }
420                         set {
421                                 ViewState ["FinishPreviousButtonImageUrl"] = value;
422                                 UpdateControls ();
423                         }
424                 }
425                 
426             [DefaultValueAttribute (null)]
427             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
428             [NotifyParentPropertyAttribute (true)]
429             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
430                 public Style FinishPreviousButtonStyle {
431                         get {
432                                 if (finishPreviousButtonStyle == null) {
433                                         finishPreviousButtonStyle = new Style ();
434                                         if (IsTrackingViewState)
435                                                 ((IStateManager)finishPreviousButtonStyle).TrackViewState ();
436                                 }
437                                 return finishPreviousButtonStyle;
438                         }
439                 }
440                 
441             [LocalizableAttribute (true)]
442                 public virtual string FinishPreviousButtonText {
443                         get {
444                                 object v = ViewState ["FinishPreviousButtonText"];
445                                 return v != null ? (string)v : "Previous";
446                         }
447                         set {
448                                 ViewState ["FinishPreviousButtonText"] = value;
449                                 UpdateControls ();
450                         }
451                 }
452                 
453             [DefaultValueAttribute (ButtonType.Button)]
454                 public virtual ButtonType FinishPreviousButtonType {
455                         get {
456                                 object v = ViewState ["FinishPreviousButtonType"];
457                                 return v != null ? (ButtonType)v : ButtonType.Button;
458                         }
459                         set {
460                                 ViewState ["FinishPreviousButtonType"] = value;
461                                 UpdateControls ();
462                         }
463                 }
464                 
465             [DefaultValueAttribute (null)]
466             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
467             [NotifyParentPropertyAttribute (true)]
468             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
469                 public TableItemStyle HeaderStyle {
470                         get {
471                                 if (headerStyle == null) {
472                                         headerStyle = new TableItemStyle ();
473                                         if (IsTrackingViewState)
474                                                 ((IStateManager)headerStyle).TrackViewState ();
475                                 }
476                                 return headerStyle;
477                         }
478                 }
479                 
480                 [DefaultValue (null)]
481                 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
482                 [PersistenceMode (PersistenceMode.InnerProperty)]
483             [Browsable (false)]
484                 public virtual ITemplate HeaderTemplate {
485                         get { return headerTemplate; }
486                         set { headerTemplate = value; UpdateControls (); }
487                 }
488                 
489             [DefaultValueAttribute ("")]
490             [LocalizableAttribute (true)]
491                 public virtual string HeaderText {
492                         get {
493                                 object v = ViewState ["HeaderText"];
494                                 return v != null ? (string)v : string.Empty;
495                         }
496                         set {
497                                 ViewState ["HeaderText"] = value;
498                                 UpdateControls ();
499                         }
500                 }
501                 
502             [DefaultValueAttribute (null)]
503             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
504             [NotifyParentPropertyAttribute (true)]
505             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
506                 public Style NavigationButtonStyle {
507                         get {
508                                 if (navigationButtonStyle == null) {
509                                         navigationButtonStyle = new Style ();
510                                         if (IsTrackingViewState)
511                                                 ((IStateManager)navigationButtonStyle).TrackViewState ();
512                                 }
513                                 return navigationButtonStyle;
514                         }
515                 }
516                 
517             [DefaultValueAttribute (null)]
518             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
519             [NotifyParentPropertyAttribute (true)]
520             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
521                 public TableItemStyle NavigationStyle {
522                         get {
523                                 if (navigationStyle == null) {
524                                         navigationStyle = new TableItemStyle ();
525                                         if (IsTrackingViewState)
526                                                 ((IStateManager)navigationStyle).TrackViewState ();
527                                 }
528                                 return navigationStyle;
529                         }
530                 }
531                 
532             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
533             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
534             [DefaultValueAttribute (null)]
535             [NotifyParentPropertyAttribute (true)]
536                 public TableItemStyle SideBarStyle {
537                         get {
538                                 if (sideBarStyle == null) {
539                                         sideBarStyle = new TableItemStyle ();
540                                         if (IsTrackingViewState)
541                                                 ((IStateManager)sideBarStyle).TrackViewState ();
542                                 }
543                                 return sideBarStyle;
544                         }
545                 }
546                 
547             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
548             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
549             [DefaultValueAttribute (null)]
550             [NotifyParentPropertyAttribute (true)]
551                 public Style SideBarButtonStyle {
552                         get {
553                                 if (sideBarButtonStyle == null) {
554                                         sideBarButtonStyle = new Style ();
555                                         if (IsTrackingViewState)
556                                                 ((IStateManager)sideBarButtonStyle).TrackViewState ();
557                                 }
558                                 return sideBarButtonStyle;
559                         }
560                 }
561                 
562                 [DefaultValue (null)]
563                 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
564                 [PersistenceMode (PersistenceMode.InnerProperty)]
565             [Browsable (false)]
566                 public virtual ITemplate SideBarTemplate {
567                         get { return sideBarTemplate; }
568                         set { sideBarTemplate = value; UpdateControls (); }
569                 }
570
571                 [Localizable (true)]
572                 [MonoTODO]
573                 public virtual string SkipLinkText 
574                 {
575                         get
576                         {
577                                 object v = ViewState ["SkipLinkText"];
578                                 return v != null ? (string) v : "Skip Navigation Links.";
579                         }
580                         set
581                         {
582                                 ViewState ["SkipLinkText"] = value;
583                         }
584                 }
585                 
586                 [DefaultValue (null)]
587                 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
588                 [PersistenceMode (PersistenceMode.InnerProperty)]
589             [Browsable (false)]
590                 public virtual ITemplate StartNavigationTemplate {
591                         get { return startNavigationTemplate; }
592                         set { startNavigationTemplate = value; UpdateControls (); }
593                 }
594                 
595             [UrlPropertyAttribute]
596             [DefaultValueAttribute ("")]
597             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
598                 public virtual string StartNextButtonImageUrl {
599                         get {
600                                 object v = ViewState ["StartNextButtonImageUrl"];
601                                 return v != null ? (string)v : string.Empty;
602                         }
603                         set {
604                                 ViewState ["StartNextButtonImageUrl"] = value;
605                                 UpdateControls ();
606                         }
607                 }
608                 
609             [DefaultValueAttribute (null)]
610             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
611             [NotifyParentPropertyAttribute (true)]
612             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
613                 public Style StartNextButtonStyle {
614                         get {
615                                 if (startNextButtonStyle == null) {
616                                         startNextButtonStyle = new Style ();
617                                         if (IsTrackingViewState)
618                                                 ((IStateManager)startNextButtonStyle).TrackViewState ();
619                                 }
620                                 return startNextButtonStyle;
621                         }
622                 }
623                 
624             [LocalizableAttribute (true)]
625                 public virtual string StartNextButtonText {
626                         get {
627                                 object v = ViewState ["StartNextButtonText"];
628                                 return v != null ? (string)v : "Next";
629                         }
630                         set {
631                                 ViewState ["StartNextButtonText"] = value;
632                                 UpdateControls ();
633                         }
634                 }
635                 
636             [DefaultValueAttribute (ButtonType.Button)]
637                 public virtual ButtonType StartNextButtonType {
638                         get {
639                                 object v = ViewState ["StartNextButtonType"];
640                                 return v != null ? (ButtonType)v : ButtonType.Button;
641                         }
642                         set {
643                                 ViewState ["StartNextButtonType"] = value;
644                                 UpdateControls ();
645                         }
646                 }
647                 
648                 [DefaultValue (null)]
649                 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
650                 [PersistenceMode (PersistenceMode.InnerProperty)]
651             [Browsable (false)]
652                 public virtual ITemplate StepNavigationTemplate {
653                         get { return stepNavigationTemplate; }
654                         set { stepNavigationTemplate = value; UpdateControls (); }
655                 }
656                 
657             [UrlPropertyAttribute]
658             [DefaultValueAttribute ("")]
659             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
660                 public virtual string StepNextButtonImageUrl {
661                         get {
662                                 object v = ViewState ["StepNextButtonImageUrl"];
663                                 return v != null ? (string)v : string.Empty;
664                         }
665                         set {
666                                 ViewState ["StepNextButtonImageUrl"] = value;
667                                 UpdateControls ();
668                         }
669                 }
670                 
671             [DefaultValueAttribute (null)]
672             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
673             [NotifyParentPropertyAttribute (true)]
674             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
675                 public Style StepNextButtonStyle {
676                         get {
677                                 if (stepNextButtonStyle == null) {
678                                         stepNextButtonStyle = new Style ();
679                                         if (IsTrackingViewState)
680                                                 ((IStateManager)stepNextButtonStyle).TrackViewState ();
681                                 }
682                                 return stepNextButtonStyle;
683                         }
684                 }
685                 
686             [LocalizableAttribute (true)]
687                 public virtual string StepNextButtonText {
688                         get {
689                                 object v = ViewState ["StepNextButtonText"];
690                                 return v != null ? (string)v : "Next";
691                         }
692                         set {
693                                 ViewState ["StepNextButtonText"] = value;
694                                 UpdateControls ();
695                         }
696                 }
697                 
698             [DefaultValueAttribute (ButtonType.Button)]
699                 public virtual ButtonType StepNextButtonType {
700                         get {
701                                 object v = ViewState ["StepNextButtonType"];
702                                 return v != null ? (ButtonType)v : ButtonType.Button;
703                         }
704                         set {
705                                 ViewState ["StepNextButtonType"] = value;
706                                 UpdateControls ();
707                         }
708                 }
709                 
710             [UrlPropertyAttribute]
711             [DefaultValueAttribute ("")]
712             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
713                 public virtual string StepPreviousButtonImageUrl {
714                         get {
715                                 object v = ViewState ["StepPreviousButtonImageUrl"];
716                                 return v != null ? (string)v : string.Empty;
717                         }
718                         set {
719                                 ViewState ["StepPreviousButtonImageUrl"] = value;
720                                 UpdateControls ();
721                         }
722                 }
723                 
724             [DefaultValueAttribute (null)]
725             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
726             [NotifyParentPropertyAttribute (true)]
727             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
728                 public Style StepPreviousButtonStyle {
729                         get {
730                                 if (stepPreviousButtonStyle == null) {
731                                         stepPreviousButtonStyle = new Style ();
732                                         if (IsTrackingViewState)
733                                                 ((IStateManager)stepPreviousButtonStyle).TrackViewState ();
734                                 }
735                                 return stepPreviousButtonStyle;
736                         }
737                 }
738                 
739             [LocalizableAttribute (true)]
740                 public virtual string StepPreviousButtonText {
741                         get {
742                                 object v = ViewState ["StepPreviousButtonText"];
743                                 return v != null ? (string)v : "Previous";
744                         }
745                         set {
746                                 ViewState ["StepPreviousButtonText"] = value;
747                                 UpdateControls ();
748                         }
749                 }
750                 
751             [DefaultValueAttribute (ButtonType.Button)]
752                 public virtual ButtonType StepPreviousButtonType {
753                         get {
754                                 object v = ViewState ["StepPreviousButtonType"];
755                                 return v != null ? (ButtonType)v : ButtonType.Button;
756                         }
757                         set {
758                                 ViewState ["StepPreviousButtonType"] = value;
759                                 UpdateControls ();
760                         }
761                 }
762                 
763             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
764             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
765             [DefaultValueAttribute (null)]
766             [NotifyParentPropertyAttribute (true)]
767                 public TableItemStyle StepStyle {
768                         get {
769                                 if (stepStyle == null) {
770                                         stepStyle = new TableItemStyle ();
771                                         if (IsTrackingViewState)
772                                                 ((IStateManager)stepStyle).TrackViewState ();
773                                 }
774                                 return stepStyle;
775                         }
776                 }
777                 
778             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
779             [EditorAttribute ("System.Web.UI.Design.WebControls.WizardStepCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
780             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
781             [ThemeableAttribute (false)]
782                 public virtual WizardStepCollection WizardSteps {
783                         get {
784                                 if (steps == null)
785                                         steps = new WizardStepCollection (this);
786                                 return steps;
787                         }
788                 }
789
790                 [MonoTODO]
791                 protected virtual new HtmlTextWriterTag TagKey
792                 {
793                         get {
794                                 return HtmlTextWriterTag.Table;
795                         }
796                 }
797
798                 internal virtual ITemplate SideBarItemTemplate
799                 {
800                         get { return sideBarItemTemplate; }
801                 }
802                 
803                 public ICollection GetHistory ()
804                 {
805                         if (history == null) history = new ArrayList ();
806                         return history;
807                 }
808                 
809                 public void MoveTo (WizardStepBase wizardStep)
810                 {
811                         if (wizardStep == null) throw new ArgumentNullException ("wizardStep");
812                         
813                         int i = WizardSteps.IndexOf (wizardStep);
814                         if (i == -1) throw new ArgumentException ("The provided wizard step does not belong to this wizard.");
815                         
816                         ActiveStepIndex = i;
817                 }
818                 
819                 public WizardStepType GetStepType (WizardStepBase wizardStep, int index)
820                 {
821                         if (wizardStep.StepType == WizardStepType.Auto) {
822                                 if (index == WizardSteps.Count - 1)
823                                         return WizardStepType.Finish;
824                                 else if (index == 0)
825                                         return WizardStepType.Start;
826                                 else
827                                         return WizardStepType.Step;
828                         } else
829                                 return wizardStep.StepType;
830                          
831                 }
832                 
833                 protected virtual bool AllowNavigationToStep (int index)
834                 {
835                         if (index < 0 || index >= WizardSteps.Count) return false;
836                         if (history == null) return true;
837                         if (!history.Contains (index)) return true;
838                         return WizardSteps [index].AllowReturn;
839                 } 
840                 
841                 protected internal override void OnInit (EventArgs e)
842                 {
843                         Page.RegisterRequiresControlState (this);
844                         base.OnInit (e);
845                 }
846                 
847                 protected override ControlCollection CreateControlCollection ()
848                 {
849                         ControlCollection col = new ControlCollection (this);
850                         col.SetReadonly (true);
851                         return col;
852                 }
853                 
854                 protected internal override void CreateChildControls ()
855                 {
856                         CreateControlHierarchy ();
857                 }
858                 
859                 protected virtual void CreateControlHierarchy ()
860                 {
861                         styles.Clear ();
862
863                         wizardTable = new Table ();
864                         wizardTable.CellPadding = CellPadding; 
865                         wizardTable.CellSpacing = CellSpacing; 
866                         wizardTable.ID = this.ID;
867                         
868                         AddHeaderRow (wizardTable);
869                         
870                         TableRow viewRow = new TableRow ();
871                         TableCell viewCell = new TableCell ();
872
873                         if (multiView == null)
874                         {
875                                 multiView = new MultiView();
876                                 foreach (View v in WizardSteps) {
877                                         if (v is TemplatedWizardStep) 
878                                                 InstantiateTemplateStep ((TemplatedWizardStep) v);
879                                         multiView.Views.Add (v);
880                                 }
881                         }
882                         
883                         multiView.ActiveViewIndex = activeStepIndex;
884                         
885                         RegisterApplyStyle (viewCell, StepStyle);
886                         viewCell.Controls.Add (multiView);
887                         viewRow.Cells.Add (viewCell);
888                         viewRow.Height = new Unit ("100%");
889                         wizardTable.Rows.Add (viewRow);
890                         
891                         TableRow buttonRow = new TableRow ();
892                         TableCell buttonCell = new TableCell ();
893                         buttonCell.HorizontalAlign = HorizontalAlign.Right;
894                         CreateButtonBar (buttonCell);
895                         buttonRow.Cells.Add (buttonCell);
896                         wizardTable.Rows.Add (buttonRow);
897                         
898                         if (DisplaySideBar && ActiveStep.StepType != WizardStepType.Complete) {
899                                 Table contentTable = wizardTable;
900                                 contentTable.Height = new Unit ("100%");
901                                 contentTable.Width = new Unit ("100%");
902                                 
903                                 wizardTable = new Table ();
904                                 wizardTable.CellPadding = CellPadding; 
905                                 wizardTable.CellSpacing = CellSpacing;
906                                 TableRow row = new TableRow ();
907
908                                 TableCellNamingContainer sideBarCell = new TableCellNamingContainer ();
909                                 sideBarCell.ControlStyle.Height = Unit.Percentage (100);
910                                 CreateSideBar (sideBarCell);
911                                 row.Cells.Add (sideBarCell);
912                                 
913                                 TableCell contentCell = new TableCell ();
914                                 contentCell.Controls.Add (contentTable);
915                                 contentCell.Height = new Unit ("100%");
916                                 row.Cells.Add (contentCell);
917                                 
918                                 wizardTable.Rows.Add (row);
919                         }
920                         
921                         Controls.SetReadonly (false);
922                         Controls.Add (wizardTable);
923                         Controls.SetReadonly (true);
924                 }
925
926                 internal virtual void InstantiateTemplateStep(TemplatedWizardStep step)
927                 {
928                         step.InstantiateInContainer ();
929
930                         if (step.CustomNavigationTemplate != null) {
931                                 WizardStepType stepType = GetStepType (step, ActiveStepIndex);
932                                 switch (stepType) {
933                                 case WizardStepType.Start:
934                                         startNavigationTemplate = step.CustomNavigationTemplate;
935                                         break;
936
937                                 case WizardStepType.Step:
938                                         stepNavigationTemplate = step.CustomNavigationTemplate;
939                                         break;
940
941                                 case WizardStepType.Finish:
942                                         finishNavigationTemplate = step.CustomNavigationTemplate;
943                                         break;
944                                 }
945                         }
946                 }
947                 
948                 void CreateButtonBar (TableCell buttonBarCell)
949                 {
950                         Table t = new Table ();
951                         t.CellPadding = 5;
952                         t.CellSpacing = 5;
953                         TableRow row = new TableRow ();
954                         RegisterApplyStyle (buttonBarCell, NavigationStyle);
955                         
956                         WizardStepType stepType = GetStepType (ActiveStep, ActiveStepIndex);
957                         switch (stepType) {
958                                 case WizardStepType.Start:
959                                         if (startNavigationTemplate != null) {
960                                                 AddTemplateButtonBar (buttonBarCell, startNavigationTemplate, StartNextButtonID, CancelButtonID);
961                                                 return;
962                                         } else {
963                                                 if (AllowNavigationToStep (ActiveStepIndex + 1))
964                                                         AddButtonCell (row, CreateButton (StartNextButtonID, MoveNextCommandName, StartNextButtonType, StartNextButtonText, StartNextButtonImageUrl, StartNextButtonStyle));
965                                                 if (DisplayCancelButton)
966                                                         AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
967                                         }
968                                         break;
969                                 case WizardStepType.Step:
970                                         if (stepNavigationTemplate != null) {
971                                                 AddTemplateButtonBar (buttonBarCell, stepNavigationTemplate, StepPreviousButtonID, StepNextButtonID, CancelButtonID);
972                                                 return;
973                                         } else {
974                                                 if (AllowNavigationToStep (ActiveStepIndex - 1))
975                                                         AddButtonCell (row, CreateButton (StepPreviousButtonID, MovePreviousCommandName, StepPreviousButtonType, StepPreviousButtonText, StepPreviousButtonImageUrl, StepPreviousButtonStyle));
976                                                 if (AllowNavigationToStep (ActiveStepIndex + 1))
977                                                         AddButtonCell (row, CreateButton (StepNextButtonID, MoveNextCommandName, StepNextButtonType, StepNextButtonText, StepNextButtonImageUrl, StepNextButtonStyle));
978                                                 if (DisplayCancelButton)
979                                                         AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
980                                         }
981                                         break;
982                                 case WizardStepType.Finish:
983                                         if (finishNavigationTemplate != null) {
984                                                 AddTemplateButtonBar (buttonBarCell, finishNavigationTemplate, FinishPreviousButtonID, FinishButtonID, CancelButtonID);
985                                                 return;
986                                         } else {
987                                                 if (AllowNavigationToStep (ActiveStepIndex - 1))
988                                                         AddButtonCell (row, CreateButton (FinishPreviousButtonID, MovePreviousCommandName, FinishPreviousButtonType, FinishPreviousButtonText, FinishPreviousButtonImageUrl, FinishPreviousButtonStyle));
989                                                 AddButtonCell (row, CreateButton (FinishButtonID, MoveCompleteCommandName, FinishCompleteButtonType, FinishCompleteButtonText, FinishCompleteButtonImageUrl, FinishCompleteButtonStyle));
990                                                 if (DisplayCancelButton)
991                                                         AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
992                                         }
993                                         break;
994                         }
995                         t.Rows.Add (row);
996                         buttonBarCell.Controls.Add (t);
997                 }
998                 
999                 internal Control CreateButton (string id, string command, ButtonType type, string text, string image, Style style)
1000                 {
1001                         WebControl b;
1002                         switch (type) {
1003                         case ButtonType.Button:
1004                                 b = CreateStandartButton ();
1005                                 break;
1006                         case ButtonType.Image:
1007                                 b = CreateImageButton (image);
1008                                 break;
1009                         case ButtonType.Link:
1010                                 b = CreateLinkButton ();
1011                                 break;
1012                         default:
1013                                 throw new ArgumentOutOfRangeException ("type");
1014                         }
1015                         
1016                         b.ID = id;
1017                         b.EnableTheming = false;
1018                         ((IButtonControl) b).CommandName = command;
1019                         ((IButtonControl) b).Text = text;
1020                         ((IButtonControl) b).ValidationGroup = ID;
1021                         
1022                         RegisterApplyStyle (b, NavigationButtonStyle);
1023                         RegisterApplyStyle (b, style);
1024                         return b;
1025                 }
1026
1027                 WebControl CreateStandartButton () {
1028                         Button btn = new Button ();
1029                         return btn;
1030                 }
1031
1032                 WebControl CreateImageButton (string imageUrl) {
1033                         ImageButton img = new ImageButton ();
1034                         img.ImageUrl = imageUrl;
1035                         return img;
1036                 }
1037
1038                 WebControl CreateLinkButton () {
1039                         LinkButton link = new LinkButton ();
1040                         return link;
1041                 }
1042
1043                 void AddTemplateButtonBar (TableCell cell, ITemplate template, params string[] buttonIds)
1044                 {
1045                         template.InstantiateIn (cell);
1046                         
1047                         foreach (string id in buttonIds) {
1048                                 IButtonControl b = cell.FindControl (id) as IButtonControl;
1049                                 if (b != null) RegisterCommandEvents (b);
1050                         }
1051                 }
1052                 
1053                 void AddButtonCell (TableRow row, Control control)
1054                 {
1055                         TableCell cell = new TableCell ();
1056                         cell.HorizontalAlign = HorizontalAlign.Right;
1057                         cell.Controls.Add (control);
1058                         row.Cells.Add (cell);
1059                 }
1060                 
1061                 void CreateSideBar (TableCell sideBarCell)
1062                 {
1063                         RegisterApplyStyle (sideBarCell, SideBarStyle);
1064
1065                         if (SkipLinkText != "") {
1066                                 System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
1067                                 anchor.HRef = "#" + ClientID + "_SkipLink";
1068
1069                                 Image img = new Image ();
1070                                 ClientScriptManager csm = new ClientScriptManager (null);
1071                                 img.ImageUrl = csm.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif");
1072                                 img.Attributes.Add ("height", "0");
1073                                 img.Attributes.Add ("width", "0");
1074                                 img.AlternateText = SkipLinkText;
1075
1076                                 anchor.Controls.Add (img);
1077                                 sideBarCell.Controls.Add (anchor);
1078                         }
1079
1080                         if (sideBarTemplate != null) {
1081                                 sideBarTemplate.InstantiateIn (sideBarCell);
1082                                 stepDatalist = sideBarCell.FindControl (DataListID) as DataList;
1083                                 stepDatalist.ItemDataBound += new DataListItemEventHandler(StepDatalistItemDataBound);
1084                                 if (stepDatalist == null)
1085                                         throw new InvalidOperationException ("The side bar template must contain a DataList control with id '" + DataListID + "'.");
1086                         } else {
1087                                 stepDatalist = new DataList ();
1088                                 stepDatalist.ID = DataListID;
1089                                 stepDatalist.ItemTemplate = SideBarItemTemplate;
1090                                 sideBarCell.Controls.Add (stepDatalist);
1091                         }
1092
1093                         if (SkipLinkText != "") {
1094                                 System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
1095                                 anchor.ID = "SkipLink";
1096                                 sideBarCell.Controls.Add (anchor);
1097                         }
1098
1099                         stepDatalist.CellSpacing = 0;
1100                         stepDatalist.DataSource = WizardSteps;
1101                         stepDatalist.DataBind ();
1102                 }
1103
1104                 void StepDatalistItemDataBound (object sender, DataListItemEventArgs e)
1105                 {
1106                         if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
1107                                 IButtonControl button = (IButtonControl) e.Item.FindControl (SideBarButtonID);
1108                                 WizardStep step = (WizardStep) e.Item.DataItem;
1109
1110                                 button.CommandName = Wizard.MoveToCommandName;
1111                                 button.CommandArgument = WizardSteps.IndexOf (step).ToString ();
1112                                 button.Text = step.Name;
1113                         }
1114                 }
1115                 
1116                 void AddHeaderRow (Table table)
1117                 {
1118                         if (HeaderText.Length != 0 || headerTemplate != null) {
1119                                 TableRow row = new TableRow ();
1120                                 TableCell cell = new TableCell ();
1121                                 RegisterApplyStyle (cell, HeaderStyle);
1122                                 if (headerTemplate != null)
1123                                         headerTemplate.InstantiateIn (cell);
1124                                 else
1125                                         cell.Text = HeaderText;
1126                                 row.Cells.Add (cell);
1127                                 table.Rows.Add (row);
1128                         }
1129                 }
1130                 
1131                 internal void RegisterApplyStyle (WebControl control, Style style)
1132                 {
1133                         styles.Add (new object[] { control, style });
1134                 }
1135                 
1136                 protected override Style CreateControlStyle ()
1137                 {
1138                         TableStyle style = new TableStyle ();
1139                         style.CellPadding = 0;
1140                         style.CellSpacing = 0;
1141                         return style;
1142                 }
1143
1144                 [MonoTODO]
1145                 protected override IDictionary GetDesignModeState ()
1146                 {
1147                         throw new NotImplementedException ();
1148                 }
1149                 
1150                 protected internal override void LoadControlState (object ob)
1151                 {
1152                         if (ob == null) return;
1153                         object[] state = (object[]) ob;
1154                         base.LoadControlState (state[0]);
1155                         activeStepIndex = (int) state[1];
1156                         history = (ArrayList) state[2];
1157                 }
1158                 
1159                 protected internal override object SaveControlState ()
1160                 {
1161                         object bstate = base.SaveControlState ();
1162                         return new object[] {
1163                                 bstate, activeStepIndex, history
1164                         };
1165                 }
1166                 
1167                 protected override void LoadViewState (object savedState)
1168                 {
1169                         if (savedState == null) {
1170                                 base.LoadViewState (null);
1171                                 return;
1172                         }
1173                         
1174                         object[] states = (object[]) savedState;
1175                         base.LoadViewState (states [0]);
1176                         
1177                         if (states[1] != null) ((IStateManager)StepStyle).LoadViewState (states[1]);
1178                         if (states[2] != null) ((IStateManager)SideBarStyle).LoadViewState (states[2]);
1179                         if (states[3] != null) ((IStateManager)HeaderStyle).LoadViewState (states[3]);
1180                         if (states[4] != null) ((IStateManager)NavigationStyle).LoadViewState (states[4]);
1181                         if (states[5] != null) ((IStateManager)SideBarButtonStyle).LoadViewState (states[5]);
1182                         if (states[6] != null) ((IStateManager)CancelButtonStyle).LoadViewState (states[6]);
1183                         if (states[7] != null) ((IStateManager)FinishCompleteButtonStyle).LoadViewState (states[7]);
1184                         if (states[8] != null) ((IStateManager)FinishPreviousButtonStyle).LoadViewState (states[8]);
1185                         if (states[9] != null) ((IStateManager)StartNextButtonStyle).LoadViewState (states[9]);
1186                         if (states[10] != null) ((IStateManager)StepNextButtonStyle).LoadViewState (states[10]);
1187                         if (states[11] != null) ((IStateManager)StepPreviousButtonStyle).LoadViewState (states[11]);
1188                         if (states[12] != null) ((IStateManager)NavigationButtonStyle).LoadViewState (states[12]);
1189                 }
1190                 
1191                 protected override object SaveViewState ()
1192                 {
1193                         object[] state = new object [13];
1194                         state [0] = base.SaveViewState ();
1195                         
1196                         if (stepStyle != null) state [1] = ((IStateManager)stepStyle).SaveViewState ();
1197                         if (sideBarStyle != null) state [2] = ((IStateManager)sideBarStyle).SaveViewState ();
1198                         if (headerStyle != null) state [3] = ((IStateManager)headerStyle).SaveViewState ();
1199                         if (navigationStyle != null) state [4] = ((IStateManager)navigationStyle).SaveViewState ();
1200                         if (sideBarButtonStyle != null) state [5] = ((IStateManager)sideBarButtonStyle).SaveViewState ();
1201                         if (cancelButtonStyle != null) state [6] = ((IStateManager)cancelButtonStyle).SaveViewState ();
1202                         if (finishCompleteButtonStyle != null) state [7] = ((IStateManager)finishCompleteButtonStyle).SaveViewState ();
1203                         if (finishPreviousButtonStyle != null) state [8] = ((IStateManager)finishPreviousButtonStyle).SaveViewState ();
1204                         if (startNextButtonStyle != null) state [9] = ((IStateManager)startNextButtonStyle).SaveViewState ();
1205                         if (stepNextButtonStyle != null) state [10] = ((IStateManager)stepNextButtonStyle).SaveViewState ();
1206                         if (stepPreviousButtonStyle != null) state [11] = ((IStateManager)stepPreviousButtonStyle).SaveViewState ();
1207                         if (navigationButtonStyle != null) state [12] = ((IStateManager)navigationButtonStyle).SaveViewState ();
1208                         
1209                         for (int n=0; n<state.Length; n++)
1210                                 if (state [n] != null) return state;
1211                         return null;
1212                 }
1213                 
1214                 protected override void TrackViewState ()
1215                 {
1216                         base.TrackViewState();
1217                         if (stepStyle != null) ((IStateManager)stepStyle).TrackViewState();
1218                         if (sideBarStyle != null) ((IStateManager)sideBarStyle).TrackViewState();
1219                         if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
1220                         if (navigationStyle != null) ((IStateManager)navigationStyle).TrackViewState();
1221                         if (sideBarButtonStyle != null) ((IStateManager)sideBarButtonStyle).TrackViewState();
1222                         if (cancelButtonStyle != null) ((IStateManager)cancelButtonStyle).TrackViewState();
1223                         if (finishCompleteButtonStyle != null) ((IStateManager)finishCompleteButtonStyle).TrackViewState();
1224                         if (finishPreviousButtonStyle != null) ((IStateManager)finishPreviousButtonStyle).TrackViewState();
1225                         if (startNextButtonStyle != null) ((IStateManager)startNextButtonStyle).TrackViewState();
1226                         if (stepNextButtonStyle != null) ((IStateManager)stepNextButtonStyle).TrackViewState();
1227                         if (stepPreviousButtonStyle != null) ((IStateManager)stepPreviousButtonStyle).TrackViewState();
1228                         if (navigationButtonStyle != null) ((IStateManager)navigationButtonStyle).TrackViewState();
1229                 }
1230                 
1231                 protected internal void RegisterCommandEvents (IButtonControl button)
1232                 {
1233                         button.Command += ProcessCommand;
1234                 }
1235                 
1236                 void ProcessCommand (object sender, CommandEventArgs args)
1237                 {
1238                         Control c = sender as Control;
1239                         if (c != null) {
1240                                 switch (c.ID) {
1241                                         case "CancelButton":
1242                                                 ProcessEvent ("Cancel", null);
1243                                                 return;
1244                                         case "FinishButton":
1245                                                 ProcessEvent ("MoveComplete", null);
1246                                                 return;
1247                                         case "StepPreviousButton":
1248                                         case "FinishPreviousButton":
1249                                                 ProcessEvent ("MovePrevious", null);
1250                                                 return;
1251                                         case "StartNextButton":
1252                                         case "StepNextButton":
1253                                                 ProcessEvent ("MoveNext", null);
1254                                                 return;
1255                                 }
1256                         }
1257                         ProcessEvent (args.CommandName, args.CommandArgument as string);
1258                 }
1259
1260                 protected override bool OnBubbleEvent (object source, EventArgs e)
1261                 {
1262                         CommandEventArgs args = e as CommandEventArgs;
1263                         if (args != null) {
1264                                 ProcessEvent (args.CommandName, args.CommandArgument as string);
1265                                 return true;
1266                         }
1267                         return base.OnBubbleEvent (source, e);
1268                 }
1269                 
1270                 void ProcessEvent (string commandName, string commandArg)
1271                 {
1272                         switch (commandName) {
1273                                 case "Cancel":
1274                                         if (CancelDestinationPageUrl.Length > 0)
1275                                                 Context.Response.Redirect (CancelDestinationPageUrl);
1276                                         else
1277                                                 OnCancelButtonClick (EventArgs.Empty);
1278                                         break;
1279
1280                                 case "MoveComplete":
1281                                         if (FinishDestinationPageUrl.Length > 0) {
1282                                                 Context.Response.Redirect (FinishDestinationPageUrl);
1283                                                 return;
1284                                         }
1285                                 
1286                                         int next = -1;
1287                                         for (int n=0; n<WizardSteps.Count; n++) {
1288                                                 if (WizardSteps [n].StepType == WizardStepType.Complete) {
1289                                                         next = n;
1290                                                         break;
1291                                                 }
1292                                         }
1293                                         if (next != -1) {
1294                                                 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, next);
1295                                                 OnFinishButtonClick (args);
1296                                                 if (!args.Cancel)
1297                                                         ActiveStepIndex = next;
1298                                         }
1299                                         break;
1300                                         
1301                                 case "MoveNext":
1302                                         if (ActiveStepIndex < WizardSteps.Count - 1) {
1303                                                 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex + 1);
1304                                                 OnNextButtonClick (args);
1305                                                 if (!args.Cancel)
1306                                                         ActiveStepIndex++;
1307                                         }
1308                                         break;
1309                                                         
1310                                 case "MovePrevious":
1311                                         if (ActiveStepIndex > 0) {
1312                                                 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex - 1);
1313                                                 OnPreviousButtonClick (args);
1314                                                 if (!args.Cancel)
1315                                                         ActiveStepIndex--;
1316                                         }
1317                                         break;
1318                                         
1319                                 case "Move":
1320                                         int newb = int.Parse (commandArg);
1321                                         ActiveStepIndex = newb;
1322                                         break;
1323                         }
1324                 }
1325                 
1326                 void UpdateControls ()
1327                 {
1328                         ChildControlsCreated = false;
1329                 }
1330                 
1331                 internal void UpdateViews ()
1332                 {
1333                         multiView = null;
1334                         UpdateControls ();
1335                 }
1336                 
1337                 protected internal override void Render (HtmlTextWriter writer)
1338                 {
1339                         if (multiView.ActiveViewIndex != ActiveStepIndex)
1340                                 CreateControlHierarchy ();
1341
1342                         wizardTable.ApplyStyle (ControlStyle);
1343
1344                         foreach (object[] styleDef in styles)
1345                                 ((WebControl)styleDef[0]).ApplyStyle ((Style)styleDef[1]);
1346                         
1347                         wizardTable.Render (writer);
1348                 }
1349
1350                 class TableCellNamingContainer : TableCell, INamingContainer
1351                 {
1352                 }
1353
1354                 class SideBarButtonTemplate: ITemplate
1355                 {
1356                         Wizard wizard;
1357                         
1358                         public SideBarButtonTemplate (Wizard wizard)
1359                         {
1360                                 this.wizard = wizard;
1361                         }
1362                         
1363                         public void InstantiateIn (Control control)
1364                         {
1365                                 LinkButton b = new LinkButton ();
1366                                 wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1367                                 control.Controls.Add (b);
1368                                 control.DataBinding += Bound;
1369                         }
1370                         
1371                         void Bound (object s, EventArgs args)
1372                         {
1373                                 WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1374                                 if (step != null) {
1375                                         DataListItem c = (DataListItem) s;
1376                                         LinkButton b = (LinkButton) c.Controls[0];
1377                                         b.ID = SideBarButtonID;
1378                                         b.CommandName = Wizard.MoveToCommandName;
1379                                         b.CommandArgument = wizard.WizardSteps.IndexOf (step).ToString ();
1380                                         b.Text = step.Name;
1381                                         if (step.StepType == WizardStepType.Complete)
1382                                                 b.Enabled = false;
1383                                         if (step == wizard.ActiveStep)
1384                                                 c.Font.Bold = true;
1385                                         wizard.RegisterCommandEvents (b);
1386                                 }
1387                         }
1388                 }
1389         }
1390 }
1391
1392 #endif