Menu.cs 57 KB

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