this.OnSelectedIndexChanged(EventArgs.Empty);
}
- public void ChangeItemBackColor(int index, Color backColor)
- => this.ChangeSubItemBackColor(index, 0, backColor);
-
- public void ChangeItemForeColor(int index, Color foreColor)
- => this.ChangeSubItemForeColor(index, 0, foreColor);
-
- public void ChangeItemFont(int index, Font fnt)
- => this.ChangeSubItemFont(index, 0, fnt);
-
- public void ChangeItemFontAndColor(int index, Color foreColor, Font fnt)
- => this.ChangeSubItemStyles(index, 0, BackColor, foreColor, fnt);
-
- public void ChangeItemStyles(int index, Color backColor, Color foreColor, Font fnt)
- => this.ChangeSubItemStyles(index, 0, backColor, foreColor, fnt);
-
- public void ChangeSubItemBackColor(int itemIndex, int subitemIndex, Color backColor)
+ public void ChangeItemBackColor(ListViewItem item, Color backColor)
{
- var item = this.Items[itemIndex];
- item.SubItems[subitemIndex].BackColor = backColor;
- SetUpdateBounds(item, subitemIndex);
- this.Update();
- this.changeBounds = Rectangle.Empty;
- }
+ if (item.BackColor == backColor)
+ return;
- public void ChangeSubItemForeColor(int itemIndex, int subitemIndex, Color foreColor)
- {
- var item = this.Items[itemIndex];
- item.SubItems[subitemIndex].ForeColor = foreColor;
- SetUpdateBounds(item, subitemIndex);
+ item.BackColor = backColor;
+ SetUpdateBounds(item);
this.Update();
this.changeBounds = Rectangle.Empty;
}
- public void ChangeSubItemFont(int itemIndex, int subitemIndex, Font fnt)
+ public void ChangeItemForeColor(ListViewItem item, Color foreColor)
{
- var item = this.Items[itemIndex];
- item.SubItems[subitemIndex].Font = fnt;
- SetUpdateBounds(item, subitemIndex);
- this.Update();
- this.changeBounds = Rectangle.Empty;
- }
+ if (item.ForeColor == foreColor)
+ return;
- public void ChangeSubItemFontAndColor(int itemIndex, int subitemIndex, Color foreColor, Font fnt)
- {
- var item = this.Items[itemIndex];
- var subItem = item.SubItems[subitemIndex];
- subItem.ForeColor = foreColor;
- subItem.Font = fnt;
- SetUpdateBounds(item, subitemIndex);
+ item.ForeColor = foreColor;
+ SetUpdateBounds(item);
this.Update();
this.changeBounds = Rectangle.Empty;
}
- public void ChangeSubItemStyles(int itemIndex, int subitemIndex, Color backColor, Color foreColor, Font fnt)
+ public void ChangeItemFontAndColor(ListViewItem item, Color foreColor, Font fnt)
{
- var item = this.Items[itemIndex];
- var subItem = item.SubItems[subitemIndex];
- subItem.BackColor = backColor;
- subItem.ForeColor = foreColor;
- subItem.Font = fnt;
- SetUpdateBounds(item, subitemIndex);
+ if (item.ForeColor == foreColor && item.Font == fnt)
+ return;
+
+ item.ForeColor = foreColor;
+ item.Font = fnt;
+ SetUpdateBounds(item);
this.Update();
this.changeBounds = Rectangle.Empty;
}
- private void SetUpdateBounds(ListViewItem item, int subItemIndex)
+ private void SetUpdateBounds(ListViewItem item)
{
try
{
- if (subItemIndex > this.Columns.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(subItemIndex));
- }
- if (item.UseItemStyleForSubItems)
- {
- this.changeBounds = item.Bounds;
- }
- else
- {
- this.changeBounds = this.GetSubItemBounds(item, subItemIndex);
- }
+ this.changeBounds = item.Bounds;
}
catch (ArgumentException)
{
}
}
- private Rectangle GetSubItemBounds(ListViewItem item, int subitemIndex)
- {
- if (subitemIndex == 0 && this.Columns.Count > 0)
- {
- Rectangle col0 = item.Bounds;
- return new Rectangle(col0.Left, col0.Top, item.SubItems[1].Bounds.X + 1, col0.Height);
- }
- else
- {
- return item.SubItems[subitemIndex].Bounds;
- }
- }
-
[StructLayout(LayoutKind.Sequential)]
private struct NMHDR
{
/// <summary>キャッシュする範囲の終了インデックス</summary>
public int EndIndex { get; set; }
- /// <summary>キャッシュされた <see cref="ListViewItem"/> インスタンス</summary>
- public ListViewItem[] ListItem { get; set; }
-
- /// <summary>キャッシュされた範囲に対応する <see cref="PostClass"/> インスタンス</summary>
- public PostClass[] Post { get; set; }
+ /// <summary>キャッシュされた範囲に対応する <see cref="ListViewItem"/> と <see cref="PostClass"/> の組</summary>
+ public (ListViewItem, PostClass)[] Cache { get; set; }
/// <summary>キャッシュされたアイテムの件数</summary>
public int Count
{
if (this.Contains(index))
{
- item = this.ListItem[index - this.StartIndex];
- post = this.Post[index - this.StartIndex];
+ (item, post) = this.Cache[index - this.StartIndex];
return true;
}
else
{
DList.Update();
if (SettingManager.Common.UseUnreadStyle)
- DList.ChangeItemFontAndColor(Item.Index, cl, fnt);
+ DList.ChangeItemFontAndColor(Item, cl, fnt);
else
- DList.ChangeItemForeColor(Item.Index, cl);
+ DList.ChangeItemForeColor(Item, cl);
//if (_itemCache != null) DList.RedrawItems(_itemCacheIndex, _itemCacheIndex + _itemCache.Length - 1, false);
}
}
if (listCache == null)
return;
- var index = listCache.StartIndex;
var listView = (DetailsListView)listCache.TargetList;
- foreach (var cachedPost in listCache.Post)
+ foreach (var (listViewItem, cachedPost) in listCache.Cache)
{
var backColor = this.JudgeColor(_post, cachedPost);
- listView.ChangeItemBackColor(index++, backColor);
+ listView.ChangeItemBackColor(listViewItem, backColor);
}
}
- private void ColorizeList(ListViewItem Item, int Index)
+ private void ColorizeList(ListViewItem Item, PostClass post, int Index)
{
//Index:更新対象のListviewItem.Index。Colorを返す。
//-1は全キャッシュ。Colorは返さない(ダミーを戻す)
else
_post = this.CurrentPost;
- PostClass tPost = GetCurTabPost(Index);
-
if (_post == null) return;
if (Item.Index == -1)
- Item.BackColor = JudgeColor(_post, tPost);
+ Item.BackColor = JudgeColor(_post, post);
else
- this.CurrentListView.ChangeItemBackColor(Item.Index, JudgeColor(_post, tPost));
+ this.CurrentListView.ChangeItemBackColor(Item, JudgeColor(_post, post));
}
private Color JudgeColor(PostClass BasePost, PostClass TargetPost)
TargetList = this.CurrentListView,
StartIndex = startIndex,
EndIndex = endIndex,
- Post = posts,
- ListItem = listItems,
+ Cache = Enumerable.Zip(listItems, posts, (x, y) => (x, y)).ToArray(),
};
Interlocked.Exchange(ref this._listItemCache, listCache);
ChangeItemStyleRead(read, itm, Post, null);
if (tab.TabName == this.CurrentTabName)
- this.ColorizeList(itm, Index);
+ this.ColorizeList(itm, Post, Index);
return itm;
}