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)
30 using System.ComponentModel;
33 namespace System.Windows.Forms
35 [DefaultProperty ("Text")]
36 [DesignTimeVisible (false)]
38 public class ColumnHeader : Component, ICloneable
40 #region Instance Variables
41 private StringFormat format = new StringFormat ();
42 private string text = "ColumnHeader";
43 private HorizontalAlignment text_alignment = HorizontalAlignment.Left;
44 private int width = ThemeEngine.Current.ListViewDefaultColumnWidth;
47 internal Rectangle column_rect = Rectangle.Empty;
48 internal bool pressed = false;
49 internal ListView owner;
50 #endregion // Instance Variables
52 #region Internal Constructor
53 internal ColumnHeader (ListView owner, string text,
54 HorizontalAlignment alignment, int width)
59 this.text_alignment = alignment;
62 #endregion // Internal Constructor
64 #region Public Constructors
65 public ColumnHeader () { }
66 #endregion // Public Constructors
68 #region Private Internal Methods Properties
69 // Since this class inherits from MarshalByRef,
70 // we can't do ColumnHeader.column_rect.XXX. Hence,
71 // we have some of the following properties to work around CS0197.
72 internal bool Pressed {
73 get { return this.pressed; }
77 get { return this.column_rect.X; }
78 set { this.column_rect.X = value; }
82 get { return this.column_rect.Y; }
83 set { this.column_rect.Y = value; }
87 get { return this.column_rect.Width; }
88 set { this.column_rect.Width = value; }
92 get { return this.column_rect.Height; }
93 set { this.column_rect.Height = value; }
96 internal Rectangle Rect {
97 get { return this.column_rect; }
100 internal StringFormat Format {
101 get { return this.format; }
104 internal void CalcColumnHeader ()
106 if (text_alignment == HorizontalAlignment.Center)
107 format.Alignment = StringAlignment.Center;
108 else if (text_alignment == HorizontalAlignment.Right)
109 format.Alignment = StringAlignment.Far;
111 format.Alignment = StringAlignment.Near;
112 format.LineAlignment = StringAlignment.Center;
113 format.Trimming = StringTrimming.EllipsisWord;
114 // text is wrappable only in LargeIcon and SmallIcon views
115 format.FormatFlags = StringFormatFlags.NoWrap;
118 this.column_rect.Width = width;
120 this.column_rect.Height = owner.Font.Height + 5 ;
122 this.column_rect.Height = ThemeEngine.Current.DefaultFont.Height + 5;
124 else if (this.Index != -1)
125 this.column_rect.Size = owner.GetChildColumnSize (this.Index);
127 this.column_rect.Size = Size.Empty;
129 #endregion // Private Internal Methods Properties
131 #region Public Instance Properties
135 if (owner != null && owner.Columns != null
136 && owner.Columns.Contains (this)) {
137 return owner.Columns.IndexOf (this);
144 public ListView ListView {
145 get { return owner; }
158 [DefaultValue (HorizontalAlignment.Left)]
160 public HorizontalAlignment TextAlign {
161 get { return text_alignment; }
163 text_alignment = value;
172 get { return width; }
179 #endregion // Public Instance Properties
181 #region Public Methods
182 public object Clone ()
184 ColumnHeader columnHeader = new ColumnHeader ();
185 columnHeader.text = text;
186 columnHeader.text_alignment = text_alignment;
187 columnHeader.width = width;
188 columnHeader.owner = owner;
189 columnHeader.format = (StringFormat) Format.Clone ();
190 columnHeader.column_rect = Rectangle.Empty;
194 public override string ToString ()
196 return string.Format ("ColumnHeader: Text: {0}", text);
198 #endregion // Public Methods
200 #region Protected Methods
201 protected override void Dispose (bool disposing)
203 base.Dispose (disposing);
205 #endregion // Protected Methods