imageStyles [TreeViewImageSet.BulletedList3] = new ImageStyle (null, null, null, "star_full", "star_empty", "star_full");
imageStyles [TreeViewImageSet.BulletedList4] = new ImageStyle (null, null, null, "star_full", "star_empty", "dots");
imageStyles [TreeViewImageSet.Contacts] = new ImageStyle ("TreeView_plus", "TreeView_minus", "contact", null, null, null);
- imageStyles [TreeViewImageSet.Events] = new ImageStyle ("TreeView_plus", "TreeView_minus", "TreeView_noexpand", null, "warning", null);
- imageStyles [TreeViewImageSet.Inbox] = new ImageStyle ("TreeView_plus", "TreeView_minus", "TreeView_noexpand", "inbox", "inbox", "inbox");
+ imageStyles [TreeViewImageSet.Events] = new ImageStyle (null, null, null, "warning", "warning", "warning");
+ imageStyles [TreeViewImageSet.Inbox] = new ImageStyle (null, null, null, "inbox", "inbox", "inbox");
imageStyles [TreeViewImageSet.Msdn] = new ImageStyle ("box_plus", "box_minus", "box_noexpand", null, null, null);
- imageStyles [TreeViewImageSet.Simple] = new ImageStyle ("TreeView_plus", "TreeView_minus", "box_full", null, null, null);
- imageStyles [TreeViewImageSet.Simple2] = new ImageStyle ("TreeView_plus", "TreeView_minus", "box_empty", null, null, null);
+ imageStyles [TreeViewImageSet.Simple] = new ImageStyle (null, null, "box_full", null, null, null);
+ imageStyles [TreeViewImageSet.Simple2] = new ImageStyle (null, null, "box_empty", null, null, null);
// TODO
imageStyles [TreeViewImageSet.News] = new ImageStyle ("TreeView_plus", "TreeView_minus", "TreeView_noexpand", null, null, null);
void FindCheckedNodes (TreeNodeCollection nodeList, TreeNodeCollection result)
{
foreach (TreeNode node in nodeList) {
- if (node.Checked) result.Add (node);
+ if (node.Checked) result.Add (node, false);
FindCheckedNodes (node.ChildNodes, result);
}
}
if (selectedNode != null)
selectedNode.SelectedFlag = false;
selectedNode = node;
- selectedNode.SelectedFlag = true;
if (!loading)
OnSelectedNodeChanged (new TreeNodeEventArgs (selectedNode));
}
{
if (node.Expanded.HasValue && node.Expanded.Value)
OnTreeNodeExpanded (new TreeNodeEventArgs (node));
- else
+ else if (node.Expanded.HasValue && node.IsParentNode)
OnTreeNodeCollapsed (new TreeNodeEventArgs (node));
}
if (leafNodeStyle != null) {
leafNodeStyle.TrackViewState();
}
- if (levelStyles != null) {
+ if (levelStyles != null && levelStyles.Count > 0) {
((IStateManager)levelStyles).TrackViewState();
}
if (nodeStyle != null) {
FillBoundChildrenRecursive (e, Nodes);
}
- private void FillBoundChildrenRecursive (IHierarchicalEnumerable hEnumerable, TreeNodeCollection nodeCollection) {
+ private void FillBoundChildrenRecursive (IHierarchicalEnumerable hEnumerable, TreeNodeCollection nodeCollection)
+ {\r
+ if (hEnumerable == null)\r
+ return;\r
foreach (object obj in hEnumerable) {
IHierarchyData hdata = hEnumerable.GetHierarchyData (obj);
TreeNode child = new TreeNode ();
res = true;
}
- if (ShowCheckBoxes != TreeNodeTypes.None) {
- UnsetCheckStates (Nodes, postCollection);
- SetCheckStates (postCollection);
- res = true;
- }
+ UnsetCheckStates (Nodes, postCollection);
+ SetCheckStates (postCollection);
if (EnableClientScript) {
string states = postCollection [ClientID + "_ExpandStates"];
string ctree = ClientID + "_data";
string script = string.Format ("var {0} = new Object ();\n", ctree);
+ script += string.Format ("{0}.uid = {1};\n", ctree, ClientScriptManager.GetScriptLiteral (UniqueID));
script += string.Format ("{0}.showImage = {1};\n", ctree, ClientScriptManager.GetScriptLiteral (ShowExpandCollapse));
if (ShowExpandCollapse) {
}
if (Page != null) {
+ script += string.Format ("{0}.form = {1};\n", ctree, Page.theForm);
script += string.Format ("{0}.populateFromClient = {1};\n", ctree, ClientScriptManager.GetScriptLiteral (PopulateNodesFromClient));
script += string.Format ("{0}.expandAlt = {1};\n", ctree, ClientScriptManager.GetScriptLiteral (GetNodeImageToolTip (true, null)));
script += string.Format ("{0}.collapseAlt = {1};\n", ctree, ClientScriptManager.GetScriptLiteral (GetNodeImageToolTip (false, null)));
if (EnableClientScript) {
Page.ClientScript.RegisterHiddenField (ClientID + "_ExpandStates", GetExpandStates ());
-
+
// Make sure the basic script infrastructure is rendered
- Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
- Page.ClientScript.GetPostBackClientHyperlink (this, "");
+ Page.ClientScript.RegisterWebFormClientScript ();
}
if (EnableClientScript && PopulateNodesFromClient) {
RegisterStyle (LeafNodeStyle, LeafNodeLinkStyle);
- if (levelStyles != null) {
- levelLinkStyles = new List<Style> ();
+ if (levelStyles != null && levelStyles.Count > 0) {
+ levelLinkStyles = new List<Style> (levelStyles.Count);
foreach (Style style in levelStyles) {
Style linkStyle = new Style ();
levelLinkStyles.Add (linkStyle);
void RegisterStyle (Style baseStyle) {
if (Page.Header == null)
return;
- string className = IncrementStyleClassName ();
+ string className = IncrementStyleClassName ().Trim ('_');
baseStyle.SetRegisteredCssClass (className);
Page.Header.StyleSheet.CreateStyleRule (baseStyle, this, "." + className);
}
// Node icon
- string imageUrl = node.ImageUrl;
- if (imageUrl == "" && imageStyle != null) {
+ string imageUrl = node.ImageUrl.Length > 0 ? ResolveClientUrl (node.ImageUrl) : null;
+ if (String.IsNullOrEmpty (imageUrl) && imageStyle != null) {
if (imageStyle.RootIcon != null && node.IsRootNode)
imageUrl = GetNodeIconUrl (imageStyle.RootIcon);
else if (imageStyle.ParentIcon != null && node.IsParentNode)
imageUrl = GetNodeIconUrl (imageStyle.LeafIcon);
}
- if (imageUrl != "") {
+ if (level < LevelStyles.Count && LevelStyles [level].ImageUrl != null)
+ imageUrl = ResolveClientUrl (LevelStyles [level].ImageUrl);
+
+ if (!String.IsNullOrEmpty (imageUrl)) {
writer.RenderBeginTag (HtmlTextWriterTag.Td); // TD
BeginNodeTag (writer, node, clientExpand);
writer.AddAttribute ("src", imageUrl);
// Checkbox
- bool showChecks;
- if (node.ShowCheckBox.HasValue)
- showChecks = node.ShowCheckBox.Value;
- else
- showChecks = (ShowCheckBoxes == TreeNodeTypes.All) ||
- ((ShowCheckBoxes & TreeNodeTypes.Leaf) > 0 && node.IsLeafNode) ||
- ((ShowCheckBoxes & TreeNodeTypes.Parent) > 0 && node.IsParentNode && node.Parent != null) ||
- ((ShowCheckBoxes & TreeNodeTypes.Root) > 0 && node.Parent == null && node.ChildNodes.Count > 0);
-
- if (showChecks) {
+ if (node.ShowCheckBoxInternal) {
writer.AddAttribute ("name", ClientID + "_cs_" + node.Path);
writer.AddAttribute ("type", "checkbox");
writer.AddAttribute ("title", node.Text);
if (hasChildNodes)
{
+ AddChildrenPadding (writer, node);
if (level >= levelLines.Count) {
if (hasNext) levelLines.Add (this);
else levelLines.Add (null);
for (int n=0; n<num; n++)
RenderNode (writer, node.ChildNodes [n], level + 1, levelLines, true, n<num-1);
}
+ AddChildrenPadding (writer, node);
}
}
+ private void AddChildrenPadding (HtmlTextWriter writer, TreeNode node)
+ {
+ if (nodeStyle == null)
+ return;
+ Unit cnp = nodeStyle.ChildNodesPadding;
+ double value;
+
+ if (cnp.IsEmpty || (value = cnp.Value) == 0)
+ return;
+
+ if (cnp.Type != UnitType.Pixel)
+ return;
+
+ writer.RenderBeginTag (HtmlTextWriterTag.Table);
+ writer.AddAttribute ("height", ((int)value).ToString ());
+ writer.RenderBeginTag (HtmlTextWriterTag.Tr);
+ writer.RenderBeginTag (HtmlTextWriterTag.Td);
+ writer.RenderEndTag (); // td
+ writer.RenderEndTag (); // tr
+ writer.RenderEndTag (); // table
+ }
+
private void RenderMenuItemSpacing (HtmlTextWriter writer, Unit itemSpacing) {
writer.AddStyleAttribute ("height", itemSpacing.ToString ());
writer.RenderBeginTag (HtmlTextWriterTag.Tr);
writer.AddAttribute ("title", node.ToolTip);
if (node.NavigateUrl != "") {
- writer.AddAttribute ("href", node.NavigateUrl);
- if (node.Target.Length > 0)
- writer.AddAttribute ("target", node.Target);
- else if (Target.Length > 0)
- writer.AddAttribute ("target", Target);
+ string target = node.Target.Length > 0 ? node.Target : Target;
+#if TARGET_J2EE
+ string navUrl = ResolveClientUrl (node.NavigateUrl, String.Compare (target, "_blank", StringComparison.InvariantCultureIgnoreCase) != 0);
+#else
+ string navUrl = ResolveClientUrl (node.NavigateUrl);
+#endif
+ writer.AddAttribute ("href", navUrl);
+ if (target.Length > 0)
+ writer.AddAttribute ("target", target);
writer.RenderBeginTag (HtmlTextWriterTag.A);
}
else if (node.SelectAction != TreeNodeSelectAction.None) {
string GetNodeImageUrl (string shape, ImageStyle imageStyle)
{
if (ShowLines) {
- if (LineImagesFolder != "")
- return LineImagesFolder + "/" + shape + ".gif";
+ if (!String.IsNullOrEmpty (LineImagesFolder))
+ return ResolveClientUrl (LineImagesFolder + "/" + shape + ".gif");
} else {
- if (shape == "plus") {
- if (ExpandImageUrl != "")
- return ExpandImageUrl;
- if (imageStyle != null && imageStyle.Expand != null)
- return imageStyle.Expand;
- }
- else if (shape == "minus") {
- if (CollapseImageUrl != "")
- return CollapseImageUrl;
- if (imageStyle != null && imageStyle.Collapse != null)
- return imageStyle.Collapse;
+ if (imageStyle != null) {
+ if (shape == "plus") {
+ if (!String.IsNullOrEmpty (imageStyle.Expand))
+ return GetNodeIconUrl (imageStyle.Expand);
+ }
+ else if (shape == "minus") {
+ if (!String.IsNullOrEmpty (imageStyle.Collapse))
+ return GetNodeIconUrl (imageStyle.Collapse);
+ }
+ else if (shape == "noexpand") {
+ if (!String.IsNullOrEmpty (imageStyle.NoExpand))
+ return GetNodeIconUrl (imageStyle.NoExpand);
+ }
}
- else if (shape == "noexpand") {
- if (NoExpandImageUrl != "")
- return NoExpandImageUrl;
- if (imageStyle != null && imageStyle.NoExpand != null)
- return imageStyle.NoExpand;
+ else {
+ if (shape == "plus") {
+ if (!String.IsNullOrEmpty (ExpandImageUrl))
+ return ResolveClientUrl (ExpandImageUrl);
+ }
+ else if (shape == "minus") {
+ if (!String.IsNullOrEmpty (CollapseImageUrl))
+ return ResolveClientUrl (CollapseImageUrl);
+ }
+ else if (shape == "noexpand") {
+ if (!String.IsNullOrEmpty (NoExpandImageUrl))
+ return ResolveClientUrl (NoExpandImageUrl);
+ }
}
+ if (!String.IsNullOrEmpty (LineImagesFolder))
+ return ResolveClientUrl (LineImagesFolder + "/" + shape + ".gif");
}
return AssemblyResourceLoader.GetResourceUrl (typeof(TreeView), "TreeView_" + shape + ".gif");
}
string GetClientEvent (TreeNode node, string ev)
{
- return Page.ClientScript.GetPostBackClientHyperlink (this, ev + "|" + node.Path);
+ return Page.ClientScript.GetPostBackClientHyperlink (this, ev + "|" + node.Path, true);
}
string GetClientExpandEvent (TreeNode node)
void UnsetCheckStates (TreeNodeCollection col, NameValueCollection states)
{
- foreach (TreeNode node in col) {
- if (node.Checked) {
- string val = states [ClientID + "_cs_" + node.Path];
- if (val != "on") node.Checked = false;
+ foreach (TreeNode node in col) {\r
+ if (node.ShowCheckBoxInternal && node.Checked) {
+ if (states == null || states [ClientID + "_cs_" + node.Path] == null)\r
+ node.Checked = false;
}
if (node.HasChildData)
UnsetCheckStates (node.ChildNodes, states);
}
void SetCheckStates (NameValueCollection states)
- {
+ {\r
+ if (states == null)\r
+ return;
+
string keyPrefix = ClientID + "_cs_";
foreach (string key in states) {
- if (key.StartsWith (keyPrefix)) {
+ if (key.StartsWith (keyPrefix, StringComparison.Ordinal)) {
string id = key.Substring (keyPrefix.Length);
TreeNode node = FindNodeByPos (id);
- if (node != null)
- node.Checked = (Context.Request.Form [key] == "on");
+ if (node != null && !node.Checked)\r
+ node.Checked = true;
}
}
}