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 { /// /// Eto.Forms extension methods /// public static class Extensions2 { /// /// Gets a standard form window to display /// /// Title of the form /// Width in pixels /// Height in pixels /// Form contents (DynamicLayout) /// public static Form GetStandardForm(string title, int width, int height, DynamicLayout content) { return Common.GetDefaultEditorForm(title, width, height, content); } /// /// Gets a standard form window to display with scrollable contents /// /// Title of the form /// Width in pixels /// Height in pixels /// Form contents (DynamicLayout) /// Contents are scrollable /// public static Form GetStandardForm(string title, int width, int height, TableLayout content, bool scrollable) { return Common.GetDefaultEditorForm(title, width, height, content, scrollable); } /// /// Gets a Form window for multiple tabbed contents /// /// Title of the form /// Width in pixels /// Height in pixels /// List of controls to display in the tabs. Set the Tag property of the control to display as the tab text. /// public static Form GetTabbedForm(string title, int width, int height, Control[] contents) { return Common.GetDefaultTabbedForm(title, width, height, contents); } /// /// Gets the standard control container (DynamicLayout) /// /// public static DynamicLayout GetStandardContainer() { return Common.GetDefaultContainer(); } /// /// Creates and returns a Dialog window. /// /// Control to display in the dialog. /// Title of the dialog. /// Width in pixels /// Height in pixels /// public static Dialog CreateDialog(Control content, String title, int width = 0, int height = 0) { return Common.CreateDialog(content, title, width, height); } /// /// Adds a header text to the container. /// /// Layout container /// Label text /// public static Label AddHeader(DynamicLayout container, string text) { return Common.CreateAndAddLabelRow(container, text); } /// /// Adds a description row to the container. /// /// Layout container /// Description text /// public static Label AddDescription(DynamicLayout container, string text) { return Common.CreateAndAddDescriptionRow(container, text); } /// /// Adds a textbox for editing a double (numeric) value. /// /// Layout container /// Text (description) /// Current value to display on the textbox /// Number format (i.e. 'N2') /// Handler for the TextChanged event. /// public static TextBox AddEditTextBox(DynamicLayout container, string text, double currentvalue, string numberformat = "", Action textchangedhandler = null) { if (numberformat == "") numberformat = "N2"; return Common.CreateAndAddTextBoxRow(container, numberformat, text, currentvalue, textchangedhandler); } /// /// Adds a DropDown with selectable items /// /// Layout container /// Text (description) /// Selectable items /// Index of the currently selected item (zero-based) /// Handler for the SelectedIndexChanged event. /// public static DropDown AddDropDown(DynamicLayout container, string text, List options, int selected, Action selectedindexchangedhandler = null) { return Common.CreateAndAddDropDownRow(container, text, options, selected, selectedindexchangedhandler); } /// /// Adds a CheckBox /// /// Layout container /// Text (description) /// /// Handler for the CheckedChanged event. /// public static CheckBox AddCheckBox(DynamicLayout container, string text, bool ischecked, Action checkedchangedhandler = null) { return Common.CreateAndAddCheckBoxRow(container, text, ischecked, checkedchangedhandler); } /// /// Adds a numeric stepper (selector) /// /// Layout container /// Text (description) /// The current value of the stepper /// Maximum selectable value /// Minimum selectable value /// Decimal places /// Handler for the ValueChanged event /// public static TextBox AddNumericStepper(DynamicLayout container, string text, double value, double minvalue, double maxvalue, int decimalplaces, Action valuechangedhandler = null) { return Common.CreateAndAddNumericEditorRow2(container, text, value, minvalue, maxvalue, decimalplaces, valuechangedhandler); } /// /// Adds a button with a label. /// /// Layout container /// Text (description) /// Text to be displayed in the button /// Handler for the Click event. /// public static Button AddButtonWithLabel(DynamicLayout container, string text, string buttontext, Action clickhandler = null) { return Common.CreateAndAddLabelAndButtonRow(container, text, buttontext, null, clickhandler); } /// /// Adds a button /// /// Layout container /// Text to be displayed in the button /// Handler for the Click event. /// public static Button AddButton(DynamicLayout container, string buttontext, Action clickhandler = null) { return Common.CreateAndAddButtonRow(container, buttontext, null, clickhandler); } /// /// Adds a control to the container. /// /// Layout container /// Control to add public static void AddControl(DynamicLayout container, Control control) { Common.CreateAndAddControlRow(container, control); } /// /// Adds an empty row to the container for spacing purposes. /// /// Layout container public static void AddEmptySpace(DynamicLayout container) { Common.CreateAndAddEmptySpace(container); } /// /// /// /// /// public static IEnumerable GetAllChildren(Control control) { var controls = control.VisualControls.Cast(); try { if (control is Panel) controls = ((Panel)control).Controls.Cast(); if (control is DocumentControl) controls = ((DocumentControl)control).Pages.Cast(); if (control is Form) controls = ((Form)control).Children.Cast(); if (control is Layout) controls = ((Layout)control).Children.Cast(); if (control is DynamicLayout && ((DynamicLayout)control).Content != null) controls = ((DynamicLayout)control).Content.VisualControls.Cast(); if (control is Scrollable) controls = ((Scrollable)control).Content.VisualControls.Cast(); } 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; } } } } } }