Xamarin-4959: Fix copy of clipboard data after app exits
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DrawListViewSubItemEventArgs.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) 2004-2005 Novell, Inc.
21 //
22 // Authors:
23 //      Alan McGovern (alan.mcgovern@gmail.com)
24 //
25
26
27 using System.Drawing;
28
29 namespace System.Windows.Forms
30 {
31     public class DrawListViewSubItemEventArgs : EventArgs
32     {
33         #region Private Fields
34
35         private Rectangle bounds;
36         private int columnIndex;
37                 private bool drawDefault;
38         private Graphics graphics;
39         private ColumnHeader header;
40         private ListViewItem item;
41         private int itemIndex;
42         private ListViewItemStates itemState;
43         private ListViewItem.ListViewSubItem subItem;
44
45         #endregion Private Fields
46
47
48         #region Properties
49
50         public Rectangle Bounds {
51             get { return bounds; }
52         }
53
54         public int ColumnIndex {
55             get { return columnIndex; }
56         }
57
58         public bool DrawDefault {
59             get { return drawDefault; }
60             set { drawDefault = value; }
61         }
62
63         public Graphics Graphics {
64             get { return graphics; }
65         }
66
67         public ColumnHeader Header {
68             get { return header; }
69         }
70
71         public ListViewItem Item {
72             get { return item; }
73         }
74
75         public int ItemIndex {
76             get { return itemIndex; }
77         }
78
79         public ListViewItemStates ItemState {
80             get { return itemState; }
81         }
82
83         public ListViewItem.ListViewSubItem SubItem {
84             get { return this.subItem; }
85         }
86
87         #endregion Properties 
88
89
90         #region Constructors
91
92         public DrawListViewSubItemEventArgs(Graphics graphics, Rectangle bounds,
93                                             ListViewItem item, ListViewItem.ListViewSubItem subItem,
94                                             int itemIndex, int columnIndex,
95                                             ColumnHeader header, ListViewItemStates itemState)
96         {
97             this.bounds = bounds;
98             this.columnIndex = columnIndex;
99             this.graphics = graphics;
100             this.header = header;
101             this.item = item;
102             this.itemIndex = itemIndex;
103             this.itemState = itemState;
104             this.subItem = subItem;
105         }
106
107         #endregion Constructors
108
109
110         #region Public Methods
111
112         public void DrawBackground ()
113         {
114                 graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (subItem.BackColor), bounds);
115         }
116
117         public void DrawFocusRectangle (Rectangle bounds)
118         {
119                 if ((itemState & ListViewItemStates.Focused) != 0) {
120                         Rectangle rect = new Rectangle (bounds.X + 1, bounds.Y + 1, bounds.Width - 1, bounds.Height - 1);
121                         ThemeEngine.Current.CPDrawFocusRectangle (graphics, rect, subItem.ForeColor, subItem.BackColor);
122                 }
123         }
124
125         public void DrawText ()
126         {
127                 DrawText (TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter);
128         }
129
130         public void DrawText (TextFormatFlags flags)
131         {
132                 // Text adjustments
133                 Rectangle text_bounds = new Rectangle (bounds.X + 8, bounds.Y, bounds.Width - 13, bounds.Height);
134                 TextRenderer.DrawText (graphics, subItem.Text, subItem.Font, text_bounds, subItem.ForeColor, flags);
135         }
136
137         #endregion Public Methods
138     }
139 }