Skip to content

Commit f8eb623

Browse files
authored
1376-V100-Extending-KryptonTaskDialog (#2481)
* 1376-V100-Extending-KryptonTaskDialog - Implement a new version of KryptonTaskDialog - Remove old version of KryptonTaskDialogTaskDialog * 1376-V100-Extending-KryptonTaskDialog - Implement a new version of KryptonTaskDialog * 1376-V100-Extending-KryptonTaskDialog - Temporary addidtion of Doxygen documentation * 1376-V100-Extending-KryptonTaskDialog - Fixes: Gradient not painted when BackColor2 is set and BackColor1 is changed. - Fixes: KryptonTaskDialog.Dialog.Form.IgnoreAlt option now only intercepts KEYS_ALT_F4 exactly - Fixes: If the expander changes visibility the footer now reactes to that. - Fixes: Some typos and doc tags. * 1376-V100-Extending-KryptonTaskDialog - Fixes: Gradient not painted when BackColor2 is set and BackColor1 is changed. - Fixes: KryptonTaskDialog.Dialog.Form.IgnoreAlt option now only intercepts KEYS_ALT_F4 exactly - Fixes: If the expander changes visibility the footer now reactes to that. - Fixes: Some typos and doc tags. - And the changelog. * - Issue: #1376 - Fixes: Gradient not painted when BackColor2 is set and BackColor1 is changed. - Fixes: KryptonTaskDialog.Dialog.Form.IgnoreAlt option now only intercepts KEYS_ALT_F4 exactly - Fixes: If the expander changes visibility the footer now reactes to that. - Fixes: Some typos and doc tags. - Changes: OnVisibleChanged to private in KryptonTaskDialogElementBase - And the changelog * 1376-V100-Extending-KryptonTaskDialog - Adds: Dynamic sizing - Adds: Elements, Checkbox Combobox & Hyperlink * 1376-V100-Extending-KryptonTaskDialog - Adds: Dynamic sizing - Adds: Elements, Checkbox Combobox & Hyperlink * 1376-V100-Extending-KryptonTaskDialog - Adds: Dynamic sizing - Adds: Elements, Checkbox Combobox & Hyperlink * 1376-V100-Extending-KryptonTaskDialog - Adds: Dynamic sizing - Adds: Elements, Checkbox Combobox & Hyperlink - For details see #1376
1 parent d1568f4 commit f8eb623

30 files changed

+1915
-357
lines changed

Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonTaskDialog/Elements/KryptonTaskDialogElementBase.cs

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,115 @@ namespace Krypton.Toolkit;
2121
/// </summary>
2222
public abstract class KryptonTaskDialogElementBase :
2323
IKryptonTaskDialogElementBase,
24+
IKryptonTaskDialogElementEventSizeChanged,
2425
IDisposable
2526
{
2627
#region Fields
27-
private bool _disposed = false;
28+
private bool _disposed;
2829
private KryptonPanel _panel;
2930
private bool _panelVisible;
31+
private KryptonTaskDialogDefaults _taskDialogDefaults;
3032
#endregion
3133

3234
#region Events
35+
/// <summary>
36+
/// Subscribers will be notified when the visibility of the element has changed.
37+
/// </summary>
3338
public event Action VisibleChanged;
39+
40+
/// <summary>
41+
/// Subscribers will be notified when size of the element has changed.
42+
/// </summary>
43+
public event Action SizeChanged;
3444
#endregion
3545

3646
#region Indentity
3747
/// <summary>
3848
/// Default constructor
3949
/// </summary>
40-
public KryptonTaskDialogElementBase()
50+
public KryptonTaskDialogElementBase(KryptonTaskDialogDefaults taskDialogDefaults)
4151
{
52+
// Set the data
53+
_taskDialogDefaults = taskDialogDefaults;
54+
55+
// Although OnGlobalPaletteChanged synchronizes palette changes with the elements,
56+
// The initialisation is done here.
57+
Palette = KryptonManager.CurrentGlobalPalette;
58+
// Execute OnGlobalPaletteChanged once to set the initial palette and wire the PalettePaint event.
59+
OnGlobalPaletteChanged(null!, null!);
60+
// From there the event handler will take over.
61+
KryptonManager.GlobalPaletteChanged += OnGlobalPaletteChanged;
62+
63+
_disposed = false;
64+
4265
_panel = new()
4366
{
4467
Margin = new Padding(0),
4568
Padding = new Padding(0),
4669
Visible = false
4770
};
48-
_panelVisible = _panel.Visible;
49-
71+
_panelVisible = false;
72+
73+
LayoutDirty = false;
74+
}
75+
#endregion
76+
77+
#region Protected
78+
protected void OnSizeChanged()
79+
{
80+
SizeChanged?.Invoke();
5081
}
5182
#endregion
5283

53-
#region Internal
84+
#region Protected (virtual)
85+
/// <summary>
86+
/// Will be connented to and fired from the active palette.
87+
/// </summary>
88+
/// <param name="sender">Source of the event.</param>
89+
/// <param name="e">Event data.</param>
90+
protected virtual void OnPalettePaint(object? sender, PaletteLayoutEventArgs e)
91+
{
92+
}
93+
94+
/// <summary>
95+
/// Acts on Krypton Manager palette changes.
96+
/// </summary>
97+
/// <param name="sender">Source of the event.</param>
98+
/// <param name="e">Event data.</param>
99+
protected virtual void OnGlobalPaletteChanged(object? sender, EventArgs e)
100+
{
101+
if (Palette is not null)
102+
{
103+
Palette.PalettePaint -= OnPalettePaint;
104+
}
105+
106+
Palette = KryptonManager.CurrentGlobalPalette;
107+
108+
if (Palette is not null)
109+
{
110+
Palette.PalettePaint += OnPalettePaint;
111+
}
112+
}
113+
#endregion
114+
115+
#region Internal (virtual)
116+
/// <summary>
117+
/// Requests a layout of the element.<br/>
118+
/// Practically this is used to update the element before it is shown.<br/>
119+
/// </summary>
120+
internal virtual void PerformLayout()
121+
{
122+
}
123+
54124
/// <summary>
55125
/// Krypton panel that hosts the Element's controls and used for themed background coloring.
56126
/// </summary>
57127
internal KryptonPanel Panel => _panel;
128+
129+
/// <summary>
130+
/// Access to the active global palette.
131+
/// </summary>
132+
internal PaletteBase Palette { get; private set; }
58133
#endregion
59134

60135
#region Public virtual
@@ -85,7 +160,7 @@ public virtual bool Visible
85160
{
86161
get => _panelVisible;
87162
set
88-
{
163+
{
89164
if (_panelVisible != value)
90165
{
91166
_panelVisible = value;
@@ -101,17 +176,26 @@ public virtual bool Visible
101176
/// Not implemented
102177
/// </summary>
103178
/// <returns>String.Empty</returns>
104-
public override string ToString()
179+
public sealed override string ToString()
105180
{
106181
return string.Empty;
107182
}
108183
#endregion
109184

110185
#region Public
111186
/// <summary>
112-
/// The height of the element.
187+
/// Returns if the element's layout needs a refresh when visible or before the dialog will be displayed.
188+
/// </summary>
189+
internal bool LayoutDirty { get; set; }
190+
191+
/// <summary>
192+
/// Return the height of the element when visible.<br/>
193+
/// When not visible Height returns zero.
113194
/// </summary>
114-
public int Height => Panel.Height;
195+
public int Height => _panelVisible ? Panel.Height : 0;
196+
197+
/// <inheritdoc/>
198+
internal KryptonTaskDialogDefaults Defaults => _taskDialogDefaults;
115199
#endregion
116200

117201
#region Private
@@ -142,7 +226,15 @@ private void OnVisibleChanged()
142226
protected virtual void Dispose(bool disposing)
143227
{
144228
if (!_disposed && disposing)
145-
{
229+
{
230+
KryptonManager.GlobalPaletteChanged -= OnGlobalPaletteChanged;
231+
232+
if (Palette is not null)
233+
{
234+
Palette.PalettePaint -= OnPalettePaint;
235+
Palette = null!;
236+
}
237+
146238
_disposed = true;
147239
}
148240
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#region BSD License
2+
/*
3+
*
4+
* Original BSD 3-Clause License (https://github.com/ComponentFactory/Krypton/blob/master/LICENSE)
5+
* © Component Factory Pty Ltd, 2006 - 2016, (Version 4.5.0.0) All rights reserved.
6+
*
7+
* New BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit/blob/master/LICENSE)
8+
* Modifications by Peter Wagner (aka Wagnerp), Simon Coghlan (aka Smurf-IV), Giduac, Ahmed Abdelhameed, tobitege et al. 2025 - 2025. All rights reserved.
9+
*
10+
*/
11+
#endregion
12+
13+
namespace Krypton.Toolkit;
14+
15+
public class KryptonTaskDialogElementCheckBox : KryptonTaskDialogElementSingleLineControlBase,
16+
IKryptonTaskDialogElementText
17+
{
18+
private KryptonCheckBox _checkBox;
19+
20+
/// <summary>
21+
/// Default constructor
22+
/// </summary>
23+
public KryptonTaskDialogElementCheckBox(KryptonTaskDialogDefaults taskDialogDefaults)
24+
: base(taskDialogDefaults, 1)
25+
{
26+
Panel.Width = Defaults.ClientWidth;
27+
28+
_checkBox = new();
29+
_checkBox.AutoSize = true;
30+
_checkBox.Padding = new Padding(5, 0, 0, 0);
31+
_checkBox.Margin = _nullMargin;
32+
_checkBox.CheckState = CheckState.Unchecked;
33+
34+
_tlp.Controls.Add(_checkBox, 0, 0);
35+
36+
LayoutDirty = true;
37+
}
38+
39+
#region Private
40+
#endregion
41+
private void OnSizeChanged(bool performLayout = false)
42+
{
43+
// Updates / changes are deferred if the element is not visible or until PerformLayout is called
44+
if (LayoutDirty && (Visible || performLayout))
45+
{
46+
Panel.Height = _checkBox.Height + Defaults.PanelTop + Defaults.PanelBottom;
47+
48+
if (!performLayout)
49+
{
50+
base.OnSizeChanged();
51+
}
52+
53+
LayoutDirty = false;
54+
55+
}
56+
}
57+
58+
#region Protected/Internal
59+
protected override void OnPalettePaint(object? sender, PaletteLayoutEventArgs e)
60+
{
61+
base.OnPalettePaint(sender, e);
62+
63+
// Flag dirty, and if visible call OnSizeChanged,
64+
// otherwise leave it deferred for a call from PerformLayout.
65+
LayoutDirty = true;
66+
if (Visible)
67+
{
68+
OnSizeChanged();
69+
}
70+
}
71+
72+
internal override void PerformLayout()
73+
{
74+
base.PerformLayout();
75+
OnSizeChanged(true);
76+
}
77+
#endregion
78+
79+
#region Public
80+
/// <summary>
81+
/// The text for the checkbox.
82+
/// </summary>
83+
public virtual string Text
84+
{
85+
get => _checkBox.Text;
86+
set => _checkBox.Text = value;
87+
}
88+
89+
/// <inheritdoc/>
90+
public override Color ForeColor
91+
{
92+
get => _checkBox.StateCommon.ShortText.Color1;
93+
set => _checkBox.StateCommon.ShortText.Color1 = value;
94+
}
95+
96+
/// <summary>
97+
/// The checked state of the checkbox.<br/>
98+
/// </summary>
99+
public bool Checked
100+
{
101+
get => _checkBox.Checked;
102+
set => _checkBox.Checked = value;
103+
}
104+
#endregion
105+
}

0 commit comments

Comments
 (0)