diff --git a/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.API.cs b/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.API.cs index 94fd8cf87a..af741013fc 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.API.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.API.cs @@ -163,6 +163,16 @@ namespace BizHawk.Client.EmuHawk } } + /// + /// Compatibility method from VirtualListView + /// + /// + public void ensureVisible() + { + if (_selectedItems.Count != 0) + MakeIndexVisible(_selectedItems.Last().RowIndex.Value); + } + public void ClearSelectedRows() { _selectedItems.Clear(); diff --git a/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.Drawing.cs b/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.Drawing.cs index 91c2b624eb..96f0b1dd83 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.Drawing.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.Drawing.cs @@ -75,14 +75,18 @@ namespace BizHawk.Client.EmuHawk if (BorderSize > 0) { - // paint parent border - using (var gParent = this.Parent.CreateGraphics()) + // apparently mono can sometimes call OnPaint before attached to the parent?? + if (this.Parent != null) { - Pen borderPen = new Pen(BorderColor); - for (int b = 1, c = 1; b <= BorderSize; b++, c += 2) + // paint parent border + using (var gParent = this.Parent.CreateGraphics()) { - gParent.DrawRectangle(borderPen, this.Left - b, this.Top - b, this.Width + c, this.Height + c); - } + Pen borderPen = new Pen(BorderColor); + for (int b = 1, c = 1; b <= BorderSize; b++, c += 2) + { + gParent.DrawRectangle(borderPen, this.Left - b, this.Top - b, this.Width + c, this.Height + c); + } + } } } } @@ -99,7 +103,8 @@ namespace BizHawk.Client.EmuHawk QueryItemTextAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, out text, ref offsetX, ref offsetY); Color bgColor = ColumnHeaderBackgroundColor; - QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor); + QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _columns.IndexOf(_draggingCell.Column), ref bgColor); + QueryItemBkColorAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor); int x1 = _currentX.Value - (_draggingCell.Column.Width.Value / 2); int y1 = _currentY.Value - (CellHeight / 2); @@ -124,7 +129,8 @@ namespace BizHawk.Client.EmuHawk QueryItemTextAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, out text, ref offsetX, ref offsetY); Color bgColor = CellBackgroundColor; - QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor); + QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _columns.IndexOf(_draggingCell.Column), ref bgColor); + QueryItemBkColorAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor); int x1 = _currentX.Value - (_draggingCell.Column.Width.Value / 2); int y1 = _currentY.Value - (CellHeight / 2); @@ -144,7 +150,7 @@ namespace BizHawk.Client.EmuHawk foreach (var column in visibleColumns) { - var point = new Point(column.Left.Value + 2 * CellWidthPadding - _hBar.Value, CellHeightPadding); // TODO: fix this CellPadding issue (2 * CellPadding vs just CellPadding) + var point = new Point(column.Left.Value + CellWidthPadding - _hBar.Value, CellHeightPadding); string t = column.Text; ResizeTextToFit(ref t, column.Width.Value, ColumnHeaderFont); @@ -448,7 +454,8 @@ namespace BizHawk.Client.EmuHawk } Color cellColor = rowColor; - QueryItemBkColor?.Invoke(cell.RowIndex.Value, cell.Column, ref cellColor); + QueryItemBkColor?.Invoke(cell.RowIndex.Value, _columns.IndexOf(cell.Column), ref cellColor); + QueryItemBkColorAdvanced?.Invoke(cell.RowIndex.Value, cell.Column, ref cellColor); // Alpha layering for cell before selection float alpha = (float)cellColor.A / 255; @@ -494,7 +501,8 @@ namespace BizHawk.Client.EmuHawk for (int j = FirstVisibleColumn; j <= lastVisible; j++) // Horizontal { Color itemColor = CellBackgroundColor; - QueryItemBkColor(f + startIndex, visibleColumns[j], ref itemColor); + QueryItemBkColor?.Invoke(f + startIndex, _columns.IndexOf(visibleColumns[j]), ref itemColor); + QueryItemBkColorAdvanced?.Invoke(f + startIndex, visibleColumns[j], ref itemColor); if (itemColor == CellBackgroundColor) { itemColor = rowColor; diff --git a/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.EventHandlers.cs b/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.EventHandlers.cs index e000f2f41c..6bfa01ccb2 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.EventHandlers.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.EventHandlers.cs @@ -36,6 +36,12 @@ namespace BizHawk.Client.EmuHawk [Category("Virtual")] public event QueryItemBkColorHandler QueryItemBkColor; + /// + /// Fire the event which requests the background color for the passed cell + /// + [Category("Virtual")] + public event QueryItemBkColorHandlerAdvanced QueryItemBkColorAdvanced; + [Category("Virtual")] public event QueryRowBkColorHandler QueryRowBkColor; @@ -110,7 +116,8 @@ namespace BizHawk.Client.EmuHawk /// /// Retrieve the background color for a cell /// - public delegate void QueryItemBkColorHandler(int index, ListColumn column, ref Color color); + public delegate void QueryItemBkColorHandlerAdvanced(int index, ListColumn column, ref Color color); + public delegate void QueryItemBkColorHandler(int index, int column, ref Color color); public delegate void QueryRowBkColorHandler(int index, ref Color color); /// diff --git a/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.cs b/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.cs index b3b7383069..0c1d138ef1 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/PlatformAgnosticVirtualListView.cs @@ -34,13 +34,13 @@ namespace BizHawk.Client.EmuHawk public PlatformAgnosticVirtualListView() { - ColumnHeaderFont = new Font("Arial", 8, FontStyle.Bold); + ColumnHeaderFont = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Bold, GraphicsUnit.Point); ColumnHeaderFontColor = Color.Black; ColumnHeaderBackgroundColor = Color.LightGray; ColumnHeaderBackgroundHighlightColor = SystemColors.HighlightText; ColumnHeaderOutlineColor = Color.Black; - CellFont = new Font("Arial", 8, FontStyle.Regular); + CellFont = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point); CellFontColor = Color.Black; CellBackgroundColor = Color.White; CellBackgroundHighlightColor = Color.Blue; diff --git a/BizHawk.Client.EmuHawk/tools/ToolHelpers.cs b/BizHawk.Client.EmuHawk/tools/ToolHelpers.cs index 870c8da835..43f0147c6b 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolHelpers.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolHelpers.cs @@ -119,6 +119,21 @@ namespace BizHawk.Client.EmuHawk } } + protected void LoadColumnInfo(PlatformAgnosticVirtualListView listView, ToolDialogSettings.ColumnList columns) + { + listView.AllColumns.Clear(); + + var cl = columns + .Where(c => c.Visible) + .OrderBy(c => c.Index); + + foreach (var column in cl) + { + string colText = column.Name.Replace("Column", ""); + listView.AddColumn(column.Name, colText, column.Width, PlatformAgnosticVirtualListView.ListColumn.InputType.Text); + } + } + protected void SaveColumnInfo(VirtualListView listview, ToolDialogSettings.ColumnList columns) { foreach (ColumnHeader column in listview.Columns) @@ -128,6 +143,15 @@ namespace BizHawk.Client.EmuHawk } } + protected void SaveColumnInfo(PlatformAgnosticVirtualListView listview, ToolDialogSettings.ColumnList columns) + { + foreach (var column in listview.AllColumns) + { + columns[column.Name].Index = listview.AllColumns.IndexOf(column); + columns[column.Name].Width = column.Width.Value; + } + } + protected void RefreshFloatingWindowControl(bool floatingWindow) { Owner = floatingWindow ? null : GlobalWin.MainForm; diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.Designer.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.Designer.cs index b126c12fe1..bd99f5a605 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.Designer.cs @@ -32,7 +32,7 @@ System.Windows.Forms.ToolStripMenuItem SearchMenuItem; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RamSearch)); this.TotalSearchLabel = new System.Windows.Forms.Label(); - this.WatchListView = new BizHawk.Client.EmuHawk.VirtualListView(); + this.WatchListView = new BizHawk.Client.EmuHawk.PlatformAgnosticVirtualListView(); this.AddressColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ValueColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.PreviousColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); @@ -211,13 +211,10 @@ this.WatchListView.UseCustomBackground = true; this.WatchListView.View = System.Windows.Forms.View.Details; this.WatchListView.VirtualMode = true; - this.WatchListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.WatchListView_ColumnClick); this.WatchListView.SelectedIndexChanged += new System.EventHandler(this.WatchListView_SelectedIndexChanged); - this.WatchListView.VirtualItemsSelectionRangeChanged += new System.Windows.Forms.ListViewVirtualItemsSelectionRangeChangedEventHandler(this.WatchListView_VirtualItemsSelectionRangeChanged); this.WatchListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewRamSearch_DragDrop); this.WatchListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.DragEnterWrapper); this.WatchListView.Enter += new System.EventHandler(this.WatchListView_Enter); - this.WatchListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.WatchListView_KeyDown); this.WatchListView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.WatchListView_MouseDoubleClick); // // AddressColumn @@ -1422,7 +1419,7 @@ #endregion private System.Windows.Forms.Label TotalSearchLabel; - VirtualListView WatchListView; + BizHawk.Client.EmuHawk.PlatformAgnosticVirtualListView WatchListView; private System.Windows.Forms.ColumnHeader AddressColumn; private System.Windows.Forms.ColumnHeader ValueColumn; private System.Windows.Forms.ColumnHeader PreviousColumn; diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 10684faf1a..476e1113b4 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -51,9 +51,9 @@ namespace BizHawk.Client.EmuHawk SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); InitializeComponent(); - WatchListView.QueryItemText += ListView_QueryItemText; - WatchListView.QueryItemBkColor += ListView_QueryItemBkColor; - WatchListView.VirtualMode = true; + + SetupListViewSettings(); + Closing += (o, e) => SaveConfigSettings(); _sortedColumn = ""; @@ -62,6 +62,32 @@ namespace BizHawk.Client.EmuHawk Settings = new RamSearchSettings(); } + private void SetupListViewSettings() + { + WatchListView.BorderColor = System.Drawing.Color.Black; + WatchListView.BorderSize = 1; + WatchListView.MultiSelect = true; + WatchListView.CellWidthPadding = 2; + WatchListView.CellHeightPadding = 1; + WatchListView.ScrollSpeed = 3; + WatchListView.AllowColumnResize = true; + WatchListView.AllowColumnReorder = true; + WatchListView.ColumnHeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 7.7F); + WatchListView.ColumnHeaderFontColor = System.Drawing.Color.Black; + WatchListView.ColumnHeaderBackgroundColor = System.Drawing.Color.White; + WatchListView.ColumnHeaderBackgroundHighlightColor = System.Drawing.Color.LightSteelBlue; + WatchListView.ColumnHeaderOutlineColor = System.Drawing.Color.LightGray; + WatchListView.CellFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point); + WatchListView.CellFontColor = System.Drawing.Color.Black; + WatchListView.CellBackgroundColor = System.Drawing.Color.White; + + WatchListView.QueryItemText += ListView_QueryItemText; + WatchListView.QueryItemBkColor += ListView_QueryItemBkColor; + WatchListView.ColumnClick += WatchListView_ColumnClick; + WatchListView.KeyDown += WatchListView_KeyDown; + WatchListView.VirtualMode = true; + } + [RequiredService] public IMemoryDomains MemoryDomains { get; set; } @@ -163,33 +189,30 @@ namespace BizHawk.Client.EmuHawk private void ListView_QueryItemBkColor(int index, int column, ref Color color) { - if (column == 0) + if (_searches.Count > 0) { - if (_searches.Count > 0 && column == 0) + var nextColor = Color.White; + + var isCheat = Global.CheatList.IsActive(_settings.Domain, _searches[index].Address); + var isWeeded = Settings.PreviewMode && !_forcePreviewClear && _searches.Preview(_searches[index].Address); + + if (_searches[index].Address >= _searches[index].Domain.Size) { - var nextColor = Color.White; - - var isCheat = Global.CheatList.IsActive(_settings.Domain, _searches[index].Address); - var isWeeded = Settings.PreviewMode && !_forcePreviewClear && _searches.Preview(_searches[index].Address); - - if (_searches[index].Address >= _searches[index].Domain.Size) - { - nextColor = Color.PeachPuff; - } - else if (isCheat) - { - nextColor = isWeeded ? Color.Lavender : Color.LightCyan; - } - else - { - if (isWeeded) - { - nextColor = Color.Pink; - } - } - - color = nextColor; + nextColor = Color.PeachPuff; } + else if (isCheat) + { + nextColor = isWeeded ? Color.Lavender : Color.LightCyan; + } + else + { + if (isWeeded) + { + nextColor = Color.Pink; + } + } + + color = nextColor; } } @@ -202,7 +225,7 @@ namespace BizHawk.Client.EmuHawk return; } - var columnName = WatchListView.Columns[column].Name; + var columnName = WatchListView.AllColumns[column].Name; switch (columnName) { case WatchList.ADDRESS: @@ -551,7 +574,7 @@ namespace BizHawk.Client.EmuHawk _forcePreviewClear = true; } - private IEnumerable SelectedIndices => WatchListView.SelectedIndices.Cast(); + private IEnumerable SelectedIndices => WatchListView.SelectedRows; private IEnumerable SelectedItems { @@ -771,7 +794,7 @@ namespace BizHawk.Client.EmuHawk DifferenceRadio.Enabled = true; DifferentByBox.Enabled = true; ClearChangeCountsToolBarItem.Enabled = true; - WatchListView.Columns[WatchList.CHANGES].Width = Settings.Columns[WatchList.CHANGES].Width; + WatchListView.AllColumns[WatchList.CHANGES].Width = Settings.Columns[WatchList.CHANGES].Width; SetReboot(true); } @@ -794,8 +817,8 @@ namespace BizHawk.Client.EmuHawk PreviousValueRadio.Checked = true; } - Settings.Columns[WatchList.CHANGES].Width = WatchListView.Columns[WatchList.CHANGES].Width; - WatchListView.Columns[WatchList.CHANGES].Width = 0; + Settings.Columns[WatchList.CHANGES].Width = WatchListView.AllColumns[WatchList.CHANGES].Width.Value; + WatchListView.AllColumns[WatchList.CHANGES].Width = 0; SetReboot(true); } @@ -808,7 +831,7 @@ namespace BizHawk.Client.EmuHawk _searches.RemoveRange(indices); UpdateList(); - WatchListView.SelectedIndices.Clear(); + WatchListView.ClearSelectedRows(); ToggleSearchDependentToolBarItems(); } } @@ -899,7 +922,7 @@ namespace BizHawk.Client.EmuHawk private void GoToSpecifiedAddress() { - WatchListView.SelectedIndices.Clear(); + WatchListView.ClearSelectedRows(); var prompt = new InputPrompt { Text = "Go to Address", @@ -1708,8 +1731,10 @@ namespace BizHawk.Client.EmuHawk } else if (e.KeyCode == Keys.Escape && !e.Control && !e.Alt && !e.Shift) { - WatchListView.SelectedIndices.Clear(); + WatchListView.ClearSelectedRows(); } + + base.OnKeyDown(e); } private void WatchListView_SelectedIndexChanged(object sender, EventArgs e) @@ -1739,9 +1764,9 @@ namespace BizHawk.Client.EmuHawk WatchListView.Refresh(); } - private void WatchListView_ColumnClick(object sender, ColumnClickEventArgs e) + private void WatchListView_ColumnClick(object sender, PlatformAgnosticVirtualListView.ColumnClickEventArgs e) { - var column = WatchListView.Columns[e.Column]; + var column = WatchListView.AllColumns[WatchListView.AllColumns.IndexOf(e.Column)]; if (column.Name != _sortedColumn) { _sortReverse = false;