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) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
31 using System.ComponentModel;
33 namespace System.Windows.Forms {
35 public class DataGridViewColumnHeaderCell : DataGridViewHeaderCell {
37 private SortOrder sortGlyphDirection = SortOrder.None;
38 private object header_text;
40 public DataGridViewColumnHeaderCell () {
43 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
44 public SortOrder SortGlyphDirection {
45 get { return sortGlyphDirection; }
46 set { sortGlyphDirection = value; }
49 public override object Clone () {
50 return MemberwiseClone();
53 public override ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex) {
55 throw new ArgumentOutOfRangeException("RowIndex is not -1");
57 if (base.ContextMenuStrip != null) {
58 return base.ContextMenuStrip;
60 return base.GetInheritedContextMenuStrip(rowIndex); //////////////////////////////
63 public override DataGridViewCellStyle GetInheritedStyle (DataGridViewCellStyle inheritedCellStyle, int rowIndex, bool includeColors) {
65 DataGridViewCellStyle result;
70 result = DataGridView.ColumnHeadersDefaultCellStyle;
76 public override string ToString () {
77 return GetType().Name;
80 protected override AccessibleObject CreateAccessibilityInstance () {
81 return new DataGridViewColumnHeaderCellAccessibleObject(this);
84 protected override object GetClipboardContent (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format) {
89 throw new ArgumentOutOfRangeException ("rowIndex");
91 value = GetValue (rowIndex) as string;
93 string table_prefix = string.Empty, cell_prefix = string.Empty, row_prefix = string.Empty;
94 string table_suffix = string.Empty, cell_suffix = string.Empty, row_suffix = string.Empty;
96 if (format == DataFormats.UnicodeText || format == DataFormats.Text) {
97 if (lastCell && !inLastRow)
98 cell_suffix = Environment.NewLine;
101 } else if (format == DataFormats.CommaSeparatedValue) {
102 if (lastCell && !inLastRow)
103 cell_suffix = Environment.NewLine;
106 } else if (format == DataFormats.Html) {
108 table_prefix = "<TABLE>";
109 row_prefix = "<THEAD>";
112 cell_prefix = "<TH>";
113 cell_suffix = "</TH>";
116 row_suffix = "</THEAD>";
118 table_suffix = "</TABLE>";
130 value = string.Empty;
132 value = table_prefix + row_prefix + cell_prefix + value + cell_suffix + row_suffix + table_suffix;
138 protected override Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
139 return new Rectangle();
142 protected override Size GetPreferredSize (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) {
143 throw new NotImplementedException();
146 protected override object GetValue (int rowIndex) {
147 if (header_text != null)
150 if (OwningColumn != null && !OwningColumn.HeaderTextSet)
151 return OwningColumn.Name;
156 [MonoTODO ("Paint sort arrows")]
157 protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
159 DataGridViewPaintParts pre = DataGridViewPaintParts.Background | DataGridViewPaintParts.SelectionBackground;
160 pre = pre & paintParts;
162 base.Paint (graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, pre);
165 if ((paintParts & DataGridViewPaintParts.ContentForeground) == DataGridViewPaintParts.ContentForeground) {
166 Color color = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
168 TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.TextBoxControl;
170 Rectangle contentbounds = cellBounds;
171 contentbounds.Height -= 2;
172 contentbounds.Width -= 2;
174 if (formattedValue != null)
175 TextRenderer.DrawText (graphics, formattedValue.ToString (), cellStyle.Font, contentbounds, color, flags);
179 DataGridViewPaintParts post = DataGridViewPaintParts.Border;
180 post = post & paintParts;
182 base.Paint (graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, post);
185 protected override bool SetValue (int rowIndex, object value) {
190 protected class DataGridViewColumnHeaderCellAccessibleObject : DataGridViewCellAccessibleObject {
192 public DataGridViewColumnHeaderCellAccessibleObject (DataGridViewColumnHeaderCell owner) : base (owner) {
195 public override Rectangle Bounds {
196 get { return base.Bounds; }
199 public override string DefaultAction {
200 get { return base.DefaultAction; }
203 public override string Name {
204 get { return base.Name; }
207 public override AccessibleObject Parent {
208 get { return base.Parent; }
211 public override AccessibleRole Role {
212 get { return base.Role; }
215 public override AccessibleStates State {
216 get { return base.State; }
219 public override string Value {
220 get { return base.Value; }
223 public override void DoDefaultAction () {
224 base.DoDefaultAction();
227 public override AccessibleObject Navigate (AccessibleNavigation navigationDirection) {
228 return base.Navigate(navigationDirection);
231 public override void Select (AccessibleSelection flags)