Skip to content

Commit e3d7226

Browse files
committed
updated unecessary castings from BufferedDataGridView to DataGridView
1 parent 911eb85 commit e3d7226

10 files changed

Lines changed: 392 additions & 296 deletions

src/LogExpert/Classes/PaintHelper.cs

Lines changed: 85 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ internal class PaintHelper
3232

3333
#region Public methods
3434

35-
public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridView, int rowIndex,
36-
DataGridViewCellPaintingEventArgs e)
35+
public static void CellPainting(ILogPaintContext logPaintCtx, BufferedDataGridView gridView, int rowIndex, DataGridViewCellPaintingEventArgs e)
3736
{
3837
if (rowIndex < 0 || e.ColumnIndex < 0)
3938
{
4039
e.Handled = false;
4140
return;
4241
}
4342
ILogLine line = logPaintCtx.GetLogLine(rowIndex);
43+
4444
if (line != null)
4545
{
4646
HilightEntry entry = logPaintCtx.FindHighlightEntry(line, true);
@@ -49,9 +49,10 @@ public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridV
4949
{
5050
Color backColor = e.CellStyle.SelectionBackColor;
5151
Brush brush;
52+
5253
if (gridView.Focused)
5354
{
54-
brush = new SolidBrush(e.CellStyle.SelectionBackColor);
55+
brush = new SolidBrush(backColor);
5556
}
5657
else
5758
{
@@ -63,7 +64,8 @@ public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridV
6364
}
6465
else
6566
{
66-
Color bgColor = LogExpert.Config.ColorMode.DockBackgroundColor;
67+
Color bgColor = ColorMode.DockBackgroundColor;
68+
6769
if (!DebugOptions.disableWordHighlight)
6870
{
6971
if (entry != null)
@@ -78,6 +80,7 @@ public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridV
7880
bgColor = entry.BackgroundColor;
7981
}
8082
}
83+
8184
e.CellStyle.BackColor = bgColor;
8285
e.PaintBackground(e.ClipBounds, false);
8386
}
@@ -94,6 +97,7 @@ public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridV
9497
if (e.ColumnIndex == 0)
9598
{
9699
Entities.Bookmark bookmark = logPaintCtx.GetBookmarkForLine(rowIndex);
100+
97101
if (bookmark != null)
98102
{
99103
Rectangle r; // = new Rectangle(e.CellBounds.Left + 2, e.CellBounds.Top + 2, 6, 6);
@@ -102,11 +106,15 @@ public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridV
102106
Brush brush = new SolidBrush(logPaintCtx.BookmarkColor);
103107
e.Graphics.FillRectangle(brush, r);
104108
brush.Dispose();
109+
105110
if (bookmark.Text.Length > 0)
106111
{
107-
StringFormat format = new();
108-
format.LineAlignment = StringAlignment.Center;
109-
format.Alignment = StringAlignment.Center;
112+
StringFormat format = new()
113+
{
114+
LineAlignment = StringAlignment.Center,
115+
Alignment = StringAlignment.Center
116+
};
117+
110118
Brush brush2 = new SolidBrush(Color.FromArgb(255, 190, 100, 0));
111119
Font font = logPaintCtx.MonospacedFont;
112120
e.Graphics.DrawString("i", font, brush2, new RectangleF(r.Left, r.Top, r.Width, r.Height),
@@ -124,43 +132,49 @@ public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridV
124132

125133
public static DataGridViewTextBoxColumn CreateMarkerColumn()
126134
{
127-
DataGridViewTextBoxColumn markerColumn = new();
128-
markerColumn.HeaderText = "";
129-
markerColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
130-
markerColumn.Resizable = DataGridViewTriState.False;
131-
markerColumn.DividerWidth = 1;
132-
markerColumn.ReadOnly = true;
133-
markerColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
135+
DataGridViewTextBoxColumn markerColumn = new()
136+
{
137+
HeaderText = "",
138+
AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet,
139+
Resizable = DataGridViewTriState.False,
140+
DividerWidth = 1,
141+
ReadOnly = true,
142+
SortMode = DataGridViewColumnSortMode.NotSortable
143+
};
134144

135145
return markerColumn;
136146
}
137147

138148
public static DataGridViewTextBoxColumn CreateLineNumberColumn()
139149
{
140-
DataGridViewTextBoxColumn lineNumberColumn = new();
141-
lineNumberColumn.HeaderText = "Line";
142-
lineNumberColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
143-
lineNumberColumn.Resizable = DataGridViewTriState.NotSet;
144-
lineNumberColumn.DividerWidth = 1;
145-
lineNumberColumn.ReadOnly = true;
146-
lineNumberColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
150+
DataGridViewTextBoxColumn lineNumberColumn = new()
151+
{
152+
HeaderText = "Line",
153+
AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet,
154+
Resizable = DataGridViewTriState.NotSet,
155+
DividerWidth = 1,
156+
ReadOnly = true,
157+
SortMode = DataGridViewColumnSortMode.NotSortable
158+
};
147159

148160
return lineNumberColumn;
149161
}
150162

151163
public static DataGridViewColumn CreateTitleColumn(string colName)
152164
{
153-
DataGridViewColumn titleColumn = new LogTextColumn();
154-
titleColumn.HeaderText = colName;
155-
titleColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
156-
titleColumn.Resizable = DataGridViewTriState.NotSet;
157-
titleColumn.DividerWidth = 1;
158-
titleColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
165+
DataGridViewColumn titleColumn = new LogTextColumn
166+
{
167+
HeaderText = colName,
168+
AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet,
169+
Resizable = DataGridViewTriState.NotSet,
170+
DividerWidth = 1,
171+
SortMode = DataGridViewColumnSortMode.NotSortable
172+
};
159173

160174
return titleColumn;
161175
}
162176

163-
public static void SetColumnizer(ILogLineColumnizer columnizer, DataGridView gridView)
177+
public static void SetColumnizer(ILogLineColumnizer columnizer, BufferedDataGridView gridView)
164178
{
165179
int rowCount = gridView.RowCount;
166180
int currLine = gridView.CurrentCellAddress.Y;
@@ -199,7 +213,7 @@ public static void SetColumnizer(ILogLineColumnizer columnizer, DataGridView gri
199213
//AutoResizeColumns(gridView);
200214
}
201215

202-
public static void AutoResizeColumns(DataGridView gridView)
216+
public static void AutoResizeColumns(BufferedDataGridView gridView)
203217
{
204218
try
205219
{
@@ -223,7 +237,7 @@ public static void AutoResizeColumns(DataGridView gridView)
223237
}
224238
}
225239

226-
public static void ApplyDataGridViewPrefs(DataGridView dataGridView, Preferences prefs)
240+
public static void ApplyDataGridViewPrefs(BufferedDataGridView dataGridView, Preferences prefs)
227241
{
228242
if (dataGridView.Columns.Count > 1)
229243
{
@@ -250,30 +264,43 @@ public static void ApplyDataGridViewPrefs(DataGridView dataGridView, Preferences
250264

251265
public static Rectangle BorderWidths(DataGridViewAdvancedBorderStyle advancedBorderStyle)
252266
{
253-
Rectangle rect = new();
267+
Rectangle rect = new()
268+
{
269+
X = advancedBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.None
270+
? 0
271+
: 1
272+
};
254273

255-
rect.X = advancedBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.None ? 0 : 1;
256274
if (advancedBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.OutsetDouble ||
257275
advancedBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.InsetDouble)
258276
{
259277
rect.X++;
260278
}
261279

262-
rect.Y = advancedBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.None ? 0 : 1;
280+
rect.Y = advancedBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.None
281+
? 0
282+
: 1;
283+
263284
if (advancedBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.OutsetDouble ||
264285
advancedBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.InsetDouble)
265286
{
266287
rect.Y++;
267288
}
268289

269-
rect.Width = advancedBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.None ? 0 : 1;
290+
rect.Width = advancedBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.None
291+
? 0
292+
: 1;
293+
270294
if (advancedBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.OutsetDouble ||
271295
advancedBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.InsetDouble)
272296
{
273297
rect.Width++;
274298
}
275299

276-
rect.Height = advancedBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.None ? 0 : 1;
300+
rect.Height = advancedBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.None
301+
? 0
302+
: 1;
303+
277304
if (advancedBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.OutsetDouble ||
278305
advancedBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.InsetDouble)
279306
{
@@ -290,12 +317,12 @@ public static Rectangle BorderWidths(DataGridViewAdvancedBorderStyle advancedBor
290317

291318
#region Private Methods
292319

293-
private static void PaintCell(ILogPaintContext logPaintCtx, DataGridViewCellPaintingEventArgs e, DataGridView gridView, bool noBackgroundFill, HilightEntry groundEntry)
320+
private static void PaintCell(ILogPaintContext logPaintCtx, DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, bool noBackgroundFill, HilightEntry groundEntry)
294321
{
295322
PaintHighlightedCell(logPaintCtx, e, gridView, noBackgroundFill, groundEntry);
296323
}
297324

298-
private static void PaintHighlightedCell(ILogPaintContext logPaintCtx, DataGridViewCellPaintingEventArgs e, DataGridView gridView, bool noBackgroundFill, HilightEntry groundEntry)
325+
private static void PaintHighlightedCell(ILogPaintContext logPaintCtx, DataGridViewCellPaintingEventArgs e, BufferedDataGridView gridView, bool noBackgroundFill, HilightEntry groundEntry)
299326
{
300327
object value = e.Value ?? string.Empty;
301328

@@ -310,9 +337,11 @@ private static void PaintHighlightedCell(ILogPaintContext logPaintCtx, DataGridV
310337
{
311338
if (string.IsNullOrEmpty(column.FullValue) == false)
312339
{
313-
HilightMatchEntry hme = new();
314-
hme.StartPos = 0;
315-
hme.Length = column.FullValue.Length;
340+
HilightMatchEntry hme = new()
341+
{
342+
StartPos = 0,
343+
Length = column.FullValue.Length
344+
};
316345

317346
var he = new HilightEntry
318347
{
@@ -335,20 +364,23 @@ private static void PaintHighlightedCell(ILogPaintContext logPaintCtx, DataGridV
335364
}
336365

337366
int leftPad = e.CellStyle.Padding.Left;
367+
338368
RectangleF rect = new(e.CellBounds.Left + leftPad, e.CellBounds.Top, e.CellBounds.Width, e.CellBounds.Height);
369+
339370
Rectangle borderWidths = BorderWidths(e.AdvancedBorderStyle);
340371
Rectangle valBounds = e.CellBounds;
372+
341373
valBounds.Offset(borderWidths.X, borderWidths.Y);
342374
valBounds.Width -= borderWidths.Right;
343375
valBounds.Height -= borderWidths.Bottom;
376+
344377
if (e.CellStyle.Padding != Padding.Empty)
345378
{
346379
valBounds.Offset(e.CellStyle.Padding.Left, e.CellStyle.Padding.Top);
347380
valBounds.Width -= e.CellStyle.Padding.Horizontal;
348381
valBounds.Height -= e.CellStyle.Padding.Vertical;
349382
}
350383

351-
352384
TextFormatFlags flags =
353385
TextFormatFlags.Left
354386
| TextFormatFlags.SingleLine
@@ -462,19 +494,23 @@ private static IList<HilightMatchEntry> MergeHighlightMatchEntries(IList<Hilight
462494
{
463495
if (entryArray[pos] != currentEntry)
464496
{
465-
HilightMatchEntry me = new();
466-
me.StartPos = lastStartPos;
467-
me.Length = pos - lastStartPos;
468-
me.HilightEntry = currentEntry;
497+
HilightMatchEntry me = new()
498+
{
499+
StartPos = lastStartPos,
500+
Length = pos - lastStartPos,
501+
HilightEntry = currentEntry
502+
};
469503
mergedList.Add(me);
470504
currentEntry = entryArray[pos];
471505
lastStartPos = pos;
472506
}
473507
}
474-
HilightMatchEntry me2 = new();
475-
me2.StartPos = lastStartPos;
476-
me2.Length = pos - lastStartPos;
477-
me2.HilightEntry = currentEntry;
508+
HilightMatchEntry me2 = new()
509+
{
510+
StartPos = lastStartPos,
511+
Length = pos - lastStartPos,
512+
HilightEntry = currentEntry
513+
};
478514
mergedList.Add(me2);
479515
}
480516
return mergedList;

src/LogExpert/Controls/LogWindow/LogWindow.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public LogWindow(LogTabWindow.LogTabWindow parent, string fileName, bool isTempF
160160
ForcePersistenceLoading = forcePersistenceLoading;
161161

162162
dataGridView.CellValueNeeded += OnDataGridViewCellValueNeeded;
163-
dataGridView.CellPainting += OnDataGridView_CellPainting;
163+
dataGridView.CellPainting += OnDataGridViewCellPainting;
164164

165165
filterGridView.CellValueNeeded += OnFilterGridViewCellValueNeeded;
166166
filterGridView.CellPainting += OnFilterGridViewCellPainting;
@@ -561,10 +561,13 @@ internal void RefreshAllGrids()
561561

562562
internal void ChangeMultifileMask()
563563
{
564-
MultiFileMaskDialog dlg = new(this, FileName);
565-
dlg.Owner = this;
566-
dlg.MaxDays = _multiFileOptions.MaxDayTry;
567-
dlg.FileNamePattern = _multiFileOptions.FormatPattern;
564+
MultiFileMaskDialog dlg = new(this, FileName)
565+
{
566+
Owner = this,
567+
MaxDays = _multiFileOptions.MaxDayTry,
568+
FileNamePattern = _multiFileOptions.FormatPattern
569+
};
570+
568571
if (dlg.ShowDialog() == DialogResult.OK)
569572
{
570573
_multiFileOptions.FormatPattern = dlg.FileNamePattern;
@@ -647,7 +650,7 @@ private void OnButtonSizeChanged(object sender, EventArgs e)
647650

648651
private delegate void PositionAfterReloadFx(ReloadMemento reloadMemento);
649652

650-
private delegate void AutoResizeColumnsFx(DataGridView gridView);
653+
private delegate void AutoResizeColumnsFx(BufferedDataGridView gridView);
651654

652655
private delegate bool BoolReturnDelegate();
653656

0 commit comments

Comments
 (0)