Skip to content

Commit 0927f1b

Browse files
author
Mirroring
committed
Merge commit 'f8fd9912b53d6d815d94b0bd81dbaa11d6cd86a5'
2 parents 5a60f26 + f8fd991 commit 0927f1b

File tree

11 files changed

+226
-63
lines changed

11 files changed

+226
-63
lines changed

src/System.Drawing.Common/src/System/Drawing/Printing/PageSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Rectangle Bounds
5353
public bool Color
5454
{
5555
get => _color.IsDefault
56-
? _printerSettings.GetModeField(ModeField.Color, (short)DEVMODE_COLOR.DMCOLOR_MONOCHROME) == (short)DEVMODE_COLOR.DMCOLOR_MONOCHROME
56+
? _printerSettings.GetModeField(ModeField.Color, (short)DEVMODE_COLOR.DMCOLOR_MONOCHROME) == (short)DEVMODE_COLOR.DMCOLOR_COLOR
5757
: (bool)_color;
5858
set => _color = value;
5959
}

src/System.Drawing.Common/tests/Helpers.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Drawing.Printing;
56
using System.Text;
67
using Windows.Win32;
@@ -21,6 +22,47 @@ public unsafe static class Helpers
2122

2223
public static bool AreAnyPrintersInstalled() => s_anyInstalledPrinters;
2324

25+
private const string PrintToPdfPrinterName = "Microsoft Print to PDF";
26+
27+
/// <summary>
28+
/// Checks if PDF printing is supported by verifying installed printers.
29+
/// </summary>
30+
/// <returns><see langword="true"/> if a PDF printer is installed; otherwise, <see langword="false"/>.</returns>
31+
public static bool CanPrintToPdf()
32+
{
33+
foreach (string name in InstalledPrinters)
34+
{
35+
if (name.StartsWith(PrintToPdfPrinterName, StringComparison.Ordinal))
36+
{
37+
return true;
38+
}
39+
}
40+
41+
return false;
42+
}
43+
44+
/// <summary>
45+
/// Attempts to get the name of the PDF printer installed on the system.
46+
/// </summary>
47+
/// <param name="printerName">
48+
/// When this method returns, contains the name of the PDF printer if found; otherwise, <see langword="null"/>.
49+
/// </param>
50+
/// <returns><see langword="true"/> if a PDF printer is found; otherwise, <see langword="false"/>.</returns>
51+
public static bool TryGetPdfPrinterName([NotNullWhen(true)] out string? printerName)
52+
{
53+
foreach (string name in InstalledPrinters)
54+
{
55+
if (name.StartsWith(PrintToPdfPrinterName, StringComparison.Ordinal))
56+
{
57+
printerName = name;
58+
return true;
59+
}
60+
}
61+
62+
printerName = null;
63+
return false;
64+
}
65+
2466
public static string GetTestBitmapPath(string fileName) => GetTestPath("bitmaps", fileName);
2567
public static string GetTestFontPath(string fileName) => GetTestPath("fonts", fileName);
2668
public static string GetTestColorProfilePath(string fileName) => GetTestPath("colorProfiles", fileName);

src/System.Drawing.Common/tests/System/Drawing/Printing/PageSettingsTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,21 @@ public void Clone_Success()
6363
Assert.Equal(ps.PaperSource.Kind, clone.PaperSource.Kind);
6464
Assert.Equal(ps.PaperSource.SourceName, clone.PaperSource.SourceName);
6565
}
66+
67+
[ConditionalFact(Helpers.AnyInstalledPrinters)]
68+
public void PrintToPDF_DefaultPageSettings_IsColor()
69+
{
70+
// Regression test for https://github.com/dotnet/winforms/issues/13367
71+
if (!Helpers.TryGetPdfPrinterName(out string? printerName))
72+
{
73+
return;
74+
}
75+
76+
PrinterSettings printerSettings = new()
77+
{
78+
PrinterName = printerName
79+
};
80+
81+
printerSettings.DefaultPageSettings.Color.Should().BeTrue("PDF printer should support color printing.");
82+
}
6683
}

src/System.Drawing.Common/tests/System/Drawing/Printing/PrintDocumentTests.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ public void EndPrint_SetValue_ReturnsExpected()
160160
Assert.False(flag);
161161
}
162162

163-
[ConditionalFact(nameof(CanPrintToPdf))]
163+
[ConditionalFact(typeof(Helpers), nameof(Helpers.CanPrintToPdf))]
164164
public void Print_DefaultPrintController_Success()
165165
{
166-
if (!CanPrintToPdf())
166+
if (!Helpers.TryGetPdfPrinterName(out string? printerName))
167167
{
168168
return;
169169
}
@@ -172,7 +172,7 @@ public void Print_DefaultPrintController_Success()
172172
PrintEventHandler endPrintHandler = new((sender, e) => endPrintCalled = true);
173173
using (PrintDocument document = new())
174174
{
175-
document.PrinterSettings.PrinterName = GetPdfPrinterName();
175+
document.PrinterSettings.PrinterName = printerName;
176176
document.PrinterSettings.PrintFileName = GetTestFilePath();
177177
document.PrinterSettings.PrintToFile = true;
178178
document.EndPrint += endPrintHandler;
@@ -247,33 +247,6 @@ private void AssertDefaultPageSettings(PageSettings pageSettings)
247247
Assert.True(pageSettings.PrinterSettings.IsDefaultPrinter);
248248
}
249249

250-
private const string PrintToPdfPrinterName = "Microsoft Print to PDF";
251-
private static bool CanPrintToPdf()
252-
{
253-
foreach (string name in Helpers.InstalledPrinters)
254-
{
255-
if (name.StartsWith(PrintToPdfPrinterName, StringComparison.Ordinal))
256-
{
257-
return true;
258-
}
259-
}
260-
261-
return false;
262-
}
263-
264-
private static string GetPdfPrinterName()
265-
{
266-
foreach (string name in Helpers.InstalledPrinters)
267-
{
268-
if (name.StartsWith(PrintToPdfPrinterName, StringComparison.Ordinal))
269-
{
270-
return name;
271-
}
272-
}
273-
274-
throw new InvalidOperationException("No PDF printer installed");
275-
}
276-
277250
private class TestPrintController : PrintController
278251
{
279252
public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)

src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ private void TestHook_GetAllSnapLines(ref Message m)
799799

800800
if (host.GetDesigner(comp) is ControlDesigner designer)
801801
{
802-
foreach (SnapLine line in designer.SnapLinesInternal)
802+
foreach (SnapLine line in designer.SnapLines)
803803
{
804804
snapLineInfo.Append($"{line}\tAssociated Control = {designer.Control.Name}:::");
805805
}

src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/DragAssistanceManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ internal DragAssistanceManager(
165165
/// </summary>
166166
private void AddSnapLines(ControlDesigner controlDesigner, List<SnapLine> horizontalList, List<SnapLine> verticalList, bool isTarget, bool validTarget)
167167
{
168-
IList<SnapLine> snapLines = controlDesigner.SnapLinesInternal;
168+
IList snapLines = controlDesigner.SnapLines;
169169
// Used for padding snaplines
170170
Rectangle controlRect = controlDesigner.Control.ClientRectangle;
171171
// Used for all others

src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/Behavior/SnapLineTests.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,59 @@ public void SnapLine_ToString(string filter, string expected)
236236

237237
Assert.Equal(expected, snapLine.ToString());
238238
}
239+
240+
// Unit test for https://github.com/dotnet/winforms/issues/13305
241+
[Fact]
242+
public void SnapLine_ReturnOverrided()
243+
{
244+
using ControlDesigner baseDesigner = new();
245+
using Control control = new();
246+
baseDesigner.Initialize(control);
247+
baseDesigner.SnapLines.Count.Should().Be(8);
248+
249+
ControlDesigner derivedDesigner = new ButtonBaseDesigner();
250+
using Button button = new();
251+
derivedDesigner.Initialize(button);
252+
derivedDesigner.SnapLines.Count.Should().Be(9);
253+
254+
derivedDesigner = new ComboBoxDesigner();
255+
using ComboBox comboBox = new();
256+
derivedDesigner.Initialize(comboBox);
257+
derivedDesigner.SnapLines.Count.Should().Be(9);
258+
259+
derivedDesigner = new DateTimePickerDesigner();
260+
using DateTimePicker dateTimePicker = new();
261+
derivedDesigner.Initialize(dateTimePicker);
262+
derivedDesigner.SnapLines.Count.Should().Be(9);
263+
264+
derivedDesigner = new LabelDesigner();
265+
using Label label = new();
266+
derivedDesigner.Initialize(label);
267+
derivedDesigner.SnapLines.Count.Should().Be(9);
268+
269+
derivedDesigner = new ParentControlDesigner();
270+
derivedDesigner.Initialize(control);
271+
derivedDesigner.SnapLines.Count.Should().Be(12);
272+
273+
derivedDesigner = new SplitterPanelDesigner();
274+
using SplitContainer splitContainer = new();
275+
using SplitterPanel splitterPanel = new(splitContainer);
276+
derivedDesigner.Initialize(splitterPanel);
277+
derivedDesigner.SnapLines.Count.Should().Be(4);
278+
279+
derivedDesigner = new TextBoxBaseDesigner();
280+
using TextBox textBox = new();
281+
derivedDesigner.Initialize(textBox);
282+
derivedDesigner.SnapLines.Count.Should().Be(9);
283+
284+
derivedDesigner = new ToolStripContentPanelDesigner();
285+
using ToolStripContentPanel toolStripContentPanel = new();
286+
derivedDesigner.Initialize(toolStripContentPanel);
287+
derivedDesigner.SnapLines.Count.Should().Be(4);
288+
289+
derivedDesigner = new UpDownBaseDesigner();
290+
using DomainUpDown domainUpDown = new();
291+
derivedDesigner.Initialize(domainUpDown);
292+
derivedDesigner.SnapLines.Count.Should().Be(9);
293+
}
239294
}

src/System.Windows.Forms/src/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/GridEntry.GridEntryAccessibleObject.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,10 @@ internal override void SetFocus()
410410

411411
base.SetFocus();
412412

413-
RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId);
413+
if (!PropertyGridView.InPropertySet && !PropertyGridView.EditMouseDown)
414+
{
415+
RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId);
416+
}
414417
}
415418
}
416419
}

src/System.Windows.Forms/src/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.Flags.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private enum Flags : ushort
2222
/// </summary>
2323
ButtonLaunchedEditor = 0x0100,
2424
NoDefault = 0x0200,
25-
ResizableDropDown = 0x0400
25+
ResizableDropDown = 0x0400,
26+
EditMouseDown = 0x0800
2627
}
2728
}

src/System.Windows.Forms/src/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.cs

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,44 +2566,59 @@ private void OnEditLostFocus(object? sender, EventArgs e)
25662566
InvokeLostFocus(this, EventArgs.Empty);
25672567
}
25682568

2569-
private void OnEditMouseDown(object? sender, MouseEventArgs e)
2569+
internal bool EditMouseDown
25702570
{
2571-
if (!FocusInside)
2572-
{
2573-
SelectGridEntry(_selectedGridEntry, pageIn: false);
2574-
}
2575-
2576-
if (e.Clicks % 2 == 0)
2577-
{
2578-
DoubleClickRow(_selectedRow, toggleExpand: false, RowValue);
2579-
EditTextBox.SelectAll();
2580-
}
2571+
get => _flags.HasFlag(Flags.EditMouseDown);
2572+
private set => SetFlag(Flags.EditMouseDown, value);
2573+
}
25812574

2582-
if (_rowSelectTime == 0)
2575+
private void OnEditMouseDown(object? sender, MouseEventArgs e)
2576+
{
2577+
try
25832578
{
2584-
return;
2585-
}
2586-
2587-
// Check if the click happened within the double click time since the row was selected.
2588-
// This allows the edits to be selected with two clicks instead of 3 (select row, double click).
2589-
long timeStamp = DateTime.Now.Ticks;
2590-
int delta = (int)((timeStamp - _rowSelectTime) / 10000); // make it milliseconds
2579+
EditMouseDown = true;
25912580

2592-
if (delta < SystemInformation.DoubleClickTime)
2593-
{
2594-
Point screenPoint = EditTextBox.PointToScreen(e.Location);
2581+
if (!FocusInside)
2582+
{
2583+
SelectGridEntry(_selectedGridEntry, pageIn: false);
2584+
}
25952585

2596-
if (Math.Abs(screenPoint.X - _rowSelectPos.X) < SystemInformation.DoubleClickSize.Width &&
2597-
Math.Abs(screenPoint.Y - _rowSelectPos.Y) < SystemInformation.DoubleClickSize.Height)
2586+
if (e.Clicks % 2 == 0)
25982587
{
25992588
DoubleClickRow(_selectedRow, toggleExpand: false, RowValue);
2600-
PInvoke.SendMessage(EditTextBox, PInvoke.WM_LBUTTONUP, (WPARAM)0, (LPARAM)e.Location);
26012589
EditTextBox.SelectAll();
26022590
}
26032591

2604-
_rowSelectPos = Point.Empty;
2592+
if (_rowSelectTime == 0)
2593+
{
2594+
return;
2595+
}
26052596

2606-
_rowSelectTime = 0;
2597+
// Check if the click happened within the double click time since the row was selected.
2598+
// This allows the edits to be selected with two clicks instead of 3 (select row, double click).
2599+
long timeStamp = DateTime.Now.Ticks;
2600+
int delta = (int)((timeStamp - _rowSelectTime) / 10000); // make it milliseconds
2601+
2602+
if (delta < SystemInformation.DoubleClickTime)
2603+
{
2604+
Point screenPoint = EditTextBox.PointToScreen(e.Location);
2605+
2606+
if (Math.Abs(screenPoint.X - _rowSelectPos.X) < SystemInformation.DoubleClickSize.Width &&
2607+
Math.Abs(screenPoint.Y - _rowSelectPos.Y) < SystemInformation.DoubleClickSize.Height)
2608+
{
2609+
DoubleClickRow(_selectedRow, toggleExpand: false, RowValue);
2610+
PInvoke.SendMessage(EditTextBox, PInvoke.WM_LBUTTONUP, (WPARAM)0, (LPARAM)e.Location);
2611+
EditTextBox.SelectAll();
2612+
}
2613+
2614+
_rowSelectPos = Point.Empty;
2615+
2616+
_rowSelectTime = 0;
2617+
}
2618+
}
2619+
finally
2620+
{
2621+
EditMouseDown = false;
26072622
}
26082623
}
26092624

@@ -3998,7 +4013,7 @@ private void Refresh(bool fullRefresh, int startRow, int endRow)
39984013
startRow = 0;
39994014
}
40004015

4001-
if (OwnerGrid.HavePropertyEntriesChanged())
4016+
if (fullRefresh || OwnerGrid.HavePropertyEntriesChanged())
40024017
{
40034018
if (HasEntries && !InPropertySet && !CommitEditTextBox())
40044019
{

0 commit comments

Comments
 (0)