Menu.cs 44 KB

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