2017-08-23 23:59:45 -07:00
|
|
|
|
/*
|
2022-07-16 07:46:44 -07:00
|
|
|
|
Copyright (c) 2022, Lars Brubaker, John Lewin
|
2017-08-23 23:59:45 -07:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-08-23 17:27:30 -07:00
|
|
|
|
using System;
|
2018-04-19 12:39:38 -07:00
|
|
|
|
using System.Linq;
|
2016-06-01 18:17:11 -07:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2018-06-18 09:42:13 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
2017-10-17 12:35:24 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
2016-06-01 18:17:11 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2018-04-16 18:55:01 -07:00
|
|
|
|
public class DialogPage : FlowLayoutWidget
|
2016-06-01 18:17:11 -07:00
|
|
|
|
{
|
2018-06-18 09:42:13 -07:00
|
|
|
|
protected GuiWidget headerRow;
|
2018-11-03 10:12:27 -07:00
|
|
|
|
protected FlowLayoutWidget contentRow;
|
2018-06-17 12:22:33 -07:00
|
|
|
|
protected FlowLayoutWidget footerRow;
|
2016-06-02 17:46:49 -07:00
|
|
|
|
|
2018-07-18 09:23:04 -07:00
|
|
|
|
private TextWidget headerLabel;
|
2020-07-22 08:05:39 -07:00
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
public GuiWidget CancelButton { get; private set; }
|
2016-06-02 17:46:49 -07:00
|
|
|
|
|
2017-10-17 12:35:24 -07:00
|
|
|
|
public Vector2 WindowSize { get; set; }
|
|
|
|
|
|
|
2016-06-01 18:17:11 -07:00
|
|
|
|
protected double labelFontSize = 12 * GuiWidget.DeviceScale;
|
2020-07-22 08:05:39 -07:00
|
|
|
|
|
2016-06-01 18:17:11 -07:00
|
|
|
|
protected double errorFontSize = 10 * GuiWidget.DeviceScale;
|
2016-06-02 17:46:49 -07:00
|
|
|
|
|
2018-04-10 07:35:08 -07:00
|
|
|
|
protected ThemeConfig theme;
|
2018-06-24 11:21:34 -07:00
|
|
|
|
private int actionCount = 0;
|
2019-05-09 11:43:51 -07:00
|
|
|
|
private SystemWindow systemWindow;
|
2019-05-13 15:38:53 -07:00
|
|
|
|
private GuiWidget _acceptButton;
|
2018-04-10 07:35:08 -07:00
|
|
|
|
|
2018-06-18 09:42:13 -07:00
|
|
|
|
public DialogPage(string cancelButtonText = null, bool useOverflowBar = false)
|
2020-08-14 18:46:54 -07:00
|
|
|
|
: base(FlowDirection.TopToBottom)
|
2016-06-01 18:17:11 -07:00
|
|
|
|
{
|
2018-04-10 07:35:08 -07:00
|
|
|
|
theme = ApplicationController.Instance.Theme;
|
|
|
|
|
|
|
2018-04-16 18:55:01 -07:00
|
|
|
|
this.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
this.VAnchor = VAnchor.Stretch;
|
2018-04-10 07:35:08 -07:00
|
|
|
|
|
2017-12-04 10:39:08 -08:00
|
|
|
|
if (cancelButtonText == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
cancelButtonText = "Cancel".Localize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
CancelButton = theme.CreateDialogButton(cancelButtonText);
|
|
|
|
|
|
CancelButton.Margin = new BorderDouble(left: 3);
|
|
|
|
|
|
CancelButton.Name = "Cancel Wizard Button";
|
2016-06-01 18:17:11 -07:00
|
|
|
|
|
2016-06-07 13:47:41 -07:00
|
|
|
|
// Create the header row for the widget
|
2018-06-18 09:42:13 -07:00
|
|
|
|
if (useOverflowBar)
|
2016-06-01 18:17:11 -07:00
|
|
|
|
{
|
2018-06-18 09:42:13 -07:00
|
|
|
|
headerRow = new OverflowBar(theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "HeaderRow",
|
|
|
|
|
|
Margin = new BorderDouble(0, 3, 0, 0),
|
|
|
|
|
|
Padding = new BorderDouble(0, 12),
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "HeaderRow",
|
|
|
|
|
|
Margin = new BorderDouble(0, 3, 0, 0),
|
|
|
|
|
|
Padding = new BorderDouble(0, 12),
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-16 18:55:01 -07:00
|
|
|
|
this.AddChild(headerRow);
|
2016-06-07 13:47:41 -07:00
|
|
|
|
|
2018-10-15 18:25:53 -07:00
|
|
|
|
headerLabel = new TextWidget("Setup Wizard".Localize(), pointSize: 24, textColor: theme.PrimaryAccentColor)
|
2016-06-07 13:47:41 -07:00
|
|
|
|
{
|
2018-07-18 09:23:04 -07:00
|
|
|
|
AutoExpandBoundsToText = true,
|
|
|
|
|
|
EllipsisIfClipped = true,
|
2017-08-08 17:49:26 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch
|
2016-06-07 13:47:41 -07:00
|
|
|
|
};
|
|
|
|
|
|
headerRow.AddChild(headerLabel);
|
2016-06-01 18:17:11 -07:00
|
|
|
|
|
2016-06-07 13:47:41 -07:00
|
|
|
|
// Create the main control container
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2016-06-07 13:47:41 -07:00
|
|
|
|
{
|
|
|
|
|
|
Padding = new BorderDouble(10),
|
2018-10-29 16:27:04 -07:00
|
|
|
|
BackgroundColor = theme.SectionBackgroundColor,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
2016-06-07 13:47:41 -07:00
|
|
|
|
};
|
2018-11-03 10:12:27 -07:00
|
|
|
|
this.AddChild(contentRow);
|
2016-06-01 18:17:11 -07:00
|
|
|
|
|
2016-06-07 13:47:41 -07:00
|
|
|
|
// Create the footer (button) container
|
|
|
|
|
|
footerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
|
|
|
|
|
|
{
|
2019-03-20 13:10:26 -07:00
|
|
|
|
Name = "FooterRow",
|
2018-07-16 14:30:18 -07:00
|
|
|
|
HAnchor = HAnchor.Fit | HAnchor.Right,
|
2018-04-16 18:55:01 -07:00
|
|
|
|
VAnchor = VAnchor.Fit,
|
2017-08-24 00:47:18 -07:00
|
|
|
|
Margin = new BorderDouble(0, 6),
|
|
|
|
|
|
Padding = new BorderDouble(top: 4, bottom: 2)
|
2016-06-07 13:47:41 -07:00
|
|
|
|
};
|
2018-04-16 18:55:01 -07:00
|
|
|
|
this.AddChild(footerRow);
|
2016-06-07 12:52:05 -07:00
|
|
|
|
|
2018-04-16 13:38:07 -07:00
|
|
|
|
#if !__ANDROID__
|
|
|
|
|
|
headerRow.Padding = new BorderDouble(0, 3, 0, 3);
|
2016-06-07 12:52:05 -07:00
|
|
|
|
|
2018-07-18 09:23:04 -07:00
|
|
|
|
headerLabel.PointSize = 14;
|
2018-11-03 09:13:07 -07:00
|
|
|
|
headerLabel.TextColor = theme.TextColor;
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.Padding = new BorderDouble(5);
|
2018-04-14 21:11:37 -07:00
|
|
|
|
|
2018-04-16 13:38:07 -07:00
|
|
|
|
footerRow.Padding = 0;
|
2018-04-16 18:55:01 -07:00
|
|
|
|
footerRow.Margin = new BorderDouble(top: theme.DefaultContainerPadding);
|
2018-04-16 13:38:07 -07:00
|
|
|
|
#endif
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
2017-08-08 17:49:26 -07:00
|
|
|
|
|
2019-05-13 15:38:53 -07:00
|
|
|
|
public GuiWidget AcceptButton
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _acceptButton;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_acceptButton = value;
|
|
|
|
|
|
theme.ApplyPrimaryActionStyle(_acceptButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-23 08:38:17 -08:00
|
|
|
|
// Add public accessor for content panel
|
|
|
|
|
|
public FlowLayoutWidget ContentRow => contentRow;
|
|
|
|
|
|
|
2018-06-19 15:02:25 -07:00
|
|
|
|
public DialogWindow DialogWindow { get; set; }
|
2017-10-20 06:11:24 -07:00
|
|
|
|
|
2017-08-23 15:51:29 -07:00
|
|
|
|
public string WindowTitle { get; set; }
|
|
|
|
|
|
|
2017-10-18 22:49:03 -07:00
|
|
|
|
public bool AlwaysOnTopOfMain { get; set; } = true;
|
|
|
|
|
|
|
2017-08-24 00:16:31 -07:00
|
|
|
|
public string HeaderText
|
|
|
|
|
|
{
|
|
|
|
|
|
get => headerLabel.Text;
|
|
|
|
|
|
set => headerLabel.Text = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-24 11:21:34 -07:00
|
|
|
|
public void AddPageAction(GuiWidget button, bool highlightFirstAction = true)
|
2017-08-23 17:27:30 -07:00
|
|
|
|
{
|
2018-06-24 11:21:34 -07:00
|
|
|
|
if (highlightFirstAction
|
|
|
|
|
|
&& actionCount++ == 0)
|
|
|
|
|
|
{
|
2019-05-13 15:38:53 -07:00
|
|
|
|
this.AcceptButton = button;
|
2018-06-24 11:21:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-17 12:41:00 -07:00
|
|
|
|
button.Margin = theme.ButtonSpacing;
|
2017-08-23 17:27:30 -07:00
|
|
|
|
footerRow.AddChild(button);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-18 09:24:29 -07:00
|
|
|
|
protected void SetCancelButtonName(string newName)
|
|
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
CancelButton.Name = newName;
|
2017-10-18 09:24:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-03 08:32:42 -07:00
|
|
|
|
protected void SetCancelButtonText(string text)
|
|
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
CancelButton.Text = text;
|
2018-05-03 08:32:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-18 09:24:29 -07:00
|
|
|
|
protected void HideCancelButton()
|
|
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
CancelButton.Visible = false;
|
2017-10-18 09:24:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-23 17:27:30 -07:00
|
|
|
|
public override void OnLoad(EventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Add 'Close' event listener after derived types have had a chance to register event listeners
|
2022-03-16 17:25:59 -07:00
|
|
|
|
CancelButton.Click += (s, e) =>
|
2017-08-23 17:27:30 -07:00
|
|
|
|
{
|
2019-05-09 13:21:17 -07:00
|
|
|
|
if (this.AllowCancel())
|
2017-08-23 17:27:30 -07:00
|
|
|
|
{
|
2019-03-20 16:05:06 -07:00
|
|
|
|
this.DialogWindow?.ClosePage();
|
2017-08-23 17:27:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-05-09 11:43:51 -07:00
|
|
|
|
// Register listeners
|
|
|
|
|
|
systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
|
|
|
|
|
|
systemWindow.KeyDown += SystemWindow_KeyDown;
|
2018-04-19 12:39:38 -07:00
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
footerRow.AddChild(CancelButton);
|
2017-08-23 17:27:30 -07:00
|
|
|
|
|
|
|
|
|
|
base.OnLoad(args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-09 13:21:17 -07:00
|
|
|
|
public bool AllowCancel()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool windowAbortCancel = false;
|
|
|
|
|
|
|
|
|
|
|
|
this.OnCancel(out bool pageAbortCancel);
|
|
|
|
|
|
|
|
|
|
|
|
if (!pageAbortCancel)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.DialogWindow.OnCancel(out windowAbortCancel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Allow cancel if page and DialogWindow do not abort
|
|
|
|
|
|
return !pageAbortCancel
|
|
|
|
|
|
&& !windowAbortCancel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-18 09:24:29 -07:00
|
|
|
|
protected virtual void OnCancel(out bool abortCancel)
|
|
|
|
|
|
{
|
|
|
|
|
|
abortCancel = false;
|
|
|
|
|
|
}
|
2019-05-09 11:43:51 -07:00
|
|
|
|
|
|
|
|
|
|
public override void OnClosed(EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Unregister listeners
|
|
|
|
|
|
if (systemWindow != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
systemWindow.KeyDown -= SystemWindow_KeyDown;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SystemWindow_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
|
{
|
2019-06-10 16:24:40 -07:00
|
|
|
|
if (e.KeyCode == Keys.Escape
|
|
|
|
|
|
&& !e.Handled)
|
2019-05-09 11:43:51 -07:00
|
|
|
|
{
|
|
|
|
|
|
this.OnCancel(out bool abortCancel);
|
|
|
|
|
|
|
|
|
|
|
|
if (!abortCancel)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.DialogWindow?.ClosePage();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-05-13 15:38:53 -07:00
|
|
|
|
else if (e.KeyCode == Keys.Enter
|
2019-05-14 22:36:06 -07:00
|
|
|
|
&& this.AcceptButton != null
|
|
|
|
|
|
&& this.AcceptButton.Visible
|
|
|
|
|
|
&& this.AcceptButton.Enabled)
|
2019-05-13 15:38:53 -07:00
|
|
|
|
{
|
|
|
|
|
|
var tabStops = this.ActiveTabStops();
|
|
|
|
|
|
|
|
|
|
|
|
// If no tab stop child is actively focused, fire click on the AcceptButton
|
|
|
|
|
|
if (!tabStops.Any(w => w.Focused))
|
|
|
|
|
|
{
|
|
|
|
|
|
this.AcceptButton.InvokeClick();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-05-09 11:43:51 -07:00
|
|
|
|
}
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|