writer.RenderBeginTag(HtmlTextWriterTag.Tr);
}
writer.RenderBeginTag(HtmlTextWriterTag.Td);
// Set the style
if (_owner.Page != null && _owner.Page.SupportsStyleSheets) {
string styleClass = _owner.GetCssClassName(this, false);
if (styleClass.Trim().Length > 0) {
writer.AddAttribute(HtmlTextWriterAttribute.Class, styleClass);
}
}
else if (mergedStyle != null) {
mergedStyle.AddAttributesToRender(writer);
}
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
if (!_owner.ItemWrap) {
writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap");
}
if (orientation == Orientation.Vertical) {
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
}
writer.RenderBeginTag(HtmlTextWriterTag.Td);
if (_owner.Page != null && _owner.Page.SupportsStyleSheets) {
bool applyInlineBorder;
string styleClass = _owner.GetCssClassName(this, true, out applyInlineBorder);
if (styleClass.Trim().Length > 0) {
writer.AddAttribute(HtmlTextWriterAttribute.Class, styleClass);
if (applyInlineBorder) {
// Add inline style to force the border to none to override any CssClass (VSWhidbey 336610)
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "none");
// And an inline font-size of 1em to avoid squaring relative font sizes by applying them twice
writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "1em");
}
}
}
else {
if (mergedStyle != null) {
mergedStyle.HyperLinkStyle.AddAttributesToRender(writer);
}
}
string accessKey = _owner.AccessKey;
if (enabled && Selectable) {
// If there is a navigation url on this item, set up the navigation stuff
if (NavigateUrl.Length > 0) {
writer.AddAttribute(HtmlTextWriterAttribute.Href, _owner.ResolveClientUrl(NavigateUrl));
// Use the MenuItem Target if it has one, the Menu's if it doesn't
string target = ViewState["Target"] as string;
if (target == null) {
target = _owner.Target;
}
if (target.Length > 0) {
writer.AddAttribute(HtmlTextWriterAttribute.Target, target);
}
}
// Otherwise, write out a postback that will select the item
else {
writer.AddAttribute(HtmlTextWriterAttribute.Href,
_owner.Page.ClientScript.GetPostBackClientHyperlink(_owner, InternalValuePath, true, true));
}
// AccessKey
if (!_owner.AccessKeyRendered && (accessKey.Length != 0)) {
writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, accessKey, true);
_owner.AccessKeyRendered = true;
}
}
else {
// Span if disabled or not selectable
if (!enabled) {
writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "true");
}
else if ((ChildItems.Count != 0) && (depthPlusOne >= _owner.StaticDisplayLevels)) {
// For accessibility reasons, we want the a to have an href even if it's not selectable
// because we want it to be focusable if it has dynamic children.
writer.AddAttribute(HtmlTextWriterAttribute.Href, "#");
writer.AddStyleAttribute(HtmlTextWriterStyle.Cursor, "text");
// AccessKey
if (!_owner.AccessKeyRendered && (accessKey.Length != 0)) {
writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, accessKey, true);
_owner.AccessKeyRendered = true;
}
}
}
if (depth != 0 && depth < _owner.StaticDisplayLevels) {
Unit indent = _owner.StaticSubMenuIndent;
// In 4.0, the default value of Menu.StaticSubMenuIndent was changed from 16px to Unit.Empty,
// since the table and list rendering modes need to have different effective default values.
// To maintain back compat, the effective default value for table rendering is 16px.
// Dev10 Bug 741543
if (indent.IsEmpty) {
indent = Unit.Pixel(16);
}
if (indent.Value != 0) {
double indentValue = indent.Value * depth;
if (indentValue < Unit.MaxValue) {
indent = new Unit(indentValue, indent.Type);
}
else {
indent = new Unit(Unit.MaxValue, indent.Type);
}
writer.AddStyleAttribute("margin-left", indent.ToString(CultureInfo.InvariantCulture));
}
}
//
// We're rendering an A tag in all cases so that the client script can always find the items by tag name
writer.RenderBeginTag(HtmlTextWriterTag.A);
// Render out the item icon, if it is set and if the item is not templated
if (ImageUrl.Length > 0 && NotTemplated()) {
//
writer.AddAttribute(HtmlTextWriterAttribute.Src, _owner.ResolveClientUrl(ImageUrl));
writer.AddAttribute(HtmlTextWriterAttribute.Alt, ToolTip);
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "none");
writer.AddStyleAttribute("vertical-align", "middle");
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
// Item text
RenderText(writer);
// or
writer.RenderEndTag();
bool shouldRenderExpandImage = ((depthPlusOne >= _owner.StaticDisplayLevels) &&
(depthPlusOne < _owner.MaximumDepth));
string expandImageUrl = (shouldRenderExpandImage ? GetExpandImageUrl() : String.Empty);
// Render some space if horizontal
bool needsSpace = false;
if ((orientation == Orientation.Horizontal) &&
(depth < _owner.StaticDisplayLevels) &&
(!shouldRenderExpandImage || (expandImageUrl.Length == 0)) &&
((mergedStyle == null) || mergedStyle.ItemSpacing.IsEmpty)) {
if (((Depth + 1) < _owner.StaticDisplayLevels) && (ChildItems.Count != 0)) {
// next level is static too and exists, so we're not the last static
needsSpace = true;
}
else {
// Static item with no static children.
// We need to check if there are any static items at any level after this one.
// This is done by checking if any ancestor is not last.
// This walk should be marginally executed as multiple static display levels
// don't make sense on a horizontal menu.
MenuItem parent = this;
while (parent != null) {
if (((parent.Parent == null) &&
(_owner.Items.Count != 0) &&
(parent != _owner.Items[_owner.Items.Count - 1])) ||
((parent.Parent != null) &&
(parent.Parent.ChildItems.Count != 0) &&
(parent != parent.Parent.ChildItems[parent.Parent.ChildItems.Count - 1]))) {
needsSpace = true;
break;
}
parent = parent.Parent;
}
}
}
//
writer.RenderEndTag();
if (shouldRenderExpandImage && expandImageUrl.Length > 0) {
//
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "0");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
//
writer.AddAttribute(HtmlTextWriterAttribute.Src, expandImageUrl);
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "none");
writer.AddStyleAttribute(HtmlTextWriterStyle.VerticalAlign, "middle");
if (depth < _owner.StaticDisplayLevels) {
writer.AddAttribute(HtmlTextWriterAttribute.Alt,
String.Format(CultureInfo.CurrentCulture, _owner.StaticPopOutImageTextFormatString, Text));
}
else if (depth >= _owner.StaticDisplayLevels) {
writer.AddAttribute(HtmlTextWriterAttribute.Alt,
String.Format(CultureInfo.CurrentCulture, _owner.DynamicPopOutImageTextFormatString, Text));
}
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
// |
writer.RenderEndTag();
}
writer.RenderEndTag(); //
writer.RenderEndTag(); //