Menu.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  1. //
  2. // System.Web.UI.WebControls.Menu.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. // Igor Zelmanovich ([email protected])
  7. //
  8. // (C) 2004 Novell, Inc (http://www.novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. #if NET_2_0
  31. using System;
  32. using System.Collections;
  33. using System.Text;
  34. using System.ComponentModel;
  35. using System.Web.UI;
  36. using System.Web.Handlers;
  37. using System.Collections.Specialized;
  38. using System.IO;
  39. using System.Drawing;
  40. using System.Collections.Generic;
  41. namespace System.Web.UI.WebControls
  42. {
  43. [DefaultEvent ("MenuItemClick")]
  44. [ControlValueProperty ("SelectedValue")]
  45. [Designer ("System.Web.UI.Design.WebControls.MenuDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  46. public class Menu : HierarchicalDataBoundControl, IPostBackEventHandler, INamingContainer
  47. {
  48. MenuItemStyle dynamicMenuItemStyle;
  49. SubMenuStyle dynamicMenuStyle;
  50. MenuItemStyle dynamicSelectedStyle;
  51. MenuItemStyle staticMenuItemStyle;
  52. SubMenuStyle staticMenuStyle;
  53. MenuItemStyle staticSelectedStyle;
  54. Style staticHoverStyle;
  55. Style dynamicHoverStyle;
  56. MenuItemStyleCollection levelMenuItemStyles;
  57. MenuItemStyleCollection levelSelectedStyles;
  58. SubMenuStyleCollection levelSubMenuStyles;
  59. ITemplate staticItemTemplate;
  60. ITemplate dynamicItemTemplate;
  61. MenuItemCollection items;
  62. MenuItemBindingCollection dataBindings;
  63. MenuItem selectedItem;
  64. string selectedItemPath;
  65. Hashtable bindings;
  66. Hashtable _menuItemControls;
  67. bool _requiresChildControlsDataBinding;
  68. int registeredStylesCounter = -1;
  69. List<Style> levelSelectedLinkStyles;
  70. List<Style> levelMenuItemLinkStyles;
  71. Style popOutBoxStyle;
  72. Style controlLinkStyle;
  73. Style dynamicMenuItemLinkStyle;
  74. Style staticMenuItemLinkStyle;
  75. Style dynamicSelectedLinkStyle;
  76. Style staticSelectedLinkStyle;
  77. Style dynamicHoverLinkStyle;
  78. Style staticHoverLinkStyle;
  79. private static readonly object MenuItemClickEvent = new object();
  80. private static readonly object MenuItemDataBoundEvent = new object();
  81. public static readonly string MenuItemClickCommandName = "Click";
  82. public event MenuEventHandler MenuItemClick {
  83. add { Events.AddHandler (MenuItemClickEvent, value); }
  84. remove { Events.RemoveHandler (MenuItemClickEvent, value); }
  85. }
  86. public event MenuEventHandler MenuItemDataBound {
  87. add { Events.AddHandler (MenuItemDataBoundEvent, value); }
  88. remove { Events.RemoveHandler (MenuItemDataBoundEvent, value); }
  89. }
  90. protected virtual void OnMenuItemClick (MenuEventArgs e)
  91. {
  92. if (Events != null) {
  93. MenuEventHandler eh = (MenuEventHandler) Events [MenuItemClickEvent];
  94. if (eh != null) eh (this, e);
  95. }
  96. }
  97. protected virtual void OnMenuItemDataBound (MenuEventArgs e)
  98. {
  99. if (Events != null) {
  100. MenuEventHandler eh = (MenuEventHandler) Events [MenuItemDataBoundEvent];
  101. if (eh != null) eh (this, e);
  102. }
  103. }
  104. [DefaultValueAttribute (null)]
  105. [PersistenceMode (PersistenceMode.InnerProperty)]
  106. [EditorAttribute ("System.Web.UI.Design.WebControls.MenuBindingsEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  107. [MergablePropertyAttribute (false)]
  108. public MenuItemBindingCollection DataBindings {
  109. get {
  110. if (dataBindings == null) {
  111. dataBindings = new MenuItemBindingCollection ();
  112. if (IsTrackingViewState)
  113. ((IStateManager)dataBindings).TrackViewState();
  114. }
  115. return dataBindings;
  116. }
  117. }
  118. [DefaultValue (500)]
  119. [ThemeableAttribute (false)]
  120. public int DisappearAfter {
  121. get {
  122. object o = ViewState ["DisappearAfter"];
  123. if (o != null) return (int)o;
  124. return 500;
  125. }
  126. set {
  127. ViewState["DisappearAfter"] = value;
  128. }
  129. }
  130. [ThemeableAttribute (true)]
  131. [DefaultValue ("")]
  132. [UrlProperty]
  133. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  134. public string DynamicBottomSeparatorImageUrl {
  135. get {
  136. object o = ViewState ["dbsiu"];
  137. if (o != null) return (string)o;
  138. return "";
  139. }
  140. set {
  141. ViewState["dbsiu"] = value;
  142. }
  143. }
  144. [DefaultValueAttribute ("")]
  145. public string DynamicItemFormatString {
  146. get {
  147. object o = ViewState ["DynamicItemFormatString"];
  148. if (o != null) return (string)o;
  149. return "";
  150. }
  151. set {
  152. ViewState["DynamicItemFormatString"] = value;
  153. }
  154. }
  155. [DefaultValue ("")]
  156. [UrlProperty]
  157. [WebCategory ("Appearance")]
  158. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  159. public string DynamicTopSeparatorImageUrl {
  160. get {
  161. object o = ViewState ["dtsiu"];
  162. if (o != null) return (string)o;
  163. return "";
  164. }
  165. set {
  166. ViewState["dtsiu"] = value;
  167. }
  168. }
  169. [DefaultValue ("")]
  170. [UrlProperty]
  171. [WebCategory ("Appearance")]
  172. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  173. public string StaticBottomSeparatorImageUrl {
  174. get {
  175. object o = ViewState ["sbsiu"];
  176. if (o != null) return (string)o;
  177. return "";
  178. }
  179. set {
  180. ViewState["sbsiu"] = value;
  181. }
  182. }
  183. [DefaultValue ("")]
  184. [UrlProperty]
  185. [WebCategory ("Appearance")]
  186. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  187. public string StaticTopSeparatorImageUrl {
  188. get {
  189. object o = ViewState ["stsiu"];
  190. if (o != null) return (string)o;
  191. return "";
  192. }
  193. set {
  194. ViewState["stsiu"] = value;
  195. }
  196. }
  197. [DefaultValue (Orientation.Vertical)]
  198. public Orientation Orientation {
  199. get {
  200. object o = ViewState ["Orientation"];
  201. if (o != null) return (Orientation) o;
  202. return Orientation.Vertical;
  203. }
  204. set {
  205. ViewState["Orientation"] = value;
  206. }
  207. }
  208. [DefaultValue (1)]
  209. [ThemeableAttribute (true)]
  210. public int StaticDisplayLevels {
  211. get {
  212. object o = ViewState ["StaticDisplayLevels"];
  213. if (o != null) return (int)o;
  214. return 1;
  215. }
  216. set {
  217. if (value < 1) throw new ArgumentOutOfRangeException ();
  218. ViewState["StaticDisplayLevels"] = value;
  219. }
  220. }
  221. [DefaultValueAttribute ("")]
  222. public string StaticItemFormatString {
  223. get {
  224. object o = ViewState ["StaticItemFormatString"];
  225. if (o != null) return (string)o;
  226. return "";
  227. }
  228. set {
  229. ViewState["StaticItemFormatString"] = value;
  230. }
  231. }
  232. [DefaultValue (typeof (Unit), "16px")]
  233. [ThemeableAttribute (true)]
  234. public Unit StaticSubMenuIndent {
  235. get {
  236. object o = ViewState ["StaticSubMenuIndent"];
  237. if (o != null) return (Unit)o;
  238. return new Unit (16);
  239. }
  240. set {
  241. ViewState["StaticSubMenuIndent"] = value;
  242. }
  243. }
  244. [ThemeableAttribute (true)]
  245. [DefaultValue (3)]
  246. public int MaximumDynamicDisplayLevels {
  247. get {
  248. object o = ViewState ["MaximumDynamicDisplayLevels"];
  249. if (o != null) return (int)o;
  250. return 3;
  251. }
  252. set {
  253. if (value < 0) throw new ArgumentOutOfRangeException ();
  254. ViewState["MaximumDynamicDisplayLevels"] = value;
  255. }
  256. }
  257. [DefaultValue (0)]
  258. public int DynamicVerticalOffset {
  259. get {
  260. object o = ViewState ["DynamicVerticalOffset"];
  261. if (o != null) return (int)o;
  262. return 0;
  263. }
  264. set {
  265. ViewState["DynamicVerticalOffset"] = value;
  266. }
  267. }
  268. [DefaultValue (0)]
  269. public int DynamicHorizontalOffset {
  270. get {
  271. object o = ViewState ["DynamicHorizontalOffset"];
  272. if (o != null) return (int)o;
  273. return 0;
  274. }
  275. set {
  276. ViewState["DynamicHorizontalOffset"] = value;
  277. }
  278. }
  279. [DefaultValue (true)]
  280. public bool DynamicEnableDefaultPopOutImage {
  281. get {
  282. object o = ViewState ["dedpoi"];
  283. if (o != null) return (bool)o;
  284. return true;
  285. }
  286. set {
  287. ViewState["dedpoi"] = value;
  288. }
  289. }
  290. [DefaultValue (true)]
  291. public bool StaticEnableDefaultPopOutImage {
  292. get {
  293. object o = ViewState ["sedpoi"];
  294. if (o != null) return (bool)o;
  295. return true;
  296. }
  297. set {
  298. ViewState["sedpoi"] = value;
  299. }
  300. }
  301. [DefaultValueAttribute (null)]
  302. [PersistenceMode (PersistenceMode.InnerProperty)]
  303. [Editor ("System.Web.UI.Design.MenuItemCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  304. [MergablePropertyAttribute (false)]
  305. public MenuItemCollection Items {
  306. get {
  307. if (items == null) {
  308. items = new MenuItemCollection (this);
  309. if (IsTrackingViewState)
  310. ((IStateManager)items).TrackViewState();
  311. }
  312. return items;
  313. }
  314. }
  315. [DefaultValue ('/')]
  316. public char PathSeparator {
  317. get {
  318. object o = ViewState ["PathSeparator"];
  319. if(o != null) return (char)o;
  320. return '/';
  321. }
  322. set {
  323. ViewState ["PathSeparator"] = value;
  324. }
  325. }
  326. [DefaultValue (false)]
  327. public bool ItemWrap {
  328. get {
  329. object o = ViewState ["ItemWrap"];
  330. if(o != null) return (bool)o;
  331. return false;
  332. }
  333. set {
  334. ViewState ["ItemWrap"] = value;
  335. }
  336. }
  337. private Style PopOutBoxStyle {
  338. get {
  339. if (popOutBoxStyle == null) {
  340. popOutBoxStyle = new Style ();
  341. popOutBoxStyle.BackColor = Color.White;
  342. }
  343. return popOutBoxStyle;
  344. }
  345. }
  346. private Style ControlLinkStyle {
  347. get {
  348. if (controlLinkStyle == null) {
  349. controlLinkStyle = new Style ();
  350. controlLinkStyle.AlwaysRenderTextDecoration = true;
  351. }
  352. return controlLinkStyle;
  353. }
  354. }
  355. private Style DynamicMenuItemLinkStyle {
  356. get {
  357. if (dynamicMenuItemLinkStyle == null) {
  358. dynamicMenuItemLinkStyle = new Style ();
  359. }
  360. return dynamicMenuItemLinkStyle;
  361. }
  362. }
  363. private Style StaticMenuItemLinkStyle {
  364. get {
  365. if (staticMenuItemLinkStyle == null) {
  366. staticMenuItemLinkStyle = new Style ();
  367. }
  368. return staticMenuItemLinkStyle;
  369. }
  370. }
  371. private Style DynamicSelectedLinkStyle {
  372. get {
  373. if (dynamicSelectedLinkStyle == null) {
  374. dynamicSelectedLinkStyle = new Style ();
  375. }
  376. return dynamicSelectedLinkStyle;
  377. }
  378. }
  379. private Style StaticSelectedLinkStyle {
  380. get {
  381. if (staticSelectedLinkStyle == null) {
  382. staticSelectedLinkStyle = new Style ();
  383. }
  384. return staticSelectedLinkStyle;
  385. }
  386. }
  387. private Style DynamicHoverLinkStyle {
  388. get {
  389. if (dynamicHoverLinkStyle == null) {
  390. dynamicHoverLinkStyle = new Style ();
  391. }
  392. return dynamicHoverLinkStyle;
  393. }
  394. }
  395. private Style StaticHoverLinkStyle {
  396. get {
  397. if (staticHoverLinkStyle == null) {
  398. staticHoverLinkStyle = new Style ();
  399. }
  400. return staticHoverLinkStyle;
  401. }
  402. }
  403. [PersistenceMode (PersistenceMode.InnerProperty)]
  404. [NotifyParentProperty (true)]
  405. [DefaultValue (null)]
  406. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  407. public MenuItemStyle DynamicMenuItemStyle {
  408. get {
  409. if (dynamicMenuItemStyle == null) {
  410. dynamicMenuItemStyle = new MenuItemStyle ();
  411. if (IsTrackingViewState)
  412. dynamicMenuItemStyle.TrackViewState();
  413. }
  414. return dynamicMenuItemStyle;
  415. }
  416. }
  417. [PersistenceMode (PersistenceMode.InnerProperty)]
  418. [NotifyParentProperty (true)]
  419. [DefaultValue (null)]
  420. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  421. public MenuItemStyle DynamicSelectedStyle {
  422. get {
  423. if (dynamicSelectedStyle == null) {
  424. dynamicSelectedStyle = new MenuItemStyle ();
  425. if (IsTrackingViewState)
  426. dynamicSelectedStyle.TrackViewState();
  427. }
  428. return dynamicSelectedStyle;
  429. }
  430. }
  431. [PersistenceMode (PersistenceMode.InnerProperty)]
  432. [NotifyParentProperty (true)]
  433. [DefaultValue (null)]
  434. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  435. public SubMenuStyle DynamicMenuStyle {
  436. get {
  437. if (dynamicMenuStyle == null) {
  438. dynamicMenuStyle = new SubMenuStyle ();
  439. if (IsTrackingViewState)
  440. dynamicMenuStyle.TrackViewState();
  441. }
  442. return dynamicMenuStyle;
  443. }
  444. }
  445. [PersistenceMode (PersistenceMode.InnerProperty)]
  446. [NotifyParentProperty (true)]
  447. [DefaultValue (null)]
  448. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  449. public MenuItemStyle StaticMenuItemStyle {
  450. get {
  451. if (staticMenuItemStyle == null) {
  452. staticMenuItemStyle = new MenuItemStyle ();
  453. if (IsTrackingViewState)
  454. staticMenuItemStyle.TrackViewState();
  455. }
  456. return staticMenuItemStyle;
  457. }
  458. }
  459. [PersistenceMode (PersistenceMode.InnerProperty)]
  460. [NotifyParentProperty (true)]
  461. [DefaultValue (null)]
  462. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  463. public MenuItemStyle StaticSelectedStyle {
  464. get {
  465. if (staticSelectedStyle == null) {
  466. staticSelectedStyle = new MenuItemStyle ();
  467. if (IsTrackingViewState)
  468. staticSelectedStyle.TrackViewState();
  469. }
  470. return staticSelectedStyle;
  471. }
  472. }
  473. [PersistenceMode (PersistenceMode.InnerProperty)]
  474. [NotifyParentProperty (true)]
  475. [DefaultValue (null)]
  476. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  477. public SubMenuStyle StaticMenuStyle {
  478. get {
  479. if (staticMenuStyle == null) {
  480. staticMenuStyle = new SubMenuStyle ();
  481. if (IsTrackingViewState)
  482. staticMenuStyle.TrackViewState();
  483. }
  484. return staticMenuStyle;
  485. }
  486. }
  487. [DefaultValue (null)]
  488. [PersistenceMode (PersistenceMode.InnerProperty)]
  489. [Editor ("System.Web.UI.Design.WebControls.MenuItemStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  490. public MenuItemStyleCollection LevelMenuItemStyles {
  491. get {
  492. if (levelMenuItemStyles == null) {
  493. levelMenuItemStyles = new MenuItemStyleCollection ();
  494. if (IsTrackingViewState)
  495. ((IStateManager)levelMenuItemStyles).TrackViewState();
  496. }
  497. return levelMenuItemStyles;
  498. }
  499. }
  500. [DefaultValue (null)]
  501. [PersistenceMode (PersistenceMode.InnerProperty)]
  502. [Editor ("System.Web.UI.Design.WebControls.MenuItemStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  503. public MenuItemStyleCollection LevelSelectedStyles {
  504. get {
  505. if (levelSelectedStyles == null) {
  506. levelSelectedStyles = new MenuItemStyleCollection ();
  507. if (IsTrackingViewState)
  508. ((IStateManager)levelSelectedStyles).TrackViewState();
  509. }
  510. return levelSelectedStyles;
  511. }
  512. }
  513. [DefaultValue (null)]
  514. [PersistenceMode (PersistenceMode.InnerProperty)]
  515. [Editor ("System.Web.UI.Design.WebControls.SubMenuStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  516. public SubMenuStyleCollection LevelSubMenuStyles {
  517. get {
  518. if (levelSubMenuStyles == null) {
  519. levelSubMenuStyles = new SubMenuStyleCollection ();
  520. if (IsTrackingViewState)
  521. ((IStateManager)levelSubMenuStyles).TrackViewState();
  522. }
  523. return levelSubMenuStyles;
  524. }
  525. }
  526. [PersistenceMode (PersistenceMode.InnerProperty)]
  527. [NotifyParentProperty (true)]
  528. [DefaultValue (null)]
  529. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  530. public Style DynamicHoverStyle {
  531. get {
  532. if (dynamicHoverStyle == null) {
  533. dynamicHoverStyle = new Style ();
  534. if (IsTrackingViewState)
  535. dynamicHoverStyle.TrackViewState();
  536. }
  537. return dynamicHoverStyle;
  538. }
  539. }
  540. [PersistenceMode (PersistenceMode.InnerProperty)]
  541. [NotifyParentProperty (true)]
  542. [DefaultValue (null)]
  543. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  544. public Style StaticHoverStyle {
  545. get {
  546. if (staticHoverStyle == null) {
  547. staticHoverStyle = new Style ();
  548. if (IsTrackingViewState)
  549. staticHoverStyle.TrackViewState();
  550. }
  551. return staticHoverStyle;
  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 ScrollDownImageUrl {
  558. get {
  559. object o = ViewState ["sdiu"];
  560. if (o != null) return (string)o;
  561. return "";
  562. }
  563. set {
  564. ViewState["sdiu"] = value;
  565. }
  566. }
  567. [DefaultValue ("")]
  568. [UrlProperty]
  569. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  570. public string ScrollUpImageUrl {
  571. get {
  572. object o = ViewState ["suiu"];
  573. if (o != null) return (string)o;
  574. return "";
  575. }
  576. set {
  577. ViewState["suiu"] = value;
  578. }
  579. }
  580. [Localizable (true)]
  581. public string ScrollDownText {
  582. get {
  583. object o = ViewState ["ScrollDownText"];
  584. if (o != null) return (string) o;
  585. return Locale.GetText ("Scroll down");
  586. }
  587. set {
  588. ViewState["ScrollDownText"] = value;
  589. }
  590. }
  591. [Localizable (true)]
  592. public string ScrollUpText {
  593. get {
  594. object o = ViewState ["ScrollUpText"];
  595. if (o != null) return (string) o;
  596. return Locale.GetText ("Scroll up");
  597. }
  598. set {
  599. ViewState["ScrollUpText"] = value;
  600. }
  601. }
  602. public string DynamicPopOutImageTextFormatString
  603. {
  604. get
  605. {
  606. object o = ViewState ["dpoitf"];
  607. if (o != null) return (string) o;
  608. return Locale.GetText ("Expand {0}");
  609. }
  610. set
  611. {
  612. ViewState ["dpoitf"] = value;
  613. }
  614. }
  615. [DefaultValue ("")]
  616. [UrlProperty]
  617. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  618. public string DynamicPopOutImageUrl {
  619. get {
  620. object o = ViewState ["dpoiu"];
  621. if (o != null) return (string)o;
  622. return "";
  623. }
  624. set {
  625. ViewState["dpoiu"] = value;
  626. }
  627. }
  628. public string StaticPopOutImageTextFormatString
  629. {
  630. get
  631. {
  632. object o = ViewState ["spoitf"];
  633. if (o != null) return (string) o;
  634. return Locale.GetText ("Expand {0}");
  635. }
  636. set
  637. {
  638. ViewState ["spoitf"] = value;
  639. }
  640. }
  641. [DefaultValue ("")]
  642. [UrlProperty]
  643. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  644. public string StaticPopOutImageUrl {
  645. get {
  646. object o = ViewState ["spoiu"];
  647. if (o != null) return (string)o;
  648. return "";
  649. }
  650. set {
  651. ViewState["spoiu"] = value;
  652. }
  653. }
  654. [DefaultValue ("")]
  655. public string Target {
  656. get {
  657. object o = ViewState ["Target"];
  658. if (o != null) return (string) o;
  659. return "";
  660. }
  661. set {
  662. ViewState["Target"] = value;
  663. }
  664. }
  665. [DefaultValue (null)]
  666. [TemplateContainer (typeof(MenuItemTemplateContainer), BindingDirection.OneWay)]
  667. [PersistenceMode (PersistenceMode.InnerProperty)]
  668. [Browsable (false)]
  669. public ITemplate StaticItemTemplate {
  670. get { return staticItemTemplate; }
  671. set { staticItemTemplate = value; }
  672. }
  673. [DefaultValue (null)]
  674. [TemplateContainer (typeof(MenuItemTemplateContainer), BindingDirection.OneWay)]
  675. [PersistenceMode (PersistenceMode.InnerProperty)]
  676. [Browsable (false)]
  677. public ITemplate DynamicItemTemplate {
  678. get { return dynamicItemTemplate; }
  679. set { dynamicItemTemplate = value; }
  680. }
  681. [Browsable (false)]
  682. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  683. public MenuItem SelectedItem {
  684. get {
  685. if (selectedItem == null && selectedItemPath != null) {
  686. selectedItem = FindItemByPos (selectedItemPath);
  687. }
  688. return selectedItem;
  689. }
  690. }
  691. [Browsable (false)]
  692. [DefaultValue ("")]
  693. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  694. public string SelectedValue {
  695. get { return selectedItem != null ? selectedItem.Value : ""; }
  696. }
  697. [Localizable (true)]
  698. public string SkipLinkText
  699. {
  700. get {
  701. object o = ViewState ["SkipLinkText"];
  702. if (o != null)
  703. return (string) o;
  704. return "Skip Navigation Links";
  705. }
  706. set {
  707. ViewState ["SkipLinkText"] = value;
  708. }
  709. }
  710. internal void SetSelectedItem (MenuItem item)
  711. {
  712. if (selectedItem == item) return;
  713. selectedItem = item;
  714. selectedItemPath = item.Path;
  715. }
  716. public MenuItem FindItem (string valuePath)
  717. {
  718. if (valuePath == null) throw new ArgumentNullException ("valuePath");
  719. string[] path = valuePath.Split (PathSeparator);
  720. int n = 0;
  721. MenuItemCollection col = Items;
  722. bool foundBranch = true;
  723. while (col.Count > 0 && foundBranch) {
  724. foundBranch = false;
  725. foreach (MenuItem item in col) {
  726. if (item.Value == path [n]) {
  727. if (++n == path.Length) return item;
  728. col = item.ChildItems;
  729. foundBranch = true;
  730. break;
  731. }
  732. }
  733. }
  734. return null;
  735. }
  736. string GetBindingKey (string dataMember, int depth)
  737. {
  738. return dataMember + " " + depth;
  739. }
  740. internal MenuItemBinding FindBindingForItem (string type, int depth)
  741. {
  742. if (bindings == null) return null;
  743. MenuItemBinding bin = (MenuItemBinding) bindings [GetBindingKey (type, depth)];
  744. if (bin != null) return bin;
  745. bin = (MenuItemBinding) bindings [GetBindingKey (type, -1)];
  746. if (bin != null) return bin;
  747. bin = (MenuItemBinding) bindings [GetBindingKey ("", depth)];
  748. if (bin != null) return bin;
  749. bin = (MenuItemBinding) bindings [GetBindingKey ("", -1)];
  750. return bin;
  751. }
  752. protected internal override void PerformDataBinding ()
  753. {
  754. base.PerformDataBinding ();
  755. // Do not attempt to bind data if there is no
  756. // data source set.
  757. if (!IsBoundUsingDataSourceID && (DataSource == null)) {
  758. EnsureChildControlsDataBound ();
  759. return;
  760. }
  761. InitializeDataBindings ();
  762. HierarchicalDataSourceView data = GetData ("");
  763. if (data == null) {
  764. throw new InvalidOperationException ("No view returned by data source control.");
  765. }
  766. Items.Clear ();
  767. IHierarchicalEnumerable e = data.Select ();
  768. FillBoundChildrenRecursive (e, Items);
  769. CreateChildControlsForItems ();
  770. ChildControlsCreated = true;
  771. EnsureChildControlsDataBound ();
  772. }
  773. private void FillBoundChildrenRecursive (IHierarchicalEnumerable hEnumerable, MenuItemCollection itemCollection)
  774. {
  775. if (hEnumerable == null)
  776. return;
  777. foreach (object obj in hEnumerable) {
  778. IHierarchyData hdata = hEnumerable.GetHierarchyData (obj);
  779. MenuItem item = new MenuItem ();
  780. itemCollection.Add (item);
  781. item.Bind (hdata);
  782. OnMenuItemDataBound (new MenuEventArgs (item));
  783. if (hdata == null || !hdata.HasChildren)
  784. continue;
  785. IHierarchicalEnumerable e = hdata.GetChildren ();
  786. FillBoundChildrenRecursive (e, item.ChildItems);
  787. }
  788. }
  789. protected void SetItemDataBound (MenuItem node, bool dataBound)
  790. {
  791. node.SetDataBound (dataBound);
  792. }
  793. protected void SetItemDataPath (MenuItem node, string dataPath)
  794. {
  795. node.SetDataPath (dataPath);
  796. }
  797. protected void SetItemDataItem (MenuItem node, object dataItem)
  798. {
  799. node.SetDataItem (dataItem);
  800. }
  801. protected internal virtual void RaisePostBackEvent (string eventArgument)
  802. {
  803. if (!Enabled)
  804. return;
  805. EnsureChildControls();
  806. MenuItem item = FindItemByPos (eventArgument);
  807. if (item == null) return;
  808. item.Selected = true;
  809. OnMenuItemClick (new MenuEventArgs (item));
  810. }
  811. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  812. {
  813. RaisePostBackEvent (eventArgument);
  814. }
  815. MenuItem FindItemByPos (string path)
  816. {
  817. string[] indexes = path.Split ('_');
  818. MenuItem item = null;
  819. foreach (string index in indexes) {
  820. int i = int.Parse (index);
  821. if (item == null) {
  822. if (i >= Items.Count) return null;
  823. item = Items [i];
  824. } else {
  825. if (i >= item.ChildItems.Count) return null;
  826. item = item.ChildItems [i];
  827. }
  828. }
  829. return item;
  830. }
  831. protected override HtmlTextWriterTag TagKey {
  832. get { return HtmlTextWriterTag.Table; }
  833. }
  834. protected override void TrackViewState()
  835. {
  836. EnsureDataBound ();
  837. base.TrackViewState();
  838. if (dataBindings != null) {
  839. ((IStateManager)dataBindings).TrackViewState ();
  840. }
  841. if (items != null) {
  842. ((IStateManager)items).TrackViewState();
  843. }
  844. if (dynamicMenuItemStyle != null)
  845. dynamicMenuItemStyle.TrackViewState ();
  846. if (dynamicMenuStyle != null)
  847. dynamicMenuStyle.TrackViewState ();
  848. if (levelMenuItemStyles != null && levelMenuItemStyles.Count > 0)
  849. ((IStateManager)levelMenuItemStyles).TrackViewState();
  850. if (levelSelectedStyles != null && levelMenuItemStyles.Count > 0)
  851. ((IStateManager)levelSelectedStyles).TrackViewState();
  852. if (levelSubMenuStyles != null && levelSubMenuStyles.Count > 0)
  853. ((IStateManager)levelSubMenuStyles).TrackViewState();
  854. if (dynamicSelectedStyle != null)
  855. dynamicSelectedStyle.TrackViewState();
  856. if (staticMenuItemStyle != null)
  857. staticMenuItemStyle.TrackViewState ();
  858. if (staticMenuStyle != null)
  859. staticMenuStyle.TrackViewState ();
  860. if (staticSelectedStyle != null)
  861. staticSelectedStyle.TrackViewState();
  862. if (staticHoverStyle != null)
  863. staticHoverStyle.TrackViewState();
  864. if (dynamicHoverStyle != null)
  865. dynamicHoverStyle.TrackViewState();
  866. }
  867. protected override object SaveViewState()
  868. {
  869. object[] states = new object [14];
  870. states[0] = base.SaveViewState ();
  871. states[1] = dataBindings == null ? null : ((IStateManager)dataBindings).SaveViewState();
  872. states[2] = items == null ? null : ((IStateManager)items).SaveViewState();
  873. states[3] = dynamicMenuItemStyle == null ? null : dynamicMenuItemStyle.SaveViewState();
  874. states[4] = dynamicMenuStyle == null ? null : dynamicMenuStyle.SaveViewState();
  875. states[5] = levelMenuItemStyles == null ? null : ((IStateManager)levelMenuItemStyles).SaveViewState();
  876. states[6] = levelSelectedStyles == null ? null : ((IStateManager)levelSelectedStyles).SaveViewState();
  877. states[7] = dynamicSelectedStyle == null ? null : dynamicSelectedStyle.SaveViewState();
  878. states[8] = (staticMenuItemStyle == null ? null : staticMenuItemStyle.SaveViewState());
  879. states[9] = staticMenuStyle == null ? null : staticMenuStyle.SaveViewState();
  880. states[10] = staticSelectedStyle == null ? null : staticSelectedStyle.SaveViewState();
  881. states[11] = staticHoverStyle == null ? null : staticHoverStyle.SaveViewState();
  882. states[12] = dynamicHoverStyle == null ? null : dynamicHoverStyle.SaveViewState();
  883. states[13] = levelSubMenuStyles == null ? null : ((IStateManager)levelSubMenuStyles).SaveViewState();
  884. for (int i = states.Length - 1; i >= 0; i--) {
  885. if (states [i] != null)
  886. return states;
  887. }
  888. return null;
  889. }
  890. protected override void LoadViewState (object savedState)
  891. {
  892. if (savedState == null)
  893. return;
  894. object [] states = (object []) savedState;
  895. base.LoadViewState (states[0]);
  896. if (states[1] != null)
  897. ((IStateManager)DataBindings).LoadViewState(states[1]);
  898. if (states[2] != null)
  899. ((IStateManager)Items).LoadViewState(states[2]);
  900. if (states[3] != null)
  901. DynamicMenuItemStyle.LoadViewState (states[3]);
  902. if (states[4] != null)
  903. DynamicMenuStyle.LoadViewState (states[4]);
  904. if (states[5] != null)
  905. ((IStateManager)LevelMenuItemStyles).LoadViewState(states[5]);
  906. if (states[6] != null)
  907. ((IStateManager)LevelSelectedStyles).LoadViewState(states[6]);
  908. if (states[7] != null)
  909. DynamicSelectedStyle.LoadViewState (states[7]);
  910. if (states[8] != null)
  911. StaticMenuItemStyle.LoadViewState (states[8]);
  912. if (states[9] != null)
  913. StaticMenuStyle.LoadViewState (states[9]);
  914. if (states[10] != null)
  915. StaticSelectedStyle.LoadViewState (states[10]);
  916. if (states[11] != null)
  917. StaticHoverStyle.LoadViewState (states[11]);
  918. if (states[12] != null)
  919. DynamicHoverStyle.LoadViewState (states[12]);
  920. if (states[13] != null)
  921. ((IStateManager)LevelSubMenuStyles).LoadViewState(states[13]);
  922. }
  923. protected internal override void OnInit (EventArgs e)
  924. {
  925. Page.RegisterRequiresControlState (this);
  926. base.OnInit (e);
  927. }
  928. protected internal override void LoadControlState (object ob)
  929. {
  930. if (ob == null) return;
  931. object[] state = (object[]) ob;
  932. base.LoadControlState (state[0]);
  933. selectedItemPath = state[1] as string;
  934. }
  935. protected internal override object SaveControlState ()
  936. {
  937. object bstate = base.SaveControlState ();
  938. object mstate = selectedItemPath;
  939. if (bstate != null || mstate != null)
  940. return new object[] { bstate, mstate };
  941. else
  942. return null;
  943. }
  944. protected internal override void CreateChildControls ()
  945. {
  946. if (!IsBoundUsingDataSourceID && (DataSource == null)) {
  947. CreateChildControlsForItems ();
  948. }
  949. else {
  950. EnsureDataBound ();
  951. }
  952. }
  953. private void CreateChildControlsForItems () {
  954. Controls.Clear ();
  955. // Check for HasChildViewState to avoid unnecessary calls to ClearChildViewState.
  956. if (HasChildViewState)
  957. ClearChildViewState ();
  958. _menuItemControls = new Hashtable ();
  959. CreateChildControlsForItems (Items);
  960. _requiresChildControlsDataBinding = true;
  961. }
  962. private void CreateChildControlsForItems (MenuItemCollection items ) {
  963. foreach (MenuItem item in items) {
  964. bool isDynamicItem = IsDynamicItem (item);
  965. if (isDynamicItem && dynamicItemTemplate != null) {
  966. MenuItemTemplateContainer cter = new MenuItemTemplateContainer (item.Index, item);
  967. dynamicItemTemplate.InstantiateIn (cter);
  968. _menuItemControls [item] = cter;
  969. Controls.Add (cter);
  970. }
  971. else if (!isDynamicItem && staticItemTemplate != null) {
  972. MenuItemTemplateContainer cter = new MenuItemTemplateContainer (item.Index, item);
  973. staticItemTemplate.InstantiateIn (cter);
  974. _menuItemControls [item] = cter;
  975. Controls.Add (cter);
  976. }
  977. if (item.HasChildData)
  978. CreateChildControlsForItems (item.ChildItems);
  979. }
  980. }
  981. protected override void EnsureDataBound ()
  982. {
  983. base.EnsureDataBound ();
  984. EnsureChildControlsDataBound ();
  985. }
  986. private void EnsureChildControlsDataBound () {
  987. if (!_requiresChildControlsDataBinding)
  988. return;
  989. DataBindChildren ();
  990. _requiresChildControlsDataBinding = false;
  991. }
  992. [MonoTODO ("Not implemented")]
  993. protected override IDictionary GetDesignModeState ()
  994. {
  995. throw new NotImplementedException ();
  996. }
  997. [MonoTODO ("Not implemented")]
  998. protected override void SetDesignModeState (IDictionary data)
  999. {
  1000. throw new NotImplementedException ();
  1001. }
  1002. public override ControlCollection Controls {
  1003. get { return base.Controls; }
  1004. }
  1005. public sealed override void DataBind ()
  1006. {
  1007. base.DataBind ();
  1008. }
  1009. protected override bool OnBubbleEvent (object source, EventArgs args)
  1010. {
  1011. if (!(args is CommandEventArgs))
  1012. return false;
  1013. MenuEventArgs menuArgs = args as MenuEventArgs;
  1014. if (menuArgs != null && string.Equals (menuArgs.CommandName, MenuItemClickCommandName))
  1015. OnMenuItemClick (menuArgs);
  1016. return true;
  1017. }
  1018. protected override void OnDataBinding (EventArgs e)
  1019. {
  1020. EnsureChildControls ();
  1021. base.OnDataBinding (e);
  1022. }
  1023. protected internal override void OnPreRender (EventArgs e)
  1024. {
  1025. base.OnPreRender (e);
  1026. if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(Menu), "Menu.js")) {
  1027. string url = Page.ClientScript.GetWebResourceUrl (typeof(Menu), "Menu.js");
  1028. Page.ClientScript.RegisterClientScriptInclude (typeof(Menu), "Menu.js", url);
  1029. }
  1030. string cmenu = ClientID + "_data";
  1031. string script = string.Format ("var {0} = new Object ();\n", cmenu);
  1032. script += string.Format ("{0}.disappearAfter = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DisappearAfter));
  1033. script += string.Format ("{0}.vertical = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (Orientation == Orientation.Vertical));
  1034. if (DynamicHorizontalOffset != 0)
  1035. script += string.Format ("{0}.dho = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DynamicHorizontalOffset));
  1036. if (DynamicVerticalOffset != 0)
  1037. script += string.Format ("{0}.dvo = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DynamicVerticalOffset));
  1038. // The order in which styles are defined matters when more than one class
  1039. // is assigned to an element
  1040. RegisterStyle (PopOutBoxStyle);
  1041. RegisterStyle (ControlStyle, ControlLinkStyle);
  1042. if (staticMenuItemStyle != null)
  1043. RegisterStyle (StaticMenuItemStyle, StaticMenuItemLinkStyle);
  1044. if (staticMenuStyle != null)
  1045. RegisterStyle (StaticMenuStyle);
  1046. if (dynamicMenuItemStyle != null)
  1047. RegisterStyle (DynamicMenuItemStyle, DynamicMenuItemLinkStyle);
  1048. if (dynamicMenuStyle != null)
  1049. RegisterStyle (DynamicMenuStyle);
  1050. if (levelMenuItemStyles != null && levelMenuItemStyles.Count > 0) {
  1051. levelMenuItemLinkStyles = new List<Style> (levelMenuItemStyles.Count);
  1052. foreach (Style style in levelMenuItemStyles) {
  1053. Style linkStyle = new Style ();
  1054. levelMenuItemLinkStyles.Add (linkStyle);
  1055. RegisterStyle (style, linkStyle);
  1056. }
  1057. }
  1058. if (levelSubMenuStyles != null)
  1059. foreach (Style style in levelSubMenuStyles)
  1060. RegisterStyle (style);
  1061. if (staticSelectedStyle != null)
  1062. RegisterStyle (staticSelectedStyle, StaticSelectedLinkStyle);
  1063. if (dynamicSelectedStyle != null)
  1064. RegisterStyle (dynamicSelectedStyle, DynamicSelectedLinkStyle);
  1065. if (levelSelectedStyles != null && levelSelectedStyles.Count > 0) {
  1066. levelSelectedLinkStyles = new List<Style> (levelSelectedStyles.Count);
  1067. foreach (Style style in levelSelectedStyles) {
  1068. Style linkStyle = new Style ();
  1069. levelSelectedLinkStyles.Add (linkStyle);
  1070. RegisterStyle (style, linkStyle);
  1071. }
  1072. }
  1073. if (staticHoverStyle != null) {
  1074. if (Page.Header == null)
  1075. throw new InvalidOperationException ("Using Menu.StaticHoverStyle requires Page.Header to be non-null (e.g. <head runat=\"server\" />).");
  1076. RegisterStyle (staticHoverStyle, StaticHoverLinkStyle);
  1077. script += string.Format ("{0}.staticHover = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (staticHoverStyle.RegisteredCssClass));
  1078. script += string.Format ("{0}.staticLinkHover = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (StaticHoverLinkStyle.RegisteredCssClass));
  1079. }
  1080. if (dynamicHoverStyle != null) {
  1081. if (Page.Header == null)
  1082. throw new InvalidOperationException ("Using Menu.DynamicHoverStyle requires Page.Header to be non-null (e.g. <head runat=\"server\" />).");
  1083. RegisterStyle (dynamicHoverStyle, DynamicHoverLinkStyle);
  1084. script += string.Format ("{0}.dynamicHover = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (dynamicHoverStyle.RegisteredCssClass));
  1085. script += string.Format ("{0}.dynamicLinkHover = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DynamicHoverLinkStyle.RegisteredCssClass));
  1086. }
  1087. Page.ClientScript.RegisterStartupScript (typeof(Menu), ClientID, script, true);
  1088. }
  1089. void InitializeDataBindings () {
  1090. if (dataBindings != null && dataBindings.Count > 0) {
  1091. bindings = new Hashtable ();
  1092. foreach (MenuItemBinding bin in dataBindings) {
  1093. string key = GetBindingKey (bin.DataMember, bin.Depth);
  1094. bindings [key] = bin;
  1095. }
  1096. }
  1097. else
  1098. bindings = null;
  1099. }
  1100. string IncrementStyleClassName () {
  1101. registeredStylesCounter++;
  1102. return ClientID + "_" + registeredStylesCounter;
  1103. }
  1104. void RegisterStyle (Style baseStyle, Style linkStyle) {
  1105. linkStyle.CopyTextStylesFrom (baseStyle);
  1106. linkStyle.BorderStyle = BorderStyle.None;
  1107. RegisterStyle (linkStyle);
  1108. RegisterStyle (baseStyle);
  1109. }
  1110. void RegisterStyle (Style baseStyle)
  1111. {
  1112. if (Page.Header == null)
  1113. return;
  1114. string className = IncrementStyleClassName ();
  1115. baseStyle.SetRegisteredCssClass (className);
  1116. Page.Header.StyleSheet.CreateStyleRule (baseStyle, this, "." + className);
  1117. }
  1118. protected internal override void Render (HtmlTextWriter writer)
  1119. {
  1120. if (Items.Count > 0)
  1121. base.Render (writer);
  1122. }
  1123. protected override void AddAttributesToRender (HtmlTextWriter writer)
  1124. {
  1125. writer.AddAttribute ("cellpadding", "0");
  1126. writer.AddAttribute ("cellspacing", "0");
  1127. writer.AddAttribute ("border", "0");
  1128. if (Page.Header != null) {
  1129. // styles are registered
  1130. if (staticMenuStyle != null) {
  1131. AddCssClass (ControlStyle, staticMenuStyle.CssClass);
  1132. AddCssClass (ControlStyle, staticMenuStyle.RegisteredCssClass);
  1133. }
  1134. if (levelSubMenuStyles != null && levelSubMenuStyles.Count > 0) {
  1135. AddCssClass (ControlStyle, levelSubMenuStyles [0].CssClass);
  1136. AddCssClass (ControlStyle, levelSubMenuStyles [0].RegisteredCssClass);
  1137. }
  1138. }
  1139. else {
  1140. // styles are not registered
  1141. if (staticMenuStyle != null){
  1142. ControlStyle.CopyFrom (staticMenuStyle);
  1143. }
  1144. if (levelSubMenuStyles != null && levelSubMenuStyles.Count > 0) {
  1145. ControlStyle.CopyFrom (levelSubMenuStyles [0]);
  1146. }
  1147. }
  1148. base.AddAttributesToRender (writer);
  1149. }
  1150. void AddCssClass (Style style, string cssClass) {
  1151. style.AddCssClass (cssClass);
  1152. }
  1153. public override void RenderBeginTag (HtmlTextWriter writer)
  1154. {
  1155. if (SkipLinkText != "") {
  1156. System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
  1157. anchor.HRef = "#" + ClientID + "_SkipLink";
  1158. Image img = new Image ();
  1159. ClientScriptManager csm = new ClientScriptManager (null);
  1160. img.ImageUrl = csm.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif");
  1161. img.Attributes.Add ("height", "0");
  1162. img.Attributes.Add ("width", "0");
  1163. img.AlternateText = SkipLinkText;
  1164. anchor.Controls.Add (img);
  1165. anchor.Render (writer);
  1166. }
  1167. base.RenderBeginTag (writer);
  1168. }
  1169. public override void RenderEndTag (HtmlTextWriter writer)
  1170. {
  1171. base.RenderEndTag (writer);
  1172. if (StaticDisplayLevels == 1 && MaximumDynamicDisplayLevels > 0)
  1173. RenderDynamicMenu (writer, Items);
  1174. if (SkipLinkText != "") {
  1175. System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
  1176. anchor.ID = ClientID + "_SkipLink";
  1177. anchor.Render (writer);
  1178. }
  1179. }
  1180. protected internal override void RenderContents (HtmlTextWriter writer)
  1181. {
  1182. RenderMenuBody (writer, Items, Orientation == Orientation.Vertical, false, false);
  1183. }
  1184. void RenderDynamicMenu (HtmlTextWriter writer, MenuItemCollection items) {
  1185. for (int n = 0; n < items.Count; n++) {
  1186. if (DisplayChildren (items [n])) {
  1187. RenderDynamicMenu (writer, items [n]);
  1188. RenderDynamicMenu (writer, items [n].ChildItems);
  1189. }
  1190. }
  1191. }
  1192. void RenderDynamicMenu (HtmlTextWriter writer, MenuItem item)
  1193. {
  1194. SubMenuStyle style = new SubMenuStyle ();
  1195. if (Page.Header != null) {
  1196. AddCssClass (style, PopOutBoxStyle.RegisteredCssClass);
  1197. }
  1198. else {
  1199. style.CopyFrom (PopOutBoxStyle);
  1200. }
  1201. FillMenuStyle (true, item.Depth + 1, style);
  1202. style.AddAttributesToRender (writer);
  1203. writer.AddStyleAttribute ("visibility", "hidden");
  1204. writer.AddStyleAttribute ("position", "absolute");
  1205. writer.AddStyleAttribute ("z-index", "1");
  1206. writer.AddStyleAttribute ("left", "0px");
  1207. writer.AddStyleAttribute ("top", "0px");
  1208. writer.AddAttribute ("id", GetItemClientId (item, "s"));
  1209. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1210. // Up button
  1211. writer.AddAttribute ("id", GetItemClientId (item, "cu"));
  1212. writer.AddStyleAttribute ("display", "block");
  1213. writer.AddStyleAttribute ("text-align", "center");
  1214. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "u"));
  1215. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "u"));
  1216. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1217. string src = ScrollUpImageUrl != "" ? ScrollUpImageUrl : Page.ClientScript.GetWebResourceUrl (typeof(Menu), "arrow_up.gif");
  1218. writer.AddAttribute ("src", src);
  1219. writer.AddAttribute ("alt", ScrollUpText);
  1220. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1221. writer.RenderEndTag (); // IMG
  1222. writer.RenderEndTag (); // DIV scroll button
  1223. writer.AddAttribute ("id", GetItemClientId (item, "cb")); // Scroll container
  1224. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1225. writer.AddAttribute ("id", GetItemClientId (item, "cc")); // Content
  1226. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1227. RenderMenu (writer, item.ChildItems, true, true, item.Depth + 1, false);
  1228. writer.RenderEndTag (); // DIV Content
  1229. writer.RenderEndTag (); // DIV Scroll container
  1230. // Down button
  1231. writer.AddAttribute ("id", GetItemClientId (item, "cd"));
  1232. writer.AddStyleAttribute ("display", "block");
  1233. writer.AddStyleAttribute ("text-align", "center");
  1234. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "d"));
  1235. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "d"));
  1236. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1237. src = ScrollDownImageUrl != "" ? ScrollDownImageUrl : Page.ClientScript.GetWebResourceUrl (typeof(Menu), "arrow_down.gif");
  1238. writer.AddAttribute ("src", src);
  1239. writer.AddAttribute ("alt", ScrollDownText);
  1240. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1241. writer.RenderEndTag (); // IMG
  1242. writer.RenderEndTag (); // DIV scroll button
  1243. writer.RenderEndTag (); // DIV menu
  1244. }
  1245. void RenderMenuBeginTagAttributes (HtmlTextWriter writer, bool dynamic, int menuLevel) {
  1246. writer.AddAttribute ("cellpadding", "0");
  1247. writer.AddAttribute ("cellspacing", "0");
  1248. writer.AddAttribute ("border", "0");
  1249. if (!dynamic) {
  1250. SubMenuStyle style = new SubMenuStyle ();
  1251. FillMenuStyle (dynamic, menuLevel, style);
  1252. style.AddAttributesToRender (writer);
  1253. }
  1254. }
  1255. private void FillMenuStyle (bool dynamic, int menuLevel, SubMenuStyle style) {
  1256. if (Page.Header != null) {
  1257. // styles are registered
  1258. if (!dynamic && staticMenuStyle != null) {
  1259. AddCssClass (style, staticMenuStyle.CssClass);
  1260. AddCssClass (style, staticMenuStyle.RegisteredCssClass);
  1261. }
  1262. if (dynamic && dynamicMenuStyle != null) {
  1263. AddCssClass (style, dynamicMenuStyle.CssClass);
  1264. AddCssClass (style, dynamicMenuStyle.RegisteredCssClass);
  1265. }
  1266. if (levelSubMenuStyles != null && levelSubMenuStyles.Count > menuLevel) {
  1267. AddCssClass (style, levelSubMenuStyles [menuLevel].CssClass);
  1268. AddCssClass (style, levelSubMenuStyles [menuLevel].RegisteredCssClass);
  1269. }
  1270. }
  1271. else {
  1272. // styles are not registered
  1273. if (!dynamic && staticMenuStyle != null) {
  1274. style.CopyFrom (staticMenuStyle);
  1275. }
  1276. if (dynamic && dynamicMenuStyle != null) {
  1277. style.CopyFrom (dynamicMenuStyle);
  1278. }
  1279. if (levelSubMenuStyles != null && levelSubMenuStyles.Count > menuLevel) {
  1280. style.CopyFrom (levelSubMenuStyles [menuLevel]);
  1281. }
  1282. }
  1283. }
  1284. void RenderMenu (HtmlTextWriter writer, MenuItemCollection items, bool vertical, bool dynamic, int menuLevel, bool notLast)
  1285. {
  1286. RenderMenuBeginTag (writer, dynamic, menuLevel);
  1287. RenderMenuBody (writer, items, vertical, dynamic, notLast);
  1288. RenderMenuEndTag (writer);
  1289. }
  1290. void RenderMenuBeginTag (HtmlTextWriter writer, bool dynamic, int menuLevel)
  1291. {
  1292. RenderMenuBeginTagAttributes (writer, dynamic, menuLevel);
  1293. writer.RenderBeginTag (HtmlTextWriterTag.Table);
  1294. }
  1295. void RenderMenuEndTag (HtmlTextWriter writer)
  1296. {
  1297. writer.RenderEndTag ();
  1298. }
  1299. void RenderMenuBody (HtmlTextWriter writer, MenuItemCollection items, bool vertical, bool dynamic, bool notLast) {
  1300. if (!vertical)
  1301. writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1302. int count = items.Count;
  1303. for (int n = 0; n < count; n++) {
  1304. MenuItem item = items [n];
  1305. RenderMenuItem (writer, item, (n + 1 == count) ? notLast : true, n == 0);
  1306. }
  1307. if (!vertical)
  1308. writer.RenderEndTag (); // TR
  1309. }
  1310. void RenderMenuItemSpacing (HtmlTextWriter writer, Unit itemSpacing, bool vertical) {
  1311. if (vertical) {
  1312. writer.AddStyleAttribute ("height", itemSpacing.ToString ());
  1313. writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1314. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1315. writer.RenderEndTag ();
  1316. writer.RenderEndTag ();
  1317. }
  1318. else {
  1319. writer.AddStyleAttribute ("width", itemSpacing.ToString ());
  1320. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1321. writer.RenderEndTag ();
  1322. }
  1323. }
  1324. private bool IsDynamicItem (MenuItem item) {
  1325. return item.Depth + 1 > StaticDisplayLevels;
  1326. }
  1327. private bool DisplayChildren (MenuItem item) {
  1328. return (item.Depth + 1 < StaticDisplayLevels + MaximumDynamicDisplayLevels) && item.ChildItems.Count > 0;
  1329. }
  1330. void RenderMenuItem (HtmlTextWriter writer, MenuItem item, bool notLast, bool isFirst) {
  1331. bool displayChildren = DisplayChildren (item);
  1332. bool dynamicChildren = displayChildren && (item.Depth + 1 >= StaticDisplayLevels);
  1333. bool isDynamicItem = IsDynamicItem (item);
  1334. bool vertical = (Orientation == Orientation.Vertical) || isDynamicItem;
  1335. Unit itemSpacing = GetItemSpacing (item, isDynamicItem);
  1336. if (itemSpacing != Unit.Empty && (item.Depth > 0 || !isFirst))
  1337. RenderMenuItemSpacing (writer, itemSpacing, vertical);
  1338. if(!String.IsNullOrEmpty(item.ToolTip))
  1339. writer.AddAttribute (HtmlTextWriterAttribute.Title, item.ToolTip);
  1340. if (vertical)
  1341. writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1342. string parentId = isDynamicItem ? "'" + item.Parent.Path + "'" : "null";
  1343. if (dynamicChildren) {
  1344. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
  1345. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}')", ClientID, item.Path));
  1346. }
  1347. else if (isDynamicItem) {
  1348. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverDynamicLeafItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
  1349. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
  1350. }
  1351. else {
  1352. writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverStaticLeafItem ('{0}','{1}')", ClientID, item.Path));
  1353. writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}')", ClientID, item.Path));
  1354. }
  1355. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1356. // Top separator image
  1357. if (isDynamicItem && DynamicTopSeparatorImageUrl != "") {
  1358. writer.AddAttribute ("src", ResolveClientUrl (DynamicTopSeparatorImageUrl));
  1359. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1360. writer.RenderEndTag (); // IMG
  1361. }
  1362. else if (!isDynamicItem && StaticTopSeparatorImageUrl != "") {
  1363. writer.AddAttribute ("src", ResolveClientUrl (StaticTopSeparatorImageUrl));
  1364. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1365. writer.RenderEndTag (); // IMG
  1366. }
  1367. // Menu item box
  1368. MenuItemStyle style = new MenuItemStyle ();
  1369. if (Page.Header != null) {
  1370. // styles are registered
  1371. if (!isDynamicItem && staticMenuItemStyle != null) {
  1372. AddCssClass (style, staticMenuItemStyle.CssClass);
  1373. AddCssClass (style, staticMenuItemStyle.RegisteredCssClass);
  1374. }
  1375. if (isDynamicItem && dynamicMenuItemStyle != null) {
  1376. AddCssClass (style, dynamicMenuItemStyle.CssClass);
  1377. AddCssClass (style, dynamicMenuItemStyle.RegisteredCssClass);
  1378. }
  1379. if (levelMenuItemStyles != null && levelMenuItemStyles.Count > item.Depth) {
  1380. AddCssClass (style, levelMenuItemStyles [item.Depth].CssClass);
  1381. AddCssClass (style, levelMenuItemStyles [item.Depth].RegisteredCssClass);
  1382. }
  1383. if (item == SelectedItem) {
  1384. if (!isDynamicItem && staticSelectedStyle != null) {
  1385. AddCssClass (style, staticSelectedStyle.CssClass);
  1386. AddCssClass (style, staticSelectedStyle.RegisteredCssClass);
  1387. }
  1388. if (isDynamicItem && dynamicSelectedStyle != null) {
  1389. AddCssClass (style, dynamicSelectedStyle.CssClass);
  1390. AddCssClass (style, dynamicSelectedStyle.RegisteredCssClass);
  1391. }
  1392. if (levelSelectedStyles != null && levelSelectedStyles.Count > item.Depth) {
  1393. AddCssClass (style, levelSelectedStyles [item.Depth].CssClass);
  1394. AddCssClass (style, levelSelectedStyles [item.Depth].RegisteredCssClass);
  1395. }
  1396. }
  1397. }
  1398. else {
  1399. // styles are not registered
  1400. if (!isDynamicItem && staticMenuItemStyle != null) {
  1401. style.CopyFrom (staticMenuItemStyle);
  1402. }
  1403. if (isDynamicItem && dynamicMenuItemStyle != null) {
  1404. style.CopyFrom (dynamicMenuItemStyle);
  1405. }
  1406. if (levelMenuItemStyles != null && levelMenuItemStyles.Count > item.Depth) {
  1407. style.CopyFrom (levelMenuItemStyles [item.Depth]);
  1408. }
  1409. if (item == SelectedItem) {
  1410. if (!isDynamicItem && staticSelectedStyle != null) {
  1411. style.CopyFrom (staticSelectedStyle);
  1412. }
  1413. if (isDynamicItem && dynamicSelectedStyle != null) {
  1414. style.CopyFrom (dynamicSelectedStyle);
  1415. }
  1416. if (levelSelectedStyles != null && levelSelectedStyles.Count > item.Depth) {
  1417. style.CopyFrom (levelSelectedStyles [item.Depth]);
  1418. }
  1419. }
  1420. }
  1421. style.AddAttributesToRender (writer);
  1422. writer.AddAttribute ("id", GetItemClientId (item, "i"));
  1423. writer.AddAttribute ("cellpadding", "0");
  1424. writer.AddAttribute ("cellspacing", "0");
  1425. writer.AddAttribute ("border", "0");
  1426. writer.AddAttribute ("width", "100%");
  1427. writer.RenderBeginTag (HtmlTextWriterTag.Table);
  1428. writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1429. // Menu item text
  1430. if (vertical)
  1431. writer.AddStyleAttribute (HtmlTextWriterStyle.Width, "100%");
  1432. if (!ItemWrap)
  1433. writer.AddStyleAttribute ("white-space", "nowrap");
  1434. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1435. RenderItemHref (writer, item);
  1436. Style linkStyle = new Style ();
  1437. if (Page.Header != null) {
  1438. // styles are registered
  1439. AddCssClass (linkStyle, ControlLinkStyle.RegisteredCssClass);
  1440. if (!isDynamicItem && staticMenuItemStyle != null) {
  1441. AddCssClass (linkStyle, staticMenuItemStyle.CssClass);
  1442. AddCssClass (linkStyle, staticMenuItemLinkStyle.RegisteredCssClass);
  1443. }
  1444. if (isDynamicItem && dynamicMenuItemStyle != null) {
  1445. AddCssClass (linkStyle, dynamicMenuItemStyle.CssClass);
  1446. AddCssClass (linkStyle, dynamicMenuItemLinkStyle.RegisteredCssClass);
  1447. }
  1448. if (levelMenuItemStyles != null && levelMenuItemStyles.Count > item.Depth) {
  1449. AddCssClass (linkStyle, levelMenuItemStyles [item.Depth].CssClass);
  1450. AddCssClass (linkStyle, levelMenuItemLinkStyles [item.Depth].RegisteredCssClass);
  1451. }
  1452. if (item == SelectedItem) {
  1453. if (!isDynamicItem && staticSelectedStyle != null) {
  1454. AddCssClass (linkStyle, staticSelectedStyle.CssClass);
  1455. AddCssClass (linkStyle, staticSelectedLinkStyle.RegisteredCssClass);
  1456. }
  1457. if (isDynamicItem && dynamicSelectedStyle != null) {
  1458. AddCssClass (linkStyle, dynamicSelectedStyle.CssClass);
  1459. AddCssClass (linkStyle, dynamicSelectedLinkStyle.RegisteredCssClass);
  1460. }
  1461. if (levelSelectedStyles != null && levelSelectedStyles.Count > item.Depth) {
  1462. AddCssClass (linkStyle, levelSelectedStyles [item.Depth].CssClass);
  1463. AddCssClass (linkStyle, levelSelectedLinkStyles [item.Depth].RegisteredCssClass);
  1464. }
  1465. }
  1466. }
  1467. else {
  1468. // styles are not registered
  1469. linkStyle.CopyFrom (ControlLinkStyle);
  1470. if (!isDynamicItem && staticMenuItemStyle != null) {
  1471. linkStyle.CopyFrom (staticMenuItemLinkStyle);
  1472. }
  1473. if (isDynamicItem && dynamicMenuItemStyle != null) {
  1474. linkStyle.CopyFrom (dynamicMenuItemLinkStyle);
  1475. }
  1476. if (levelMenuItemStyles != null && levelMenuItemStyles.Count > item.Depth) {
  1477. linkStyle.CopyFrom (levelMenuItemLinkStyles [item.Depth]);
  1478. }
  1479. if (item == SelectedItem) {
  1480. if (!isDynamicItem && staticSelectedStyle != null) {
  1481. linkStyle.CopyFrom (staticSelectedLinkStyle);
  1482. }
  1483. if (isDynamicItem && dynamicSelectedStyle != null) {
  1484. linkStyle.CopyFrom (dynamicSelectedLinkStyle);
  1485. }
  1486. if (levelSelectedStyles != null && levelSelectedStyles.Count > item.Depth) {
  1487. linkStyle.CopyFrom (levelSelectedLinkStyles [item.Depth]);
  1488. }
  1489. }
  1490. linkStyle.AlwaysRenderTextDecoration = true;
  1491. }
  1492. linkStyle.AddAttributesToRender (writer);
  1493. writer.AddAttribute ("id", GetItemClientId (item, "l"));
  1494. if (item.Depth > 0 && !isDynamicItem) {
  1495. Unit indent = new Unit (StaticSubMenuIndent.Value * item.Depth, StaticSubMenuIndent.Type);
  1496. writer.AddStyleAttribute ("margin-left", indent.ToString ());
  1497. }
  1498. writer.RenderBeginTag (HtmlTextWriterTag.A);
  1499. RenderItemContent (writer, item, isDynamicItem);
  1500. writer.RenderEndTag (); // A
  1501. writer.RenderEndTag (); // TD
  1502. // Popup image
  1503. if (dynamicChildren) {
  1504. string popOutImage = GetPopOutImage (item, isDynamicItem);
  1505. if (popOutImage != null) {
  1506. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1507. writer.AddAttribute ("src", ResolveClientUrl (popOutImage));
  1508. writer.AddAttribute ("border", "0");
  1509. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1510. writer.RenderEndTag (); // IMG
  1511. writer.RenderEndTag (); // TD
  1512. }
  1513. }
  1514. writer.RenderEndTag (); // TR
  1515. writer.RenderEndTag (); // TABLE
  1516. // Bottom separator image
  1517. string separatorImg = item.SeparatorImageUrl;
  1518. if (separatorImg.Length == 0) {
  1519. if (isDynamicItem)
  1520. separatorImg = DynamicBottomSeparatorImageUrl;
  1521. else
  1522. separatorImg = StaticBottomSeparatorImageUrl;
  1523. }
  1524. if (separatorImg.Length > 0) {
  1525. writer.AddAttribute ("src", ResolveClientUrl (separatorImg));
  1526. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1527. writer.RenderEndTag (); // IMG
  1528. }
  1529. writer.RenderEndTag (); // TD
  1530. if (vertical)
  1531. writer.RenderEndTag (); // TR
  1532. if (itemSpacing != Unit.Empty)
  1533. RenderMenuItemSpacing (writer, itemSpacing, vertical);
  1534. else if (!vertical && (notLast || displayChildren)) {
  1535. if (!displayChildren || !dynamicChildren) {
  1536. writer.AddStyleAttribute ("width", "3px");
  1537. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1538. writer.RenderEndTag ();
  1539. }
  1540. }
  1541. // Submenu
  1542. if (displayChildren && !dynamicChildren) {
  1543. if (vertical)
  1544. writer.RenderBeginTag (HtmlTextWriterTag.Tr);
  1545. writer.RenderBeginTag (HtmlTextWriterTag.Td);
  1546. writer.AddAttribute ("width", "100%");
  1547. RenderMenu (writer, item.ChildItems, Orientation == Orientation.Vertical, false, item.Depth + 1, notLast);
  1548. if (item.Depth + 2 == StaticDisplayLevels)
  1549. RenderDynamicMenu (writer, item.ChildItems);
  1550. writer.RenderEndTag (); // TD
  1551. if (vertical)
  1552. writer.RenderEndTag (); // TR
  1553. }
  1554. }
  1555. void RenderItemContent (HtmlTextWriter writer, MenuItem item, bool isDynamicItem) {
  1556. if (_menuItemControls!=null && _menuItemControls [item] != null) {
  1557. ((Control) _menuItemControls [item]).Render (writer);
  1558. }
  1559. else {
  1560. if (!String.IsNullOrEmpty (item.ImageUrl)) {
  1561. writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveClientUrl (item.ImageUrl));
  1562. writer.AddAttribute (HtmlTextWriterAttribute.Alt, item.ToolTip);
  1563. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "none");
  1564. writer.AddStyleAttribute (HtmlTextWriterStyle.VerticalAlign, "middle");
  1565. writer.RenderBeginTag (HtmlTextWriterTag.Img);
  1566. writer.RenderEndTag (); // IMG
  1567. }
  1568. if (isDynamicItem && DynamicItemFormatString.Length > 0) {
  1569. writer.Write (string.Format (DynamicItemFormatString, item.Text));
  1570. }
  1571. else if (!isDynamicItem && StaticItemFormatString.Length > 0) {
  1572. writer.Write (string.Format (StaticItemFormatString, item.Text));
  1573. }
  1574. else {
  1575. writer.Write (item.Text);
  1576. }
  1577. }
  1578. }
  1579. Unit GetItemSpacing (MenuItem item, bool dynamic)
  1580. {
  1581. Unit itemSpacing = Unit.Empty;
  1582. if (item.Selected) {
  1583. if (levelSelectedStyles != null && item.Depth < levelSelectedStyles.Count) {
  1584. itemSpacing = levelSelectedStyles [item.Depth].ItemSpacing;
  1585. if (itemSpacing != Unit.Empty) return itemSpacing;
  1586. }
  1587. if (dynamic && dynamicSelectedStyle != null)
  1588. itemSpacing = dynamicSelectedStyle.ItemSpacing;
  1589. else if (!dynamic && staticSelectedStyle != null)
  1590. itemSpacing = staticSelectedStyle.ItemSpacing;
  1591. if (itemSpacing != Unit.Empty)
  1592. return itemSpacing;
  1593. }
  1594. if (levelMenuItemStyles != null && item.Depth < levelMenuItemStyles.Count) {
  1595. itemSpacing = levelMenuItemStyles [item.Depth].ItemSpacing;
  1596. if (itemSpacing != Unit.Empty) return itemSpacing;
  1597. }
  1598. if (dynamic && dynamicMenuItemStyle != null)
  1599. return dynamicMenuItemStyle.ItemSpacing;
  1600. else if (!dynamic && staticMenuItemStyle != null)
  1601. return staticMenuItemStyle.ItemSpacing;
  1602. else
  1603. return Unit.Empty;
  1604. }
  1605. string GetPopOutImage (MenuItem item, bool isDynamicItem)
  1606. {
  1607. if (item.PopOutImageUrl != "")
  1608. return item.PopOutImageUrl;
  1609. if (isDynamicItem) {
  1610. if (DynamicPopOutImageUrl != "")
  1611. return DynamicPopOutImageUrl;
  1612. if (DynamicEnableDefaultPopOutImage)
  1613. return AssemblyResourceLoader.GetResourceUrl (typeof(Menu), "arrow_plus.gif");
  1614. } else {
  1615. if (StaticPopOutImageUrl != "")
  1616. return StaticPopOutImageUrl;
  1617. if (StaticEnableDefaultPopOutImage)
  1618. return AssemblyResourceLoader.GetResourceUrl (typeof(Menu), "arrow_plus.gif");
  1619. }
  1620. return null;
  1621. }
  1622. void RenderItemHref (HtmlTextWriter writer, MenuItem item)
  1623. {
  1624. if (!item.BranchEnabled) {
  1625. writer.AddAttribute ("disabled", "true");
  1626. }
  1627. else if (!item.Selectable) {
  1628. writer.AddAttribute ("href", "#");
  1629. writer.AddStyleAttribute ("cursor", "text");
  1630. }
  1631. else if (item.NavigateUrl != "") {
  1632. string target = item.Target != "" ? item.Target : Target;
  1633. #if TARGET_J2EE
  1634. string navUrl = ResolveClientUrl (item.NavigateUrl, String.Compare (target, "_blank", true) != 0);
  1635. #else
  1636. string navUrl = ResolveClientUrl (item.NavigateUrl);
  1637. #endif
  1638. writer.AddAttribute ("href", navUrl);
  1639. if (target != "")
  1640. writer.AddAttribute ("target", target);
  1641. }
  1642. else {
  1643. writer.AddAttribute ("href", GetClientEvent (item));
  1644. }
  1645. }
  1646. string GetItemClientId (MenuItem item, string sufix)
  1647. {
  1648. return ClientID + "_" + item.Path + sufix;
  1649. }
  1650. string GetClientEvent (MenuItem item)
  1651. {
  1652. return Page.ClientScript.GetPostBackClientHyperlink (this, item.Path);
  1653. }
  1654. }
  1655. }
  1656. #endif