public GrtListNode(string caption, NodeIdWrapper nodeId, GrtTreeNode parent, GrtListModel model) : base(caption) { NodeId = nodeId; Parent = parent; Model = model; }
void rolesTreeView_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.None; if ((rolesTreeView.DropPosition.Position == NodePosition.Inside) && (e.Data.GetDataPresent(typeof(TreeNodeAdv[])) == true)) { e.Effect = DragDropEffects.Move; } else if (rolesTreeView.DropPosition.Node != null) { NodeIdWrapper nid = roleTreeBE.get_parent(((GrtTreeNode)rolesTreeView.DropPosition.Node.Tag).NodeId); bool is_root = !nid.is_valid(); if (is_root) { bool dragging_non_root = false; TreeNodeAdv[] nodes = (TreeNodeAdv[])e.Data.GetData(typeof(TreeNodeAdv[])); if (nodes != null) { foreach (TreeNodeAdv node in nodes) { NodeIdWrapper next_id = ((GrtTreeNode)node.Tag).NodeId; dragging_non_root = roleTreeBE.get_parent(next_id).is_valid(); if (dragging_non_root) { e.Effect = DragDropEffects.Move; break; } } } } } }
/// <summary> /// Returns a node list of all child nodes of a given parent node /// </summary> /// <param name="treePath">The path of the parent node</param> /// <returns>The list of child nodes for the given parent path node</returns> public override System.Collections.IEnumerable GetChildren(TreePath treePath) { NodeIdWrapper parentNodeId; bool settingTopNode = false; if (treePath.IsEmpty()) { settingTopNode = true; parentNodeId = model.get_root(); } else { GrtTreeNode parent = treePath.LastNode as GrtTreeNode; if (parent != null) { parentNodeId = parent.NodeId; } else { parentNodeId = null; } } if (parentNodeId != null) { // The backend has child nodes on a node not before it was expanded. int childCount = model.count_children(parentNodeId); if (childCount == 0) { // But expand only if we don't have any children yet. Otherwise // get many unnecessary refresh calls. model.expand_node(parentNodeId); childCount = model.count_children(parentNodeId); } for (int i = 0; i < childCount; i++) { NodeIdWrapper nodeId = model.get_child(parentNodeId, i); GrtTreeNode node; string caption; model.get_field(nodeId, columns[0].index, out caption); node = new GrtTreeNode(caption, nodeId, null, this); if (settingTopNode) { topNode = node; } //items.Add(node); yield return(node); } } //return items; }
/// <summary> /// Returns a node list of all child nodes of a given parent node /// </summary> /// <param name="treePath">The path of the parent node</param> /// <returns>The list of child nodes for the given parent path node</returns> public override System.Collections.IEnumerable GetChildren(TreePath treePath) { List <GrtTreeNode> items = null; NodeIdWrapper parentNodeId; bool settingTopNode = false; if (treePath.IsEmpty()) { settingTopNode = true; parentNodeId = model.get_root(); } else { GrtTreeNode parent = treePath.LastNode as GrtTreeNode; if (parent != null) { parentNodeId = parent.NodeId; } else { parentNodeId = null; } } if (parentNodeId != null) { int childCount = model.count_children(parentNodeId); items = new List <GrtTreeNode>(); for (int i = 0; i < childCount; i++) { NodeIdWrapper nodeId = model.get_child(parentNodeId, i); GrtTreeNode node; string caption; model.get_field(nodeId, columns[0].index, out caption); if (disabledNames.Contains(caption)) { continue; } node = new GrtTreeNode(caption, nodeId, null, this); if (settingTopNode) { topNode = node; } items.Add(node); } } return(items); }
private void roleObjectsTreeView_SelectionChanged(object sender, EventArgs e) { if (roleObjectsTreeView.SelectedNode != null) { NodeIdWrapper nodeId = new NodeIdWrapper(roleObjectsTreeView.SelectedNode.Index); roleObjectListWrapper.set_selected_node(nodeId); RefreshPrivilegesList(); } else { roleObjectListWrapper.set_selected_node(new NodeIdWrapper()); RefreshPrivilegesList(); } }
/// <summary> /// Converts the current placeholder (the last line in the columns grid) into a real column. /// </summary> void activateColumnPlaceholder(NodeIdWrapper node) { // The following code is a bit involved, but it makes the table grid // properly display the default PK column name and all its other settings. // Tell the backend we are editing now the placeholder row. grtList.set_field(node, (int)MySQLTableColumnsListWrapper.MySQLColumnListColumns.Name, 1); // Get the default value for the name field... String value; grtList.get_field(node, (int)MySQLTableColumnsListWrapper.MySQLColumnListColumns.Name, out value); // ... and set it in the backend. This way the backend will know next time // we set a value that we need a new place holder. grtList.set_field(node, (int)MySQLTableColumnsListWrapper.MySQLColumnListColumns.Name, value); }
void rolesTreeView_DragDrop(object sender, DragEventArgs e) { TreeNodeAdv[] nodes = (TreeNodeAdv[])e.Data.GetData(typeof(TreeNodeAdv[])); TreeNodeAdv dropNode = rolesTreeView.DropPosition.Node; if (dropNode == null) { return; } NodeIdWrapper dropNodeId = ((GrtTreeNode)dropNode.Tag).NodeId; if (rolesTreeView.DropPosition.Position == NodePosition.Inside) { foreach (TreeNodeAdv node in nodes) { if (node.Equals(dropNode)) { continue; } NodeIdWrapper next_id = ((GrtTreeNode)node.Tag).NodeId; roleTreeBE.append_child(dropNodeId, next_id); } roleTreeBE.refresh(); rolesTreeView.Model = null; rolesTreeView.Model = roleTreeModel; //rolesTreeView.DropPosition.Node.IsExpanded = true; } else { foreach (TreeNodeAdv node in nodes) { NodeIdWrapper next_id = ((GrtTreeNode)(node.Tag)).NodeId; roleTreeBE.move_to_top_level(next_id); } roleTreeBE.refresh(); rolesTreeView.Model = null; rolesTreeView.Model = roleTreeModel; } }
/// <summary> /// Returns a node list of all child nodes of a given parent node /// </summary> /// <param name="treePath">The path of the parent node</param> /// <returns>The list of child nodes for the given parent path node</returns> public override System.Collections.IEnumerable GetChildren(TreePath treePath) { //List<GrtListNode> items = new List<GrtListNode>(); // Get count but add the additional row for new columns int count = grtList.count(); for (int i = 0; i < count; i++) { NodeIdWrapper nodeId = grtList.get_node(i); GrtListNode node; string caption; grtList.get_field(nodeId, columns[0].index, out caption); node = new GrtListNode(caption, nodeId, null, this); yield return(node); } }
/// <summary> /// Returns a node list of all child nodes of a given parent node /// </summary> /// <param name="treePath">The path of the parent node</param> /// <returns>The list of child nodes for the given parent path node</returns> public override System.Collections.IEnumerable GetChildren(TreePath treePath) { List <GrtListNode> items = new List <GrtListNode>(); int count = grtList.count(); for (int i = 0; i < count; i++) { NodeIdWrapper nodeId = grtList.get_node(i); GrtListNode node; string caption; grtList.get_field(nodeId, 0, out caption); node = new GrtListNode(caption, nodeId, null, this); items.Add(node); } return(items); }
/// <summary> /// Updates all fields of the given node. /// </summary> private void UpdateListViewNode(NodeIdWrapper nodeId, ListView listView) { // Find the listview item that corresponds to the given node id and update it. // Don't wrap this with BeginUpdate/EndUpdate. That will produce more flicker than // just updating the item. String objectId = wbOverview.get_node_unique_id(nodeId); foreach (ListViewItem item in listView.Items) { String currentObjectId = (item.Tag as Identifier).objectId; if (currentObjectId != null && currentObjectId == objectId) { string caption; wbOverview.get_field(nodeId, (int)Overview.Columns.Label, out caption); item.Text = caption; item.ToolTipText = caption; // Note: the first sub item is the same as the main item. int offset = -1; foreach (ListViewItem.ListViewSubItem subItem in item.SubItems) { if (offset > -1) { String detailText; wbOverview.get_field(nodeId, (int)Overview.Columns.FirstDetailField + offset, out detailText); subItem.Text = detailText.Replace(Environment.NewLine, " / "); } offset++; } break; } } }
public Identifier(NodeIdWrapper id) { this.id = id; }
private void RefreshGroupTabs(NodeIdWrapper node) { if (panelsByNode.ContainsKey(node.toString())) { CollapsingPanel panel = panelsByNode[node.toString()]; panel.SuspendLayout(); panel.Controls.Clear(); PopulateSections(panel, currentOverviewDisplayMode, false); Refresh(); panel.ResumeLayout(); } }
private void RefreshItemList(NodeIdWrapper node, Overview.NodeType nodeType) { if (listsByNode.ContainsKey(node.toString())) { ListView list = listsByNode[node.toString()]; if (nodeType == Overview.NodeType.Section) { int childCount = wbOverview.count_children(node) - 1; String info = "(" + childCount + ((childCount == 1) ? " item" : " items") + ")"; SetInfoLabelForList(list, info); } if (list.View == View.Details) SaveColumnStates(list); PopulateListView(node, list); if (list.View == View.Details) RestoreColumnStates(list); } }
private void FillPanelContent(NodeIdWrapper panelNodeId, Overview.DisplayMode displayMode, CollapsingPanel overviewPanel) { // Check the node type of the child items int itemNodeType; wbOverview.get_field(panelNodeId, (int)Overview.Columns.ChildNodeType, out itemNodeType); switch ((Overview.NodeType)itemNodeType) { case Overview.NodeType.Group: { // If the child items are of type Group, add them as tabs. EnableTabViewForPanel(displayMode, overviewPanel); // Fill child items if (wbOverview.count_children(panelNodeId) > 0) FillPanelContent(wbOverview.get_child(panelNodeId, 0), currentOverviewDisplayMode, overviewPanel); } break; case Overview.NodeType.Section: // If they are of item type Section populate the list view with sections and items. PopulateSections(overviewPanel, displayMode, true); break; case Overview.NodeType.Item: { // If the child entry is an item thean we don't have any intermediate structure. ListView sectionListview = GetSectionListview(panelNodeId, overviewPanel, false, displayMode, "", ""); cacheListview(panelNodeId.toString(), sectionListview); PopulateListView(panelNodeId, sectionListview); break; } } }
private void storageRadioButton_CheckedChanged(object sender, EventArgs e) { if (columnsTreeView.SelectedNode == null) return; NodeIdWrapper nodeId = new NodeIdWrapper(columnsTreeView.SelectedNode.Index); RadioButton button = sender as RadioButton; if (button.Checked) { columnsListModel.GrtList.set_field(nodeId, (int)MySQLTableColumnsListWrapper.MySQLColumnListColumns.GeneratedStorageType, sender == virtualRadioButton ? "VIRTUAL" : "STORED"); } }
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) { base.OnCellPainting(e); if (e.ColumnIndex < 0 || e.RowIndex < 0) return; NodeIdWrapper NodeIdWrapper = new NodeIdWrapper(e.RowIndex); Bitmap icon = null; Rectangle rect = e.CellBounds; if (e.ColumnIndex == 0) { // Check if we have to draw a busy indicator. int type; Model.get_field(NodeIdWrapper, 0, out type); if ((MessageType) type == MessageType.BusyMsg) { icon = (e.RowIndex % 2 == 1) ? Resources.busy_indicator_lightblue : Resources.busy_indicator_white; ImageAnimator.UpdateFrames(); rect.X += (rect.Width - icon.Width) / 2; rect.Y += (rect.Height - icon.Height) / 2; rect.Size = icon.Size; } } if (icon == null) { int iconId = Model.get_field_icon(NodeIdWrapper, e.ColumnIndex, IconSize.Icon16); icon = IconManagerWrapper.get_instance().get_icon(iconId); if (icon != null) { rect.Size = icon.Size; // Horizontal alignment. switch (e.CellStyle.Alignment) { case DataGridViewContentAlignment.TopRight: case DataGridViewContentAlignment.MiddleRight: case DataGridViewContentAlignment.BottomRight: rect.X += e.CellBounds.Width - rect.Width; rect.X -= 1; // cell border width (required only for right alignment) break; case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.BottomCenter: rect.X += (e.CellBounds.Width - rect.Width) / 2; break; } // Vertical alignment. switch (e.CellStyle.Alignment) { case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.MiddleRight: rect.Y += (e.CellBounds.Height - rect.Height) / 2; break; case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.BottomRight: rect.Y += e.CellBounds.Height - rect.Height; break; } } } if (icon != null) { e.PaintBackground(e.CellBounds, true); e.Graphics.DrawImageUnscaledAndClipped(icon, rect); e.Handled = true; } }
public void SearchAndFocusNode(String text) { if ((lastSearchText == null) || !text.StartsWith(lastSearchText)) lastFoundNode = null; lastSearchText = text; lastFoundNode = wbOverview.search_child_item_node_matching(null, lastFoundNode, text); if (lastFoundNode != null) FocusNode(lastFoundNode); }
private void FocusNode(NodeIdWrapper node) { NodeIdWrapper parent = wbOverview.get_parent(node); int index = node.end(); if (listsByNode.ContainsKey(parent.toString())) { ListView list = listsByNode[parent.toString()]; list.Focus(); list.SelectedIndices.Clear(); list.Items[index].Selected = true; } }
/// <summary> /// Converts the current placeholder (the last line in the columns grid) into a real column. /// </summary> void activateColumnPlaceholder(NodeIdWrapper node) { // The following code is a bit involved, but it makes the table grid // properly display the default PK column name and all its other settings. // Tell the backend we are editing now the placeholder row. grtList.set_field(node, (int) MySQLTableColumnsListWrapper.MySQLColumnListColumns.Name, 1); // Get the default value for the name field... String value; grtList.get_field(node, (int) MySQLTableColumnsListWrapper.MySQLColumnListColumns.Name, out value); // ... and set it in the backend. This way the backend will know next time // we set a value that we need a new place holder. grtList.set_field(node, (int) MySQLTableColumnsListWrapper.MySQLColumnListColumns.Name, value); }
private void columnFlagsChanged(object sender, EventArgs e) { if (columnsTreeView.SelectedNode == null) return; NodeIdWrapper nodeId = new NodeIdWrapper(columnsTreeView.SelectedNode.Index); CheckBox box = sender as CheckBox; int value = box.Checked ? 1 : 0; MySQLTableColumnsListWrapper.MySQLColumnListColumns columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.Name; switch (box.Tag.ToString()) { case "0": columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsPK; break; case "1": columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsNotNull; break; case "2": columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsUnique; break; case "3": columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsBinary; break; case "4": columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsUnsigned; break; case "5": columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsZerofill; break; case "6": columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsAutoIncrement; break; case "7": columnValue = MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsGenerated; break; } if (columnValue != MySQLTableColumnsListWrapper.MySQLColumnListColumns.Name) { if (!columnsListModel.GrtList.set_field(nodeId, (int)columnValue, value)) { // Value not accepted. Restore previous one. columnsListModel.GrtList.get_field(nodeId, (int)columnValue, out value); box.Checked = value != 0; } } if (columnValue == MySQLTableColumnsListWrapper.MySQLColumnListColumns.IsGenerated) { virtualRadioButton.Enabled = box.Checked; storedRadioButton.Enabled = box.Checked; String stringValue; if (box.Checked) { if (!virtualRadioButton.Checked && !storedRadioButton.Checked) virtualRadioButton.Checked = true; // Default value. defaultLabel.Text = "Expression:"; if (columnsListModel.GrtList.get_field(nodeId, (int)MySQLTableColumnsListWrapper.MySQLColumnListColumns.GeneratedExpression, out stringValue)) { columnDefaultTextBox.Text = stringValue; } else columnDefaultTextBox.Text = ""; } else { defaultLabel.Text = "Default:"; if (columnsListModel.GrtList.get_field(nodeId, (int)MySQLTableColumnsListWrapper.MySQLColumnListColumns.Default, out stringValue)) { columnDefaultTextBox.Text = stringValue; } else columnDefaultTextBox.Text = ""; } } columnsListModel.RefreshModel(); }
private void columnCollationComboBox_SelectedIndexChanged(object sender, EventArgs e) { // set charset/collation if (columnsTreeView.SelectedNode != null) { NodeIdWrapper nodeId = new NodeIdWrapper(columnsTreeView.SelectedNode.Index); if (columnCollationComboBox.SelectedIndex == 0) { columnsListModel.GrtList.set_field(nodeId, (int)MySQLTableColumnsListWrapper.MySQLColumnListColumns.CharsetCollation, ""); } else { columnsListModel.GrtList.set_field(nodeId, (int)MySQLTableColumnsListWrapper.MySQLColumnListColumns.CharsetCollation, columnCollationComboBox.Text); } } }
private void updateColumnTextField(MySQLTableColumnsListWrapper.MySQLColumnListColumns column, TextBox box) { if (columnsTreeView.SelectedNode != null) { // Change an attribute triggers a whole chain of events which ultimately cause the // table editor to refresh completely (including all nodes in the columns tree etc.). // So we have to take measure to restore what was active when the user changed the value. NodeIdWrapper nodeId = new NodeIdWrapper(columnsTreeView.SelectedNode.Index); if (!columnsListModel.GrtList.set_field(nodeId, (int)column, box.Text)) { CustomMessageBox.Show(MessageType.MessageError, "Could not set new value", "The entered value contains errors and cannot be accepted. The previous value is kept instead.", "Close"); string originalText; columnsListModel.GrtList.get_field(nodeId, (int)column, out originalText); box.Text = originalText; } columnsTreeView.SelectedNode = columnsTreeView.Root.Children[nodeId.get_by_index(0)]; } }
public void RefreshNodeChildren(NodeIdWrapper node) { int nodeType; if ((null == node) || !node.is_valid()) { RebuildModelContents(); return; } if (overviewInvalid) return; // find the container and refresh it if (wbOverview.get_field(node, (int)Overview.Columns.NodeType, out nodeType)) { wbOverview.refresh_node(node, true); if (nodeType == (int)Overview.NodeType.Section) { RefreshItemList(node, (Overview.NodeType)nodeType); } else if (nodeType == (int)Overview.NodeType.Group) { CollapsingPanel panel = panelsByNode[node.toString()]; } else if (nodeType == (int)Overview.NodeType.Division) { int childNodeType; wbOverview.get_field(node, (int)Overview.Columns.ChildNodeType, out childNodeType); switch ((Overview.NodeType)childNodeType) { case Overview.NodeType.Group: // Group as children of Division means a tabview RefreshGroupTabs(node); break; case Overview.NodeType.Section: break; case Overview.NodeType.Item: RefreshItemList(node, (Overview.NodeType)nodeType); break; } } } }
void overviewPanel_TabHeaderMouseUp(object sender, MouseEventArgs e) { CollapsingPanel panel = sender as CollapsingPanel; if (panel != null) { if (panel != null && panel.Tag != null) { List<MySQL.Base.MenuItem> items; List<NodeIdWrapper> nodes = new List<NodeIdWrapper>(); NodeIdWrapper itemNodeId= new NodeIdWrapper(); int tab = panel.GetTabAtPosition(e.X, e.Y); if (tab >= 0) { itemNodeId = wbOverview.get_child((panel.Tag as Identifier).id, tab); nodes.Add(itemNodeId); } items = wbOverview.get_popup_items_for_nodes(nodes); if (items != null && items.Count > 0) { System.Windows.Forms.ContextMenuStrip menu; menu = workbenchMenuManager.ShowContextMenu(panel, items, e.X, e.Y, new EventHandler(PopupActionHandler)); menu.Tag = panel; SetMenuItemsTag(menu.Items, CreateIdentifier(itemNodeId)); } } } }
public void RefreshNodeInfo(NodeIdWrapper node) { int nodeType; // if we're refreshing a node, first check what type is it, then update it // through its container or the item itself if (wbOverview.get_field(node, (int)Overview.Columns.NodeType, out nodeType)) { wbOverview.refresh_node(node, false); switch ((Overview.NodeType)nodeType) { case Overview.NodeType.Root: // Do nothing. We refresh the entire content with the model refresh notification. break; case Overview.NodeType.Item: // find the object in its container NodeIdWrapper parent = wbOverview.get_parent(node); if (listsByNode.ContainsKey(parent.toString())) { ListView list = listsByNode[parent.toString()]; UpdateListViewNode(node, list); } break; case Overview.NodeType.Section: // a CollapsingPanel break; case Overview.NodeType.Group: { // schema tabs if (panelsByNode.ContainsKey(wbOverview.get_parent(node).toString())) { CollapsingPanel panel = panelsByNode[wbOverview.get_parent(node).toString()]; panel.Refresh(); panel.Update(); } break; } default: throw new Exception("Model overview: invalid node type found"); } } }
private void PopulateListView(NodeIdWrapper parentNodeId, ListView listView) { listView.BeginUpdate(); try { int itemCount = wbOverview.count_children(parentNodeId); ListViewItem[] items = new ListViewItem[itemCount]; int detail_fields_count = wbOverview.get_details_field_count(parentNodeId); for (int i = 0; i < itemCount; i++) { NodeIdWrapper itemNodeId = wbOverview.get_child(parentNodeId, i); string caption; wbOverview.get_field(itemNodeId, (int)Overview.Columns.Label, out caption); ListViewItem item = new ListViewItem(caption, FindImageIndex(itemNodeId, listView.View)); item.Tag = CreateIdentifier(itemNodeId); item.ToolTipText = caption; // Add details for that item, if available. for (int counter = 0; counter < detail_fields_count; counter++) { String detailText; wbOverview.get_field(itemNodeId, (int)Overview.Columns.FirstDetailField + counter, out detailText); item.SubItems.Add(detailText.Replace(Environment.NewLine, " / ")); } items[i] = item; } listView.Items.Clear(); listView.Items.AddRange(items); // Setting the sorter also starts sorting. listView.ListViewItemSorter = new InsensitiveListviewComparer(0, SortOrder.Ascending); Win32.SetSortIcon(listView, 0, SortOrder.Ascending); // select stuff List<int> selected = wbOverview.get_selected_children(parentNodeId); foreach (int i in selected) listView.SelectedIndices.Add(i); } finally { listView.EndUpdate(); listView.PerformLayout(); }; }
private Identifier CreateIdentifier(NodeIdWrapper nodeId) { Identifier identifier = new Identifier(nodeId); identifier.objectId = wbOverview.get_node_unique_id(nodeId); return identifier; }
private void PopulateListViewColumns(NodeIdWrapper sectionNodeId, ListView sectionListview, Overview.DisplayMode displayMode) { // Refresh columns for this view. sectionListview.Columns.Clear(); sectionListview.Columns.Add("Name", 200); // Only add more columns if we are not in tile view mode. // We add columns also for large icon view, even though we don't see them, as we can then // quicker switch between large icon and tile view (no need to re-populate the view then). if (displayMode == Overview.DisplayMode.List) { int columnCount = wbOverview.get_details_field_count(sectionNodeId); for (int counter = 0; counter < columnCount; counter++) { String columnCaption = wbOverview.get_field_name(sectionNodeId, (int)Overview.Columns.FirstDetailField + counter); sectionListview.Columns.Add(columnCaption, 100); } } }
/// <summary> /// Returns the image index for a given node and view mode as cached in the mapper. /// If such a mapping does not exist yet then one is created. /// /// Note: wbOverview must be assigned already to make this work. /// </summary> /// <returns> /// The index of the image within the associated image list. /// </returns> private int FindImageIndex(NodeIdWrapper id, View view) { IconSize size = IconSize.Icon16; if (view == View.LargeIcon) size = IconSize.Icon48; int iconId = wbOverview.get_field_icon(id, (int)Overview.Columns.Label, size); int iconKey = CreateIconKey(iconId, view); if (!imageIndexMapper.ContainsKey(iconKey)) { // There is no image index stored yet for this node. // Add a new mapping for it. // This is necessary as we cannot guarantee that both image indices are the same for // small and large icons (which would be necessary if we want to use the same index for // both, large and small icon view). So we have to set the index depending on the view mode. int listIndex = IconManagerWrapper.get_instance().add_icon_to_imagelist(iconId); imageIndexMapper.Add(iconKey, listIndex); } return imageIndexMapper[iconKey]; }
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) { base.OnCellPainting(e); if (e.ColumnIndex < 0 || e.RowIndex < 0) { return; } NodeIdWrapper NodeIdWrapper = new NodeIdWrapper(e.RowIndex); Bitmap icon = null; Rectangle rect = e.CellBounds; if (e.ColumnIndex == 0) { // Check if we have to draw a busy indicator. int type; Model.get_field(NodeIdWrapper, 0, out type); if ((MessageType)type == MessageType.BusyMsg) { icon = (e.RowIndex % 2 == 1) ? Resources.busy_indicator_lightblue : Resources.busy_indicator_white; ImageAnimator.UpdateFrames(); rect.X += (rect.Width - icon.Width) / 2; rect.Y += (rect.Height - icon.Height) / 2; rect.Size = icon.Size; } } if (icon == null) { int iconId = Model.get_field_icon(NodeIdWrapper, e.ColumnIndex, IconSize.Icon16); icon = IconManagerWrapper.get_instance().get_icon(iconId); if (icon != null) { rect.Size = icon.Size; // Horizontal alignment. switch (e.CellStyle.Alignment) { case DataGridViewContentAlignment.TopRight: case DataGridViewContentAlignment.MiddleRight: case DataGridViewContentAlignment.BottomRight: rect.X += e.CellBounds.Width - rect.Width; rect.X -= 1; // cell border width (required only for right alignment) break; case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.BottomCenter: rect.X += (e.CellBounds.Width - rect.Width) / 2; break; } // Vertical alignment. switch (e.CellStyle.Alignment) { case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.MiddleRight: rect.Y += (e.CellBounds.Height - rect.Height) / 2; break; case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.BottomRight: rect.Y += e.CellBounds.Height - rect.Height; break; } } } if (icon != null) { e.PaintBackground(e.CellBounds, true); e.Graphics.DrawImageUnscaledAndClipped(icon, rect); e.Handled = true; } }
/// <summary> /// Returns the listview for a given section. If it does not exist yet it gets created. /// Optionally a simple panel is added as header for this section. /// </summary> private ListView GetSectionListview(NodeIdWrapper controlNodeId, CollapsingPanel overviewPanel, bool addSectionHeader, Overview.DisplayMode displayMode, String caption, String info) { // Iterate over all sections we have already and find the one with the given control id. String objectId = wbOverview.get_node_unique_id(controlNodeId); foreach (Control control in overviewPanel.Controls) { if (control.Tag != null) { String currentObjectId = (control.Tag as Identifier).objectId; if (currentObjectId != null && currentObjectId == objectId) { ListView listview = control as ListView; SetViewMode(listview, displayMode); return listview; } } } // If we come here then the section does not exist yet, so add it. Start with a header. if (addSectionHeader) { Panel panel = new Panel(); panel.BorderStyle = BorderStyle.None; panel.Padding = new Padding(5, 2, 5, 0); panel.BackgroundImage = Resources.header_bar_blue; panel.BackgroundImageLayout = ImageLayout.None; panel.Height = 24; // Insert client controls in reverse order. // Info label. Label infoLabel = new Label(); infoLabel.Text = info; infoLabel.ForeColor = Color.Gray; infoLabel.Font = overviewPanel.Font; infoLabel.AutoSize = true; infoLabel.Margin = new Padding(10, 0, 0, 0); infoLabel.Dock = DockStyle.Left; panel.Controls.Add(infoLabel); overviewPanel.Controls.Add(panel); // Caption label. Label captionLabel = new Label(); captionLabel.Text = caption; //captionLabel.Font = new Font(overviewPanel.Font, FontStyle.Bold); captionLabel.AutoSize = true; captionLabel.Dock = DockStyle.Left; captionLabel.ForeColor = Color.Black; panel.Controls.Add(captionLabel); overviewPanel.Controls.Add(panel); } // Then the content view. ListView sectionListview = new ListView(); sectionListview.BorderStyle = BorderStyle.None; sectionListview.AllowColumnReorder = true; sectionListview.ShowItemToolTips = true; // Undocumented feature: enabling AutoSize will indeed make the control automatically resize // (the docs say it wouldn't) though without considering long captions. For them to work // additionally Scrollable can be set to true to show a scrollbar, but only in this special case. sectionListview.AutoSize = true; sectionListview.MultiSelect = false; sectionListview.Scrollable = true; sectionListview.Visible = true; sectionListview.Font = overviewPanel.Font; sectionListview.Tag = CreateIdentifier(controlNodeId); sectionListview.Sorting = SortOrder.None; // We do custom sort. sectionListview.DoubleClick += new EventHandler(listViewDoubleClick); sectionListview.ItemDrag += new ItemDragEventHandler(listViewItemDrag); sectionListview.SelectedIndexChanged += new EventHandler(listViewSelectedIndexChanged); sectionListview.KeyDown += new KeyEventHandler(listViewKeyDown); sectionListview.MouseUp += new MouseEventHandler(listViewMouseUp); sectionListview.ColumnClick += new ColumnClickEventHandler(ListviewColumnClick); sectionListview.Enter += new EventHandler(ListViewEnter); // Renaming of overview nodes sectionListview.LabelEdit = true; sectionListview.AfterLabelEdit += new LabelEditEventHandler(listViewAfterLabelEdit); sectionListview.BeforeLabelEdit += new LabelEditEventHandler(listViewBeforeLabelEdit); // Add it to the panel. Usually the layout engine of the panel should take care for // the layout of the controls, but just to be sure we set here a dock style. overviewPanel.Controls.Add(sectionListview); sectionListview.Dock = DockStyle.Top; // Set Image Lists sectionListview.SmallImageList = IconManagerWrapper.ImageList16; sectionListview.LargeImageList = IconManagerWrapper.ImageList48; SetViewMode(sectionListview, displayMode); sectionListview.Update(); return sectionListview; }