Skip to content

Commit

Permalink
Enable nullability in ToolStripItemInternalLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetrou committed Jun 14, 2022
1 parent 1ea8dd5 commit 8df1e42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ToolStripLayoutData(ToolStrip toolStrip)
_size = toolStrip.Size;
}

public bool IsCurrent(ToolStrip toolStrip)
public bool IsCurrent(ToolStrip? toolStrip)
=> toolStrip is not null && toolStrip.Size == _size && toolStrip.LayoutStyle == _layoutStyle && toolStrip.AutoSize == _autoSize;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Drawing;
using System.Windows.Forms.ButtonInternal;

Expand All @@ -16,14 +14,14 @@ public partial class ToolStripItem
/// </summary>
internal partial class ToolStripItemInternalLayout
{
private ToolStripItemLayoutOptions _currentLayoutOptions;
private ToolStripItemLayoutOptions? _currentLayoutOptions;
private readonly ToolStripItem _ownerItem;
private ButtonBaseAdapter.LayoutData _layoutData;
private ButtonBaseAdapter.LayoutData? _layoutData;
private const int BorderWidth = 2;
private readonly static Size s_invalidSize = new Size(int.MinValue, int.MinValue);

private Size _lastPreferredSize = s_invalidSize;
private ToolStripLayoutData _parentLayoutData;
private ToolStripLayoutData? _parentLayoutData;

public ToolStripItemInternalLayout(ToolStripItem ownerItem)
{
Expand All @@ -37,7 +35,7 @@ public virtual Rectangle ImageRectangle
get
{
Rectangle imageRect = LayoutData.ImageBounds;
imageRect.Intersect(_layoutData.Field);
imageRect.Intersect(_layoutData!.Field);
return imageRect;
}
}
Expand All @@ -47,20 +45,20 @@ internal ButtonBaseAdapter.LayoutData LayoutData
get
{
EnsureLayout();
return _layoutData;
return _layoutData!;
}
}

public Size PreferredImageSize => Owner.PreferredImageSize;

protected virtual ToolStrip ParentInternal => _ownerItem?.ParentInternal;
protected virtual ToolStrip? ParentInternal => _ownerItem?.ParentInternal;

public virtual Rectangle TextRectangle
{
get
{
Rectangle textRect = LayoutData.TextBounds;
textRect.Intersect(_layoutData.Field);
textRect.Intersect(_layoutData!.Field);
return textRect;
}
}
Expand Down Expand Up @@ -128,7 +126,7 @@ protected virtual ToolStripItemLayoutOptions CommonLayoutOptions()
layoutOptions.GdiTextFormatFlags = ContentAlignToTextFormat(Owner.TextAlign, Owner.RightToLeft == RightToLeft.Yes);

// Hide underlined &File unless ALT is pressed
layoutOptions.GdiTextFormatFlags = (Owner.ShowKeyboardCues) ? layoutOptions.GdiTextFormatFlags : layoutOptions.GdiTextFormatFlags | TextFormatFlags.HidePrefix;
layoutOptions.GdiTextFormatFlags = Owner.ShowKeyboardCues ? layoutOptions.GdiTextFormatFlags : layoutOptions.GdiTextFormatFlags | TextFormatFlags.HidePrefix;

return layoutOptions;
}
Expand Down Expand Up @@ -159,7 +157,6 @@ private ButtonBaseAdapter.LayoutData GetLayoutData()

public virtual Size GetPreferredSize(Size constrainingSize)
{
Size preferredSize = Size.Empty;
EnsureLayout();
// we would prefer not to be larger than the ToolStrip itself.
// so we'll ask the ButtonAdapter layout guy what it thinks
Expand All @@ -169,7 +166,7 @@ public virtual Size GetPreferredSize(Size constrainingSize)

if (_ownerItem is not null)
{
_lastPreferredSize = _currentLayoutOptions.GetPreferredSizeCore(constrainingSize);
_lastPreferredSize = _currentLayoutOptions!.GetPreferredSizeCore(constrainingSize);
return _lastPreferredSize;
}

Expand All @@ -179,7 +176,7 @@ public virtual Size GetPreferredSize(Size constrainingSize)
internal void PerformLayout()
{
_layoutData = GetLayoutData();
ToolStrip parent = ParentInternal;
ToolStrip? parent = ParentInternal;
if (parent is not null)
{
_parentLayoutData = new ToolStripLayoutData(parent);
Expand Down

0 comments on commit 8df1e42

Please sign in to comment.