[winforms] Use conditional attributes, not ifdefs to insert conditional code
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.RTF / Font.cs
index 65610a751518941fcc99f4bd65bf1b3fed43490e..7feaa46954ce111b29ee8955f7ac13b2281aa680 100644 (file)
 // COMPLETE
 
 namespace System.Windows.Forms.RTF {
-       internal class Font {
+
+#if RTF_LIB
+       public
+#else
+       internal
+#endif
+       class Font {
                #region Local Variables
                private string          name;
                private string          alt_name;
@@ -38,11 +44,14 @@ namespace System.Windows.Forms.RTF {
                private int             type;
                private int             codepage;
                private Font            next;
+               private RTF             rtf;
                #endregion      // Local Variables
 
                #region Constructors
                public Font(RTF rtf) {
+                       this.rtf = rtf;
                        num = -1;
+                       name = String.Empty;
 
                        lock (rtf) {
                                if (rtf.Fonts == null)
@@ -84,6 +93,8 @@ namespace System.Windows.Forms.RTF {
                        }
 
                        set {
+                               // Whack any previous font with the same number
+                               DeleteFont(rtf, value);
                                num = value;
                        }
                }
@@ -141,6 +152,34 @@ namespace System.Windows.Forms.RTF {
                #endregion      // Properties
 
                #region Methods
+               static public bool DeleteFont(RTF rtf, int font_number) {
+                       Font    f;
+                       Font    prev;
+
+                       lock (rtf) {
+                               f = rtf.Fonts;
+                               prev = null;
+                               while ((f != null) && (f.num != font_number)) {
+                                       prev = f;
+                                       f = f.next;
+                               }
+
+                               if (f != null) {
+                                       if (f == rtf.Fonts) {
+                                               rtf.Fonts = f.next;
+                                       } else {
+                                               if (prev != null) {
+                                                       prev.next = f.next;
+                                               } else {
+                                                       rtf.Fonts = f.next;
+                                               }
+                                       }
+                                       return true;
+                               }
+                       }
+                       return false;
+               }
+
                static public Font GetFont(RTF rtf, int font_number) {
                        Font    f;