Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- working my way through the new() and nullable style(s) #1042

Merged
merged 1 commit into from
Jul 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=adorner/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=and/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=and_0020acti/@EntryIndexedValue">False</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=blit/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=blitting/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coghlan/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=colour/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dependant/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public BreadCrumbButtonSpecCollection(KryptonBreadCrumb owner)
private bool _dropDownNavigaton;
private float _cornerRoundingRadius;
private readonly ViewDrawDocker _drawDocker;
private readonly ButtonSpecManagerDraw _buttonManager;
private VisualPopupToolTip _visualPopupToolTip;
private readonly ButtonSpecManagerDraw? _buttonManager;
private VisualPopupToolTip? _visualPopupToolTip;
private KryptonBreadCrumbItem? _selectedItem;
private readonly ViewLayoutCrumbs _layoutCrumbs;
private ButtonStyle _buttonStyle;
Expand Down Expand Up @@ -264,11 +264,11 @@ public override bool AutoSize
[DefaultValue(true)]
public bool UseMnemonic
{
get => _buttonManager.UseMnemonic;
get => _buttonManager?.UseMnemonic?? true;

set
{
if (_buttonManager.UseMnemonic != value)
if (_buttonManager?.UseMnemonic != value)
{
_buttonManager.UseMnemonic = value;
PerformNeedPaint(true);
Expand Down Expand Up @@ -533,9 +533,9 @@ public bool DesignerGetHitTest(Point pt)
/// <param name="pt">Mouse location.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
public Component DesignerComponentFromPoint(Point pt) =>
public Component? DesignerComponentFromPoint(Point pt) =>
// Ignore call as view builder is already destructed
IsDisposed ? null : ViewManager.ComponentFromPoint(pt);
IsDisposed ? null : ViewManager?.ComponentFromPoint(pt);

// Ask the current view for a decision
/// <summary>
Expand Down Expand Up @@ -598,7 +598,7 @@ protected override void OnEnabledChanged(EventArgs e)
_drawDocker.Enabled = Enabled;

// Update state to reflect change in enabled state
_buttonManager.RefreshButtons();
_buttonManager?.RefreshButtons();

// Change in enabled state requires a layout and repaint
PerformNeedPaint(true);
Expand All @@ -620,7 +620,7 @@ protected override void OnEnabledChanged(EventArgs e)
protected override void OnButtonSpecChanged(object sender, EventArgs e)
{
// Recreate all the button specs with new values
_buttonManager.RecreateButtons();
_buttonManager?.RecreateButtons();

// Let base class perform standard processing
base.OnButtonSpecChanged(sender, e);
Expand Down Expand Up @@ -709,7 +709,7 @@ private void OnShowToolTip(object sender, ToolTipEventArgs e)
bool shadow = true;

// Find the button spec associated with the tooltip request
ButtonSpec? buttonSpec = _buttonManager.ButtonSpecFromView(e.Target);
ButtonSpec? buttonSpec = _buttonManager?.ButtonSpecFromView(e.Target);

// If the tooltip is for a button spec
if (buttonSpec != null)
Expand All @@ -718,7 +718,7 @@ private void OnShowToolTip(object sender, ToolTipEventArgs e)
if (AllowButtonSpecToolTips)
{
// Create a helper object to provide tooltip values
ButtonSpecToContent buttonSpecMapping = new ButtonSpecToContent(Redirector, buttonSpec);
var buttonSpecMapping = new ButtonSpecToContent(Redirector, buttonSpec);

// Is there actually anything to show for the tooltip
if (buttonSpecMapping.HasContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ protected override void OnPaint(PaintEventArgs e)

int internalBorder = BORDER_SIZE;

Rectangle focusRectangle = new Rectangle(internalBorder, internalBorder,
var focusRectangle = new Rectangle(internalBorder, internalBorder,
bounds.Width - _dropDownRectangle.Width - internalBorder, bounds.Height - (internalBorder * 2));

PaletteBase? palette = KryptonManager.CurrentGlobalPalette;
Expand Down Expand Up @@ -1115,13 +1115,17 @@ private void UpdateOSUACShieldIcon(UACShieldIconSize? iconSize = null, Size? cus

private static void PaintArrow(Graphics graphics, Rectangle rectangle)
{
Point midPoint = new Point(Convert.ToInt32(rectangle.Left + rectangle.Width / 2),
var midPoint = new Point(Convert.ToInt32(rectangle.Left + rectangle.Width / 2),
Convert.ToInt32(rectangle.Top + rectangle.Height / 2));

midPoint.X += (rectangle.Width % 2);

Point[] arrow = new Point[] { new Point(midPoint.X - 2, midPoint.Y - 1),
new Point(midPoint.X + 3, midPoint.Y - 1), new Point(midPoint.X, midPoint.Y + 2) };
var arrow = new Point[]
{
new Point(midPoint.X - 2, midPoint.Y - 1),
new Point(midPoint.X + 3, midPoint.Y - 1),
new Point(midPoint.X, midPoint.Y + 2)
};

graphics.FillPolygon(SystemBrushes.ControlText, arrow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public bool Checked
if (value != ViewDrawButton.Checked)
{
// Generate a pre-change event allowing it to be cancelled
CancelEventArgs ce = new CancelEventArgs();
var ce = new CancelEventArgs();
OnCheckedChanging(ce);

// If the change is allowed to occur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ protected override void OnLayout(LayoutEventArgs levent)
base.OnLayout(levent);

// Ask the panel to layout given our available size
using ViewLayoutContext context = new ViewLayoutContext(_viewManager, this, _kryptonCheckedListBox,
using var context = new ViewLayoutContext(_viewManager, this, _kryptonCheckedListBox,
_kryptonCheckedListBox.Renderer);
ViewDrawPanel.Layout(context);
}
Expand Down Expand Up @@ -645,7 +645,7 @@ protected override void WndProc(ref Message m)
else
{
// Find the item under the mouse
Point mousePoint = new Point((int)m.LParam.ToInt64());
var mousePoint = new Point((int)m.LParam.ToInt64());
var mouseIndex = IndexFromPoint(mousePoint);

// If we have an actual item from the point
Expand Down Expand Up @@ -813,7 +813,7 @@ internal IEnumerator InnerArrayGetEnumerator(int stateMask, bool anyBit)
#region Private
private void WmPaint(ref Message m)
{
PI.PAINTSTRUCT ps = new PI.PAINTSTRUCT();
var ps = new PI.PAINTSTRUCT();

// Do we need to BeginPaint or just take the given HDC?
IntPtr hdc = m.WParam == IntPtr.Zero ? PI.BeginPaint(Handle, ref ps) : m.WParam;
Expand All @@ -839,14 +839,13 @@ private void WmPaint(ref Message m)
using (Graphics g = Graphics.FromHdc(_screenDC))
{
// Ask the view element to layout in given space, needs this before a render call
using (ViewLayoutContext context =
new ViewLayoutContext(this, _kryptonCheckedListBox.Renderer))
using (var context = new ViewLayoutContext(this, _kryptonCheckedListBox.Renderer))
{
context.DisplayRectangle = realRect;
ViewDrawPanel.Layout(context);
}

using (RenderContext context = new RenderContext(this, _kryptonCheckedListBox, g,
using (var context = new RenderContext(this, _kryptonCheckedListBox, g,
realRect, _kryptonCheckedListBox.Renderer))
{
ViewDrawPanel.Render(context);
Expand All @@ -860,7 +859,7 @@ private void WmPaint(ref Message m)

if (Items.Count == 0)
{
using RenderContext context = new RenderContext(this, _kryptonCheckedListBox, g,
using var context = new RenderContext(this, _kryptonCheckedListBox, g,
realRect, _kryptonCheckedListBox.Renderer);
ViewDrawPanel.Render(context);
}
Expand All @@ -869,12 +868,12 @@ private void WmPaint(ref Message m)
// Now blit from the bitmap from the screen to the real dc
PI.BitBlt(hdc, 0, 0, realRect.Width, realRect.Height, _screenDC, 0, 0, PI.SRCCOPY);

// When disabled with no items the above code does not draw the backround! Strange but true and
// When disabled with no items the above code does not draw the background! Strange but true and
// so we need to draw the background instead directly, without using a bit blitting of bitmap
if (Items.Count == 0)
{
using Graphics g = Graphics.FromHdc(hdc);
using RenderContext context = new RenderContext(this, _kryptonCheckedListBox, g,
using var context = new RenderContext(this, _kryptonCheckedListBox, g,
realRect, _kryptonCheckedListBox.Renderer);
ViewDrawPanel.Render(context);
}
Expand Down Expand Up @@ -926,7 +925,7 @@ private void LbnSelChange()
{
CheckState checkedState = _kryptonCheckedListBox.GetItemCheckState(selectedIndex);
CheckState newCheckValue = (checkedState != CheckState.Unchecked) ? CheckState.Unchecked : CheckState.Checked;
ItemCheckEventArgs ice = new ItemCheckEventArgs(selectedIndex, newCheckValue, checkedState);
var ice = new ItemCheckEventArgs(selectedIndex, newCheckValue, checkedState);
_kryptonCheckedListBox.SetItemCheckState(selectedIndex, ice.NewValue);
}
_lastSelected = selectedIndex;
Expand Down Expand Up @@ -1791,7 +1790,7 @@ public void SetItemCheckState(int index, CheckState value)
if (value != checkedState)
{
// Give developers a chance to see and alter the change
ItemCheckEventArgs ice = new ItemCheckEventArgs(index, value, checkedState);
var ice = new ItemCheckEventArgs(index, value, checkedState);
OnItemCheck(ice);

// If a change is still occurring
Expand Down Expand Up @@ -2308,15 +2307,15 @@ private void OnListBoxDrawItem(object sender, DrawItemEventArgs e)
// Easier to draw using a graphics instance than a DC!
using Graphics g = Graphics.FromHdc(_screenDC);
// Ask the view element to layout in given space, needs this before a render call
using (ViewLayoutContext context = new ViewLayoutContext(this, Renderer))
using (var context = new ViewLayoutContext(this, Renderer))
{
context.DisplayRectangle = e.Bounds;
_listBox.ViewDrawPanel.Layout(context);
_layoutDocker.Layout(context);
}

// Ask the view element to actually draw
using (RenderContext context = new RenderContext(this, g, e.Bounds, Renderer))
using (var context = new RenderContext(this, g, e.Bounds, Renderer))
{
_listBox.ViewDrawPanel.Render(context);
_layoutDocker.Render(context);
Expand Down Expand Up @@ -2344,7 +2343,7 @@ private void OnListBoxMeasureItem(object sender, MeasureItemEventArgs e)
UpdateContentFromItemIndex(e.Index);

// Ask the view element to layout in given space, needs this before a render call
using ViewLayoutContext context = new ViewLayoutContext(this, Renderer);
using var context = new ViewLayoutContext(this, Renderer);
Size size = _layoutDocker.GetPreferredSize(context);
e.ItemWidth = size.Width;
e.ItemHeight = size.Height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ private bool ShowDropDown()
}

// Package up the context menu and positioning values we will use later
ContextPositionMenuArgs cpma = new ContextPositionMenuArgs(null,
var cpma = new ContextPositionMenuArgs(null,
_kryptonContextMenu, GetPositionH(), GetPositionV());
// Let use examine and later values
OnDropDown(cpma);
Expand Down Expand Up @@ -1480,14 +1480,14 @@ private void DecideOnVisible(KryptonContextMenuItemBase visible, KryptonContextM
private void OnClickMoreColors(object sender, EventArgs e)
{
// Give user a chance to cancel showing the Krypton more colors dialog
CancelEventArgs cea = new CancelEventArgs();
var cea = new CancelEventArgs();
OnMoreColors(cea);

// If not instructed to cancel then...
if (!cea.Cancel)
{
// Use a Krypton color dialog for the selection of custom colors
KryptonColorDialog cd = new KryptonColorDialog
var cd = new KryptonColorDialog
{
Color = SelectedColor,
FullOpen = _allowFullOpen
Expand Down
Loading