1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
23 // Ravindra (rkumar@novell.com)
27 // $Log: ColumnHeader.cs,v $
28 // Revision 1.3 2004/10/26 09:33:00 ravindra
29 // Added some internal members and calculations for ColumnHeader.
31 // Revision 1.2 2004/10/15 15:06:44 ravindra
32 // Flushing some formatting changes.
34 // Revision 1.1 2004/09/30 13:25:33 ravindra
35 // Supporting class for ListView control.
41 using System.ComponentModel;
44 namespace System.Windows.Forms
46 [DefaultProperty ("Text")]
47 [DesignTimeVisible (false)]
49 public class ColumnHeader : Component, ICloneable
51 #region Instance Variables
52 internal ListView owner;
53 private StringFormat format;
54 private string text = "ColumnHeader";
55 private HorizontalAlignment text_alignment = HorizontalAlignment.Left;
56 private int width = ThemeEngine.Current.DefaultColumnWidth;
58 internal Rectangle column_rect = Rectangle.Empty;
59 #endregion // Instance Variables
61 #region Internal Constructor
62 internal ColumnHeader (ListView owner, string text, HorizontalAlignment alignment, int width)
67 this.text_alignment = alignment;
70 #endregion // Internal Constructor
72 #region Public Constructors
73 public ColumnHeader () { }
74 #endregion // Public Constructors
76 #region Private Internal Methods Properties
77 // Since this class inherits from MarshalByRef,
78 // we can't do ColumnHeader.column_rect.XXX. Hence,
79 // we have following properties to work around.
81 get { return this.column_rect.X; }
82 set { this.column_rect.X = value; }
86 get { return this.column_rect.Y; }
87 set { this.column_rect.Y = value; }
91 get { return this.column_rect.Width; }
92 set { this.column_rect.Width = value; }
96 get { return this.column_rect.Height; }
97 set { this.column_rect.Height = value; }
100 internal Rectangle Rect {
101 get { return this.column_rect; }
104 internal StringFormat Format {
105 get { return this.format; }
108 internal void CalcColumnHeader ()
110 format = new StringFormat ();
111 if (text_alignment == HorizontalAlignment.Center)
112 format.Alignment = StringAlignment.Center;
113 else if (text_alignment == HorizontalAlignment.Right)
114 format.Alignment = StringAlignment.Far;
116 format.Alignment = StringAlignment.Near;
117 format.LineAlignment = StringAlignment.Center;
118 format.Trimming = StringTrimming.EllipsisWord;
119 // text is wrappable only in LargeIcon and SmallIcon views
120 format.FormatFlags = StringFormatFlags.NoWrap;
123 this.column_rect.Width = width;
125 this.column_rect.Height = owner.Font.Height;
127 this.column_rect.Height = ThemeEngine.Current.DefaultFont.Height;
129 else if (this.Index != -1)
130 this.column_rect.Size = owner.GetChildColumnSize (this.Index);
132 this.column_rect.Size = Size.Empty;
134 #endregion // Private Internal Methods Properties
136 #region Public Instance Properties
140 if (owner != null && owner.Columns != null
141 && owner.Columns.Contains (this)) {
142 return owner.Columns.IndexOf (this);
149 public ListView ListView {
150 get { return owner; }
163 [DefaultValue (HorizontalAlignment.Left)]
165 public HorizontalAlignment TextAlign {
166 get { return text_alignment; }
168 text_alignment = value;
177 get { return width; }
184 #endregion // Public Instance Properties
186 #region Public Methods
187 public virtual object Clone ()
189 ColumnHeader columnHeader = new ColumnHeader ();
190 columnHeader.text = text;
191 columnHeader.text_alignment = text_alignment;
192 columnHeader.width = width;
193 columnHeader.owner = owner;
194 columnHeader.column_rect = column_rect = new Rectangle (Point.Empty, Size.Empty);
198 public override string ToString ()
200 return string.Format ("ColumnHeader: Text: {0}", text);
202 #endregion // Public Methods
204 #region Protected Methods
205 protected override void Dispose (bool disposing)
207 base.Dispose (disposing);
209 #endregion // Protected Methods