2 // System.Windows.Forms.ColorDialog.cs
5 // stubbed out by Jaak Simm (jaaksimm@firm.ee)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
9 // (C) Ximian, Inc., 2002
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System
.Runtime
.InteropServices
;
36 namespace System
.Windows
.Forms
{
39 /// Represents a common dialog box that displays available colors along with controls that allow the user to define custom colors.
42 public class ColorDialog
: CommonDialog
{
44 private bool allowFullOpen
;
45 private bool anyColor
;
47 private int[] customColors
;
48 private bool fullOpen
;
49 private bool showHelp
;
50 private bool solidColorOnly
;
52 public ColorDialog() : base()
57 // these are show to be in the ms implmentation by winchurn
58 // but are not valid since they are not abstract or have any accessors.
59 //protected virtual IntPtr Instance { }
60 //protected virtual int Options { }
62 public virtual bool AllowFullOpen
{
67 allowFullOpen
= value;
71 public virtual bool AnyColor
{
89 public int[] CustomColors
{
94 if ( value != null ) {
95 for ( int i
= 0; i
< Math
.Min ( customColors
.Length
, value.Length
); i
++ )
96 customColors
[ i
] = value [ i
];
101 public virtual bool FullOpen
{
110 public virtual bool ShowHelp
{
119 public virtual bool SolidColorOnly
{
121 return solidColorOnly
;
124 solidColorOnly
= value;
128 public override void Reset()
130 allowFullOpen
= true;
134 customColors
= new int [ 16 ];
135 for ( int i
= 0; i
< customColors
.Length
; i
++ )
136 customColors
[ i
] = Win32
.RGB ( Color
.White
);
140 solidColorOnly
= false;
143 protected override bool RunDialog( IntPtr hwndOwner
)
145 CHOOSECOLOR cc
= new CHOOSECOLOR ( );
146 cc
.hwndOwner
= hwndOwner
;
147 cc
.lStructSize
= ( uint ) Marshal
.SizeOf( cc
);
148 cc
.Flags
= (int) ( ChooseColorFlags
.CC_RGBINIT
| ChooseColorFlags
.CC_ENABLEHOOK
);
150 cc
.lpfnHook
= new Win32
.FnHookProc ( this.HookProc
);
152 if ( AllowFullOpen
) {
154 cc
.Flags
|= (int) ChooseColorFlags
.CC_FULLOPEN
;
156 else cc
.Flags
|= (int) ChooseColorFlags
.CC_PREVENTFULLOPEN
;
159 cc
.Flags
|= (int) ChooseColorFlags
.CC_ANYCOLOR
;
162 cc
.Flags
|= (int) ChooseColorFlags
.CC_SHOWHELP
;
164 if ( SolidColorOnly
)
165 cc
.Flags
|= (int) ChooseColorFlags
.CC_SOLIDCOLOR
;
167 cc
.rgbResult
= Win32
.RGB ( Color
);
169 cc
.lpCustColors
= Marshal
.AllocHGlobal ( Marshal
.SizeOf( customColors
[0] ) * customColors
.Length
);
170 Marshal
.Copy ( customColors
, 0, cc
.lpCustColors
, customColors
.Length
);
174 res
= Win32
.ChooseColor ( ref cc
);
177 this.Color
= Color
.FromArgb ( cc
.rgbResult
);
178 Marshal
.Copy ( cc
.lpCustColors
, customColors
, 0, customColors
.Length
);
182 Marshal
.FreeHGlobal ( cc
.lpCustColors
);
188 public override string ToString()
190 return GetType( ).FullName
.ToString ( ) + ", Color: " + Color
.ToString ( );