Menu.cs 42 KB

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