Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Web.DataVisualization / Common / Utilities / KeywordsRegistry.cs
1 //-------------------------------------------------------------
2 // <copyright company=\92Microsoft Corporation\92>
3 //   Copyright © Microsoft Corporation. All Rights Reserved.
4 // </copyright>
5 //-------------------------------------------------------------
6 // @owner=alexgor, deliant
7 //=================================================================
8 //  File:               KeywordsRegistry.cs
9 //
10 //  Namespace:  System.Web.UI.WebControls[Windows.Forms].Charting.Utilities
11 //
12 //      Classes:        KeywordsRegistry, KeywordInfo
13 //
14 //  Purpose:    A registry that keeps track of all available 
15 //                              keywords and name of the objects and properties
16 //                              where they can be used.
17 //
18 //  Formatting Keywords Overview:
19 //  -----------------------------
20 //  A Formatting Keyword is a specially formatted character sequence 
21 //  that gets replaced by an associated Chart Series value, or 
22 //  calculated value. Keywords can be used with most string properties 
23 //  of Series and DataPoint objects. 
24 //  
25 //  Here is an example of setting series labels so that the first 
26 //  line will display the Y value and the second line displays 
27 //  the X value. 
28 //      
29 //      Chart1.Series["Series1"].Label = "Y = #VALY\nX = #VALX";
30 //  
31 //  Series label in this case will look like this: 
32 //  
33 //      Y = 45.78
34 //      X = 456
35 //  
36 //  An optional format string can be added after the keyword. 
37 //  For example, when you set the Format option to Percent for 
38 //  the first Y value, the resulting keyword produced is "#VALY{P}".  
39 //  You can also apply format strings in code-behind using the same 
40 //  nomenclature; you do this by following the keyword with a format 
41 //  specifier enclosed in braces.  For information concerning the 
42 //  types of formatting that can be used, see the Formatting Types 
43 //  topic in the MSDN library.
44 //
45 //      Reviewed:       AG - Microsoft 5, 2007
46 //
47 //===================================================================
48
49
50 #region Used Namespaces
51
52 using System;
53 using System.Drawing;
54 using System.Collections;
55 using System.ComponentModel;
56 using System.ComponentModel.Design;
57
58 #if Microsoft_CONTROL
59     using System.Windows.Forms.DataVisualization.Charting;
60     using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
61 #else
62 using System.Web.UI.DataVisualization.Charting;
63 using System.Web.UI.DataVisualization.Charting.ChartTypes;
64 #endif
65
66 #endregion
67
68 #if Microsoft_CONTROL
69     namespace System.Windows.Forms.DataVisualization.Charting.Utilities
70 #else // Microsoft_CONTROL
71         namespace System.Web.UI.DataVisualization.Charting.Utilities
72 #endif // Microsoft_CONTROL
73 {
74     /// <summary>
75     /// KeywordName class contains constant strings defining
76     /// names of all keywords used in the data point and series classes.
77     /// </summary>
78         internal static class KeywordName
79         {
80             #region Keyword Names
81
82             internal const string Index = "#INDEX";
83             internal const string ValX = "#VALX";
84             internal const string ValY = "#VALY";
85             internal const string Val = "#VAL";
86             internal const string Total = "#TOTAL";
87             internal const string Percent = "#PERCENT";
88             internal const string Label = "#LABEL";
89             internal const string AxisLabel = "#AXISLABEL";
90             internal const string LegendText = "#LEGENDTEXT";
91             internal const string SeriesName = "#SERIESNAME";
92             internal const string Ser = "#SER";
93             internal const string Avg = "#AVG";
94             internal const string Max = "#MAX";
95             internal const string Min = "#MIN";
96             internal const string Last = "#LAST";
97             internal const string First = "#FIRST";
98             internal const string CustomProperty = "#CUSTOMPROPERTY";
99
100             #endregion // Keyword Names
101         }
102
103         /// <summary>
104     /// KeywordRegistry class stores information about all 
105     /// chart formatting keywords. It automatically registers 
106     /// all known keywords when object is constructed. This 
107     /// data is exposed as ArrayList through the \91registeredKeywords\92 
108     /// field. Each item in this ArrayList is a KeywordInfo 
109     /// object which describes a single formatting keyword.
110         /// </summary>
111         internal class KeywordsRegistry : IServiceProvider
112         {
113                 #region Fields
114
115                 // List of registered keywords
116                 internal        ArrayList               registeredKeywords = new ArrayList();
117
118                 #endregion
119
120                 #region Constructor and Services
121
122                 /// <summary>
123                 /// Keywords registry public constructor.
124                 /// </summary>
125                 public KeywordsRegistry()
126                 {
127                         // Register Keywords used in the chart
128                         RegisterKeywords();
129                 }
130
131                 /// <summary>
132                 /// Returns Keywords registry service object.
133                 /// </summary>
134                 /// <param name="serviceType">Service type to get.</param>
135                 /// <returns>Custom properties registry service.</returns>
136                 [EditorBrowsableAttribute(EditorBrowsableState.Never)]
137                 object IServiceProvider.GetService(Type serviceType)
138                 {
139                         if(serviceType == typeof(KeywordsRegistry))
140                         {
141                                 return this;
142                         }
143                         throw (new ArgumentException( SR.ExceptionKeywordsRegistryUnsupportedType(serviceType.ToString())));
144                 }
145
146                 #endregion
147
148                 #region Keywords Registering methods
149
150                 /// <summary>
151                 /// Registers all chart formatting keywords.
152                 /// </summary>
153                 private void RegisterKeywords()
154                 {
155             string seriesPointSupportedProperties = "Text,Label,LabelMapAreaAttributes,ToolTip,Url,LabelToolTip,MapAreaAttributes,AxisLabel,LegendToolTip,LegendMapAreaAttributes,LegendUrl,LegendText";
156
157                         // #INDEX keyword
158                         this.Register(
159                 SR.DescriptionKeyWordNameIndexDataPoint,
160                                 KeywordName.Index,
161                                 string.Empty,
162                 SR.DescriptionKeyWordIndexDataPoint2,
163                                 "DataPoint",
164                                 seriesPointSupportedProperties,
165                                 false,
166                                 false);
167
168                         // #VALX keyword
169                         this.Register(
170                 SR.DescriptionKeyWordNameXValue,
171                                 KeywordName.ValX,
172                                 string.Empty,
173                 SR.DescriptionKeyWordXValue,
174                                 "Series,DataPoint,Annotation,LegendCellColumn",
175                                 seriesPointSupportedProperties,
176                                 true,
177                                 false);
178
179                         // #VALY keyword
180                         this.Register(
181                 SR.DescriptionKeyWordNameYValue,
182                                 KeywordName.Val,
183                                 string.Empty,
184                 SR.DescriptionKeyWordYValue,
185                                 "Series,DataPoint,Annotation,LegendCellColumn,LegendCellColumn",
186                                 seriesPointSupportedProperties,
187                                 true,
188                                 true);
189
190                         // #TOTAL keyword
191                         this.Register(
192                 SR.DescriptionKeyWordNameTotalYValues,
193                                 KeywordName.Total,
194                                 string.Empty,
195                 SR.DescriptionKeyWordTotalYValues,
196                                 "Series,DataPoint,Annotation,LegendCellColumn",
197                                 seriesPointSupportedProperties,
198                                 true,
199                                 false);
200
201                         // #PERCENT keyword
202                         this.Register(
203                 SR.DescriptionKeyWordNameYValuePercentTotal,
204                                 KeywordName.Percent,
205                                 string.Empty,
206                 SR.DescriptionKeyWordYValuePercentTotal,
207                                 "Series,DataPoint,Annotation,LegendCellColumn",
208                                 seriesPointSupportedProperties,
209                                 true,
210                                 true);
211
212                         // #INDEX keyword
213                         this.Register(
214                 SR.DescriptionKeyWordNameIndexTheDataPoint,
215                                 KeywordName.Index,
216                                 string.Empty,
217                 SR.DescriptionKeyWordIndexDataPoint,
218                                 "Series,DataPoint,Annotation,LegendCellColumn",
219                                 seriesPointSupportedProperties,
220                                 false,
221                                 false);
222
223                         // #LABEL keyword
224                         this.Register(
225                 SR.DescriptionKeyWordNameLabelDataPoint,
226                                 KeywordName.Label,
227                                 string.Empty,
228                 SR.DescriptionKeyWordLabelDataPoint,
229                                 "Series,DataPoint,Annotation,LegendCellColumn",
230                                 seriesPointSupportedProperties,
231                                 false,
232                                 false);
233
234                         // #AXISLABEL keyword
235                         this.Register(
236                 SR.DescriptionKeyWordNameAxisLabelDataPoint,
237                                 KeywordName.AxisLabel,
238                                 string.Empty,
239                 SR.DescriptionKeyWordAxisLabelDataPoint,
240                                 "Series,DataPoint,Annotation,LegendCellColumn",
241                                 seriesPointSupportedProperties,
242                                 false,
243                                 false);
244
245                         // #LEGENDTEXT keyword
246                         this.Register(
247                 SR.DescriptionKeyWordNameLegendText,
248                                 KeywordName.LegendText,
249                                 string.Empty,
250                 SR.DescriptionKeyWordLegendText,
251                                 "Series,DataPoint,Annotation,LegendCellColumn",
252                                 seriesPointSupportedProperties,
253                                 false,
254                                 false);
255
256                         // #SERIESNAME keyword
257                         this.Register(
258                 SR.DescriptionKeyWordNameSeriesName,
259                                 KeywordName.SeriesName,
260                                 KeywordName.Ser,
261                 SR.DescriptionKeyWordSeriesName,
262                                 "Series,DataPoint,Annotation,LegendCellColumn",
263                                 seriesPointSupportedProperties,
264                                 false,
265                                 false);
266
267                         // *************** NEW KEYWORDS in version 5.5 ***************
268
269                         // #AVG keyword
270                         this.Register(
271                 SR.DescriptionKeyWordNameAverageYValues,
272                                 KeywordName.Avg,
273                                 string.Empty,
274                 SR.DescriptionKeyWordAverageYValues,
275                                 "Series,DataPoint,Annotation,LegendCellColumn",
276                                 seriesPointSupportedProperties,
277                                 true,
278                                 true);
279
280                         // #MAX keyword
281                         this.Register(
282                 SR.DescriptionKeyWordNameMaximumYValues,
283                                 KeywordName.Max,
284                                 string.Empty,
285                 SR.DescriptionKeyWordMaximumYValues,
286                                 "Series,DataPoint,Annotation,LegendCellColumn",
287                                 seriesPointSupportedProperties,
288                                 true,
289                                 true);
290
291                         // #MIN keyword
292                         this.Register(
293                 SR.DescriptionKeyWordNameMinimumYValues,
294                                 KeywordName.Min,
295                                 string.Empty,
296                 SR.DescriptionKeyWordMinimumYValues,
297                                 "Series,DataPoint,Annotation,LegendCellColumn",
298                                 seriesPointSupportedProperties,
299                                 true,
300                                 true);
301
302                         // #LAST keyword
303                         this.Register(
304                 SR.DescriptionKeyWordNameLastPointYValue,
305                                 KeywordName.Last,
306                                 string.Empty,
307                 SR.DescriptionKeyWordLastPointYValue,
308                                 "Series,DataPoint,Annotation,LegendCellColumn",
309                                 seriesPointSupportedProperties,
310                                 true,
311                                 true);
312
313                         // #FIRST keyword
314                         this.Register(
315                 SR.DescriptionKeyWordNameFirstPointYValue,
316                                 KeywordName.First,
317                                 string.Empty,
318                 SR.DescriptionKeyWordFirstPointYValue,
319                                 "Series,DataPoint,Annotation,LegendCellColumn",
320                                 seriesPointSupportedProperties,
321                                 true,
322                                 true);
323                 }
324
325                 #endregion // Keywords Registering methods
326
327                 #region Registry methods
328
329         /// <summary>
330         /// Adds keyword information into the registry.
331         /// </summary>
332         /// <param name="name">Keyword full name.</param>
333         /// <param name="keyword">Keyword text.</param>
334         /// <param name="keywordAliases">Keyword alternative text.</param>
335         /// <param name="description">Keyword description.</param>
336         /// <param name="appliesToTypes">Comma separated list of applicable classes</param>
337         /// <param name="appliesToProperties">Comma separated list of applicable properties.</param>
338         /// <param name="supportsFormatting">True if formatting is supported.</param>
339         /// <param name="supportsValueIndex">True if different point Y values are supported.</param>
340                 public void Register(
341                         string name,
342                         string keyword,
343                         string keywordAliases,
344                         string description,
345                         string appliesToTypes,
346                         string appliesToProperties,
347                         bool supportsFormatting,
348                         bool supportsValueIndex)
349                 {
350                         // Create new keyword information object
351                         KeywordInfo keywordInfo = new KeywordInfo(
352                                 name,
353                                 keyword,
354                                 keywordAliases,
355                                 description,
356                                 appliesToTypes,
357                                 appliesToProperties,
358                                 supportsFormatting,
359                                 supportsValueIndex);
360
361                         // Add keyword information to the hash table
362                         registeredKeywords.Add(keywordInfo);
363                 }
364
365                 #endregion
366         }
367
368         /// <summary>
369     /// KeywordInfo class stores information about a single 
370     /// formatting keyword. This information includes Name, 
371     /// Description, list of data types and properties it 
372     /// applies to and other information.
373         /// </summary>
374     internal class KeywordInfo
375         {
376                 #region Public Fields
377
378                 /// <summary>
379                 /// Keyword full name.
380                 /// </summary>
381                 public  string                          Name = String.Empty;
382
383                 /// <summary>
384                 /// String that represent this keyword in the property (keyword).
385                 /// </summary>
386                 public  string                          Keyword = String.Empty;
387
388                 /// <summary>
389                 /// Comma separated strings that may alternatively represent this 
390                 /// keyword in the property.
391                 /// </summary>
392                 public  string                          KeywordAliases = String.Empty;
393
394                 /// <summary>
395                 /// Keyword description.
396                 /// </summary>
397                 public  string                          Description = String.Empty;
398
399                 /// <summary>
400                 /// Comma separated names of classes this keyword applies to.
401                 /// </summary>
402                 public  string                          AppliesToTypes = String.Empty;
403
404                 /// <summary>
405                 /// Comma separated names of properties this keyword applies to.
406                 /// </summary>
407                 public  string                          AppliesToProperties = String.Empty;
408
409                 /// <summary>
410                 /// True if keyword value can be formatted.
411                 /// </summary>
412                 public  bool                            SupportsFormatting = false;
413
414                 /// <summary>
415                 /// True if keyword can be used with different point Y values.
416                 /// </summary>
417                 public  bool                            SupportsValueIndex = false;
418
419                 #endregion // Public Fields
420
421                 #region Constructor
422
423         /// <summary>
424         /// Keyword information object constructor
425         /// </summary>
426         /// <param name="name">Keyword full name.</param>
427         /// <param name="keyword">Keyword text.</param>
428         /// <param name="keywordAliases">Keyword alternative text.</param>
429         /// <param name="description">Keyword description.</param>
430         /// <param name="appliesToTypes">Comma separated list of applicable classes</param>
431         /// <param name="appliesToProperties">Comma separated list of applicable properties.</param>
432         /// <param name="supportsFormatting">True if formatting is supported.</param>
433         /// <param name="supportsValueIndex">True if different point Y values are supported.</param>
434                 public KeywordInfo(
435                         string name,
436                         string keyword,
437                         string keywordAliases,
438                         string description,
439                         string appliesToTypes,
440                         string appliesToProperties,
441                         bool supportsFormatting,
442                         bool supportsValueIndex)
443                 {
444                         this.Name = name;
445                         this.Keyword = keyword;
446                         this.KeywordAliases = keywordAliases;
447                         this.Description = description;
448                         this.AppliesToTypes = appliesToTypes;
449                         this.AppliesToProperties = appliesToProperties;
450                         this.SupportsFormatting = supportsFormatting;
451                         this.SupportsValueIndex = supportsValueIndex;
452                 }
453
454                 #endregion // Constructor
455
456                 #region Methods
457
458                 /// <summary>
459                 /// Returns a String that represents the current keyword Information.
460                 /// </summary>
461                 /// <returns>Returns keyword name.</returns>
462                 public override string ToString()
463                 {
464                         return this.Name;
465                 }
466                 /// <summary>
467                 /// Gets an array of keywords names including the aliases.
468                 /// </summary>
469                 /// <returns>A string array of keyword names that represent this keyword.</returns>
470                 public string[] GetKeywords()
471                 {
472             // NOTE: Each keyword has a unique name. In addition the keyword may have an
473             // alternative names (aliases). 
474             // Most common scenario for a keyword aliase is when keyword has a long and
475             // short form. For example, KeywordName.Ser and "#SERIES".
476             
477                         // Fill array of possible names for that keyword
478                         if(this.KeywordAliases.Length > 0)
479                         {
480                                 string[] keywordAliases = this.KeywordAliases.Split(',');
481                                 string[] keywordNames = new string[keywordAliases.Length + 1];
482                                 keywordNames[0] = this.Keyword;
483                                 keywordAliases.CopyTo(keywordNames, 1);
484                                 return keywordNames;
485                         }
486                         else
487                         {
488                                 return new string[] { this.Keyword };
489                         }
490                 }
491
492                 #endregion // Methods
493         }
494 }
495