/// <summary> /// Draws the data of a tree node at the specified location.</summary> /// <param name="node">The tree control's node whose data is to be drawn</param> /// <param name="g">The current GDI+ graphics object</param> /// <param name="x">The x-coordinate of the upper-left corner of the node label</param> /// <param name="y">The y-coordinate of the upper-left corner of the node label</param> public override void DrawData(TreeControl.Node node, Graphics g, int x, int y) { var treeListControl = node.TreeControl as TreeListControl; ItemInfo info = new WinFormsItemInfo(); m_itemView.GetInfo(node.Tag, info); if (info.Properties.Length ==0) return; Region oldClip = g.Clip; UpdateColumnWidths(node, info, g); int xOffset = treeListControl.TreeWidth; for (int i = 0; i < info.Properties.Length; ++i) { var dataEditor = info.Properties[i] as DataEditor; if (dataEditor != null) // show object data details in columns { if (TrackingEditor != null && (TrackingEditor.Owner == node.Tag) && (TrackingEditor.Name == dataEditor.Name)) dataEditor = TrackingEditor; var clip = new Rectangle(xOffset, y, treeListControl.Columns[i].ActualWidth, treeListControl.GetRowHeight(node)); if (i == info.Properties.Length-1) // extends last column clip.Width = node.TreeControl.ActualClientSize.Width - xOffset; g.SetClip(clip); dataEditor.PaintValue(g, clip); } xOffset += treeListControl.Columns[i].ActualWidth; } g.Clip = oldClip; }
/// <summary> /// Updates an item to the current state of its corresponding object</summary> private void UpdateItem(ListViewItem item) { ItemInfo info = new WinFormsItemInfo(m_control.SmallImageList); m_itemView.GetInfo(item.Tag, info); string label = info.Label; item.SubItems.Clear(); if (info.Properties != null) { int count = Math.Min(m_columnNames.Length, info.Properties.Length); for (int i = 0; i < count; i++) { object value = info.Properties[i]; ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(item, GetObjectString(value)); subItem.Tag = value; item.SubItems.Add(subItem); } } item.Text = label; item.ImageIndex = info.ImageIndex; item.Checked = info.Checked; if (item.Font.Style != info.FontStyle) { item.Font = new Font(item.Font, info.FontStyle); } }
/// <summary> /// Gets the children of the given parent object</summary> /// <param name="parent">Parent object</param> /// <returns>Enumeration of children of the parent object</returns> public IEnumerable <object> GetChildren(object parent) { if (parent == this) { foreach (string categoryName in m_categories.Keys) { yield return(categoryName); } } else { string categoryName = parent as string; if (categoryName != null) { List <object> category; if (m_categories.TryGetValue(categoryName, out category)) { foreach (object item in category) { ItemInfo info = new WinFormsItemInfo(); GetInfo(item, info); if (m_searchInput.IsNullOrEmpty() || m_searchInput.Matches(info.Label)) { yield return(item); } } } } } }
/// <summary> /// Callback to determine if an item in the tree is filtered in (return true) or out</summary> /// <param name="item">Item tested for filtering</param> /// <returns>True if filtered in, false if filtered out</returns> public bool DefaultFilter(object item) { IItemView itemView = TreeView.As <IItemView>(); if (itemView != null) { ItemInfo info = new WinFormsItemInfo(); itemView.GetInfo(item, info); return(SearchInputUI.IsNullOrEmpty() || SearchInputUI.Matches(info.Label)); } return(true); // Don't filter anything if the context doesn't implement IItemView }
/// <summary> /// Callback to determine if an item in the tree is filtered in (return true) or out</summary> /// <param name="item">Item tested for filtering</param> /// <returns>True if filtered in, false if filtered out</returns> public bool DefaultFilter(object item) { bool result = true; IItemView itemView = TreeView.As<IItemView>(); if(!SearchInputUI.IsNullOrEmpty()) { ItemInfo info = new WinFormsItemInfo(); itemView.GetInfo(item, info); result = info.Label != null && SearchInputUI.Matches(info.Label); } return result; }
/// <summary> /// Callback to determine if an item in the tree is filtered in (return true) or out</summary> /// <param name="item">Item tested for filtering</param> /// <returns>True if filtered in, false if filtered out</returns> public bool DefaultFilter(object item) { bool result = true; IItemView itemView = TreeView.As <IItemView>(); if (!SearchInputUI.IsNullOrEmpty()) { ItemInfo info = new WinFormsItemInfo(); itemView.GetInfo(item, info); result = info.Label != null && SearchInputUI.Matches(info.Label); } return(result); }
/// <summary> /// Callback to determine if an item in the tree is filtered in (return true) or out</summary> /// <param name="item">Item tested for filtering</param> /// <returns>True if filtered in, false if filtered out</returns> public bool DefaultFilter(object item) { bool result = true; IItemView itemView = TreeView.As <IItemView>(); if (m_TagPanel.TagList.Count != 0) { ItemInfo info = new WinFormsItemInfo(); itemView.GetInfo(item, info); result = info.Label != null && m_TagPanel.Matches(info.Label); } return(result); }
private void searchInput_Updated(object sender, EventArgs e) { if (TreeControl.Root == null) { return; } if (m_searchInput.IsNullOrEmpty()) { if (m_searching) { // get the tree control to force-reload the tree data m_paletteTreeAdapter.RefreshControl(); RestoreExpansion(); } m_searching = false; return; } else { if (!m_searching) { RememberExpansion(); } m_searching = true; } m_paletteTreeAdapter.RefreshControl(); // expand categories that have matched children foreach (object category in m_paletteTreeAdapter.GetChildren(m_paletteTreeAdapter)) { foreach (object typeName in m_paletteTreeAdapter.GetChildren(category)) { ItemInfo info = new WinFormsItemInfo(); m_paletteTreeAdapter.GetInfo(typeName, info); if (m_searchInput.Matches(info.Label)) { TreeControlAdapter.Expand(category); break; } } } RestoreExpansion(); }
/// <summary> /// Gets the object tags of the current selection</summary> private List <object> GetSelectedObjects() { List <object> result = new List <object>(); foreach (ListViewItem listViewItem in m_control.SelectedItems) { if (listViewItem.Tag != null) { object item = listViewItem.Tag; ItemInfo info = new WinFormsItemInfo(m_control.SmallImageList); m_itemView.GetInfo(item, info); if (info.AllowSelect) { result.Add(item); } } } return(result); }
private void UpdateNode(TreeControl.Node node) { ItemInfo info = new WinFormsItemInfo(m_treeControl.ImageList, m_treeControl.StateImageList); info.IsExpandedInView = node.Expanded; if (m_itemView != null && node.Tag != null) { m_itemView.GetInfo(node.Tag, info); } node.Label = info.Label; node.FontStyle = info.FontStyle; node.ImageIndex = info.ImageIndex; node.StateImageIndex = info.StateImageIndex; node.IsLeaf = info.IsLeaf; node.HasCheck = info.HasCheck; node.CheckBoxEnabled = info.CheckBoxEnabled; node.CheckState = info.GetCheckState(); node.AllowSelect = info.AllowSelect; node.AllowLabelEdit = info.AllowLabelEdit; node.HoverText = info.HoverText; if (m_selectionContext != null && !m_synchronizingSelection) { try { m_synchronizingSelection = true; node.Selected = m_selectionContext.SelectionContains(MakePath(node)); } finally { m_synchronizingSelection = false; } } }
private static ItemInfo GetItemInfo(object item, IItemView itemView, ImageList imageList, ImageList stateImageList) { var info = new WinFormsItemInfo(imageList, stateImageList); if (itemView == null) { info.Label = GetObjectString(item); info.Properties = new object[0]; info.ImageIndex = TreeListView.InvalidImageIndex; info.StateImageIndex = TreeListView.InvalidImageIndex; info.CheckState = CheckState.Unchecked; info.FontStyle = FontStyle.Regular; info.IsLeaf = true; info.IsExpandedInView = false; info.HoverText = string.Empty; } else { itemView.GetInfo(item, info); } return(info); }
/// <summary> /// Updates an item to the current state of its corresponding object</summary> private void UpdateItem(ListViewItem item) { ItemInfo info = new WinFormsItemInfo(m_control.SmallImageList); m_itemView.GetInfo(item.Tag, info); string label = info.Label; item.SubItems.Clear(); if (info.Properties != null) { int count = Math.Min(m_columnNames.Length, info.Properties.Length); for (int i = 0; i < count; i++) { object value = info.Properties[i]; ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(item, GetObjectString(value)); subItem.Tag = value; item.SubItems.Add(subItem); } } item.Text = label; item.ImageIndex = info.ImageIndex; item.Checked = info.Checked; if (item.Font.Style != info.FontStyle) item.Font = new Font(item.Font, info.FontStyle); }
private void searchInput_Updated(object sender, EventArgs e) { if (TreeControl.Root == null) return; if (m_searchInput.IsNullOrEmpty()) { if (m_searching) { // get the tree control to force-reload the tree data TreeAdapter.RefreshControl(); RestoreExpansion(); } m_searching = false; return; } else { if (!m_searching) RememberExpansion(); m_searching = true; } TreeAdapter.RefreshControl(); // expand categories that have matched children foreach (object category in TreeAdapter.GetChildren(TreeAdapter)) { foreach (object typeName in TreeAdapter.GetChildren(category)) { ItemInfo info = new WinFormsItemInfo(); TreeAdapter.GetInfo(typeName, info); if (m_searchInput.Matches(info.Label)) { TreeControlAdapter.Expand(category); break; } } } RestoreExpansion(); }
/// <summary> /// Get the data editor hit by point p; also set edit mode if the editor supports multiple controls.</summary> /// <param name="node">The node</param> /// <param name="p">The point</param> /// <returns>Data editor hit by point</returns> internal DataEditor GetDataEditor(TreeControl.Node node, Point p) { var treeListControl = node.TreeControl as TreeListControl; ItemInfo info = new WinFormsItemInfo(); treeListControl.TreeListItemRenderer.ItemView.GetInfo(node.Tag, info); if (info.Properties.Length != treeListControl.Columns.Count) return null; int left = treeListControl.TreeWidth; for (int i = 0; i < treeListControl.Columns.Count; ++i) { var column = treeListControl.Columns[i]; if (p.X >= left && p.X <= left + column.ActualWidth) { var dataEditor = info.Properties[i] as DataEditor; if (dataEditor != null) { foreach (NodeLayoutInfo nodeLayout in NodeLayout) { if (nodeLayout.Node == node) { dataEditor.TextBox = m_editTextBox; dataEditor.Bounds = GetEditArea(nodeLayout, dataEditor); dataEditor.SetEditingMode(p); break; } } } return dataEditor; } left += column.ActualWidth; } return null; }
/// <summary> /// Gets the children of the given parent object</summary> /// <param name="parent">Parent object</param> /// <returns>Enumeration of children of the parent object</returns> public IEnumerable<object> GetChildren(object parent) { if (parent == this) { foreach (string categoryName in m_categories.Keys) yield return categoryName; } else { string categoryName = parent as string; if (categoryName != null) { List<object> category; if (m_categories.TryGetValue(categoryName, out category)) { foreach (object item in category) { ItemInfo info = new WinFormsItemInfo(); GetInfo(item, info); if (m_searchInput.IsNullOrEmpty() || m_searchInput.Matches(info.Label)) yield return item; } } } } }
/// <summary> /// Gets the object tags of the current selection</summary> private List<object> GetSelectedObjects() { List<object> result = new List<object>(); foreach (ListViewItem listViewItem in m_control.SelectedItems) { if (listViewItem.Tag != null) { object item = listViewItem.Tag; ItemInfo info = new WinFormsItemInfo(m_control.SmallImageList); m_itemView.GetInfo(item, info); if (info.AllowSelect) result.Add(item); } } return result; }
/// <summary> /// Callback to determine if an item in the tree is filtered in (return true) or out</summary> /// <param name="item">Item tested for filtering</param> /// <returns>True if filtered in, false if filtered out</returns> public bool DefaultFilter(object item) { IItemView itemView = TreeView.As<IItemView>(); if (itemView != null) { ItemInfo info = new WinFormsItemInfo(); itemView.GetInfo(item, info); return SearchInputUI.IsNullOrEmpty() || SearchInputUI.Matches(info.Label); } return true; // Don't filter anything if the context doesn't implement IItemView }
private static ItemInfo GetItemInfo(object item, IItemView itemView, ImageList imageList, ImageList stateImageList) { var info = new WinFormsItemInfo(imageList, stateImageList); if (itemView == null) { info.Label = GetObjectString(item); info.Properties = new object[0]; info.ImageIndex = TreeListView.InvalidImageIndex; info.StateImageIndex = TreeListView.InvalidImageIndex; info.CheckState = CheckState.Unchecked; info.FontStyle = FontStyle.Regular; info.IsLeaf = true; info.IsExpandedInView = false; info.HoverText = string.Empty; } else { itemView.GetInfo(item, info); } return info; }