using MathNet.Numerics;
using System.IO;
using System.Threading.Tasks;
#nullable enable
namespace LibationUiBase.Forms;
public enum DialogResult
{
/// Nothing is returned from the dialog box. This means that the modal dialog continues running.
None = 0,
/// The dialog box return value is OK (usually sent from a button labeled OK).
OK = 1, //IDOK
/// The dialog box return value is Cancel (usually sent from a button labeled Cancel).
Cancel = 2, //IDCANCEL
/// The dialog box return value is Abort (usually sent from a button labeled Abort).
Abort = 3, //IDABORT
/// The dialog box return value is Retry (usually sent from a button labeled Retry).
Retry = 4, //IDRETRY
/// The dialog box return value is Ignore (usually sent from a button labeled Ignore).
Ignore = 5, //IDIGNORE
/// The dialog box return value is Yes (usually sent from a button labeled Yes).
Yes = 6, //IDYES
/// The dialog box return value is No (usually sent from a button labeled No).
No = 7, //IDNO
/// The dialog box return value is Try Again (usually sent from a button labeled Try Again).
TryAgain = 10, //IDTRYAGAIN
/// The dialog box return value is Continue (usually sent from a button labeled Continue).
Continue = 11 //IDCONTINUE
}
public enum MessageBoxIcon
{
/// Specifies that the message box contain no symbols.
None = 0x00000000,
/// Specifies that the message box contains a hand symbol.
Hand = 0x00000010, //MB_ICONHAND
/// Specifies that the message box contains a question mark symbol.
Question = 0x00000020, //MB_ICONQUESTION
/// Specifies that the message box contains an exclamation symbol.
Exclamation = 0x00000030, //MB_ICONEXCLAMATION
/// Specifies that the message box contains an asterisk symbol.
Asterisk = 0x00000040, //MB_ICONASTERISK
/// Specifies that the message box contains a hand icon. This field is constant.
Stop = Hand,
/// Specifies that the message box contains a hand icon.
Error = Hand,
/// Specifies that the message box contains an exclamation icon.
Warning = Exclamation,
/// Specifies that the message box contains an asterisk icon.
Information = Asterisk
}
public enum MessageBoxButtons
{
/// Specifies that the message box contains an OK button.
OK = 0x00000000, //MB_OK
/// Specifies that the message box contains OK and Cancel buttons.
OKCancel = 0x00000001, //MB_OKCANCEL
/// Specifies that the message box contains Abort, Retry, and Ignore buttons.
AbortRetryIgnore = 0x00000002, //MB_ABORTRETRYIGNORE
/// Specifies that the message box contains Yes, No, and Cancel buttons.
YesNoCancel = 0x00000003, //MB_YESNOCANCEL
/// Specifies that the message box contains Yes and No buttons.
YesNo = 0x00000004, //MB_YESNO
/// Specifies that the message box contains Retry and Cancel buttons.
RetryCancel = 0x00000005, //MB_RETRYCANCEL
/// Specifies that the message box contains Cancel, Try Again, and Continue buttons.
CancelTryContinue = 0x00000006 //MB_CANCELTRYCONTINUE
}
public enum MessageBoxDefaultButton
{
/// Specifies that the first button on the message box should be the default button.
Button1 = 0x00000000, //MB_DEFBUTTON1
/// Specifies that the second button on the message box should be the default button.
Button2 = 0x00000100, //MB_DEFBUTTON2
/// Specifies that the third button on the message box should be the default button.
Button3 = 0x00000200, //MB_DEFBUTTON3
/// Specifies that the Help button on the message box should be the default button.
Button4 = 0x00000300, //MB_DEFBUTTON4
}
///
/// Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, and default button.
///
/// An implementation of a GUI window that will own the modal dialog box
/// The text to display in the message box
/// The text to display in the title bar of the message box
/// One of the values that specifies which buttons to disply in the message box
/// One of the values that specifies which icon to disply in the message box
/// One of the values that specifies the default button of the message box
/// A value indicating whether the message box's position should be saved and restored the next time it is shown
/// One of the values
public delegate Task ShowAsyncDelegate(object? owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool saveAndRestorePosition = true);
public static class MessageBoxBase
{
private static ShowAsyncDelegate? s_ShowAsyncImpl;
public static ShowAsyncDelegate ShowAsyncImpl
{
get => s_ShowAsyncImpl ?? DefaultShowAsyncImpl;
set => s_ShowAsyncImpl = value;
}
private static Task DefaultShowAsyncImpl(object? owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool saveAndRestorePosition = true)
{
// default to a no-op impl
Serilog.Log.Logger.Error("MessageBoxBase implementation not set. {@DebugInfo}", new { owner, message, caption, buttons, icon, defaultButton });
return Task.FromResult(DialogResult.None);
}
public static Task Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool saveAndRestorePosition = true)
=> ShowAsyncImpl(null, text, caption, buttons, icon, defaultButton);
public static Task Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, bool saveAndRestorePosition = true)
=> ShowAsyncImpl(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1, saveAndRestorePosition);
public static Task Show(string text, string caption, MessageBoxButtons buttons)
=> ShowAsyncImpl(null, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
public static Task Show(string text, string caption)
=> ShowAsyncImpl(null, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
public static Task Show(string text)
=> ShowAsyncImpl(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
public static Task Show(object? owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
=> ShowAsyncImpl(owner, text, caption, buttons, icon, defaultButton);
public static Task Show(object? owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
=> ShowAsyncImpl(owner, text, caption, buttons, icon, MessageBoxDefaultButton.Button1);
public static Task Show(object? owner, string text, string caption, MessageBoxButtons buttons)
=> ShowAsyncImpl(owner, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
public static Task Show(object? owner, string text, string caption)
=> ShowAsyncImpl(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
public static Task Show(object? owner, string text)
=> ShowAsyncImpl(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
}