Wizard.cs 54 KB

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