Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Winforms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Design.Editors.Facade3x", "src\System.Windows.Forms.Design.Editors\src\System.Windows.Forms.Design.Editors.Facade3x.csproj", "{E0681991-228A-420E-85D5-A9E796F0AAE0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiMonthCalendarTests", "src\System.Windows.Forms\tests\IntegrationTests\MauiTests\MauimonthCalendarTests\MauiMonthCalendarTests.csproj", "{9DDC6936-9197-4C09-8640-AF0BE4918700}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiTestsHelper", "src\System.Windows.Forms\tests\IntegrationTests\MauiTests\MauiTestsHelper\MauiTestsHelper.csproj", "{44BB1092-1844-4EAF-8DF5-338DE4C3149A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -248,6 +252,14 @@ Global
{E0681991-228A-420E-85D5-A9E796F0AAE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0681991-228A-420E-85D5-A9E796F0AAE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0681991-228A-420E-85D5-A9E796F0AAE0}.Release|Any CPU.Build.0 = Release|Any CPU
{9DDC6936-9197-4C09-8640-AF0BE4918700}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DDC6936-9197-4C09-8640-AF0BE4918700}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DDC6936-9197-4C09-8640-AF0BE4918700}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DDC6936-9197-4C09-8640-AF0BE4918700}.Release|Any CPU.Build.0 = Release|Any CPU
{44BB1092-1844-4EAF-8DF5-338DE4C3149A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{44BB1092-1844-4EAF-8DF5-338DE4C3149A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44BB1092-1844-4EAF-8DF5-338DE4C3149A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44BB1092-1844-4EAF-8DF5-338DE4C3149A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -287,6 +299,8 @@ Global
{90B27178-F535-43F7-886E-0AB75203F246} = {77FEDB47-F7F6-490D-AF7C-ABB4A9E0B9D7}
{9BFDE7F2-C8F3-40D6-9A16-8DCD1A37E900} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
{E0681991-228A-420E-85D5-A9E796F0AAE0} = {434C00C3-E498-4BA7-9764-9F0FC8CFE457}
{9DDC6936-9197-4C09-8640-AF0BE4918700} = {8F20A905-BD37-4D80-B8DF-FA45276FC23F}
{44BB1092-1844-4EAF-8DF5-338DE4C3149A} = {8F20A905-BD37-4D80-B8DF-FA45276FC23F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
[assembly: InternalsVisibleTo("MauiListViewTests, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Windows.Forms.IntegrationTests.Common, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("System.Windows.Forms.Maui.IntegrationTests, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("MauiMonthCalendarTests, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("MauiTestsHelper, PublicKey=00000000000000000400000000000000")]

// This is needed in order to Moq internal interfaces for testing
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("System.Windows.Forms.Tests, PublicKey=00000000000000000400000000000000")]
[assembly: InternalsVisibleTo("MauiMonthCalendarTests, PublicKey=00000000000000000400000000000000")]

// This is needed in order to Moq internal interfaces for testing
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,12 @@ internal static Kernel32.SYSTEMTIME DateTimeToSysTime(DateTime time)
/// </summary>
internal static DateTime SysTimeToDateTime(Kernel32.SYSTEMTIME s)
{
if (s.wYear <= 0 || s.wMonth <= 0 || s.wDay <= 0)
{
Debug.Fail("Incorrect SYSTEMTIME info!");
return DateTime.MinValue;
}

return new DateTime(s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wSecond);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public CalendarChildAccessibleObject GetFromPoint(MCHITTESTINFO hitTestInfo)
case MCHT.CALENDARWEEKNUM:
case MCHT.CALENDARDATE:
AccessibleObject rowAccessibleObject = _calendarAccessibleObject.GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarRow, this, hitTestInfo.iRow);

if (rowAccessibleObject == null)
{
return null;
}

return _calendarAccessibleObject.GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarCell, rowAccessibleObject, hitTestInfo.iCol);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public partial class MonthCalendar
/// </summary>
internal abstract class CalendarChildAccessibleObject : AccessibleObject
{
protected MonthCalendarAccessibleObject _calendarAccessibleObject;
protected readonly MonthCalendarAccessibleObject _calendarAccessibleObject;
protected int _calendarIndex;
protected CalendarChildType _itemType;

public CalendarChildAccessibleObject(MonthCalendarAccessibleObject calendarAccessibleObject, int calendarIndex, CalendarChildType itemType)
{
_calendarAccessibleObject = calendarAccessibleObject;
_calendarAccessibleObject = calendarAccessibleObject ?? throw new ArgumentNullException(nameof(calendarAccessibleObject));
_calendarIndex = calendarIndex;
_itemType = itemType;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ public void RaiseMouseClick()
return;
}

var rectangle = CalculateBoundingRectangle();
RECT rectangle = CalculateBoundingRectangle();
int x = rectangle.left + ((rectangle.right - rectangle.left) / 2);
int y = rectangle.top + ((rectangle.bottom - rectangle.top) / 2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public partial class MonthCalendar
/// </summary>
internal abstract class CalendarGridChildAccessibleObject : CalendarChildAccessibleObject
{
protected AccessibleObject _parentAccessibleObject;
protected readonly AccessibleObject _parentAccessibleObject;

public CalendarGridChildAccessibleObject(MonthCalendarAccessibleObject calendarAccessibleObject, int calendarIndex, CalendarChildType itemType,
AccessibleObject parentAccessibleObject, int itemIndex) : base(calendarAccessibleObject, calendarIndex, itemType)
{
_parentAccessibleObject = parentAccessibleObject;
_parentAccessibleObject = parentAccessibleObject ?? throw new ArgumentNullException(nameof(parentAccessibleObject));
}

public override AccessibleObject Parent => _parentAccessibleObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class MonthCalendarAccessibleObject : ControlAccessibleObject
public MonthCalendarAccessibleObject(Control owner)
: base(owner)
{
_owner = owner as MonthCalendar;
_owner = (MonthCalendar)owner;
}

public UiaCore.UIA ControlType =>
Expand Down Expand Up @@ -83,10 +83,6 @@ public override string Name
}

name = string.Empty;
if (_owner == null)
{
return name;
}

if (_owner._mcCurView == MCMV.MONTH)
{
Expand Down Expand Up @@ -134,47 +130,34 @@ public override string Value
{
get
{
var value = string.Empty;
if (_owner == null)
{
return value;
}

try
{
if (_owner._mcCurView == MCMV.MONTH)
{
if (System.DateTime.Equals(_owner.SelectionStart.Date, _owner.SelectionEnd.Date))
{
value = _owner.SelectionStart.ToLongDateString();
}
else
{
value = string.Format("{0} - {1}", _owner.SelectionStart.ToLongDateString(), _owner.SelectionEnd.ToLongDateString());
return _owner.SelectionStart.ToLongDateString();
}

return string.Format("{0} - {1}", _owner.SelectionStart.ToLongDateString(), _owner.SelectionEnd.ToLongDateString());
}
else if (_owner._mcCurView == MCMV.YEAR)

if (_owner._mcCurView == MCMV.YEAR)
{
if (System.DateTime.Equals(_owner.SelectionStart.Month, _owner.SelectionEnd.Month))
{
value = _owner.SelectionStart.ToString("y");
}
else
{
value = string.Format("{0} - {1}", _owner.SelectionStart.ToString("y"), _owner.SelectionEnd.ToString("y"));
return _owner.SelectionStart.ToString("y");
}

return string.Format("{0} - {1}", _owner.SelectionStart.ToString("y"), _owner.SelectionEnd.ToString("y"));
}
else
{
value = string.Format("{0} - {1}", _owner.SelectionRange.Start.ToString(), _owner.SelectionRange.End.ToString());
}

return string.Format("{0} - {1}", _owner.SelectionRange.Start.ToString(), _owner.SelectionRange.End.ToString());
}
catch
{
value = base.Value;
return base.Value;
}

return value;
}
set => base.Value = value;
}
Expand All @@ -195,6 +178,7 @@ internal override int ColumnCount

int columnCount = 0;
bool success = true;

while (success)
{
success = GetCalendarGridInfo(
Expand Down Expand Up @@ -236,6 +220,7 @@ internal override int RowCount

int rowCount = 0;
bool success = true;

while (success)
{
success = GetCalendarGridInfo(
Expand Down Expand Up @@ -271,6 +256,7 @@ internal override UiaCore.IRawElementProviderFragment ElementProviderFromPoint(d
int innerY = (int)y;

MCHITTESTINFO hitTestInfo = GetHitTestInfo(innerX, innerY);

switch ((MCHT)hitTestInfo.uHit)
{
case MCHT.TITLEBTNPREV:
Expand All @@ -289,7 +275,7 @@ internal override UiaCore.IRawElementProviderFragment ElementProviderFromPoint(d
case MCHT.CALENDARDATE:
// Get calendar body's child.
CalendarBodyAccessibleObject calendarBodyAccessibleObject = (CalendarBodyAccessibleObject)GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarBody);
return calendarBodyAccessibleObject.GetFromPoint(hitTestInfo);
return calendarBodyAccessibleObject?.GetFromPoint(hitTestInfo);

case MCHT.TODAYLINK:
return GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.TodayLink);
Expand Down Expand Up @@ -361,7 +347,8 @@ public string GetCalendarChildName(int calendarIndex, CalendarChildType calendar

private CalendarCellAccessibleObject GetCalendarCell(int calendarIndex, AccessibleObject parentAccessibleObject, int columnIndex)
{
if (columnIndex < 0 ||
if (parentAccessibleObject == null ||
columnIndex < 0 ||
columnIndex >= MAX_DAYS ||
columnIndex >= ColumnCount)
{
Expand All @@ -379,12 +366,16 @@ private CalendarCellAccessibleObject GetCalendarCell(int calendarIndex, Accessib
out Kernel32.SYSTEMTIME systemEndDate,
out Kernel32.SYSTEMTIME systemStartDate);

DateTime endDate = DateTimePicker.SysTimeToDateTime(systemEndDate).Date;
DateTime startDate = DateTimePicker.SysTimeToDateTime(systemStartDate).Date;

if (getNameResult && !string.IsNullOrEmpty(text))
{
string cellName = GetCalendarCellName(endDate, startDate, text, rowIndex == -1);
string cellName = string.Empty;

if (getDateResult)
{
DateTime endDate = DateTimePicker.SysTimeToDateTime(systemEndDate).Date;
DateTime startDate = DateTimePicker.SysTimeToDateTime(systemStartDate).Date;
cellName = GetCalendarCellName(endDate, startDate, text, rowIndex == -1);
}

// The cell is present on the calendar, so create accessible object for it.
return new CalendarCellAccessibleObject(this, calendarIndex, parentAccessibleObject, rowIndex, columnIndex, cellName);
Expand Down Expand Up @@ -414,7 +405,8 @@ private string GetCalendarCellName(DateTime endDate, DateTime startDate, string

private CalendarRowAccessibleObject GetCalendarRow(int calendarIndex, AccessibleObject parentAccessibleObject, int rowIndex)
{
if ((HasHeaderRow ? rowIndex < -1 : rowIndex < 0) ||
if (parentAccessibleObject == null ||
(HasHeaderRow ? rowIndex < -1 : rowIndex < 0) ||
rowIndex >= RowCount)
{
return null;
Expand All @@ -439,7 +431,7 @@ private CalendarRowAccessibleObject GetCalendarRow(int calendarIndex, Accessible

SelectionRange cellsRange = _owner.GetDisplayRange(false);

if (cellsRange.Start > DateTimePicker.SysTimeToDateTime(endDate) || cellsRange.End < DateTimePicker.SysTimeToDateTime(startDate))
if (cellsRange == null || cellsRange.Start > DateTimePicker.SysTimeToDateTime(endDate) || cellsRange.End < DateTimePicker.SysTimeToDateTime(startDate))
{
// Do not create row if the row's first cell is out of the current calendar's view range.
return null;
Expand Down Expand Up @@ -648,6 +640,7 @@ private unsafe void SendMouseInput(int x, int y, User32.MOUSEEVENTF flags)
public void RaiseAutomationEventForChild(UiaCore.UIA automationEventId, DateTime selectionStart, DateTime selectionEnd)
{
AccessibleObject calendarChildAccessibleObject = GetCalendarChildAccessibleObject(selectionStart, selectionEnd);

if (calendarChildAccessibleObject != null)
{
calendarChildAccessibleObject.RaiseAutomationEvent(automationEventId);
Expand All @@ -661,13 +654,23 @@ public void RaiseAutomationEventForChild(UiaCore.UIA automationEventId, DateTime

private AccessibleObject GetCalendarChildAccessibleObject(DateTime selectionStart, DateTime selectionEnd)
{
int columnCount = ColumnCount;

AccessibleObject bodyAccessibleObject = GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarBody);

if (bodyAccessibleObject == null)
{
return null;
}

for (int row = 0; row < RowCount; row++)
{
AccessibleObject rowAccessibleObject = GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarRow, bodyAccessibleObject, row);
for (int column = 0; column < columnCount; column++)

if (rowAccessibleObject == null)
{
continue;
}

for (int column = 0; column < ColumnCount; column++)
{
bool success = GetCalendarGridInfo(
MCGIF.DATE,
Expand All @@ -685,6 +688,7 @@ private AccessibleObject GetCalendarChildAccessibleObject(DateTime selectionStar
}

AccessibleObject cellAccessibleObject = GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarCell, rowAccessibleObject, column);

if (cellAccessibleObject == null)
{
continue;
Expand Down Expand Up @@ -715,7 +719,15 @@ internal override UiaCore.IRawElementProviderSimple[] GetColumnHeaderItems()

UiaCore.IRawElementProviderSimple[] headers =
new UiaCore.IRawElementProviderSimple[MonthCalendarAccessibleObject.MAX_DAYS];
AccessibleObject headerRowAccessibleObject = GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarRow, this, -1);

AccessibleObject bodyAccessibleObject = GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarBody, this, -1);
AccessibleObject headerRowAccessibleObject = GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarRow, bodyAccessibleObject, -1);

if (headerRowAccessibleObject == null)
{
return null;
}

for (int columnIndex = 0; columnIndex < MonthCalendarAccessibleObject.MAX_DAYS; columnIndex++)
{
headers[columnIndex] = GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarCell, headerRowAccessibleObject, columnIndex);
Expand Down
Loading