private void UpdateGroups()
{
if (!mImageListView.showGroups)
return;
int x = mItemAreaBounds.Left - mImageListView.ViewOffset.X;
int y = mItemAreaBounds.Top - mImageListView.ViewOffset.Y;
if (mImageListView.View == View.Gallery)
{
totalWidth = 0;
totalHeight = mItemAreaBounds.Height;
}
else if (mImageListView.View == View.Details)
{
totalHeight = 0;
}
else
{
totalHeight = 0;
totalWidth = mItemAreaBounds.Width;
}
foreach (ImageListView.ImageListViewGroup group in mImageListView.groups)
{
if (mImageListView.View == View.Gallery)
{
// Number of rows and columns to enclose all items
group.itemRows = mDisplayedRows;
group.itemCols = (int)System.Math.Ceiling((float)group.ItemCount / (float)mDisplayedRows);
// Header area
group.headerBounds = new Rectangle(x, y, cachedGroupHeaderHeight, mItemSize.Height * mDisplayedRows);
x += cachedGroupHeaderHeight;
// Item area
group.itemBounds = new Rectangle(x, y, group.itemCols * mItemSizeWithMargin.Width, group.itemRows * mItemSizeWithMargin.Height);
if (group.Collapsed)
group.itemBounds.Width = 0;
// Update total size
totalWidth += group.headerBounds.Width + group.itemBounds.Width;
// Offset to next group
x += group.itemBounds.Width;
}
else
{
// Number of rows and columns to enclose all items
group.itemCols = mDisplayedCols;
group.itemRows = (int)System.Math.Ceiling((float)group.ItemCount / (float)mDisplayedCols);
// Header area
group.headerBounds = new Rectangle(x, y, mClientArea.Width + mImageListView.ViewOffset.X, cachedGroupHeaderHeight);
y += cachedGroupHeaderHeight;
// Item area
group.itemBounds = new Rectangle(x, y, group.itemCols * mItemSizeWithMargin.Width, group.itemRows * mItemSizeWithMargin.Height);
if (group.Collapsed)
group.itemBounds.Height = 0;
// Update total size
totalHeight += group.headerBounds.Height + group.itemBounds.Height;
// Offset to next group
y += group.itemBounds.Height;
}
group.isVisible = ItemAreaBounds.IntersectsWith(group.headerBounds) || ItemAreaBounds.IntersectsWith(group.itemBounds);
}
// Groups processed
mImageListView.groups.collectionModified = false;
}