office-gobmx/sc/inc/dpgroup.hxx

231 lines
8.8 KiB
C++
Raw Normal View History

/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: dpgroup.hxx,v $
*
* $Revision: 1.4 $
*
* last change: $Author: rt $ $Date: 2005-09-08 17:34:35 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
#ifndef SC_DPGROUP_HXX
#define SC_DPGROUP_HXX
#include <vector>
#ifndef SC_DPTABDAT_HXX
#include "dptabdat.hxx"
#endif
class ScDocument;
class SvNumberFormatter;
// --------------------------------------------------------------------
//! API struct?
struct ScDPNumGroupInfo
{
sal_Bool Enable;
sal_Bool DateValues;
sal_Bool AutoStart;
sal_Bool AutoEnd;
double Start;
double End;
double Step;
ScDPNumGroupInfo() : Enable(sal_False), DateValues(sal_False), AutoStart(sal_False), AutoEnd(sal_False),
Start(0.0), End(0.0), Step(0.0) {}
};
// --------------------------------------------------------------------
// ScDPDateGroupHelper is used as part of ScDPGroupDimension (additional dim.)
// or ScDPNumGroupDimension (innermost, replaces the original dim.).
// Source index, name and result collection are stored at the parent.
class ScDPDateGroupHelper
{
ScDPNumGroupInfo aNumInfo; // only start and end (incl. auto flags) are used
sal_Int32 nDatePart; // single part
public:
ScDPDateGroupHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
~ScDPDateGroupHelper();
sal_Int32 GetDatePart() const { return nDatePart; }
const ScDPNumGroupInfo& GetNumInfo() const { return aNumInfo; }
void FillColumnEntries( TypedStrCollection& rEntries, const TypedStrCollection& rOriginal,
SvNumberFormatter* pFormatter ) const;
};
// --------------------------------------------------------------------
typedef ::std::vector<ScDPItemData> ScDPItemDataVec;
class ScDPGroupItem
{
ScDPItemData aGroupName; // name of group item
ScDPItemDataVec aElements; // names of items in original dimension
public:
ScDPGroupItem( const ScDPItemData& rName );
~ScDPGroupItem();
void AddElement( const ScDPItemData& rName );
const ScDPItemData& GetName() const { return aGroupName; }
bool HasElement( const ScDPItemData& rData ) const;
bool HasCommonElement( const ScDPGroupItem& rOther ) const;
};
typedef ::std::vector<ScDPGroupItem> ScDPGroupItemVec;
class ScDPGroupDimension
{
long nSourceDim;
long nGroupDim;
String aGroupName;
ScDPDateGroupHelper* pDateHelper;
ScDPGroupItemVec aItems;
mutable TypedStrCollection* pCollection; // collection of item names (cached)
public:
ScDPGroupDimension( long nSource, const String& rNewName );
ScDPGroupDimension( const ScDPGroupDimension& rOther );
~ScDPGroupDimension();
ScDPGroupDimension& operator=( const ScDPGroupDimension& rOther );
void AddItem( const ScDPGroupItem& rItem );
void SetGroupDim( long nDim ); // called from AddGroupDimension
long GetSourceDim() const { return nSourceDim; }
long GetGroupDim() const { return nGroupDim; }
const String& GetName() const { return aGroupName; }
const TypedStrCollection& GetColumnEntries( const TypedStrCollection& rOriginal, ScDocument* pDoc ) const;
const ScDPGroupItem* GetGroupForData( const ScDPItemData& rData ) const; // rData = entry in original dim.
const ScDPGroupItem* GetGroupForName( const ScDPItemData& rName ) const; // rName = entry in group dim.
const ScDPDateGroupHelper* GetDateHelper() const { return pDateHelper; }
void MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
void DisposeData();
};
typedef ::std::vector<ScDPGroupDimension> ScDPGroupDimensionVec;
// --------------------------------------------------------------------
class ScDPNumGroupDimension
{
ScDPNumGroupInfo aGroupInfo; // settings
ScDPDateGroupHelper* pDateHelper;
mutable TypedStrCollection* pCollection; // collection of item names (cached)
mutable bool bHasNonInteger; // initialized in GetNumEntries
mutable sal_Unicode cDecSeparator; // initialized in GetNumEntries
public:
ScDPNumGroupDimension();
ScDPNumGroupDimension( const ScDPNumGroupInfo& rInfo );
ScDPNumGroupDimension( const ScDPNumGroupDimension& rOther );
~ScDPNumGroupDimension();
ScDPNumGroupDimension& operator=( const ScDPNumGroupDimension& rOther );
const TypedStrCollection& GetNumEntries( const TypedStrCollection& rOriginal, ScDocument* pDoc ) const;
const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; }
bool HasNonInteger() const { return bHasNonInteger; }
sal_Unicode GetDecSeparator() const { return cDecSeparator; }
const ScDPDateGroupHelper* GetDateHelper() const { return pDateHelper; }
void MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
void DisposeData();
};
// --------------------------------------------------------------------
//
// proxy implementation of ScDPTableData to add grouped items
//
class ScDPGroupTableData : public ScDPTableData
{
ScDPTableData* pSourceData;
long nSourceCount;
ScDPGroupDimensionVec aGroups;
ScDPNumGroupDimension* pNumGroups; // array[nSourceCount]
ScDocument* pDoc;
void FillGroupValues( ScDPItemData* pItemData, long nCount, const long* pDims );
long* CopyFields( const long* pSourceDims, long nCount );
bool IsNumGroupDimension( long nDimension ) const;
void GetNumGroupInfo( long nDimension, ScDPNumGroupInfo& rInfo,
bool& rNonInteger, sal_Unicode& rDecimal );
public:
// takes ownership of pSource
ScDPGroupTableData( ScDPTableData* pSource, ScDocument* pDocument );
virtual ~ScDPGroupTableData();
void AddGroupDimension( const ScDPGroupDimension& rGroup );
void SetNumGroupDimension( long nIndex, const ScDPNumGroupDimension& rGroup );
long GetDimensionIndex( const String& rName );
ScDocument* GetDocument() { return pDoc; }
virtual long GetColumnCount();
virtual const TypedStrCollection& GetColumnEntries(long nColumn);
virtual String getDimensionName(long nColumn);
virtual BOOL getIsDataLayoutDimension(long nColumn);
virtual BOOL IsDateDimension(long nDim);
virtual UINT32 GetNumberFormat(long nDim);
virtual void DisposeData();
virtual void SetEmptyFlags( BOOL bIgnoreEmptyRows, BOOL bRepeatIfEmpty );
virtual void ResetIterator();
virtual BOOL GetNextRow( const ScDPTableIteratorParam& rParam );
virtual BOOL IsBaseForGroup(long nDim) const;
virtual long GetGroupBase(long nGroupDim) const;
virtual BOOL IsNumOrDateGroup(long nDim) const;
virtual BOOL IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
const ScDPItemData& rBaseData, long nBaseIndex ) const;
virtual BOOL HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
const ScDPItemData& rSecondData, long nSecondIndex ) const;
};
#endif