1 namespace System.Workflow.ComponentModel.Design
2 {
3     using System;
4     using System.IO;
5     using System.Xml;
6     using System.Text;
7     using System.Drawing;
8     using System.Resources;
9     using System.Reflection;
10     using System.Diagnostics;
11     using System.Collections;
12     using System.Drawing.Text;
13     using System.Globalization;
14     using System.Windows.Forms;
15     using System.Drawing.Design;
16     using System.ComponentModel;
17     using System.Drawing.Drawing2D;
18     using System.Collections.Generic;
19     using System.Collections.ObjectModel;
20     using System.ComponentModel.Design;
21     using System.Collections.Specialized;
22     using System.Runtime.InteropServices;
23     using System.ComponentModel.Design.Serialization;
24     using Microsoft.Win32;
25     using System.Workflow.ComponentModel.Compiler;
26     using System.Workflow.ComponentModel.Serialization;
27     using System.Windows.Forms.Design;
28 
29     //
30 
31 
32 
33     #region WorkflowTheme Enums
34     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
35     public enum ThemeType
36     {
37         Default = 0,
38         System = 1,
39         UserDefined = 2
40     }
41 
42     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
43     public enum DesignerGeometry
44     {
45         Rectangle = 0,
46         RoundedRectangle = 1
47     }
48 
49     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
50     public enum TextQuality
51     {
52         Aliased = 0,
53         AntiAliased = 1,
54     }
55 
56     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
57     public enum DesignerSize
58     {
59         //Please note that this enum is used to access array and hence we need to
60         //change all the arrays before changing this enum
61         Small = 0,
62         Medium = 1,
63         Large = 2
64     }
65 
66     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
67     public enum DesignerContentAlignment
68     {
69         Left = 1,
70         Top = 2,
71         Right = 4,
72         Bottom = 8,
73         Center = 16,
74         TopLeft = Left + Top,
75         TopCenter = Center + Top,
76         TopRight = Right + Top,
77         CenterLeft = Left + Center,
78         CenterRight = Right + Center,
79         BottomLeft = Left + Bottom,
80         BottomCenter = Center + Bottom,
81         BottomRight = Right + Bottom,
82         Fill = 32
83     }
84 
85     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
86     public enum LineAnchor
87     {
88         None = 0,
89         Arrow = 1,
90         ArrowAnchor = 2,
91         Diamond = 3,
92         DiamondAnchor = 4,
93         Round = 5,
94         RoundAnchor = 6,
95         Rectangle = 7,
96         RectangleAnchor = 8,
97         RoundedRectangle = 9,
98         RoundedRectangleAnchor = 10
99     }
100 
101     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
102     public enum AmbientProperty
103     {
104         DesignerSize = 0,
105         OperatingSystemSetting = 1
106     }
107     #endregion
108 
109     #region Class ActivityDesignerThemeAttribute
110     [AttributeUsage(AttributeTargets.Class)]
111     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
112     public sealed class ActivityDesignerThemeAttribute : Attribute
113     {
114         private Type designerThemeType = null;
115         private string xml = String.Empty;
116 
ActivityDesignerThemeAttribute(Type designerThemeType)117         public ActivityDesignerThemeAttribute(Type designerThemeType)
118         {
119             this.designerThemeType = designerThemeType;
120         }
121 
122         public Type DesignerThemeType
123         {
124             get
125             {
126                 return this.designerThemeType;
127             }
128         }
129 
130         public string Xml
131         {
132             get
133             {
134                 return this.xml;
135             }
136 
137             set
138             {
139                 this.xml = value;
140             }
141         }
142     }
143     #endregion
144 
145     #region Class WorkflowTheme
146     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
147     public sealed class WorkflowTheme : IDisposable
148     {
149         #region Static Members
150         private static readonly string WorkflowThemesSubKey = "Themes";
151         private const string ThemeTypeKey = "ThemeType";
152         private const string ThemePathKey = "ThemeFilePath";
153         private const string ThemeResourceNS = "System.Workflow.ComponentModel.Design.ActivityDesignerThemes.";
154         internal const string DefaultThemeFileExtension = "*.wtm";
155         internal static string DefaultNamespace = typeof(WorkflowTheme).Namespace.Replace(".", "_");
156         private static IUIService uiService = null; //cached session-wide ui service (for getting environment font)
157         private static Font defaultFont = null;
158         #endregion
159 
160         #region Members and Initialization
161         private static WorkflowTheme currentTheme = null;
162         private static bool enableChangeNotification = true;
163         public static event System.EventHandler ThemeChanged;
164 
165         private ThemeType themeType = ThemeType.UserDefined;
166         private string name = String.Empty;
167         private string version = "1.0";
168         private string description = DR.GetString(DR.DefaultThemeDescription);
169         private string filePath = String.Empty;
170         private ThemeCollection designerThemes = new ThemeCollection();
171         private bool readOnly = false;
172 
WorkflowTheme()173         static WorkflowTheme()
174         {
175             WorkflowTheme.currentTheme = LoadThemeSettingFromRegistry();
176             if (WorkflowTheme.currentTheme != null)
177                 WorkflowTheme.currentTheme.ReadOnly = true;
178         }
179 
WorkflowTheme()180         public WorkflowTheme()
181         {
182             this.filePath = WorkflowTheme.GenerateThemeFilePath();
183             if (this.filePath != null && this.filePath.Length > 0)
184                 this.name = Path.GetFileNameWithoutExtension(this.filePath);
185         }
186 
~WorkflowTheme()187         ~WorkflowTheme()
188         {
189             Dispose(false);
190         }
191 
IDisposable.Dispose()192         void IDisposable.Dispose()
193         {
194             Dispose(true);
195             GC.SuppressFinalize(this);
196         }
197 
Dispose(bool disposing)198         private void Dispose(bool disposing)
199         {
200             //Dispose all the members first before doing anything with the resources
201             foreach (DesignerTheme designerTheme in this.designerThemes)
202                 ((IDisposable)designerTheme).Dispose();
203             this.designerThemes.Clear();
204         }
205         #endregion
206 
207         #region Static Properties and Methods
208         internal static IUIService UIService
209         {
210             get
211             {
212                 return WorkflowTheme.uiService;
213             }
214             set
215             {
216                 WorkflowTheme.uiService = value;
217                 WorkflowTheme.defaultFont = null; //clear cached font
218                 WorkflowTheme.CurrentTheme.AmbientTheme.UpdateFont();
219             }
220         }
221 
GetDefaultFont()222         internal static Font GetDefaultFont()
223         {
224             if (WorkflowTheme.defaultFont == null)
225             {
226                 if (WorkflowTheme.UIService != null)
227                     WorkflowTheme.defaultFont = WorkflowTheme.UIService.Styles["DialogFont"] as Font;
228 
229                 if (WorkflowTheme.defaultFont == null)
230                     WorkflowTheme.defaultFont = Control.DefaultFont;
231             }
232 
233             return defaultFont;
234         }
235 
236         public static string RegistryKeyPath
237         {
238             get
239             {
240                 return DesignerHelpers.DesignerPerUserRegistryKey + "\\" + WorkflowThemesSubKey;
241             }
242         }
243 
244         public static WorkflowTheme CurrentTheme
245         {
246             get
247             {
248                 if (WorkflowTheme.currentTheme == null)
249                 {
250                     WorkflowTheme.currentTheme = CreateStandardTheme(ThemeType.Default);
251                     WorkflowTheme.currentTheme.ReadOnly = true;
252                 }
253 
254                 return WorkflowTheme.currentTheme;
255             }
256 
257             set
258             {
259                 if (WorkflowTheme.currentTheme == value)
260                     return;
261 
262                 if (value == null)
263                     throw new ArgumentNullException("value");
264 
265                 WorkflowTheme oldTheme = WorkflowTheme.currentTheme;
266 
267                 WorkflowTheme.currentTheme = value;
268                 WorkflowTheme.currentTheme.ReadOnly = true;
269 
270                 if (WorkflowTheme.EnableChangeNotification)
271                 {
272                     //We dont want to dispose the standard themes here
273                     if (oldTheme != null)
274                     {
275                         ((IDisposable)oldTheme).Dispose();
276                         oldTheme = null;
277                     }
278 
279                     FireThemeChange();
280                 }
281             }
282         }
283 
284         public static bool EnableChangeNotification
285         {
286             get
287             {
288                 return WorkflowTheme.enableChangeNotification;
289             }
290 
291             set
292             {
293                 if (WorkflowTheme.enableChangeNotification == value)
294                     return;
295                 WorkflowTheme.enableChangeNotification = value;
296             }
297         }
298 
299         public static string LookupPath
300         {
301             get
302             {
303                 string path = string.Empty;
304                 try
305                 {
306                     path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
307                     if (String.IsNullOrEmpty(path))
308                     {
309                         Debug.Assert(false, "Install directory key is missing!");
310                         path = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
311                     }
312 
313                     path = Path.Combine(path, "Windows Workflow Foundation" + Path.DirectorySeparatorChar + "Themes");
314                     path += Path.DirectorySeparatorChar;
315                 }
316                 catch
317                 {
318                 }
319 
320                 Debug.Assert(path != null && path.Length > 0);
321                 return path;
322             }
323         }
324 
GenerateThemeFilePath()325         public static string GenerateThemeFilePath()
326         {
327             string path = LookupPath;
328             string tempThemePath = Path.Combine(path, DR.GetString(DR.MyFavoriteTheme) + ".wtm");
329             for (int i = 1; File.Exists(tempThemePath); i++)
330             {
331                 tempThemePath = Path.Combine(path, DR.GetString(DR.MyFavoriteTheme) + i.ToString(CultureInfo.InvariantCulture) + ".wtm");
332             }
333             return tempThemePath;
334         }
335 
LoadThemeSettingFromRegistry()336         public static WorkflowTheme LoadThemeSettingFromRegistry()
337         {
338             WorkflowTheme loadedTheme = null;
339 
340             RegistryKey themeKey = Registry.CurrentUser.OpenSubKey(WorkflowTheme.RegistryKeyPath);
341             if (themeKey != null)
342             {
343                 ThemeType themeType = ThemeType.Default;
344                 try
345                 {
346                     object registryValue = themeKey.GetValue(WorkflowTheme.ThemeTypeKey);
347                     if (registryValue is string)
348                         themeType = (ThemeType)Enum.Parse(typeof(ThemeType), (string)registryValue, true);
349 
350                     if (themeType == ThemeType.UserDefined)
351                     {
352                         registryValue = themeKey.GetValue(WorkflowTheme.ThemePathKey);
353                         string themePath = (registryValue is string) ? (string)registryValue : String.Empty;
354                         if (File.Exists(themePath))
355                         {
356                             string extension = Path.GetExtension(themePath);
357                             if (extension.Equals(WorkflowTheme.DefaultThemeFileExtension.Replace("*", ""), StringComparison.Ordinal))
358                                 loadedTheme = WorkflowTheme.Load(themePath);
359                         }
360                     }
361                 }
362                 catch
363                 {
364                     //We eat the exception
365                 }
366                 finally
367                 {
368                     if (loadedTheme == null)
369                     {
370                         if (themeType == ThemeType.UserDefined)
371                             themeType = ThemeType.Default;
372                         loadedTheme = CreateStandardTheme(themeType);
373                     }
374 
375                     themeKey.Close();
376                 }
377             }
378 
379             return loadedTheme;
380         }
381 
SaveThemeSettingToRegistry()382         public static void SaveThemeSettingToRegistry()
383         {
384             RegistryKey themeKey = Registry.CurrentUser.CreateSubKey(WorkflowTheme.RegistryKeyPath);
385             if (themeKey != null)
386             {
387                 try
388                 {
389                     themeKey.SetValue(WorkflowTheme.ThemeTypeKey, WorkflowTheme.CurrentTheme.themeType);
390                     if (WorkflowTheme.CurrentTheme.themeType == ThemeType.UserDefined)
391                         themeKey.SetValue(WorkflowTheme.ThemePathKey, WorkflowTheme.CurrentTheme.FilePath);
392                     else
393                         themeKey.SetValue(WorkflowTheme.ThemePathKey, String.Empty);
394                 }
395                 catch
396                 {
397                     //We eat the exception
398                 }
399                 finally
400                 {
401                     themeKey.Close();
402                 }
403             }
404         }
405 
CreateStandardTheme(ThemeType standardThemeType)406         public static WorkflowTheme CreateStandardTheme(ThemeType standardThemeType)
407         {
408             WorkflowTheme theme = null;
409             if (standardThemeType == ThemeType.Default)
410             {
411                 theme = new WorkflowTheme();
412                 theme.AmbientTheme.UseDefaultFont();
413             }
414             else if (standardThemeType == ThemeType.System)
415             {
416                 theme = new WorkflowTheme();
417                 theme.AmbientTheme.UseOperatingSystemSettings = true;
418             }
419             else
420             {
421                 return null;
422             }
423 
424             string[] standardThemeParams = StandardThemes[standardThemeType] as string[];
425             Debug.Assert(standardThemeParams != null);
426             if (standardThemeParams != null)
427             {
428                 theme.Name = standardThemeParams[0];
429                 theme.themeType = standardThemeType;
430                 theme.Description = standardThemeParams[1];
431                 theme.FilePath = LookupPath;
432             }
433             return theme;
434         }
435 
436         public static IDictionary<ThemeType, string[]> StandardThemes
437         {
438             get
439             {
440                 //DO NOT CHANGE THE ORDER OF THE THEMES ADDED BELOW
441                 Dictionary<ThemeType, string[]> standardThemes = new Dictionary<ThemeType, string[]>();
442                 standardThemes.Add(ThemeType.Default, new string[] { DR.GetString(DR.DefaultTheme), DR.GetString(DR.DefaultThemeDescription) });
443                 standardThemes.Add(ThemeType.System, new string[] { DR.GetString(DR.OSTheme), DR.GetString(DR.SystemThemeDescription) });
444                 return standardThemes;
445             }
446         }
447 
FireThemeChange()448         internal static void FireThemeChange()
449         {
450             if (WorkflowTheme.ThemeChanged != null)
451                 WorkflowTheme.ThemeChanged(WorkflowTheme.currentTheme, EventArgs.Empty);
452         }
453         #endregion
454 
455         #region Load/Save
Load(string themeFilePath)456         public static WorkflowTheme Load(string themeFilePath)
457         {
458             DesignerSerializationManager serializationManager = new DesignerSerializationManager();
459             using (serializationManager.CreateSession())
460                 return WorkflowTheme.Load(serializationManager, themeFilePath);
461         }
462 
Load(IDesignerSerializationManager serializationManager, string themeFilePath)463         public static WorkflowTheme Load(IDesignerSerializationManager serializationManager, string themeFilePath)
464         {
465             if (serializationManager == null)
466                 throw new ArgumentNullException("serializationManager");
467 
468             WorkflowTheme theme = null;
469             if (themeFilePath != null && File.Exists(themeFilePath))
470             {
471                 XmlReader xmlReader = XmlReader.Create(themeFilePath);
472                 ThemeSerializationProvider themeSerializationProvider = new ThemeSerializationProvider();
473 
474                 try
475                 {
476                     serializationManager.AddSerializationProvider(themeSerializationProvider);
477                     WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
478                     theme = xomlSerializer.Deserialize(serializationManager, xmlReader) as WorkflowTheme;
479                 }
480                 finally
481                 {
482                     serializationManager.RemoveSerializationProvider(themeSerializationProvider);
483                     xmlReader.Close();
484                 }
485 
486                 if (theme != null)
487                     theme.filePath = themeFilePath;
488             }
489 
490             return theme;
491         }
492 
Save(string themeFilePath)493         public void Save(string themeFilePath)
494         {
495             if (themeFilePath == null || themeFilePath.Length == 0)
496                 throw new ArgumentException(DR.GetString(DR.ThemePathNotValid), "themeFilePath");
497 
498             DesignerSerializationManager dsManager = new DesignerSerializationManager();
499             using (dsManager.CreateSession())
500             {
501                 WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(dsManager);
502                 XmlWriter streamWriter = null;
503                 ThemeSerializationProvider themeSerializationProvider = new ThemeSerializationProvider();
504 
505                 try
506                 {
507                     string directory = Path.GetDirectoryName(themeFilePath);
508                     if (directory.Length > 0 && !Directory.Exists(directory))
509                         Directory.CreateDirectory(directory);
510 
511                     streamWriter = Helpers.CreateXmlWriter(themeFilePath);
512                     serializationManager.AddSerializationProvider(themeSerializationProvider);
513                     WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
514                     xomlSerializer.Serialize(serializationManager, streamWriter, this);
515                 }
516                 finally
517                 {
518                     serializationManager.RemoveSerializationProvider(themeSerializationProvider);
519                     if (streamWriter != null)
520                         streamWriter.Close();
521                 }
522 
523                 this.filePath = themeFilePath;
524             }
525         }
526         #endregion
527 
528         #region a-la ICloneable Members
Clone()529         public WorkflowTheme Clone()
530         {
531             WorkflowTheme theme = null;
532 
533             DesignerSerializationManager serializationManager = new DesignerSerializationManager();
534             using (serializationManager.CreateSession())
535             {
536                 ThemeSerializationProvider themeSerializationProvider = new ThemeSerializationProvider();
537                 StringWriter stringWriter = new StringWriter(new StringBuilder(), CultureInfo.InvariantCulture);
538                 StringReader stringReader = null;
539 
540                 try
541                 {
542                     ((IDesignerSerializationManager)serializationManager).AddSerializationProvider(themeSerializationProvider);
543                     WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
544                     using (XmlWriter xmlWriter = Helpers.CreateXmlWriter(stringWriter))
545                         xomlSerializer.Serialize(serializationManager, xmlWriter, this);
546 
547                     stringReader = new StringReader(stringWriter.ToString());
548                     using (XmlReader xmlReader = XmlReader.Create(stringReader))
549                         theme = xomlSerializer.Deserialize(serializationManager, xmlReader) as WorkflowTheme;
550                 }
551                 finally
552                 {
553                     ((IDesignerSerializationManager)serializationManager).RemoveSerializationProvider(themeSerializationProvider);
554                     stringReader.Close();
555                     stringWriter.Close();
556                 }
557             }
558 
559             if (theme != null)
560             {
561                 theme.filePath = this.filePath;
562 
563                 //Now we go thru all the designer themes and call Initialize on them
564                 foreach (DesignerTheme designerTheme in theme.DesignerThemes)
565                     designerTheme.Initialize();
566             }
567 
568             return theme;
569         }
570         #endregion
571 
572         #region Public Properties and Methods
573         public string Name
574         {
575             get
576             {
577                 return this.name;
578             }
579 
580             set
581             {
582                 if (ReadOnly)
583                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
584 
585                 this.name = value;
586             }
587         }
588 
589         public string Version
590         {
591             get
592             {
593                 return this.version;
594             }
595 
596             set
597             {
598                 if (ReadOnly)
599                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
600 
601                 this.version = value;
602             }
603         }
604 
605         public string Description
606         {
607             get
608             {
609                 return this.description;
610             }
611 
612             set
613             {
614                 if (ReadOnly)
615                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
616 
617                 this.description = value;
618             }
619         }
620 
621         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
622         [Browsable(false)]
623         public string FilePath
624         {
625             get
626             {
627                 return this.filePath;
628             }
629 
630             set
631             {
632                 if (ReadOnly)
633                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
634 
635                 this.filePath = value;
636             }
637         }
638 
639         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
640         public string ContainingFileDirectory
641         {
642             get
643             {
644                 string directory = String.Empty;
645                 if (this.filePath.Length > 0)
646                 {
647                     try
648                     {
649                         directory = Path.GetDirectoryName(this.filePath) + Path.DirectorySeparatorChar;
650                     }
651                     catch
652                     {
653                     }
654                 }
655 
656                 return directory;
657             }
658         }
659 
660         [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
661         public IList DesignerThemes
662         {
663             get
664             {
665                 return this.designerThemes;
666             }
667         }
668 
669         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
670         public AmbientTheme AmbientTheme
671         {
672             get
673             {
674                 return GetTheme(typeof(WorkflowView)) as AmbientTheme;
675             }
676         }
677 
678         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
GetDesignerTheme(ActivityDesigner designer)679         public ActivityDesignerTheme GetDesignerTheme(ActivityDesigner designer)
680         {
681             if (designer == null)
682                 throw new ArgumentNullException("designer");
683 
684             return GetTheme(designer.GetType()) as ActivityDesignerTheme;
685         }
686 
GetTheme(Type designerType)687         internal DesignerTheme GetTheme(Type designerType)
688         {
689             bool wasReadOnly = ReadOnly;
690             DesignerTheme designerTheme = (this.designerThemes.Contains(designerType.FullName)) ? this.designerThemes[designerType.FullName] : null;
691 
692             try
693             {
694                 ReadOnly = false;
695 
696                 if (designerTheme == null || (designerTheme.DesignerType != null && !designerType.Equals(designerTheme.DesignerType)))
697                 {
698                     //This means that the two types are not equal and hence we need to replace the theme
699                     bool replaceTheme = (designerTheme != null);
700 
701                     AttributeCollection attributeCollection = TypeDescriptor.GetAttributes(designerType);
702                     ActivityDesignerThemeAttribute themeAttrib = attributeCollection[typeof(ActivityDesignerThemeAttribute)] as ActivityDesignerThemeAttribute;
703                     if (themeAttrib == null)
704                         throw new InvalidOperationException(DR.GetString(DR.Error_ThemeAttributeMissing, designerType.FullName));
705 
706                     if (themeAttrib.DesignerThemeType == null)
707                         throw new InvalidOperationException(DR.GetString(DR.Error_ThemeTypeMissing, designerType.FullName));
708 
709                     if (themeAttrib.Xml.Length > 0)
710                     {
711                         //First check if the theme initializer is obtained from resource as a manifest
712                         Stream stream = designerType.Assembly.GetManifestResourceStream(designerType, themeAttrib.Xml);
713                         if (stream == null)
714                             stream = designerType.Assembly.GetManifestResourceStream(WorkflowTheme.ThemeResourceNS + themeAttrib.Xml);
715 
716                         //Check if the theme initializer is obtained from file
717                         XmlReader textReader = (stream != null) ? XmlReader.Create(stream) : null;
718                         if (textReader == null)
719                             textReader = XmlReader.Create(new StringReader(themeAttrib.Xml));
720 
721                         if (textReader != null)
722                         {
723                             DesignerSerializationManager serializationManager = new DesignerSerializationManager();
724                             using (serializationManager.CreateSession())
725                             {
726                                 ThemeSerializationProvider themeSerializationProvider = new ThemeSerializationProvider();
727 
728                                 try
729                                 {
730                                     ((IDesignerSerializationManager)serializationManager).AddSerializationProvider(themeSerializationProvider);
731                                     ((IDesignerSerializationManager)serializationManager).Context.Push(this);
732                                     WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
733                                     designerTheme = xomlSerializer.Deserialize(serializationManager, textReader) as DesignerTheme;
734 
735                                     if (designerTheme != null && !themeAttrib.DesignerThemeType.IsAssignableFrom(designerTheme.GetType()))
736                                     {
737                                         ((IDesignerSerializationManager)serializationManager).ReportError(new WorkflowMarkupSerializationException(DR.GetString(DR.ThemeTypesMismatch, new object[] { themeAttrib.DesignerThemeType.FullName, designerTheme.GetType().FullName })));
738                                         designerTheme = null;
739                                     }
740 
741                                     if (serializationManager.Errors.Count > 0)
742                                     {
743                                         string errors = String.Empty;
744                                         foreach (object ex in serializationManager.Errors)
745                                             errors += ex.ToString() + @"\n";
746                                         Debug.WriteLine(errors);
747                                     }
748                                 }
749                                 finally
750                                 {
751                                     //In some cases the type resolution throws an exception when we try to create a illegal theme type,
752                                     //this is the reason we need to catch it and proceed further
753                                     ((IDesignerSerializationManager)serializationManager).RemoveSerializationProvider(themeSerializationProvider);
754                                     textReader.Close();
755                                 }
756                             }
757                         }
758                     }
759 
760                     if (designerTheme == null)
761                     {
762                         try
763                         {
764                             designerTheme = Activator.CreateInstance(themeAttrib.DesignerThemeType, new object[] { this }) as DesignerTheme;
765                         }
766                         catch
767                         {
768                             //If an exception is thrown here then surely we can not create designerTheme specified by the user so we create a default theme
769                             //and give it to the user
770                             designerTheme = new ActivityDesignerTheme(this);
771                         }
772                     }
773 
774                     designerTheme.DesignerType = designerType;
775                     designerTheme.ApplyTo = designerType.FullName;
776                     designerTheme.Initialize();
777                     if (replaceTheme)
778                         this.designerThemes.Remove(designerType.FullName);
779                     this.designerThemes.Add(designerTheme);
780                 }
781 
782                 if (designerTheme.DesignerType == null)
783                     designerTheme.DesignerType = designerType;
784             }
785             finally
786             {
787                 ReadOnly = wasReadOnly;
788             }
789 
790             return designerTheme;
791         }
792 
AmbientPropertyChanged(AmbientProperty ambientProperty)793         internal void AmbientPropertyChanged(AmbientProperty ambientProperty)
794         {
795             foreach (DesignerTheme theme in this.designerThemes)
796             {
797                 bool oldReadOnly = this.ReadOnly;
798                 this.ReadOnly = false;
799                 theme.OnAmbientPropertyChanged(ambientProperty);
800                 this.ReadOnly = oldReadOnly;
801             }
802         }
803 
804         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
805         public ThemeType Type
806         {
807             get
808             {
809                 return this.themeType;
810             }
811         }
812 
813         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
814         public bool ReadOnly
815         {
816             get
817             {
818                 return this.readOnly;
819             }
820 
821             set
822             {
823                 this.readOnly = value;
824             }
825         }
826         #endregion
827 
828         #region Class ThemeCollection
829         private class ThemeCollection : KeyedCollection<string, DesignerTheme>
830         {
GetKeyForItem(DesignerTheme item)831             protected override string GetKeyForItem(DesignerTheme item)
832             {
833                 Debug.Assert(item.ApplyTo != null && item.ApplyTo.Length > 0);
834                 return item.ApplyTo;
835             }
836         }
837         #endregion
838     }
839     #endregion
840 
841     #region Class DesignerTheme
842     [DesignerSerializer(typeof(ThemeSerializer), typeof(WorkflowMarkupSerializer))]
843     [TypeConverter(typeof(ThemeTypeConverter))]
844     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
845     public abstract class DesignerTheme : IDisposable, IPropertyValueProvider
846     {
847         #region Members and Initialization
848         private WorkflowTheme workflowTheme = null;
849         private Type designerType = null;
850         private string designerTypeName = String.Empty;
851 
DesignerTheme(WorkflowTheme theme)852         protected DesignerTheme(WorkflowTheme theme)
853         {
854             this.workflowTheme = theme;
855         }
856 
~DesignerTheme()857         ~DesignerTheme()
858         {
859             Dispose(false);
860         }
861 
IDisposable.Dispose()862         void IDisposable.Dispose()
863         {
864             Dispose(true);
865             GC.SuppressFinalize(this);
866         }
867 
Initialize()868         public virtual void Initialize()
869         {
870         }
871 
Dispose(bool disposing)872         protected virtual void Dispose(bool disposing)
873         {
874         }
875         #endregion
876 
877         #region Properties and Methods
878         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
879         [Browsable(false)]
880         protected WorkflowTheme ContainingTheme
881         {
882             get
883             {
884                 return this.workflowTheme;
885             }
886         }
887 
888         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
889         [Browsable(false)]
890         public virtual Type DesignerType
891         {
892             get
893             {
894                 return this.designerType;
895             }
896 
897             set
898             {
899                 if (ReadOnly)
900                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
901 
902                 this.designerType = value;
903             }
904         }
905 
906         [Browsable(false)]
907         public virtual string ApplyTo
908         {
909             get
910             {
911                 return this.designerTypeName;
912             }
913 
914             set
915             {
916                 if (ReadOnly)
917                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
918 
919                 this.designerTypeName = value;
920             }
921         }
922 
OnAmbientPropertyChanged(AmbientProperty ambientProperty)923         public virtual void OnAmbientPropertyChanged(AmbientProperty ambientProperty)
924         {
925         }
926 
927         [Browsable(false)]
928         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
929         public bool ReadOnly
930         {
931             get
932             {
933                 if (this.workflowTheme != null)
934                     return this.workflowTheme.ReadOnly;
935                 else
936                     return false;
937             }
938             internal set
939             {
940                 if (this.workflowTheme != null)
941                     this.workflowTheme.ReadOnly = value;
942             }
943         }
944         #endregion
945 
946         #region IPropertyValueProvider Members
IPropertyValueProvider.GetPropertyValues(ITypeDescriptorContext context)947         ICollection IPropertyValueProvider.GetPropertyValues(ITypeDescriptorContext context)
948         {
949             //You can filter the enum values here by using EnumFilterConverter
950             return GetPropertyValues(context);
951         }
952 
GetPropertyValues(ITypeDescriptorContext context)953         internal virtual ICollection GetPropertyValues(ITypeDescriptorContext context)
954         {
955             //You can filter the enum values here by using EnumFilterConverter
956             return new object[] { };
957         }
958         #endregion
959 
960         #region Class ThemeSerializer
961         private class ThemeSerializer : WorkflowMarkupSerializer
962         {
CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)963             protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
964             {
965                 if (typeof(DesignerTheme).IsAssignableFrom(type))
966                     return Activator.CreateInstance(type, new object[] { serializationManager.Context[typeof(WorkflowTheme)] });
967                 else
968                     return base.CreateInstance(serializationManager, type);
969             }
970         }
971         #endregion
972 
973     }
974     #endregion
975 
976     #region Class ActivityDesignerTheme
977     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
978     public class ActivityDesignerTheme : DesignerTheme
979     {
980         #region Constants
981         private static readonly Size[] DesignerSizes = new Size[] { new Size(90, 40), new Size(130, 41), new Size(110, 50) };
982         private static readonly Size[] ImageSizes = new Size[] { new Size(16, 16), new Size(16, 16), new Size(24, 24) };
983         #endregion
984 
985         #region Members and Initialization
986         //Public members
987         private string designerImagePath = String.Empty;
988         private Color foreColor = Color.Black;
989         private Color borderColor = Color.Black;
990         private DashStyle borderStyle = DashStyle.Solid;
991         private Color backColorStart = Color.White;
992         private Color backColorEnd = Color.Empty;
993         private LinearGradientMode backgroundStyle = LinearGradientMode.Horizontal;
994 
995         //Temporary members
996         private Image designerImage;
997         private Pen foregroundPen;
998         private Pen borderPen;
999         private Brush foregroundBrush;
1000         private Brush backgroundBrush;
1001         private Rectangle backgroundBrushRect;
1002 
ActivityDesignerTheme(WorkflowTheme theme)1003         public ActivityDesignerTheme(WorkflowTheme theme)
1004             : base(theme)
1005         {
1006         }
1007 
Dispose(bool disposing)1008         protected override void Dispose(bool disposing)
1009         {
1010             try
1011             {
1012                 if (this.designerImage != null)
1013                 {
1014                     this.designerImage.Dispose();
1015                     this.designerImage = null;
1016                 }
1017 
1018                 if (this.foregroundPen != null)
1019                 {
1020                     this.foregroundPen.Dispose();
1021                     this.foregroundPen = null;
1022                 }
1023 
1024                 if (this.foregroundBrush != null)
1025                 {
1026                     this.foregroundBrush.Dispose();
1027                     this.foregroundBrush = null;
1028                 }
1029 
1030                 if (this.borderPen != null)
1031                 {
1032                     this.borderPen.Dispose();
1033                     this.borderPen = null;
1034                 }
1035 
1036                 if (this.backgroundBrush != null)
1037                 {
1038                     this.backgroundBrush.Dispose();
1039                     this.backgroundBrush = null;
1040                 }
1041             }
1042             finally
1043             {
1044                 base.Dispose(disposing);
1045             }
1046         }
1047 
Initialize()1048         public override void Initialize()
1049         {
1050             base.Initialize();
1051 
1052             if (ContainingTheme.AmbientTheme.UseOperatingSystemSettings)
1053                 ApplySystemColors();
1054         }
1055         #endregion
1056 
1057         #region Publicly browsable Properties
1058         [DispId(1)]
1059         [SRDescription("ImageDesc", DR.ResourceSet)]
1060         [SRCategory("ForegroundCategory", DR.ResourceSet)]
1061         [Editor(typeof(ImageBrowserEditor), typeof(UITypeEditor))]
1062         public virtual string DesignerImagePath
1063         {
1064             get
1065             {
1066                 return this.designerImagePath;
1067             }
1068 
1069             set
1070             {
1071                 if (ReadOnly)
1072                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1073 
1074                 if (value != null && value.Length > 0 && value.Contains(Path.DirectorySeparatorChar.ToString()) && Path.IsPathRooted(value))
1075                 {
1076                     value = DesignerHelpers.GetRelativePath(ContainingTheme.ContainingFileDirectory, value);
1077 
1078                     if (!DesignerHelpers.IsValidImageResource(this, ContainingTheme.ContainingFileDirectory, value))
1079                         throw new InvalidOperationException(DR.GetString(DR.Error_InvalidImageResource));
1080                 }
1081 
1082                 this.designerImagePath = value;
1083                 if (this.designerImage != null)
1084                 {
1085                     this.designerImage.Dispose();
1086                     this.designerImage = null;
1087                 }
1088             }
1089         }
1090 
1091         [DispId(2)]
1092         [SRDescription("ForeColorDesc", DR.ResourceSet)]
1093         [SRCategory("ForegroundCategory", DR.ResourceSet)]
1094         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
1095         [TypeConverter(typeof(ColorPickerConverter))]
1096         public virtual Color ForeColor
1097         {
1098             get
1099             {
1100                 return this.foreColor;
1101             }
1102 
1103             set
1104             {
1105                 if (ReadOnly)
1106                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1107 
1108                 this.foreColor = value;
1109 
1110                 if (this.foregroundPen != null)
1111                 {
1112                     this.foregroundPen.Dispose();
1113                     this.foregroundPen = null;
1114                 }
1115 
1116                 if (this.foregroundBrush != null)
1117                 {
1118                     this.foregroundBrush.Dispose();
1119                     this.foregroundBrush = null;
1120                 }
1121             }
1122         }
1123 
1124         [DispId(3)]
1125         [SRDescription("BorderColorDesc", DR.ResourceSet)]
1126         [SRCategory("ForegroundCategory", DR.ResourceSet)]
1127         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
1128         [TypeConverter(typeof(ColorPickerConverter))]
1129         public virtual Color BorderColor
1130         {
1131             get
1132             {
1133                 return this.borderColor;
1134             }
1135 
1136             set
1137             {
1138                 if (ReadOnly)
1139                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1140 
1141                 this.borderColor = value;
1142                 if (this.borderPen != null)
1143                 {
1144                     this.borderPen.Dispose();
1145                     this.borderPen = null;
1146                 }
1147             }
1148         }
1149 
1150         [DispId(4)]
1151         [SRDescription("BorderStyleDesc", DR.ResourceSet)]
1152         [SRCategory("ForegroundCategory", DR.ResourceSet)]
1153         [TypeConverter(typeof(FilteredEnumConverter))]
1154         public virtual DashStyle BorderStyle
1155         {
1156             get
1157             {
1158                 return this.borderStyle;
1159             }
1160 
1161             set
1162             {
1163                 if (ReadOnly)
1164                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1165 
1166                 if (value == DashStyle.Custom)
1167                     throw new Exception(DR.GetString(DR.CustomStyleNotSupported));
1168 
1169                 this.borderStyle = value;
1170                 if (this.borderPen != null)
1171                 {
1172                     this.borderPen.Dispose();
1173                     this.borderPen = null;
1174                 }
1175             }
1176         }
1177 
1178         [DispId(5)]
1179         [SRDescription("BackColorStartDesc", DR.ResourceSet)]
1180         [SRCategory("BackgroundCategory", DR.ResourceSet)]
1181         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
1182         [TypeConverter(typeof(ColorPickerConverter))]
1183         public virtual Color BackColorStart
1184         {
1185             get
1186             {
1187                 return this.backColorStart;
1188             }
1189 
1190             set
1191             {
1192                 if (ReadOnly)
1193                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1194 
1195                 this.backColorStart = value;
1196                 if (this.backgroundBrush != null)
1197                 {
1198                     this.backgroundBrush.Dispose();
1199                     this.backgroundBrush = null;
1200                 }
1201             }
1202         }
1203 
1204         [DispId(6)]
1205         [SRDescription("BackColorEndDesc", DR.ResourceSet)]
1206         [SRCategory("BackgroundCategory", DR.ResourceSet)]
1207         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
1208         [TypeConverter(typeof(ColorPickerConverter))]
1209         public virtual Color BackColorEnd
1210         {
1211             get
1212             {
1213                 return this.backColorEnd;
1214             }
1215 
1216             set
1217             {
1218                 if (ReadOnly)
1219                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1220 
1221                 this.backColorEnd = value;
1222                 if (this.backgroundBrush != null)
1223                 {
1224                     this.backgroundBrush.Dispose();
1225                     this.backgroundBrush = null;
1226                 }
1227             }
1228         }
1229 
1230         [DispId(7)]
1231         [SRDescription("BackgroundStyleDesc", DR.ResourceSet)]
1232         [SRCategory("BackgroundCategory", DR.ResourceSet)]
1233         public virtual LinearGradientMode BackgroundStyle
1234         {
1235             get
1236             {
1237                 return this.backgroundStyle;
1238             }
1239 
1240             set
1241             {
1242                 if (ReadOnly)
1243                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1244 
1245                 this.backgroundStyle = value;
1246                 if (this.backgroundBrush != null)
1247                 {
1248                     this.backgroundBrush.Dispose();
1249                     this.backgroundBrush = null;
1250                 }
1251             }
1252         }
1253         #endregion
1254 
1255         #region Helper Properties
1256         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1257         [Browsable(false)]
1258         public Pen ForegroundPen
1259         {
1260             get
1261             {
1262                 if (this.foregroundPen == null)
1263                     this.foregroundPen = new Pen(this.foreColor, BorderWidth);
1264                 return this.foregroundPen;
1265             }
1266         }
1267 
1268         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1269         [Browsable(false)]
1270         public Brush ForegroundBrush
1271         {
1272             get
1273             {
1274                 if (this.foregroundBrush == null)
1275                     this.foregroundBrush = new SolidBrush(this.foreColor);
1276                 return this.foregroundBrush;
1277             }
1278         }
1279 
1280         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1281         [Browsable(false)]
1282         public Pen BorderPen
1283         {
1284             get
1285             {
1286                 if (this.borderPen == null)
1287                 {
1288                     this.borderPen = new Pen(this.borderColor, BorderWidth);
1289                     this.borderPen.DashStyle = this.borderStyle;
1290                 }
1291                 return this.borderPen;
1292             }
1293         }
1294 
1295         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1296         [Browsable(false)]
GetBackgroundBrush(Rectangle rectangle)1297         public Brush GetBackgroundBrush(Rectangle rectangle)
1298         {
1299             if (this.backgroundBrush == null || this.backgroundBrushRect != rectangle)
1300             {
1301                 if (this.backgroundBrush != null)
1302                     this.backgroundBrush.Dispose();
1303                 this.backgroundBrushRect = rectangle;
1304 
1305                 if (this.backColorStart == this.backColorEnd)
1306                     this.backgroundBrush = new SolidBrush(this.backColorStart);
1307                 else
1308                     this.backgroundBrush = new LinearGradientBrush(this.backgroundBrushRect, this.backColorStart, this.backColorEnd, this.backgroundStyle);
1309             }
1310             return this.backgroundBrush;
1311         }
1312 
1313         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1314         [Browsable(false)]
1315         public Size Size
1316         {
1317             get
1318             {
1319                 return ActivityDesignerTheme.DesignerSizes[(int)ContainingTheme.AmbientTheme.DesignerSize];
1320             }
1321         }
1322 
1323         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1324         [Browsable(false)]
1325         public DesignerGeometry DesignerGeometry
1326         {
1327             get
1328             {
1329                 if (ContainingTheme.AmbientTheme.DrawRounded)
1330                     return DesignerGeometry.RoundedRectangle;
1331                 else
1332                     return DesignerGeometry.Rectangle;
1333             }
1334         }
1335 
1336         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1337         [Browsable(false)]
1338         public Image DesignerImage
1339         {
1340             get
1341             {
1342                 if (this.designerImage == null && this.designerImagePath.Length > 0)
1343                     this.designerImage = DesignerHelpers.GetImageFromPath(this, ContainingTheme.ContainingFileDirectory, this.designerImagePath);
1344                 return this.designerImage;
1345             }
1346         }
1347 
1348         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1349         [Browsable(false)]
1350         public Size ImageSize
1351         {
1352             get
1353             {
1354                 return ActivityDesignerTheme.ImageSizes[(int)ContainingTheme.AmbientTheme.DesignerSize];
1355             }
1356         }
1357 
1358         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1359         [Browsable(false)]
1360         public Font Font
1361         {
1362             get
1363             {
1364                 return ContainingTheme.AmbientTheme.Font;
1365             }
1366         }
1367 
1368         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1369         [Browsable(false)]
1370         public Font BoldFont
1371         {
1372             get
1373             {
1374                 return ContainingTheme.AmbientTheme.BoldFont;
1375             }
1376         }
1377 
1378         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1379         [Browsable(false)]
1380         public int BorderWidth
1381         {
1382             get
1383             {
1384                 return ContainingTheme.AmbientTheme.BorderWidth;
1385             }
1386         }
1387 
OnAmbientPropertyChanged(AmbientProperty ambientProperty)1388         public override void OnAmbientPropertyChanged(AmbientProperty ambientProperty)
1389         {
1390             if (ambientProperty == AmbientProperty.DesignerSize)
1391             {
1392                 ForeColor = this.foreColor;
1393                 BorderColor = this.borderColor;
1394             }
1395             else if (ambientProperty == AmbientProperty.OperatingSystemSetting)
1396             {
1397                 ApplySystemColors();
1398             }
1399         }
1400 
ApplySystemColors()1401         private void ApplySystemColors()
1402         {
1403             ForeColor = SystemColors.ControlText;
1404             BorderColor = SystemColors.ControlDark;
1405             BackColorStart = SystemColors.Control;
1406             BackColorEnd = SystemColors.ControlLight;
1407         }
1408         #endregion
1409 
1410         #region IPropertyValueProvider Implementation
GetPropertyValues(ITypeDescriptorContext context)1411         internal override ICollection GetPropertyValues(ITypeDescriptorContext context)
1412         {
1413             object[] values = new object[] { };
1414             if (string.Equals(context.PropertyDescriptor.Name, "BorderStyle", StringComparison.Ordinal))
1415                 values = new object[] { DashStyle.Solid, DashStyle.Dash, DashStyle.DashDot, DashStyle.DashDotDot, DashStyle.Dot };
1416 
1417             return values;
1418         }
1419         #endregion
1420     }
1421     #endregion
1422 
1423     #region Class CompositeDesignerTheme
1424     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
1425     public class CompositeDesignerTheme : ActivityDesignerTheme
1426     {
1427         #region Static Members
1428         internal static readonly Pen ExpandButtonForegoundPen = new Pen(Color.Black, 1);
1429         internal static readonly Pen ExpandButtonBorderPen = new Pen(Color.FromArgb(123, 154, 181), 1);
1430 
1431         private static readonly Size[] ExpandButtonSizes = new Size[] { new Size(8, 8), new Size(8, 8), new Size(12, 12) };
1432         private static readonly Size[] ConnectorSizes = new Size[] { new Size(15, 30), new Size(15, 19), new Size(25, 50) };
1433         #endregion
1434 
1435         #region Members and Constructor
1436         //Members
1437         private DesignerContentAlignment watermarkAlignment = DesignerContentAlignment.BottomRight;
1438         private string watermarkImagePath = String.Empty;
1439         private bool dropShadow = false;
1440         private LineAnchor startCap = LineAnchor.None;
1441         private LineAnchor endCap = LineAnchor.ArrowAnchor;
1442 
1443         //Temporary variables
1444         private Brush expandButtonBackBrush;
1445         private Rectangle expandButtonRectangle = Rectangle.Empty;
1446         private Image watermarkImage;
1447 
CompositeDesignerTheme(WorkflowTheme theme)1448         public CompositeDesignerTheme(WorkflowTheme theme)
1449             : base(theme)
1450         {
1451         }
1452 
Dispose(bool disposing)1453         protected override void Dispose(bool disposing)
1454         {
1455             try
1456             {
1457                 if (this.expandButtonBackBrush != null)
1458                 {
1459                     this.expandButtonBackBrush.Dispose();
1460                     this.expandButtonBackBrush = null;
1461                 }
1462 
1463                 if (this.watermarkImage != null)
1464                 {
1465                     this.watermarkImage.Dispose();
1466                     this.watermarkImage = null;
1467                 }
1468             }
1469             finally
1470             {
1471                 base.Dispose(disposing);
1472             }
1473         }
1474 
Initialize()1475         public override void Initialize()
1476         {
1477             base.Initialize();
1478 
1479             if (ContainingTheme.AmbientTheme.UseOperatingSystemSettings)
1480                 ApplySystemColors();
1481         }
1482 
1483         #endregion
1484 
1485         #region Publicly browsable Properties
1486         [DispId(8)]
1487         [SRDescription("WatermarkDesc", DR.ResourceSet)]
1488         [SRCategory("BackgroundCategory", DR.ResourceSet)]
1489         [Editor(typeof(ImageBrowserEditor), typeof(UITypeEditor))]
1490         public virtual string WatermarkImagePath
1491         {
1492             get
1493             {
1494                 return this.watermarkImagePath;
1495             }
1496 
1497             set
1498             {
1499                 if (ReadOnly)
1500                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1501 
1502                 if (!String.IsNullOrEmpty(value) && value.Contains(Path.DirectorySeparatorChar.ToString()) && Path.IsPathRooted(value))
1503                 {
1504                     value = DesignerHelpers.GetRelativePath(ContainingTheme.ContainingFileDirectory, value);
1505 
1506                     if (!DesignerHelpers.IsValidImageResource(this, ContainingTheme.ContainingFileDirectory, value))
1507                         throw new InvalidOperationException(DR.GetString(DR.Error_InvalidImageResource));
1508                 }
1509 
1510                 this.watermarkImagePath = value;
1511                 if (this.watermarkImage != null)
1512                 {
1513                     this.watermarkImage.Dispose();
1514                     this.watermarkImage = null;
1515                 }
1516             }
1517         }
1518 
1519         [DispId(9)]
1520         [DefaultValue(DesignerContentAlignment.BottomRight)]
1521         [SRDescription("WatermarkAlignmentDesc", DR.ResourceSet)]
1522         [SRCategory("BackgroundCategory", DR.ResourceSet)]
1523         public virtual DesignerContentAlignment WatermarkAlignment
1524         {
1525             get
1526             {
1527                 return this.watermarkAlignment;
1528             }
1529 
1530             set
1531             {
1532                 if (ReadOnly)
1533                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1534 
1535                 this.watermarkAlignment = value;
1536             }
1537         }
1538 
1539         [DefaultValue(false)]
1540         [DispId(10)]
1541         [SRDescription("DropShadowDesc", DR.ResourceSet)]
1542         [SRCategory("BackgroundCategory", DR.ResourceSet)]
1543         public virtual bool ShowDropShadow
1544         {
1545             get
1546             {
1547                 return this.dropShadow;
1548             }
1549 
1550             set
1551             {
1552                 if (ReadOnly)
1553                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1554 
1555                 this.dropShadow = value;
1556             }
1557         }
1558 
1559         [DefaultValue(LineAnchor.None)]
1560         [DispId(11)]
1561         [SRDescription("ConnectorStartCapDesc", DR.ResourceSet)]
1562         [SRCategory("ForegroundCategory", DR.ResourceSet)]
1563         public virtual LineAnchor ConnectorStartCap
1564         {
1565             get
1566             {
1567                 return this.startCap;
1568             }
1569 
1570             set
1571             {
1572                 if (ReadOnly)
1573                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1574 
1575                 this.startCap = value;
1576             }
1577         }
1578 
1579         [DefaultValue(LineAnchor.ArrowAnchor)]
1580         [DispId(12)]
1581         [SRDescription("ConnectorEndCapDesc", DR.ResourceSet)]
1582         [SRCategory("ForegroundCategory", DR.ResourceSet)]
1583         public virtual LineAnchor ConnectorEndCap
1584         {
1585             get
1586             {
1587                 return this.endCap;
1588             }
1589 
1590             set
1591             {
1592                 if (ReadOnly)
1593                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1594 
1595                 this.endCap = value;
1596             }
1597         }
1598         #endregion
1599 
1600         #region Helper Methods
1601         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1602         [Browsable(false)]
1603         public virtual Size ConnectorSize
1604         {
1605             get
1606             {
1607                 if (DesignerType != null && typeof(FreeformActivityDesigner).IsAssignableFrom(DesignerType))
1608                 {
1609                     int connectorSize = CompositeDesignerTheme.ConnectorSizes[(int)ContainingTheme.AmbientTheme.DesignerSize].Height;
1610                     return new Size(connectorSize, connectorSize);
1611                 }
1612                 else
1613                 {
1614                     return CompositeDesignerTheme.ConnectorSizes[(int)ContainingTheme.AmbientTheme.DesignerSize];
1615                 }
1616             }
1617         }
1618 
1619         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1620         [Browsable(false)]
1621         public virtual Size ExpandButtonSize
1622         {
1623             get
1624             {
1625                 return CompositeDesignerTheme.ExpandButtonSizes[(int)ContainingTheme.AmbientTheme.DesignerSize];
1626             }
1627         }
1628 
GetExpandButtonBackgroundBrush(Rectangle rectangle)1629         public Brush GetExpandButtonBackgroundBrush(Rectangle rectangle)
1630         {
1631             if (this.expandButtonBackBrush == null || this.expandButtonRectangle != rectangle)
1632             {
1633                 if (this.expandButtonBackBrush != null)
1634                     this.expandButtonBackBrush.Dispose();
1635                 this.expandButtonRectangle = rectangle;
1636                 this.expandButtonBackBrush = new LinearGradientBrush(this.expandButtonRectangle, Color.White, Color.FromArgb(173, 170, 156), LinearGradientMode.ForwardDiagonal);
1637             }
1638             return this.expandButtonBackBrush;
1639         }
1640 
1641         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1642         [Browsable(false)]
1643         public Image WatermarkImage
1644         {
1645             get
1646             {
1647                 if (this.watermarkImage == null && this.watermarkImagePath.Length > 0)
1648                     this.watermarkImage = DesignerHelpers.GetImageFromPath(this, ContainingTheme.ContainingFileDirectory, this.watermarkImagePath);
1649                 return this.watermarkImage;
1650             }
1651         }
1652 
OnAmbientPropertyChanged(AmbientProperty ambientProperty)1653         public override void OnAmbientPropertyChanged(AmbientProperty ambientProperty)
1654         {
1655             base.OnAmbientPropertyChanged(ambientProperty);
1656 
1657             if (ambientProperty == AmbientProperty.OperatingSystemSetting)
1658                 ApplySystemColors();
1659         }
1660 
ApplySystemColors()1661         private void ApplySystemColors()
1662         {
1663             //the root designers should be transparent...
1664             BackColorStart = Color.Empty;
1665             BackColorEnd = Color.Empty;
1666         }
1667         #endregion
1668     }
1669     #endregion
1670 
1671     #region Class ActivityPreviewDesignerTheme
1672     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
1673     public class ActivityPreviewDesignerTheme : CompositeDesignerTheme
1674     {
1675         #region Static Members
1676         internal static readonly Bitmap LeftScrollImage = DR.GetImage(DR.MoveLeft) as Bitmap;
1677         internal static readonly Bitmap LeftScrollImageUp = DR.GetImage(DR.MoveLeftUp) as Bitmap;
1678         internal static readonly Bitmap RightScrollImage = DR.GetImage(DR.MoveRight) as Bitmap;
1679         internal static readonly Bitmap RightScrollImageUp = DR.GetImage(DR.MoveRightUp) as Bitmap;
1680         internal static readonly Bitmap PreviewButtonImage = DR.GetImage(DR.PreviewModeIcon) as Bitmap;
1681         internal static readonly Bitmap EditButtonImage = DR.GetImage(DR.EditModeIcon) as Bitmap;
1682         internal static readonly Bitmap PreviewImage = DR.GetImage(DR.PreviewIndicator) as Bitmap;
1683 
1684         private static readonly Size[] ItemSizes = new Size[] { new Size(20, 20), new Size(20, 20), new Size(30, 30) };
1685         private static readonly Size[] PreviewButtonSizes = new Size[] { new Size(16, 16), new Size(16, 16), new Size(20, 20) };
1686         private static readonly Size[] PreviewWindowSizes = new Size[] { new Size(172, 120), new Size(172, 120), new Size(212, 160) };
1687         private const int DefaultItemCount = 5;
1688         #endregion
1689 
1690         #region Members
1691         private Color previewForeColor = Color.WhiteSmoke;
1692         private Color previewBackColor = Color.White;
1693         private Color previewBorderColor = Color.Gray;
1694 
1695         //Temporary members
1696         private Brush previewForegroundBrush;
1697         private Brush previewBackgroundBrush;
1698         private Pen previewBorderPen;
1699 
ActivityPreviewDesignerTheme(WorkflowTheme theme)1700         public ActivityPreviewDesignerTheme(WorkflowTheme theme)
1701             : base(theme)
1702         {
1703         }
1704 
Dispose(bool disposing)1705         protected override void Dispose(bool disposing)
1706         {
1707             try
1708             {
1709                 if (this.previewForegroundBrush != null)
1710                 {
1711                     this.previewForegroundBrush.Dispose();
1712                     this.previewForegroundBrush = null;
1713                 }
1714 
1715                 if (this.previewBackgroundBrush != null)
1716                 {
1717                     this.previewBackgroundBrush.Dispose();
1718                     this.previewBackgroundBrush = null;
1719                 }
1720 
1721                 if (this.previewBorderPen != null)
1722                 {
1723                     this.previewBorderPen.Dispose();
1724                     this.previewBorderPen = null;
1725                 }
1726             }
1727             finally
1728             {
1729                 base.Dispose(disposing);
1730             }
1731         }
1732 
Initialize()1733         public override void Initialize()
1734         {
1735             base.Initialize();
1736 
1737             if (ContainingTheme.AmbientTheme.UseOperatingSystemSettings)
1738                 ApplySystemColors();
1739         }
1740         #endregion
1741 
1742         #region Publicly browsable Properties
1743         [DispId(13)]
1744         [SRDescription("PreviewForeColorDesc", DR.ResourceSet)]
1745         [SRCategory("ForegroundCategory", DR.ResourceSet)]
1746         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
1747         [TypeConverter(typeof(ColorPickerConverter))]
1748         public Color PreviewForeColor
1749         {
1750             get
1751             {
1752                 return this.previewForeColor;
1753             }
1754 
1755             set
1756             {
1757                 if (ReadOnly)
1758                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1759 
1760                 this.previewForeColor = value;
1761                 if (this.previewForegroundBrush != null)
1762                 {
1763                     this.previewForegroundBrush.Dispose();
1764                     this.previewForegroundBrush = null;
1765                 }
1766             }
1767         }
1768 
1769         [DispId(14)]
1770         [SRDescription("PreviewBackColorDesc", DR.ResourceSet)]
1771         [SRCategory("BackgroundCategory", DR.ResourceSet)]
1772         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
1773         [TypeConverter(typeof(ColorPickerConverter))]
1774         public Color PreviewBackColor
1775         {
1776             get
1777             {
1778                 return this.previewBackColor;
1779             }
1780 
1781             set
1782             {
1783                 if (ReadOnly)
1784                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1785 
1786                 this.previewBackColor = value;
1787                 if (this.previewBackgroundBrush != null)
1788                 {
1789                     this.previewBackgroundBrush.Dispose();
1790                     this.previewBackgroundBrush = null;
1791                 }
1792             }
1793         }
1794 
1795         [DispId(15)]
1796         [SRDescription("PreviewBorderColorDesc", DR.ResourceSet)]
1797         [SRCategory("ForegroundCategory", DR.ResourceSet)]
1798         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
1799         [TypeConverter(typeof(ColorPickerConverter))]
1800         public Color PreviewBorderColor
1801         {
1802             get
1803             {
1804                 return this.previewBorderColor;
1805             }
1806 
1807             set
1808             {
1809                 if (ReadOnly)
1810                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
1811 
1812                 this.previewBorderColor = value;
1813                 if (this.previewBorderPen != null)
1814                 {
1815                     this.previewBorderPen.Dispose();
1816                     this.previewBorderPen = null;
1817                 }
1818             }
1819         }
1820         #endregion
1821 
1822         #region Helper Properties
1823         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1824         [Browsable(false)]
1825         internal Size PreviewItemSize
1826         {
1827             get
1828             {
1829                 return ActivityPreviewDesignerTheme.ItemSizes[(int)ContainingTheme.AmbientTheme.DesignerSize];
1830             }
1831         }
1832 
1833         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1834         [Browsable(false)]
1835         internal int PreviewItemCount
1836         {
1837             get
1838             {
1839                 return ActivityPreviewDesignerTheme.DefaultItemCount;
1840             }
1841         }
1842 
1843         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1844         [Browsable(false)]
1845         internal Size PreviewWindowSize
1846         {
1847             get
1848             {
1849                 return ActivityPreviewDesignerTheme.PreviewWindowSizes[(int)ContainingTheme.AmbientTheme.DesignerSize];
1850             }
1851         }
1852 
1853         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1854         [Browsable(false)]
1855         internal Size PreviewButtonSize
1856         {
1857             get
1858             {
1859                 return ActivityPreviewDesignerTheme.PreviewButtonSizes[(int)ContainingTheme.AmbientTheme.DesignerSize];
1860             }
1861         }
1862 
1863         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1864         [Browsable(false)]
1865         internal Pen PreviewBorderPen
1866         {
1867             get
1868             {
1869                 if (this.previewBorderPen == null)
1870                     this.previewBorderPen = new Pen(this.previewBorderColor, BorderWidth);
1871                 return this.previewBorderPen;
1872             }
1873         }
1874 
1875         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1876         [Browsable(false)]
1877         internal Brush PreviewForegroundBrush
1878         {
1879             get
1880             {
1881                 if (this.previewForegroundBrush == null)
1882                     this.previewForegroundBrush = new SolidBrush(this.previewForeColor);
1883                 return this.previewForegroundBrush;
1884             }
1885         }
1886 
1887         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1888         [Browsable(false)]
1889         internal Brush PreviewBackgroundBrush
1890         {
1891             get
1892             {
1893                 if (this.previewBackgroundBrush == null)
1894                     this.previewBackgroundBrush = new SolidBrush(this.previewBackColor);
1895                 return this.previewBackgroundBrush;
1896             }
1897         }
1898 
OnAmbientPropertyChanged(AmbientProperty ambientProperty)1899         public override void OnAmbientPropertyChanged(AmbientProperty ambientProperty)
1900         {
1901             base.OnAmbientPropertyChanged(ambientProperty);
1902 
1903             if (ambientProperty == AmbientProperty.DesignerSize)
1904                 PreviewBorderColor = this.previewBorderColor;
1905             else if (ambientProperty == AmbientProperty.OperatingSystemSetting)
1906                 ApplySystemColors();
1907         }
1908 
ApplySystemColors()1909         private void ApplySystemColors()
1910         {
1911             PreviewForeColor = SystemColors.ButtonFace;
1912             PreviewBackColor = SystemColors.Window;
1913             PreviewBorderColor = SystemColors.ControlDarkDark;
1914             BorderColor = SystemColors.ControlDarkDark;
1915         }
1916         #endregion
1917     }
1918     #endregion
1919 
1920     #region Class AmbientTheme
1921     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
1922     public class AmbientTheme : DesignerTheme
1923     {
1924         #region Constants which wont change
1925         internal const float WatermarkTransparency = 0.25f;
1926         internal const int ArcDiameter = 8;
1927         internal const int DropShadowWidth = 4;
1928 
1929         internal static Color TransparentColor = Color.FromArgb(255, 0, 255);
1930         internal static readonly Image ConfigErrorImage = DR.GetImage(DR.ConfigError);
1931         internal static readonly Image ScrollIndicatorImage = DR.GetImage(DR.ArrowLeft);
1932         internal static readonly Image DropIndicatorImage = DR.GetImage(DR.DropShapeShort);
1933         internal static readonly Image LockImage = DR.GetImage(DR.PreviewIndicator);
1934         internal static readonly Image ReadOnlyImage = DR.GetImage(DR.ReadOnly);
1935 
1936         internal static readonly Pen SmartTagBorderPen = new Pen(Color.Black, 1);
1937         internal static readonly Pen MagnifierPen = new Pen(Color.Black, 2);
1938         internal static readonly Pen WorkflowBorderPen = new Pen(Color.FromArgb(127, 157, 185), 1);
1939         internal static readonly Brush WorkspaceBackgroundBrush = new SolidBrush(Color.FromArgb(234, 234, 236));
1940         internal static readonly Brush FadeBrush = new SolidBrush(Color.FromArgb(120, 255, 255, 255));
1941         internal static readonly Brush DisabledBrush = new SolidBrush(Color.FromArgb(40, Color.Gray));
1942         internal static readonly Brush PageShadowBrush = new SolidBrush(Color.FromArgb(75, 75, 75));
1943 
1944         internal const float ScrollIndicatorTransparency = 0.7f;
1945         internal static readonly Size DragImageMargins = new Size(4, 4);
1946         internal static readonly Size DragImageTextSize = new Size(100, 60);
1947         internal static readonly Size DragImageIconSize = new Size(16, 16);
1948 
1949         internal const int MinZoom = 10;
1950         internal const int MaxZoom = 400;
1951         internal const int ScrollUnit = 25;
1952         internal const int MinShadowDepth = 0;
1953         internal const int MaxShadowDepth = 8;
1954 
1955         private static float[] fontSizes = null;
1956         private static readonly Size[] GridSizes = new Size[] { new Size(30, 30), new Size(40, 40), new Size(60, 60) };
1957         private static readonly Size[] MarginSizes = new Size[] { new Size(2, 2), new Size(4, 4), new Size(6, 6) };
1958         private static readonly Size[] SelectionSizes = new Size[] { new Size(2, 2), new Size(4, 4), new Size(6, 6) };
1959         private static readonly Size[] GlyphSizes = new Size[] { new Size(10, 10), new Size(14, 14), new Size(18, 18) };
1960         private static readonly Size[] ScrollIndicatorSizes = new Size[] { new Size(24, 24), new Size(32, 32), new Size(40, 40) };
1961         private static readonly Size[] DropIndicatorSizes = new Size[] { new Size(8, 8), new Size(12, 12), new Size(16, 16) };
1962         private static readonly Size[] MagnifierSizes = new Size[] { new Size(50, 50), new Size(100, 100), new Size(150, 150) };
1963         private static readonly int[] BorderWidths = new int[] { 1, 1, 3 };
1964 
1965         private const int DefaultShadowDepth = 6;
1966         #endregion
1967 
1968         private static float[] FontSizes
1969         {
1970             get
1971             {
1972                 if (fontSizes == null)
1973                     fontSizes = new float[] { WorkflowTheme.GetDefaultFont().SizeInPoints - 2.0f, WorkflowTheme.GetDefaultFont().SizeInPoints, WorkflowTheme.GetDefaultFont().SizeInPoints + 2.0f };
1974                 return fontSizes;
1975             }
1976         }
1977 
1978         #region Members
1979         //General category
1980         private bool useOperatingSystemSettings = false;
1981         private bool showConfigErrors = true;
1982         private bool drawShadow = false;
1983 
1984         //Advanced
1985         private bool drawGrayscale = false;
1986         private Color dropIndicatorColor = Color.Green;
1987         private Color selectionForeColor = Color.Blue;
1988         private Color selectionPatternColor = Color.DarkGray;
1989         private Color foreColor = Color.Gray;
1990         private Color backColor = Color.White;
1991         private Color commentIndicatorColor = Color.FromArgb(49, 198, 105);
1992         private Color readonlyIndicatorColor = Color.Gray;
1993         private DesignerContentAlignment watermarkAlignment = DesignerContentAlignment.BottomRight;
1994         private string watermarkImagePath = String.Empty;
1995         private bool useDefaultFont = false;
1996 
1997         //Grid
1998         private bool showGrid = false;
1999         private DashStyle gridStyle = DashStyle.Dash;
2000         private Color gridColor = Color.FromArgb(192, 192, 192);
2001 
2002         //Font
2003         private string fontName = WorkflowTheme.GetDefaultFont().FontFamily.Name;
2004         private TextQuality textQuality = TextQuality.Aliased;
2005 
2006         //Designer
2007         private DesignerSize designerStyle = DesignerSize.Medium;
2008         private bool drawRounded = true;
2009         private bool showDesignerBorder = true;
2010         #endregion
2011 
2012         #region Resource Members
2013         private Font font;
2014         private Font boldFont;
2015         private Pen foregroundPen;
2016         private Pen selectionForegroundPen;
2017         private Pen selectionPatternPen;
2018         private Pen majorGridPen;
2019         private Pen minorGridPen;
2020         private Pen dropIndicatorPen;
2021         private Pen commentIndicatorPen;
2022         private Brush backgroundBrush;
2023         private Brush foregroundBrush;
2024         private Brush selectionForegroundBrush;
2025         private Brush dropIndicatorBrush;
2026         private Brush commentIndicatorBrush;
2027         private Brush readonlyIndicatorBrush;
2028         private Brush majorGridBrush;
2029         private Brush minorGridBrush;
2030         private Image watermarkImage;
2031         #endregion
2032 
AmbientTheme(WorkflowTheme theme)2033         public AmbientTheme(WorkflowTheme theme)
2034             : base(theme)
2035         {
2036         }
2037 
Dispose(bool disposing)2038         protected override void Dispose(bool disposing)
2039         {
2040             try
2041             {
2042                 //We stop listening to OS setting events
2043                 UseOperatingSystemSettings = false;
2044 
2045                 if (this.font != null)
2046                 {
2047                     this.font.Dispose();
2048                     this.font = null;
2049                 }
2050 
2051                 if (this.boldFont != null)
2052                 {
2053                     this.boldFont.Dispose();
2054                     this.boldFont = null;
2055                 }
2056 
2057                 if (this.watermarkImage != null)
2058                 {
2059                     this.watermarkImage.Dispose();
2060                     this.watermarkImage = null;
2061                 }
2062 
2063                 if (this.foregroundPen != null)
2064                 {
2065                     this.foregroundPen.Dispose();
2066                     this.foregroundPen = null;
2067                 }
2068 
2069                 if (this.foregroundBrush != null)
2070                 {
2071                     this.foregroundBrush.Dispose();
2072                     this.foregroundBrush = null;
2073                 }
2074 
2075                 if (this.backgroundBrush != null)
2076                 {
2077                     this.backgroundBrush.Dispose();
2078                     this.backgroundBrush = null;
2079                 }
2080 
2081                 if (this.dropIndicatorPen != null)
2082                 {
2083                     this.dropIndicatorPen.Dispose();
2084                     this.dropIndicatorPen = null;
2085                 }
2086 
2087                 if (this.selectionPatternPen != null)
2088                 {
2089                     this.selectionPatternPen.Dispose();
2090                     this.selectionPatternPen = null;
2091                 }
2092 
2093                 if (this.selectionForegroundPen != null)
2094                 {
2095                     this.selectionForegroundPen.Dispose();
2096                     this.selectionForegroundPen = null;
2097                 }
2098 
2099                 if (this.majorGridPen != null)
2100                 {
2101                     this.majorGridPen.Dispose();
2102                     this.majorGridPen = null;
2103                 }
2104 
2105                 if (this.majorGridBrush != null)
2106                 {
2107                     this.majorGridBrush.Dispose();
2108                     this.majorGridBrush = null;
2109                 }
2110 
2111                 if (this.minorGridPen != null)
2112                 {
2113                     this.minorGridPen.Dispose();
2114                     this.minorGridPen = null;
2115                 }
2116 
2117                 if (this.minorGridBrush != null)
2118                 {
2119                     this.minorGridBrush.Dispose();
2120                     this.minorGridBrush = null;
2121                 }
2122 
2123                 if (this.commentIndicatorPen != null)
2124                 {
2125                     this.commentIndicatorPen.Dispose();
2126                     this.commentIndicatorPen = null;
2127                 }
2128 
2129                 if (this.commentIndicatorBrush != null)
2130                 {
2131                     this.commentIndicatorBrush.Dispose();
2132                     this.commentIndicatorBrush = null;
2133                 }
2134 
2135                 if (this.readonlyIndicatorBrush != null)
2136                 {
2137                     this.readonlyIndicatorBrush.Dispose();
2138                     this.readonlyIndicatorBrush = null;
2139                 }
2140 
2141                 if (this.dropIndicatorBrush != null)
2142                 {
2143                     this.dropIndicatorBrush.Dispose();
2144                     this.dropIndicatorBrush = null;
2145                 }
2146 
2147                 if (this.selectionForegroundBrush != null)
2148                 {
2149                     this.selectionForegroundBrush.Dispose();
2150                     this.selectionForegroundBrush = null;
2151                 }
2152             }
2153             finally
2154             {
2155                 base.Dispose(disposing);
2156             }
2157         }
2158 
Initialize()2159         public override void Initialize()
2160         {
2161             base.Initialize();
2162 
2163             if (this.useOperatingSystemSettings)
2164                 ApplySystemColors();
2165         }
2166 
2167         #region Publicly browsable Properties
2168 
2169         #region General Properties
2170         [Browsable(false)]
2171         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2172         public virtual bool UseOperatingSystemSettings
2173         {
2174             get
2175             {
2176                 return this.useOperatingSystemSettings;
2177             }
2178 
2179             internal set
2180             {
2181                 this.useOperatingSystemSettings = value;
2182                 if (this.useOperatingSystemSettings)
2183                 {
2184                     SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(OnOperatingSystemSettingsChanged);
2185                     OnOperatingSystemSettingsChanged(this, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Color));
2186                 }
2187                 else
2188                 {
2189                     SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(OnOperatingSystemSettingsChanged);
2190                 }
2191             }
2192         }
2193 
2194         [DispId(1)]
2195         [SRDescription("FontDesc", DR.ResourceSet)]
2196         [SRCategory("WorkflowAppearanceCategory", DR.ResourceSet)]
2197         [TypeConverter(typeof(FontFamilyConverter))]
2198         public virtual string FontName
2199         {
2200             get
2201             {
2202                 return this.fontName;
2203             }
2204 
2205             set
2206             {
2207                 if (ReadOnly)
2208                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2209 
2210                 if (value == null || value.Length == 0)
2211                     throw new Exception(DR.GetString(DR.EmptyFontFamilyNotSupported));
2212 
2213                 try
2214                 {
2215                     Font font = new Font(value, FontSize);
2216                     if (font != null)
2217                         font.Dispose();
2218                 }
2219                 catch (Exception e)
2220                 {
2221                     throw new Exception(DR.GetString(DR.FontFamilyNotSupported, value), e);
2222                 }
2223 
2224                 this.fontName = value;
2225                 if (this.font != null)
2226                 {
2227                     this.font.Dispose();
2228                     this.font = null;
2229                 }
2230 
2231                 if (this.boldFont != null)
2232                 {
2233                     this.boldFont.Dispose();
2234                     this.boldFont = null;
2235                 }
2236             }
2237         }
2238 
2239         [DefaultValue(TextQuality.Aliased)]
2240         [DispId(2)]
2241         [SRDescription("TextQualityDesc", DR.ResourceSet)]
2242         [SRCategory("WorkflowAppearanceCategory", DR.ResourceSet)]
2243         public virtual TextQuality TextQuality
2244         {
2245             get
2246             {
2247                 return this.textQuality;
2248             }
2249 
2250             set
2251             {
2252                 if (ReadOnly)
2253                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2254 
2255                 this.textQuality = value;
2256             }
2257         }
2258 
2259         [DispId(3)]
2260         [DefaultValue(true)]
2261         [SRDescription("ShowConfigErrorDesc", DR.ResourceSet)]
2262         [SRCategory("WorkflowAppearanceCategory", DR.ResourceSet)]
2263         public virtual bool ShowConfigErrors
2264         {
2265             get
2266             {
2267                 return this.showConfigErrors;
2268             }
2269 
2270             set
2271             {
2272                 if (ReadOnly)
2273                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2274 
2275                 this.showConfigErrors = value;
2276             }
2277         }
2278 
2279         [DefaultValue(false)]
2280         [DispId(6)]
2281         [SRDescription("GrayscaleWorkflowDesc", DR.ResourceSet)]
2282         [SRCategory("WorkflowAppearanceCategory", DR.ResourceSet)]
2283         public virtual bool DrawGrayscale
2284         {
2285             get
2286             {
2287                 return this.drawGrayscale;
2288             }
2289 
2290             set
2291             {
2292                 if (ReadOnly)
2293                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2294 
2295                 this.drawGrayscale = value;
2296             }
2297         }
2298         #endregion
2299 
2300         #region Workflow Foreground Properties
2301         [DispId(7)]
2302         [SRDescription("DropHiliteDesc", DR.ResourceSet)]
2303         [SRCategory("ForegroundCategory", DR.ResourceSet)]
2304         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
2305         [TypeConverter(typeof(ColorPickerConverter))]
2306         public virtual Color DropIndicatorColor
2307         {
2308             get
2309             {
2310                 return this.dropIndicatorColor;
2311             }
2312 
2313             set
2314             {
2315                 if (ReadOnly)
2316                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2317 
2318                 this.dropIndicatorColor = value;
2319 
2320                 if (this.dropIndicatorPen != null)
2321                 {
2322                     this.dropIndicatorPen.Dispose();
2323                     this.dropIndicatorPen = null;
2324                 }
2325 
2326                 if (this.dropIndicatorBrush != null)
2327                 {
2328                     this.dropIndicatorBrush.Dispose();
2329                     this.dropIndicatorBrush = null;
2330                 }
2331             }
2332         }
2333 
2334         [DispId(8)]
2335         [SRDescription("SelectionForegroundDesc", DR.ResourceSet)]
2336         [SRCategory("ForegroundCategory", DR.ResourceSet)]
2337         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
2338         [TypeConverter(typeof(ColorPickerConverter))]
2339         public virtual Color SelectionForeColor
2340         {
2341             get
2342             {
2343                 return this.selectionForeColor;
2344             }
2345 
2346             set
2347             {
2348                 if (ReadOnly)
2349                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2350 
2351                 this.selectionForeColor = value;
2352 
2353                 if (this.selectionForegroundPen != null)
2354                 {
2355                     this.selectionForegroundPen.Dispose();
2356                     this.selectionForegroundPen = null;
2357                 }
2358 
2359                 if (this.selectionForegroundBrush != null)
2360                 {
2361                     this.selectionForegroundBrush.Dispose();
2362                     this.selectionForegroundBrush = null;
2363                 }
2364             }
2365         }
2366 
2367         [DispId(9)]
2368         [SRDescription("SelectionPatternDesc", DR.ResourceSet)]
2369         [SRCategory("ForegroundCategory", DR.ResourceSet)]
2370         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
2371         [TypeConverter(typeof(ColorPickerConverter))]
2372         public virtual Color SelectionPatternColor
2373         {
2374             get
2375             {
2376                 return this.selectionPatternColor;
2377             }
2378 
2379             set
2380             {
2381                 if (ReadOnly)
2382                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2383 
2384                 this.selectionPatternColor = value;
2385 
2386                 if (this.selectionPatternPen != null)
2387                 {
2388                     this.selectionPatternPen.Dispose();
2389                     this.selectionPatternPen = null;
2390                 }
2391             }
2392         }
2393 
2394         [DispId(10)]
2395         [SRDescription("WorkflowForegroundDesc", DR.ResourceSet)]
2396         [SRCategory("ForegroundCategory", DR.ResourceSet)]
2397         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
2398         [TypeConverter(typeof(ColorPickerConverter))]
2399         public virtual Color ForeColor
2400         {
2401             get
2402             {
2403                 return this.foreColor;
2404             }
2405 
2406             set
2407             {
2408                 if (ReadOnly)
2409                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2410 
2411                 this.foreColor = value;
2412 
2413                 if (this.foregroundPen != null)
2414                 {
2415                     this.foregroundPen.Dispose();
2416                     this.foregroundPen = null;
2417                 }
2418 
2419                 if (this.foregroundBrush != null)
2420                 {
2421                     this.foregroundBrush.Dispose();
2422                     this.foregroundBrush = null;
2423                 }
2424             }
2425         }
2426 
2427         [DispId(11)]
2428         [SRDescription("CommentColorDesc", DR.ResourceSet)]
2429         [SRCategory("ForegroundCategory", DR.ResourceSet)]
2430         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
2431         [TypeConverter(typeof(ColorPickerConverter))]
2432         public virtual Color CommentIndicatorColor
2433         {
2434             get
2435             {
2436                 return this.commentIndicatorColor;
2437             }
2438 
2439             set
2440             {
2441                 if (ReadOnly)
2442                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2443 
2444                 this.commentIndicatorColor = value;
2445 
2446                 if (this.commentIndicatorPen != null)
2447                 {
2448                     this.commentIndicatorPen.Dispose();
2449                     this.commentIndicatorPen = null;
2450                 }
2451 
2452                 if (this.commentIndicatorBrush != null)
2453                 {
2454                     this.commentIndicatorBrush.Dispose();
2455                     this.commentIndicatorBrush = null;
2456                 }
2457             }
2458         }
2459 
2460         [DispId(12)]
2461         [SRDescription("LockColorDesc", DR.ResourceSet)]
2462         [SRCategory("ForegroundCategory", DR.ResourceSet)]
2463         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
2464         [TypeConverter(typeof(ColorPickerConverter))]
2465         public virtual Color ReadonlyIndicatorColor
2466         {
2467             get
2468             {
2469                 return this.readonlyIndicatorColor;
2470             }
2471 
2472             set
2473             {
2474                 if (ReadOnly)
2475                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2476 
2477                 this.readonlyIndicatorColor = value;
2478 
2479                 if (this.readonlyIndicatorBrush != null)
2480                 {
2481                     this.readonlyIndicatorBrush.Dispose();
2482                     this.readonlyIndicatorBrush = null;
2483                 }
2484             }
2485         }
2486         #endregion
2487 
2488         #region Workflow Background Properties
2489         [DispId(13)]
2490         [SRDescription("WorkflowBackgroundDesc", DR.ResourceSet)]
2491         [SRCategory("BackgroundCategory", DR.ResourceSet)]
2492         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
2493         [TypeConverter(typeof(ColorPickerConverter))]
2494         public virtual Color BackColor
2495         {
2496             get
2497             {
2498                 return this.backColor;
2499             }
2500 
2501             set
2502             {
2503                 if (ReadOnly)
2504                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2505 
2506                 this.backColor = value;
2507 
2508                 if (this.backgroundBrush != null)
2509                 {
2510                     this.backgroundBrush.Dispose();
2511                     this.backgroundBrush = null;
2512                 }
2513             }
2514         }
2515 
2516         [DefaultValue(false)]
2517         [DispId(14)]
2518         [SRDescription("WorkflowShadowDesc", DR.ResourceSet)]
2519         [SRCategory("WorkflowAppearanceCategory", DR.ResourceSet)]
2520         public virtual bool DrawShadow
2521         {
2522             get
2523             {
2524                 return this.drawShadow;
2525             }
2526 
2527             set
2528             {
2529                 if (ReadOnly)
2530                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2531 
2532                 this.drawShadow = value;
2533             }
2534         }
2535 
2536 
2537         [DispId(15)]
2538         [SRDescription("WorkflowWatermarkDesc", DR.ResourceSet)]
2539         [SRCategory("BackgroundCategory", DR.ResourceSet)]
2540         [Editor(typeof(ImageBrowserEditor), typeof(UITypeEditor))]
2541         public virtual string WatermarkImagePath
2542         {
2543             get
2544             {
2545                 return this.watermarkImagePath;
2546             }
2547 
2548             set
2549             {
2550                 if (ReadOnly)
2551                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2552 
2553                 if (!String.IsNullOrEmpty(value) && value.Contains(Path.DirectorySeparatorChar.ToString()) && Path.IsPathRooted(value))
2554                 {
2555                     value = DesignerHelpers.GetRelativePath(ContainingTheme.ContainingFileDirectory, value);
2556 
2557                     if (!DesignerHelpers.IsValidImageResource(this, ContainingTheme.ContainingFileDirectory, value))
2558                         throw new InvalidOperationException(DR.GetString(DR.Error_InvalidImageResource));
2559                 }
2560 
2561                 this.watermarkImagePath = value;
2562                 if (this.watermarkImage != null)
2563                 {
2564                     this.watermarkImage.Dispose();
2565                     this.watermarkImage = null;
2566                 }
2567             }
2568         }
2569 
2570         [DispId(16)]
2571         [DefaultValue(DesignerContentAlignment.BottomRight)]
2572         [SRDescription("WatermarkAlignmentDesc", DR.ResourceSet)]
2573         [SRCategory("BackgroundCategory", DR.ResourceSet)]
2574         public virtual DesignerContentAlignment WatermarkAlignment
2575         {
2576             get
2577             {
2578                 return this.watermarkAlignment;
2579             }
2580 
2581             set
2582             {
2583                 if (ReadOnly)
2584                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2585 
2586                 this.watermarkAlignment = value;
2587             }
2588         }
2589 
2590         [DefaultValue(false)]
2591         [DispId(17)]
2592         [SRDescription("ShowGridDesc", DR.ResourceSet)]
2593         [SRCategory("BackgroundCategory", DR.ResourceSet)]
2594         public virtual bool ShowGrid
2595         {
2596             get
2597             {
2598                 return this.showGrid;
2599             }
2600 
2601             set
2602             {
2603                 if (ReadOnly)
2604                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2605 
2606                 this.showGrid = value;
2607             }
2608         }
2609 
2610         [DefaultValue(DashStyle.Dash)]
2611         [DispId(18)]
2612         [SRDescription("GridStyleDesc", DR.ResourceSet)]
2613         [SRCategory("BackgroundCategory", DR.ResourceSet)]
2614         public virtual DashStyle GridStyle
2615         {
2616             get
2617             {
2618                 return this.gridStyle;
2619             }
2620 
2621             set
2622             {
2623                 if (ReadOnly)
2624                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2625 
2626                 this.gridStyle = value;
2627 
2628                 if (this.majorGridPen != null)
2629                 {
2630                     this.majorGridPen.Dispose();
2631                     this.majorGridPen = null;
2632                 }
2633 
2634                 if (this.minorGridPen != null)
2635                 {
2636                     this.minorGridPen.Dispose();
2637                     this.minorGridPen = null;
2638                 }
2639             }
2640         }
2641 
2642         [DispId(19)]
2643         [SRDescription("GridColorDesc", DR.ResourceSet)]
2644         [SRCategory("BackgroundCategory", DR.ResourceSet)]
2645         [Editor(typeof(ColorPickerEditor), typeof(UITypeEditor))]
2646         [TypeConverter(typeof(ColorPickerConverter))]
2647         public virtual Color GridColor
2648         {
2649             get
2650             {
2651                 return this.gridColor;
2652             }
2653 
2654             set
2655             {
2656                 if (ReadOnly)
2657                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2658 
2659                 this.gridColor = value;
2660 
2661                 if (this.majorGridPen != null)
2662                 {
2663                     this.majorGridPen.Dispose();
2664                     this.majorGridPen = null;
2665                 }
2666 
2667                 if (this.majorGridBrush != null)
2668                 {
2669                     this.majorGridBrush.Dispose();
2670                     this.majorGridBrush = null;
2671                 }
2672 
2673                 if (this.minorGridPen != null)
2674                 {
2675                     this.minorGridPen.Dispose();
2676                     this.minorGridPen = null;
2677                 }
2678 
2679                 if (this.minorGridBrush != null)
2680                 {
2681                     this.minorGridBrush.Dispose();
2682                     this.minorGridBrush = null;
2683                 }
2684             }
2685         }
2686         #endregion
2687 
2688         #endregion
2689 
2690         #region Activity Appearance Properties
2691         //
2692 
2693         [Browsable(false)]
2694         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2695         [DefaultValue(DesignerSize.Medium)]
2696         [DispId(20)]
2697         [SRDescription("DesignerSizeDesc", DR.ResourceSet)]
2698         [SRCategory("ActivityAppearanceCategory", DR.ResourceSet)]
2699         public virtual DesignerSize DesignerSize
2700         {
2701             get
2702             {
2703                 return this.designerStyle;
2704             }
2705 
2706             set
2707             {
2708                 if (ReadOnly)
2709                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2710 
2711                 this.designerStyle = value;
2712                 ContainingTheme.AmbientPropertyChanged(AmbientProperty.DesignerSize);
2713             }
2714         }
2715 
2716         [DefaultValue(true)]
2717         [DispId(21)]
2718         [SRDescription("DrawRoundedDesignersDesc", DR.ResourceSet)]
2719         [SRCategory("ActivityAppearanceCategory", DR.ResourceSet)]
2720         public virtual bool DrawRounded
2721         {
2722             get
2723             {
2724                 return this.drawRounded;
2725             }
2726 
2727             set
2728             {
2729                 if (ReadOnly)
2730                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2731 
2732                 this.drawRounded = value;
2733             }
2734         }
2735 
2736         [DefaultValue(true)]
2737         [DispId(24)]
2738         [SRDescription("DesignerBorderDesc", DR.ResourceSet)]
2739         [SRCategory("ActivityAppearanceCategory", DR.ResourceSet)]
2740         public virtual bool ShowDesignerBorder
2741         {
2742             get
2743             {
2744                 return this.showDesignerBorder;
2745             }
2746 
2747             set
2748             {
2749                 if (ReadOnly)
2750                     throw new InvalidOperationException(DR.GetString(DR.ThemePropertyReadOnly));
2751 
2752                 this.showDesignerBorder = value;
2753             }
2754         }
2755         #endregion
2756 
2757         #region Helper Properties and Methods
2758         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2759         [Browsable(false)]
2760         public virtual Size Margin
2761         {
2762             get
2763             {
2764                 return AmbientTheme.MarginSizes[(int)this.designerStyle];
2765             }
2766         }
2767 
2768         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2769         [Browsable(false)]
2770         public virtual Size SelectionSize
2771         {
2772             get
2773             {
2774                 return AmbientTheme.SelectionSizes[(int)this.designerStyle];
2775             }
2776         }
2777 
2778         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2779         [Browsable(false)]
2780         public virtual Size GlyphSize
2781         {
2782             get
2783             {
2784                 return AmbientTheme.GlyphSizes[(int)this.designerStyle];
2785             }
2786         }
2787 
2788         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2789         [Browsable(false)]
2790         internal Size ScrollIndicatorSize
2791         {
2792             get
2793             {
2794                 return AmbientTheme.ScrollIndicatorSizes[(int)this.designerStyle];
2795             }
2796         }
2797 
2798         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2799         [Browsable(false)]
2800         internal Size DropIndicatorSize
2801         {
2802             get
2803             {
2804                 return AmbientTheme.DropIndicatorSizes[(int)this.designerStyle];
2805             }
2806         }
2807 
2808         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2809         [Browsable(false)]
2810         internal Size MagnifierSize
2811         {
2812             get
2813             {
2814                 return AmbientTheme.MagnifierSizes[(int)this.designerStyle];
2815             }
2816         }
2817 
2818         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2819         [Browsable(false)]
2820         internal int ShadowDepth
2821         {
2822             get
2823             {
2824                 return ((this.drawShadow) ? AmbientTheme.DefaultShadowDepth : 0);
2825             }
2826         }
2827 
2828         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2829         [Browsable(false)]
2830         public virtual Size GridSize
2831         {
2832             get
2833             {
2834                 return AmbientTheme.GridSizes[(int)this.designerStyle];
2835             }
2836         }
2837 
2838         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2839         [Browsable(false)]
2840         public virtual int BorderWidth
2841         {
2842             get
2843             {
2844                 return AmbientTheme.BorderWidths[(int)ContainingTheme.AmbientTheme.DesignerSize];
2845             }
2846         }
2847 
2848         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2849         [Browsable(false)]
2850         public Pen MajorGridPen
2851         {
2852             get
2853             {
2854                 if (this.majorGridPen == null)
2855                 {
2856                     this.majorGridPen = new Pen(this.gridColor, 1);
2857                     this.majorGridPen.DashStyle = DashStyle.Dash;
2858                 }
2859                 return this.majorGridPen;
2860             }
2861         }
2862 
2863         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2864         [Browsable(false)]
2865         public Brush MajorGridBrush
2866         {
2867             get
2868             {
2869                 if (this.majorGridBrush == null)
2870                     this.majorGridBrush = new SolidBrush(this.gridColor);
2871                 return this.majorGridBrush;
2872             }
2873         }
2874 
2875         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2876         [Browsable(false)]
2877         public Pen MinorGridPen
2878         {
2879             get
2880             {
2881                 if (this.minorGridPen == null)
2882                 {
2883                     Color minorGridColor = Color.FromArgb(this.gridColor.A, Math.Min(this.gridColor.R + 32, 255), Math.Min(this.gridColor.G + 32, 255), Math.Min(this.gridColor.B + 32, 255));
2884                     this.minorGridPen = new Pen(minorGridColor, 1);
2885                     this.minorGridPen.DashStyle = DashStyle.Dot;
2886                 }
2887                 return this.minorGridPen;
2888             }
2889         }
2890 
2891         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2892         [Browsable(false)]
2893         internal Brush MinorGridBrush
2894         {
2895             get
2896             {
2897                 if (this.minorGridBrush == null)
2898                 {
2899                     Color minorGridColor = Color.FromArgb(this.gridColor.A, Math.Min(this.gridColor.R + 32, 255), Math.Min(this.gridColor.G + 32, 255), Math.Min(this.gridColor.B + 32, 255));
2900                     this.minorGridBrush = new SolidBrush(minorGridColor);
2901                 }
2902                 return this.minorGridBrush;
2903             }
2904         }
2905 
2906         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2907         [Browsable(false)]
2908         public Pen SelectionPatternPen
2909         {
2910             get
2911             {
2912                 if (this.selectionPatternPen == null)
2913                 {
2914                     this.selectionPatternPen = new Pen(this.selectionPatternColor, 1);
2915                     this.selectionPatternPen.DashStyle = DashStyle.Dot;
2916                 }
2917 
2918                 return this.selectionPatternPen;
2919             }
2920         }
2921 
2922         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2923         [Browsable(false)]
2924         public Pen SelectionForegroundPen
2925         {
2926             get
2927             {
2928                 if (this.selectionForegroundPen == null)
2929                     this.selectionForegroundPen = new Pen(this.selectionForeColor, 1);
2930                 return this.selectionForegroundPen;
2931             }
2932         }
2933 
2934         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2935         [Browsable(false)]
2936         public Brush SelectionForegroundBrush
2937         {
2938             get
2939             {
2940                 if (this.selectionForegroundBrush == null)
2941                     this.selectionForegroundBrush = new SolidBrush(this.selectionForeColor);
2942                 return this.selectionForegroundBrush;
2943             }
2944         }
2945 
2946         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2947         [Browsable(false)]
2948         public Pen DropIndicatorPen
2949         {
2950             get
2951             {
2952                 if (this.dropIndicatorPen == null)
2953                     this.dropIndicatorPen = new Pen(this.dropIndicatorColor, BorderWidth);
2954                 return this.dropIndicatorPen;
2955             }
2956         }
2957 
2958         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2959         [Browsable(false)]
2960         public Brush DropIndicatorBrush
2961         {
2962             get
2963             {
2964                 if (this.dropIndicatorBrush == null)
2965                     this.dropIndicatorBrush = new SolidBrush(this.dropIndicatorColor);
2966                 return this.dropIndicatorBrush;
2967             }
2968         }
2969 
2970         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2971         [Browsable(false)]
2972         public Pen ForegroundPen
2973         {
2974             get
2975             {
2976                 if (this.foregroundPen == null)
2977                 {
2978                     this.foregroundPen = new Pen(this.foreColor, 1);
2979                     this.foregroundPen.DashStyle = DashStyle.Dot;
2980                 }
2981                 return this.foregroundPen;
2982             }
2983         }
2984 
2985         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2986         [Browsable(false)]
2987         public Pen CommentIndicatorPen
2988         {
2989             get
2990             {
2991                 if (this.commentIndicatorPen == null)
2992                     this.commentIndicatorPen = new Pen(this.commentIndicatorColor, 1);
2993                 return this.commentIndicatorPen;
2994             }
2995         }
2996 
2997         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2998         [Browsable(false)]
2999         public Brush CommentIndicatorBrush
3000         {
3001             get
3002             {
3003                 if (this.commentIndicatorBrush == null)
3004                     this.commentIndicatorBrush = new SolidBrush(Color.FromArgb(40, this.commentIndicatorColor));
3005                 return this.commentIndicatorBrush;
3006             }
3007         }
3008 
3009         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3010         [Browsable(false)]
3011         public Brush ReadonlyIndicatorBrush
3012         {
3013             get
3014             {
3015                 if (this.readonlyIndicatorBrush == null)
3016                     this.readonlyIndicatorBrush = new SolidBrush(Color.FromArgb(20, this.readonlyIndicatorColor));
3017                 return this.readonlyIndicatorBrush;
3018             }
3019         }
3020 
3021         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3022         [Browsable(false)]
3023         public Brush ForegroundBrush
3024         {
3025             get
3026             {
3027                 if (this.foregroundBrush == null)
3028                     this.foregroundBrush = new SolidBrush(this.foreColor);
3029                 return this.foregroundBrush;
3030             }
3031         }
3032 
3033         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3034         [Browsable(false)]
3035         public Brush BackgroundBrush
3036         {
3037             get
3038             {
3039                 if (this.backgroundBrush == null)
3040                     this.backgroundBrush = new SolidBrush(this.backColor);
3041                 return this.backgroundBrush;
3042             }
3043         }
3044 
3045         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3046         [Browsable(false)]
3047         public Image WorkflowWatermarkImage
3048         {
3049             get
3050             {
3051                 if (this.watermarkImage == null && this.watermarkImagePath.Length > 0)
3052                     this.watermarkImage = DesignerHelpers.GetImageFromPath(this, ContainingTheme.ContainingFileDirectory, this.watermarkImagePath);
3053                 return this.watermarkImage;
3054             }
3055         }
3056 
3057         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3058         [Browsable(false)]
3059         public Font Font
3060         {
3061             get
3062             {
3063                 if (this.font == null)
3064                 {
3065                     Debug.Assert(this.fontName != null && this.fontName.Length > 0);
3066                     if (this.fontName == null || this.fontName.Length == 0)
3067                         this.fontName = WorkflowTheme.GetDefaultFont().FontFamily.Name;
3068 
3069                     ArrayList supportedFonts = new ArrayList(AmbientTheme.SupportedFonts);
3070                     Debug.Assert(supportedFonts.Contains(this.fontName));
3071                     if (!supportedFonts.Contains(this.fontName))
3072                         this.fontName = WorkflowTheme.GetDefaultFont().FontFamily.Name;
3073 
3074                     this.font = new Font(this.fontName, FontSize);
3075                 }
3076                 return this.font;
3077             }
3078         }
3079 
3080         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3081         [Browsable(false)]
3082         public Font BoldFont
3083         {
3084             get
3085             {
3086                 if (this.boldFont == null)
3087                 {
3088                     Debug.Assert(this.fontName != null && this.fontName.Length > 0);
3089                     if (this.fontName == null || this.fontName.Length == 0)
3090                         this.fontName = WorkflowTheme.GetDefaultFont().FontFamily.Name;
3091 
3092                     ArrayList supportedFonts = new ArrayList(AmbientTheme.SupportedFonts);
3093                     Debug.Assert(supportedFonts.Contains(this.fontName));
3094                     if (!supportedFonts.Contains(this.fontName))
3095                         this.fontName = WorkflowTheme.GetDefaultFont().FontFamily.Name;
3096 
3097                     this.boldFont = new Font(this.fontName, FontSize, FontStyle.Bold);
3098                 }
3099                 return this.boldFont;
3100             }
3101         }
3102 
3103         [Browsable(false)]
3104         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3105         private float FontSize
3106         {
3107             get
3108             {
3109                 //
3110 
3111                 if (this.useOperatingSystemSettings)
3112                     return SystemInformation.MenuFont.SizeInPoints;
3113                 else
3114                     return AmbientTheme.FontSizes[(int)this.DesignerSize];
3115             }
3116         }
3117 
UseDefaultFont()3118         internal void UseDefaultFont()
3119         {
3120             this.useDefaultFont = true;
3121         }
3122 
UpdateFont()3123         internal void UpdateFont()
3124         {
3125             if (this.useDefaultFont)
3126             {
3127                 bool oldReadOnly = ReadOnly;
3128                 ReadOnly = false;
3129                 this.FontName = WorkflowTheme.GetDefaultFont().FontFamily.Name;
3130                 ReadOnly = oldReadOnly;
3131             }
3132         }
3133 
OnAmbientPropertyChanged(AmbientProperty ambientProperty)3134         public override void OnAmbientPropertyChanged(AmbientProperty ambientProperty)
3135         {
3136             base.OnAmbientPropertyChanged(ambientProperty);
3137 
3138             if (ambientProperty == AmbientProperty.DesignerSize)
3139             {
3140                 //We set the same properties again so that the pens and brushes are reset to
3141                 //consider the new designer style for creation
3142                 DropIndicatorColor = this.dropIndicatorColor;
3143                 FontName = this.fontName;
3144             }
3145             else if (ambientProperty == AmbientProperty.OperatingSystemSetting)
3146             {
3147                 //Apply the system colors
3148                 ApplySystemColors();
3149             }
3150         }
3151 
3152         internal static string[] SupportedFonts
3153         {
3154             get
3155             {
3156                 ArrayList fontNames = new ArrayList();
3157                 foreach (FontFamily family in FontFamily.Families)
3158                     fontNames.Add(family.Name);
3159                 fontNames.Sort(CaseInsensitiveComparer.Default);
3160                 return ((string[])fontNames.ToArray(typeof(string)));
3161             }
3162         }
3163 
OnOperatingSystemSettingsChanged(object sender, UserPreferenceChangedEventArgs e)3164         private void OnOperatingSystemSettingsChanged(object sender, UserPreferenceChangedEventArgs e)
3165         {
3166             if (e.Category == UserPreferenceCategory.Color || e.Category == UserPreferenceCategory.VisualStyle)
3167             {
3168                 ContainingTheme.AmbientPropertyChanged(AmbientProperty.OperatingSystemSetting);
3169                 WorkflowTheme.FireThemeChange();
3170             }
3171         }
3172 
ApplySystemColors()3173         private void ApplySystemColors()
3174         {
3175             DropIndicatorColor = SystemColors.HotTrack;
3176             SelectionForeColor = SystemColors.Highlight;
3177             SelectionPatternColor = SystemColors.Highlight;
3178             ForeColor = SystemColors.WindowText;
3179             CommentIndicatorColor = SystemColors.GrayText;
3180             ReadonlyIndicatorColor = SystemColors.GrayText;
3181             BackColor = SystemColors.Window;
3182             GridColor = SystemColors.InactiveBorder;
3183             FontName = WorkflowTheme.GetDefaultFont().FontFamily.Name;
3184         }
3185         #endregion
3186 
3187         #region IPropertyValueProvider Implementation
GetPropertyValues(ITypeDescriptorContext context)3188         internal override ICollection GetPropertyValues(ITypeDescriptorContext context)
3189         {
3190             object[] values = new object[] { };
3191             if (string.Equals(context.PropertyDescriptor.Name, "GridStyle", StringComparison.Ordinal))
3192                 values = new object[] { DashStyle.Solid, DashStyle.Dash, DashStyle.Dot };
3193             return values;
3194         }
3195         #endregion
3196     }
3197     #endregion
3198 
3199     #region TypeConverters, TypeDescriptors, PropertyDescriptors, UITypeEditors
3200 
3201     #region Class ThemeTypeDescriptor
3202     internal sealed class ThemeTypeConverter : ExpandableObjectConverter
3203     {
ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)3204         public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
3205         {
3206             if (destinationType == typeof(string) && context.PropertyDescriptor != null)
3207                 return String.Empty;
3208             else
3209                 return base.ConvertTo(context, culture, value, destinationType);
3210         }
3211 
GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)3212         public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
3213         {
3214             PropertyDescriptorCollection srcProperties = base.GetProperties(context, value, attributes);
3215             return srcProperties.Sort(new PropertyDescriptorSorter());
3216         }
3217 
3218         #region Class PropertyDescriptorSorter
3219         private sealed class PropertyDescriptorSorter : IComparer
3220         {
IComparer.Compare(object obj1, object obj2)3221             int IComparer.Compare(object obj1, object obj2)
3222             {
3223                 PropertyDescriptor property1 = obj1 as PropertyDescriptor;
3224                 PropertyDescriptor property2 = obj2 as PropertyDescriptor;
3225                 DispIdAttribute prop1DispID = property1.Attributes[typeof(DispIdAttribute)] as DispIdAttribute;
3226                 DispIdAttribute prop2DispID = property2.Attributes[typeof(DispIdAttribute)] as DispIdAttribute;
3227 
3228                 if (prop1DispID == null)
3229                     return 1;
3230                 else if (prop2DispID == null)
3231                     return -1;
3232                 else
3233                     return prop1DispID.Value - prop2DispID.Value;
3234             }
3235         }
3236         #endregion
3237     }
3238     #endregion
3239 
3240     #region Class ColorPickerConverter
3241     internal sealed class ColorPickerConverter : ColorConverter
3242     {
GetStandardValuesSupported(ITypeDescriptorContext context)3243         public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
3244         {
3245             return false;
3246         }
3247     }
3248     #endregion
3249 
3250     #region Class FilteredEnumConverter
3251     internal sealed class FilteredEnumConverter : PropertyValueProviderTypeConverter
3252     {
CanConvertFrom(ITypeDescriptorContext context, Type sourceType)3253         public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
3254         {
3255             return (sourceType == typeof(string));
3256         }
3257 
ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)3258         public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
3259         {
3260             return Enum.Parse(context.PropertyDescriptor.PropertyType, (string)value);
3261         }
3262     }
3263     #endregion
3264 
3265     #region Class FontFamilyConverter
3266     internal sealed class FontFamilyConverter : TypeConverter
3267     {
GetStandardValuesSupported(ITypeDescriptorContext context)3268         public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
3269         {
3270             return true;
3271         }
3272 
GetStandardValuesExclusive(ITypeDescriptorContext context)3273         public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
3274         {
3275             return true;
3276         }
3277 
GetStandardValues(ITypeDescriptorContext context)3278         public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
3279         {
3280             return new TypeConverter.StandardValuesCollection(AmbientTheme.SupportedFonts);
3281         }
3282     }
3283     #endregion
3284 
3285     #region Class ImageBrowserEditor
3286     internal sealed class ImageBrowserEditor : UITypeEditor
3287     {
GetEditStyle(ITypeDescriptorContext context)3288         public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
3289         {
3290             return UITypeEditorEditStyle.Modal;
3291         }
3292 
EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)3293         public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
3294         {
3295             OpenFileDialog fileDialog = new OpenFileDialog();
3296             fileDialog.AddExtension = true;
3297             fileDialog.DefaultExt = WorkflowTheme.DefaultThemeFileExtension;
3298             fileDialog.CheckFileExists = true;
3299             fileDialog.Filter = DR.GetString(DR.ImageFileFilter);
3300             if (fileDialog.ShowDialog() == DialogResult.OK)
3301                 return fileDialog.FileName;
3302             else
3303                 return value;
3304         }
3305     }
3306     #endregion
3307 
3308     #region Class ColorPickerEditor
3309     internal sealed class ColorPickerEditor : UITypeEditor
3310     {
GetEditStyle(ITypeDescriptorContext context)3311         public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
3312         {
3313             return UITypeEditorEditStyle.Modal;
3314         }
3315 
GetPaintValueSupported(ITypeDescriptorContext context)3316         public override bool GetPaintValueSupported(ITypeDescriptorContext context)
3317         {
3318             return (context != null && context.PropertyDescriptor != null);
3319         }
3320 
PaintValue(PaintValueEventArgs e)3321         public override void PaintValue(PaintValueEventArgs e)
3322         {
3323             base.PaintValue(e);
3324 
3325             if (e.Value is Color)
3326             {
3327                 Color selectedColor = (Color)e.Value;
3328                 if (selectedColor != Color.Empty)
3329                 {
3330                     using (Brush fillBrush = new SolidBrush(selectedColor))
3331                         e.Graphics.FillRectangle(fillBrush, e.Bounds);
3332                 }
3333             }
3334         }
3335 
EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)3336         public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
3337         {
3338             ColorDialog colorDialog = new ColorDialog();
3339             colorDialog.AllowFullOpen = true;
3340             colorDialog.FullOpen = true;
3341             colorDialog.AnyColor = true;
3342             colorDialog.Color = (value is Color) ? (Color)value : Color.White;
3343             if (colorDialog.ShowDialog() == DialogResult.OK)
3344                 return colorDialog.Color;
3345             else
3346                 return value;
3347         }
3348     }
3349     #endregion
3350 
3351     #endregion
3352 
3353     #region Serializers
3354 
3355     #region Class ThemeSerializationProvider
3356     internal sealed class ThemeSerializationProvider : WorkflowMarkupSerializationProvider
3357     {
3358         #region IDesignerSerializationProvider Members
GetSerializer(IDesignerSerializationManager manager, object currentSerializer, Type objectType, Type serializerType)3359         public override object GetSerializer(IDesignerSerializationManager manager, object currentSerializer, Type objectType, Type serializerType)
3360         {
3361             if (serializerType.IsAssignableFrom(typeof(WorkflowMarkupSerializer)))
3362             {
3363                 if (typeof(System.Drawing.Color) == objectType)
3364                     return new ColorMarkupSerializer();
3365                 else if (typeof(Size) == objectType)
3366                     return new SizeMarkupSerializer();
3367             }
3368 
3369             return base.GetSerializer(manager, currentSerializer, objectType, serializerType);
3370         }
3371         #endregion
3372     }
3373     #endregion
3374 
3375     #endregion
3376 }
3377