Example #1
0
		/// <summary>
		/// BuildMenu builds the top-level menu.  It is called from the OnDataBinding method as well
		/// as from <see cref="CreateChildControls"/>.  It has code to check if the top-level menu should be
		/// laid out horizontally or vertically.
		/// </summary>
		protected virtual void BuildMenu()
		{
			string image = string.Empty;
			string mouseoverimage = string.Empty;
			string mousedownimage = string.Empty;
			string mouseupimage = string.Empty;			

			// iterate through the Items
			Table menu = new Table();
			menu.Attributes.Add("id", this.ClientID);
			menu.MergeStyle(this.ControlStyle);

			menu.CellPadding = ItemPadding;
			menu.CellSpacing = ItemSpacing;
			menu.GridLines = GridLines;

			// Add the Menu control's STYLE properties to the TABLE
			IEnumerator key = this.Style.Keys.GetEnumerator();
			while(key.MoveNext())
			{
				string k = key.Current.ToString();
				menu.Style.Add(k, this.Style[k]);
			}

			menu.Style.Remove("Z-INDEX");		// remove z-index added automatically by grid positioning

			// set the Z-INDEX
			menu.Style.Add("z-index", this.zIndex.ToString());
			curzindex = this.zIndex + 2;

			BuildOpacity(menu);
			
			TableRow tr = null;
			if (Layout == MenuLayout.Horizontal)
				tr = new TableRow();

			// Iterate through the top-level menu's menuitems, and add a <td> tag for each menuItem
			for (int i = 0; i < this.items.Count; i++)
			{
				MenuItem mi = this.items[i];

				//add by johnny start
				if (this.MainSpacingWidth != 0)
				{
					if (i % 2 == 1)
					{
						TableCell tdblank = new TableCell();
						tdblank.Width=this.MainSpacingWidth;
						tdblank.BackColor = Color.Empty;
						tr.Cells.Add(tdblank);
					}
				}
				//end

				// only render this MenuItem if it is visible and the user has permissions
				if (mi.Visible && UserHasPermission(mi)) 
				{ 
					if (Layout == MenuLayout.Vertical)
						tr = new TableRow();

					TableCell td = new TableCell();
					td.ApplyStyle(this.unselectedMenuItemStyle);
					// The style is overwritten by anything specifically set in menuitem
					if (mi.BackColor != Color.Empty) 
						td.BackColor = mi.BackColor;
					if (mi.Font != null)
						td.Font.CopyFrom(mi.Font);
					if (mi.ForeColor != Color.Empty)
						td.ForeColor = mi.ForeColor;
					if (mi.Height != Unit.Empty)
						td.Height = mi.Height;
					if (mi.Width != Unit.Empty)
						td.Width = mi.Width;
					if (mi.CssClass != String.Empty)
						td.CssClass = mi.CssClass;
					else if	(this.DefaultCssClass != String.Empty)
						td.CssClass = this.DefaultCssClass;
					if (mi.BorderColor != Color.Empty)
						td.BorderColor = mi.BorderColor;
					if (mi.BorderStyle != BorderStyle.NotSet)
						td.BorderStyle = mi.BorderStyle;
					if (mi.BorderWidth != Unit.Empty)
						td.BorderWidth = mi.BorderWidth;
					if (mi.HorizontalAlign != System.Web.UI.WebControls.HorizontalAlign.NotSet)
						td.HorizontalAlign = mi.HorizontalAlign;
					if (mi.VerticalAlign != System.Web.UI.WebControls.VerticalAlign.NotSet)
						td.VerticalAlign = mi.VerticalAlign;
					BuildOpacity(td);
					if (mi.Text != string.Empty)
						td.Text = mi.Text;  // Text
					else if (mi.Image != string.Empty) // Show Image
					{
						System.Web.UI.WebControls.Image cellimage = new System.Web.UI.WebControls.Image();

						cellimage.ImageUrl = mi.Image;
						cellimage.AlternateText = mi.ImageAltText;
						td.Controls.Add(cellimage);
						
						image = mi.Image;
						mouseoverimage = mi.MouseOverImage;
						mousedownimage = mi.MouseDownImage;
						mouseupimage = mi.MouseUpImage;
					}
					td.Attributes.Add("id", mi.MenuID);

					// Add in the left or right image as needed
					if (mi.LeftImage != String.Empty) 
					{
						System.Web.UI.WebControls.Image leftimage = new System.Web.UI.WebControls.Image();
						System.Web.UI.WebControls.Literal leftliteral = new System.Web.UI.WebControls.Literal();

						leftimage.ImageAlign = mi.LeftImageAlign;
						if (mi.LeftImageRightPadding != Unit.Empty)
							leftimage.Style.Add("margin-right",mi.LeftImageRightPadding.Value.ToString());
						leftimage.ImageUrl = mi.LeftImage;
						td.Controls.Add(leftimage);

						leftliteral.Text = td.Text;
						td.Controls.Add(leftliteral);
					} 
					else if (mi.RightImage != String.Empty) 
					{
						System.Web.UI.WebControls.Image rightimage = new System.Web.UI.WebControls.Image();
						System.Web.UI.WebControls.Literal rightliteral = new System.Web.UI.WebControls.Literal();
						
						rightliteral.Text = td.Text;
						td.Controls.Add(rightliteral);

						rightimage.ImageAlign = mi.RightImageAlign;
						if (mi.RightImageLeftPadding != Unit.Empty)
							rightimage.Style.Add("margin-left",mi.RightImageLeftPadding.Value.ToString());
						rightimage.ImageUrl = mi.RightImage;
						td.Controls.Add(rightimage);
					}

					// Prepare MouseOverCssClass
					string mouseover = String.Empty;

					if (this.DefaultMouseOverCssClass != string.Empty || mi.MouseOverCssClass != string.Empty || this.selectedMenuItemStyle.CssClass != String.Empty)
						mouseover = "this.className='" + GetClass(this.DefaultMouseOverCssClass, mi.MouseOverCssClass, this.selectedMenuItemStyle.CssClass) + "';";

					if (mi.Enabled) // if enabled...
					{
						// Generate OnClick handler
						if (mi.JavascriptCommand != String.Empty) // javascript command
							td.Attributes.Add("onclick", mi.JavascriptCommand + "skm_closeSubMenus(document.getElementById('" + this.ClientID + "'));");
						else if (mi.Url != String.Empty) 
						{
							if (mi.Target != String.Empty)
								td.Attributes.Add("onclick", "javascript:skm_closeSubMenus(document.getElementById('" + this.ClientID + "'));window.open('" + GetURL(mi.ResolveURL, mi.Url) + "','" + mi.Target + "');");
							else if (this.DefaultTarget != String.Empty)
								td.Attributes.Add("onclick", "javascript:skm_closeSubMenus(document.getElementById('" + this.ClientID + "'));window.open('" + GetURL(mi.ResolveURL, mi.Url) + "','" + this.DefaultTarget + "');");
							else
								td.Attributes.Add("onclick", "javascript:skm_closeSubMenus(document.getElementById('" + this.ClientID + "'));location.href='" + GetURL(mi.ResolveURL, mi.Url) + "';");
						}
						else if (mi.CommandName != String.Empty) // Must be postback action
							td.Attributes.Add("onclick", Page.GetPostBackClientHyperlink(this, mi.CommandName));
						else if (this.ClickToOpen) // Open submenu on click
							if (Layout == MenuLayout.Vertical)
								td.Attributes.Add("onclick", "javascript:skm_mousedOverMenu('" + this.ClientID + "',this, document.getElementById('" + this.ClientID + "'), true, '" + mouseoverimage + "');" + GenerateShimCall("true", mi.MenuID + "-subMenu") + mouseover);
							else
								td.Attributes.Add("onclick", "javascript:skm_mousedOverMenu('" + this.ClientID + "',this, document.getElementById('" + this.ClientID + "'), false, '" + mouseoverimage + "');" + GenerateShimCall("true", mi.MenuID + "-subMenu") + mouseover);
					}

					if (mi.Enabled)
					{
						// Output Tooltip
						if (mi.ToolTip != String.Empty) 
							td.ToolTip = mi.ToolTip;

						// Output MouseDownCssClass or MouseDownImage
						string mousedown = String.Empty;

						if (this.DefaultMouseDownCssClass != string.Empty || mi.MouseDownCssClass != string.Empty)
							mousedown = "this.className='" + GetClass(this.DefaultMouseDownCssClass, mi.MouseDownCssClass) + "';";

						if (mousedownimage != String.Empty)
							mousedown += "setimage(this, '" + mousedownimage + "');";

						if (mousedown != string.Empty)
							td.Attributes.Add("onmousedown", mousedown);

						// Output MouseUpCssClass or MouseUpImage
						string mouseup = String.Empty;

						if (this.DefaultMouseUpCssClass != string.Empty || mi.MouseUpCssClass != string.Empty)
							mouseup = "this.className='" + GetClass(this.DefaultMouseUpCssClass, mi.MouseUpCssClass) + "';";

						if (mouseupimage != String.Empty)
							mouseup += "setimage(this, '" + mouseupimage + "');";

						if (mouseup != string.Empty)
							td.Attributes.Add("onmouseup", mouseup);

						if (this.ClickToOpen == false) 
						{
							if (Layout == MenuLayout.Vertical)
								td.Attributes.Add("onmouseover", "javascript:skm_mousedOverMenu('" + this.ClientID + "',this, document.getElementById('" + this.ClientID + "'), true, '" + mouseoverimage + "');" + GenerateShimCall("true", mi.MenuID + "-subMenu") + mouseover);
							else
								td.Attributes.Add("onmouseover", "javascript:skm_mousedOverMenu('" + this.ClientID + "',this, document.getElementById('" + this.ClientID + "'), false, '" + mouseoverimage + "');" + GenerateShimCall("true", mi.MenuID + "-subMenu") + mouseover);
						} 
						else
							td.Attributes.Add("onmouseover", "javascript:skm_mousedOverClickToOpen('" + this.ClientID + "', this, document.getElementById('" + this.ClientID + "'), '" + mouseoverimage + "');"+ mouseover);
						
						td.Attributes.Add("onmouseout", "javascript:skm_mousedOutMenu('" + this.ClientID +"', this, '" + image + "');" + "this.className='" + GetClass(this.DefaultCssClass, mi.CssClass, this.unselectedMenuItemStyle.CssClass) + "';");
					} 
					else // disabled...
					{
						td.Attributes.Add("onmouseover", "javascript:skm_mousedOverSpacer('" + this.ClientID + "', this, document.getElementById('" + this.ClientID + "'));");
						td.Attributes.Add("onmouseout", "javascript:skm_mousedOutSpacer('" + this.ClientID + "', this);");
					}

					if (mi.Url != String.Empty || mi.CommandName != String.Empty)
						if (this.Cursor != MouseCursor.Default) 
						{
							if (this.Page.Request.Browser.Browser == "IE")
								td.Style.Add("cursor","hand"); 
							else
								td.Style.Add("cursor","pointer"); 
						}

					tr.Cells.Add(td);

					if (Layout == MenuLayout.Vertical)
						menu.Rows.Add(tr);

					// Add the subitems for this menu, if needed
					if (mi.SubItems.Count > 0)
					{
						// Create an IFrame (IE5.5 or better) to windowed form elements that might
						// interfere with display of the menu
						if (this.Page.Request.Browser.Browser == "IE" && Convert.ToDouble(this.Page.Request.Browser.Version, enUSCulture) >= 5.5) 
						{
							System.Web.UI.HtmlControls.HtmlGenericControl iframe = new System.Web.UI.HtmlControls.HtmlGenericControl();
							iframe.TagName = "iframe";
							iframe.Attributes.Add("id", "shim" + mi.MenuID + "-subMenu");
							iframe.Attributes.Add("src", IFrameSrc);
							iframe.Attributes.Add("scrolling", "no");
							iframe.Attributes.Add("frameborder", "no");
							iframe.Style.Add("position", "absolute");
							iframe.Style.Add("top", "0px");
							iframe.Style.Add("left", "0px");
							iframe.Style.Add("display", "none");
							BuildOpacity(iframe);
							Controls.Add(iframe);			
						}

						this.subItemsIds.Add(mi.MenuID + "-subMenu");
						AddMenu(mi.MenuID + "-subMenu", mi.SubItems);
					}
				}
			}

			if (Layout == MenuLayout.Horizontal)
				menu.Rows.Add(tr);

			Controls.Add(menu);
		}
Example #2
0
 public override void RenderBeginTag(HtmlTextWriter writer)
 {
     Table tbl = new Table();
     tbl.ID = "tbl_" + this.ID;
     tbl.MergeStyle(this.ControlStyle);
     tbl.RenderBeginTag(writer);
 }