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 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
;
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
)
76 this.text_alignment
= alignment
;
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.
90 get { return this.column_rect.X; }
91 set { this.column_rect.X = value; }
95 get { return this.column_rect.Y; }
96 set { this.column_rect.Y = value; }
100 get { return this.column_rect.Width; }
101 set { this.column_rect.Width = value; }
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
;
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
;
132 this.column_rect
.Width
= width
;
134 this.column_rect
.Height
= owner
.Font
.Height
;
136 this.column_rect
.Height
= ThemeEngine
.Current
.DefaultFont
.Height
;
138 else if (this.Index
!= -1)
139 this.column_rect
.Size
= owner
.GetChildColumnSize (this.Index
);
141 this.column_rect
.Size
= Size
.Empty
;
143 #endregion // Private Internal Methods Properties
145 #region Public Instance Properties
149 if (owner
!= null && owner
.Columns
!= null
150 && owner
.Columns
.Contains (this)) {
151 return owner
.Columns
.IndexOf (this);
158 public ListView ListView
{
159 get { return owner; }
172 [DefaultValue (HorizontalAlignment
.Left
)]
174 public HorizontalAlignment TextAlign
{
175 get { return text_alignment; }
177 text_alignment
= value;
186 get { return width; }
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
;
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