williamr@2: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@2: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: // Written by DanH, Sept 1995 williamr@2: #if !defined(__BACELL_H__) williamr@2: #define __BACELL_H__ williamr@2: williamr@2: #if !defined(__E32DEF_H_) williamr@2: #include williamr@2: #endif williamr@2: williamr@2: #if !defined(__S32STRM_H__) williamr@2: #include williamr@2: #endif williamr@2: williamr@2: //class RReadStream; williamr@2: //class RWriteStream; williamr@2: williamr@2: class TCellRef williamr@2: /** williamr@2: Identifies a cell by row and column number. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: inline TCellRef(); williamr@2: inline TCellRef(TInt aRow,TInt aCol); williamr@2: williamr@2: inline TBool operator==(const TCellRef& aCell) const; williamr@2: inline TBool operator!=(const TCellRef& aCell) const; williamr@2: williamr@2: inline TCellRef& operator+=(const TCellRef& aCell); williamr@2: inline TCellRef& operator-=(const TCellRef& aCell); williamr@2: williamr@2: IMPORT_C void Offset(TInt aRowOffset,TInt aColOffset); williamr@2: // williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream); williamr@2: inline void ExternalizeL(RWriteStream& aStream) const; williamr@2: public: williamr@2: /** The row number. */ williamr@2: TInt iRow; williamr@2: /** The column number. */ williamr@2: TInt iCol; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: IMPORT_C TCellRef operator+(const TCellRef& aLeft,const TCellRef& aRight); williamr@2: IMPORT_C TCellRef operator-(const TCellRef& aLeft,const TCellRef& aRight); williamr@2: williamr@2: inline TCellRef::TCellRef() williamr@2: /** Default constructor. williamr@2: williamr@2: The object's row and column number are undefined. */ williamr@2: {} williamr@2: inline TCellRef::TCellRef(TInt aRow,TInt aCol) williamr@2: : iRow(aRow),iCol(aCol) williamr@2: /** Constructor taking a row and column number. williamr@2: williamr@2: @param aRow The row number. williamr@2: @param aCol The column number. */ williamr@2: {} williamr@2: inline TBool TCellRef::operator==(const TCellRef& aCell) const williamr@2: /** Compares this cell with the specified cell for equality. williamr@2: williamr@2: @param aCell The cell to be compared. williamr@2: @return ETrue, if the row numbers are the same and column numbers are williamr@2: the same. */ williamr@2: {return aCell.iRow==iRow && aCell.iCol==iCol;} williamr@2: inline TBool TCellRef::operator!=(const TCellRef& aCell) const williamr@2: /** Compares this cell with the specified cell for inequality. williamr@2: williamr@2: @param aCell The cell to be compared. williamr@2: @return ETrue, if the row numbers are different or the column numbers are williamr@2: different. */ williamr@2: {return aCell.iRow!=iRow || aCell.iCol!=iCol;} williamr@2: inline TCellRef& TCellRef::operator+=(const TCellRef& aCell) williamr@2: /** Adds the specified cell to this cell. williamr@2: williamr@2: Addition is the process of adding the specified cell's row and column williamr@2: numbers to this cell's row and column numbers respectively. williamr@2: williamr@2: @param aCell The cell to be added. williamr@2: @return A reference to this cell object. */ williamr@2: {Offset(aCell.iRow,aCell.iCol);return *this;} williamr@2: inline TCellRef& TCellRef::operator-=(const TCellRef& aCell) williamr@2: /** Subtracts the specified cell from this cell. williamr@2: williamr@2: Subtraction is the process of subtracting the specified cell's row and williamr@2: column numbers from this cell's row and column numbers respectively. williamr@2: williamr@2: @param aCell The cell to be subtracted. williamr@2: @return A reference to this cell object. */ williamr@2: {Offset(-aCell.iRow,-aCell.iCol);return *this;} williamr@2: inline void TCellRef::ExternalizeL(RWriteStream& aStream) const williamr@2: /** Externalises an object of this class to a write stream. williamr@2: williamr@2: The presence of this function means that the standard templated operator<<() williamr@2: can be used to externalise objects of this class. williamr@2: williamr@2: @param aStream Stream to which the object should be externalised. */ williamr@2: {aStream.WriteInt32L(iRow);aStream.WriteInt32L(iCol);} williamr@2: williamr@2: williamr@2: class TRangeRef williamr@2: /** williamr@2: Identifies a range of cells by start and end cell references. williamr@2: The range is inclusive of both the start and end cells. williamr@2: @see TCellRef williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: inline TRangeRef(); williamr@2: inline TRangeRef(const TCellRef& aFrom,const TCellRef& aTo); williamr@2: inline TRangeRef(TInt aFromRow,TInt aFromCol,TInt aToRow,TInt aToCol); williamr@2: williamr@2: IMPORT_C TBool operator==(const TRangeRef& aRange) const; williamr@2: inline TBool operator!=(const TRangeRef& aRange) const; williamr@2: williamr@2: inline void SetRange(const TCellRef& aFrom,const TCellRef& aTo); williamr@2: inline void SetRange(TInt aFromRow,TInt aFromCol,TInt aToRow,TInt aToCol); williamr@2: inline TInt NoRows() const; williamr@2: inline TInt NoCols() const; williamr@2: IMPORT_C TInt NoCells() const; williamr@2: IMPORT_C TBool Contains(const TCellRef& aCell) const; williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream); williamr@2: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; williamr@2: public: williamr@2: /** The start cell. */ williamr@2: TCellRef iFrom; williamr@2: /** The end cell. */ williamr@2: TCellRef iTo; williamr@2: public: williamr@2: class TIter; // defined outside TRangeRef class as contains TRangeRef williamr@2: }; williamr@2: class TRangeRef::TIter williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TIter(const TRangeRef& aRangeRef); williamr@2: IMPORT_C TBool operator++(); williamr@2: inline TBool InRange() const; williamr@2: public: williamr@2: TCellRef iCurrent; williamr@2: private: williamr@2: TRangeRef iRange; williamr@2: }; williamr@2: williamr@2: williamr@2: inline TRangeRef::TRangeRef() williamr@2: /** Default constructor. williamr@2: williamr@2: The object's start cell and end cell are undefined. */ williamr@2: {} williamr@2: inline TRangeRef::TRangeRef(const TCellRef& aFrom,const TCellRef& aTo) williamr@2: : iFrom(aFrom),iTo(aTo) williamr@2: /** Constructor taking a start and end cell. williamr@2: williamr@2: @param aFrom The start cell. williamr@2: @param aTo The end cell. */ williamr@2: {} williamr@2: inline TRangeRef::TRangeRef(TInt aFromRow,TInt aFromCol,TInt aToRow,TInt aToCol) williamr@2: : iFrom(aFromRow,aFromCol),iTo(aToRow,aToCol) williamr@2: /** Constructor taking a start row and start column number, and an end row and williamr@2: end column number. williamr@2: williamr@2: @param aFromRow The start row number. williamr@2: @param aFromCol The start column number. williamr@2: @param aToRow The end row number. williamr@2: @param aToCol The end column number. */ williamr@2: {} williamr@2: inline void TRangeRef::SetRange(const TCellRef& aFrom,const TCellRef& aTo) williamr@2: /** Sets the cell range to the specified cells. williamr@2: williamr@2: @param aFrom The start cell for the range. williamr@2: @param aTo The end cell for the range. */ williamr@2: {iFrom=aFrom;iTo=aTo;} williamr@2: inline void TRangeRef::SetRange(TInt aFromRow,TInt aFromCol,TInt aToRow,TInt aToCol) williamr@2: /** Sets the cell range to the specified start row and column, and end row williamr@2: and column. williamr@2: williamr@2: @param aFromRow The start row number. williamr@2: @param aFromCol The start column number. williamr@2: @param aToRow The end row number. williamr@2: @param aToCol The end column number. */ williamr@2: {iFrom.iRow=aFromRow;iFrom.iCol=aFromCol;iTo.iRow=aToRow;iTo.iCol=aToCol;} williamr@2: inline TBool TRangeRef::operator!=(const TRangeRef& aRange) const williamr@2: /** Compares this cell range with the specified cell range for inequality. williamr@2: williamr@2: @param aRange The cell to be compared. williamr@2: @return ETrue, if the start cells are different or the end cells are williamr@2: different. */ williamr@2: {return !operator==(aRange);} williamr@2: inline TInt TRangeRef::NoRows() const williamr@2: /** Gets the number of rows represented by the range. williamr@2: williamr@2: @return The number of rows. */ williamr@2: {return iTo.iRow - iFrom.iRow + 1;} williamr@2: inline TInt TRangeRef::NoCols() const williamr@2: /** Gets the number of columns represented by the range. williamr@2: williamr@2: @return The number of columns. */ williamr@2: {return iTo.iCol - iFrom.iCol + 1;} williamr@2: inline TBool TRangeRef::TIter::InRange() const williamr@2: {return iRange.Contains(iCurrent);} williamr@2: williamr@2: #endif