Remove the CustomControls/Util file and move all the classes into the Form Extensions file, since they were all extension methods for window form objects

This commit is contained in:
adelikat 2014-07-27 15:22:30 +00:00
parent c9b7686b44
commit 0397ea1ff4
25 changed files with 195 additions and 177 deletions

View File

@ -479,7 +479,6 @@
<Compile Include="CustomControls\ToolStripEx.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CustomControls\Util.cs" />
<Compile Include="CustomControls\ViewportPanel.cs">
<SubType>Component</SubType>
</Compile>

View File

@ -1,171 +0,0 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk
{
public static class Extensions
{
// extension method to make Control.Invoke easier to use
public static void Invoke(this Control control, Action action)
{
control.Invoke(action);
}
}
public static class WinFormExtensions
{
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this Form form)
{
GlobalWin.Sound.StopSound();
var result = form.ShowDialog();
GlobalWin.Sound.StartSound();
return result;
}
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this CommonDialog form)
{
GlobalWin.Sound.StopSound();
var result = form.ShowDialog();
GlobalWin.Sound.StartSound();
return result;
}
}
public static class ListViewExtensions
{
[StructLayout(LayoutKind.Sequential)]
public struct HDITEM
{
public Mask mask;
public int cxy;
[MarshalAs(UnmanagedType.LPTStr)]
public string pszText;
public IntPtr hbm;
public int cchTextMax;
public Format fmt;
public IntPtr lParam;
// _WIN32_IE >= 0x0300
public int iImage;
public int iOrder;
// _WIN32_IE >= 0x0500
public uint type;
public IntPtr pvFilter;
// _WIN32_WINNT >= 0x0600
public uint state;
[Flags]
public enum Mask
{
Format = 0x4, // HDI_FORMAT
};
[Flags]
public enum Format
{
SortDown = 0x200, // HDF_SORTDOWN
SortUp = 0x400, // HDF_SORTUP
};
};
public const int LVM_FIRST = 0x1000;
public const int LVM_GETHEADER = LVM_FIRST + 31;
public const int HDM_FIRST = 0x1200;
public const int HDM_GETITEM = HDM_FIRST + 11;
public const int HDM_SETITEM = HDM_FIRST + 12;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref HDITEM lParam);
/// <summary>
/// Dumps the contents of the ListView into a tab separated list of lines
/// </summary>
public static string CopyItemsAsText(this ListView listViewControl)
{
var indexes = listViewControl.SelectedIndices;
if (indexes.Count <= 0)
{
return String.Empty;
}
var sb = new StringBuilder();
// walk over each selected item and subitem within it to generate a string from it
foreach (int index in indexes)
{
foreach (ListViewItem.ListViewSubItem item in listViewControl.Items[index].SubItems)
{
if (!String.IsNullOrWhiteSpace(item.Text))
{
sb.Append(item.Text).Append('\t');
}
}
// remove the last tab
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n");
}
// remove last newline
sb.Length -= 2;
return sb.ToString();
}
public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order)
{
IntPtr columnHeader = SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
for (int columnNumber = 0; columnNumber <= listViewControl.Columns.Count - 1; columnNumber++)
{
var columnPtr = new IntPtr(columnNumber);
var item = new HDITEM
{
mask = HDITEM.Mask.Format
};
if (SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero)
{
throw new Win32Exception();
}
if (order != SortOrder.None && columnNumber == columnIndex)
{
switch (order)
{
case SortOrder.Ascending:
item.fmt &= ~HDITEM.Format.SortDown;
item.fmt |= HDITEM.Format.SortUp;
break;
case SortOrder.Descending:
item.fmt &= ~HDITEM.Format.SortUp;
item.fmt |= HDITEM.Format.SortDown;
break;
}
}
else
{
item.fmt &= ~HDITEM.Format.SortDown & ~HDITEM.Format.SortUp;
}
if (SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero)
{
throw new Win32Exception();
}
}
}
}
}

View File

@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Common.ReflectionExtensions;
namespace BizHawk.Client.EmuHawk.ControlExtensions
namespace BizHawk.Client.EmuHawk.WinFormExtensions
{
public static class ControlExtensions
{
@ -25,5 +28,165 @@ namespace BizHawk.Client.EmuHawk.ControlExtensions
.ToArray());
box.SelectedItem = enumVal.GetDescription();
}
// extension method to make Control.Invoke easier to use
public static void Invoke(this Control control, Action action)
{
control.Invoke(action);
}
}
public static class FormExtensions
{
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this Form form)
{
GlobalWin.Sound.StopSound();
var result = form.ShowDialog();
GlobalWin.Sound.StartSound();
return result;
}
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this CommonDialog form)
{
GlobalWin.Sound.StopSound();
var result = form.ShowDialog();
GlobalWin.Sound.StartSound();
return result;
}
}
public static class ListViewExtensions
{
[StructLayout(LayoutKind.Sequential)]
public struct HDITEM
{
public Mask mask;
public int cxy;
[MarshalAs(UnmanagedType.LPTStr)]
public string pszText;
public IntPtr hbm;
public int cchTextMax;
public Format fmt;
public IntPtr lParam;
// _WIN32_IE >= 0x0300
public int iImage;
public int iOrder;
// _WIN32_IE >= 0x0500
public uint type;
public IntPtr pvFilter;
// _WIN32_WINNT >= 0x0600
public uint state;
[Flags]
public enum Mask
{
Format = 0x4, // HDI_FORMAT
};
[Flags]
public enum Format
{
SortDown = 0x200, // HDF_SORTDOWN
SortUp = 0x400, // HDF_SORTUP
};
};
public const int LVM_FIRST = 0x1000;
public const int LVM_GETHEADER = LVM_FIRST + 31;
public const int HDM_FIRST = 0x1200;
public const int HDM_GETITEM = HDM_FIRST + 11;
public const int HDM_SETITEM = HDM_FIRST + 12;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref HDITEM lParam);
/// <summary>
/// Dumps the contents of the ListView into a tab separated list of lines
/// </summary>
public static string CopyItemsAsText(this ListView listViewControl)
{
var indexes = listViewControl.SelectedIndices;
if (indexes.Count <= 0)
{
return String.Empty;
}
var sb = new StringBuilder();
// walk over each selected item and subitem within it to generate a string from it
foreach (int index in indexes)
{
foreach (ListViewItem.ListViewSubItem item in listViewControl.Items[index].SubItems)
{
if (!String.IsNullOrWhiteSpace(item.Text))
{
sb.Append(item.Text).Append('\t');
}
}
// remove the last tab
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n");
}
// remove last newline
sb.Length -= 2;
return sb.ToString();
}
public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order)
{
IntPtr columnHeader = SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
for (int columnNumber = 0; columnNumber <= listViewControl.Columns.Count - 1; columnNumber++)
{
var columnPtr = new IntPtr(columnNumber);
var item = new HDITEM
{
mask = HDITEM.Mask.Format
};
if (SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero)
{
throw new Win32Exception();
}
if (order != SortOrder.None && columnNumber == columnIndex)
{
switch (order)
{
case SortOrder.Ascending:
item.fmt &= ~HDITEM.Format.SortDown;
item.fmt |= HDITEM.Format.SortUp;
break;
case SortOrder.Descending:
item.fmt &= ~HDITEM.Format.SortUp;
item.fmt |= HDITEM.Format.SortDown;
break;
}
}
else
{
item.fmt &= ~HDITEM.Format.SortDown & ~HDITEM.Format.SortUp;
}
if (SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero)
{
throw new Win32Exception();
}
}
}
}
}

View File

@ -17,6 +17,7 @@ using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.config.NES;
using BizHawk.Client.EmuHawk.CustomControls;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -33,6 +33,8 @@ using BizHawk.Emulation.Cores.Sony.PSP;
using BizHawk.Emulation.DiscSystem;
using BizHawk.Emulation.Cores.Nintendo.N64;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{
public partial class MainForm : Form

View File

@ -11,6 +11,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
//notes: eventually, we intend to have a "firmware acquisition interface" exposed to the emulator cores.
//it will be implemented by emuhawk, and use firmware keys to fetch the firmware content.

View File

@ -1,6 +1,8 @@
using System;
using System.Windows.Forms;
using BizHawk.Client.EmuHawk.WinFormExtensions;
//todo - display details on the current resolution status
//todo - check(mark) the one thats selected
//todo - turn top info into textboxes i guess, labels suck

View File

@ -7,6 +7,7 @@ using System.Drawing;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -8,7 +8,7 @@ using BizHawk.Common.StringExtensions;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Cores.Nintendo.N64;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.ControlExtensions;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using System.IO;
using System.Security.Cryptography;

View File

@ -8,7 +8,7 @@ using BizHawk.Common.StringExtensions;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Cores.Nintendo.N64;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.ControlExtensions;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -9,6 +9,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -7,6 +7,8 @@ using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Client.Common.MovieConversionExtensions;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{
public partial class RecordMovie : Form

View File

@ -9,6 +9,8 @@ using System.Windows.Forms;
using System.Threading;
using System.IO;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{
public partial class BatchRun : Form

View File

@ -6,6 +6,7 @@ using System.Windows.Forms;
using BizHawk.Common.NumberExtensions;
using BizHawk.Client.Common;
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -14,6 +14,7 @@ using BizHawk.Common.StringExtensions;
using BizHawk.Common.IOExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -7,9 +7,11 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using LuaInterface;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using LuaInterface;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Drawing.Imaging;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Drawing.Imaging;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Drawing.Imaging;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Drawing.Imaging;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -3,11 +3,13 @@ using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Client.Common.MovieConversionExtensions;
using System.Text;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -6,6 +6,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -7,6 +7,7 @@ using System.Text;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -13,6 +13,8 @@ using BizHawk.Common.StringExtensions;
using BizHawk.Common.NumberExtensions;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{
/// <summary>

View File

@ -8,6 +8,7 @@ using System.Text;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk
{