911 lines
36 KiB
C#
911 lines
36 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: DarkModeForms.Messenger
|
|
// Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
|
|
// MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7
|
|
// Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe
|
|
|
|
using Raton.Classes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Forms;
|
|
|
|
#nullable disable
|
|
namespace DarkModeForms;
|
|
|
|
public static class Messenger
|
|
{
|
|
private static Action<object, KeyValue.ValidateEventArgs> ValidateControlsHandler;
|
|
private static MessageBoxDefaultButton _defaultButton;
|
|
private static Dictionary<Control, Timer> timers;
|
|
|
|
public static event Action<object, KeyValue.ValidateEventArgs> ValidateControls
|
|
{
|
|
add => Messenger.ValidateControlsHandler += value;
|
|
remove => Messenger.ValidateControlsHandler -= value;
|
|
}
|
|
|
|
private static void ResetEvents()
|
|
{
|
|
Messenger.ValidateControlsHandler = (Action<object, KeyValue.ValidateEventArgs>) null;
|
|
}
|
|
|
|
public static DialogResult MessageBox(string Message)
|
|
{
|
|
return Messenger.MessageBox(Message, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, true);
|
|
}
|
|
|
|
public static DialogResult MessageBox(Exception ex, bool ShowTrace = true)
|
|
{
|
|
return Messenger.MessageBox(ex.Message + (ShowTrace ? "\r\n" + ex.StackTrace : ""), "Error!", icon: MessageBoxIcon.Hand);
|
|
}
|
|
|
|
public static DialogResult MessageBox(
|
|
string Message,
|
|
string title,
|
|
MessageBoxButtons buttons = MessageBoxButtons.OK,
|
|
MessageBoxIcon icon = MessageBoxIcon.Asterisk,
|
|
bool pIsDarkMode = true)
|
|
{
|
|
MsgIcon Icon = MsgIcon.None;
|
|
switch (icon)
|
|
{
|
|
case MessageBoxIcon.Hand:
|
|
Icon = MsgIcon.Error;
|
|
break;
|
|
case MessageBoxIcon.Question:
|
|
Icon = MsgIcon.Question;
|
|
break;
|
|
case MessageBoxIcon.Exclamation:
|
|
Icon = MsgIcon.Warning;
|
|
break;
|
|
case MessageBoxIcon.Asterisk:
|
|
Icon = MsgIcon.Success;
|
|
break;
|
|
}
|
|
return Messenger.MessageBox(Message, title, Icon, buttons, pIsDarkMode);
|
|
}
|
|
|
|
public static DialogResult MessageBox(
|
|
string Message,
|
|
string title,
|
|
MessageBoxButtons buttons,
|
|
MessageBoxIcon icon,
|
|
MessageBoxDefaultButton DefaultButton,
|
|
bool pIsDarkMode = true)
|
|
{
|
|
Messenger._defaultButton = DefaultButton;
|
|
return Messenger.MessageBox(Message, title, buttons, icon, pIsDarkMode);
|
|
}
|
|
|
|
public static DialogResult MessageBox(
|
|
string Message,
|
|
string title,
|
|
MessageBoxButtons buttons = MessageBoxButtons.OK,
|
|
MsgIcon icon = MsgIcon.None,
|
|
bool pIsDarkMode = true)
|
|
{
|
|
return Messenger.MessageBox(Message, title, icon, buttons, pIsDarkMode);
|
|
}
|
|
|
|
public static DialogResult MessageBox(
|
|
Form pOwner,
|
|
string Message,
|
|
string title,
|
|
MessageBoxButtons buttons,
|
|
MsgIcon icon = MsgIcon.None,
|
|
bool pIsDarkMode = true)
|
|
{
|
|
return Messenger.MessageBox(Message, title, icon, buttons, pIsDarkMode, owner: pOwner);
|
|
}
|
|
|
|
public static DialogResult MessageBox(
|
|
string Message,
|
|
string title,
|
|
MsgIcon Icon,
|
|
MessageBoxButtons buttons = MessageBoxButtons.OK,
|
|
bool pIsDarkMode = true,
|
|
MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1,
|
|
Form owner = null)
|
|
{
|
|
Form form1 = new Form();
|
|
form1.FormBorderStyle = FormBorderStyle.FixedDialog;
|
|
form1.StartPosition = FormStartPosition.CenterParent;
|
|
form1.MaximizeBox = false;
|
|
form1.MinimizeBox = false;
|
|
form1.Text = title;
|
|
form1.Width = 340;
|
|
form1.Height = 170;
|
|
form1.KeyPreview = true;
|
|
Form form = form1;
|
|
if (owner != null)
|
|
form.Owner = owner;
|
|
DarkMode.Start(form);
|
|
Base64Icons base64Icons = new Base64Icons();
|
|
int height = System.Drawing.SystemFonts.DefaultFont.Height;
|
|
Panel panel1 = new Panel();
|
|
panel1.Dock = DockStyle.Bottom;
|
|
panel1.Height = 48 /*0x30*/;
|
|
panel1.BackColor = Color.Transparent;
|
|
panel1.BorderStyle = BorderStyle.None;
|
|
Panel panel2 = panel1;
|
|
form.Controls.Add((Control) panel2);
|
|
Dictionary<string, string> buttonTranslations = Messenger.GetButtonTranslations(Messenger.GetCurrentLanguage());
|
|
List<Button> buttonList1 = new List<Button>();
|
|
switch (buttons)
|
|
{
|
|
case MessageBoxButtons.OK:
|
|
List<Button> buttonList2 = buttonList1;
|
|
Button button1 = new Button();
|
|
button1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button1.DialogResult = DialogResult.OK;
|
|
button1.Text = buttonTranslations["OK"];
|
|
button1.Height = height + 10;
|
|
button1.FlatStyle = FlatStyle.System;
|
|
buttonList2.Add(button1);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.KeyPreview = true;
|
|
form.KeyDown += (KeyEventHandler) ((s, e) =>
|
|
{
|
|
if (e.KeyCode != Keys.Escape)
|
|
return;
|
|
form.Close();
|
|
});
|
|
form.FormClosed += (FormClosedEventHandler) ((s, e) => form.DialogResult = DialogResult.OK);
|
|
break;
|
|
case MessageBoxButtons.OKCancel:
|
|
List<Button> buttonList3 = buttonList1;
|
|
Button button2 = new Button();
|
|
button2.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button2.DialogResult = DialogResult.OK;
|
|
button2.Text = buttonTranslations["OK"];
|
|
button2.Height = height + 10;
|
|
button2.FlatStyle = FlatStyle.System;
|
|
buttonList3.Add(button2);
|
|
List<Button> buttonList4 = buttonList1;
|
|
Button button3 = new Button();
|
|
button3.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button3.DialogResult = DialogResult.Cancel;
|
|
button3.Text = buttonTranslations["Cancel"];
|
|
button3.FlatStyle = FlatStyle.System;
|
|
buttonList4.Add(button3);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.CancelButton = (IButtonControl) buttonList1[1];
|
|
break;
|
|
case MessageBoxButtons.AbortRetryIgnore:
|
|
List<Button> buttonList5 = buttonList1;
|
|
Button button4 = new Button();
|
|
button4.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button4.DialogResult = DialogResult.Abort;
|
|
button4.Text = buttonTranslations["Abort"];
|
|
buttonList5.Add(button4);
|
|
List<Button> buttonList6 = buttonList1;
|
|
Button button5 = new Button();
|
|
button5.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button5.DialogResult = DialogResult.Retry;
|
|
button5.Text = buttonTranslations["Retry"];
|
|
buttonList6.Add(button5);
|
|
List<Button> buttonList7 = buttonList1;
|
|
Button button6 = new Button();
|
|
button6.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button6.DialogResult = DialogResult.Ignore;
|
|
button6.Text = buttonTranslations["Ignore"];
|
|
buttonList7.Add(button6);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.ControlBox = false;
|
|
break;
|
|
case MessageBoxButtons.YesNoCancel:
|
|
List<Button> buttonList8 = buttonList1;
|
|
Button button7 = new Button();
|
|
button7.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button7.DialogResult = DialogResult.Yes;
|
|
button7.Text = buttonTranslations["Yes"];
|
|
buttonList8.Add(button7);
|
|
List<Button> buttonList9 = buttonList1;
|
|
Button button8 = new Button();
|
|
button8.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button8.DialogResult = DialogResult.No;
|
|
button8.Text = buttonTranslations["No"];
|
|
buttonList9.Add(button8);
|
|
List<Button> buttonList10 = buttonList1;
|
|
Button button9 = new Button();
|
|
button9.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button9.DialogResult = DialogResult.Cancel;
|
|
button9.Text = buttonTranslations["Cancel"];
|
|
buttonList10.Add(button9);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.CancelButton = (IButtonControl) buttonList1[2];
|
|
break;
|
|
case MessageBoxButtons.YesNo:
|
|
List<Button> buttonList11 = buttonList1;
|
|
Button button10 = new Button();
|
|
button10.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button10.DialogResult = DialogResult.Yes;
|
|
button10.Text = buttonTranslations["Yes"];
|
|
buttonList11.Add(button10);
|
|
List<Button> buttonList12 = buttonList1;
|
|
Button button11 = new Button();
|
|
button11.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button11.DialogResult = DialogResult.No;
|
|
button11.Text = buttonTranslations["No"];
|
|
buttonList12.Add(button11);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.ControlBox = false;
|
|
break;
|
|
case MessageBoxButtons.RetryCancel:
|
|
List<Button> buttonList13 = buttonList1;
|
|
Button button12 = new Button();
|
|
button12.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button12.DialogResult = DialogResult.Retry;
|
|
button12.Text = buttonTranslations["Retry"];
|
|
button12.FlatStyle = FlatStyle.System;
|
|
buttonList13.Add(button12);
|
|
List<Button> buttonList14 = buttonList1;
|
|
Button button13 = new Button();
|
|
button13.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button13.DialogResult = DialogResult.Cancel;
|
|
button13.Text = buttonTranslations["Cancel"];
|
|
buttonList14.Add(button13);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.CancelButton = (IButtonControl) buttonList1[1];
|
|
break;
|
|
}
|
|
int num1 = 4;
|
|
int num2 = form.ClientSize.Width;
|
|
Font font = System.Drawing.SystemFonts.MessageBoxFont ?? System.Drawing.SystemFonts.DefaultFont;
|
|
using (Graphics graphics = form.CreateGraphics())
|
|
{
|
|
for (int index = buttonList1.Count - 1; index >= 0; --index)
|
|
{
|
|
Button button14 = buttonList1[index];
|
|
panel2.Controls.Add((Control) button14);
|
|
button14.TabIndex = index;
|
|
button14.Font = font;
|
|
SizeF sizeF = graphics.MeasureString(button14.Text, font);
|
|
button14.Size = new System.Drawing.Size((int) sizeF.Width + 20, font.Height + 10);
|
|
button14.Location = new System.Drawing.Point(num2 - (button14.Width + num1), (panel2.Height - button14.Height) / 2);
|
|
num2 = button14.Left;
|
|
}
|
|
}
|
|
int defaultButton1 = (int) Messenger._defaultButton;
|
|
if (defaultButton1 > 0)
|
|
{
|
|
int index = defaultButton1 >> 8;
|
|
if (index < buttonList1.Count)
|
|
{
|
|
buttonList1[index].Select();
|
|
buttonList1[index].FlatStyle = FlatStyle.Flat;
|
|
}
|
|
}
|
|
int num3 = 45;
|
|
Rectangle rectangle = new Rectangle(12, 12, 0, 0);
|
|
if (Icon != MsgIcon.None)
|
|
{
|
|
PictureBox pictureBox1 = new PictureBox();
|
|
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
|
|
pictureBox1.Size = new System.Drawing.Size(num3, num3);
|
|
PictureBox pictureBox2 = pictureBox1;
|
|
pictureBox2.Image = base64Icons.GetIcon(Icon);
|
|
form.Controls.Add((Control) pictureBox2);
|
|
rectangle.Size = new System.Drawing.Size(num3, num3);
|
|
pictureBox2.SetBounds(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
|
|
pictureBox2.BringToFront();
|
|
}
|
|
Label label1 = new Label();
|
|
label1.Text = Message;
|
|
label1.AutoSize = false;
|
|
label1.TextAlign = ContentAlignment.MiddleLeft;
|
|
label1.Location = new System.Drawing.Point(rectangle.X + rectangle.Width + 10, rectangle.Y);
|
|
label1.Size = new System.Drawing.Size(form.ClientSize.Width - (rectangle.X + rectangle.Width) - 20, num3);
|
|
Label label2 = label1;
|
|
form.Controls.Add((Control) label2);
|
|
form.ClientSize = new System.Drawing.Size(340, panel2.Height + label2.Height + 20);
|
|
string localMessage = Message;
|
|
string localTitle = title;
|
|
form.KeyDown += (KeyEventHandler) ((sender, e) =>
|
|
{
|
|
if (!e.Control || e.KeyCode != Keys.C)
|
|
return;
|
|
System.Windows.Forms.Clipboard.SetText($"Title: {localTitle}\r\nMessage: {localMessage}");
|
|
e.Handled = true;
|
|
});
|
|
return form.ShowDialog();
|
|
}
|
|
|
|
private static MessageBoxButtons ToWinForms(MessageBoxButton btn)
|
|
{
|
|
switch (btn)
|
|
{
|
|
case MessageBoxButton.OKCancel:
|
|
return MessageBoxButtons.OKCancel;
|
|
case MessageBoxButton.YesNoCancel:
|
|
return MessageBoxButtons.YesNoCancel;
|
|
case MessageBoxButton.YesNo:
|
|
return MessageBoxButtons.YesNo;
|
|
default:
|
|
return MessageBoxButtons.OK;
|
|
}
|
|
}
|
|
|
|
private static MsgIcon ToMsgIcon(MessageBoxImage img)
|
|
{
|
|
switch (img)
|
|
{
|
|
case MessageBoxImage.Hand:
|
|
return MsgIcon.Error;
|
|
case MessageBoxImage.Question:
|
|
return MsgIcon.Question;
|
|
case MessageBoxImage.Exclamation:
|
|
return MsgIcon.Warning;
|
|
case MessageBoxImage.Asterisk:
|
|
return MsgIcon.Info;
|
|
default:
|
|
return MsgIcon.None;
|
|
}
|
|
}
|
|
|
|
private static MessageBoxResult ToWpfResult(DialogResult r)
|
|
{
|
|
switch (r)
|
|
{
|
|
case DialogResult.OK:
|
|
return MessageBoxResult.OK;
|
|
case DialogResult.Cancel:
|
|
return MessageBoxResult.Cancel;
|
|
case DialogResult.Yes:
|
|
return MessageBoxResult.Yes;
|
|
case DialogResult.No:
|
|
return MessageBoxResult.No;
|
|
default:
|
|
return MessageBoxResult.None;
|
|
}
|
|
}
|
|
|
|
public static MessageBoxResult MessageBox(
|
|
string message,
|
|
string title = "",
|
|
MessageBoxButton buttons = MessageBoxButton.OK,
|
|
MessageBoxImage icon = MessageBoxImage.None,
|
|
bool pIsDarkMode = true)
|
|
{
|
|
MessageBoxButtons winForms = Messenger.ToWinForms(buttons);
|
|
MsgIcon msgIcon = Messenger.ToMsgIcon(icon);
|
|
return Messenger.ToWpfResult(Messenger.MessageBox(message, title, msgIcon, winForms, pIsDarkMode));
|
|
}
|
|
|
|
public static DialogResult InputBox(
|
|
string title,
|
|
string promptText,
|
|
ref List<KeyValue> Fields,
|
|
MsgIcon Icon = MsgIcon.None,
|
|
MessageBoxButtons buttons = MessageBoxButtons.OK,
|
|
bool pIsDarkMode = true)
|
|
{
|
|
Form form1 = new Form();
|
|
form1.FormBorderStyle = FormBorderStyle.FixedDialog;
|
|
form1.StartPosition = FormStartPosition.CenterParent;
|
|
form1.MaximizeBox = false;
|
|
form1.MinimizeBox = false;
|
|
form1.Text = title;
|
|
form1.Width = 340;
|
|
form1.Height = 170;
|
|
Form form = form1;
|
|
DarkModeCS darkModeCs = new DarkModeCS(form)
|
|
{
|
|
ColorMode = pIsDarkMode ? DarkModeCS.DisplayMode.DarkMode : DarkModeCS.DisplayMode.ClearMode
|
|
};
|
|
darkModeCs.ApplyTheme(pIsDarkMode);
|
|
ErrorProvider Err = new ErrorProvider();
|
|
Base64Icons base64Icons = new Base64Icons();
|
|
Panel panel1 = new Panel();
|
|
panel1.Dock = DockStyle.Bottom;
|
|
panel1.Height = 48 /*0x30*/;
|
|
panel1.BackColor = darkModeCs.OScolors.Surface;
|
|
panel1.ForeColor = darkModeCs.OScolors.TextActive;
|
|
Panel panel2 = panel1;
|
|
form.Controls.Add((Control) panel2);
|
|
if (Icon != MsgIcon.None)
|
|
{
|
|
PictureBox pictureBox1 = new PictureBox();
|
|
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
|
|
pictureBox1.Size = new System.Drawing.Size(48 /*0x30*/, 48 /*0x30*/);
|
|
PictureBox pictureBox2 = pictureBox1;
|
|
pictureBox2.Image = base64Icons.GetIcon(Icon);
|
|
panel2.Controls.Add((Control) pictureBox2);
|
|
pictureBox2.SetBounds(0, 2, 48 /*0x30*/, 48 /*0x30*/);
|
|
pictureBox2.BringToFront();
|
|
}
|
|
Dictionary<string, string> buttonTranslations = Messenger.GetButtonTranslations(Messenger.GetCurrentLanguage());
|
|
List<Button> buttonList1 = new List<Button>();
|
|
switch (buttons)
|
|
{
|
|
case MessageBoxButtons.OK:
|
|
List<Button> buttonList2 = buttonList1;
|
|
Button button1 = new Button();
|
|
button1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button1.DialogResult = DialogResult.OK;
|
|
button1.Text = buttonTranslations["OK"];
|
|
buttonList2.Add(button1);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
break;
|
|
case MessageBoxButtons.OKCancel:
|
|
List<Button> buttonList3 = buttonList1;
|
|
Button button2 = new Button();
|
|
button2.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button2.DialogResult = DialogResult.OK;
|
|
button2.Text = buttonTranslations["OK"];
|
|
buttonList3.Add(button2);
|
|
List<Button> buttonList4 = buttonList1;
|
|
Button button3 = new Button();
|
|
button3.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button3.DialogResult = DialogResult.Cancel;
|
|
button3.Text = buttonTranslations["Cancel"];
|
|
buttonList4.Add(button3);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.CancelButton = (IButtonControl) buttonList1[1];
|
|
break;
|
|
case MessageBoxButtons.AbortRetryIgnore:
|
|
List<Button> buttonList5 = buttonList1;
|
|
Button button4 = new Button();
|
|
button4.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button4.DialogResult = DialogResult.Retry;
|
|
button4.Text = buttonTranslations["Retry"];
|
|
buttonList5.Add(button4);
|
|
List<Button> buttonList6 = buttonList1;
|
|
Button button5 = new Button();
|
|
button5.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button5.DialogResult = DialogResult.Abort;
|
|
button5.Text = buttonTranslations["Abort"];
|
|
buttonList6.Add(button5);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.CancelButton = (IButtonControl) buttonList1[1];
|
|
break;
|
|
case MessageBoxButtons.YesNoCancel:
|
|
List<Button> buttonList7 = buttonList1;
|
|
Button button6 = new Button();
|
|
button6.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button6.DialogResult = DialogResult.Yes;
|
|
button6.Text = buttonTranslations["Yes"];
|
|
buttonList7.Add(button6);
|
|
List<Button> buttonList8 = buttonList1;
|
|
Button button7 = new Button();
|
|
button7.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button7.DialogResult = DialogResult.No;
|
|
button7.Text = buttonTranslations["No"];
|
|
buttonList8.Add(button7);
|
|
List<Button> buttonList9 = buttonList1;
|
|
Button button8 = new Button();
|
|
button8.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button8.DialogResult = DialogResult.Cancel;
|
|
button8.Text = buttonTranslations["Cancel"];
|
|
buttonList9.Add(button8);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.CancelButton = (IButtonControl) buttonList1[2];
|
|
break;
|
|
case MessageBoxButtons.YesNo:
|
|
List<Button> buttonList10 = buttonList1;
|
|
Button button9 = new Button();
|
|
button9.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button9.DialogResult = DialogResult.Yes;
|
|
button9.Text = buttonTranslations["Yes"];
|
|
buttonList10.Add(button9);
|
|
List<Button> buttonList11 = buttonList1;
|
|
Button button10 = new Button();
|
|
button10.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button10.DialogResult = DialogResult.No;
|
|
button10.Text = buttonTranslations["No"];
|
|
buttonList11.Add(button10);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.CancelButton = (IButtonControl) buttonList1[1];
|
|
break;
|
|
case MessageBoxButtons.RetryCancel:
|
|
List<Button> buttonList12 = buttonList1;
|
|
Button button11 = new Button();
|
|
button11.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button11.DialogResult = DialogResult.Retry;
|
|
button11.Text = buttonTranslations["Retry"];
|
|
buttonList12.Add(button11);
|
|
List<Button> buttonList13 = buttonList1;
|
|
Button button12 = new Button();
|
|
button12.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
button12.DialogResult = DialogResult.Cancel;
|
|
button12.Text = buttonTranslations["Cancel"];
|
|
buttonList13.Add(button12);
|
|
form.AcceptButton = (IButtonControl) buttonList1[0];
|
|
form.CancelButton = (IButtonControl) buttonList1[1];
|
|
break;
|
|
}
|
|
int num1 = 4;
|
|
int num2 = form.ClientSize.Width;
|
|
foreach (Button button13 in buttonList1)
|
|
{
|
|
button13.FlatAppearance.BorderColor = form.AcceptButton == button13 ? darkModeCs.OScolors.Accent : darkModeCs.OScolors.Control;
|
|
panel2.Controls.Add((Control) button13);
|
|
button13.Location = new System.Drawing.Point(num2 - (button13.Width + num1), (panel2.Height - button13.Height) / 2);
|
|
num2 = button13.Left;
|
|
}
|
|
Label label1 = new Label();
|
|
if (!string.IsNullOrWhiteSpace(promptText))
|
|
{
|
|
label1.Dock = DockStyle.Top;
|
|
label1.Text = promptText;
|
|
label1.AutoSize = false;
|
|
label1.Height = 24;
|
|
label1.TextAlign = ContentAlignment.MiddleCenter;
|
|
}
|
|
else
|
|
{
|
|
label1.Location = new System.Drawing.Point(0, 0);
|
|
label1.Width = 0;
|
|
label1.Height = 0;
|
|
}
|
|
form.Controls.Add((Control) label1);
|
|
TableLayoutPanel tableLayoutPanel1 = new TableLayoutPanel();
|
|
tableLayoutPanel1.Size = new System.Drawing.Size(form.ClientSize.Width - 20, 50);
|
|
tableLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
|
|
tableLayoutPanel1.BackColor = darkModeCs.OScolors.Background;
|
|
tableLayoutPanel1.AutoSize = true;
|
|
tableLayoutPanel1.ColumnCount = 2;
|
|
tableLayoutPanel1.Location = new System.Drawing.Point(10, label1.Location.Y + label1.Height + 4);
|
|
TableLayoutPanel tableLayoutPanel2 = tableLayoutPanel1;
|
|
form.Controls.Add((Control) tableLayoutPanel2);
|
|
tableLayoutPanel2.ColumnStyles.Clear();
|
|
tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
|
|
tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute));
|
|
tableLayoutPanel2.ColumnStyles[1].Width = (float) (form.ClientSize.Width - 120);
|
|
tableLayoutPanel2.RowStyles.Clear();
|
|
int ChangeDelayMS = 1000;
|
|
int row = 0;
|
|
foreach (KeyValue keyValue in Fields)
|
|
{
|
|
KeyValue field = keyValue;
|
|
Label label2 = new Label();
|
|
label2.Text = field.Key;
|
|
label2.AutoSize = false;
|
|
label2.Dock = DockStyle.Fill;
|
|
label2.TextAlign = ContentAlignment.MiddleCenter;
|
|
Label label3 = label2;
|
|
Control field_Control = (Control) null;
|
|
BorderStyle borderStyle = darkModeCs.IsDarkMode ? BorderStyle.FixedSingle : BorderStyle.Fixed3D;
|
|
if (field.ValueType == KeyValue.ValueTypes.String)
|
|
{
|
|
TextBox textBox = new TextBox();
|
|
textBox.Text = field.Value;
|
|
textBox.Dock = DockStyle.Fill;
|
|
textBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
|
field_Control = (Control) textBox;
|
|
field_Control.TextChanged += (EventHandler) ((sender, args) => Messenger.AddTextChangedDelay<TextBox>((TextBox) field_Control, ChangeDelayMS, (Action<TextBox>) (text =>
|
|
{
|
|
field.Value = ((Control) sender).Text;
|
|
((Control) sender).Text = Convert.ToString(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
})));
|
|
}
|
|
if (field.ValueType == KeyValue.ValueTypes.Multiline)
|
|
{
|
|
TextBox textBox = new TextBox();
|
|
textBox.Text = field.Value;
|
|
textBox.Dock = DockStyle.Fill;
|
|
textBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
|
|
textBox.Multiline = true;
|
|
textBox.ScrollBars = ScrollBars.Vertical;
|
|
field_Control = (Control) textBox;
|
|
field_Control.TextChanged += (EventHandler) ((sender, args) => Messenger.AddTextChangedDelay<TextBox>((TextBox) field_Control, ChangeDelayMS, (Action<TextBox>) (text =>
|
|
{
|
|
field.Value = ((Control) sender).Text;
|
|
((Control) sender).Text = Convert.ToString(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
})));
|
|
}
|
|
if (field.ValueType == KeyValue.ValueTypes.Password)
|
|
{
|
|
TextBox textBox = new TextBox();
|
|
textBox.Text = field.Value;
|
|
textBox.Dock = DockStyle.Fill;
|
|
textBox.UseSystemPasswordChar = true;
|
|
textBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
|
field_Control = (Control) textBox;
|
|
field_Control.TextChanged += (EventHandler) ((sender, args) => Messenger.AddTextChangedDelay<TextBox>((TextBox) field_Control, ChangeDelayMS, (Action<TextBox>) (text =>
|
|
{
|
|
field.Value = ((Control) sender).Text;
|
|
((Control) sender).Text = Convert.ToString(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
})));
|
|
}
|
|
if (field.ValueType == KeyValue.ValueTypes.Integer)
|
|
{
|
|
NumericUpDown numericUpDown = new NumericUpDown();
|
|
numericUpDown.Minimum = -2147483648M;
|
|
numericUpDown.Maximum = 2147483647M;
|
|
numericUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
|
numericUpDown.Value = (Decimal) Convert.ToInt32(field.Value);
|
|
numericUpDown.ThousandsSeparator = true;
|
|
numericUpDown.Dock = DockStyle.Fill;
|
|
numericUpDown.DecimalPlaces = 0;
|
|
field_Control = (Control) numericUpDown;
|
|
((NumericUpDown) field_Control).ValueChanged += (EventHandler) ((sender, args) => Messenger.AddTextChangedDelay<NumericUpDown>((NumericUpDown) field_Control, ChangeDelayMS, (Action<NumericUpDown>) (text =>
|
|
{
|
|
field.Value = ((NumericUpDown) sender).Value.ToString();
|
|
((NumericUpDown) sender).Value = (Decimal) Convert.ToInt32(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
})));
|
|
}
|
|
if (field.ValueType == KeyValue.ValueTypes.Decimal)
|
|
{
|
|
NumericUpDown numericUpDown = new NumericUpDown();
|
|
numericUpDown.Minimum = -2147483648M;
|
|
numericUpDown.Maximum = 2147483647M;
|
|
numericUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
|
|
numericUpDown.Value = Convert.ToDecimal(field.Value);
|
|
numericUpDown.ThousandsSeparator = false;
|
|
numericUpDown.Dock = DockStyle.Fill;
|
|
numericUpDown.DecimalPlaces = 2;
|
|
field_Control = (Control) numericUpDown;
|
|
((NumericUpDown) field_Control).ValueChanged += (EventHandler) ((sender, args) => Messenger.AddTextChangedDelay<NumericUpDown>((NumericUpDown) field_Control, ChangeDelayMS, (Action<NumericUpDown>) (text =>
|
|
{
|
|
field.Value = ((NumericUpDown) sender).Value.ToString();
|
|
((NumericUpDown) sender).Value = Convert.ToDecimal(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
})));
|
|
}
|
|
if (field.ValueType == KeyValue.ValueTypes.Date)
|
|
{
|
|
DateTimePicker dateTimePicker = new DateTimePicker();
|
|
dateTimePicker.Value = Convert.ToDateTime(field.Value);
|
|
dateTimePicker.Dock = DockStyle.Fill;
|
|
dateTimePicker.Format = DateTimePickerFormat.Short;
|
|
dateTimePicker.CalendarForeColor = darkModeCs.OScolors.TextActive;
|
|
dateTimePicker.CalendarMonthBackground = darkModeCs.OScolors.Control;
|
|
dateTimePicker.CalendarTitleBackColor = darkModeCs.OScolors.Surface;
|
|
dateTimePicker.CalendarTitleForeColor = darkModeCs.OScolors.TextActive;
|
|
field_Control = (Control) dateTimePicker;
|
|
((DateTimePicker) field_Control).ValueChanged += (EventHandler) ((sender, args) =>
|
|
{
|
|
field.Value = ((DateTimePicker) sender).Value.ToString();
|
|
((DateTimePicker) sender).Value = Convert.ToDateTime(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
Err.SetIconAlignment(field_Control, ErrorIconAlignment.MiddleLeft);
|
|
});
|
|
}
|
|
if (field.ValueType == KeyValue.ValueTypes.Time)
|
|
{
|
|
DateTimePicker dateTimePicker = new DateTimePicker();
|
|
dateTimePicker.Value = Convert.ToDateTime(field.Value);
|
|
dateTimePicker.Dock = DockStyle.Fill;
|
|
dateTimePicker.Format = DateTimePickerFormat.Time;
|
|
field_Control = (Control) dateTimePicker;
|
|
((DateTimePicker) field_Control).ValueChanged += (EventHandler) ((sender, args) =>
|
|
{
|
|
field.Value = ((DateTimePicker) sender).Value.ToString();
|
|
((DateTimePicker) sender).Value = Convert.ToDateTime(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
Err.SetIconAlignment(field_Control, ErrorIconAlignment.MiddleLeft);
|
|
});
|
|
}
|
|
if (field.ValueType == KeyValue.ValueTypes.Boolean)
|
|
{
|
|
CheckBox checkBox = new CheckBox();
|
|
checkBox.Checked = Convert.ToBoolean(field.Value);
|
|
checkBox.Dock = DockStyle.Fill;
|
|
checkBox.Text = field.Key;
|
|
field_Control = (Control) checkBox;
|
|
((CheckBox) field_Control).CheckedChanged += (EventHandler) ((sender, args) =>
|
|
{
|
|
field.Value = ((CheckBox) sender).Checked.ToString();
|
|
((CheckBox) sender).Checked = Convert.ToBoolean(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
});
|
|
}
|
|
if (field.ValueType == KeyValue.ValueTypes.Dynamic)
|
|
{
|
|
FlatComboBox flatComboBox = new FlatComboBox();
|
|
flatComboBox.DataSource = (object) field.DataSet;
|
|
flatComboBox.ValueMember = "Value";
|
|
flatComboBox.DisplayMember = "Key";
|
|
flatComboBox.Dock = DockStyle.Fill;
|
|
flatComboBox.BackColor = darkModeCs.OScolors.Control;
|
|
flatComboBox.ButtonColor = darkModeCs.OScolors.Surface;
|
|
flatComboBox.ForeColor = darkModeCs.OScolors.TextActive;
|
|
flatComboBox.SelectedValue = (object) field.Value;
|
|
flatComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
flatComboBox.FlatStyle = darkModeCs.IsDarkMode ? FlatStyle.Flat : FlatStyle.Standard;
|
|
field_Control = (Control) flatComboBox;
|
|
((ListControl) field_Control).SelectedValueChanged += (EventHandler) ((sender, args) =>
|
|
{
|
|
field.Value = ((ListControl) sender).SelectedValue.ToString();
|
|
((ListControl) sender).SelectedValue = (object) Convert.ToString(field.Value);
|
|
Err.SetError(field_Control, field.ErrorText);
|
|
});
|
|
}
|
|
tableLayoutPanel2.Controls.Add((Control) label3, 0, row);
|
|
if (field.ValueType == KeyValue.ValueTypes.Multiline)
|
|
{
|
|
tableLayoutPanel2.Controls.Add(field_Control, 1, row);
|
|
for (int index = 0; index < 6; ++index)
|
|
{
|
|
++row;
|
|
++tableLayoutPanel2.RowCount;
|
|
tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Absolute, (float) field_Control.Height));
|
|
}
|
|
tableLayoutPanel2.SetRowSpan(field_Control, 6);
|
|
}
|
|
else
|
|
tableLayoutPanel2.Controls.Add(field_Control, 1, row);
|
|
Err.SetIconAlignment(field_Control, ErrorIconAlignment.MiddleLeft);
|
|
if (field_Control is ComboBox)
|
|
{
|
|
field_Control.CreateControl();
|
|
((ListControl) field_Control).SelectedValue = (object) field.Value;
|
|
}
|
|
field_Control.TabIndex = row;
|
|
++row;
|
|
}
|
|
tableLayoutPanel2.Width = form.ClientSize.Width - 20;
|
|
form.ClientSize = new System.Drawing.Size(340, panel2.Height + label1.Height + tableLayoutPanel2.Height + 20);
|
|
form.FormClosing += (FormClosingEventHandler) ((sender, e) =>
|
|
{
|
|
if (form.ActiveControl != form.AcceptButton)
|
|
return;
|
|
KeyValue.ValidateEventArgs validateEventArgs = new KeyValue.ValidateEventArgs((string) null);
|
|
Action<object, KeyValue.ValidateEventArgs> validateControlsHandler = Messenger.ValidateControlsHandler;
|
|
if (validateControlsHandler != null)
|
|
validateControlsHandler((object) form, validateEventArgs);
|
|
e.Cancel = validateEventArgs.Cancel;
|
|
if (e.Cancel)
|
|
return;
|
|
form.DialogResult = form.AcceptButton.DialogResult;
|
|
});
|
|
return form.ShowDialog();
|
|
}
|
|
|
|
private static void AddTextChangedDelay<TControl>(
|
|
TControl control,
|
|
int milliseconds,
|
|
Action<TControl> action)
|
|
where TControl : Control
|
|
{
|
|
if (Messenger.timers == null)
|
|
Messenger.timers = new Dictionary<Control, Timer>();
|
|
if (Messenger.timers.ContainsKey((Control) control))
|
|
{
|
|
Messenger.timers[(Control) control].Stop();
|
|
Messenger.timers.Remove((Control) control);
|
|
}
|
|
Timer timer = new Timer();
|
|
timer.Interval = milliseconds;
|
|
timer.Tick += (EventHandler) ((sender, e) =>
|
|
{
|
|
timer.Stop();
|
|
Messenger.timers.Remove((Control) control);
|
|
action(control);
|
|
});
|
|
timer.Start();
|
|
Messenger.timers.Add((Control) control, timer);
|
|
}
|
|
|
|
public static string GetCurrentLanguage(string pDefault = "en")
|
|
{
|
|
string currentLanguage = pDefault;
|
|
string letterIsoLanguageName = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
|
|
if (Messenger.IsCurrentLanguageSupported(new List<string>()
|
|
{
|
|
"en",
|
|
"es",
|
|
"fr",
|
|
"de",
|
|
"ru",
|
|
"ko",
|
|
"pt"
|
|
}, letterIsoLanguageName))
|
|
currentLanguage = letterIsoLanguageName;
|
|
if (letterIsoLanguageName.ToLowerInvariant().Equals("zh"))
|
|
{
|
|
string name = CultureInfo.CurrentCulture.Name;
|
|
currentLanguage = string.Equals(name, "zh-CN") || string.Equals(name, "zh-SG") || string.Equals(name, "zh-Hans") ? "zh-Hans" : (string.Equals(name, "zh-TW") || string.Equals(name, "zh-HK") || string.Equals(name, "zh-MO") || string.Equals(name, "zh-Hant") ? "zh-Hant" : "zh-Hans");
|
|
}
|
|
return currentLanguage;
|
|
}
|
|
|
|
private static Dictionary<string, string> GetButtonTranslations(string pLanguage)
|
|
{
|
|
Dictionary<string, string> buttonTranslations = (Dictionary<string, string>) null;
|
|
string str = new Dictionary<string, string>()
|
|
{
|
|
{
|
|
"en",
|
|
"OK|Cancel|Yes|No|Continue|Retry|Abort|Ignore|Try Again"
|
|
},
|
|
{
|
|
"es",
|
|
"Aceptar|Cancelar|Sí|No|Continuar|Reintentar|Abortar|Ignorar|Intentar"
|
|
},
|
|
{
|
|
"fr",
|
|
"Accepter|Annuler|Oui|Non|Continuer|Réessayer|Abandonner|Ignorer|Essayer"
|
|
},
|
|
{
|
|
"de",
|
|
"Akzeptieren|Abbrechen|Ja|Nein|Weiter|Wiederholen|Abbrechen|Ignorieren|Versuchen"
|
|
},
|
|
{
|
|
"ru",
|
|
"Принять|Отменить|Да|Нет|Продолжить|Повторить|Прервать|Игнорировать|Пытаться"
|
|
},
|
|
{
|
|
"ko",
|
|
"확인|취소|예|아니오|계속|다시 시도|중단|무시|써 보다"
|
|
},
|
|
{
|
|
"pt",
|
|
"Aceitar|Cancelar|Sim|Não|Continuar|Tentar novamente|Abortar|Ignorar|Tentar"
|
|
},
|
|
{
|
|
"zh-Hans",
|
|
"确定|取消|是|否|继续|重试|中止|忽略|尝试"
|
|
},
|
|
{
|
|
"zh-Hant",
|
|
"確定|取消|是|否|繼續|重試|中止|忽略|嘗試"
|
|
}
|
|
}[pLanguage];
|
|
if (!string.IsNullOrEmpty(str))
|
|
{
|
|
List<string> list = ((IEnumerable<string>) str.Split('|')).ToList<string>();
|
|
buttonTranslations = new Dictionary<string, string>()
|
|
{
|
|
{
|
|
"OK",
|
|
list[0]
|
|
},
|
|
{
|
|
"Cancel",
|
|
list[1]
|
|
},
|
|
{
|
|
"Yes",
|
|
list[2]
|
|
},
|
|
{
|
|
"No",
|
|
list[3]
|
|
},
|
|
{
|
|
"Continue",
|
|
list[4]
|
|
},
|
|
{
|
|
"Retry",
|
|
list[5]
|
|
},
|
|
{
|
|
"Abort",
|
|
list[6]
|
|
},
|
|
{
|
|
"Ignore",
|
|
list[7]
|
|
},
|
|
{
|
|
"Try Again",
|
|
list[8]
|
|
}
|
|
};
|
|
}
|
|
return buttonTranslations;
|
|
}
|
|
|
|
private static bool IsCurrentLanguageSupported(List<string> languages, string currentLanguage)
|
|
{
|
|
currentLanguage = languages != null && currentLanguage != null ? currentLanguage.ToLowerInvariant() : throw new ArgumentNullException(languages == null ? nameof (languages) : nameof (currentLanguage));
|
|
if (languages.Contains(currentLanguage))
|
|
return true;
|
|
if (currentLanguage.Length < 2)
|
|
return false;
|
|
string str = currentLanguage.Substring(0, 2);
|
|
return languages.Contains(str);
|
|
}
|
|
}
|