//
// Copyright © 2006-2010, Intel Corporation. All rights reserved.
//
//File: MessageManager.cs
//
// Contents: Various functions meant for displaying messages to users
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Gui.Forms;
namespace AMT_SW_GUI
{
///
/// This class manages all the messages presented to the user.
/// This class capable of getting string message or exception and show the relevant message to the user.
///
public class MessageManager
{
private static System.Drawing.Icon icon;
private static bool RTL;
private static bool handOnButtons = false;
private static string localYES = "Yes";
private static string localNO = "No";
private static string localCANCEL = "Cancel";
private static string localOK = "OK";
public static void InitMessageManager(System.Drawing.Icon ApplicationIcon, bool RightToLeft,string strYes, string strNo, string strCancel,string strOK,bool handCursorOnButtons)
{
localYES = strYes;
localNO = strNo;
localCANCEL = strCancel;
localOK = strOK;
handOnButtons = handCursorOnButtons;
InitMessageManager(ApplicationIcon, RightToLeft);
}
public static void InitMessageManager(System.Drawing.Icon ApplicationIcon, bool RightToLeft)
{
icon = ApplicationIcon;
RTL = RightToLeft;
}
public static void InitMessageManager(System.Drawing.Icon ApplicationIcon)
{
InitMessageManager(ApplicationIcon, false);
}
///
/// Display the user text message in a simple message box
///
///
public static DialogResult ShowMessage(string text, string caption, Form parent)
{
if (null == text)
{
return DialogResult.Cancel;
}
else
{
if (null == caption)
{
caption = "";
}
using (MessageForm mf = new MessageForm(text, caption, MessageForm.MessageType.INFO, MessageForm.MessageFormType.OK, RTL, localYES, localNO, localCANCEL, localOK, handOnButtons))
{
mf.Icon = icon;
mf.Owner = parent;
return mf.ShowDialog();
}
}
}
public static DialogResult ShowMessage(string text, string caption)
{
return ShowMessage(text, caption, null);
}
public static DialogResult ShowWarningMessage(string text, string caption, MessageBoxButtons buttons, Form parent)
{
if (null == text)
{
return DialogResult.Cancel;
}
else
{
if (null == caption)
{
caption = "";
}
using (MessageForm mf = new MessageForm(text, caption, MessageForm.MessageType.WARNING, MessageForm.GetButtons(buttons), RTL, localYES, localNO, localCANCEL, localOK,handOnButtons))
{
mf.Icon = icon;
mf.Owner = parent;
return mf.ShowDialog();
}
}
}
public static DialogResult ShowWarningMessage(string text, string caption, MessageBoxButtons buttons)
{
return ShowWarningMessage(text, caption, buttons, null);
}
public static DialogResult ShowErrorMessage(string text, string caption, Form parent)
{
if (null == text)
{
return DialogResult.Cancel;
}
else
{
if (null == caption)
{
caption = "";
}
using (MessageForm mf = new MessageForm(text, caption, MessageForm.MessageType.ERROR, MessageForm.MessageFormType.OK, RTL, localYES, localNO, localCANCEL, localOK,handOnButtons))
{
mf.Icon = icon;
mf.Owner = parent;
return mf.ShowDialog();
}
}
}
public static DialogResult ShowErrorMessage(string text, string caption)
{
return ShowErrorMessage(text, caption, null);
}
public static DialogResult ShowQuestionMessage(string text, string caption, Form parent)
{
if (null == text)
{
return DialogResult.No;
}
else
{
if (null == caption)
{
caption = "";
}
using (MessageForm mf = new MessageForm(text, caption, MessageForm.MessageType.QUESTION, MessageForm.MessageFormType.YesNo, RTL, localYES, localNO, localCANCEL,localOK,handOnButtons))
{
mf.Icon = icon;
mf.Owner = parent;
return mf.ShowDialog();
}
}
}
public static DialogResult ShowQuestionMessage(string text, string caption)
{
return ShowQuestionMessage(text, caption, null);
}
}
}