Fix bug #395
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewCellPaintingEventArgs.cs
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.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26
27 using System.ComponentModel;
28 using System.Drawing;
29
30 namespace System.Windows.Forms {
31
32         public class DataGridViewCellPaintingEventArgs : HandledEventArgs {
33
34                 private DataGridView dataGridView;
35                 private Graphics graphics;
36                 private Rectangle clipBounds; 
37                 private Rectangle cellBounds;
38                 private int rowIndex;
39                 private int columnIndex;
40                 private DataGridViewElementStates cellState;
41                 private object cellValue;
42                 private object formattedValue;
43                 private string errorText;
44                 private DataGridViewCellStyle cellStyle;
45                 private DataGridViewAdvancedBorderStyle advancedBorderStyle;
46                 private DataGridViewPaintParts paintParts;
47
48                 public DataGridViewCellPaintingEventArgs (DataGridView dataGridView, Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, int columnIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
49                         this.dataGridView = dataGridView;
50                         this.graphics = graphics;
51                         this.clipBounds = clipBounds;
52                         this.cellBounds = cellBounds;
53                         this.rowIndex = rowIndex;
54                         this.columnIndex = columnIndex;
55                         this.cellState = cellState;
56                         this.cellValue = value;
57                         this.formattedValue = formattedValue;
58                         this.errorText = errorText;
59                         this.cellStyle = cellStyle;
60                         this.advancedBorderStyle = advancedBorderStyle;
61                         this.paintParts = paintParts;
62                 }
63
64                 public DataGridViewAdvancedBorderStyle AdvancedBorderStyle {
65                         get { return advancedBorderStyle; }
66                 }
67
68                 public Rectangle CellBounds {
69                         get { return cellBounds; }
70                 }
71
72                 public DataGridViewCellStyle CellStyle {
73                         get { return cellStyle; }
74                 }
75
76                 public Rectangle ClipBounds {
77                         get { return clipBounds; }
78                 }
79
80                 public int ColumnIndex {
81                         get { return columnIndex; }
82                 }
83
84                 public string ErrorText {
85                         get { return errorText; }
86                 }
87
88                 public object FormattedValue {
89                         get { return formattedValue; }
90                 }
91
92                 public Graphics Graphics {
93                         get { return graphics; }
94                 }
95
96                 public DataGridViewPaintParts PaintParts {
97                         get { return paintParts; }
98                 }
99
100                 public int RowIndex {
101                         get { return rowIndex; }
102                 }
103
104                 public DataGridViewElementStates State {
105                         get { return cellState; }
106                 }
107
108                 public object Value {
109                         get { return cellValue; }
110                 }
111
112                 public void Paint (Rectangle clipBounds, DataGridViewPaintParts paintParts) {
113                         if (rowIndex < -1 || rowIndex >= dataGridView.Rows.Count)
114                                 throw new InvalidOperationException("Invalid \"RowIndex.\"");
115                         if (columnIndex < -1 || columnIndex >= dataGridView.Columns.Count)
116                                 throw new InvalidOperationException("Invalid \"ColumnIndex.\"");
117
118                         DataGridViewCell cell;
119
120                         if (rowIndex == -1 && columnIndex == -1)
121                                 cell = dataGridView.TopLeftHeaderCell;
122                         else if (rowIndex == -1)
123                                 cell = dataGridView.Columns[columnIndex].HeaderCell;
124                         else if (columnIndex == -1)
125                                 cell = dataGridView.Rows[rowIndex].HeaderCell;
126                         else
127                                 cell = dataGridView.Rows[rowIndex].Cells[columnIndex];
128
129                         cell.PaintInternal (graphics, clipBounds, cellBounds, rowIndex, cellState, Value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);                               
130                 }
131
132                 public void PaintBackground (Rectangle clipBounds, bool cellsPaintSelectionBackground)
133                 {
134                         Paint (clipBounds, DataGridViewPaintParts.Background | DataGridViewPaintParts.Border);
135                 }
136                         
137                 [MonoInternalNote ("Needs row header cell edit pencil glyph")]
138                 public void PaintContent (Rectangle clipBounds)
139                 {
140                         Paint (clipBounds, DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground);
141                 }
142
143         }
144
145 }