/*
* Virtual groups - Classes and interfaces needed to implement virtual groups
*
* Author: Phillip Piper
* Date: 28/08/2009 11:10am
*
* Change log:
* 2011-02-21 JPP - Correctly honor group comparer and collapsible groups settings
* v2.3
* 2009-08-28 JPP - Initial version
*
* To do:
*
* Copyright (C) 2009-2014 Phillip Piper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* If you wish to use this code in a closed source application, please contact phillip_piper@bigfoot.com.
*/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace BrightIdeasSoftware
{
///
/// A IVirtualGroups is the interface that a virtual list must implement to support virtual groups
///
public interface IVirtualGroups
{
///
/// Return the list of groups that should be shown according to the given parameters
///
///
///
IList GetGroups(GroupingParameters parameters);
///
/// Return the index of the item that appears at the given position within the given group.
///
///
///
///
int GetGroupMember(OLVGroup group, int indexWithinGroup);
///
/// Return the index of the group to which the given item belongs
///
///
///
int GetGroup(int itemIndex);
///
/// Return the index at which the given item is shown in the given group
///
///
///
///
int GetIndexWithinGroup(OLVGroup group, int itemIndex);
///
/// A hint that the given range of items are going to be required
///
///
///
///
///
void CacheHint(int fromGroupIndex, int fromIndex, int toGroupIndex, int toIndex);
}
///
/// This is a safe, do nothing implementation of a grouping strategy
///
public class AbstractVirtualGroups : IVirtualGroups
{
///
/// Return the list of groups that should be shown according to the given parameters
///
///
///
public virtual IList GetGroups(GroupingParameters parameters) {
return new List();
}
///
/// Return the index of the item that appears at the given position within the given group.
///
///
///
///
public virtual int GetGroupMember(OLVGroup group, int indexWithinGroup) {
return -1;
}
///
/// Return the index of the group to which the given item belongs
///
///
///
public virtual int GetGroup(int itemIndex) {
return -1;
}
///
/// Return the index at which the given item is shown in the given group
///
///
///
///
public virtual int GetIndexWithinGroup(OLVGroup group, int itemIndex) {
return -1;
}
///
/// A hint that the given range of items are going to be required
///
///
///
///
///
public virtual void CacheHint(int fromGroupIndex, int fromIndex, int toGroupIndex, int toIndex) {
}
}
///
/// Provides grouping functionality to a FastObjectListView
///
public class FastListGroupingStrategy : AbstractVirtualGroups
{
///
/// Create groups for FastListView
///
///
///
public override IList GetGroups(GroupingParameters parmameters) {
// There is a lot of overlap between this method and ObjectListView.MakeGroups()
// Any changes made here may need to be reflected there
// This strategy can only be used on FastObjectListViews
FastObjectListView folv = (FastObjectListView)parmameters.ListView;
// Separate the list view items into groups, using the group key as the descrimanent
int objectCount = 0;
NullableDictionary