diff --git a/Results/Forms/ListViewEx.cs b/Results/Forms/ListViewEx.cs new file mode 100644 index 000000000..532dd8cd9 --- /dev/null +++ b/Results/Forms/ListViewEx.cs @@ -0,0 +1,456 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Windows.Forms; +using System.Runtime.InteropServices; + +namespace Results.Forms +{ + /// + /// Event Handler for SubItem events + /// + public delegate void SubItemEventHandler(object sender, SubItemEventArgs e); + /// + /// Event Handler for SubItemEndEditing events + /// + public delegate void SubItemEndEditingEventHandler(object sender, SubItemEndEditingEventArgs e); + + + /// + /// Inherited ListView to allow in-place editing of subitems + /// + public class ListViewEx : System.Windows.Forms.ListView + { + #region Interop structs, imports and constants + /// + /// MessageHeader for WM_NOTIFY + /// + private struct NMHDR + { +#pragma warning disable + public IntPtr hwndFrom; + public Int32 idFrom; + public Int32 code; +#pragma warning restore + } + + + [DllImport("user32.dll")] + private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wPar, IntPtr lPar); + [DllImport("user32.dll", CharSet=CharSet.Ansi)] + private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int len, ref int [] order); + + // ListView messages + private const int LVM_FIRST = 0x1000; + private const int LVM_GETCOLUMNORDERARRAY = (LVM_FIRST + 59); + + // Windows Messages that will abort editing + private const int WM_HSCROLL = 0x114; + private const int WM_VSCROLL = 0x115; + private const int WM_SIZE = 0x05; + private const int WM_NOTIFY = 0x4E; + + private const int HDN_FIRST = -300; + private const int HDN_BEGINDRAG = (HDN_FIRST-10); + private const int HDN_ITEMCHANGINGA = (HDN_FIRST-0); + private const int HDN_ITEMCHANGINGW = (HDN_FIRST-20); + #endregion + + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public event SubItemEventHandler SubItemClicked; + public event SubItemEventHandler SubItemBeginEditing; + public event SubItemEndEditingEventHandler SubItemEndEditing; + + public ListViewEx() + { + // This call is required by the Windows.Forms Form Designer. + InitializeComponent(); + + base.FullRowSelect = true; + base.View = View.Details; + base.AllowColumnReorder = true; + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if( components != null ) + components.Dispose(); + } + base.Dispose( disposing ); + } + + #region Component Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + #endregion + + private bool _doubleClickActivation = false; + /// + /// Is a double click required to start editing a cell? + /// + public bool DoubleClickActivation + { + get { return _doubleClickActivation; } + set { _doubleClickActivation = value; } + } + + + /// + /// Retrieve the order in which columns appear + /// + /// Current display order of column indices + public int[] GetColumnOrder() + { + IntPtr lPar = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * Columns.Count); + + IntPtr res = SendMessage(Handle, LVM_GETCOLUMNORDERARRAY, new IntPtr(Columns.Count), lPar); + if (res.ToInt32() == 0) // Something went wrong + { + Marshal.FreeHGlobal(lPar); + return null; + } + + int [] order = new int[Columns.Count]; + Marshal.Copy(lPar, order, 0, Columns.Count); + + Marshal.FreeHGlobal(lPar); + + return order; + } + + + /// + /// Find ListViewItem and SubItem Index at position (x,y) + /// + /// relative to ListView + /// relative to ListView + /// Item at position (x,y) + /// SubItem index + public int GetSubItemAt(int x, int y, out ListViewItem item) + { + item = this.GetItemAt(x, y); + + if (item != null) + { + int[] order = GetColumnOrder(); + Rectangle lviBounds; + int subItemX; + + lviBounds = item.GetBounds(ItemBoundsPortion.Entire); + subItemX = lviBounds.Left; + for (int i=0; i + /// Get bounds for a SubItem + /// + /// Target ListViewItem + /// Target SubItem index + /// Bounds of SubItem (relative to ListView) + public Rectangle GetSubItemBounds(ListViewItem Item, int SubItem) + { + int[] order = GetColumnOrder(); + + Rectangle subItemRect = Rectangle.Empty; + if (SubItem >= order.Length) + throw new IndexOutOfRangeException("SubItem "+SubItem+" out of range"); + + if (Item == null) + throw new ArgumentNullException("Item"); + + Rectangle lviBounds = Item.GetBounds(ItemBoundsPortion.Entire); + int subItemX = lviBounds.Left; + + ColumnHeader col; + int i; + for (i=0; i + /// Fire SubItemClicked + /// + ///Point of click/doubleclick + private void EditSubitemAt(Point p) + { + ListViewItem item; + int idx = GetSubItemAt(p.X, p.Y, out item); + if (idx >= 0) + { + OnSubItemClicked(new SubItemEventArgs(item, idx)); + } + } + + #endregion + + #region In-place editing functions + // The control performing the actual editing + private Control _editingControl; + // The LVI being edited + private ListViewItem _editItem; + // The SubItem being edited + private int _editSubItem; + + protected void OnSubItemBeginEditing(SubItemEventArgs e) + { + if (SubItemBeginEditing != null) SubItemBeginEditing(this, e); + } + + protected void OnSubItemEndEditing(SubItemEndEditingEventArgs e) + { + if (SubItemEndEditing != null) SubItemEndEditing(this, e); + } + + protected void OnSubItemClicked(SubItemEventArgs e) + { + if (SubItemClicked != null) SubItemClicked(this, e); + } + + + /// + /// Begin in-place editing of given cell + /// + /// Control used as cell editor + /// ListViewItem to edit + /// SubItem index to edit + public void StartEditing(Control c, ListViewItem Item, int SubItem) + { + OnSubItemBeginEditing(new SubItemEventArgs(Item, SubItem)); + + Rectangle rcSubItem = GetSubItemBounds(Item, SubItem); + + if (rcSubItem.X < 0) + { + // Left edge of SubItem not visible - adjust rectangle position and width + rcSubItem.Width += rcSubItem.X; + rcSubItem.X=0; + } + if (rcSubItem.X+rcSubItem.Width > this.Width) + { + // Right edge of SubItem not visible - adjust rectangle width + rcSubItem.Width = this.Width-rcSubItem.Left; + } + + // Subitem bounds are relative to the location of the ListView! + rcSubItem.Offset(Left, Top); + + // In case the editing control and the listview are on different parents, + // account for different origins + Point origin = new Point(0,0); + Point lvOrigin = this.Parent.PointToScreen(origin); + Point ctlOrigin = c.Parent.PointToScreen(origin); + + rcSubItem.Offset(lvOrigin.X-ctlOrigin.X, lvOrigin.Y-ctlOrigin.Y); + + // Position and show editor + c.Bounds = rcSubItem; + c.Text = Item.SubItems[SubItem].Text; + c.Visible = true; + c.BringToFront(); + c.Focus(); + + _editingControl = c; + _editingControl.Leave += new EventHandler(_editControl_Leave); + _editingControl.KeyPress += new KeyPressEventHandler(_editControl_KeyPress); + + _editItem = Item; + _editSubItem = SubItem; + } + + + private void _editControl_Leave(object sender, EventArgs e) + { + // cell editor losing focus + EndEditing(true); + } + + private void _editControl_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) + { + switch (e.KeyChar) + { + case (char)(int)Keys.Escape: + { + EndEditing(false); + break; + } + + case (char)(int)Keys.Enter: + { + EndEditing(true); + break; + } + } + } + + /// + /// Accept or discard current value of cell editor control + /// + /// Use the _editingControl's Text as new SubItem text or discard changes? + public void EndEditing(bool AcceptChanges) + { + if (_editingControl == null) + return; + + SubItemEndEditingEventArgs e = new SubItemEndEditingEventArgs( + _editItem, // The item being edited + _editSubItem, // The subitem index being edited + AcceptChanges ? + _editingControl.Text : // Use editControl text if changes are accepted + _editItem.SubItems[_editSubItem].Text, // or the original subitem's text, if changes are discarded + !AcceptChanges // Cancel? + ); + + OnSubItemEndEditing(e); + + _editItem.SubItems[_editSubItem].Text = e.DisplayText; + + _editingControl.Leave -= new EventHandler(_editControl_Leave); + _editingControl.KeyPress -= new KeyPressEventHandler(_editControl_KeyPress); + + _editingControl.Visible = false; + + _editingControl = null; + _editItem = null; + _editSubItem = -1; + } + #endregion + } + + + /// + /// Event Args for SubItemClicked event + /// + public class SubItemEventArgs : EventArgs + { + int subItem = -1; /// Sub-item index + ListViewItem item = null; + + public int SubItem { get { return subItem; } } + public ListViewItem Item { get { return item; } } + + public SubItemEventArgs(ListViewItem item, int subItem) + { + this.subItem = subItem; + this.item = item; + } + } + + + /// + /// Event Args for SubItemEndEditingClicked event + /// + public class SubItemEndEditingEventArgs : SubItemEventArgs + { + string displayText = string.Empty; + bool cancel = true; + + public SubItemEndEditingEventArgs(ListViewItem item, int subItem, string displayText, bool cancel) : + base(item, subItem) + { + this.displayText = displayText; + this.cancel = cancel; + } + public string DisplayText + { + get { return displayText; } + set { displayText = value; } + } + public bool Cancel + { + get { return cancel; } + set { cancel = value; } + } + } +} diff --git a/Results/Forms/ListViewEx.resx b/Results/Forms/ListViewEx.resx new file mode 100644 index 000000000..7e323966c --- /dev/null +++ b/Results/Forms/ListViewEx.resx @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.0.0.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + diff --git a/TestBenchFramework/BenchControl/Output/FileWriters/Basic/ResultsConfigDlg.cs b/Results/Forms/ResultsConfigDlg.cs similarity index 94% rename from TestBenchFramework/BenchControl/Output/FileWriters/Basic/ResultsConfigDlg.cs rename to Results/Forms/ResultsConfigDlg.cs index b0b761ae4..418ed2a85 100644 --- a/TestBenchFramework/BenchControl/Output/FileWriters/Basic/ResultsConfigDlg.cs +++ b/Results/Forms/ResultsConfigDlg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2016 Sensus Metering Systems +/// Copyright (c) 2016 Sensus Metering Systems /// using System; using System.Collections.Generic; @@ -7,10 +7,9 @@ using System.Windows.Forms; using log4net; using Config.Entities; using Results; -using TBF.Resources; -using TBF.UiControls; +using Results.Resources; -namespace TBF.BenchControl.Output.FileWriters.Basic +namespace Results.Forms { public partial class ResultsConfigDlg : Form { @@ -32,8 +31,8 @@ namespace TBF.BenchControl.Output.FileWriters.Basic Control[] editors; - public IList AvailableItems; - public IList SelectedItems; + public IList AvailableItems; + public IList SelectedItems; public bool Compound; /// false = single meter items, true = combined meter items @@ -116,7 +115,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic void selectedResultsListViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e) { ListViewItem lvi = e.Item; - Results.WMeterRsltItemSpec item = lvi.Tag as Results.WMeterRsltItemSpec; + WMeterRsltItemSpec item = lvi.Tag as WMeterRsltItemSpec; switch ((Column)e.SubItem) { @@ -173,8 +172,8 @@ namespace TBF.BenchControl.Output.FileWriters.Basic void RedrawAvailable() { availableResultsListBox.Items.Clear(); - AvailableItems = new List(); - foreach (var item in Results.WMeterRsltItemSpec.AllItems) + AvailableItems = new List(); + foreach (var item in WMeterRsltItemSpec.AllItems) { AvailableItems.Add(item); availableResultsListBox.Items.Add(item.Name); @@ -300,7 +299,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic return; } - Results.WMeterRsltItemSpec tmp = SelectedItems[selIdx - 1]; + WMeterRsltItemSpec tmp = SelectedItems[selIdx - 1]; SelectedItems[selIdx - 1] = SelectedItems[selIdx]; SelectedItems[selIdx] = tmp; @@ -324,7 +323,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic return; } - Results.WMeterRsltItemSpec tmp = SelectedItems[selIdx + 1]; + WMeterRsltItemSpec tmp = SelectedItems[selIdx + 1]; SelectedItems[selIdx + 1] = SelectedItems[selIdx]; SelectedItems[selIdx] = tmp; diff --git a/TestBenchFramework/BenchControl/Output/FileWriters/Basic/ResultsConfigDlg.designer.cs b/Results/Forms/ResultsConfigDlg.designer.cs similarity index 95% rename from TestBenchFramework/BenchControl/Output/FileWriters/Basic/ResultsConfigDlg.designer.cs rename to Results/Forms/ResultsConfigDlg.designer.cs index b033f3a7f..cabe108dd 100644 --- a/TestBenchFramework/BenchControl/Output/FileWriters/Basic/ResultsConfigDlg.designer.cs +++ b/Results/Forms/ResultsConfigDlg.designer.cs @@ -1,7 +1,7 @@ /// -/// Copyright (c) 2013-2016 Sensus Metering Systems +/// Copyright (c) 2016 Sensus Metering Systems /// -namespace TBF.BenchControl.Output.FileWriters.Basic +namespace Results.Forms { partial class ResultsConfigDlg { @@ -39,7 +39,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic this.removeAllButton = new System.Windows.Forms.Button(); this.removeButton = new System.Windows.Forms.Button(); this.addButton = new System.Windows.Forms.Button(); - this.selectedResultsListViewEx = new TBF.UiControls.ListViewEx(); + this.selectedResultsListViewEx = new ListViewEx(); this.upButton = new System.Windows.Forms.Button(); this.downButton = new System.Windows.Forms.Button(); this.SuspendLayout(); @@ -132,8 +132,8 @@ namespace TBF.BenchControl.Output.FileWriters.Basic this.selectedResultsListViewEx.TabIndex = 47; this.selectedResultsListViewEx.UseCompatibleStateImageBehavior = false; this.selectedResultsListViewEx.View = System.Windows.Forms.View.Details; - this.selectedResultsListViewEx.SubItemClicked += new TBF.UiControls.SubItemEventHandler(this.selectedResultsListViewEx_SubItemClicked); - this.selectedResultsListViewEx.SubItemEndEditing += new TBF.UiControls.SubItemEndEditingEventHandler(this.selectedResultsListViewEx_SubItemEndEditing); + this.selectedResultsListViewEx.SubItemClicked += new SubItemEventHandler(this.selectedResultsListViewEx_SubItemClicked); + this.selectedResultsListViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(this.selectedResultsListViewEx_SubItemEndEditing); // // upButton // @@ -195,7 +195,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic private System.Windows.Forms.Button removeAllButton; private System.Windows.Forms.Button removeButton; private System.Windows.Forms.Button addButton; - private UiControls.ListViewEx selectedResultsListViewEx; + private ListViewEx selectedResultsListViewEx; private System.Windows.Forms.Button upButton; private System.Windows.Forms.Button downButton; } diff --git a/TestBenchFramework/BenchControl/Output/FileWriters/Basic/ResultsConfigDlg.resx b/Results/Forms/ResultsConfigDlg.resx similarity index 100% rename from TestBenchFramework/BenchControl/Output/FileWriters/Basic/ResultsConfigDlg.resx rename to Results/Forms/ResultsConfigDlg.resx diff --git a/Results/Resources/Strings.Designer.cs b/Results/Resources/Strings.Designer.cs new file mode 100644 index 000000000..81e369e67 --- /dev/null +++ b/Results/Resources/Strings.Designer.cs @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Results.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Strings { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Strings() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Results.Resources.Strings", typeof(Strings).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Add >. + /// + internal static string Add { + get { + return ResourceManager.GetString("Add", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Available results. + /// + internal static string Available_results { + get { + return ResourceManager.GetString("Available_results", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cancel. + /// + internal static string CancelBtnText { + get { + return ResourceManager.GetString("CancelBtnText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Configuration. + /// + internal static string Configuration { + get { + return ResourceManager.GetString("Configuration", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Down. + /// + internal static string DownBtnText { + get { + return ResourceManager.GetString("DownBtnText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to OK. + /// + internal static string OkBtnText { + get { + return ResourceManager.GetString("OkBtnText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to < Remove. + /// + internal static string Remove { + get { + return ResourceManager.GetString("Remove", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Remove all. + /// + internal static string Remove_all { + get { + return ResourceManager.GetString("Remove_all", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Selected results. + /// + internal static string Selected_results { + get { + return ResourceManager.GetString("Selected_results", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Up. + /// + internal static string UpBtnText { + get { + return ResourceManager.GetString("UpBtnText", resourceCulture); + } + } + } +} diff --git a/Results/Resources/Strings.cs.resx b/Results/Resources/Strings.cs.resx new file mode 100644 index 000000000..6610ef484 --- /dev/null +++ b/Results/Resources/Strings.cs.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Přidat > + + + Dostupné výsledky + + + Zrušit + + + Konfigurace + + + Dolů + + + OK + + + < Odebrat + + + Odebrat vše + + + Vybrané výsledky + + + Nahoru + + \ No newline at end of file diff --git a/Results/Resources/Strings.de.resx b/Results/Resources/Strings.de.resx new file mode 100644 index 000000000..a0e9fe515 --- /dev/null +++ b/Results/Resources/Strings.de.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hinzufügen > + + + Ergebnisse + + + Abbrechen + + + Konfiguration + + + Abwärts + + + OK + + + < Entfernen + + + Alles entfernen + + + Ergebnisse ausgewählt + + + Aufwärts + + \ No newline at end of file diff --git a/Results/Resources/Strings.resx b/Results/Resources/Strings.resx new file mode 100644 index 000000000..e418ff31b --- /dev/null +++ b/Results/Resources/Strings.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Add > + + + Available results + + + Cancel + + + Configuration + + + Down + + + OK + + + < Remove + + + Remove all + + + Selected results + + + Up + + \ No newline at end of file diff --git a/Results/Results.csproj b/Results/Results.csproj index 3b48b771a..df79a4054 100644 --- a/Results/Results.csproj +++ b/Results/Results.csproj @@ -49,6 +49,8 @@ + + @@ -65,6 +67,15 @@ + + Component + + + Form + + + ResultsConfigDlg.cs + @@ -74,6 +85,11 @@ + + True + True + Strings.resx + @@ -87,6 +103,20 @@ + + + ListViewEx.cs + + + ResultsConfigDlg.cs + + + + + ResXFileCodeGenerator + Strings.Designer.cs + +