writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.AddStyleAttribute(HtmlTextWriterStyle.Width, _owner.NodeIndent.ToString(CultureInfo.InvariantCulture) + "px"); writer.RenderBeginTag(HtmlTextWriterTag.Table); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); if (_owner.ShowLines && !isLast[i]) { writer.AddAttribute(HtmlTextWriterAttribute.Src, _owner.GetImageUrl(TreeView.IImageIndex)); writer.AddAttribute(HtmlTextWriterAttribute.Alt, String.Empty); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); } writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderEndTag(); // | writer.RenderEndTag(); } else { //
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(" ");
if (_owner.ShowLines && !isLast[i]) {
writer.AddAttribute(HtmlTextWriterAttribute.Src, _owner.GetImageUrl(TreeView.IImageIndex));
writer.AddAttribute(HtmlTextWriterAttribute.Alt, String.Empty);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
writer.Write(" ");
// |
writer.RenderEndTag();
}
}
}
// A node can expand if its populate on demand or if it has children
bool canExpand = (PopulateOnDemand || (ChildNodes.Count > 0)) && _owner.ShowExpandCollapse;
string imageUrl = String.Empty;
string lineType = " ";
string imageToolTip = String.Empty;
if (last) {
if (canExpand) {
if (expanded) {
if (_owner.ShowLines) {
if (depth == 0) {
if (position == 0) {
// The first and only root node
lineType = "-";
imageUrl = _owner.GetImageUrl(TreeView.DashMinusImageIndex);
imageToolTip = _owner.CollapseImageToolTip;
}
else {
// The last root node
lineType = "l";
imageUrl = _owner.GetImageUrl(TreeView.LMinusImageIndex);
imageToolTip = _owner.CollapseImageToolTip;
}
}
else {
// The last node in a set of siblings
lineType = "l";
imageUrl = _owner.GetImageUrl(TreeView.LMinusImageIndex);
imageToolTip = _owner.CollapseImageToolTip;
}
}
else {
imageUrl = _owner.GetImageUrl(TreeView.MinusImageIndex);
imageToolTip = _owner.CollapseImageToolTip;
}
}
else {
if (_owner.ShowLines) {
if (depth == 0) {
if (position == 0) {
// The first and only root node
lineType = "-";
imageUrl = _owner.GetImageUrl(TreeView.DashPlusImageIndex);
imageToolTip = _owner.ExpandImageToolTip;
}
else {
// The last root node
lineType = "l";
imageUrl = _owner.GetImageUrl(TreeView.LPlusImageIndex);
imageToolTip = _owner.ExpandImageToolTip;
}
}
else {
// The last node in a set of sibling
lineType = "l";
imageUrl = _owner.GetImageUrl(TreeView.LPlusImageIndex);
imageToolTip = _owner.ExpandImageToolTip;
}
}
else {
imageUrl = _owner.GetImageUrl(TreeView.PlusImageIndex);
imageToolTip = _owner.ExpandImageToolTip;
}
}
}
else {
if (_owner.ShowLines) {
if (depth == 0) {
if (position == 0) {
// The first and only node, no children
lineType = "-";
imageUrl = _owner.GetImageUrl(TreeView.DashImageIndex);
}
else {
// The last root node, no children
lineType = "l";
imageUrl = _owner.GetImageUrl(TreeView.LImageIndex);
}
}
else {
// The last node in a set of siblings, no children
lineType = "l";
imageUrl = _owner.GetImageUrl(TreeView.LImageIndex);
}
}
else if (_owner.ShowExpandCollapse) {
imageUrl = _owner.GetImageUrl(TreeView.NoExpandImageIndex);
}
}
}
else {
if (canExpand) {
if (expanded) {
if (_owner.ShowLines) {
if (depth == 0) {
if (position == 0) {
// The first root node
lineType = "r";
imageUrl = _owner.GetImageUrl(TreeView.RMinusImageIndex);
imageToolTip = _owner.CollapseImageToolTip;
}
else {
// A middle root node
lineType = "t";
imageUrl = _owner.GetImageUrl(TreeView.TMinusImageIndex);
imageToolTip = _owner.CollapseImageToolTip;
}
}
else {
// A middle node
lineType = "t";
imageUrl = _owner.GetImageUrl(TreeView.TMinusImageIndex);
imageToolTip = _owner.CollapseImageToolTip;
}
}
else {
imageUrl = _owner.GetImageUrl(TreeView.MinusImageIndex);
imageToolTip = _owner.CollapseImageToolTip;
}
}
else {
if (_owner.ShowLines) {
if (depth == 0) {
if (position == 0) {
// The first root node
lineType = "r";
imageUrl = _owner.GetImageUrl(TreeView.RPlusImageIndex);
imageToolTip = _owner.ExpandImageToolTip;
}
else {
// A middle root node
lineType = "t";
imageUrl = _owner.GetImageUrl(TreeView.TPlusImageIndex);
imageToolTip = _owner.ExpandImageToolTip;
}
}
else {
// A middle node
lineType = "t";
imageUrl = _owner.GetImageUrl(TreeView.TPlusImageIndex);
imageToolTip = _owner.ExpandImageToolTip;
}
}
else {
imageUrl = _owner.GetImageUrl(TreeView.PlusImageIndex);
imageToolTip = _owner.ExpandImageToolTip;
}
}
}
else {
if (_owner.ShowLines) {
if (depth == 0) {
if (position == 0) {
// The first root node, no children
lineType = "r";
imageUrl = _owner.GetImageUrl(TreeView.RImageIndex);
}
else {
// A middle root node, no children
lineType = "t";
imageUrl = _owner.GetImageUrl(TreeView.TImageIndex);
}
}
else {
// A middle node, no children
lineType = "t";
imageUrl = _owner.GetImageUrl(TreeView.TImageIndex);
}
}
else if (_owner.ShowExpandCollapse) {
imageUrl = _owner.GetImageUrl(TreeView.NoExpandImageIndex);
}
}
}
TreeNodeTypes type = GetTreeNodeType();
// Figure out the proper node icon
string nodeImageUrl = String.Empty;
if (ImageUrl.Length > 0) {
nodeImageUrl = _owner.ResolveClientUrl(ImageUrl);
}
else {
if ((depth < _owner.LevelStyles.Count) && (_owner.LevelStyles[depth] != null) && mergedStyle.ImageUrl.Length > 0) {
nodeImageUrl = _owner.GetLevelImageUrl(depth);
}
else {
switch (type) {
case TreeNodeTypes.Root:
nodeImageUrl = _owner.GetImageUrl(TreeView.RootImageIndex);
break;
case TreeNodeTypes.Parent:
nodeImageUrl = _owner.GetImageUrl(TreeView.ParentImageIndex);
break;
case TreeNodeTypes.Leaf:
nodeImageUrl = _owner.GetImageUrl(TreeView.LeafImageIndex);
break;
}
}
}
string selectImageId = String.Empty;
if (nodeImageUrl.Length > 0) {
selectImageId = SelectID + "i";
}
if (imageUrl.Length > 0) {
// writer.RenderBeginTag(HtmlTextWriterTag.Td); if (canExpand) { // If we are using client script and there aren't any expand/collapse handlers attached, do all the toggling/populating if (_owner.RenderClientScript && !_owner.CustomExpandCollapseHandlerExists) { writer.AddAttribute(HtmlTextWriterAttribute.Id, myId); if (PopulateOnDemand) { // If we are populating from the client, add all the needed attributes and call the client script needed to make the callback if (_owner.PopulateNodesFromClient) { if (ChildNodes.Count != 0) { throw new InvalidOperationException(SR.GetString(SR.TreeView_PopulateOnlyEmptyNodes, _owner.ID)); } writer.AddAttribute(HtmlTextWriterAttribute.Href, GetPopulateNodeAttribute(writer, myId, SelectID, selectImageId, lineType, depth, isLast)); } // If we aren't populating from the client, make a postback to do the population else { string href = "javascript:0"; if (_owner.Page != null) { href = _owner.Page.ClientScript.GetPostBackClientHyperlink(_owner, "t" + InternalValuePath, true, true); } writer.AddAttribute(HtmlTextWriterAttribute.Href, href); } } else { writer.AddAttribute(HtmlTextWriterAttribute.Href, GetToggleNodeAttributeValue(myId, lineType)); } } else { string href = "javascript:0"; if (_owner.Page != null) { href = _owner.Page.ClientScript.GetPostBackClientHyperlink(_owner, "t" + InternalValuePath, true); } // If we aren't using client script to perform expansions, get a postback reference writer.AddAttribute(HtmlTextWriterAttribute.Href, href); } if (enabled == true) { // writer.RenderBeginTag(HtmlTextWriterTag.A); } writer.AddAttribute(HtmlTextWriterAttribute.Src, imageUrl); writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0"); if (imageToolTip.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Alt, String.Format(CultureInfo.CurrentCulture, imageToolTip, Text)); //fix bug 1197460, quirk it so the fix will only be enabled on projects on 4.6.1 or later version of framework if (BinaryCompatibility.Current.TargetsAtLeastFramework461) { writer.AddAttribute(HtmlTextWriterAttribute.Title, String.Format(CultureInfo.CurrentCulture, imageToolTip, Text)); } } else { writer.AddAttribute(HtmlTextWriterAttribute.Alt, String.Empty); //fix bug 1197460, quirk it so the fix will only be enabled on projects on 4.6.1 or later version of framework if (BinaryCompatibility.Current.TargetsAtLeastFramework461) { writer.AddAttribute(HtmlTextWriterAttribute.Title, String.Empty); } } writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); if (enabled == true) { // writer.RenderEndTag(); } } else { writer.AddAttribute(HtmlTextWriterAttribute.Src, imageUrl); writer.AddAttribute(HtmlTextWriterAttribute.Alt, String.Empty); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); } // | writer.RenderEndTag(); } // Since we need the same set of anchor attributes on both the image and the text // accumulate a list here first ArrayList anchorAttributes = new ArrayList(); // If there is a navigation url on this node, set up the navigation stuff if (NavigateUrl.Length > 0) { // writer.AddAttribute(HtmlTextWriterAttribute.Href, _owner.ResolveClientUrl(NavigateUrl)); anchorAttributes.Add(HtmlTextWriterAttribute.Href); anchorAttributes.Add(_owner.ResolveClientUrl(NavigateUrl)); // Use the TreeNode Target if it has one, the TreeView'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); anchorAttributes.Add(HtmlTextWriterAttribute.Target); anchorAttributes.Add(target); if (_owner.RenderClientScript) { // Use client-script to merge in the selected node style string onClick = String.Empty; if (_owner.Page != null && _owner.Page.SupportsStyleSheets && (SelectAction == TreeNodeSelectAction.Select) || (SelectAction == TreeNodeSelectAction.SelectExpand)) { onClick = Util.MergeScript(onClick, "TreeView_SelectNode(" + _owner.ClientDataObjectID + ", this,'" + SelectID + "');"); } if ((SelectAction == TreeNodeSelectAction.Expand) || (SelectAction == TreeNodeSelectAction.SelectExpand)) { if (PopulateOnDemand) { // Postback to populate // onClick = Util.MergeScript(onClick, _owner.Page.ClientScript.GetPostBackClientHyperlink(_owner, "t" + InternalValuePath, true, true)); } else if (!_owner.CustomExpandCollapseHandlerExists && canExpand) { onClick = Util.MergeScript(onClick, GetToggleNodeAttributeValue(myId, lineType)); } } // writer.AddAttribute("onclick", onClick); if (onClick.Length != 0) { anchorAttributes.Add("onclick"); anchorAttributes.Add(onClick); } } } } // Otherwise, write out a postback that will select the node else { // If client script is on, call the proper javascript and the select action is expand if (_owner.RenderClientScript && (SelectAction == TreeNodeSelectAction.Expand) && !_owner.CustomExpandCollapseHandlerExists) { // and if the node is being populated on demand, and we are populating nodes from the client, call the populateNode javascript if (PopulateOnDemand) { if (_owner.PopulateNodesFromClient) { // writer.AddAttribute(HtmlTextWriterAttribute.Href, GetPopulateNodeAttribute(writer, myId, SelectID, lineType, depth, isLast)); anchorAttributes.Add(HtmlTextWriterAttribute.Href); anchorAttributes.Add(GetPopulateNodeAttribute(writer, myId, SelectID, selectImageId, lineType, depth, isLast)); } else { // If we're not populating from the client, postback to populate // writer.AddAttribute(HtmlTextWriterAttribute.Href, _owner.Page.GetPostBackClientHyperlink(_owner, "t" + HttpUtility.HtmlEncode(InternalValuePath), true)); anchorAttributes.Add(HtmlTextWriterAttribute.Href); string href = "javascript:0"; if (_owner.Page != null) { href = _owner.Page.ClientScript.GetPostBackClientHyperlink( _owner, "t" + InternalValuePath, true, true); } anchorAttributes.Add(href); } } else if (canExpand) { // writer.AddAttribute(HtmlTextWriterAttribute.Href, GetToggleNodeAttributeValue(myId, lineType)); anchorAttributes.Add(HtmlTextWriterAttribute.Href); anchorAttributes.Add(GetToggleNodeAttributeValue(myId, lineType)); } } // If not, just render an href for a postback else if (SelectAction != TreeNodeSelectAction.None) { // writer.AddAttribute(HtmlTextWriterAttribute.Href, _owner.Page.GetPostBackClientHyperlink(_owner, "s" + HttpUtility.HtmlEncode(InternalValuePath), true)); anchorAttributes.Add(HtmlTextWriterAttribute.Href); if (_owner.Page != null) { string href = _owner.Page.ClientScript.GetPostBackClientHyperlink( _owner, "s" + InternalValuePath, true, true); anchorAttributes.Add(href); if (_owner.RenderClientScript) { anchorAttributes.Add("onclick"); anchorAttributes.Add("TreeView_SelectNode(" + _owner.ClientDataObjectID + ", this,'" + SelectID + "');"); } } else { anchorAttributes.Add("javascript:0"); } } } if (ToolTip.Length > 0) { anchorAttributes.Add(HtmlTextWriterAttribute.Title); anchorAttributes.Add(ToolTip); } // Render out the node icon, if it is set if (nodeImageUrl.Length > 0) { //writer.RenderBeginTag(HtmlTextWriterTag.Td); // ApplyAttributeList(writer, anchorAttributes); // Set the id of the text hyperlink writer.AddAttribute(HtmlTextWriterAttribute.Id, selectImageId); if (enabled == true && SelectAction != TreeNodeSelectAction.None) { writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, "-1"); writer.RenderBeginTag(HtmlTextWriterTag.A); } writer.AddAttribute(HtmlTextWriterAttribute.Src, nodeImageUrl); writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0"); if (ImageToolTip.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Alt, ImageToolTip); //fix bug 1197460, quirk it so the fix will only be enabled on projects on 4.6.1 or later version of framework if (BinaryCompatibility.Current.TargetsAtLeastFramework461) { writer.AddAttribute(HtmlTextWriterAttribute.Title, ImageToolTip); } } else { writer.AddAttribute(HtmlTextWriterAttribute.Alt, String.Empty); //fix bug 1197460, quirk it so the fix will only be enabled on projects on 4.6.1 or later version of framework if (BinaryCompatibility.Current.TargetsAtLeastFramework461) { writer.AddAttribute(HtmlTextWriterAttribute.Title, String.Empty); } } writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); if (enabled == true && SelectAction != TreeNodeSelectAction.None) { // writer.RenderEndTag(); } // | writer.RenderEndTag(); } //if (!_owner.NodeWrap) { writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap"); } 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); } } if (_owner.EnableHover && (SelectAction != TreeNodeSelectAction.None)) { writer.AddAttribute("onmouseover", "TreeView_HoverNode(" + _owner.ClientDataObjectID + ", this)"); writer.AddAttribute("onmouseout", "TreeView_UnhoverNode(this)"); } writer.RenderBeginTag(HtmlTextWriterTag.Td); // Render a check box if we need to if (GetEffectiveShowCheckBox(type)) { writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox"); string id = myId + "CheckBox"; writer.AddAttribute(HtmlTextWriterAttribute.Name, id); writer.AddAttribute(HtmlTextWriterAttribute.Id, id); // VSWhidbey 497326: Render id for easier client-side scripting if (Checked) { writer.AddAttribute(HtmlTextWriterAttribute.Checked, "checked"); } if (enabled == false) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); if (!_owner.Enabled && (_owner.RenderingCompatibility >= VersionUtil.Framework40) && !String.IsNullOrEmpty(WebControl.DisabledCssClass)) { writer.AddAttribute(HtmlTextWriterAttribute.Class, WebControl.DisabledCssClass); } } if (ToolTip.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip); } writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); } // Rendering hook for extended treeviews RenderPreText(writer); if (_owner.Page != null && _owner.Page.SupportsStyleSheets) { bool renderInlineBorder; string styleClass = _owner.GetCssClassName(this, true, out renderInlineBorder); if (styleClass.Trim().Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Class, styleClass); if (renderInlineBorder) { // 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); } } ApplyAttributeList(writer, anchorAttributes); writer.AddAttribute(HtmlTextWriterAttribute.Id, SelectID); if ((SelectAction == TreeNodeSelectAction.None) || !enabled) { // Render a span so that the styles get applied, with the ID so that POD works writer.RenderBeginTag(HtmlTextWriterTag.Span); // Render plain text if the select action was none writer.Write(Text); writer.RenderEndTag(); } else { // AccessKey if (!_owner.AccessKeyRendered && _owner.AccessKey.Length != 0) { writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, _owner.AccessKey, true); _owner.AccessKeyRendered = true; } // writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write(Text); writer.RenderEndTag(); // } // Rendering hook for extended treeviews RenderPostText(writer); // | writer.RenderEndTag(); //