public void TestSelectorWithMultiplePseudoClasses() { string selectorStr = ".class:active:hover"; ISelector selector = Selector.Parse(selectorStr); UserNode node = new UserNode(string.Empty, new[] { "class" }); node.AddState(NodeStates.Active); node.AddState(NodeStates.Hover); Assert.IsTrue(selector.IsMatch(node)); }
protected virtual void PaintNodeContent(TreeView control, TreeNode node, int visibleIndex, ControlPaintArgs args) { UserNode treeNodeNode = new UserNode(string.Empty, new[] { "Node", "TreeViewNode" }); treeNodeNode.SetParent(new ControlNode(control)); if (node.IsSelected) { treeNodeNode.AddState(NodeStates.Checked); } if (visibleIndex % 2 == 0) { treeNodeNode.AddClass("Even"); } else { treeNodeNode.AddClass("Odd"); } IRuleset treeNodeRuleset = args.StyleSheet.GetRuleset(treeNodeNode); Rectangle nodeRect = node.Bounds; Rectangle backgroundRect = new Rectangle(nodeRect.X + 2, nodeRect.Y + 1, nodeRect.Width, nodeRect.Height - 1); Rectangle textRect = new Rectangle(nodeRect.X + 1, nodeRect.Y + 3, nodeRect.Width - 1, nodeRect.Height - 3); if (control.FullRowSelect) { backgroundRect = new Rectangle(0, backgroundRect.Y, control.Width, backgroundRect.Height); } args.StyleRenderer.PaintBackground(args.Graphics, backgroundRect, treeNodeRuleset); args.StyleRenderer.PaintText(args.Graphics, textRect, treeNodeRuleset, node.Text, control.Font, TextFormatFlags.Default | TextFormatFlags.VerticalCenter); args.StyleRenderer.PaintBorder(args.Graphics, backgroundRect, treeNodeRuleset); }
private UserNode GetToolStripItemNode(ToolStripItem item) { UserNode node = new UserNode(string.Empty, new[] { "ToolStripItem", "Item" }); if (item.Selected) { node.AddState(NodeStates.Hover); } if (item is ToolStripMenuItem toolStripMenuItem && toolStripMenuItem.DropDown.Visible) { node.AddState(NodeStates.Active); } return(node); }
private void PaintSubItem(Graphics graphics, ListViewItem item, ListViewItem.ListViewSubItem subItem) { ListView listView = item.ListView; ColumnHeader columnHeader = listView.Columns[item.SubItems.IndexOf(subItem)]; Rectangle bounds = subItem.Bounds; UserNode node = new UserNode(bounds, listView.PointToClient(Cursor.Position)); node.SetClass("ListViewItem"); node.AddClass("Item"); node.SetParent(new ControlNode(listView)); if (item.Selected) { node.AddState(NodeStates.Checked); } int textPadding = 4; IRuleset ruleset = styleSheet.GetRuleset(node); Rectangle itemRect = new Rectangle(bounds.X, bounds.Y, columnHeader.Width, bounds.Height); Rectangle textRect = new Rectangle(itemRect.X + textPadding, itemRect.Y, itemRect.Width - textPadding * 2, itemRect.Height); TextFormatFlags textFormatFlags = TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix; styleRenderer.PaintText(graphics, textRect, ruleset, subItem.Text, subItem.Font, textFormatFlags); styleRenderer.PaintBorder(graphics, itemRect, ruleset); }
private void PaintItem(Graphics graphics, ListViewItem item) { Rectangle bounds = item.Bounds; UserNode node = new UserNode(bounds, item.ListView.PointToClient(Cursor.Position)); node.AddClass("ListViewItem"); node.AddClass("Item"); node.SetParent(new ControlNode(item.ListView)); if (item.Index % 2 == 0) { node.AddClass("Even"); } else { node.AddClass("Odd"); } if (item.Selected) { node.AddState(NodeStates.Checked); } IRuleset ruleset = styleSheet.GetRuleset(node); Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height); styleRenderer.PaintBackground(graphics, rect, ruleset); styleRenderer.PaintBorder(graphics, rect, ruleset); }
// Private members private void PaintTabs(TabControl control, ControlPaintArgs e) { if (control.TabPages.Count > 0) { for (int i = 0; i < control.TabPages.Count; ++i) { TabPage tabPage = control.TabPages[i]; Rectangle tabRect = control.GetTabRect(i); UserNode tabNode = new UserNode(tabRect, control.PointToClient(Cursor.Position)); tabNode.SetParent(new ControlNode(control)); tabNode.AddClass("tab"); if (i == 0) { tabRect = new Rectangle(tabRect.X + 2, tabRect.Y, tabRect.Width - 2, tabRect.Height); } if (control.SelectedIndex == i) { // Draw selected tab. tabNode.AddState(NodeStates.Checked); IRuleset tabRuleset = e.StyleSheet.GetRuleset(tabNode); Rectangle drawRect = new Rectangle(tabRect.X - 2, tabRect.Y - 2, tabRect.Width + 2, tabRect.Height + 4); Rectangle textRect = new Rectangle(tabRect.X, tabRect.Y - 2, tabRect.Width, tabRect.Height); if (i == 0) { drawRect = new Rectangle(drawRect.X + 2, drawRect.Y, drawRect.Width - 2, drawRect.Height); } e.StyleRenderer.PaintBackground(e.Graphics, drawRect, tabRuleset); e.StyleRenderer.PaintBorder(e.Graphics, drawRect, tabRuleset); e.StyleRenderer.PaintText(e.Graphics, textRect, tabRuleset, tabPage.Text, control.Font, textFormatFlags: TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); } else { // Draw unselected tab. IRuleset tabRuleset = e.StyleSheet.GetRuleset(tabNode); Rectangle drawRect = new Rectangle(tabRect.X, tabRect.Y, tabRect.Width, tabRect.Height + 2); e.StyleRenderer.PaintBackground(e.Graphics, drawRect, tabRuleset); e.StyleRenderer.PaintBorder(e.Graphics, drawRect, tabRuleset); e.StyleRenderer.PaintText(e.Graphics, tabRect, tabRuleset, tabPage.Text, control.Font, textFormatFlags: TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); } } } }
protected virtual void PaintNodeButton(TreeView control, TreeNode node, ControlPaintArgs args) { const int buttonWidth = 9; const int detailPadding = 2; UserNode nodeButtonNode = new UserNode(string.Empty, new[] { "Button" }); nodeButtonNode.SetParent(new ControlNode(control)); if (node.IsSelected) { nodeButtonNode.AddState(NodeStates.Checked); } IRuleset nodeButtonRuleset = args.StyleSheet.GetRuleset(nodeButtonNode); Rectangle nodeRect = node.Bounds; Rectangle buttonRect = new Rectangle(nodeRect.X - buttonWidth - 3, nodeRect.Y + nodeRect.Height - buttonWidth - 1, buttonWidth, buttonWidth); args.StyleRenderer.PaintBackground(args.Graphics, buttonRect, nodeButtonRuleset); args.StyleRenderer.PaintBorder(args.Graphics, buttonRect, nodeButtonRuleset); if (PaintNodeButtonContent) { Color detailColor = nodeButtonRuleset.Color?.Value ?? Color.Black; buttonRect.Inflate(-detailPadding, -detailPadding); int x = buttonRect.X; int y = buttonRect.Y; int x2 = x + buttonRect.Width - 1; int y2 = y + buttonRect.Height - 1; int midX = x + (buttonRect.Width / 2); int midY = y + (buttonRect.Height / 2); using (Pen detailPen = new Pen(detailColor)) { args.Graphics.DrawLine(detailPen, new Point(x, midY), new Point(x2, midY)); if (!node.IsExpanded) { args.Graphics.DrawLine(detailPen, new Point(midX, y), new Point(midX, y2)); } } } }
public void CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (sender is DataGridView dataGridView) { bool isColumnHeader = DataGridViewUtilities.IsColumnHeaderIndex(e.RowIndex); bool isRowHeader = DataGridViewUtilities.IsRowHeaderIndex(e.ColumnIndex); bool isHeader = isColumnHeader || isRowHeader; bool isSelected = e.State.HasFlag(DataGridViewElementStates.Selected); UserNode cellNode = new UserNode(e.CellBounds, dataGridView.PointToClient(Cursor.Position)); cellNode.AddClass("Cell"); cellNode.SetParent(new ControlNode(sender as DataGridView)); if (isColumnHeader) { cellNode.AddClass("ColumnHeader"); } else if (isRowHeader) { cellNode.AddClass("RowHeader"); } if (isHeader) { cellNode.AddClass("Header"); } if (e.RowIndex % 2 == 0) { cellNode.AddClass("Even"); } else { cellNode.AddClass("Odd"); } if (isSelected) { cellNode.AddState(NodeStates.Checked); } IRuleset ruleset = styleSheet.GetRuleset(cellNode); if (RespectNonDefaultCellColors) { ruleset = SetNonDefaultCellColors(ruleset, dataGridView, e); } if (ruleset.Color.HasValue()) { if (isSelected) { e.CellStyle.SelectionForeColor = ruleset.Color.Value; } else { e.CellStyle.ForeColor = ruleset.Color.Value; } } if (ruleset.BackgroundColor.HasValue()) { if (isSelected) { e.CellStyle.SelectionBackColor = ruleset.BackgroundColor.Value; } else { e.CellStyle.BackColor = ruleset.BackgroundColor.Value; } } if (ruleset.Opacity.HasValue() && ruleset.Opacity.Value < 1.0f) { // Draw the part of the DataGridView background behind the cell. styleRenderer.PaintParentBackground(e.Graphics, e.CellBounds, dataGridView.ClientRectangle, styleSheet.GetRuleset(dataGridView)); } styleRenderer.PaintBackground(e.Graphics, e.CellBounds, ruleset); e.PaintContent(e.ClipBounds); styleRenderer.PaintBorder(e.Graphics, e.CellBounds, ruleset); e.Handled = true; } }