/* * Styles - A style is a group of formatting attributes that can be applied to a row or a cell * * Author: Phillip Piper * Date: 29/07/2009 23:09 * * Change log: * v2.4 * 2010-03-23 JPP - Added HeaderFormatStyle and support * v2.3 * 2009-08-15 JPP - Added Decoration and Overlay properties to HotItemStyle * 2009-07-29 JPP - Initial version * * To do: * - These should be more generally available. It should be possible to do something like this: * this.olv.GetItem(i).Style = new ItemStyle(); * this.olv.GetItem(i).GetSubItem(j).Style = new CellStyle(); * * Copyright (C) 2009-2014 Phillip Piper * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * If you wish to use this code in a closed source application, please contact phillip_piper@bigfoot.com. */ using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace BrightIdeasSoftware { /// /// The common interface supported by all style objects /// public interface IItemStyle { /// /// Gets or set the font that will be used by this style /// Font Font { get; set; } /// /// Gets or set the font style /// FontStyle FontStyle { get; set; } /// /// Gets or sets the ForeColor /// Color ForeColor { get; set; } /// /// Gets or sets the BackColor /// Color BackColor { get; set; } } /// /// Basic implementation of IItemStyle /// public class SimpleItemStyle : System.ComponentModel.Component, IItemStyle { /// /// Gets or sets the font that will be applied by this style /// [DefaultValue(null)] public Font Font { get { return this.font; } set { this.font = value; } } private Font font; /// /// Gets or sets the style of font that will be applied by this style /// [DefaultValue(FontStyle.Regular)] public FontStyle FontStyle { get { return this.fontStyle; } set { this.fontStyle = value; } } private FontStyle fontStyle; /// /// Gets or sets the color of the text that will be applied by this style /// [DefaultValue(typeof (Color), "")] public Color ForeColor { get { return this.foreColor; } set { this.foreColor = value; } } private Color foreColor; /// /// Gets or sets the background color that will be applied by this style /// [DefaultValue(typeof (Color), "")] public Color BackColor { get { return this.backColor; } set { this.backColor = value; } } private Color backColor; } /// /// Instances of this class specify how should "hot items" (non-selected /// rows under the cursor) be renderered. /// public class HotItemStyle : SimpleItemStyle { /// /// Gets or sets the overlay that should be drawn as part of the hot item /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public IOverlay Overlay { get { return this.overlay; } set { this.overlay = value; } } private IOverlay overlay; /// /// Gets or sets the decoration that should be drawn as part of the hot item /// /// A decoration is different from an overlay in that an decoration /// scrolls with the listview contents, whilst an overlay does not. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public IDecoration Decoration { get { return this.decoration; } set { this.decoration = value; } } private IDecoration decoration; } /// /// This class defines how a cell should be formatted /// [TypeConverter(typeof(ExpandableObjectConverter))] public class CellStyle : IItemStyle { /// /// Gets or sets the font that will be applied by this style /// public Font Font { get { return this.font; } set { this.font = value; } } private Font font; /// /// Gets or sets the style of font that will be applied by this style /// [DefaultValue(FontStyle.Regular)] public FontStyle FontStyle { get { return this.fontStyle; } set { this.fontStyle = value; } } private FontStyle fontStyle; /// /// Gets or sets the color of the text that will be applied by this style /// [DefaultValue(typeof(Color), "")] public Color ForeColor { get { return this.foreColor; } set { this.foreColor = value; } } private Color foreColor; /// /// Gets or sets the background color that will be applied by this style /// [DefaultValue(typeof(Color), "")] public Color BackColor { get { return this.backColor; } set { this.backColor = value; } } private Color backColor; } /// /// Instances of this class describe how hyperlinks will appear /// public class HyperlinkStyle : System.ComponentModel.Component { /// /// Create a HyperlinkStyle /// public HyperlinkStyle() { this.Normal = new CellStyle(); this.Normal.ForeColor = Color.Blue; this.Over = new CellStyle(); this.Over.FontStyle = FontStyle.Underline; this.Visited = new CellStyle(); this.Visited.ForeColor = Color.Purple; this.OverCursor = Cursors.Hand; } /// /// What sort of formatting should be applied to hyperlinks in their normal state? /// [Category("Appearance"), Description("How should hyperlinks be drawn")] public CellStyle Normal { get { return this.normalStyle; } set { this.normalStyle = value; } } private CellStyle normalStyle; /// /// What sort of formatting should be applied to hyperlinks when the mouse is over them? /// [Category("Appearance"), Description("How should hyperlinks be drawn when the mouse is over them?")] public CellStyle Over { get { return this.overStyle; } set { this.overStyle = value; } } private CellStyle overStyle; /// /// What sort of formatting should be applied to hyperlinks after they have been clicked? /// [Category("Appearance"), Description("How should hyperlinks be drawn after they have been clicked")] public CellStyle Visited { get { return this.visitedStyle; } set { this.visitedStyle = value; } } private CellStyle visitedStyle; /// /// Gets or sets the cursor that should be shown when the mouse is over a hyperlink. /// [Category("Appearance"), Description("What cursor should be shown when the mouse is over a link?")] public Cursor OverCursor { get { return this.overCursor; } set { this.overCursor = value; } } private Cursor overCursor; } /// /// Instances of this class control one the styling of one particular state /// (normal, hot, pressed) of a header control /// [TypeConverter(typeof(ExpandableObjectConverter))] public class HeaderStateStyle { /// /// Gets or sets the font that will be applied by this style /// [DefaultValue(null)] public Font Font { get { return this.font; } set { this.font = value; } } private Font font; /// /// Gets or sets the color of the text that will be applied by this style /// [DefaultValue(typeof(Color), "")] public Color ForeColor { get { return this.foreColor; } set { this.foreColor = value; } } private Color foreColor; /// /// Gets or sets the background color that will be applied by this style /// [DefaultValue(typeof(Color), "")] public Color BackColor { get { return this.backColor; } set { this.backColor = value; } } private Color backColor; /// /// Gets or sets the color in which a frame will be drawn around the header for this column /// [DefaultValue(typeof(Color), "")] public Color FrameColor { get { return this.frameColor; } set { this.frameColor = value; } } private Color frameColor; /// /// Gets or sets the width of the frame that will be drawn around the header for this column /// [DefaultValue(0.0f)] public float FrameWidth { get { return this.frameWidth; } set { this.frameWidth = value; } } private float frameWidth; } /// /// This class defines how a header should be formatted in its various states. /// public class HeaderFormatStyle : System.ComponentModel.Component { /// /// Create a new HeaderFormatStyle /// public HeaderFormatStyle() { this.Hot = new HeaderStateStyle(); this.Normal = new HeaderStateStyle(); this.Pressed = new HeaderStateStyle(); } /// /// What sort of formatting should be applied to a column header when the mouse is over it? /// [Category("Appearance"), Description("How should the header be drawn when the mouse is over it?")] public HeaderStateStyle Hot { get { return this.hotStyle; } set { this.hotStyle = value; } } private HeaderStateStyle hotStyle; /// /// What sort of formatting should be applied to a column header in its normal state? /// [Category("Appearance"), Description("How should a column header normally be drawn")] public HeaderStateStyle Normal { get { return this.normalStyle; } set { this.normalStyle = value; } } private HeaderStateStyle normalStyle; /// /// What sort of formatting should be applied to a column header when pressed? /// [Category("Appearance"), Description("How should a column header be drawn when it is pressed")] public HeaderStateStyle Pressed { get { return this.pressedStyle; } set { this.pressedStyle = value; } } private HeaderStateStyle pressedStyle; /// /// Set the font for all three states /// /// public void SetFont(Font font) { this.Normal.Font = font; this.Hot.Font = font; this.Pressed.Font = font; } /// /// Set the fore color for all three states /// /// public void SetForeColor(Color color) { this.Normal.ForeColor = color; this.Hot.ForeColor = color; this.Pressed.ForeColor = color; } /// /// Set the back color for all three states /// /// public void SetBackColor(Color color) { this.Normal.BackColor = color; this.Hot.BackColor = color; this.Pressed.BackColor = color; } } }