[winforms] Pass 2 of removing NET_2_0 from winforms
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewLinkColumn.cs
1 // Permission is hereby granted, free of charge, to any person obtaining\r
2 // a copy of this software and associated documentation files (the\r
3 // "Software"), to deal in the Software without restriction, including\r
4 // without limitation the rights to use, copy, modify, merge, publish,\r
5 // distribute, sublicense, and/or sell copies of the Software, and to\r
6 // permit persons to whom the Software is furnished to do so, subject to\r
7 // the following conditions:\r
8 // \r
9 // The above copyright notice and this permission notice shall be\r
10 // included in all copies or substantial portions of the Software.\r
11 // \r
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
19 //\r
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)\r
21 //\r
22 // Authors:\r
23 //      olivier Dufour  olivier.duff@free.fr\r
24 //\r
25 //\r
26 \r
27 using System;\r
28 using System.Collections.Generic;\r
29 using System.ComponentModel;\r
30 using System.Text;\r
31 using System.Drawing;\r
32 \r
33 namespace System.Windows.Forms\r
34 {\r
35         [ToolboxBitmap ("")]\r
36         public class DataGridViewLinkColumn : DataGridViewColumn\r
37         {\r
38                 \r
39                 public DataGridViewLinkColumn ()\r
40                 {\r
41                         base.CellTemplate = new DataGridViewLinkCell ();\r
42                 }\r
43 \r
44                 public override object Clone ()\r
45                 {\r
46                         DataGridViewLinkColumn clone = (DataGridViewLinkColumn)base.Clone ();\r
47                         clone.CellTemplate = (DataGridViewCell) this.CellTemplate.Clone ();\r
48                         return clone;\r
49                 }\r
50 \r
51                 public override string ToString ()\r
52                 {\r
53                         return base.ToString ();\r
54                 }\r
55 \r
56                 #region private fields\r
57 \r
58                 private string text = string.Empty;\r
59 \r
60                 #endregion\r
61 \r
62                 #region Public Properties\r
63 \r
64                 public Color ActiveLinkColor {\r
65                         get {\r
66                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
67                                 if (template == null)\r
68                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
69                                 return template.ActiveLinkColor; \r
70                         }\r
71                         set {\r
72                                 if (this.ActiveLinkColor == value) \r
73                                         return;\r
74 \r
75                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
76                                 if (template == null)\r
77                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
78 \r
79                                 template.ActiveLinkColor = value;\r
80 \r
81                                 foreach (DataGridViewRow row in DataGridView.Rows) {\r
82                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
83                                         if (cell != null)\r
84                                                 cell.ActiveLinkColor = value;\r
85                                 }\r
86                                 DataGridView.InvalidateColumn (Index);\r
87 \r
88                         }\r
89                 }\r
90 \r
91                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
92                 [Browsable (false)]\r
93                 public override DataGridViewCell CellTemplate {\r
94                         get { return base.CellTemplate; }\r
95                         set { base.CellTemplate = value as DataGridViewLinkCell; }\r
96                 }\r
97 \r
98 \r
99                 [DefaultValue (LinkBehavior.SystemDefault)]\r
100                 public LinkBehavior LinkBehavior {\r
101                         get     {\r
102                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
103                                 if (template == null)\r
104                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
105                                 return template.LinkBehavior;\r
106                         }\r
107                         set     {\r
108                                 if (this.LinkBehavior == value) \r
109                                         return;\r
110 \r
111                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
112                                 if (template == null)\r
113                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
114 \r
115                                 template.LinkBehavior = value;\r
116                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
117                                 {\r
118                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
119                                         if (cell != null)\r
120                                                 cell.LinkBehavior = value;\r
121                                 }\r
122                                 DataGridView.InvalidateColumn (Index);\r
123                         }\r
124                 }\r
125 \r
126                 public Color LinkColor {\r
127                         get     {\r
128                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
129                                 if (template == null)\r
130                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
131                                 return template.LinkColor;\r
132                         }\r
133                         set     {\r
134                                 if (this.LinkColor == value)\r
135                                         return;\r
136                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
137                                 if (template == null)\r
138                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
139                                 template.LinkColor = value;\r
140                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
141                                 {\r
142                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
143                                         if (cell != null)\r
144                                                 cell.LinkColor = value;\r
145                                 }\r
146                                 DataGridView.InvalidateColumn (Index);\r
147                         }\r
148                 }\r
149                 [MonoInternalNote ("")]\r
150                 [DefaultValue ((string) null)]\r
151                 public string Text {\r
152                         get {\r
153                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
154                                 if (template == null)\r
155                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
156                                 return text;\r
157                         }\r
158                         set {\r
159                                 if (this.Text == value)\r
160                                         return;\r
161                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
162                                 if (template == null)\r
163                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
164                                 //TODO : sets the Text property of every cell in the column \r
165                                 //TODO only if UseColumnTextForLinkValue is true\r
166                                 text = value;\r
167                                 DataGridView.InvalidateColumn (Index);\r
168                         }\r
169                 }\r
170 \r
171                 //When TrackVisitedState is true, the VisitedLinkColor property value is used to display links that have already been visited.\r
172                 [DefaultValue (true)]\r
173                 public bool TrackVisitedState {\r
174                         get {\r
175                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
176                                 if (template == null)\r
177                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
178                                 return template.TrackVisitedState;\r
179                         }\r
180                         set {\r
181                                 if (this.TrackVisitedState == value)\r
182                                         return;\r
183                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
184                                 if (template == null)\r
185                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
186                                 template.TrackVisitedState = value;\r
187                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
188                                 {\r
189                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
190                                         if (cell != null)\r
191                                                 cell.TrackVisitedState = value;\r
192                                 }\r
193                                 DataGridView.InvalidateColumn (Index);\r
194                         }\r
195                 }\r
196 \r
197                 // true if the Text property value is displayed as the link text; false if the cell FormattedValue property value is displayed as the link text. The default is false.\r
198                 [DefaultValue (false)]\r
199                 public bool UseColumnTextForLinkValue {\r
200                         get {\r
201                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
202                                 if (template == null)\r
203                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
204                                 return template.UseColumnTextForLinkValue;\r
205                         }\r
206                         set {\r
207                                 if (this.UseColumnTextForLinkValue == value)\r
208                                         return;\r
209                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
210                                 if (template == null)\r
211                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
212                                 template.UseColumnTextForLinkValue = value;\r
213                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
214                                 {\r
215                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
216                                         if (cell != null)\r
217                                                 cell.UseColumnTextForLinkValue = value;\r
218                                 }\r
219                                 DataGridView.InvalidateColumn (Index);\r
220                         }\r
221                 }\r
222 \r
223                 //If the TrackVisitedState property is set to false, the VisitedLinkColor property is ignored.\r
224                 public Color VisitedLinkColor {\r
225                         get {\r
226                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
227                                 if (template == null)\r
228                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
229                                 return template.VisitedLinkColor;\r
230                         }\r
231                         set {\r
232                                 if (this.VisitedLinkColor == value)\r
233                                         return;\r
234                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
235                                 if (template == null)\r
236                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
237                                 template.VisitedLinkColor = value;\r
238                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
239                                 {\r
240                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
241                                         if (cell != null)\r
242                                                 cell.VisitedLinkColor = value;\r
243                                 }\r
244                                 DataGridView.InvalidateColumn (Index);\r
245                         }\r
246                 }\r
247                 #endregion\r
248         }\r
249 }\r