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

* #1020 #1033

Merged
merged 16 commits into from
Jun 29, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ private class ViewToSize : Dictionary<ViewBase, Size> { }
#region Instance Fields
private readonly KryptonRibbon _ribbon;
private readonly KryptonRibbonGroupCluster _ribbonCluster;
private ViewDrawRibbonDesignCluster _viewAddItem;
private ViewDrawRibbonDesignCluster? _viewAddItem;
private readonly ViewDrawRibbonGroupClusterSeparator _startSep;
private readonly ViewDrawRibbonGroupClusterSeparator _endSep;
private readonly PaletteBorderEdge _paletteBorderEdge;
private PaletteRibbonShape _lastShape;
private readonly NeedPaintHandler _needPaint;
private PaletteRibbonShape? _lastShape;
private readonly NeedPaintHandler? _needPaint;
private ItemToView _itemToView;
private ViewToEdge _viewToEdge;
private readonly ViewToSize _viewToSizeMedium;
private readonly ViewToSize _viewToSizeSmall;
private GroupItemSize _currentSize;
private GroupItemSize? _currentSize;
private bool _startSepVisible;
private bool _endSepVisible;
#endregion
Expand Down Expand Up @@ -76,7 +76,7 @@ public ViewLayoutRibbonGroupCluster([DisallowNull] KryptonRibbon ribbon,
_endSepVisible = false;

// Create palette used to supply a width to a border edge view
PaletteBorderEdgeRedirect borderEdgeRedirect = new(_ribbon.StateCommon.RibbonGroupClusterButton.Border, needPaint);
PaletteBorderEdgeRedirect? borderEdgeRedirect = new(_ribbon.StateCommon.RibbonGroupClusterButton.Border, needPaint);
PWagner1 marked this conversation as resolved.
Show resolved Hide resolved
_paletteBorderEdge = new PaletteBorderEdge(borderEdgeRedirect, needPaint);
_lastShape = PaletteRibbonShape.Office2007;

Expand All @@ -93,7 +93,7 @@ public ViewLayoutRibbonGroupCluster([DisallowNull] KryptonRibbon ribbon,
// At design time we want to track the mouse and show feedback
if (_ribbon.InDesignMode)
{
ViewHightlightController controller = new(this, needPaint);
ViewHightlightController? controller = new(this, needPaint);
controller.ContextClick += OnContextClick;
MouseController = controller;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ protected override void Dispose(bool disposing)
/// <returns>ViewBase of item; otherwise false.</returns>
public ViewBase? GetFirstFocusItem()
{
ViewBase view = null;
ViewBase? view = null;

// Scan all the children, which must be items
foreach (ViewBase child in this)
Expand Down Expand Up @@ -164,7 +164,7 @@ protected override void Dispose(bool disposing)
/// <returns>ViewBase of item; otherwise false.</returns>
public ViewBase? GetLastFocusItem()
{
ViewBase view = null;
ViewBase? view = null;

// Scan all the children, which must be items
foreach (ViewBase child in Reverse())
Expand Down Expand Up @@ -199,7 +199,7 @@ protected override void Dispose(bool disposing)
/// <returns>ViewBase of item; otherwise false.</returns>
public ViewBase? GetNextFocusItem(ViewBase current, ref bool matched)
{
ViewBase view = null;
ViewBase? view = null;

// Scan all the children, which must be containers
foreach (ViewBase child in this)
Expand Down Expand Up @@ -235,7 +235,7 @@ protected override void Dispose(bool disposing)
/// <returns>ViewBase of item; otherwise false.</returns>
public ViewBase? GetPreviousFocusItem(ViewBase current, ref bool matched)
{
ViewBase view = null;
ViewBase? view = null;

// Scan all the children, which must be containers
foreach (ViewBase child in Reverse())
Expand Down Expand Up @@ -317,7 +317,7 @@ public void SetGroupItemSize(GroupItemSize size)

foreach (KryptonRibbonGroupItem item in _ribbonCluster.Items)
{
IRibbonViewGroupItemView viewItemSize = _itemToView[item] as IRibbonViewGroupItemView;
IRibbonViewGroupItemView? viewItemSize = _itemToView[item] as IRibbonViewGroupItemView;
viewItemSize?.SetGroupItemSize(size);
}

Expand All @@ -331,12 +331,12 @@ public void ResetGroupItemSize()
{
foreach (KryptonRibbonGroupItem item in _ribbonCluster.Items)
{
IRibbonViewGroupItemView viewItemSize = _itemToView[item] as IRibbonViewGroupItemView;
IRibbonViewGroupItemView? viewItemSize = _itemToView[item] as IRibbonViewGroupItemView;
viewItemSize?.ResetGroupItemSize();
}

// Our current size is based on the parent one
ViewLayoutRibbonGroupLines viewLines = (ViewLayoutRibbonGroupLines)Parent;
ViewLayoutRibbonGroupLines? viewLines = (ViewLayoutRibbonGroupLines)Parent;
_currentSize = viewLines.CurrentSize == GroupItemSize.Small ? GroupItemSize.Small : GroupItemSize.Medium;
}

Expand All @@ -349,12 +349,12 @@ public override Size GetPreferredSize(ViewLayoutContext context)
// Sync child elements to the current group items
SyncChildrenToRibbonGroupItems();

ViewToSize viewToSize;
ViewToSize? viewToSize;

viewToSize = _currentSize == GroupItemSize.Small ? _viewToSizeSmall : _viewToSizeMedium;

viewToSize.Clear();

Size preferredSize = Size.Empty;

// Find total width and maximum height across all child elements
Expand Down Expand Up @@ -406,7 +406,7 @@ public override void Layout([DisallowNull] ViewLayoutContext context)
// Are there any children to layout?
if (Count > 0)
{
ViewToSize viewToSize;
ViewToSize? viewToSize;

viewToSize = _currentSize == GroupItemSize.Small ? _viewToSizeSmall : _viewToSizeMedium;

Expand Down Expand Up @@ -506,14 +506,14 @@ private void SyncChildrenToRibbonGroupItems()
ViewToEdge regenEdge = new();

// Cache the first and last visible children
ViewBase viewFirst = null;
ViewBase viewLast = null;
ViewBase? viewFirst = null;
ViewBase? viewLast = null;

// Add a view element for each group item
foreach (IRibbonGroupItem item in _ribbonCluster.Items)
{
ViewBase itemView;
ViewDrawRibbonGroupClusterEdge itemEdge;
ViewBase? itemView;
ViewDrawRibbonGroupClusterEdge? itemEdge;

// Do we already have a view for this item definition
if (_itemToView.ContainsKey(item))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Krypton.Ribbon
internal class ViewLayoutRibbonGroups : ViewComposite
{
#region Classes
private class GroupToView : Dictionary<KryptonRibbonGroup, ViewDrawRibbonGroup> {}
private class GroupToView : Dictionary<KryptonRibbonGroup, ViewDrawRibbonGroup> { }
private class ViewDrawRibbonGroupSepList : List<ViewLayoutRibbonSeparator> { }
#endregion

Expand All @@ -32,7 +32,7 @@ private class ViewDrawRibbonGroupSepList : List<ViewLayoutRibbonSeparator> { }
#endregion

#region Instance Fields
private readonly KryptonRibbon _ribbon;
private readonly KryptonRibbon? _ribbon;
private readonly KryptonRibbonTab _ribbonTab;
private NeedPaintHandler _needPaint;
private ViewDrawRibbonDesignGroup _viewAddGroup;
Expand Down Expand Up @@ -184,7 +184,7 @@ public KeyTipInfo[] GetGroupKeyTips()
/// <returns>ViewBase of item; otherwise false.</returns>
public ViewBase? GetFirstFocusItem()
{
ViewBase view = null;
ViewBase? view = null;

// Search each group until one of them returns a focus item
foreach (ViewDrawRibbonGroup group in _groupToView.Values)
Expand All @@ -207,7 +207,7 @@ public KeyTipInfo[] GetGroupKeyTips()
/// <returns>ViewBase of item; otherwise false.</returns>
public ViewBase? GetLastFocusItem()
{
ViewBase view = null;
ViewBase? view = null;

var groups = new ViewDrawRibbonGroup[_groupToView.Count];
_groupToView.Values.CopyTo(groups, 0);
Expand All @@ -234,7 +234,7 @@ public KeyTipInfo[] GetGroupKeyTips()
/// <returns>ViewBase of item; otherwise false.</returns>
public ViewBase? GetNextFocusItem(ViewBase current)
{
ViewBase view = null;
ViewBase? view = null;
var matched = false;

// Search each group until one of them returns a focus item
Expand Down Expand Up @@ -262,7 +262,7 @@ public KeyTipInfo[] GetGroupKeyTips()
/// <returns>ViewBase of item; otherwise false.</returns>
public ViewBase? GetPreviousFocusItem(ViewBase current)
{
ViewBase view = null;
ViewBase? view = null;
var matched = false;

var groups = new ViewDrawRibbonGroup[_groupToView.Count];
Expand Down Expand Up @@ -384,9 +384,9 @@ private void SyncChildrenToRibbonGroups()

// Create a new lookup that reflects any changes in groups
GroupToView regenerate = new();

// Make sure we have a view element to match each group
foreach(KryptonRibbonGroup ribGroup in _ribbonTab.Groups)
foreach (KryptonRibbonGroup ribGroup in _ribbonTab.Groups)
{
ViewDrawRibbonGroup view = null;

Expand Down Expand Up @@ -439,7 +439,7 @@ private void SyncChildrenToRibbonGroups()

Add(_groupSepCache[i]);
Add(regenerate[ribbonGroup]);

// Remove entries we still are using
if (_groupToView.ContainsKey(ribbonGroup))
{
Expand All @@ -448,7 +448,7 @@ private void SyncChildrenToRibbonGroups()
}

// When in design time help mode
if (_ribbon.InDesignHelperMode)
if (_ribbon != null && _ribbon.InDesignHelperMode)
{
// Create the design time 'Add Group' first time it is needed
_viewAddGroup ??= new ViewDrawRibbonDesignGroup(_ribbon, _needPaint);
Expand All @@ -458,7 +458,7 @@ private void SyncChildrenToRibbonGroups()
}

// Dispose of views no longer required
foreach(ViewDrawRibbonGroup ribGroup in _groupToView.Values)
foreach (ViewDrawRibbonGroup ribGroup in _groupToView.Values)
{
ribGroup.Dispose();
}
Expand Down Expand Up @@ -502,7 +502,7 @@ private int AdjustGroupStateToMatchSpace(ViewLayoutContext context)

var bestWidth = 0;
var availableWidth = context.DisplayRectangle.Width;
int[] bestIndexes = null;
int[]? bestIndexes = null;
var permIndexes = new List<int>();

// Scan each horizontal slice of the 2D array of values
Expand Down