* Control.cs: ControlCollection.Count must be public. Fixed build of
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ColorDialog.cs
index 2bd8104edec638ed1ea2d32ed527ff58952184ab..1c478bce6e4b8ebade3ae08ed3231cd219fba8de 100644 (file)
@@ -78,8 +78,6 @@ namespace System.Windows.Forms {
                        
                        form.Text = "Color";
                        
-                       form.Size = new Size (221, 332); // 300
-                       
                        form.FormBorderStyle = FormBorderStyle.FixedDialog;
                        form.MaximizeBox = false;
                        
@@ -196,7 +194,9 @@ namespace System.Windows.Forms {
                        defineColoursButton.Location = new Point (5, 244);
                        defineColoursButton.Size = new Size (210, 22);
                        defineColoursButton.TabIndex = 6;
-                       defineColoursButton.Text = Locale.GetText ("Define Colors >>");
+                       // FIXME: update resource files
+                       defineColoursButton.Text = "Define Custom Colors >>";
+                       //defineColoursButton.Text = Locale.GetText ("Define Custom Colors >>");
                        // okButton
                        okButton.FlatStyle = FlatStyle.System;
                        okButton.Location = new Point (5, 271);
@@ -222,7 +222,9 @@ namespace System.Windows.Forms {
                        addColoursButton.Location = new Point (227, 271);
                        addColoursButton.Size = new Size (213, 22);
                        addColoursButton.TabIndex = 7;
-                       addColoursButton.Text =  Locale.GetText ("Add Colors");
+                       // FIXME: update resource files
+                       addColoursButton.Text =  "Add To Custom Colors";
+                       //addColoursButton.Text =  Locale.GetText ("Add To Custom Colors");
                        
                        // baseColorControl
                        baseColorControl.Location = new Point (3, 6);
@@ -312,6 +314,8 @@ namespace System.Windows.Forms {
                        redTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
                        greenTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
                        blueTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
+                       
+                       ResetCustomColors ();
                }
                #endregion      // Public Constructors
                
@@ -376,15 +380,12 @@ namespace System.Windows.Forms {
                                        
                                        if (fullOpen && allowFullOpen) {
                                                defineColoursButton.Enabled = false;
-                                               
                                                colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
-                                               
-                                               form.Size = new Size (448, 332);
+                                               form.Size = GetFormSize (true);
                                        } else {
                                                if (allowFullOpen)
                                                        defineColoursButton.Enabled = true;
-                                               
-                                               form.Size = new Size (221, 332); // 300
+                                               form.Size = GetFormSize (false);
                                        }
                                }
                        }
@@ -398,11 +399,15 @@ namespace System.Windows.Forms {
                        }
                        
                        set {
-                               if (allowFullOpen) {
-                                       customColors = value;
+                               if (value == null)
+                                       ResetCustomColors ();
+                               else {
+                                       int[] tmp_colors = value;
                                        
-                                       baseColorControl.SetCustomColors ();
+                                       Array.Copy (tmp_colors, customColors, tmp_colors.Length);
                                }
+                                       
+                               baseColorControl.SetCustomColors ();
                        }
                }
                
@@ -449,7 +454,7 @@ namespace System.Windows.Forms {
                
                public override string ToString ()
                {
-                       return base.ToString () + ", Color: " + Color.ToString ();
+                       return base.ToString () + ",  Color: " + Color.ToString ();
                }
                #endregion      // Public Instance Methods
                
@@ -472,6 +477,10 @@ namespace System.Windows.Forms {
                #region Protected Instance Methods
                protected override bool RunDialog (IntPtr hwndOwner)
                {
+                       defineColoursButton.Enabled = (AllowFullOpen && !FullOpen);
+                       defineColoursButton.Refresh ();
+
+                       form.Size = GetFormSize (FullOpen && AllowFullOpen);
                        // currently needed, otherwise there are a lot of drawing artefacts/transparent controls if the same dialog gets opened again
                        form.Refresh ();
                        
@@ -479,7 +488,16 @@ namespace System.Windows.Forms {
                }
                #endregion      // Protected Instance Methods
                
-               #region Private Methods         
+               #region Private Methods
+
+               Size GetFormSize (bool fullOpen)
+               {
+                       if (fullOpen)
+                               return new Size (448, 332);
+                       else
+                               return new Size (221, 332); // 300
+               }
+
                void OnClickCancelButton (object sender, EventArgs e)
                {
                        form.DialogResult = DialogResult.Cancel;
@@ -499,10 +517,8 @@ namespace System.Windows.Forms {
                {
                        if (allowFullOpen) {
                                defineColoursButton.Enabled = false;
-                               
                                colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
-                               
-                               form.Size = new Size (448, 332);
+                               form.Size = GetFormSize (true);
                        }
                }
                
@@ -711,6 +727,18 @@ namespace System.Windows.Forms {
                        
                        UpdateControls (col);
                }
+               
+               void ResetCustomColors ()
+               {
+                       // check if this.customColors already exists
+                       if (customColors == null)
+                               customColors = new int [16];
+                       
+                       int default_color = Color.FromArgb(0, 255, 255, 255).ToArgb ();
+                               
+                       for (int i = 0; i < customColors.Length; i++)
+                               customColors [i] = default_color;
+               }
                #endregion
                
                #region Internal structs and classes
@@ -934,7 +962,6 @@ namespace System.Windows.Forms {
                        private SmallColorControl selectedSmallColorControl;
                        
                        private int currentlyUsedUserSmallColorControl = 0;
-                       private int[] customColors = null;
                        
                        private ColorDialog colorDialog = null;
                        
@@ -1411,19 +1438,7 @@ namespace System.Windows.Forms {
                        {
                                userSmallColorControl [currentlyUsedUserSmallColorControl].InternalColor = col;
                                
-                               // check if this.customColors already exists
-                               if (customColors == null) {
-                                       customColors = new int [16];
-                                       int white = Color.White.ToArgb ();
-                                       
-                                       for (int i = 0; i < customColors.Length; i++)
-                                               customColors [i] = white;
-                               }
-                               
-                               customColors [currentlyUsedUserSmallColorControl] = col.ToArgb ();
-                               
-                               // update ColorDialog dialog property
-                               colorDialog.CustomColors = customColors;
+                               colorDialog.customColors [currentlyUsedUserSmallColorControl] = col.ToArgb ();
                                
                                currentlyUsedUserSmallColorControl++;
                                if (currentlyUsedUserSmallColorControl > 15)
@@ -1432,16 +1447,8 @@ namespace System.Windows.Forms {
                        
                        public void SetCustomColors ()
                        {
-                               int[] customColors = colorDialog.CustomColors;
-                               
-                               if (customColors != null) {
-                                       for (int i = 0; i < customColors.Length; i++) {
-                                               userSmallColorControl [i].InternalColor = Color.FromArgb (customColors [i]);
-                                       }
-                               } else {
-                                       for (int i = 0; i < userSmallColorControl.Length; i++) {
-                                               userSmallColorControl [i].InternalColor = Color.White;
-                                       }
+                               for (int i = 0; i < colorDialog.customColors.Length; i++) {
+                                       userSmallColorControl [i].InternalColor = Color.FromArgb (colorDialog.customColors [i]);
                                }
                        }
                }