Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

608 lines
12 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Data;
  4. using System.IO;
  5. using System.Reflection;
  6. using System.Resources;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. namespace UDDI.Web
  10. {
  11. public delegate void MenuEventHandler( object sender, MenuEventArgs e );
  12. [ParseChildren()]
  13. public class MenuControl : UddiControl, IPostBackEventHandler
  14. {
  15. public MenuControl()
  16. {
  17. this.SelectedIndexChanged += new MenuEventHandler( this.MenuControl_SelectedIndexChanged );
  18. MenuItems = new MenuItemControlCollection();
  19. }
  20. public event MenuEventHandler SelectedIndexChanged;
  21. protected string Roots
  22. {
  23. get
  24. {
  25. return HyperLinkManager.GetSecureHyperLink( "" );
  26. }
  27. }
  28. protected MenuItemControlCollection MenuItems;
  29. public string CssClass
  30. {
  31. get{ return this.Name; }
  32. }
  33. private string name;
  34. public string Name
  35. {
  36. get{ return name; }
  37. set{ name=value; }
  38. }
  39. private MenuType type;
  40. public MenuType Type
  41. {
  42. get{ return type; }
  43. set{ type=(MenuType)value; }
  44. }
  45. private string width = "100%";
  46. public string Width
  47. {
  48. get{ return width; }
  49. set{ width=value; }
  50. }
  51. private string borderwidth = "0";
  52. public string BorderWidth
  53. {
  54. get{ return borderwidth; }
  55. set{ borderwidth=value; }
  56. }
  57. //private int selectedindex;
  58. public int SelectedIndex
  59. {
  60. get
  61. {
  62. if( null==ViewState[ this.Name + "_Index" ] )
  63. ViewState[ this.Name + "_Index" ] = 0;
  64. return (int)ViewState[ this.Name + "_Index" ];
  65. }
  66. set{ ViewState[ this.Name + "_Index" ]=value; }
  67. }
  68. public MenuItemControl SelectedItem
  69. {
  70. get
  71. {
  72. return (MenuItemControl)this.Controls[ this.SelectedIndex ];
  73. }
  74. }
  75. private string height = "100%";
  76. public string Height
  77. {
  78. get{ return height; }
  79. set{ height=value; }
  80. }
  81. private string topoffset;
  82. public string TopOffset
  83. {
  84. get{ return topoffset; }
  85. set{ topoffset=value; }
  86. }
  87. private string leftoffset;
  88. public string LeftOffset
  89. {
  90. get{ return leftoffset; }
  91. set{ leftoffset=value; }
  92. }
  93. private int staticindex=-1;
  94. public int StaticIndex
  95. {
  96. get{ return staticindex; }
  97. set{ staticindex=(int)value; }
  98. }
  99. private ArrayList items = new ArrayList();
  100. protected override void OnLoad( EventArgs e )
  101. {
  102. //
  103. // This script code is now in client.js
  104. //
  105. //if( !Page.IsClientScriptBlockRegistered( "SideNav_ClientScript" ) )
  106. //{
  107. //Page.RegisterClientScriptBlock( "SideNav_ClientScript",MenuControl.ClientScript );
  108. //}
  109. if( !Page.IsPostBack )
  110. {
  111. if( null!=Request[ this.Name + "_Index" ] )
  112. this.SelectedIndex = Convert.ToInt32( Request[ this.Name + "_Index" ] );
  113. }
  114. base.OnLoad( e );
  115. }
  116. protected override void Render( HtmlTextWriter output )
  117. {
  118. output.Write(
  119. "<table "+
  120. "width='" + this.Width + "' "+
  121. "height='" + this.Height + "' " +
  122. "class='" + this.CssClass + "' "+
  123. "border='" + this.BorderWidth + "' " +
  124. "cellpadding='4' "+
  125. "cellspacing='0' >\r\n"
  126. );
  127. if( MenuType.Horizontal==this.Type )
  128. {
  129. output.Write(
  130. "<TR >\r\n\t" );
  131. this.RenderChildren( output );
  132. output.Write(
  133. "</TR>\r\n"
  134. );
  135. }
  136. else//vertical
  137. {
  138. output.Write(
  139. " <TR height='4'>\r\n"+
  140. " <TD height='4' colspan='2' class='"+this.Name+"_Item'>&nbsp;</TD>\r\n" +
  141. " </TR>\r\n"
  142. );
  143. this.RenderChildren( output );
  144. //render the tail of the menu
  145. output.Write(
  146. "<TR height='100%'><TD width='100%' colspan='2' height='100%' class='"+this.Name+"_Item'><br><br></TD></TR>"
  147. );
  148. }
  149. output.Write(
  150. "</table>"
  151. );
  152. }
  153. protected override void RenderChildren( HtmlTextWriter output )
  154. {
  155. this.EnsureChildControls();
  156. for( int i=0;i<this.MenuItems.Count;i++ )
  157. {
  158. MenuItemControl item = this.MenuItems[ i ];
  159. if( StaticIndex>=0 )
  160. {
  161. if( i==this.StaticIndex )
  162. item.Selected=true;
  163. else
  164. item.Selected=false;
  165. }
  166. else
  167. {
  168. if( i==this.SelectedIndex )
  169. item.Selected=true;
  170. else
  171. item.Selected=false;
  172. }
  173. if( null==item.NavigateUrl && MenuItemType.Item==item.Type )
  174. {
  175. item.NavigateUrl="javascript:"+Page.GetPostBackEventReference( this, i.ToString() );
  176. }
  177. }
  178. base.RenderChildren( output );
  179. }
  180. protected override void AddParsedSubObject( object obj )
  181. {
  182. if( obj is MenuItemControl )
  183. this.AddItem( (MenuItemControl)obj );
  184. base.AddParsedSubObject( obj );
  185. }
  186. public int AddItem( MenuItemControl item )
  187. {
  188. if( null==item.Name )
  189. item.Name = this.Name;
  190. item.MenuType = this.Type;
  191. item.LeftOffSet = this.LeftOffset;
  192. return this.MenuItems.Add( item );
  193. }
  194. public void RaisePostBackEvent( string eventArgument )
  195. {
  196. int newIndex = Convert.ToInt32( eventArgument );
  197. this.EnsureChildControls();
  198. this.OnSelectedIndexChanged( new MenuEventArgs( newIndex ) );
  199. }
  200. protected void OnSelectedIndexChanged( MenuEventArgs e )
  201. {
  202. if( null!=SelectedIndexChanged )
  203. this.SelectedIndexChanged( this,e );
  204. }
  205. private void MenuControl_SelectedIndexChanged( object sender, MenuEventArgs e )
  206. {
  207. this.SelectedIndex = e.Index;
  208. }
  209. public const string ClientScript = @"
  210. <script language='javascript'>
  211. <!--
  212. function MenuItem_Action( sender, action, name )
  213. {
  214. if( null!=sender )
  215. {
  216. switch( action.toLowerCase() )
  217. {
  218. case ""leave"":
  219. if( sender.className!=name+""_ItemSelected"" )
  220. {
  221. sender.className=name+""_Item"";
  222. }
  223. break;
  224. case ""enter"":
  225. if( sender.className!=name+""_ItemSelected"" )
  226. {
  227. sender.className=name+""_ItemHovor"";
  228. }
  229. break;
  230. default:
  231. alert( ""Unknown action: "" + action );
  232. break;
  233. }
  234. }
  235. }
  236. // -->
  237. </script>
  238. ";
  239. }
  240. public class MenuEventArgs : EventArgs
  241. {
  242. public MenuEventArgs( int newindex )
  243. {
  244. this.index = newindex;
  245. }
  246. private int index;
  247. public int Index
  248. {
  249. get{ return index; }
  250. }
  251. }
  252. public class MenuItemControlCollection : CollectionBase
  253. {
  254. public MenuItemControl this[ int index ]
  255. {
  256. get{ return (MenuItemControl)this.List[ index ]; }
  257. set{ this.List[ index ] = value; }
  258. }
  259. protected internal int Add( MenuItemControl item )
  260. {
  261. return this.List.Add( item );
  262. }
  263. protected internal void Remove( MenuItemControl item )
  264. {
  265. this.List.Remove( item );
  266. }
  267. protected internal void Remove( int index )
  268. {
  269. this.List.RemoveAt( index );
  270. }
  271. }
  272. [ParseChildren()]
  273. public class MenuItemControl : UserControl
  274. {
  275. private ArrayList items = new ArrayList();
  276. protected string Root
  277. {
  278. get{ return ( "/" == Request.ApplicationPath ) ? "" : Request.ApplicationPath; }
  279. }
  280. protected string Roots
  281. {
  282. get
  283. {
  284. return HyperLinkManager.GetSecureHyperLink( "" );
  285. }
  286. }
  287. private bool requirehttps;
  288. public bool RequireHttps
  289. {
  290. get{ return requirehttps; }
  291. set{ requirehttps=value; }
  292. }
  293. private bool requirehttp;
  294. public bool RequireHttp
  295. {
  296. get{ return requirehttp; }
  297. set{ requirehttp=value; }
  298. }
  299. private string cssclass;
  300. public string CssClass
  301. {
  302. get{ return cssclass; }
  303. set{ cssclass=value; }
  304. }
  305. protected string root
  306. {
  307. get{ return HyperLinkManager.GetHyperLink( "" ); }
  308. }
  309. private bool selected;
  310. public bool Selected
  311. {
  312. get{ return selected; }
  313. set{ selected=value; }
  314. }
  315. private string text;
  316. public string Text
  317. {
  318. get
  319. {
  320. if( null!=text )
  321. {
  322. if( text.Length>65 )
  323. text=text.Substring( 0,65 ) + "...";
  324. }
  325. return text;
  326. }
  327. set{ text=value; }
  328. }
  329. private string navigateurl;
  330. public string NavigateUrl
  331. {
  332. get{ return navigateurl; }
  333. set{ navigateurl=value; }
  334. }
  335. private string navigatepage;
  336. public string NavigatePage
  337. {
  338. get{ return navigatepage; }
  339. set{ navigatepage=value; }
  340. }
  341. private string navigatetarget;
  342. public string NavigateTarget
  343. {
  344. get{ return navigatetarget; }
  345. set{ navigatetarget=value; }
  346. }
  347. private string name;
  348. public string Name
  349. {
  350. get{ return name; }
  351. set{ name=value; }
  352. }
  353. private MenuType menutype;
  354. public MenuType MenuType
  355. {
  356. get{ return menutype; }
  357. set{ menutype=(MenuType)value; }
  358. }
  359. private MenuItemType type;
  360. public MenuItemType Type
  361. {
  362. get{ return type; }
  363. set{ type=(MenuItemType)value;}
  364. }
  365. protected internal string LeftOffSet="0";
  366. protected override void Render( HtmlTextWriter output )
  367. {
  368. if( MenuType.Vertical==this.MenuType )
  369. {
  370. RenderVertical( output );
  371. }
  372. else
  373. {
  374. RenderHorizontal( output );
  375. }
  376. }
  377. protected void RenderVertical( HtmlTextWriter output )
  378. {
  379. output.Write(
  380. "<TR>\r\n\t"
  381. );
  382. RenderHorizontal( output );
  383. output.Write(
  384. "</TR>\r\n"
  385. );
  386. }
  387. protected void RenderHorizontal( HtmlTextWriter output )
  388. {
  389. output.Write(
  390. "<TD ><IMG src='" + Root + "/images/pixel.gif" + "' border='0' width='" + LeftOffSet + "'></TD>"
  391. );
  392. output.Write(
  393. "<TD "+
  394. "id='" + this.ID +"' "
  395. );
  396. if( MenuItemType.Item==this.Type )
  397. {
  398. output.Write(
  399. "onmouseover='MenuItem_Action( this,\"enter\",\"" + this.Name + "\");' " +
  400. "onmouseout='MenuItem_Action( this,\"leave\",\"" + this.Name + "\");' "
  401. );
  402. if( Selected )
  403. {
  404. output.Write(
  405. "class='" + this.Name + "_ItemSelected' "
  406. );
  407. }
  408. else
  409. {
  410. output.Write(
  411. "class='" + this.Name + "_Item' "
  412. );
  413. }
  414. }
  415. else
  416. {
  417. if( MenuItemType.Separator==this.Type )
  418. {
  419. output.Write(
  420. "class='" + this.Name + "_Separator' "
  421. );
  422. }
  423. else if( MenuItemType.Title==this.Type )
  424. {
  425. output.Write(
  426. "class='" + this.Name + "_Title' "
  427. );
  428. }
  429. else
  430. {
  431. output.Write(
  432. "class='" + this.Name + "_Item' "
  433. );
  434. }
  435. }
  436. output.Write(
  437. ">"
  438. );
  439. RenderText( output );
  440. output.Write(
  441. "</TD>\r\n" );
  442. }
  443. protected void RenderText( HtmlTextWriter output )
  444. {
  445. switch( this.Type )
  446. {
  447. case MenuItemType.Item:
  448. HyperLink l = new HyperLink();
  449. l.Text = this.Text;
  450. if( null!=this.NavigateTarget && ""!=this.NavigateTarget.Trim() )
  451. l.Target = this.NavigateTarget;
  452. string classname = this.Name + "_Text";
  453. if( this.Selected )
  454. {
  455. classname += "Selected";
  456. }
  457. else
  458. {
  459. if( null!=this.NavigatePage )
  460. {
  461. if( RequireHttps )
  462. {
  463. l.NavigateUrl = HyperLinkManager.GetSecureHyperLink( NavigatePage );
  464. }
  465. else if( RequireHttp )
  466. {
  467. l.NavigateUrl = HyperLinkManager.GetNonSecureHyperLink( NavigatePage );
  468. }
  469. else
  470. {
  471. l.NavigateUrl = HyperLinkManager.GetHyperLink( NavigatePage );
  472. }
  473. }
  474. else if( null!=this.NavigateUrl )
  475. {
  476. l.NavigateUrl = this.NavigateUrl;
  477. }
  478. }
  479. l.CssClass=classname;
  480. l.Target = this.NavigateTarget;
  481. output.Write( "<nobr>" );
  482. l.RenderControl( output );
  483. output.Write( "</nobr>" );
  484. break;
  485. case MenuItemType.Separator:
  486. Image i = new Image();
  487. i.ImageUrl = Root + "/images/pixel.gif";
  488. i.Height = new Unit( 1 );
  489. i.Width = new Unit( 1 );
  490. i.BorderWidth = new Unit( 0 );
  491. i.RenderControl( output );
  492. break;
  493. case MenuItemType.Title:
  494. Label label = new Label();
  495. label.Text = this.Text;
  496. output.Write( "<nobr>" );
  497. label.RenderControl( output );
  498. output.Write( "</nobr>" );
  499. break;
  500. }
  501. }
  502. public void RenderChildrenExt( HtmlTextWriter output )
  503. {
  504. EnsureChildControls();
  505. RenderChildren( output );
  506. }
  507. }
  508. public enum MenuType
  509. {
  510. Horizontal,
  511. Vertical
  512. }
  513. public enum MenuItemType
  514. {
  515. Title,
  516. Separator,
  517. Item
  518. }
  519. }