2017-08-23 23:59:45 -07:00
|
|
|
|
/*
|
2018-11-03 10:12:27 -07:00
|
|
|
|
Copyright (c) 2018, 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;
|
2018-04-14 20:51:01 -07:00
|
|
|
|
private GuiWidget cancelButton;
|
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;
|
|
|
|
|
|
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;
|
2018-04-10 07:35:08 -07:00
|
|
|
|
|
2018-06-18 09:42:13 -07:00
|
|
|
|
public DialogPage(string cancelButtonText = null, bool useOverflowBar = false)
|
2018-04-16 18:55:01 -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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-14 20:51:01 -07:00
|
|
|
|
cancelButton = theme.CreateDialogButton(cancelButtonText);
|
2018-07-16 14:30:18 -07:00
|
|
|
|
cancelButton.Margin = new BorderDouble(left: 3);
|
2016-11-30 13:31:19 -08:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
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
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
theme.ApplyPrimaryActionStyle(button);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
cancelButton.Name = newName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-03 08:32:42 -07:00
|
|
|
|
protected void SetCancelButtonText(string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
cancelButton.Text = text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-18 09:24:29 -07:00
|
|
|
|
protected void HideCancelButton()
|
|
|
|
|
|
{
|
|
|
|
|
|
cancelButton.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
|
cancelButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2017-10-18 09:24:29 -07:00
|
|
|
|
this.OnCancel(out bool abortCancel);
|
|
|
|
|
|
|
2017-08-23 17:27:30 -07:00
|
|
|
|
if (!abortCancel)
|
|
|
|
|
|
{
|
2018-06-19 15:02:25 -07:00
|
|
|
|
this.DialogWindow?.CloseOnIdle();
|
2017-08-23 17:27:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-04-19 12:39:38 -07:00
|
|
|
|
var systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
|
|
|
|
|
|
if(systemWindow != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
EventHandler<KeyEventArgs> checkEscape = null;
|
|
|
|
|
|
checkEscape = (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if(e.KeyCode == Keys.Escape)
|
|
|
|
|
|
{
|
|
|
|
|
|
systemWindow.KeyDown -= checkEscape;
|
|
|
|
|
|
|
|
|
|
|
|
this.OnCancel(out bool abortCancel);
|
|
|
|
|
|
|
|
|
|
|
|
if (!abortCancel)
|
|
|
|
|
|
{
|
2018-06-19 15:02:25 -07:00
|
|
|
|
this.DialogWindow?.CloseOnIdle();
|
2018-04-19 12:39:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
systemWindow.KeyDown += checkEscape;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-23 17:27:30 -07:00
|
|
|
|
footerRow.AddChild(cancelButton);
|
|
|
|
|
|
|
|
|
|
|
|
base.OnLoad(args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-18 09:24:29 -07:00
|
|
|
|
protected virtual void OnCancel(out bool abortCancel)
|
|
|
|
|
|
{
|
|
|
|
|
|
abortCancel = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-08 17:49:26 -07:00
|
|
|
|
public virtual void PageIsBecomingActive()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void PageIsBecomingInactive()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2016-06-01 18:17:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|