**** Merged from MCS ****
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ColumnHeader.cs
blob99dc246a2ebabdabe43110c3857dd3917e9f299d
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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)
22 // Author:
23 // Ravindra (rkumar@novell.com)
25 // $Revision: 1.5 $
26 // $Modtime: $
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.
46 // COMPLETE
49 using System.ComponentModel;
50 using System.Drawing;
52 namespace System.Windows.Forms
54 [DefaultProperty ("Text")]
55 [DesignTimeVisible (false)]
56 [ToolboxItem (false)]
57 public class ColumnHeader : Component, ICloneable
59 #region Instance Variables
60 internal ListView owner;
61 private StringFormat format;
62 private string text = "ColumnHeader";
63 private HorizontalAlignment text_alignment = HorizontalAlignment.Left;
64 private int width = ThemeEngine.Current.ListViewDefaultColumnWidth;
65 // column area
66 internal Rectangle column_rect = Rectangle.Empty;
67 #endregion // Instance Variables
69 #region Internal Constructor
70 internal ColumnHeader (ListView owner, string text,
71 HorizontalAlignment alignment, int width)
73 this.owner = owner;
74 this.text = text;
75 this.width = width;
76 this.text_alignment = alignment;
77 CalcColumnHeader ();
79 #endregion // Internal Constructor
81 #region Public Constructors
82 public ColumnHeader () { }
83 #endregion // Public Constructors
85 #region Private Internal Methods Properties
86 // Since this class inherits from MarshalByRef,
87 // we can't do ColumnHeader.column_rect.XXX. Hence,
88 // we have some of the following properties to work around CS0197.
89 internal int X {
90 get { return this.column_rect.X; }
91 set { this.column_rect.X = value; }
94 internal int Y {
95 get { return this.column_rect.Y; }
96 set { this.column_rect.Y = value; }
99 internal int Wd {
100 get { return this.column_rect.Width; }
101 set { this.column_rect.Width = value; }
104 internal int Ht {
105 get { return this.column_rect.Height; }
106 set { this.column_rect.Height = value; }
109 internal Rectangle Rect {
110 get { return this.column_rect; }
113 internal StringFormat Format {
114 get { return this.format; }
117 internal void CalcColumnHeader ()
119 format = new StringFormat ();
120 if (text_alignment == HorizontalAlignment.Center)
121 format.Alignment = StringAlignment.Center;
122 else if (text_alignment == HorizontalAlignment.Right)
123 format.Alignment = StringAlignment.Far;
124 else
125 format.Alignment = StringAlignment.Near;
126 format.LineAlignment = StringAlignment.Center;
127 format.Trimming = StringTrimming.EllipsisWord;
128 // text is wrappable only in LargeIcon and SmallIcon views
129 format.FormatFlags = StringFormatFlags.NoWrap;
131 if (width >= 0) {
132 this.column_rect.Width = width;
133 if (owner != null)
134 this.column_rect.Height = owner.Font.Height;
135 else
136 this.column_rect.Height = ThemeEngine.Current.DefaultFont.Height;
138 else if (this.Index != -1)
139 this.column_rect.Size = owner.GetChildColumnSize (this.Index);
140 else
141 this.column_rect.Size = Size.Empty;
143 #endregion // Private Internal Methods Properties
145 #region Public Instance Properties
146 [Browsable (false)]
147 public int Index {
148 get {
149 if (owner != null && owner.Columns != null
150 && owner.Columns.Contains (this)) {
151 return owner.Columns.IndexOf (this);
153 return -1;
157 [Browsable (false)]
158 public ListView ListView {
159 get { return owner; }
162 [Localizable (true)]
163 public string Text {
164 get { return text; }
165 set {
166 text = value;
167 if (owner != null)
168 owner.Redraw (true);
172 [DefaultValue (HorizontalAlignment.Left)]
173 [Localizable (true)]
174 public HorizontalAlignment TextAlign {
175 get { return text_alignment; }
176 set {
177 text_alignment = value;
178 if (owner != null)
179 owner.Redraw (true);
183 [DefaultValue (60)]
184 [Localizable (true)]
185 public int Width {
186 get { return width; }
187 set {
188 width = value;
189 if (owner != null)
190 owner.Redraw (true);
193 #endregion // Public Instance Properties
195 #region Public Methods
196 public virtual object Clone ()
198 ColumnHeader columnHeader = new ColumnHeader ();
199 columnHeader.text = text;
200 columnHeader.text_alignment = text_alignment;
201 columnHeader.width = width;
202 columnHeader.owner = owner;
203 columnHeader.column_rect = Rectangle.Empty;
204 return columnHeader;
207 public override string ToString ()
209 return string.Format ("ColumnHeader: Text: {0}", text);
211 #endregion // Public Methods
213 #region Protected Methods
214 protected override void Dispose (bool disposing)
216 base.Dispose (disposing);
218 #endregion // Protected Methods