* ListView.cs: When doing layout calculations don't use a ref
[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 #if NET_2_0\r
28 \r
29 using System;\r
30 using System.Collections.Generic;\r
31 using System.ComponentModel;\r
32 using System.Text;\r
33 using System.Drawing;\r
34 \r
35 namespace System.Windows.Forms\r
36 {\r
37         public class DataGridViewLinkColumn : DataGridViewColumn\r
38         {\r
39                 \r
40                 public DataGridViewLinkColumn ()\r
41                 {\r
42                         base.CellTemplate = new DataGridViewLinkCell ();\r
43                 }\r
44 \r
45                 public override object Clone ()\r
46                 {\r
47                         DataGridViewLinkColumn clone = (DataGridViewLinkColumn)base.Clone ();\r
48                         clone.CellTemplate = (DataGridViewCell) this.CellTemplate.Clone ();\r
49                         return clone;\r
50                 }\r
51 \r
52                 public override string ToString ()\r
53                 {\r
54                         return base.ToString ();\r
55                 }\r
56 \r
57                 #region private fields\r
58 \r
59                 private string text = string.Empty;\r
60 \r
61                 #endregion\r
62 \r
63                 #region Public Properties\r
64 \r
65                 public Color ActiveLinkColor {\r
66                         get {\r
67                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
68                                 if (template == null)\r
69                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
70                                 return template.ActiveLinkColor; \r
71                         }\r
72                         set {\r
73                                 if (this.ActiveLinkColor == value) \r
74                                         return;\r
75 \r
76                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
77                                 if (template == null)\r
78                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
79 \r
80                                 template.ActiveLinkColor = value;\r
81 \r
82                                 foreach (DataGridViewRow row in DataGridView.Rows) {\r
83                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
84                                         if (cell != null)\r
85                                                 cell.ActiveLinkColor = value;\r
86                                 }\r
87                                 DataGridView.InvalidateColumn (Index);\r
88 \r
89                         }\r
90                 }\r
91 \r
92                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
93                 [Browsable (false)]\r
94                 public override DataGridViewCell CellTemplate {\r
95                         get { return base.CellTemplate; }\r
96                         set { base.CellTemplate = value as DataGridViewLinkCell; }\r
97                 }\r
98 \r
99 \r
100                 [DefaultValue (LinkBehavior.SystemDefault)]\r
101                 public LinkBehavior LinkBehavior {\r
102                         get     {\r
103                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
104                                 if (template == null)\r
105                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
106                                 return template.LinkBehavior;\r
107                         }\r
108                         set     {\r
109                                 if (this.LinkBehavior == value) \r
110                                         return;\r
111 \r
112                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
113                                 if (template == null)\r
114                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
115 \r
116                                 template.LinkBehavior = value;\r
117                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
118                                 {\r
119                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
120                                         if (cell != null)\r
121                                                 cell.LinkBehavior = value;\r
122                                 }\r
123                                 DataGridView.InvalidateColumn (Index);\r
124                         }\r
125                 }\r
126 \r
127                 public Color LinkColor {\r
128                         get     {\r
129                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
130                                 if (template == null)\r
131                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
132                                 return template.LinkColor;\r
133                         }\r
134                         set     {\r
135                                 if (this.LinkColor == value)\r
136                                         return;\r
137                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
138                                 if (template == null)\r
139                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
140                                 template.LinkColor = value;\r
141                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
142                                 {\r
143                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
144                                         if (cell != null)\r
145                                                 cell.LinkColor = value;\r
146                                 }\r
147                                 DataGridView.InvalidateColumn (Index);\r
148                         }\r
149                 }\r
150                 [MonoTODO]\r
151                 [DefaultValue ((string) null)]\r
152                 public string Text {\r
153                         get {\r
154                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
155                                 if (template == null)\r
156                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
157                                 return text;\r
158                         }\r
159                         set {\r
160                                 if (this.Text == value)\r
161                                         return;\r
162                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
163                                 if (template == null)\r
164                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
165                                 //TODO : sets the Text property of every cell in the column \r
166                                 //TODO only if UseColumnTextForLinkValue is true\r
167                                 text = value;\r
168                                 DataGridView.InvalidateColumn (Index);\r
169                         }\r
170                 }\r
171 \r
172                 //When TrackVisitedState is true, the VisitedLinkColor property value is used to display links that have already been visited.\r
173                 [DefaultValue (true)]\r
174                 public bool TrackVisitedState {\r
175                         get {\r
176                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
177                                 if (template == null)\r
178                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
179                                 return template.TrackVisitedState;\r
180                         }\r
181                         set {\r
182                                 if (this.TrackVisitedState == value)\r
183                                         return;\r
184                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
185                                 if (template == null)\r
186                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
187                                 template.TrackVisitedState = value;\r
188                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
189                                 {\r
190                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
191                                         if (cell != null)\r
192                                                 cell.TrackVisitedState = value;\r
193                                 }\r
194                                 DataGridView.InvalidateColumn (Index);\r
195                         }\r
196                 }\r
197 \r
198                 // 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
199                 [DefaultValue (false)]\r
200                 public bool UseColumnTextForLinkValue {\r
201                         get {\r
202                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
203                                 if (template == null)\r
204                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
205                                 return template.UseColumnTextForLinkValue;\r
206                         }\r
207                         set {\r
208                                 if (this.UseColumnTextForLinkValue == value)\r
209                                         return;\r
210                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
211                                 if (template == null)\r
212                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
213                                 template.UseColumnTextForLinkValue = value;\r
214                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
215                                 {\r
216                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
217                                         if (cell != null)\r
218                                                 cell.UseColumnTextForLinkValue = value;\r
219                                 }\r
220                                 DataGridView.InvalidateColumn (Index);\r
221                         }\r
222                 }\r
223 \r
224                 //If the TrackVisitedState property is set to false, the VisitedLinkColor property is ignored.\r
225                 public Color VisitedLinkColor {\r
226                         get {\r
227                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
228                                 if (template == null)\r
229                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
230                                 return template.VisitedLinkColor;\r
231                         }\r
232                         set {\r
233                                 if (this.VisitedLinkColor == value)\r
234                                         return;\r
235                                 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;\r
236                                 if (template == null)\r
237                                         throw new InvalidOperationException ("CellTemplate is null when getting this property.");\r
238                                 template.VisitedLinkColor = value;\r
239                                 foreach (DataGridViewRow row in DataGridView.Rows)\r
240                                 {\r
241                                         DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;\r
242                                         if (cell != null)\r
243                                                 cell.VisitedLinkColor = value;\r
244                                 }\r
245                                 DataGridView.InvalidateColumn (Index);\r
246                         }\r
247                 }\r
248                 #endregion\r
249         }\r
250 }\r
251 \r
252 #endif