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.

416 lines
12 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using System.Web.UI.HtmlControls;
  6. using UDDI;
  7. namespace UDDI.Web
  8. {
  9. public class TabControl : Control, INamingContainer, IPostBackEventHandler
  10. {
  11. protected TableStyle style = new TableStyle();
  12. protected TableItemStyle tabBeginStyle = new TableItemStyle();
  13. protected TableItemStyle tabBeginSelectedStyle = new TableItemStyle();
  14. protected TableItemStyle tabStyle = new TableItemStyle();
  15. protected TableItemStyle tabSelectedStyle = new TableItemStyle();
  16. protected TableItemStyle tabEndStyle = new TableItemStyle();
  17. protected TableItemStyle tabEndSelectedStyle = new TableItemStyle();
  18. protected TableItemStyle tabGapStyle = new TableItemStyle();
  19. protected TableItemStyle tabPageStyle = new TableItemStyle();
  20. protected TableStyle tabBodyStyle = new TableStyle();
  21. protected bool defaultStyle = true;
  22. protected bool tabSwitch = false;
  23. public delegate void TabChangeEventHandler( object sender, int oldIndex, int newIndex );
  24. public event TabChangeEventHandler BeforeTabChange;
  25. public event TabChangeEventHandler TabChange;
  26. public TabControl()
  27. {
  28. }
  29. public int SelectedIndex
  30. {
  31. get
  32. {
  33. if( null == ViewState[ "index" ] )
  34. return 0;
  35. return (int)ViewState[ "index" ];
  36. }
  37. set { ViewState[ "index" ] = value; }
  38. }
  39. public TableStyle Style
  40. {
  41. get { return style; }
  42. }
  43. public TableItemStyle TabBeginStyle
  44. {
  45. get { return tabBeginStyle; }
  46. }
  47. public TableItemStyle TabBeginSelectedStyle
  48. {
  49. get { return tabBeginSelectedStyle; }
  50. }
  51. public TableItemStyle TabStyle
  52. {
  53. get { return tabStyle; }
  54. }
  55. public TableItemStyle TabSelectedStyle
  56. {
  57. get { return tabSelectedStyle; }
  58. }
  59. public TableItemStyle TabEndStyle
  60. {
  61. get { return tabEndStyle; }
  62. }
  63. public TableItemStyle TabEndSelectedStyle
  64. {
  65. get { return tabEndSelectedStyle; }
  66. }
  67. public TableItemStyle TabGapStyle
  68. {
  69. get { return tabGapStyle; }
  70. }
  71. public TableItemStyle TabPageStyle
  72. {
  73. get { return tabPageStyle; }
  74. }
  75. public TableStyle TabBodyStyle
  76. {
  77. get{ return tabBodyStyle; }
  78. }
  79. public bool DefaultStyle
  80. {
  81. get { return defaultStyle; }
  82. set { defaultStyle = value; }
  83. }
  84. protected override void OnInit( EventArgs e )
  85. {
  86. if( defaultStyle )
  87. {
  88. TabBeginStyle.CssClass = "tabBegin";
  89. TabStyle.CssClass = "tab";
  90. TabEndStyle.CssClass = "tabEnd";
  91. TabBeginSelectedStyle.CssClass = "tabBeginSelected";
  92. TabSelectedStyle.CssClass = "tabSelected";
  93. TabEndSelectedStyle.CssClass = "tabEndSelected";
  94. TabGapStyle.CssClass = "tabGap";
  95. TabPageStyle.CssClass = "tabPage";
  96. TabBodyStyle.CssClass = "tabPage";
  97. }
  98. }
  99. protected override void AddParsedSubObject( object obj )
  100. {
  101. if( obj is TabPage )
  102. this.Controls.Add( (Control)obj );
  103. }
  104. void IPostBackEventHandler.RaisePostBackEvent( string eventArgument )
  105. {
  106. tabSwitch = true;
  107. if( ((UddiPage)Page).EditMode )
  108. return;
  109. int oldIndex = SelectedIndex;
  110. int newIndex = Convert.ToInt32( eventArgument );
  111. this.EnsureChildControls();
  112. if( null != BeforeTabChange )
  113. BeforeTabChange( this, oldIndex, newIndex );
  114. SelectedIndex = newIndex;
  115. if( null != TabChange )
  116. TabChange( this, oldIndex, newIndex );
  117. }
  118. protected override void Render( HtmlTextWriter output )
  119. {
  120. int index = 0;
  121. int visiblePageCount = 0;
  122. int capWidth = ( ( UddiBrowser.IsDownlevel && !UddiBrowser.IsNetscape6 ) ? 1 : 4 );
  123. output.AddAttribute( HtmlTextWriterAttribute.Cellpadding, "0" );
  124. output.AddAttribute( HtmlTextWriterAttribute.Cellspacing, "0" );
  125. output.AddAttribute( HtmlTextWriterAttribute.Border, "0" );
  126. if( !UddiBrowser.IsDownlevel || UddiBrowser.IsNetscape6 )
  127. output.AddAttribute( HtmlTextWriterAttribute.Width, "100%" );
  128. Style.AddAttributesToRender( output );
  129. output.RenderBeginTag( HtmlTextWriterTag.Table );
  130. output.RenderBeginTag( HtmlTextWriterTag.Colgroup );
  131. foreach( TabPage page in Controls )
  132. {
  133. if( page.ShouldDisplay )
  134. {
  135. output.Write( "<col width='" + capWidth + "'>" );
  136. output.Write( "<col>" );
  137. output.Write( "<col width='" + capWidth + "'>" );
  138. }
  139. }
  140. if( !UddiBrowser.IsDownlevel || UddiBrowser.IsNetscape6 )
  141. output.Write( "<col width='0*'>" );
  142. output.RenderEndTag();
  143. output.RenderBeginTag( HtmlTextWriterTag.Tr );
  144. foreach( TabPage page in Controls )
  145. {
  146. if( page.ShouldDisplay )
  147. {
  148. //
  149. // Create the begin tab cell.
  150. //
  151. if( index == SelectedIndex )
  152. TabBeginSelectedStyle.AddAttributesToRender( output );
  153. else
  154. TabBeginStyle.AddAttributesToRender( output );
  155. output.AddAttribute( "width", capWidth.ToString() );
  156. output.RenderBeginTag( HtmlTextWriterTag.Td );
  157. output.Write( "<img src='" + ((UddiPage)Page).Root + "/images/trans_pixel.gif' width='" + capWidth + "'>" );
  158. output.RenderEndTag();
  159. //
  160. // Create the link and text for the tab.
  161. //
  162. if( index == SelectedIndex )
  163. TabSelectedStyle.AddAttributesToRender( output );
  164. else
  165. TabStyle.AddAttributesToRender( output );
  166. if( !UddiBrowser.IsDownlevel || UddiBrowser.IsNetscape6 )
  167. output.AddAttribute( "width", "100" );
  168. output.AddAttribute( "align", "center" );
  169. output.RenderBeginTag( HtmlTextWriterTag.Td );
  170. output.AddAttribute( HtmlTextWriterAttribute.Href, "javascript:" + Page.GetPostBackEventReference( this, Convert.ToString( index ) ) );
  171. output.Write( "<nobr>&nbsp;&nbsp;" );
  172. output.RenderBeginTag( HtmlTextWriterTag.A );
  173. output.Write( Localization.GetString( page.Name ) );
  174. output.RenderEndTag();
  175. output.Write( "&nbsp;&nbsp;</nobr>" );
  176. output.RenderEndTag();
  177. //
  178. // Create the closing tab cell.
  179. //
  180. if( index == SelectedIndex )
  181. TabEndSelectedStyle.AddAttributesToRender( output );
  182. else
  183. TabEndStyle.AddAttributesToRender( output );
  184. output.AddAttribute( "width", capWidth.ToString() );
  185. output.RenderBeginTag( HtmlTextWriterTag.Td );
  186. output.Write( "<img src='" + ((UddiPage)Page).Root + "/images/trans_pixel.gif' width='" + capWidth + "'>" );
  187. output.RenderEndTag();
  188. visiblePageCount ++;
  189. }
  190. index ++;
  191. }
  192. //
  193. // Render the leftover space at the end of the tabs
  194. //
  195. if( !UddiBrowser.IsDownlevel || UddiBrowser.IsNetscape6 )
  196. {
  197. TabGapStyle.AddAttributesToRender( output );
  198. output.AddAttribute( "width", "100%" );
  199. output.RenderBeginTag( HtmlTextWriterTag.Td );
  200. output.Write( "<img src='" + ((UddiPage)Page).Root + "/images/trans_pixel.gif' width='1'>" );
  201. output.RenderEndTag();
  202. }
  203. //
  204. // Add the completed tab row to the table.
  205. //
  206. output.RenderEndTag();
  207. //
  208. // Test to see if we can fix the table spacing problems in IE6
  209. // Task: Split the table in to tables
  210. //
  211. output.RenderEndTag();
  212. output.AddAttribute( HtmlTextWriterAttribute.Cellpadding, "10" );
  213. output.AddAttribute( HtmlTextWriterAttribute.Cellspacing, "0" );
  214. output.AddAttribute( HtmlTextWriterAttribute.Width, "100%" );
  215. if( UddiBrowser.IsDownlevel && !UddiBrowser.IsNetscape6 )
  216. {
  217. output.AddAttribute( HtmlTextWriterAttribute.Border, "1" );
  218. output.AddAttribute( HtmlTextWriterAttribute.Bordercolor, "#639ace" );
  219. }
  220. output.AddAttribute( HtmlTextWriterAttribute.Bgcolor, "#f0f8ff" );
  221. TabBodyStyle.AddAttributesToRender( output );
  222. output.RenderBeginTag( HtmlTextWriterTag.Table );
  223. output.RenderBeginTag( HtmlTextWriterTag.Tr );
  224. output.AddAttribute( "valign", "top" );
  225. output.RenderBeginTag( HtmlTextWriterTag.Td );
  226. if( ((UddiPage)Page).EditMode && tabSwitch )
  227. {
  228. output.AddAttribute( "color", "red" );
  229. output.RenderBeginTag( HtmlTextWriterTag.Font );
  230. output.Write( Localization.GetString( "ERROR_FINISH_EDIT" ) );
  231. output.RenderEndTag();
  232. output.Write( "<br><br>" );
  233. }
  234. this.Controls[ SelectedIndex ].RenderControl( output );
  235. output.RenderEndTag();
  236. output.RenderEndTag();
  237. output.RenderEndTag();
  238. output.Write( "<br>" );
  239. /*
  240. //
  241. // Create the tab page content
  242. //
  243. //if( UddiBrowser.IsDownlevel )
  244. //{
  245. output.RenderEndTag();
  246. output.AddAttribute( HtmlTextWriterAttribute.Cellpadding, "10" );
  247. output.AddAttribute( HtmlTextWriterAttribute.Cellspacing, "0" );
  248. output.AddAttribute( HtmlTextWriterAttribute.Width, "100%" );
  249. output.AddAttribute( HtmlTextWriterAttribute.Border, "1" );
  250. output.AddAttribute( HtmlTextWriterAttribute.Bordercolor, "#639ace" );
  251. output.AddAttribute( HtmlTextWriterAttribute.Bgcolor, "#f0f8ff" );
  252. output.RenderBeginTag( HtmlTextWriterTag.Table );
  253. output.RenderBeginTag( HtmlTextWriterTag.Tr );
  254. output.RenderBeginTag( HtmlTextWriterTag.Td );
  255. if( ((UddiPage)Page).EditMode && tabSwitch )
  256. {
  257. output.AddAttribute( "color", "red" );
  258. output.RenderBeginTag( HtmlTextWriterTag.Font );
  259. output.Write( Localization.GetString( "ERROR_FINISH_EDIT" ) );
  260. output.RenderEndTag();
  261. output.Write( "<br><br>" );
  262. }
  263. this.Controls[ SelectedIndex ].RenderControl( output );
  264. output.RenderEndTag();
  265. output.RenderEndTag();
  266. output.RenderEndTag();
  267. output.Write( "<br>" );
  268. }
  269. else
  270. {
  271. output.RenderBeginTag( HtmlTextWriterTag.Tr );
  272. TabPageStyle.AddAttributesToRender( output );
  273. output.AddAttribute( HtmlTextWriterAttribute.Valign, "top" );
  274. output.AddAttribute( HtmlTextWriterAttribute.Colspan, Convert.ToString( visiblePageCount * 3 + 1 ) );
  275. output.RenderBeginTag( HtmlTextWriterTag.Td );
  276. if( ((UddiPage)Page).EditMode && tabSwitch )
  277. {
  278. output.AddAttribute( "color", "red" );
  279. output.RenderBeginTag( HtmlTextWriterTag.Font );
  280. output.Write( Localization.GetString( "ERROR_FINISH_EDIT" ) );
  281. output.RenderEndTag();
  282. output.Write( "<br><br>" );
  283. }
  284. this.Controls[ SelectedIndex ].RenderControl( output );
  285. output.RenderEndTag();
  286. output.RenderEndTag();
  287. output.RenderEndTag();
  288. }
  289. */
  290. }
  291. }
  292. public class TabPage : Control, INamingContainer
  293. {
  294. protected RoleType requiredRole = RoleType.Anonymous;
  295. protected bool downlevelOnly = false;
  296. protected string name;
  297. public string Name
  298. {
  299. get { return name; }
  300. set { name = value; }
  301. }
  302. public RoleType RequiredRole
  303. {
  304. get { return requiredRole; }
  305. set { requiredRole = value; }
  306. }
  307. public bool AccessAllowed
  308. {
  309. get
  310. {
  311. return
  312. ( RoleType.Anonymous == requiredRole ) ||
  313. ( RoleType.User == requiredRole && UDDI.Context.User.IsUser ) ||
  314. ( RoleType.Publisher == requiredRole && UDDI.Context.User.IsPublisher ) ||
  315. ( RoleType.Coordinator == requiredRole && UDDI.Context.User.IsCoordinator ) ||
  316. ( RoleType.Administrator == requiredRole && UDDI.Context.User.IsAdministrator );
  317. }
  318. }
  319. public bool DownlevelOnly
  320. {
  321. get { return downlevelOnly; }
  322. set { downlevelOnly = value; }
  323. }
  324. public bool ShouldDisplay
  325. {
  326. get
  327. {
  328. return
  329. AccessAllowed && Visible &&
  330. ( !DownlevelOnly || ( ((UddiPage)Page).IsDownlevel && DownlevelOnly ) );
  331. }
  332. }
  333. }
  334. }