Files
mono/mcs/class/System.Web/System.Web.UI.WebControls/Menu.cs
T
Lluis Sanchez fbb5a6fb41 2004-12-03 Lluis Sanchez Gual <[email protected]>
* MenuEventArgs.cs: Changed to sealed.
	* TreeView.cs: Minor fix.
	* Menu.cs, MenuItemBindingCollection.cs, MenuItemCollection.cs,
	MenuItemStyle.cs, MenuItemBinding.cs, MenuItem.cs,
	MenuItemStyleCollection.cs: Initial Menu code.


svn path=/trunk/mcs/; revision=37044
2004-12-03 19:09:20 +00:00

257 lines
6.9 KiB
C#

//
// System.Web.UI.WebControls.Menu.cs
//
// Authors:
// Lluis Sanchez Gual ([email protected])
//
// (C) 2004 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.Handlers;
using System.Collections.Specialized;
using System.IO;
namespace System.Web.UI.WebControls
{
public class Menu : HierarchicalDataBoundControl, IPostBackEventHandler, INamingContainer
{
MenuItemCollection items;
MenuItemBindingCollection dataBindings;
MenuItem selectedItem;
Hashtable bindings;
[PersistenceMode (PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
[Editor ("System.Web.UI.Design.MenuItemBindingsEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
public virtual MenuItemBindingCollection DataBindings {
get {
if (dataBindings == null) {
dataBindings = new MenuItemBindingCollection ();
if (IsTrackingViewState)
((IStateManager)dataBindings).TrackViewState();
}
return dataBindings;
}
}
[DefaultValue (500)]
public virtual int DisappearAfter {
get {
object o = ViewState ["DisappearAfter"];
if (o != null) return (int)o;
return 500;
}
set {
ViewState["DisappearAfter"] = value;
}
}
[DefaultValue ("")]
[UrlProperty]
[WebCategory ("Appearance")]
[Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
public virtual string DynamicBottomSeparatorImageUrl {
get {
object o = ViewState ["dbsiu"];
if (o != null) return (string)o;
return "";
}
set {
ViewState["dbsiu"] = value;
}
}
/* [DefaultValue (true)]
public virtual bool DynamicEnableDefaultPopOutImage {
get {
object o = ViewState ["dedpoi"];
if (o != null) return (bool)o;
return true;
}
set {
ViewState["dedpoi"] = value;
}
}
*/
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
[PersistenceMode (PersistenceMode.InnerProperty)]
[Editor ("System.Web.UI.Design.MenuItemCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
public virtual MenuItemCollection Items {
get {
if (items == null) {
items = new MenuItemCollection (this);
if (IsTrackingViewState)
((IStateManager)items).TrackViewState();
}
return items;
}
}
[DefaultValue ('/')]
public virtual char PathSeparator {
get {
object o = ViewState ["PathSeparator"];
if(o != null) return (char)o;
return '/';
}
set {
ViewState ["PathSeparator"] = value;
}
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public MenuItem SelectedItem {
get { return selectedItem; }
}
internal void SetSelectedItem (MenuItem item)
{
if (selectedItem == item) return;
if (selectedItem != null)
selectedItem.SelectedFlag = false;
selectedItem = item;
selectedItem.SelectedFlag = true;
// OnSelectedItemChanged (new MenuItemEventArgs (selectedItem));
}
public MenuItem FindItem (string valuePath)
{
if (valuePath == null) throw new ArgumentNullException ("valuePath");
string[] path = valuePath.Split (PathSeparator);
int n = 0;
MenuItemCollection col = Items;
bool foundBranch = true;
while (col.Count > 0 && foundBranch) {
foundBranch = false;
foreach (MenuItem item in col) {
if (item.Value == path [n]) {
if (++n == path.Length) return item;
col = item.ChildItems;
foundBranch = true;
break;
}
}
}
return null;
}
string GetBindingKey (string dataMember, int depth)
{
return dataMember + " " + depth;
}
internal MenuItemBinding FindBindingForItem (string type, int depth)
{
if (bindings == null) return null;
MenuItemBinding bin = (MenuItemBinding) bindings [GetBindingKey (type, depth)];
if (bin != null) return bin;
bin = (MenuItemBinding) bindings [GetBindingKey (type, -1)];
if (bin != null) return bin;
bin = (MenuItemBinding) bindings [GetBindingKey ("", depth)];
if (bin != null) return bin;
bin = (MenuItemBinding) bindings [GetBindingKey ("", -1)];
return bin;
}
protected internal override void PerformDataBinding ()
{
base.PerformDataBinding ();
HierarchicalDataSourceView data = GetData ("");
IHierarchicalEnumerable e = data.Select ();
foreach (object obj in e) {
IHierarchyData hdata = e.GetHierarchyData (obj);
MenuItem item = new MenuItem ();
item.Bind (hdata);
Items.Add (item);
}
}
void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
{
}
protected override void TrackViewState()
{
EnsureDataBound ();
base.TrackViewState();
if (dataBindings != null) {
((IStateManager)dataBindings).TrackViewState ();
}
if (items != null) {
((IStateManager)items).TrackViewState();;
}
}
protected override object SaveViewState()
{
object[] states = new object [2];
states[0] = base.SaveViewState();
states[1] = (dataBindings == null ? null : ((IStateManager)dataBindings).SaveViewState());
states[2] = (items == null ? null : ((IStateManager)items).SaveViewState());
for (int i = states.Length - 1; i >= 0; i--) {
if (states [i] != null)
return states;
}
return null;
}
protected override void LoadViewState (object savedState)
{
if (savedState == null)
return;
object [] states = (object []) savedState;
base.LoadViewState (states[0]);
if (states[1] != null)
((IStateManager)dataBindings).LoadViewState(states[8]);
if (states[2] != null)
((IStateManager)Items).LoadViewState(states[9]);
}
protected override void RenderContents (HtmlTextWriter writer)
{
writer.WriteLine ("This is a menu");
}
}
}
#endif