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.5 2004/11/04 11:29:38 ravindra
29 // - Changed default value signatures (prefixed all with ListView).
30 // - Fixed/implemented layout LargeIcon, SmallIcon and List views for ListView.
31 // - Fixed calculations for ListViewItem and implemented Clone() method.
33 // Revision 1.4 2004/10/26 09:55:48 ravindra
34 // Some formatting for my last checkins.
36 // Revision 1.3 2004/10/26 09:33:00 ravindra
37 // Added some internal members and calculations for ColumnHeader.
39 // Revision 1.2 2004/10/15 15:06:44 ravindra
40 // Flushing some formatting changes.
42 // Revision 1.1 2004/09/30 13:25:33 ravindra
43 // Supporting class for ListView control.
49 using System.ComponentModel;
52 namespace System.Windows.Forms
54 [DefaultProperty ("Text")]
55 [DesignTimeVisible (false)]
57 public class ColumnHeader : Component, ICloneable
59 #region Instance Variables
60 private StringFormat format;
61 private string text = "ColumnHeader";
62 private HorizontalAlignment text_alignment = HorizontalAlignment.Left;
63 private int width = ThemeEngine.Current.ListViewDefaultColumnWidth;
66 internal Rectangle column_rect = Rectangle.Empty;
67 internal bool pressed = false;
68 internal ListView owner;
69 #endregion // Instance Variables
71 #region Internal Constructor
72 internal ColumnHeader (ListView owner, string text,
73 HorizontalAlignment alignment, int width)
78 this.text_alignment = alignment;
81 #endregion // Internal Constructor
83 #region Public Constructors
84 public ColumnHeader () { }
85 #endregion // Public Constructors
87 #region Private Internal Methods Properties
88 // Since this class inherits from MarshalByRef,
89 // we can't do ColumnHeader.column_rect.XXX. Hence,
90 // we have some of the following properties to work around CS0197.
91 internal bool Pressed {
92 get { return this.pressed; }
96 get { return this.column_rect.X; }
97 set { this.column_rect.X = value; }
101 get { return this.column_rect.Y; }
102 set { this.column_rect.Y = value; }
106 get { return this.column_rect.Width; }
107 set { this.column_rect.Width = value; }
111 get { return this.column_rect.Height; }
112 set { this.column_rect.Height = value; }
115 internal Rectangle Rect {
116 get { return this.column_rect; }
119 internal StringFormat Format {
120 get { return this.format; }
123 internal void CalcColumnHeader ()
125 format = new StringFormat ();
126 if (text_alignment == HorizontalAlignment.Center)
127 format.Alignment = StringAlignment.Center;
128 else if (text_alignment == HorizontalAlignment.Right)
129 format.Alignment = StringAlignment.Far;
131 format.Alignment = StringAlignment.Near;
132 format.LineAlignment = StringAlignment.Center;
133 format.Trimming = StringTrimming.EllipsisWord;
134 // text is wrappable only in LargeIcon and SmallIcon views
135 format.FormatFlags = StringFormatFlags.NoWrap;
138 this.column_rect.Width = width;
140 this.column_rect.Height = owner.Font.Height;
142 this.column_rect.Height = ThemeEngine.Current.DefaultFont.Height;
144 else if (this.Index != -1)
145 this.column_rect.Size = owner.GetChildColumnSize (this.Index);
147 this.column_rect.Size = Size.Empty;
149 #endregion // Private Internal Methods Properties
151 #region Public Instance Properties
155 if (owner != null && owner.Columns != null
156 && owner.Columns.Contains (this)) {
157 return owner.Columns.IndexOf (this);
164 public ListView ListView {
165 get { return owner; }
178 [DefaultValue (HorizontalAlignment.Left)]
180 public HorizontalAlignment TextAlign {
181 get { return text_alignment; }
183 text_alignment = value;
192 get { return width; }
199 #endregion // Public Instance Properties
201 #region Public Methods
202 public virtual object Clone ()
204 ColumnHeader columnHeader = new ColumnHeader ();
205 columnHeader.text = text;
206 columnHeader.text_alignment = text_alignment;
207 columnHeader.width = width;
208 columnHeader.owner = owner;
209 columnHeader.column_rect = Rectangle.Empty;
213 public override string ToString ()
215 return string.Format ("ColumnHeader: Text: {0}", text);
217 #endregion // Public Methods
219 #region Protected Methods
220 protected override void Dispose (bool disposing)
222 base.Dispose (disposing);
224 #endregion // Protected Methods