|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Text; |
|
|
using System.Threading.Tasks; |
|
|
using DWSIM.UI.Shared; |
|
|
using Eto.Forms; |
|
|
using Eto.Drawing; |
|
|
|
|
|
namespace DWSIM.ExtensionMethods.Eto |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
public static class Extensions2 |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Form GetStandardForm(string title, int width, int height, DynamicLayout content) |
|
|
{ |
|
|
return Common.GetDefaultEditorForm(title, width, height, content); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Form GetStandardForm(string title, int width, int height, TableLayout content, bool scrollable) |
|
|
{ |
|
|
return Common.GetDefaultEditorForm(title, width, height, content, scrollable); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Form GetTabbedForm(string title, int width, int height, Control[] contents) |
|
|
{ |
|
|
return Common.GetDefaultTabbedForm(title, width, height, contents); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static DynamicLayout GetStandardContainer() |
|
|
{ |
|
|
return Common.GetDefaultContainer(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Dialog CreateDialog(Control content, String title, int width = 0, int height = 0) |
|
|
{ |
|
|
return Common.CreateDialog(content, title, width, height); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Label AddHeader(DynamicLayout container, string text) |
|
|
{ |
|
|
return Common.CreateAndAddLabelRow(container, text); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Label AddDescription(DynamicLayout container, string text) |
|
|
{ |
|
|
return Common.CreateAndAddDescriptionRow(container, text); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static TextBox AddEditTextBox(DynamicLayout container, string text, double currentvalue, |
|
|
string numberformat = "", Action<TextBox, EventArgs> textchangedhandler = null) |
|
|
{ |
|
|
if (numberformat == "") numberformat = "N2"; |
|
|
return Common.CreateAndAddTextBoxRow(container, numberformat, text, currentvalue, textchangedhandler); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static DropDown AddDropDown(DynamicLayout container, string text, List<string> options, int selected, |
|
|
Action<DropDown, EventArgs> selectedindexchangedhandler = null) |
|
|
{ |
|
|
return Common.CreateAndAddDropDownRow(container, text, options, selected, selectedindexchangedhandler); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static CheckBox AddCheckBox(DynamicLayout container, string text, bool ischecked, |
|
|
Action<CheckBox, EventArgs> checkedchangedhandler = null) |
|
|
{ |
|
|
return Common.CreateAndAddCheckBoxRow(container, text, ischecked, checkedchangedhandler); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static TextBox AddNumericStepper(DynamicLayout container, string text, double value, |
|
|
double minvalue, double maxvalue, int decimalplaces, Action<TextBox, EventArgs> valuechangedhandler = null) |
|
|
{ |
|
|
return Common.CreateAndAddNumericEditorRow2(container, text, value, minvalue, maxvalue, decimalplaces, valuechangedhandler); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Button AddButtonWithLabel(DynamicLayout container, string text, string buttontext, Action<Button, EventArgs> clickhandler = null) |
|
|
{ |
|
|
return Common.CreateAndAddLabelAndButtonRow(container, text, buttontext, null, clickhandler); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Button AddButton(DynamicLayout container, string buttontext, Action<Button, EventArgs> clickhandler = null) |
|
|
{ |
|
|
return Common.CreateAndAddButtonRow(container, buttontext, null, clickhandler); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void AddControl(DynamicLayout container, Control control) |
|
|
{ |
|
|
Common.CreateAndAddControlRow(container, control); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void AddEmptySpace(DynamicLayout container) |
|
|
{ |
|
|
Common.CreateAndAddEmptySpace(container); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<Control> GetAllChildren(Control control) |
|
|
{ |
|
|
var controls = control.VisualControls.Cast<Control>(); |
|
|
try |
|
|
{ |
|
|
if (control is Panel) controls = ((Panel)control).Controls.Cast<Control>(); |
|
|
if (control is DocumentControl) controls = ((DocumentControl)control).Pages.Cast<Control>(); |
|
|
if (control is Form) controls = ((Form)control).Children.Cast<Control>(); |
|
|
if (control is Layout) controls = ((Layout)control).Children.Cast<Control>(); |
|
|
if (control is DynamicLayout && ((DynamicLayout)control).Content != null) |
|
|
controls = ((DynamicLayout)control).Content.VisualControls.Cast<Control>(); |
|
|
if (control is Scrollable) controls = ((Scrollable)control).Content.VisualControls.Cast<Control>(); |
|
|
} |
|
|
catch { } |
|
|
return controls.SelectMany(ctrl => GetAllChildren(ctrl)).Concat(controls); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void SetFontAndPadding(this Form form) |
|
|
{ |
|
|
|
|
|
var sysfont = global::Eto.Drawing.SystemFonts.Message(); |
|
|
var regularfont = new Font(sysfont.Family.Name, sysfont.Size); |
|
|
var boldfont = new Font(sysfont.Family.Name, sysfont.Size, FontStyle.Bold); |
|
|
|
|
|
var allcontrols = GetAllChildren(form); |
|
|
foreach (var control in allcontrols) |
|
|
{ |
|
|
if (control is CommonControl) |
|
|
{ |
|
|
var font = ((CommonControl)control).Font; |
|
|
if (font.Bold) |
|
|
{ |
|
|
((CommonControl)control).Font = boldfont; |
|
|
} |
|
|
else |
|
|
{ |
|
|
((CommonControl)control).Font = regularfont; |
|
|
} |
|
|
} |
|
|
if (control is TextBox) |
|
|
{ |
|
|
var tb = (TextBox)control; |
|
|
var d = 0.0; |
|
|
if (Double.TryParse(tb.Text, out d)) |
|
|
{ |
|
|
tb.TextAlignment = TextAlignment.Right; |
|
|
} |
|
|
} |
|
|
else if (control is TableLayout) |
|
|
{ |
|
|
((TableLayout)control).Padding = new Padding((int)(2 * GlobalSettings.Settings.DpiScale)); |
|
|
} |
|
|
if (control is TextBox) |
|
|
{ |
|
|
var tb = (TextBox)control; |
|
|
var d = 0.0; |
|
|
if (Double.TryParse(tb.Text, out d)) |
|
|
{ |
|
|
tb.TextAlignment = TextAlignment.Right; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|