Menu.cs 58 KB

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