* Wizard.cs: implemented SkipLinkText, TagKey
[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")]\r
40         [BindableAttribute (false)]\r
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";\r
46                 public static readonly string MoveCompleteCommandName = "MoveComplete";\r
47                 public static readonly string MoveNextCommandName = "MoveNext";\r
48                 public static readonly string MovePreviousCommandName = "MovePrevious";\r
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)]\r
189             [BrowsableAttribute (false)]\r
190                 public WizardStepBase ActiveStep {
191                         get {
192                                 if (activeStepIndex < -1 || activeStepIndex >= steps.Count)
193                                         throw new InvalidOperationException ("ActiveStepIndex has an invalid value.");
194                                 if (activeStepIndex == -1) return null;
195                                 return steps [activeStepIndex];
196                         }
197                 }
198                 
199             [DefaultValueAttribute (-1)]\r
200             [ThemeableAttribute (false)]\r
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]\r
222             [DefaultValueAttribute ("")]\r
223             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]\r
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)]\r
236             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
237             [NotifyParentPropertyAttribute (true)]\r
238             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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)]\r
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)]\r
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]\r
275             [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
276             [DefaultValueAttribute ("")]\r
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             \r
287             [DefaultValueAttribute (0)]\r
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)]\r
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)]\r
312             [ThemeableAttribute (false)]\r
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)]\r
325             [ThemeableAttribute (false)]\r
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]\r
338             [DefaultValueAttribute ("")]\r
339             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]\r
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)]\r
352             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
353             [NotifyParentPropertyAttribute (true)]\r
354             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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)]\r
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)]\r
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]\r
391             [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
392             [DefaultValueAttribute ("")]\r
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             \r
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]\r
413             [DefaultValueAttribute ("")]\r
414             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]\r
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)]\r
427             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
428             [NotifyParentPropertyAttribute (true)]\r
429             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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)]\r
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)]\r
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)]\r
466             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
467             [NotifyParentPropertyAttribute (true)]\r
468             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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 ("")]\r
490             [LocalizableAttribute (true)]\r
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)]\r
503             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
504             [NotifyParentPropertyAttribute (true)]\r
505             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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)]\r
518             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
519             [NotifyParentPropertyAttribute (true)]\r
520             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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)]\r
533             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
534             [DefaultValueAttribute (null)]\r
535             [NotifyParentPropertyAttribute (true)]\r
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)]\r
548             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
549             [DefaultValueAttribute (null)]\r
550             [NotifyParentPropertyAttribute (true)]\r
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]\r
596             [DefaultValueAttribute ("")]\r
597             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]\r
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)]\r
610             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
611             [NotifyParentPropertyAttribute (true)]\r
612             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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)]\r
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)]\r
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]\r
658             [DefaultValueAttribute ("")]\r
659             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]\r
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)]\r
672             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
673             [NotifyParentPropertyAttribute (true)]\r
674             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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)]\r
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)]\r
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]\r
711             [DefaultValueAttribute ("")]\r
712             [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]\r
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)]\r
725             [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
726             [NotifyParentPropertyAttribute (true)]\r
727             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
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)]\r
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)]\r
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)]\r
764             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
765             [DefaultValueAttribute (null)]\r
766             [NotifyParentPropertyAttribute (true)]\r
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)]\r
779             [EditorAttribute ("System.Web.UI.Design.WebControls.WizardStepCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
780             [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
781             [ThemeableAttribute (false)]\r
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                                 TableCell sideBarCell = new TableCell ();
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                 Control CreateButton (string id, string command, ButtonType type, string text, string image, Style style)
1000                 {
1001                         DataControlButton b = new DataControlButton (this, text, image, command, "", false);
1002                         b.ID = id;
1003                         b.ButtonType = type;
1004                         RegisterApplyStyle (b, NavigationButtonStyle);
1005                         RegisterApplyStyle (b, style);
1006                         return b;
1007                 }
1008                 
1009                 void AddTemplateButtonBar (TableCell cell, ITemplate template, params string[] buttonIds)
1010                 {
1011                         template.InstantiateIn (cell);
1012                         
1013                         foreach (string id in buttonIds) {
1014                                 IButtonControl b = cell.FindControl (id) as IButtonControl;
1015                                 if (b != null) RegisterCommandEvents (b);
1016                         }
1017                 }
1018                 
1019                 void AddButtonCell (TableRow row, Control control)
1020                 {
1021                         TableCell cell = new TableCell ();
1022                         cell.HorizontalAlign = HorizontalAlign.Right;
1023                         cell.Controls.Add (control);
1024                         row.Cells.Add (cell);
1025                 }
1026                 
1027                 void CreateSideBar (TableCell sideBarCell)
1028                 {
1029                         RegisterApplyStyle (sideBarCell, SideBarStyle);
1030
1031                         if (SkipLinkText != "") {
1032                                 System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
1033                                 anchor.HRef = "#" + ClientID + "_SkipLink";
1034
1035                                 Image img = new Image ();\r
1036                                 ClientScriptManager csm = new ClientScriptManager (null);\r
1037                                 img.ImageUrl = csm.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif");
1038                                 img.Attributes.Add ("height", "0");
1039                                 img.Attributes.Add ("width", "0");
1040                                 img.AlternateText = SkipLinkText;
1041
1042                                 anchor.Controls.Add (img);
1043                                 sideBarCell.Controls.Add (anchor);
1044                         }
1045
1046                         if (sideBarTemplate != null) {
1047                                 sideBarTemplate.InstantiateIn (sideBarCell);
1048                                 stepDatalist = sideBarCell.FindControl (DataListID) as DataList;
1049                                 if (stepDatalist == null)
1050                                         throw new InvalidOperationException ("The side bar template must contain a DataList control with id '" + DataListID + "'.");
1051                         } else {
1052                                 stepDatalist = new DataList ();
1053                                 stepDatalist.ID = DataListID;
1054                                 stepDatalist.CellSpacing = 0;
1055                                 sideBarCell.Controls.Add (stepDatalist);
1056                         }
1057
1058                         if (SkipLinkText != "") {
1059                                 System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
1060                                 anchor.ID = "SkipLink";
1061                                 sideBarCell.Controls.Add (anchor);
1062                         }
1063
1064                         stepDatalist.DataSource = WizardSteps;
1065                         stepDatalist.ItemTemplate = SideBarItemTemplate;
1066                         stepDatalist.DataBind ();
1067                 }
1068                 
1069                 void AddHeaderRow (Table table)
1070                 {
1071                         if (HeaderText.Length != 0 || headerTemplate != null) {
1072                                 TableRow row = new TableRow ();
1073                                 TableCell cell = new TableCell ();
1074                                 RegisterApplyStyle (cell, HeaderStyle);
1075                                 if (headerTemplate != null)
1076                                         headerTemplate.InstantiateIn (cell);
1077                                 else
1078                                         cell.Text = HeaderText;
1079                                 row.Cells.Add (cell);
1080                                 table.Rows.Add (row);
1081                         }
1082                 }
1083                 
1084                 internal void RegisterApplyStyle (WebControl control, Style style)
1085                 {
1086                         styles.Add (new object[] { control, style });
1087                 }
1088                 
1089                 protected override Style CreateControlStyle ()
1090                 {
1091                         TableStyle style = new TableStyle ();
1092                         style.CellPadding = 0;
1093                         style.CellSpacing = 0;
1094                         return style;
1095                 }
1096
1097                 [MonoTODO]
1098                 protected override IDictionary GetDesignModeState ()
1099                 {
1100                         throw new NotImplementedException ();
1101                 }
1102                 
1103                 protected internal override void LoadControlState (object ob)
1104                 {
1105                         if (ob == null) return;
1106                         object[] state = (object[]) ob;
1107                         base.LoadControlState (state[0]);
1108                         activeStepIndex = (int) state[1];
1109                         history = (ArrayList) state[2];
1110                 }
1111                 
1112                 protected internal override object SaveControlState ()
1113                 {
1114                         object bstate = base.SaveControlState ();
1115                         return new object[] {
1116                                 bstate, activeStepIndex, history
1117                         };
1118                 }
1119                 
1120                 protected override void LoadViewState (object savedState)
1121                 {
1122                         if (savedState == null) {
1123                                 base.LoadViewState (null);
1124                                 return;
1125                         }
1126                         
1127                         object[] states = (object[]) savedState;
1128                         base.LoadViewState (states [0]);
1129                         
1130                         if (states[1] != null) ((IStateManager)StepStyle).LoadViewState (states[1]);
1131                         if (states[2] != null) ((IStateManager)SideBarStyle).LoadViewState (states[2]);
1132                         if (states[3] != null) ((IStateManager)HeaderStyle).LoadViewState (states[3]);
1133                         if (states[4] != null) ((IStateManager)NavigationStyle).LoadViewState (states[4]);
1134                         if (states[5] != null) ((IStateManager)SideBarButtonStyle).LoadViewState (states[5]);
1135                         if (states[6] != null) ((IStateManager)CancelButtonStyle).LoadViewState (states[6]);
1136                         if (states[7] != null) ((IStateManager)FinishCompleteButtonStyle).LoadViewState (states[7]);
1137                         if (states[8] != null) ((IStateManager)FinishPreviousButtonStyle).LoadViewState (states[8]);
1138                         if (states[9] != null) ((IStateManager)StartNextButtonStyle).LoadViewState (states[9]);
1139                         if (states[10] != null) ((IStateManager)StepNextButtonStyle).LoadViewState (states[10]);
1140                         if (states[11] != null) ((IStateManager)StepPreviousButtonStyle).LoadViewState (states[11]);
1141                         if (states[12] != null) ((IStateManager)NavigationButtonStyle).LoadViewState (states[12]);
1142                 }
1143                 
1144                 protected override object SaveViewState ()
1145                 {
1146                         object[] state = new object [13];
1147                         state [0] = base.SaveViewState ();
1148                         
1149                         if (stepStyle != null) state [1] = ((IStateManager)stepStyle).SaveViewState ();
1150                         if (sideBarStyle != null) state [2] = ((IStateManager)sideBarStyle).SaveViewState ();
1151                         if (headerStyle != null) state [3] = ((IStateManager)headerStyle).SaveViewState ();
1152                         if (navigationStyle != null) state [4] = ((IStateManager)navigationStyle).SaveViewState ();
1153                         if (sideBarButtonStyle != null) state [5] = ((IStateManager)sideBarButtonStyle).SaveViewState ();
1154                         if (cancelButtonStyle != null) state [6] = ((IStateManager)cancelButtonStyle).SaveViewState ();
1155                         if (finishCompleteButtonStyle != null) state [7] = ((IStateManager)finishCompleteButtonStyle).SaveViewState ();
1156                         if (finishPreviousButtonStyle != null) state [8] = ((IStateManager)finishPreviousButtonStyle).SaveViewState ();
1157                         if (startNextButtonStyle != null) state [9] = ((IStateManager)startNextButtonStyle).SaveViewState ();
1158                         if (stepNextButtonStyle != null) state [10] = ((IStateManager)stepNextButtonStyle).SaveViewState ();
1159                         if (stepPreviousButtonStyle != null) state [11] = ((IStateManager)stepPreviousButtonStyle).SaveViewState ();
1160                         if (navigationButtonStyle != null) state [12] = ((IStateManager)navigationButtonStyle).SaveViewState ();
1161                         
1162                         for (int n=0; n<state.Length; n++)
1163                                 if (state [n] != null) return state;
1164                         return null;
1165                 }
1166                 
1167                 protected override void TrackViewState ()
1168                 {
1169                         base.TrackViewState();
1170                         if (stepStyle != null) ((IStateManager)stepStyle).TrackViewState();
1171                         if (sideBarStyle != null) ((IStateManager)sideBarStyle).TrackViewState();
1172                         if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
1173                         if (navigationStyle != null) ((IStateManager)navigationStyle).TrackViewState();
1174                         if (sideBarButtonStyle != null) ((IStateManager)sideBarButtonStyle).TrackViewState();
1175                         if (cancelButtonStyle != null) ((IStateManager)cancelButtonStyle).TrackViewState();
1176                         if (finishCompleteButtonStyle != null) ((IStateManager)finishCompleteButtonStyle).TrackViewState();
1177                         if (finishPreviousButtonStyle != null) ((IStateManager)finishPreviousButtonStyle).TrackViewState();
1178                         if (startNextButtonStyle != null) ((IStateManager)startNextButtonStyle).TrackViewState();
1179                         if (stepNextButtonStyle != null) ((IStateManager)stepNextButtonStyle).TrackViewState();
1180                         if (stepPreviousButtonStyle != null) ((IStateManager)stepPreviousButtonStyle).TrackViewState();
1181                         if (navigationButtonStyle != null) ((IStateManager)navigationButtonStyle).TrackViewState();
1182                 }
1183                 
1184                 protected internal void RegisterCommandEvents (IButtonControl button)
1185                 {
1186                         button.Command += ProcessCommand;
1187                 }
1188                 
1189                 void ProcessCommand (object sender, CommandEventArgs args)
1190                 {
1191                         Control c = sender as Control;
1192                         if (c != null) {
1193                                 switch (c.ID) {
1194                                         case "CancelButton":
1195                                                 ProcessEvent ("Cancel", null);
1196                                                 return;
1197                                         case "FinishButton":
1198                                                 ProcessEvent ("MoveComplete", null);
1199                                                 return;
1200                                         case "StepPreviousButton":
1201                                         case "FinishPreviousButton":
1202                                                 ProcessEvent ("MovePrevious", null);
1203                                                 return;
1204                                         case "StartNextButton":
1205                                         case "StepNextButton":
1206                                                 ProcessEvent ("MoveNext", null);
1207                                                 return;
1208                                 }
1209                         }
1210                         ProcessEvent (args.CommandName, args.CommandArgument as string);
1211                 }
1212
1213                 protected override bool OnBubbleEvent (object source, EventArgs e)
1214                 {
1215                         CommandEventArgs args = e as CommandEventArgs;
1216                         if (args != null) {
1217                                 ProcessEvent (args.CommandName, args.CommandArgument as string);
1218                         }
1219                         return base.OnBubbleEvent (source, e);
1220                 }
1221                 
1222                 void ProcessEvent (string commandName, string commandArg)
1223                 {
1224                         switch (commandName) {
1225                                 case "Cancel":
1226                                         if (CancelDestinationPageUrl.Length > 0)
1227                                                 Context.Response.Redirect (CancelDestinationPageUrl);
1228                                         else
1229                                                 OnCancelButtonClick (EventArgs.Empty);
1230                                         break;
1231 \r
1232                                 case "MoveComplete":
1233                                         if (FinishDestinationPageUrl.Length > 0) {
1234                                                 Context.Response.Redirect (FinishDestinationPageUrl);
1235                                                 return;
1236                                         }
1237                                 
1238                                         int next = -1;
1239                                         for (int n=0; n<WizardSteps.Count; n++) {
1240                                                 if (WizardSteps [n].StepType == WizardStepType.Complete) {
1241                                                         next = n;
1242                                                         break;
1243                                                 }
1244                                         }
1245                                         if (next != -1) {
1246                                                 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, next);
1247                                                 OnFinishButtonClick (args);
1248                                                 if (!args.Cancel)
1249                                                         ActiveStepIndex = next;
1250                                         }
1251                                         break;
1252                                         \r
1253                                 case "MoveNext":
1254                                         if (ActiveStepIndex < WizardSteps.Count - 1) {\r
1255                                                 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex + 1);
1256                                                 OnNextButtonClick (args);
1257                                                 if (!args.Cancel)
1258                                                         ActiveStepIndex++;
1259                                         }
1260                                         break;
1261                                                         
1262                                 case "MovePrevious":\r
1263                                         if (ActiveStepIndex > 0) {\r
1264                                                 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex - 1);
1265                                                 OnPreviousButtonClick (args);
1266                                                 if (!args.Cancel)
1267                                                         ActiveStepIndex--;
1268                                         }
1269                                         break;
1270                                         
1271                                 case "Move":
1272                                         int newb = int.Parse (commandArg);
1273                                         ActiveStepIndex = newb;
1274                                         break;
1275                         }
1276                 }
1277                 
1278                 void UpdateControls ()
1279                 {
1280                         ChildControlsCreated = false;
1281                 }
1282                 
1283                 internal void UpdateViews ()
1284                 {
1285                         multiView = null;
1286                         UpdateControls ();
1287                 }
1288                 
1289                 protected internal override void Render (HtmlTextWriter writer)
1290                 {
1291                         if (multiView.ActiveViewIndex != ActiveStepIndex)
1292                                 CreateControlHierarchy ();
1293
1294                         wizardTable.ApplyStyle (ControlStyle);
1295
1296                         foreach (object[] styleDef in styles)
1297                                 ((WebControl)styleDef[0]).ApplyStyle ((Style)styleDef[1]);
1298                         
1299                         wizardTable.Render (writer);
1300                 }
1301                 
1302                 class SideBarButtonTemplate: ITemplate
1303                 {
1304                         Wizard wizard;
1305                         
1306                         public SideBarButtonTemplate (Wizard wizard)
1307                         {
1308                                 this.wizard = wizard;
1309                         }
1310                         
1311                         public void InstantiateIn (Control control)
1312                         {
1313                                 LinkButton b = new LinkButton ();
1314                                 wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1315                                 control.Controls.Add (b);
1316                                 control.DataBinding += Bound;
1317                         }
1318                         
1319                         void Bound (object s, EventArgs args)
1320                         {
1321                                 WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1322                                 if (step != null) {
1323                                         DataListItem c = (DataListItem) s;
1324                                         LinkButton b = (LinkButton) c.Controls[0];
1325                                         b.ID = SideBarButtonID;
1326                                         b.CommandName = Wizard.MoveToCommandName;
1327                                         b.CommandArgument = wizard.WizardSteps.IndexOf (step).ToString ();
1328                                         b.Text = step.Name;
1329                                         if (step.StepType == WizardStepType.Complete)
1330                                                 b.Enabled = false;
1331                                         if (step == wizard.ActiveStep)
1332                                                 c.Font.Bold = true;
1333                                         wizard.RegisterCommandEvents (b);
1334                                 }
1335                         }
1336                 }
1337         }
1338 }
1339
1340 #endif