/
ColorDialog.cs
137 lines (124 loc) · 4.36 KB
/
ColorDialog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using Eto.Drawing;
namespace Eto.Forms
{
/// <summary>
/// Dialog for choosing a color
/// </summary>
/// <remarks>
/// The color dialog on some platforms may run asynchronously, and return immediately after
/// the <see cref="CommonDialog.ShowDialog(Control)"/> call. For example, on OS X the color picker is a non-modal
/// shared tool window that stays on the screen until the user dismisses it.
///
/// You should always handle the <see cref="ColorChanged"/> event to determine when the value has changed.
/// </remarks>
[Handler(typeof(ColorDialog.IHandler))]
public class ColorDialog : CommonDialog
{
new IHandler Handler { get { return (IHandler)base.Handler; } }
/// <summary>
/// Occurs when the <see cref="Color"/> has changed.
/// </summary>
public event EventHandler<EventArgs> ColorChanged;
/// <summary>
/// Raises the <see cref="ColorChanged"/> event.
/// </summary>
/// <param name="e">Event arguments.</param>
protected virtual void OnColorChanged(EventArgs e)
{
if (ColorChanged != null)
ColorChanged(this, e);
}
/// <summary>
/// Gets or sets the selected color.
/// </summary>
/// <value>The selected color.</value>
public Color Color
{
get { return Handler.Color; }
set { Handler.Color = value; }
}
/// <summary>
/// Gets or sets a value indicating whether the user can adjust the Alpha component of the Color.
/// </summary>
/// <remarks>
/// This may or may not be supported in all platforms (e.g. WinForms).
/// Use <see cref="SupportsAllowAlpha"/> to determine if the current platform supports this feature.
/// </remarks>
/// <value><c>true</c> to allow adjustment of alpha; otherwise, <c>false</c>.</value>
/// <seealso cref="SupportsAllowAlpha"/>
public bool AllowAlpha
{
get { return Handler.AllowAlpha; }
set { Handler.AllowAlpha = value; }
}
/// <summary>
/// Gets a value indicating that the current platform supports the <see cref="AllowAlpha"/> property.
/// </summary>
/// <remarks>
/// If not supported, the setting will be ignored.
/// </remarks>
/// <value><c>true</c> AllowAlpha is supported; otherwise, <c>false</c>.</value>
/// <seealso cref="AllowAlpha"/>
public bool SupportsAllowAlpha => Handler.SupportsAllowAlpha;
static readonly object callback = new Callback();
/// <summary>
/// Gets an instance of an object used to perform callbacks to the widget from handler implementations
/// </summary>
/// <returns>The callback instance to use for this widget</returns>
protected override object GetCallback() { return callback; }
/// <summary>
/// Callback interface for the <see cref="ColorDialog"/>
/// </summary>
public new interface ICallback
{
/// <summary>
/// Raises the color changed event.
/// </summary>
void OnColorChanged(ColorDialog widget, EventArgs e);
}
/// <summary>
/// Callback implementation for handlers of the <see cref="ColorDialog"/>
/// </summary>
protected class Callback : ICallback
{
/// <summary>
/// Raises the color changed event.
/// </summary>
public void OnColorChanged(ColorDialog widget, EventArgs e)
{
widget.Platform.Invoke(() => widget.OnColorChanged(e));
}
}
/// <summary>
/// Handler interface for the <see cref="ColorDialog"/>
/// </summary>
public new interface IHandler : CommonDialog.IHandler
{
/// <summary>
/// Gets or sets the selected color.
/// </summary>
/// <value>The selected color.</value>
Color Color { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the user can adjust the Alpha component of the Color.
/// </summary>
/// <remarks>
/// This may or may not be supported in all platforms (e.g. WinForms).
/// Use <see cref="SupportsAllowAlpha"/> to determine if the current platform supports this feature.
/// </remarks>
/// <value><c>true</c> to allow adjustment of alpha; otherwise, <c>false</c>.</value>
/// <seealso cref="SupportsAllowAlpha"/>
bool AllowAlpha { get; set; }
/// <summary>
/// Gets a value indicating that the current platform supports the <see cref="AllowAlpha"/> property.
/// </summary>
/// <remarks>
/// If not supported, the setting will be ignored.
/// </remarks>
/// <value><c>true</c> AllowAlpha is supported; otherwise, <c>false</c>.</value>
/// <seealso cref="AllowAlpha"/>
bool SupportsAllowAlpha { get; }
}
}
}