Menu.cs 47 KB

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