Fix bug #395
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewRowPrePaintEventArgs.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 using System.ComponentModel;
27 using System.Drawing;
28
29 namespace System.Windows.Forms {
30
31         public class DataGridViewRowPrePaintEventArgs : HandledEventArgs {
32
33                 private DataGridView dataGridView;
34                 private Graphics graphics;
35                 private Rectangle clipBounds;
36                 private Rectangle rowBounds;
37                 private int rowIndex;
38                 private DataGridViewElementStates rowState;
39                 private string errorText;
40                 private DataGridViewCellStyle inheritedRowStyle;
41                 private bool isFirstDisplayedRow;
42                 private bool isLastVisibleRow;
43                 private DataGridViewPaintParts paintParts;
44
45                 public DataGridViewRowPrePaintEventArgs (DataGridView dataGridView, Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, string errorText, DataGridViewCellStyle inheritedRowStyle, bool isFirstDisplayedRow, bool isLastVisibleRow) {
46                         this.dataGridView = dataGridView;
47                         this.graphics = graphics;
48                         this.clipBounds = clipBounds;
49                         this.rowBounds = rowBounds;
50                         this.rowIndex = rowIndex;
51                         this.rowState = rowState;
52                         this.errorText = errorText;
53                         this.inheritedRowStyle = inheritedRowStyle;
54                         this.isFirstDisplayedRow = isFirstDisplayedRow;
55                         this.isLastVisibleRow = isLastVisibleRow;
56                 }
57
58                 public Rectangle ClipBounds {
59                         get { return clipBounds; }
60                         set { clipBounds = value; }
61                 }
62
63                 public string ErrorText {
64                         get { return errorText; }
65                 }
66
67                 public Graphics Graphics {
68                         get { return graphics; }
69                 }
70
71                 public DataGridViewCellStyle InheritedRowStyle {
72                         get { return inheritedRowStyle; }
73                 }
74
75                 public bool IsFirstDisplayedRow {
76                         get { return isFirstDisplayedRow; }
77                 }
78
79                 public bool IsLastVisibleRow {
80                         get { return isLastVisibleRow; }
81                 }
82
83                 public DataGridViewPaintParts PaintParts {
84                         get { return paintParts; }
85                         set { paintParts = value; }
86                 }
87
88                 public Rectangle RowBounds {
89                         get { return rowBounds; }
90                 }
91
92                 public int RowIndex {
93                         get { return rowIndex; }
94                 }
95
96                 public DataGridViewElementStates State {
97                         get { return rowState; }
98                 }
99
100                 public void DrawFocus (Rectangle bounds, bool cellsPaintSelectionBackground) {
101                         if (rowIndex < 0 || rowIndex >= dataGridView.Rows.Count)
102                                 throw new InvalidOperationException ("Invalid RowIndex.");
103
104                         DataGridViewRow row = dataGridView.GetRowInternal (rowIndex);
105
106                         row.PaintCells (graphics, clipBounds, bounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow, DataGridViewPaintParts.Focus);
107                 }
108
109                 public void PaintCells (Rectangle clipBounds, DataGridViewPaintParts paintParts)
110                 {
111                         if (rowIndex < 0 || rowIndex >= dataGridView.Rows.Count)
112                                 throw new InvalidOperationException ("Invalid RowIndex.");
113
114                         DataGridViewRow row = dataGridView.GetRowInternal (rowIndex);
115
116                         row.PaintCells (graphics, clipBounds, rowBounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow, paintParts);
117                 }
118
119                 public void PaintCellsBackground (Rectangle clipBounds, bool cellsPaintSelectionBackground)
120                 {
121                         if (cellsPaintSelectionBackground)
122                                 PaintCells (clipBounds, DataGridViewPaintParts.All);
123                         else
124                                 PaintCells (clipBounds, DataGridViewPaintParts.All & ~DataGridViewPaintParts.SelectionBackground);
125                 }
126
127                 public void PaintCellsContent (Rectangle clipBounds)
128                 {
129                         PaintCells (clipBounds, DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground);
130                 }
131
132                 public void PaintHeader (bool paintSelectionBackground)
133                 {
134                         if (paintSelectionBackground)
135                                 PaintHeader (DataGridViewPaintParts.All);
136                         else
137                                 PaintHeader (DataGridViewPaintParts.All & ~DataGridViewPaintParts.SelectionBackground);
138                 }
139
140                 public void PaintHeader (DataGridViewPaintParts paintParts)
141                 {
142                         if (rowIndex < 0 || rowIndex >= dataGridView.Rows.Count)
143                                 throw new InvalidOperationException ("Invalid RowIndex.");
144
145                         DataGridViewRow row = dataGridView.GetRowInternal (rowIndex);
146                         
147                         row.PaintHeader (graphics, clipBounds, rowBounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow, paintParts);
148                 }
149         }
150 }