Menu.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. //
  2. // System.Web.UI.WebControls.Menu.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2004 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.Text;
  33. using System.ComponentModel;
  34. using System.Web.UI;
  35. using System.Web.Handlers;
  36. using System.Collections.Specialized;
  37. using System.IO;
  38. namespace System.Web.UI.WebControls
  39. {
  40. [DefaultEvent ("MenuItemClick")]
  41. [ControlValueProperty ("SelectedValue")]
  42. [Designer ("System.Web.UI.Design.WebControls.MenuDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  43. public class Menu : HierarchicalDataBoundControl, IPostBackEventHandler, INamingContainer
  44. {
  45. MenuItemStyle dynamicMenuItemStyle;
  46. SubMenuStyle dynamicMenuStyle;
  47. MenuItemStyle dynamicSelectedStyle;
  48. MenuItemStyle staticMenuItemStyle;
  49. SubMenuStyle staticMenuStyle;
  50. MenuItemStyle staticSelectedStyle;
  51. Style staticHoverStyle;
  52. Style dynamicHoverStyle;
  53. MenuItemStyleCollection levelMenuItemStyles;
  54. MenuItemStyleCollection levelSelectedStyles;
  55. SubMenuStyleCollection levelSubMenuStyles;
  56. ITemplate staticItemTemplate;
  57. ITemplate dynamicItemTemplate;
  58. MenuItemCollection items;
  59. MenuItemBindingCollection dataBindings;
  60. MenuItem selectedItem;
  61. string selectedItemPath;
  62. Hashtable bindings;
  63. ArrayList dynamicMenus;
  64. private static readonly object MenuItemClickEvent = new object();
  65. private static readonly object MenuItemDataBoundEvent = new object();
  66. public static readonly string MenuItemClickCommandName = "Click";
  67. public event MenuEventHandler MenuItemClick {
  68. add { Events.AddHandler (MenuItemClickEvent, value); }
  69. remove { Events.RemoveHandler (MenuItemClickEvent, value); }
  70. }
  71. public event MenuEventHandler MenuItemDataBound {
  72. add { Events.AddHandler (MenuItemDataBoundEvent, value); }
  73. remove { Events.RemoveHandler (MenuItemDataBoundEvent, value); }
  74. }
  75. protected virtual void OnMenuItemClick (MenuEventArgs e)
  76. {
  77. if (Events != null) {
  78. MenuEventHandler eh = (MenuEventHandler) Events [MenuItemClickEvent];
  79. if (eh != null) eh (this, e);
  80. }
  81. }
  82. protected virtual void OnMenuItemDataBound (MenuEventArgs e)
  83. {
  84. if (Events != null) {
  85. MenuEventHandler eh = (MenuEventHandler) Events [MenuItemDataBoundEvent];
  86. if (eh != null) eh (this, e);
  87. }
  88. }
  89. [DefaultValueAttribute (null)]
  90. [PersistenceMode (PersistenceMode.InnerProperty)]
  91. [EditorAttribute ("System.Web.UI.Design.WebControls.MenuBindingsEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  92. [MergablePropertyAttribute (false)]
  93. public MenuItemBindingCollection DataBindings {
  94. get {
  95. if (dataBindings == null) {
  96. dataBindings = new MenuItemBindingCollection ();
  97. if (IsTrackingViewState)
  98. ((IStateManager)dataBindings).TrackViewState();
  99. }
  100. return dataBindings;
  101. }
  102. }
  103. [DefaultValue (500)]
  104. [ThemeableAttribute (false)]
  105. public int DisappearAfter {
  106. get {
  107. object o = ViewState ["DisappearAfter"];
  108. if (o != null) return (int)o;
  109. return 500;
  110. }
  111. set {
  112. ViewState["DisappearAfter"] = value;
  113. }
  114. }
  115. [ThemeableAttribute (true)]
  116. [DefaultValue ("")]
  117. [UrlProperty]
  118. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  119. public string DynamicBottomSeparatorImageUrl {
  120. get {
  121. object o = ViewState ["dbsiu"];
  122. if (o != null) return (string)o;
  123. return "";
  124. }
  125. set {
  126. ViewState["dbsiu"] = value;
  127. }
  128. }
  129. [DefaultValueAttribute ("")]
  130. public string DynamicItemFormatString {
  131. get {
  132. object o = ViewState ["DynamicItemFormatString"];
  133. if (o != null) return (string)o;
  134. return "";
  135. }
  136. set {
  137. ViewState["DynamicItemFormatString"] = value;
  138. }
  139. }
  140. [DefaultValue ("")]
  141. [UrlProperty]
  142. [WebCategory ("Appearance")]
  143. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  144. public string DynamicTopSeparatorImageUrl {
  145. get {
  146. object o = ViewState ["dtsiu"];
  147. if (o != null) return (string)o;
  148. return "";
  149. }
  150. set {
  151. ViewState["dtsiu"] = value;
  152. }
  153. }
  154. [DefaultValue ("")]
  155. [UrlProperty]
  156. [WebCategory ("Appearance")]
  157. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  158. public string StaticBottomSeparatorImageUrl {
  159. get {
  160. object o = ViewState ["sbsiu"];
  161. if (o != null) return (string)o;
  162. return "";
  163. }
  164. set {
  165. ViewState["sbsiu"] = value;
  166. }
  167. }
  168. [DefaultValue ("")]
  169. [UrlProperty]
  170. [WebCategory ("Appearance")]
  171. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  172. public string StaticTopSeparatorImageUrl {
  173. get {
  174. object o = ViewState ["stsiu"];
  175. if (o != null) return (string)o;
  176. return "";
  177. }
  178. set {
  179. ViewState["stsiu"] = value;
  180. }
  181. }
  182. [DefaultValue (Orientation.Vertical)]
  183. public Orientation Orientation {
  184. get {
  185. object o = ViewState ["Orientation"];
  186. if (o != null) return (Orientation) o;
  187. return Orientation.Vertical;
  188. }
  189. set {
  190. ViewState["Orientation"] = value;
  191. }
  192. }
  193. [DefaultValue (1)]
  194. [ThemeableAttribute (true)]
  195. public int StaticDisplayLevels {
  196. get {
  197. object o = ViewState ["StaticDisplayLevels"];
  198. if (o != null) return (int)o;
  199. return 1;
  200. }
  201. set {
  202. if (value < 1) throw new ArgumentOutOfRangeException ();
  203. ViewState["StaticDisplayLevels"] = value;
  204. }
  205. }
  206. [DefaultValueAttribute ("")]
  207. public string StaticItemFormatString {
  208. get {
  209. object o = ViewState ["StaticItemFormatString"];
  210. if (o != null) return (string)o;
  211. return "";
  212. }
  213. set {
  214. ViewState["StaticItemFormatString"] = value;
  215. }
  216. }
  217. [DefaultValue (typeof (Unit), "16px")]
  218. [ThemeableAttribute (true)]
  219. public Unit StaticSubMenuIndent {
  220. get {
  221. object o = ViewState ["StaticSubMenuIndent"];
  222. if (o != null) return (Unit)o;
  223. return new Unit (16);
  224. }
  225. set {
  226. ViewState["StaticSubMenuIndent"] = value;
  227. }
  228. }
  229. [ThemeableAttribute (true)]
  230. [DefaultValue (3)]
  231. public int MaximumDynamicDisplayLevels {
  232. get {
  233. object o = ViewState ["MaximumDynamicDisplayLevels"];
  234. if (o != null) return (int)o;
  235. return 3;
  236. }
  237. set {
  238. if (value < 0) throw new ArgumentOutOfRangeException ();
  239. ViewState["MaximumDynamicDisplayLevels"] = value;
  240. }
  241. }
  242. [DefaultValue (0)]
  243. public int DynamicVerticalOffset {
  244. get {
  245. object o = ViewState ["DynamicVerticalOffset"];
  246. if (o != null) return (int)o;
  247. return 0;
  248. }
  249. set {
  250. ViewState["DynamicVerticalOffset"] = value;
  251. }
  252. }
  253. [DefaultValue (0)]
  254. public int DynamicHorizontalOffset {
  255. get {
  256. object o = ViewState ["DynamicHorizontalOffset"];
  257. if (o != null) return (int)o;
  258. return 0;
  259. }
  260. set {
  261. ViewState["DynamicHorizontalOffset"] = value;
  262. }
  263. }
  264. [DefaultValue (true)]
  265. public bool DynamicEnableDefaultPopOutImage {
  266. get {
  267. object o = ViewState ["dedpoi"];
  268. if (o != null) return (bool)o;
  269. return true;
  270. }
  271. set {
  272. ViewState["dedpoi"] = value;
  273. }
  274. }
  275. [DefaultValue (true)]
  276. public bool StaticEnableDefaultPopOutImage {
  277. get {
  278. object o = ViewState ["sedpoi"];
  279. if (o != null) return (bool)o;
  280. return true;
  281. }
  282. set {
  283. ViewState["sedpoi"] = value;
  284. }
  285. }
  286. [DefaultValueAttribute (null)]
  287. [PersistenceMode (PersistenceMode.InnerProperty)]
  288. [Editor ("System.Web.UI.Design.MenuItemCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  289. [MergablePropertyAttribute (false)]
  290. public MenuItemCollection Items {
  291. get {
  292. if (items == null) {
  293. items = new MenuItemCollection (this);
  294. if (IsTrackingViewState)
  295. ((IStateManager)items).TrackViewState();
  296. }
  297. return items;
  298. }
  299. }
  300. [DefaultValue ('/')]
  301. public char PathSeparator {
  302. get {
  303. object o = ViewState ["PathSeparator"];
  304. if(o != null) return (char)o;
  305. return '/';
  306. }
  307. set {
  308. ViewState ["PathSeparator"] = value;
  309. }
  310. }
  311. [DefaultValue (false)]
  312. public bool ItemWrap {
  313. get {
  314. object o = ViewState ["ItemWrap"];
  315. if(o != null) return (bool)o;
  316. return false;
  317. }
  318. set {
  319. ViewState ["ItemWrap"] = value;
  320. }
  321. }
  322. [PersistenceMode (PersistenceMode.InnerProperty)]
  323. [NotifyParentProperty (true)]
  324. [DefaultValue (null)]
  325. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  326. public MenuItemStyle DynamicMenuItemStyle {
  327. get {
  328. if (dynamicMenuItemStyle == null) {
  329. dynamicMenuItemStyle = new MenuItemStyle ();
  330. if (IsTrackingViewState)
  331. dynamicMenuItemStyle.TrackViewState();
  332. }
  333. return dynamicMenuItemStyle;
  334. }
  335. }
  336. [PersistenceMode (PersistenceMode.InnerProperty)]
  337. [NotifyParentProperty (true)]
  338. [DefaultValue (null)]
  339. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  340. public MenuItemStyle DynamicSelectedStyle {
  341. get {
  342. if (dynamicSelectedStyle == null) {
  343. dynamicSelectedStyle = new MenuItemStyle ();
  344. if (IsTrackingViewState)
  345. dynamicSelectedStyle.TrackViewState();
  346. }
  347. return dynamicSelectedStyle;
  348. }
  349. }
  350. [PersistenceMode (PersistenceMode.InnerProperty)]
  351. [NotifyParentProperty (true)]
  352. [DefaultValue (null)]
  353. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  354. public SubMenuStyle DynamicMenuStyle {
  355. get {
  356. if (dynamicMenuStyle == null) {
  357. dynamicMenuStyle = new SubMenuStyle ();
  358. if (IsTrackingViewState)
  359. dynamicMenuStyle.TrackViewState();
  360. }
  361. return dynamicMenuStyle;
  362. }
  363. }
  364. [PersistenceMode (PersistenceMode.InnerProperty)]
  365. [NotifyParentProperty (true)]
  366. [DefaultValue (null)]
  367. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  368. public MenuItemStyle StaticMenuItemStyle {
  369. get {
  370. if (staticMenuItemStyle == null) {
  371. staticMenuItemStyle = new MenuItemStyle ();
  372. if (IsTrackingViewState)
  373. staticMenuItemStyle.TrackViewState();
  374. }
  375. return staticMenuItemStyle;
  376. }
  377. }
  378. [PersistenceMode (PersistenceMode.InnerProperty)]
  379. [NotifyParentProperty (true)]
  380. [DefaultValue (null)]
  381. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  382. public MenuItemStyle StaticSelectedStyle {
  383. get {
  384. if (staticSelectedStyle == null) {
  385. staticSelectedStyle = new MenuItemStyle ();
  386. if (IsTrackingViewState)
  387. staticSelectedStyle.TrackViewState();
  388. }
  389. return staticSelectedStyle;
  390. }
  391. }
  392. [PersistenceMode (PersistenceMode.InnerProperty)]
  393. [NotifyParentProperty (true)]
  394. [DefaultValue (null)]
  395. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  396. public SubMenuStyle StaticMenuStyle {
  397. get {
  398. if (staticMenuStyle == null) {
  399. staticMenuStyle = new SubMenuStyle ();
  400. if (IsTrackingViewState)
  401. staticMenuStyle.TrackViewState();
  402. }
  403. return staticMenuStyle;
  404. }
  405. }
  406. [DefaultValue (null)]
  407. [PersistenceMode (PersistenceMode.InnerProperty)]
  408. [Editor ("System.Web.UI.Design.WebControls.MenuItemStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  409. public MenuItemStyleCollection LevelMenuItemStyles {
  410. get {
  411. if (levelMenuItemStyles == null) {
  412. levelMenuItemStyles = new MenuItemStyleCollection ();
  413. if (IsTrackingViewState)
  414. ((IStateManager)levelMenuItemStyles).TrackViewState();
  415. }
  416. return levelMenuItemStyles;
  417. }
  418. }
  419. [DefaultValue (null)]
  420. [PersistenceMode (PersistenceMode.InnerProperty)]
  421. [Editor ("System.Web.UI.Design.WebControls.MenuItemStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  422. public MenuItemStyleCollection LevelSelectedStyles {
  423. get {
  424. if (levelSelectedStyles == null) {
  425. levelSelectedStyles = new MenuItemStyleCollection ();
  426. if (IsTrackingViewState)
  427. ((IStateManager)levelSelectedStyles).TrackViewState();
  428. }
  429. return levelSelectedStyles;
  430. }
  431. }
  432. [DefaultValue (null)]
  433. [PersistenceMode (PersistenceMode.InnerProperty)]
  434. [Editor ("System.Web.UI.Design.WebControls.SubMenuStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  435. public SubMenuStyleCollection LevelSubMenuStyles {
  436. get {
  437. if (levelSubMenuStyles == null) {
  438. levelSubMenuStyles = new SubMenuStyleCollection ();
  439. if (IsTrackingViewState)
  440. ((IStateManager)levelSubMenuStyles).TrackViewState();
  441. }
  442. return levelSubMenuStyles;
  443. }
  444. }
  445. [PersistenceMode (PersistenceMode.InnerProperty)]
  446. [NotifyParentProperty (true)]
  447. [DefaultValue (null)]
  448. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  449. public Style DynamicHoverStyle {
  450. get {
  451. if (dynamicHoverStyle == null) {
  452. dynamicHoverStyle = new Style ();
  453. if (IsTrackingViewState)
  454. dynamicHoverStyle.TrackViewState();
  455. }
  456. return dynamicHoverStyle;
  457. }
  458. }
  459. [PersistenceMode (PersistenceMode.InnerProperty)]
  460. [NotifyParentProperty (true)]
  461. [DefaultValue (null)]
  462. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  463. public Style StaticHoverStyle {
  464. get {
  465. if (staticHoverStyle == null) {
  466. staticHoverStyle = new Style ();
  467. if (IsTrackingViewState)
  468. staticHoverStyle.TrackViewState();
  469. }
  470. return staticHoverStyle;
  471. }
  472. }
  473. [DefaultValue ("")]
  474. [UrlProperty]
  475. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  476. public string ScrollDownImageUrl {
  477. get {
  478. object o = ViewState ["sdiu"];
  479. if (o != null) return (string)o;
  480. return "";
  481. }
  482. set {
  483. ViewState["sdiu"] = value;
  484. }
  485. }
  486. [DefaultValue ("")]
  487. [UrlProperty]
  488. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  489. public string ScrollUpImageUrl {
  490. get {
  491. object o = ViewState ["suiu"];
  492. if (o != null) return (string)o;
  493. return "";
  494. }
  495. set {
  496. ViewState["suiu"] = value;
  497. }
  498. }
  499. [Localizable (true)]
  500. public string ScrollDownText {
  501. get {
  502. object o = ViewState ["ScrollDownText"];
  503. if (o != null) return (string) o;
  504. return "";
  505. }
  506. set {
  507. ViewState["ScrollDownText"] = value;
  508. }
  509. }
  510. [Localizable (true)]
  511. public string ScrollUpText {
  512. get {
  513. object o = ViewState ["ScrollUpText"];
  514. if (o != null) return (string) o;
  515. return "";
  516. }
  517. set {
  518. ViewState["ScrollUpText"] = value;
  519. }
  520. }
  521. [MonoTODO]
  522. public string DynamicPopOutImageTextFormatString
  523. {
  524. get {
  525. throw new NotImplementedException ();
  526. }
  527. set {
  528. throw new NotImplementedException ();
  529. }
  530. }
  531. [DefaultValue ("")]
  532. [UrlProperty]
  533. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  534. public string DynamicPopOutImageUrl {
  535. get {
  536. object o = ViewState ["dpoiu"];
  537. if (o != null) return (string)o;
  538. return "";
  539. }
  540. set {
  541. ViewState["dpoiu"] = value;
  542. }
  543. }
  544. [MonoTODO]
  545. public string StaticPopOutImageTextFormatString
  546. {
  547. get {
  548. throw new NotImplementedException ();
  549. }
  550. set {
  551. throw new NotImplementedException ();
  552. }
  553. }
  554. [DefaultValue ("")]
  555. [UrlProperty]
  556. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  557. public string StaticPopOutImageUrl {
  558. get {
  559. object o = ViewState ["spoiu"];
  560. if (o != null) return (string)o;
  561. return "";
  562. }
  563. set {
  564. ViewState["spoiu"] = value;
  565. }
  566. }
  567. [DefaultValue ("")]
  568. public string Target {
  569. get {
  570. object o = ViewState ["Target"];
  571. if (o != null) return (string) o;
  572. return "";
  573. }
  574. set {
  575. ViewState["Target"] = value;
  576. }
  577. }
  578. [DefaultValue (null)]
  579. [TemplateContainer (typeof(MenuItemTemplateContainer), BindingDirection.OneWay)]
  580. [PersistenceMode (PersistenceMode.InnerProperty)]
  581. [Browsable (false)]
  582. public ITemplate StaticItemTemplate {
  583. get { return staticItemTemplate; }
  584. set { staticItemTemplate = value; }
  585. }
  586. [DefaultValue (null)]
  587. [TemplateContainer (typeof(MenuItemTemplateContainer), BindingDirection.OneWay)]
  588. [PersistenceMode (PersistenceMode.InnerProperty)]
  589. [Browsable (false)]
  590. public ITemplate DynamicItemTemplate {
  591. get { return dynamicItemTemplate; }
  592. set { dynamicItemTemplate = value; }
  593. }
  594. [Browsable (false)]
  595. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  596. public MenuItem SelectedItem {
  597. get {
  598. if (selectedItem == null && selectedItemPath != null) {
  599. selectedItem = FindItemByPos (selectedItemPath);
  600. }
  601. return selectedItem;
  602. }
  603. }
  604. [Browsable (false)]
  605. [DefaultValue ("")]
  606. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  607. public string SelectedValue {
  608. get { return selectedItem != null ? selectedItem.Value : null; }
  609. }
  610. [MonoTODO]
  611. [Localizable (true)]
  612. public string SkipLinkText
  613. {
  614. get {
  615. object o = ViewState ["SkipLinkText"];
  616. if (o != null)
  617. return (string) o;
  618. return String.Empty;
  619. }
  620. set {
  621. ViewState ["SkipLinkText"] = value;
  622. }
  623. }
  624. internal void SetSelectedItem (MenuItem item)
  625. {
  626. if (selectedItem == item) return;
  627. selectedItem = item;
  628. selectedItemPath = item.Path;
  629. }
  630. public MenuItem FindItem (string valuePath)
  631. {
  632. if (valuePath == null) throw new ArgumentNullException ("valuePath");
  633. string[] path = valuePath.Split (PathSeparator);
  634. int n = 0;
  635. MenuItemCollection col = Items;
  636. bool foundBranch = true;
  637. while (col.Count > 0 && foundBranch) {
  638. foundBranch = false;
  639. foreach (MenuItem item in col) {
  640. if (item.Value == path [n]) {
  641. if (++n == path.Length) return item;
  642. col = item.ChildItems;
  643. foundBranch = true;
  644. break;
  645. }
  646. }
  647. }
  648. return null;
  649. }
  650. string GetBindingKey (string dataMember, int depth)
  651. {
  652. return dataMember + " " + depth;
  653. }
  654. internal MenuItemBinding FindBindingForItem (string type, int depth)
  655. {
  656. if (bindings == null) return null;
  657. MenuItemBinding bin = (MenuItemBinding) bindings [GetBindingKey (type, depth)];
  658. if (bin != null) return bin;
  659. bin = (MenuItemBinding) bindings [GetBindingKey (type, -1)];
  660. if (bin != null) return bin;
  661. bin = (MenuItemBinding) bindings [GetBindingKey ("", depth)];
  662. if (bin != null) return bin;
  663. bin = (MenuItemBinding) bindings [GetBindingKey ("", -1)];
  664. return bin;
  665. }
  666. protected internal override void PerformDataBinding ()
  667. {
  668. base.PerformDataBinding ();
  669. HierarchicalDataSourceView data = GetData ("");
  670. IHierarchicalEnumerable e = data.Select ();
  671. foreach (object obj in e) {
  672. IHierarchyData hdata = e.GetHierarchyData (obj);
  673. MenuItem item = new MenuItem ();
  674. item.Bind (hdata);
  675. Items.Add (item);
  676. OnMenuItemDataBound (new MenuEventArgs (item));
  677. }
  678. }
  679. protected void SetItemDataBound (MenuItem node, bool dataBound)
  680. {
  681. node.SetDataBound (dataBound);
  682. }
  683. protected void SetItemDataPath (MenuItem node, string dataPath)
  684. {
  685. node.SetDataPath (dataPath);
  686. }
  687. protected void SetItemDataItem (MenuItem node, object dataItem)
  688. {
  689. node.SetDataItem (dataItem);
  690. }
  691. protected internal virtual void RaisePostBackEvent (string eventArgument)
  692. {
  693. if (!Enabled)
  694. return;
  695. EnsureChildControls();
  696. MenuItem item = FindItemByPos (eventArgument);
  697. if (item == null) return;
  698. item.Selected = true;
  699. OnMenuItemClick (new MenuEventArgs (item));
  700. }
  701. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  702. {
  703. RaisePostBackEvent (eventArgument);
  704. }
  705. MenuItem FindItemByPos (string path)
  706. {
  707. string[] indexes = path.Split ('_');
  708. MenuItem item = null;
  709. foreach (string index in indexes) {
  710. int i = int.Parse (index);
  711. if (item == null) {
  712. if (i >= Items.Count) return null;
  713. item = Items [i];
  714. } else {
  715. if (i >= item.ChildItems.Count) return null;
  716. item = item.ChildItems [i];
  717. }
  718. }
  719. return item;
  720. }
  721. protected override HtmlTextWriterTag TagKey {
  722. get { return HtmlTextWriterTag.Table; }
  723. }
  724. protected override void TrackViewState()
  725. {
  726. EnsureDataBound ();
  727. base.TrackViewState();
  728. if (dataBindings != null) {
  729. ((IStateManager)dataBindings).TrackViewState ();
  730. }
  731. if (items != null) {
  732. ((IStateManager)items).TrackViewState();
  733. }
  734. if (dynamicMenuItemStyle != null)
  735. dynamicMenuItemStyle.TrackViewState ();
  736. if (dynamicMenuStyle != null)
  737. dynamicMenuStyle.TrackViewState ();
  738. if (levelMenuItemStyles != null)
  739. ((IStateManager)levelMenuItemStyles).TrackViewState();
  740. if (levelSelectedStyles != null)
  741. ((IStateManager)levelSelectedStyles).TrackViewState();
  742. if (levelSubMenuStyles != null)
  743. ((IStateManager)levelSubMenuStyles).TrackViewState();
  744. if (dynamicSelectedStyle != null)
  745. dynamicSelectedStyle.TrackViewState();
  746. if (staticMenuItemStyle != null)
  747. staticMenuItemStyle.TrackViewState ();
  748. if (staticMenuStyle != null)
  749. staticMenuStyle.TrackViewState ();
  750. if (staticSelectedStyle != null)
  751. staticSelectedStyle.TrackViewState();
  752. if (staticHoverStyle != null)
  753. staticHoverStyle.TrackViewState();
  754. if (dynamicHoverStyle != null)
  755. dynamicHoverStyle.TrackViewState();
  756. }
  757. protected override object SaveViewState()
  758. {
  759. object[] states = new object [14];
  760. states[0] = base.SaveViewState ();
  761. states[1] = dataBindings == null ? null : ((IStateManager)dataBindings).SaveViewState();
  762. states[2] = items == null ? null : ((IStateManager)items).SaveViewState();
  763. states[3] = dynamicMenuItemStyle == null ? null : dynamicMenuItemStyle.SaveViewState();
  764. states[4] = dynamicMenuStyle == null ? null : dynamicMenuStyle.SaveViewState();
  765. states[5] = levelMenuItemStyles == null ? null : ((IStateManager)levelMenuItemStyles).SaveViewState();
  766. states[6] = levelSelectedStyles == null ? null : ((IStateManager)levelSelectedStyles).SaveViewState();
  767. states[7] = dynamicSelectedStyle == null ? null : dynamicSelectedStyle.SaveViewState();
  768. states[8] = (staticMenuItemStyle == null ? null : staticMenuItemStyle.SaveViewState());
  769. states[9] = staticMenuStyle == null ? null : staticMenuStyle.SaveViewState();
  770. states[10] = staticSelectedStyle == null ? null : staticSelectedStyle.SaveViewState();
  771. states[11] = staticHoverStyle == null ? null : staticHoverStyle.SaveViewState();
  772. states[12] = dynamicHoverStyle == null ? null : dynamicHoverStyle.SaveViewState();
  773. states[13] = levelSubMenuStyles == null ? null : ((IStateManager)levelSubMenuStyles).SaveViewState();
  774. for (int i = states.Length - 1; i >= 0; i--) {
  775. if (states [i] != null)
  776. return states;
  777. }
  778. return null;
  779. }
  780. protected override void LoadViewState (object savedState)
  781. {
  782. if (savedState == null)
  783. return;
  784. object [] states = (object []) savedState;
  785. base.LoadViewState (states[0]);
  786. if (states[1] != null)
  787. ((IStateManager)DataBindings).LoadViewState(states[1]);
  788. if (states[2] != null)
  789. ((IStateManager)Items).LoadViewState(states[2]);
  790. if (states[3] != null)
  791. DynamicMenuItemStyle.LoadViewState (states[3]);
  792. if (states[4] != null)
  793. DynamicMenuStyle.LoadViewState (states[4]);
  794. if (states[5] != null)
  795. ((IStateManager)LevelMenuItemStyles).LoadViewState(states[5]);
  796. if (states[6] != null)
  797. ((IStateManager)LevelSelectedStyles).LoadViewState(states[6]);
  798. if (states[7] != null)
  799. DynamicSelectedStyle.LoadViewState (states[7]);
  800. if (states[8] != null)
  801. StaticMenuItemStyle.LoadViewState (states[8]);
  802. if (states[9] != null)
  803. StaticMenuStyle.LoadViewState (states[9]);
  804. if (states[10] != null)
  805. StaticSelectedStyle.LoadViewState (states[10]);
  806. if (states[11] != null)
  807. StaticHoverStyle.LoadViewState (states[11]);
  808. if (states[12] != null)
  809. DynamicHoverStyle.LoadViewState (states[12]);
  810. if (states[13] != null)
  811. ((IStateManager)LevelSubMenuStyles).LoadViewState(states[13]);
  812. }
  813. protected internal override void OnInit (EventArgs e)
  814. {
  815. Page.RegisterRequiresControlState (this);
  816. base.OnInit (e);
  817. }
  818. protected internal override void LoadControlState (object ob)
  819. {
  820. if (ob == null) return;
  821. object[] state = (object[]) ob;
  822. base.LoadControlState (state[0]);
  823. selectedItemPath = state[1] as string;
  824. }
  825. protected internal override object SaveControlState ()
  826. {
  827. object bstate = base.SaveControlState ();
  828. object mstate = selectedItemPath;
  829. if (bstate != null || mstate != null)
  830. return new object[] { bstate, mstate };
  831. else
  832. return null;
  833. }
  834. protected internal override void CreateChildControls ()
  835. {
  836. Controls.Clear ();
  837. EnsureDataBound ();
  838. }
  839. protected override void EnsureDataBound ()
  840. {
  841. base.EnsureDataBound ();
  842. }
  843. [MonoTODO]
  844. protected override IDictionary GetDesignModeState ()
  845. {
  846. throw new NotImplementedException ();
  847. }
  848. [MonoTODO]
  849. protected override void SetDesignModeState (IDictionary data)
  850. {
  851. throw new NotImplementedException ();
  852. }
  853. public override ControlCollection Controls {
  854. get { return base.Controls; }
  855. }
  856. public sealed override void DataBind ()
  857. {
  858. base.DataBind ();
  859. }
  860. [MonoTODO]
  861. protected override bool OnBubbleEvent (object source, EventArgs e)
  862. {
  863. throw new NotImplementedException ();
  864. }
  865. [MonoTODO]
  866. protected override void OnDataBinding (EventArgs e)
  867. {
  868. base.OnDataBinding (e);
  869. }
  870. protected internal override void OnPreRender (EventArgs e)
  871. {
  872. base.OnPreRender (e);
  873. if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(Menu), "Menu.js")) {
  874. string url = Page.ClientScript.GetWebResourceUrl (typeof(Menu), "Menu.js");
  875. Page.ClientScript.RegisterClientScriptInclude (typeof(Menu), "Menu.js", url);
  876. }
  877. string cmenu = ClientID + "_data";
  878. string script = string.Format ("var {0} = new Object ();\n", cmenu);
  879. script += string.Format ("{0}.disappearAfter = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DisappearAfter));
  880. script += string.Format ("{0}.vertical = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (Orientation == Orientation.Vertical));
  881. if (DynamicHorizontalOffset != 0)
  882. script += string.Format ("{0}.dho = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DynamicHorizontalOffset));
  883. if (DynamicVerticalOffset != 0)
  884. script += string.Format ("{0}.dvo = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DynamicVerticalOffset));
  885. // The order in which styles are defined matters when more than one class
  886. // is assigned to an element
  887. if (dynamicMenuStyle != null)
  888. RegisterItemStyle (dynamicMenuStyle);
  889. if (staticMenuStyle != null)
  890. RegisterItemStyle (staticMenuStyle);
  891. if (staticMenuItemStyle != null)
  892. RegisterItemStyle (staticMenuItemStyle);
  893. if (dynamicMenuItemStyle != null)
  894. RegisterItemStyle (dynamicMenuItemStyle);
  895. if (levelSubMenuStyles != null)
  896. foreach (Style style in levelSubMenuStyles)
  897. RegisterItemStyle (style);
  898. if (levelMenuItemStyles != null)
  899. foreach (Style style in levelMenuItemStyles)
  900. RegisterItemStyle (style);
  901. if (staticSelectedStyle != null)
  902. RegisterItemStyle (staticSelectedStyle);
  903. if (dynamicSelectedStyle != null)
  904. RegisterItemStyle (dynamicSelectedStyle);
  905. if (levelSelectedStyles != null)
  906. foreach (Style style in levelSelectedStyles)
  907. RegisterItemStyle (style);
  908. if (dynamicHoverStyle != null)
  909. RegisterItemStyle (dynamicHoverStyle);
  910. if (staticHoverStyle != null)
  911. RegisterItemStyle (staticHoverStyle);
  912. if (staticHoverStyle != null)
  913. script += string.Format ("{0}.staticHover = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (staticHoverStyle.RegisteredCssClass));
  914. if (dynamicHoverStyle != null)
  915. script += string.Format ("{0}.dynamicHover = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (dynamicHoverStyle.RegisteredCssClass));
  916. Page.ClientScript.RegisterStartupScript (typeof(Menu), ClientID, script, true);
  917. if (dataBindings != null && dataBindings.Count > 0) {
  918. bindings = new Hashtable ();
  919. foreach (TreeNodeBinding bin in dataBindings) {
  920. string key = GetBindingKey (bin.DataMember, bin.Depth);
  921. bindings [key] = bin;
  922. }
  923. }
  924. else
  925. bindings = null;
  926. }
  927. void RegisterItemStyle (Style baseStyle)
  928. {
  929. Page.Header.StyleSheet.RegisterStyle (baseStyle, this);
  930. Style ts = new Style ();
  931. ts.CopyTextStylesFrom (baseStyle);
  932. Page.Header.StyleSheet.CreateStyleRule (ts, this, "." + baseStyle.RegisteredCssClass + " A");
  933. }
  934. protected internal override void Render (HtmlTextWriter writer)
  935. {
  936. base.Render (writer);
  937. }
  938. protected override void AddAttributesToRender (HtmlTextWriter writer)
  939. {
  940. RenderMenuBeginTagAttributes (writer, false, 0);
  941. }
  942. public override void RenderBeginTag (HtmlTextWriter writer)
  943. {
  944. base.RenderBeginTag (writer);
  945. }
  946. public override void RenderEndTag (HtmlTextWriter writer)
  947. {
  948. base.RenderEndTag (writer);
  949. // Render dynamic menus outside the main control tag
  950. for (int n=0; n<dynamicMenus.Count; n++) {
  951. MenuItem item = (MenuItem) dynamicMenus [n];
  952. RenderDynamicMenu (writer, item);
  953. }
  954. dynamicMenus = null;
  955. }
  956. protected internal override void RenderContents (HtmlTextWriter writer)
  957. {
  958. dynamicMenus = new ArrayList ();
  959. RenderMenuBody (writer, Items, Orientation == Orientation.Vertical, false);
  960. }
  961. void RenderDynamicMenu (HtmlTextWriter writer, MenuItem item)
  962. {
  963. if (dynamicMenuStyle != null)
  964. writer.AddAttribute ("class", dynamicMenuStyle.RegisteredCssClass);
  965. writer.AddStyleAttribute ("visibility", "hidden");
  966. writer.AddStyleAttribute ("position", "absolute");
  967. writer.AddStyleAttribute ("left", "0px");
  968. writer.AddStyleAttribute ("top", "0px");
  969. writer.AddAttribute ("id", GetItemClientId (item, "s"));
  970. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  971. // Up button
  972. writer.AddAttribute ("id", GetItemClientId (item, "cu"));
  973. writer.AddStyleAttribute ("display", "block");
  974. writer.AddStyleAttribute ("text-align", "center");
  975. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "u"));
  976. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "u"));
  977. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  978. string src = ScrollUpImageUrl != "" ? ScrollUpImageUrl : Page.ClientScript.GetWebResourceUrl (typeof(Menu), "arrow_up.gif");
  979. writer.AddAttribute ("src", src);
  980. writer.AddAttribute ("alt", ScrollUpText);
  981. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  982. writer.RenderEndTag (); // IMG
  983. writer.RenderEndTag (); // DIV scroll button
  984. writer.AddAttribute ("id", GetItemClientId (item, "cb")); // Scroll container
  985. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  986. writer.AddAttribute ("id", GetItemClientId (item, "cc")); // Content
  987. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  988. RenderMenu (writer, item.ChildItems, true, true, item.Depth + 1);
  989. writer.RenderEndTag (); // DIV Content
  990. writer.RenderEndTag (); // DIV Scroll container
  991. // Down button
  992. writer.AddAttribute ("id", GetItemClientId (item, "cd"));
  993. writer.AddStyleAttribute ("display", "block");
  994. writer.AddStyleAttribute ("text-align", "center");
  995. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "d"));
  996. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "d"));
  997. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  998. src = ScrollDownImageUrl != "" ? ScrollDownImageUrl : Page.ClientScript.GetWebResourceUrl (typeof(Menu), "arrow_down.gif");
  999. writer.AddAttribute ("src", src);
  1000. writer.AddAttribute ("alt", ScrollDownText);
  1001. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1002. writer.RenderEndTag (); // IMG
  1003. writer.RenderEndTag (); // DIV scroll button
  1004. writer.RenderEndTag (); // DIV menu
  1005. }
  1006. void RenderMenuBeginTagAttributes (HtmlTextWriter writer, bool dynamic, int menuLevel)
  1007. {
  1008. writer.AddAttribute ("cellpadding", "0");
  1009. writer.AddAttribute ("cellspacing", "0");
  1010. string cls = string.Empty;
  1011. if (!dynamic && staticMenuStyle != null)
  1012. cls += staticMenuStyle.RegisteredCssClass + " ";
  1013. if (levelSubMenuStyles != null && menuLevel < levelSubMenuStyles.Count)
  1014. cls += levelSubMenuStyles [menuLevel].RegisteredCssClass;
  1015. if (cls.Length != 0)
  1016. writer.AddAttribute ("class", cls);
  1017. }
  1018. void RenderMenu (HtmlTextWriter writer, MenuItemCollection items, bool vertical, bool dynamic, int menuLevel)
  1019. {
  1020. RenderMenuBeginTag (writer, dynamic, menuLevel);
  1021. RenderMenuBody (writer, items, vertical, dynamic);
  1022. RenderMenuEndTag (writer);
  1023. }
  1024. void RenderMenuBeginTag (HtmlTextWriter writer, bool dynamic, int menuLevel)
  1025. {
  1026. RenderMenuBeginTagAttributes (writer, dynamic, menuLevel);
  1027. writer.RenderBeginTag (HtmlTextWriterTag.Table);
  1028. }
  1029. void RenderMenuEndTag (HtmlTextWriter writer)
  1030. {
  1031. writer.RenderEndTag ();
  1032. }
  1033. void RenderMenuBody (HtmlTextWriter writer, MenuItemCollection items, bool vertical, bool dynamic)
  1034. {
  1035. if (!vertical) writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1036. for (int n=0; n<items.Count; n++) {
  1037. MenuItem item = items [n];
  1038. if (n > 0) {
  1039. Unit itemSpacing = GetItemSpacing (item, dynamic);
  1040. if (itemSpacing != Unit.Empty) {
  1041. if (vertical) {
  1042. writer.AddAttribute ("height", itemSpacing.ToString());
  1043. writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1044. writer.RenderEndTag ();
  1045. } else {
  1046. writer.AddAttribute ("width", itemSpacing.ToString());
  1047. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1048. writer.RenderEndTag ();
  1049. }
  1050. }
  1051. }
  1052. RenderMenuItem (writer, item);
  1053. }
  1054. if (!vertical) writer.RenderEndTag (); // TR
  1055. }
  1056. void RenderMenuItem (HtmlTextWriter writer, MenuItem item)
  1057. {
  1058. bool displayChildren = (item.Depth + 1 < StaticDisplayLevels + MaximumDynamicDisplayLevels);
  1059. bool dynamicChildren = displayChildren && (item.Depth + 1 >= StaticDisplayLevels) && item.ChildItems.Count > 0;
  1060. bool isDynamicItem = item.Depth + 1 > StaticDisplayLevels;
  1061. bool vertical = (Orientation == Orientation.Vertical) || isDynamicItem;
  1062. if (vertical)
  1063. writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1064. Style itemStyle = null;
  1065. if (levelMenuItemStyles != null && item.Depth < levelMenuItemStyles.Count)
  1066. itemStyle = levelMenuItemStyles [item.Depth];
  1067. else if (isDynamicItem) {
  1068. if (dynamicMenuItemStyle != null)
  1069. itemStyle = dynamicMenuItemStyle;
  1070. } else {
  1071. if (staticMenuItemStyle != null)
  1072. itemStyle = staticMenuItemStyle;
  1073. }
  1074. Style selectedStyle = null;
  1075. if (item == SelectedItem) {
  1076. if (levelSelectedStyles != null && item.Depth < levelSelectedStyles.Count)
  1077. selectedStyle = levelSelectedStyles [item.Depth];
  1078. else if (isDynamicItem) {
  1079. if (dynamicSelectedStyle != null)
  1080. selectedStyle = dynamicSelectedStyle;
  1081. } else {
  1082. if (staticSelectedStyle != null)
  1083. selectedStyle = staticSelectedStyle;
  1084. }
  1085. }
  1086. string cls = "";
  1087. if (itemStyle != null) cls += itemStyle.RegisteredCssClass + " ";
  1088. if (selectedStyle != null) cls += selectedStyle.RegisteredCssClass + " ";
  1089. if (cls != "")
  1090. writer.AddAttribute ("class", cls);
  1091. string parentId = isDynamicItem ? "'" + item.Parent.Path + "'" : "null";
  1092. if (dynamicChildren) {
  1093. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
  1094. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}')", ClientID, item.Path));
  1095. } else if (isDynamicItem) {
  1096. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverDynamicLeafItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
  1097. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
  1098. } else {
  1099. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverStaticLeafItem ('{0}','{1}')", ClientID, item.Path));
  1100. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}')", ClientID, item.Path));
  1101. }
  1102. writer.AddAttribute ("id", GetItemClientId (item, "i"));
  1103. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1104. // Top separator image
  1105. if (isDynamicItem && DynamicTopSeparatorImageUrl != "") {
  1106. writer.AddAttribute ("src", DynamicTopSeparatorImageUrl);
  1107. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1108. writer.RenderEndTag (); // IMG
  1109. } else if (!isDynamicItem && StaticTopSeparatorImageUrl != "") {
  1110. writer.AddAttribute ("src", StaticTopSeparatorImageUrl);
  1111. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1112. writer.RenderEndTag (); // IMG
  1113. }
  1114. // Menu item box
  1115. writer.AddAttribute ("cellpadding", "0");
  1116. writer.AddAttribute ("cellspacing", "0");
  1117. writer.AddAttribute ("width", "100%");
  1118. writer.RenderBeginTag (HtmlTextWriterTag.Table);
  1119. writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1120. if (item.Depth > 0 && !isDynamicItem) {
  1121. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1122. writer.AddStyleAttribute ("width", StaticSubMenuIndent.ToString ());
  1123. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1124. writer.RenderEndTag (); // DIV
  1125. writer.RenderEndTag (); // TD
  1126. }
  1127. if (item.ImageUrl != "") {
  1128. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1129. RenderItemHref (writer, item);
  1130. writer.RenderBeginTag (HtmlTextWriterTag.A);
  1131. writer.AddAttribute ("src", item.ImageUrl);
  1132. writer.AddAttribute ("border", "0");
  1133. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1134. writer.RenderEndTag (); // IMG
  1135. writer.RenderEndTag (); // A
  1136. writer.RenderEndTag (); // TD
  1137. }
  1138. // Menu item text
  1139. writer.AddAttribute ("width", "100%");
  1140. if (!ItemWrap)
  1141. writer.AddAttribute ("nowrap", "nowrap");
  1142. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1143. RenderItemHref (writer, item);
  1144. writer.AddStyleAttribute ("text-decoration", "none");
  1145. writer.RenderBeginTag (HtmlTextWriterTag.A);
  1146. RenderItemContent (writer, item, isDynamicItem);
  1147. writer.RenderEndTag (); // A
  1148. writer.RenderEndTag (); // TD
  1149. // Popup image
  1150. if (dynamicChildren) {
  1151. string popOutImage = GetPopOutImage (item, isDynamicItem);
  1152. if (popOutImage != null)
  1153. {
  1154. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1155. writer.AddAttribute ("src", popOutImage);
  1156. writer.AddAttribute ("border", "0");
  1157. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1158. writer.RenderEndTag (); // IMG
  1159. writer.RenderEndTag (); // TD
  1160. }
  1161. }
  1162. writer.RenderEndTag (); // TR
  1163. writer.RenderEndTag (); // TABLE
  1164. // Bottom separator image
  1165. string separatorImg = item.SeparatorImageUrl;
  1166. if (separatorImg.Length == 0) {
  1167. if (isDynamicItem) separatorImg = DynamicBottomSeparatorImageUrl;
  1168. else separatorImg = StaticBottomSeparatorImageUrl;
  1169. }
  1170. if (separatorImg.Length > 0) {
  1171. writer.AddAttribute ("src", separatorImg);
  1172. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1173. writer.RenderEndTag (); // IMG
  1174. }
  1175. // Submenu
  1176. if (vertical) {
  1177. if (displayChildren) {
  1178. if (dynamicChildren) dynamicMenus.Add (item);
  1179. else {
  1180. writer.AddAttribute ("width", "100%");
  1181. RenderMenu (writer, item.ChildItems, true, false, item.Depth + 1);
  1182. }
  1183. }
  1184. writer.RenderEndTag (); // TD
  1185. writer.RenderEndTag (); // TR
  1186. } else {
  1187. writer.RenderEndTag (); // TD
  1188. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1189. if (displayChildren) {
  1190. if (dynamicChildren) dynamicMenus.Add (item);
  1191. else RenderMenu (writer, item.ChildItems, false, false, item.Depth + 1);
  1192. }
  1193. writer.RenderEndTag (); // TD
  1194. }
  1195. }
  1196. void RenderItemContent (HtmlTextWriter writer, MenuItem item, bool isDynamicItem)
  1197. {
  1198. if (isDynamicItem && dynamicItemTemplate != null) {
  1199. MenuItemTemplateContainer cter = new MenuItemTemplateContainer (item.Index, item);
  1200. dynamicItemTemplate.InstantiateIn (cter);
  1201. cter.Render (writer);
  1202. } else if (!isDynamicItem && staticItemTemplate != null) {
  1203. MenuItemTemplateContainer cter = new MenuItemTemplateContainer (item.Index, item);
  1204. staticItemTemplate.InstantiateIn (cter);
  1205. cter.Render (writer);
  1206. } else if (isDynamicItem && DynamicItemFormatString.Length > 0) {
  1207. writer.Write (string.Format (DynamicItemFormatString, item.Text));
  1208. } else if (!isDynamicItem && StaticItemFormatString.Length > 0) {
  1209. writer.Write (string.Format (StaticItemFormatString, item.Text));
  1210. } else {
  1211. writer.Write (item.Text);
  1212. }
  1213. }
  1214. Unit GetItemSpacing (MenuItem item, bool dynamic)
  1215. {
  1216. Unit itemSpacing;
  1217. if (item.Selected) {
  1218. if (levelSelectedStyles != null && item.Depth < levelSelectedStyles.Count) {
  1219. itemSpacing = levelSelectedStyles [item.Depth].ItemSpacing;
  1220. if (itemSpacing != Unit.Empty) return itemSpacing;
  1221. }
  1222. if (dynamic) itemSpacing = DynamicSelectedStyle.ItemSpacing;
  1223. else itemSpacing = StaticSelectedStyle.ItemSpacing;
  1224. if (itemSpacing != Unit.Empty) return itemSpacing;
  1225. }
  1226. if (levelMenuItemStyles != null && item.Depth < levelMenuItemStyles.Count) {
  1227. itemSpacing = levelMenuItemStyles [item.Depth].ItemSpacing;
  1228. if (itemSpacing != Unit.Empty) return itemSpacing;
  1229. }
  1230. if (dynamic) return DynamicMenuItemStyle.ItemSpacing;
  1231. else return StaticMenuItemStyle.ItemSpacing;
  1232. }
  1233. string GetPopOutImage (MenuItem item, bool isDynamicItem)
  1234. {
  1235. if (item.PopOutImageUrl != "")
  1236. return item.PopOutImageUrl;
  1237. if (isDynamicItem) {
  1238. if (DynamicPopOutImageUrl != "")
  1239. return DynamicPopOutImageUrl;
  1240. if (DynamicEnableDefaultPopOutImage)
  1241. return AssemblyResourceLoader.GetResourceUrl (typeof(Menu), "arrow_plus.gif");
  1242. } else {
  1243. if (StaticPopOutImageUrl != "")
  1244. return StaticPopOutImageUrl;
  1245. if (StaticEnableDefaultPopOutImage)
  1246. return AssemblyResourceLoader.GetResourceUrl (typeof(Menu), "arrow_plus.gif");
  1247. }
  1248. return null;
  1249. }
  1250. void RenderItemHref (HtmlTextWriter writer, MenuItem item)
  1251. {
  1252. if (!item.BranchEnabled) {
  1253. writer.AddAttribute ("disabled", "true");
  1254. }
  1255. else if (!item.Selectable) {
  1256. writer.AddAttribute ("href", "#");
  1257. writer.AddStyleAttribute ("cursor", "text");
  1258. }
  1259. else if (item.NavigateUrl != "") {
  1260. writer.AddAttribute ("href", item.NavigateUrl);
  1261. if (item.Target != "")
  1262. writer.AddAttribute ("target", item.Target);
  1263. else if (Target != "")
  1264. writer.AddAttribute ("target", Target);
  1265. }
  1266. else {
  1267. writer.AddAttribute ("href", GetClientEvent (item));
  1268. }
  1269. }
  1270. string GetItemClientId (MenuItem item, string sufix)
  1271. {
  1272. return ClientID + "_" + item.Path + sufix;
  1273. }
  1274. string GetClientEvent (MenuItem item)
  1275. {
  1276. return Page.ClientScript.GetPostBackClientHyperlink (this, item.Path);
  1277. }
  1278. }
  1279. }
  1280. #endif