Menu.cs 47 KB

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