2018-03-21 21:14:51 -04:00
|
|
|
|
using Mesen.GUI.Config;
|
|
|
|
|
using System;
|
2015-07-05 19:03:57 -04:00
|
|
|
|
using System.Collections.Generic;
|
2016-02-07 14:42:07 -05:00
|
|
|
|
using System.ComponentModel;
|
2016-01-31 11:58:41 -05:00
|
|
|
|
using System.Drawing;
|
2015-07-05 19:03:57 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Forms
|
|
|
|
|
{
|
|
|
|
|
public class BaseForm : Form
|
|
|
|
|
{
|
2018-03-21 21:14:51 -04:00
|
|
|
|
public delegate bool ProcessCmdKeyHandler(Keys keyData);
|
|
|
|
|
public event ProcessCmdKeyHandler OnProcessCmdKey;
|
|
|
|
|
|
2016-01-16 09:50:33 -05:00
|
|
|
|
protected ToolTip toolTip;
|
|
|
|
|
private System.ComponentModel.IContainer components;
|
2016-01-31 11:58:41 -05:00
|
|
|
|
private bool _iconSet = false;
|
2018-03-21 21:14:51 -04:00
|
|
|
|
protected int _inMenu = 0;
|
|
|
|
|
private static Timer _tmrUpdateBackground;
|
2016-01-16 09:50:33 -05:00
|
|
|
|
|
2018-03-21 21:14:51 -04:00
|
|
|
|
static BaseForm()
|
|
|
|
|
{
|
|
|
|
|
bool designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
|
|
|
|
|
if(!designMode) {
|
|
|
|
|
_tmrUpdateBackground = new Timer();
|
|
|
|
|
_tmrUpdateBackground.Start();
|
|
|
|
|
_tmrUpdateBackground.Tick += tmrUpdateBackground_Tick;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-19 13:05:04 -05:00
|
|
|
|
|
2016-01-16 09:50:33 -05:00
|
|
|
|
public BaseForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2018-05-26 10:59:15 -04:00
|
|
|
|
|
|
|
|
|
protected virtual bool IsConfigForm { get { return false; } }
|
|
|
|
|
|
2018-03-21 21:14:51 -04:00
|
|
|
|
private static void tmrUpdateBackground_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Form focusedForm = null;
|
|
|
|
|
foreach(Form form in Application.OpenForms) {
|
|
|
|
|
if(form.ContainsFocus) {
|
|
|
|
|
focusedForm = form;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 17:47:02 -04:00
|
|
|
|
bool inBackground = focusedForm == null;
|
2018-03-21 21:14:51 -04:00
|
|
|
|
if(focusedForm != null) {
|
2018-05-26 10:59:15 -04:00
|
|
|
|
inBackground |= ConfigManager.Config.PreferenceInfo.PauseWhenInMenusAndConfig && focusedForm is BaseForm && (((BaseForm)focusedForm)._inMenu > 0 || ((BaseForm)focusedForm).IsConfigForm);
|
2018-03-22 17:47:02 -04:00
|
|
|
|
inBackground |= ConfigManager.Config.PreferenceInfo.PauseWhenInMenusAndConfig && !(focusedForm is BaseInputForm) && !focusedForm.GetType().FullName.Contains("Debugger");
|
|
|
|
|
inBackground |= ConfigManager.Config.PreferenceInfo.PauseWhenInDebuggingTools && focusedForm.GetType().FullName.Contains("Debugger");
|
2018-03-21 21:14:51 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 17:47:02 -04:00
|
|
|
|
InteropEmu.SetFlag(EmulationFlags.InBackground, inBackground);
|
2018-03-21 21:14:51 -04:00
|
|
|
|
}
|
2016-01-16 09:50:33 -05:00
|
|
|
|
|
2018-03-10 09:58:24 -05:00
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
|
|
|
{
|
|
|
|
|
bool? result = OnProcessCmdKey?.Invoke(keyData);
|
|
|
|
|
if(result == true) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-31 11:58:41 -05:00
|
|
|
|
public void Show(object sender, IWin32Window owner = null)
|
|
|
|
|
{
|
|
|
|
|
if(sender is ToolStripMenuItem) {
|
|
|
|
|
ToolStripItem menuItem = (ToolStripMenuItem)sender;
|
|
|
|
|
if(menuItem.Image == null) {
|
|
|
|
|
menuItem = menuItem.OwnerItem;
|
|
|
|
|
}
|
|
|
|
|
this.Icon = menuItem.Image;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-28 19:00:08 -04:00
|
|
|
|
CenterOnParent(owner);
|
|
|
|
|
base.Show();
|
2016-01-31 11:58:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 19:02:33 -04:00
|
|
|
|
private void CenterOnParent(IWin32Window owner)
|
|
|
|
|
{
|
|
|
|
|
Form parent = (Form)owner;
|
|
|
|
|
Point point = parent.PointToScreen(new Point(parent.Width / 2, parent.Height / 2));
|
|
|
|
|
|
|
|
|
|
this.StartPosition = FormStartPosition.Manual;
|
|
|
|
|
this.Top = point.Y - this.Height / 2;
|
|
|
|
|
this.Left = point.X - this.Width / 2;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-31 11:58:41 -05:00
|
|
|
|
public DialogResult ShowDialog(object sender, IWin32Window owner = null)
|
|
|
|
|
{
|
|
|
|
|
if(sender is ToolStripMenuItem) {
|
|
|
|
|
ToolStripItem menuItem = (ToolStripMenuItem)sender;
|
|
|
|
|
if(menuItem.Image == null) {
|
|
|
|
|
menuItem = menuItem.OwnerItem;
|
|
|
|
|
}
|
|
|
|
|
this.Icon = menuItem.Image;
|
|
|
|
|
}
|
|
|
|
|
return base.ShowDialog(owner);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 19:03:57 -04:00
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
if(!DesignMode) {
|
2016-01-31 11:58:41 -05:00
|
|
|
|
if(!_iconSet) {
|
|
|
|
|
base.Icon = Properties.Resources.MesenIcon;
|
|
|
|
|
}
|
2015-07-05 19:03:57 -04:00
|
|
|
|
}
|
2016-02-07 14:42:07 -05:00
|
|
|
|
|
|
|
|
|
int tabIndex = 0;
|
|
|
|
|
InitializeTabIndexes(this, ref tabIndex);
|
2016-02-19 13:05:04 -05:00
|
|
|
|
ResourceHelper.ApplyResources(this);
|
2016-02-07 14:42:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeTabIndexes(TableLayoutPanel tlp, ref int tabIndex)
|
|
|
|
|
{
|
|
|
|
|
tlp.TabIndex = tabIndex;
|
|
|
|
|
tabIndex++;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < tlp.RowCount; i++) {
|
|
|
|
|
for(int j = 0; j < tlp.ColumnCount; j++) {
|
|
|
|
|
Control ctrl = tlp.GetControlFromPosition(j, i);
|
|
|
|
|
if(ctrl != null) {
|
|
|
|
|
if(ctrl is TableLayoutPanel) {
|
|
|
|
|
InitializeTabIndexes(((TableLayoutPanel)ctrl), ref tabIndex);
|
|
|
|
|
} else {
|
|
|
|
|
InitializeTabIndexes(ctrl, ref tabIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeTabIndexes(Control container, ref int tabIndex)
|
|
|
|
|
{
|
2017-12-29 12:07:43 -05:00
|
|
|
|
if(Program.IsMono) {
|
|
|
|
|
if(container is TextBox) {
|
|
|
|
|
((TextBox)container).BorderStyle = BorderStyle.FixedSingle;
|
2018-07-10 00:05:18 -04:00
|
|
|
|
((TextBox)container).BackColor = ((TextBox)container).ReadOnly ? Color.FromArgb(240, 240, 240) : Color.FromArgb(255, 255, 255);
|
|
|
|
|
((TextBox)container).ReadOnlyChanged += (object sender, EventArgs e) => {
|
|
|
|
|
((TextBox)sender).BackColor = ((TextBox)sender).ReadOnly ? Color.FromArgb(240, 240, 240) : Color.FromArgb(255, 255, 255);
|
|
|
|
|
};
|
2017-12-29 12:07:43 -05:00
|
|
|
|
} else if(container is CheckBox) {
|
|
|
|
|
((CheckBox)container).FlatStyle = FlatStyle.Flat;
|
|
|
|
|
} else if(container is Button) {
|
|
|
|
|
((Button)container).FlatStyle = FlatStyle.Flat;
|
|
|
|
|
((Button)container).BackColor = ((Button)container).Enabled ? Color.FromArgb(230, 230, 230) : Color.FromArgb(180, 180, 180);
|
|
|
|
|
((Button)container).EnabledChanged += (object sender, EventArgs e) => {
|
|
|
|
|
((Button)sender).BackColor = ((Button)sender).Enabled ? Color.FromArgb(230, 230, 230) : Color.FromArgb(180, 180, 180);
|
|
|
|
|
};
|
|
|
|
|
} else if(container is ComboBox) {
|
|
|
|
|
((ComboBox)container).FlatStyle = FlatStyle.Flat;
|
|
|
|
|
((ComboBox)container).BackColor = ((ComboBox)container).Enabled ? Color.FromArgb(230, 230, 230) : Color.FromArgb(180, 180, 180);
|
|
|
|
|
((ComboBox)container).EnabledChanged += (object sender, EventArgs e) => {
|
|
|
|
|
((ComboBox)sender).BackColor = ((ComboBox)sender).Enabled ? Color.FromArgb(230, 230, 230) : Color.FromArgb(180, 180, 180);
|
|
|
|
|
};
|
|
|
|
|
} else if(container is TabPage) {
|
|
|
|
|
((TabPage)container).BackColor = Color.White;
|
|
|
|
|
} else if(container is MenuStrip) {
|
|
|
|
|
((MenuStrip)container).RenderMode = ToolStripRenderMode.System;
|
|
|
|
|
} else if(container is ToolStrip) {
|
|
|
|
|
((ToolStrip)container).RenderMode = ToolStripRenderMode.System;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-07 14:42:07 -05:00
|
|
|
|
container.TabIndex = tabIndex;
|
|
|
|
|
tabIndex++;
|
|
|
|
|
|
|
|
|
|
foreach(Control ctrl in container.Controls) {
|
|
|
|
|
if(ctrl is TableLayoutPanel) {
|
|
|
|
|
InitializeTabIndexes(((TableLayoutPanel)ctrl), ref tabIndex);
|
|
|
|
|
} else {
|
|
|
|
|
InitializeTabIndexes(ctrl, ref tabIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-05 19:03:57 -04:00
|
|
|
|
}
|
2016-01-16 09:50:33 -05:00
|
|
|
|
|
2016-01-31 11:58:41 -05:00
|
|
|
|
public new Image Icon
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if(value != null) {
|
|
|
|
|
Bitmap b = new Bitmap(value);
|
|
|
|
|
Icon i = System.Drawing.Icon.FromHandle(b.GetHicon());
|
|
|
|
|
base.Icon = i;
|
|
|
|
|
i.Dispose();
|
|
|
|
|
|
|
|
|
|
_iconSet = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-17 00:54:30 -04:00
|
|
|
|
|
|
|
|
|
public new SizeF AutoScaleDimensions
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if(!Program.IsMono) {
|
|
|
|
|
base.AutoScaleDimensions = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new AutoScaleMode AutoScaleMode
|
|
|
|
|
{
|
|
|
|
|
set {
|
|
|
|
|
if(Program.IsMono) {
|
|
|
|
|
base.AutoScaleMode = AutoScaleMode.None;
|
|
|
|
|
} else {
|
|
|
|
|
base.AutoScaleMode = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-31 11:58:41 -05:00
|
|
|
|
|
2016-01-16 09:50:33 -05:00
|
|
|
|
private void InitializeComponent()
|
|
|
|
|
{
|
|
|
|
|
this.components = new System.ComponentModel.Container();
|
|
|
|
|
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
|
|
|
|
|
this.SuspendLayout();
|
|
|
|
|
//
|
|
|
|
|
// toolTip
|
|
|
|
|
//
|
|
|
|
|
this.toolTip.AutomaticDelay = 0;
|
|
|
|
|
this.toolTip.AutoPopDelay = 32700;
|
|
|
|
|
this.toolTip.InitialDelay = 10;
|
|
|
|
|
this.toolTip.ReshowDelay = 10;
|
|
|
|
|
//
|
|
|
|
|
// BaseForm
|
|
|
|
|
//
|
|
|
|
|
this.Name = "BaseForm";
|
|
|
|
|
this.ResumeLayout(false);
|
|
|
|
|
|
|
|
|
|
}
|
2015-07-05 19:03:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|