⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collapsebar.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CommunityServer.Controls {

	/// <summary>
	/// An outlook-style panel bar for showing multiple content panels with associated buttons for showing them.
	/// </summary>
	public class CollapseBar : WebControl, IPostBackEventHandler, IPostBackDataHandler {

		#region Properties

		/// <exclude/>
		protected override HtmlTextWriterTag TagKey {
			get {
				return HtmlTextWriterTag.Div;
			}
		}

		/// <summary>
		/// Gets or sets the name of the current item.
		/// </summary>
		[
		Category( "Appearance" ),
		DefaultValue( "" ),
		MergableProperty( false ),
		]
		public virtual String CurrentItem {
			get {
				Object savedState = this.ViewState["CurrentItem"];
				if ( savedState != null  ) {
					return (String)savedState;
				}
				return String.Empty;
			}
			set {
				this.ViewState["CurrentItem"] = value;
			}
		}

		/// <summary>
		/// Gets the collection of items contained by the CollapseBar.
		/// </summary>
		[
		NotifyParentProperty( true ),
		DesignerSerializationVisibility( DesignerSerializationVisibility.Content ),
		PersistenceMode( PersistenceMode.InnerProperty ),
		MergableProperty( false ),
		]
		public virtual CollapseBarItemCollection Items {
			get {
				if ( _items == null ) {
					_items = new CollapseBarItemCollection( this );
				}
				return _items;
			}
		}
		private CollapseBarItemCollection _items;

		/// <summary>
		/// Gets the style applied to the current item's selection button.
		/// </summary>
		[
		Category( "Style" ),
		NotifyParentProperty( true ),
		DesignerSerializationVisibility( DesignerSerializationVisibility.Content ),
		PersistenceMode( PersistenceMode.InnerProperty ),
		]
		public virtual System.Web.UI.WebControls.Style CurrentButtonStyle {
			get {
				if ( _currentButtonStyle == null ) {
					_currentButtonStyle = new System.Web.UI.WebControls.Style();
					if ( this.IsTrackingViewState ) {
						((IStateManager)_currentButtonStyle).TrackViewState();
					}
				}
				return _currentButtonStyle;
			}
		}
		private System.Web.UI.WebControls.Style _currentButtonStyle;

		/// <summary>
		/// Gets the style applied to each item's selection button.
		/// </summary>
		[
		Category( "Style" ),
		NotifyParentProperty( true ),
		DesignerSerializationVisibility( DesignerSerializationVisibility.Content ),
		PersistenceMode( PersistenceMode.InnerProperty ),
		]
		public virtual System.Web.UI.WebControls.Style ButtonStyle {
			get {
				if ( _buttonStyle == null ) {
					_buttonStyle = new System.Web.UI.WebControls.Style();
					if ( this.IsTrackingViewState ) {
						((IStateManager)_buttonStyle).TrackViewState();
					}
				}
				return _buttonStyle;
			}
		}
		private System.Web.UI.WebControls.Style _buttonStyle;

		/// <summary>
		/// Gets the style applied to the content area.
		/// </summary>
		[
		Category( "Style" ),
		NotifyParentProperty( true ),
		DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
		PersistenceMode(PersistenceMode.InnerProperty),
		]
		public System.Web.UI.WebControls.Style ContentStyle {
			get {
				if ( _contentStyle == null ) {
					_contentStyle = new System.Web.UI.WebControls.Style();
					if ( IsTrackingViewState ) {
						((IStateManager)_contentStyle).TrackViewState();
					}
				}
				return _contentStyle;
			}
		}
		private System.Web.UI.WebControls.Style _contentStyle;

		
		private String ClientSideCurrentItemTrackerID {
			get {
				return this.UniqueID + ":CurrentItemTracker";
			}
		}

		
		private String ActiveItem {
			get {
				if ( _activeItem == null ) {
					_activeItem = this.DetermineActiveItem();
				}
				return _activeItem;
			}
		}
		private String _activeItem;

		private String DetermineActiveItem() {
			if ( this.Items.Count == 0 ) {
				return "";
			}

			String currentItem = this.CurrentItem;

			Boolean currentItemFound = false;
			foreach( CollapseBarItem item in this.Items ) {
				if ( item.Title == currentItem ) {
					currentItemFound = true;
					break;
				}
			}
			if ( !currentItemFound ) {
				currentItem = this.Items[ 0 ].Title;
			}

			return currentItem;
		}


		
		#endregion

		#region ViewState

		/// <exclude/>
		protected override void LoadViewState( object savedState ) {
			if ( savedState == null ) {
				base.LoadViewState( null );
				return;
			}

			Object[] state = savedState as Object[];
			if ( state == null || state.Length != 4 ) {
				throw new ArgumentException( "Invalid ViewState" );
			} else {
				base.LoadViewState( state[0] );
				if ( state[1] != null ) {
					((IStateManager)ButtonStyle).LoadViewState( state[1] );
				}
				if ( state[2] != null ) {
					((IStateManager)CurrentButtonStyle).LoadViewState( state[2] );
				}
				if ( state[3] != null ) {
					((IStateManager)ContentStyle).LoadViewState( state[3] );
				}
			}
		}

		/// <exclude/>
		protected override object SaveViewState() {
			Object[] state = new Object[4];
			state[0] = base.SaveViewState();
			state[1] = _buttonStyle == null ? null : ((IStateManager)_buttonStyle).SaveViewState();
			state[2] = _currentButtonStyle == null ? null : ((IStateManager)_currentButtonStyle).SaveViewState();
			state[3] = _contentStyle == null ? null : ((IStateManager)_contentStyle).SaveViewState();
			for( Int32 i = 0; i < state.Length; i++ ) {
				if ( state[i] != null ) {
					return state;
				}
			}
			return null;
		}

		/// <exclude/>
		protected override void TrackViewState() {
			base.TrackViewState();
			if ( _buttonStyle != null ) {
				((IStateManager)_buttonStyle).TrackViewState();
			}
			if ( _currentButtonStyle != null ) {
				((IStateManager)_currentButtonStyle).TrackViewState();
			}
			if ( _contentStyle != null ) {
				((IStateManager)_contentStyle).TrackViewState();
			}
		}

		#endregion

		#region Lifecycle

		/// <exclude/>
		protected override ControlCollection CreateControlCollection() {
			return new CollapseBarControlCollection( this );
		}
		/// <exclude/>
		protected override void OnLoad(EventArgs e) {
			this.LoadStateCookie();
			base.OnLoad( e );
		}

		/// <exclude/>
		protected override void OnPreRender( EventArgs e ) {
			base.OnPreRender( e );
			if ( this.Page != null ) {
				this.Page.RegisterRequiresPostBack( this );
				if ( this.RenderUpLevel ) {
					this.RegisterClientScript();
				}
			}
			this.SaveStateCookie();
		}

		/// <exclude/>
		protected override void Render( HtmlTextWriter writer ) {
			if ( this.Page != null ) {
				this.Page.VerifyRenderingInServerForm( this );
			}
			base.Render( writer );
		}

		/// <exclude/>
		protected override void RenderContents(HtmlTextWriter writer) {
			if ( this.Items.Count > 0 ) {
				if ( RenderUpLevel ) {
					RenderContentsUpLevel( writer );
				} else {
					RenderContentsDownLevel( writer );
				}
			}
		}

		
		#region Render UpLevel

		private void RenderContentsUpLevel( HtmlTextWriter writer ) {
			RenderUpLevelButtons( writer );
			RenderUpLevelItems( writer );
		}

		private void RenderUpLevelItems( HtmlTextWriter writer ) {
			foreach( CollapseBarItem item in this.Items ) {
				if ( item.Visible ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -