use tools::Long in sc

Change-Id: I8f37a8d1174ed816df971b8cee036d4e88d4a7fc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104526
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/sc/inc/ChartTools.hxx b/sc/inc/ChartTools.hxx
index 10217f9..79aa00f 100644
--- a/sc/inc/ChartTools.hxx
+++ b/sc/inc/ChartTools.hxx
@@ -16,6 +16,7 @@

#include <svx/svditer.hxx>
#include <rtl/ustring.hxx>
#include <tools/long.hxx>

#include "types.hxx"

@@ -45,7 +46,7 @@ SdrOle2Obj* findChartsByName(ScDocShell* pDocShell, SCTAB nTab,
                             ChartSourceType eChartSourceType);

SdrOle2Obj* getChartByIndex(ScDocShell* pDocShell, SCTAB nTab,
                            long nIndex, ChartSourceType eChartSourceType);
                            ::tools::Long nIndex, ChartSourceType eChartSourceType);

std::vector<SdrOle2Obj*> getAllPivotChartsConnectedTo(OUString const & sPivotTableName, ScDocShell* pDocShell);

diff --git a/sc/inc/addincol.hxx b/sc/inc/addincol.hxx
index 4114599..9ef43a0 100644
--- a/sc/inc/addincol.hxx
+++ b/sc/inc/addincol.hxx
@@ -28,6 +28,7 @@
#include <i18nlangtag/lang.h>
#include "scdllapi.h"
#include <rtl/ustring.hxx>
#include <tools/long.hxx>

#include "types.hxx"

@@ -88,10 +89,10 @@ private:
    OUString            aDescription;
    css::uno::Reference< css::reflection::XIdlMethod> xFunction;
    css::uno::Any       aObject;
    long                nArgCount;
    tools::Long                nArgCount;
    std::unique_ptr<ScAddInArgDesc[]>
                        pArgDescs;
    long                nCallerPos;
    tools::Long                nCallerPos;
    sal_uInt16          nCategory;
    OString             sHelpId;
    mutable ::std::vector< LocalizedName > maCompNames;
@@ -103,8 +104,8 @@ public:
                                    sal_uInt16 nCat, const OString&,
                                    const css::uno::Reference< css::reflection::XIdlMethod>& rFunc,
                                    const css::uno::Any& rO,
                                    long nAC, const ScAddInArgDesc* pAD,
                                    long nCP );
                                    tools::Long nAC, const ScAddInArgDesc* pAD,
                                    tools::Long nCP );
                ~ScUnoAddInFuncData();

    const OUString&  GetOriginalName() const     { return aOriginalName; }
@@ -114,9 +115,9 @@ public:
    const css::uno::Reference< css::reflection::XIdlMethod>&   GetFunction() const
                                                        { return xFunction; }
    const css::uno::Any& GetObject() const   { return aObject; }
    long                    GetArgumentCount() const    { return nArgCount; }
    tools::Long                    GetArgumentCount() const    { return nArgCount; }
    const ScAddInArgDesc*   GetArguments() const        { return pArgDescs.get(); }
    long                    GetCallerPos() const        { return nCallerPos; }
    tools::Long                    GetCallerPos() const        { return nCallerPos; }
    const OUString&         GetDescription() const      { return aDescription; }
    sal_uInt16              GetCategory() const         { return nCategory; }
    const OString&          GetHelpId() const           { return sHelpId; }
@@ -126,15 +127,15 @@ public:

    void    SetFunction( const css::uno::Reference< css::reflection::XIdlMethod>& rNewFunc,
                         const css::uno::Any& rNewObj );
    void    SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs );
    void    SetCallerPos( long nNewPos );
    void    SetArguments( tools::Long nNewCount, const ScAddInArgDesc* pNewDescs );
    void    SetCallerPos( tools::Long nNewPos );
    void    SetCompNames( const ::std::vector< LocalizedName >& rNew );
};

class SC_DLLPUBLIC ScUnoAddInCollection
{
private:
    long                    nFuncCount;
    tools::Long                    nFuncCount;
    std::unique_ptr<std::unique_ptr<ScUnoAddInFuncData>[]> ppFuncData;
    std::unique_ptr<ScAddInHashMap>       pExactHashMap;      ///< exact internal name
    std::unique_ptr<ScAddInHashMap>       pNameHashMap;       ///< internal name upper
@@ -164,14 +165,14 @@ public:
                            @param nIndex
                                0 <= nIndex < GetFuncCount()
                         */
    const ScUnoAddInFuncData*   GetFuncData( long nIndex );
    const ScUnoAddInFuncData*   GetFuncData( tools::Long nIndex );

    void                Clear();

    void                LocalizeString( OUString& rName );    ///< modify rName - input: exact name

    long                GetFuncCount();
    bool                FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
    tools::Long                GetFuncCount();
    bool                FillFunctionDesc( tools::Long nFunc, ScFuncDesc& rDesc );

    static bool         FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc );
                  /// leave rRetExcelName unchanged, if no matching name is found
@@ -201,7 +202,7 @@ private:
public:
                    // exact name
                    ScUnoAddInCall( ScUnoAddInCollection& rColl, const OUString& rName,
                                    long nParamCount );
                                    tools::Long nParamCount );
                    ~ScUnoAddInCall();

    bool                NeedsCaller() const;
@@ -209,8 +210,8 @@ public:
    void                SetCallerFromObjectShell( const SfxObjectShell* pSh );

    bool                ValidParamCount() { return bValidCount;}
    ScAddInArgumentType GetArgType( long nPos );
    void                SetParam( long nPos, const css::uno::Any& rValue );
    ScAddInArgumentType GetArgType( tools::Long nPos );
    void                SetParam( tools::Long nPos, const css::uno::Any& rValue );

    void                ExecuteCall();

diff --git a/sc/inc/attarray.hxx b/sc/inc/attarray.hxx
index 7489cbc..db18d87 100644
--- a/sc/inc/attarray.hxx
+++ b/sc/inc/attarray.hxx
@@ -191,7 +191,7 @@ public:

    void    SetPatternAreaSafe( SCROW nStartRow, SCROW nEndRow,
                                    const ScPatternAttr* pWantedPattern, bool bDefault );
    void    CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttrArray& rAttrArray );
    void    CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray );

    bool    IsEmpty() const;

@@ -210,7 +210,7 @@ public:
    void    DeleteArea( SCROW nStartRow, SCROW nEndRow );
    void    MoveTo( SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray );
    void    CopyArea(
        SCROW nStartRow, SCROW nEndRow, long nDy, ScAttrArray& rAttrArray, ScMF nStripFlags = ScMF::NONE) const;
        SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray, ScMF nStripFlags = ScMF::NONE) const;

    void    DeleteHardAttr( SCROW nStartRow, SCROW nEndRow );

diff --git a/sc/inc/cellsuno.hxx b/sc/inc/cellsuno.hxx
index aeefac9..267c688 100644
--- a/sc/inc/cellsuno.hxx
+++ b/sc/inc/cellsuno.hxx
@@ -198,7 +198,7 @@ private:

private:
    void            PaintGridRanges_Impl();
    ScRangeListRef  GetLimitedChartRanges_Impl( long nDataColumns, long nDataRows ) const;
    ScRangeListRef  GetLimitedChartRanges_Impl( tools::Long nDataColumns, tools::Long nDataRows ) const;
    void            ForceChartListener_Impl();
    std::unique_ptr<ScMemChart> CreateMemChart_Impl() const;

@@ -1096,7 +1096,7 @@ private:
    ScRange                 aTotalRange;

private:
    ScCellRangeObj*         GetObjectByIndex_Impl(long nIndex) const;
    ScCellRangeObj*         GetObjectByIndex_Impl(tools::Long nIndex) const;

public:
                            ScCellFormatsObj(ScDocShell* pDocSh, const ScRange& rR);
diff --git a/sc/inc/chartuno.hxx b/sc/inc/chartuno.hxx
index e59a9ac..aac210f 100644
--- a/sc/inc/chartuno.hxx
+++ b/sc/inc/chartuno.hxx
@@ -50,7 +50,7 @@ private:
    ScDocShell*             pDocShell;
    SCTAB                   nTab;           // Charts are per sheet

    ScChartObj*             GetObjectByIndex_Impl(long nIndex) const;
    ScChartObj*             GetObjectByIndex_Impl(tools::Long nIndex) const;
    ScChartObj*             GetObjectByName_Impl(const OUString& aName) const;

public:
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 40298a3..3adca37 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -279,7 +279,7 @@ public:
    void CopyOneCellFromClip( sc::CopyFromClipContext& rCxt, SCROW nRow1, SCROW nRow2, size_t nColOffset );

    void CopyFromClip(
        sc::CopyFromClipContext& rCxt, SCROW nRow1, SCROW nRow2, long nDy, ScColumn& rColumn );
        sc::CopyFromClipContext& rCxt, SCROW nRow1, SCROW nRow2, tools::Long nDy, ScColumn& rColumn );

    void        RemoveEditAttribs( SCROW nStartRow, SCROW nEndRow );

@@ -516,7 +516,7 @@ public:
    void        ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark );
    void        ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark );

    long GetNeededSize(
    tools::Long GetNeededSize(
        SCROW nRow, OutputDevice* pDev, double nPPTX, double nPPTY,
        const Fraction& rZoomX, const Fraction& rZoomY,
        bool bWidth, const ScNeededSizeOptions& rOptions, const ScPatternAttr** pPatternChange,
diff --git a/sc/inc/datauno.hxx b/sc/inc/datauno.hxx
index 6f7688c..b3d27827 100644
--- a/sc/inc/datauno.hxx
+++ b/sc/inc/datauno.hxx
@@ -80,7 +80,7 @@ public:
    static void FillProperties(
                    css::uno::Sequence<css::beans::PropertyValue>& rSeq,
                    const ScImportParam& rParam );
    static long GetPropertyCount() { return 4; }
    static tools::Long GetPropertyCount() { return 4; }
};

//  SortDescriptor is not available as Uno-object any longer, only Property-Sequence
@@ -95,7 +95,7 @@ public:
                    css::uno::Sequence<css::beans::PropertyValue>& rSeq,
                    const ScSortParam& rParam );
    //! SortAscending needs to get out of the SheetSortDescriptor service description
    static long GetPropertyCount()
    static tools::Long GetPropertyCount()
    {
        return 9;       // TableSortDescriptor and SheetSortDescriptor
    }
diff --git a/sc/inc/dbdocutl.hxx b/sc/inc/dbdocutl.hxx
index 759490e..a5600cc 100644
--- a/sc/inc/dbdocutl.hxx
+++ b/sc/inc/dbdocutl.hxx
@@ -22,6 +22,7 @@

#include "types.hxx"
#include <sal/types.h>
#include <tools/long.hxx>

class ScDocument;
namespace com::sun::star::uno { template <typename > class Reference; }
@@ -42,8 +43,8 @@ public:
    };
    static void PutData( ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab,
                        const css::uno::Reference< css::sdbc::XRow>& xRow,
                        long nRowPos,
                        long nType, bool bCurrency, StrData* pStrData = nullptr );
                        tools::Long nRowPos,
                        tools::Long nType, bool bCurrency, StrData* pStrData = nullptr );
};

#endif
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 7fcb3af..edc0447 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1913,7 +1913,7 @@ public:

    void                        UpdateAllRowHeights( sc::RowHeightContext& rCxt, const ScMarkData* pTabMark );

    long                        GetNeededSize( SCCOL nCol, SCROW nRow, SCTAB nTab,
    tools::Long                        GetNeededSize( SCCOL nCol, SCROW nRow, SCTAB nTab,
                                               OutputDevice* pDev,
                                               double nPPTX, double nPPTY,
                                               const Fraction& rZoomX, const Fraction& rZoomY,
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index 3f63b66..44fdc34 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -305,8 +305,8 @@ public:
                            int nOutputHeight,
                            int nTilePosX,
                            int nTilePosY,
                            long nTileWidth,
                            long nTileHeight ) override;
                            tools::Long nTileWidth,
                            tools::Long nTileHeight ) override;

    /// @see vcl::ITiledRenderable::getDocumentSize().
    virtual Size getDocumentSize() override;
diff --git a/sc/inc/dpcache.hxx b/sc/inc/dpcache.hxx
index 9265046..c77ac6e 100644
--- a/sc/inc/dpcache.hxx
+++ b/sc/inc/dpcache.hxx
@@ -27,6 +27,7 @@
#include "types.hxx"

#include <mdds/flat_segment_tree.hpp>
#include <tools/long.hxx>

#include <memory>
#include <set>
@@ -97,12 +98,12 @@ public:
    class DBConnector
    {
    public:
        virtual long getColumnCount() const = 0;
        virtual OUString getColumnLabel(long nCol) const = 0;
        virtual tools::Long getColumnCount() const = 0;
        virtual OUString getColumnLabel(tools::Long nCol) const = 0;
        virtual bool first() = 0;
        virtual bool next() = 0;
        virtual void finish() = 0;
        virtual void getValue(long nCol, ScDPItemData& rData, SvNumFormatType& rNumType) const = 0;
        virtual void getValue(tools::Long nCol, ScDPItemData& rData, SvNumFormatType& rNumType) const = 0;
        virtual ~DBConnector() {}
    };

@@ -136,21 +137,21 @@ public:
    void RemoveReference(ScDPObject* pObj) const;
    const ScDPObjectSet& GetAllReferences() const;

    SCROW GetIdByItemData(long nDim, const ScDPItemData& rItem) const;
    SCROW GetIdByItemData(tools::Long nDim, const ScDPItemData& rItem) const;

    static sal_uInt32 GetLocaleIndependentFormat( SvNumberFormatter& rFormatter, sal_uInt32 nNumFormat );
    static OUString GetLocaleIndependentFormattedNumberString( double fValue );
    static OUString GetLocaleIndependentFormattedString( double fValue, SvNumberFormatter& rFormatter, sal_uInt32 nNumFormat );
    OUString GetFormattedString(long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;
    OUString GetFormattedString(tools::Long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;
    SvNumberFormatter* GetNumberFormatter() const;

    long AppendGroupField();
    void ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType);
    SCROW SetGroupItem(long nDim, const ScDPItemData& rData);
    void GetGroupDimMemberIds(long nDim, std::vector<SCROW>& rIds) const;
    tools::Long AppendGroupField();
    void ResetGroupItems(tools::Long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType);
    SCROW SetGroupItem(tools::Long nDim, const ScDPItemData& rData);
    void GetGroupDimMemberIds(tools::Long nDim, std::vector<SCROW>& rIds) const;
    void ClearGroupFields();
    void ClearAllFields();
    const ScDPNumGroupInfo* GetNumGroupInfo(long nDim) const;
    const ScDPNumGroupInfo* GetNumGroupInfo(tools::Long nDim) const;

    /**
     * Return a group type identifier.  The values correspond with
@@ -160,12 +161,12 @@ public:
     *
     * @return group type identifier, or 0 on failure.
     */
    sal_Int32 GetGroupType(long nDim) const;
    sal_Int32 GetGroupType(tools::Long nDim) const;

    SCCOL GetDimensionIndex(const OUString& sName) const;
    sal_uInt32 GetNumberFormat( long nDim ) const;
    bool  IsDateDimension( long nDim ) const ;
    long GetDimMemberCount(long nDim) const;
    sal_uInt32 GetNumberFormat( tools::Long nDim ) const;
    bool  IsDateDimension( tools::Long nDim ) const ;
    tools::Long GetDimMemberCount(tools::Long nDim) const;

    const IndexArrayType* GetFieldIndexArray( size_t nDim ) const;
    const ScDPItemDataVec& GetDimMemberValues( SCCOL nDim ) const;
@@ -190,9 +191,9 @@ public:
    bool ValidQuery(SCROW nRow, const ScQueryParam& rQueryParam) const;

    ScDocument& GetDoc() const;
    long GetColumnCount() const;
    tools::Long GetColumnCount() const;

    const ScDPItemData* GetItemDataById( long nDim, SCROW nId ) const;
    const ScDPItemData* GetItemDataById( tools::Long nDim, SCROW nId ) const;

    size_t GetFieldCount() const;
    size_t GetGroupFieldCount() const;
@@ -209,7 +210,7 @@ public:
private:
    void PostInit();
    void Clear();
    const GroupItems* GetGroupItems(long nDim) const;
    const GroupItems* GetGroupItems(tools::Long nDim) const;
};

#endif
diff --git a/sc/inc/dpdimsave.hxx b/sc/inc/dpdimsave.hxx
index 124239c..d8cc13a 100644
--- a/sc/inc/dpdimsave.hxx
+++ b/sc/inc/dpdimsave.hxx
@@ -115,8 +115,8 @@ public:
    bool    IsEmpty() const;
    bool HasOnlyHidden(const ScDPUniqueStringSet& rVisible);

    long    GetGroupCount() const;
    const ScDPSaveGroupItem& GetGroupByIndex( long nIndex ) const;
    tools::Long    GetGroupCount() const;
    const ScDPSaveGroupItem& GetGroupByIndex( tools::Long nIndex ) const;

    void    Rename( const OUString& rNewName );

diff --git a/sc/inc/dpgroup.hxx b/sc/inc/dpgroup.hxx
index 7d6ecf0..f30f85f 100644
--- a/sc/inc/dpgroup.hxx
+++ b/sc/inc/dpgroup.hxx
@@ -52,24 +52,24 @@ public:

class ScDPGroupDimension
{
    long                        nSourceDim;
    long                        nGroupDim;
    tools::Long                        nSourceDim;
    tools::Long                        nGroupDim;
    OUString                    aGroupName;
    std::vector<ScDPGroupItem>  aItems;
    mutable std::vector<SCROW> maMemberEntries;
    bool mbDateDimension;
public:
                ScDPGroupDimension( long nSource, const OUString& rNewName );
                ScDPGroupDimension( tools::Long nSource, const OUString& rNewName );
                ScDPGroupDimension( const ScDPGroupDimension& rOther );
                ~ScDPGroupDimension();

    ScDPGroupDimension& operator=( const ScDPGroupDimension& rOther );

    void        AddItem( const ScDPGroupItem& rItem );
    void        SetGroupDim( long nDim );           // called from AddGroupDimension
    void        SetGroupDim( tools::Long nDim );           // called from AddGroupDimension

    long        GetSourceDim() const    { return nSourceDim; }
    long        GetGroupDim() const     { return nGroupDim; }
    tools::Long        GetSourceDim() const    { return nSourceDim; }
    tools::Long        GetGroupDim() const     { return nGroupDim; }
    const OUString& GetName() const { return aGroupName; }

    const std::vector< SCROW >&  GetColumnEntries( const ScDPFilteredCache&  rCacheTable ) const;
@@ -115,7 +115,7 @@ public:
class ScDPGroupTableData final : public ScDPTableData
{
    std::shared_ptr<ScDPTableData> pSourceData;
    long                    nSourceCount;
    tools::Long                    nSourceCount;
    std::vector<ScDPGroupDimension>
                            aGroups;
    std::unique_ptr<ScDPNumGroupDimension[]>
@@ -123,10 +123,10 @@ class ScDPGroupTableData final : public ScDPTableData
    ScDocument*             pDoc;

    void FillGroupValues(std::vector<SCROW>& rItems, const std::vector<long>& rDims);
    virtual long                GetSourceDim( long nDim ) override;
    virtual tools::Long                GetSourceDim( tools::Long nDim ) override;

    bool        IsNumGroupDimension( long nDimension ) const;
    void GetNumGroupInfo(long nDimension, ScDPNumGroupInfo& rInfo);
    bool        IsNumGroupDimension( tools::Long nDimension ) const;
    void GetNumGroupInfo(tools::Long nDimension, ScDPNumGroupInfo& rInfo);

    void        ModifyFilterCriteria(::std::vector<ScDPFilteredCache::Criterion>& rCriteria);

@@ -138,19 +138,19 @@ public:
    const std::shared_ptr<ScDPTableData>& GetSourceTableData() const { return pSourceData;}

    void        AddGroupDimension( const ScDPGroupDimension& rGroup );
    void        SetNumGroupDimension( long nIndex, const ScDPNumGroupDimension& rGroup );
    long        GetDimensionIndex( const OUString& rName );
    void        SetNumGroupDimension( tools::Long nIndex, const ScDPNumGroupDimension& rGroup );
    tools::Long        GetDimensionIndex( const OUString& rName );

    virtual long                    GetColumnCount() override;
    virtual long                    GetMembersCount( long nDim ) override;
    virtual const std::vector< SCROW >& GetColumnEntries( long nColumn ) override ;
    virtual const ScDPItemData* GetMemberById( long nDim, long nId) override;
    virtual long Compare( long nDim, long nDataId1, long nDataId2) override;
    virtual tools::Long                    GetColumnCount() override;
    virtual tools::Long                    GetMembersCount( tools::Long nDim ) override;
    virtual const std::vector< SCROW >& GetColumnEntries( tools::Long nColumn ) override ;
    virtual const ScDPItemData* GetMemberById( tools::Long nDim, tools::Long nId) override;
    virtual tools::Long Compare( tools::Long nDim, tools::Long nDataId1, tools::Long nDataId2) override;

    virtual OUString                getDimensionName(long nColumn) override;
    virtual bool                    getIsDataLayoutDimension(long nColumn) override;
    virtual bool                    IsDateDimension(long nDim) override;
    virtual sal_uInt32              GetNumberFormat(long nDim) override;
    virtual OUString                getDimensionName(tools::Long nColumn) override;
    virtual bool                    getIsDataLayoutDimension(tools::Long nColumn) override;
    virtual bool                    IsDateDimension(tools::Long nDim) override;
    virtual sal_uInt32              GetNumberFormat(tools::Long nDim) override;
    virtual void                    DisposeData() override;
    virtual void                    SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) override;

@@ -165,13 +165,13 @@ public:
    virtual const ScDPFilteredCache&   GetCacheTable() const override;
    virtual void ReloadCacheTable() override;

    virtual bool                    IsBaseForGroup(long nDim) const override;
    virtual long                    GetGroupBase(long nGroupDim) const override;
    virtual bool                    IsNumOrDateGroup(long nDim) const override;
    virtual bool                    IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
                                               const ScDPItemData& rBaseData, long nBaseIndex ) const override;
    virtual bool                    HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
                                                      const ScDPItemData& rSecondData, long nSecondIndex ) const override;
    virtual bool                    IsBaseForGroup(tools::Long nDim) const override;
    virtual tools::Long                    GetGroupBase(tools::Long nGroupDim) const override;
    virtual bool                    IsNumOrDateGroup(tools::Long nDim) const override;
    virtual bool                    IsInGroup( const ScDPItemData& rGroupData, tools::Long nGroupIndex,
                                               const ScDPItemData& rBaseData, tools::Long nBaseIndex ) const override;
    virtual bool                    HasCommonElement( const ScDPItemData& rFirstData, tools::Long nFirstIndex,
                                                      const ScDPItemData& rSecondData, tools::Long nSecondIndex ) const override;

#if DUMP_PIVOT_TABLE
    virtual void Dump() const override;
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 992e719..e487fd8 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -101,7 +101,7 @@ private:
    // see PivotTable::putToInteropGrabBag in sc/source/filter/oox/pivottablebuffer.cxx for details
    std::map<OUString, css::uno::Any> maInteropGrabBag;

    long                    nHeaderRows;    // page fields plus filter button
    tools::Long                    nHeaderRows;    // page fields plus filter button
    bool                    mbHeaderLayout:1;  // true : grid, false : standard
    bool                    bAllowMove:1;
    bool                    bSettingsChanged:1;
@@ -176,14 +176,14 @@ public:
    bool                IsDataDescriptionCell(const ScAddress& rPos);

    bool                IsDimNameInUse(const OUString& rName) const;
    OUString GetDimName( long nDim, bool& rIsDataLayout, sal_Int32* pFlags = nullptr );
    bool                IsDuplicated( long nDim );
    long                GetDimCount();
    OUString GetDimName( tools::Long nDim, bool& rIsDataLayout, sal_Int32* pFlags = nullptr );
    bool                IsDuplicated( tools::Long nDim );
    tools::Long                GetDimCount();
    void                GetHeaderPositionData(const ScAddress& rPos, css::sheet::DataPilotTableHeaderData& rData);
    long                GetHeaderDim( const ScAddress& rPos, css::sheet::DataPilotFieldOrientation& rOrient );
    tools::Long                GetHeaderDim( const ScAddress& rPos, css::sheet::DataPilotFieldOrientation& rOrient );
    bool                GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMouseTop,
                                       long nDragDim,
                                       tools::Rectangle& rPosRect, css::sheet::DataPilotFieldOrientation& rOrient, long& rDimPos );
                                       tools::Long nDragDim,
                                       tools::Rectangle& rPosRect, css::sheet::DataPilotFieldOrientation& rOrient, tools::Long& rDimPos );
    bool                IsFilterButton( const ScAddress& rPos );

    OUString            GetFormattedString( const OUString& rDimName, const double fValue );
@@ -198,7 +198,7 @@ public:
        std::vector<sal_Int16>& rFilterFuncs,
        const OUString& rFilterList );

    void GetMemberResultNames(ScDPUniqueStringSet& rNames, long nDimension);
    void GetMemberResultNames(ScDPUniqueStringSet& rNames, tools::Long nDimension);

    void                ToggleDetails(const css::sheet::DataPilotTableHeaderData& rElemDesc, ScDPObject* pDestObj);

diff --git a/sc/inc/dpoutput.hxx b/sc/inc/dpoutput.hxx
index 81fcf96..0f22671 100644
--- a/sc/inc/dpoutput.hxx
+++ b/sc/inc/dpoutput.hxx
@@ -59,14 +59,14 @@ private:
                            pColNumFmt;
    std::unique_ptr<sal_uInt32[]>
                            pRowNumFmt;
    long                    nColFmtCount;
    long                    nRowFmtCount;
    tools::Long                    nColFmtCount;
    tools::Long                    nRowFmtCount;
    sal_uInt32              nSingleNumFmt;

    // Output geometry related parameters
    long                    nColCount;
    long                    nRowCount;
    long                    nHeaderSize;
    tools::Long                    nColCount;
    tools::Long                    nRowCount;
    tools::Long                    nHeaderSize;
    SCCOL                   nTabStartCol;
    SCROW                   nTabStartRow;
    SCCOL                   nMemberStartCol;
@@ -85,7 +85,7 @@ private:
                                const css::sheet::DataResult& rData );
    void            HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
                                const css::sheet::MemberResult& rData,
                                bool bColHeader, long nLevel );
                                bool bColHeader, tools::Long nLevel );

    void FieldCell(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScDPOutLevelData& rData, bool bInTable);

@@ -106,7 +106,7 @@ public:

    void            Output();           //! Refresh?
    ScRange GetOutputRange( sal_Int32 nRegionType = css::sheet::DataPilotOutputRangeType::WHOLE );
    long            GetHeaderRows() const;
    tools::Long            GetHeaderRows() const;
    bool            HasError();         // range overflow or exception from source

    void            GetPositionData(const ScAddress& rPos, css::sheet::DataPilotTablePositionData& rPosData);
@@ -115,13 +115,13 @@ public:
        field region. */
    bool            GetDataResultPositionData(::std::vector< css::sheet::DataPilotFieldFilter >& rFilters, const ScAddress& rPos);

    long            GetHeaderDim( const ScAddress& rPos, css::sheet::DataPilotFieldOrientation& rOrient );
    tools::Long            GetHeaderDim( const ScAddress& rPos, css::sheet::DataPilotFieldOrientation& rOrient );
    bool GetHeaderDrag(
        const ScAddress& rPos, bool bMouseLeft, bool bMouseTop, long nDragDim,
        tools::Rectangle& rPosRect, css::sheet::DataPilotFieldOrientation& rOrient, long& rDimPos );
        const ScAddress& rPos, bool bMouseLeft, bool bMouseTop, tools::Long nDragDim,
        tools::Rectangle& rPosRect, css::sheet::DataPilotFieldOrientation& rOrient, tools::Long& rDimPos );
    bool IsFilterButton( const ScAddress& rPos );

    void GetMemberResultNames(ScDPUniqueStringSet& rNames, long nDimension);
    void GetMemberResultNames(ScDPUniqueStringSet& rNames, tools::Long nDimension);

    void            SetHeaderLayout(bool bUseGrid);
    bool            GetHeaderLayout() const { return mbHeaderLayout;}
diff --git a/sc/inc/dpresfilter.hxx b/sc/inc/dpresfilter.hxx
index 101b781..2f28383 100644
--- a/sc/inc/dpresfilter.hxx
+++ b/sc/inc/dpresfilter.hxx
@@ -11,6 +11,7 @@
#define INCLUDED_SC_INC_DPRESFILTER_HXX

#include <rtl/ustring.hxx>
#include <tools/long.hxx>
#include "calcmacros.hxx"

#include <memory>
@@ -133,8 +134,8 @@ struct ScDPResultFilterContext
{
    ScDPResultTree maFilterSet;
    std::vector<ScDPResultFilter> maFilters;
    long mnCol;
    long mnRow;
    tools::Long mnCol;
    tools::Long mnRow;

    ScDPResultFilterContext();
};
diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx
index 82089a0..54a04d7 100644
--- a/sc/inc/dpsave.hxx
+++ b/sc/inc/dpsave.hxx
@@ -26,6 +26,7 @@
#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
#include <rtl/ustring.hxx>
#include <sal/types.h>
#include <tools/long.hxx>

#include "scdllapi.h"
#include "calcmacros.hxx"
@@ -100,7 +101,7 @@ private:
    bool bDupFlag;
    css::sheet::DataPilotFieldOrientation nOrientation;
    ScGeneralFunction nFunction; // for data dimensions
    long nUsedHierarchy;
    tools::Long nUsedHierarchy;
    sal_uInt16 nShowEmptyMode; //! at level
    bool bRepeatItemLabels; //! at level
    bool bSubTotalDefault; //! at level
@@ -146,10 +147,10 @@ public:

    void SetOrientation(css::sheet::DataPilotFieldOrientation nNew);
    void SetSubTotals(std::vector<ScGeneralFunction> const & rFuncs);
    long GetSubTotalsCount() const
    tools::Long GetSubTotalsCount() const
        { return maSubTotalFuncs.size(); }

    ScGeneralFunction GetSubTotalFunc(long nIndex) const
    ScGeneralFunction GetSubTotalFunc(tools::Long nIndex) const
        { return maSubTotalFuncs[nIndex]; }

    bool HasShowEmpty() const;
@@ -165,8 +166,8 @@ public:
    ScGeneralFunction GetFunction() const
        { return nFunction; }

    void SetUsedHierarchy(long nNew);
    long GetUsedHierarchy() const
    void SetUsedHierarchy(tools::Long nNew);
    tools::Long GetUsedHierarchy() const
        { return nUsedHierarchy; }

    void SetLayoutName(const OUString& rName);
@@ -315,9 +316,9 @@ public:

    ScDPSaveDimension* GetInnermostDimension(css::sheet::DataPilotFieldOrientation nOrientation);
    ScDPSaveDimension* GetFirstDimension(css::sheet::DataPilotFieldOrientation eOrientation);
    SC_DLLPUBLIC long GetDataDimensionCount() const;
    SC_DLLPUBLIC tools::Long GetDataDimensionCount() const;

    void SetPosition( ScDPSaveDimension* pDim, long nNew );
    void SetPosition( ScDPSaveDimension* pDim, tools::Long nNew );
    SC_DLLPUBLIC void SetColumnGrand( bool bSet );
    bool GetColumnGrand() const
        { return bool(nColumnGrandMode); }
diff --git a/sc/inc/dpsdbtab.hxx b/sc/inc/dpsdbtab.hxx
index c1e6021..4498407 100644
--- a/sc/inc/dpsdbtab.hxx
+++ b/sc/inc/dpsdbtab.hxx
@@ -63,10 +63,10 @@ public:
    ScDatabaseDPData(const ScDocument* pDoc, const ScDPCache& rCache);
    virtual ~ScDatabaseDPData() override;

    virtual long                    GetColumnCount() override;
    virtual OUString                getDimensionName(long nColumn) override;
    virtual bool                    getIsDataLayoutDimension(long nColumn) override;
    virtual bool                    IsDateDimension(long nDim) override;
    virtual tools::Long                    GetColumnCount() override;
    virtual OUString                getDimensionName(tools::Long nColumn) override;
    virtual bool                    getIsDataLayoutDimension(tools::Long nColumn) override;
    virtual bool                    IsDateDimension(tools::Long nDim) override;
    virtual void                    DisposeData() override;
    virtual void                    SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) override;

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index 3e2ec432..71e7786 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -96,11 +96,11 @@ public:
    ScSheetDPData(const ScDocument* pD, const ScSheetSourceDesc& rDesc, const ScDPCache& rCache);
    virtual ~ScSheetDPData() override;

    virtual long                    GetColumnCount() override;
    virtual OUString                getDimensionName(long nColumn) override;
    virtual bool                    getIsDataLayoutDimension(long nColumn) override;
    virtual bool                    IsDateDimension(long nDim) override;
    virtual sal_uInt32              GetNumberFormat(long nDim) override;
    virtual tools::Long                    GetColumnCount() override;
    virtual OUString                getDimensionName(tools::Long nColumn) override;
    virtual bool                    getIsDataLayoutDimension(tools::Long nColumn) override;
    virtual bool                    IsDateDimension(tools::Long nDim) override;
    virtual sal_uInt32              GetNumberFormat(tools::Long nDim) override;
    virtual void                    DisposeData() override;
    virtual void                    SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) override;

diff --git a/sc/inc/dptabdat.hxx b/sc/inc/dptabdat.hxx
index 17ba76a..8f8aa3c 100644
--- a/sc/inc/dptabdat.hxx
+++ b/sc/inc/dptabdat.hxx
@@ -24,6 +24,7 @@
#include "calcmacros.hxx"

#include <svl/zforlist.hxx>
#include <tools/long.hxx>

#include <unordered_set>
#include <vector>
@@ -56,10 +57,10 @@ class ScDocument;
class SC_DLLPUBLIC ScDPTableData
{
    //  cached data for GetDatePart
    long    nLastDateVal;
    long    nLastHier;
    long    nLastLevel;
    long    nLastRet;
    tools::Long    nLastDateVal;
    tools::Long    nLastHier;
    tools::Long    nLastLevel;
    tools::Long    nLastRet;
    const ScDocument* mpDoc;
public:

@@ -89,19 +90,19 @@ public:
    ScDPTableData(const ScDocument* pDoc);
    virtual     ~ScDPTableData();

    OUString GetFormattedString(long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;
    OUString GetFormattedString(tools::Long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;

    long        GetDatePart( long nDateVal, long nHierarchy, long nLevel );
    tools::Long        GetDatePart( tools::Long nDateVal, tools::Long nHierarchy, tools::Long nLevel );

                //! use (new) typed collection instead of ScStrCollection
                //! or separate Str and ValueCollection

    virtual long                    GetColumnCount() = 0;
    virtual const std::vector< SCROW >& GetColumnEntries( long nColumn ) ;
    virtual OUString                getDimensionName(long nColumn) = 0;
    virtual bool                    getIsDataLayoutDimension(long nColumn) = 0;
    virtual bool                    IsDateDimension(long nDim) = 0;
    virtual sal_uInt32              GetNumberFormat(long nDim);
    virtual tools::Long                    GetColumnCount() = 0;
    virtual const std::vector< SCROW >& GetColumnEntries( tools::Long nColumn ) ;
    virtual OUString                getDimensionName(tools::Long nColumn) = 0;
    virtual bool                    getIsDataLayoutDimension(tools::Long nColumn) = 0;
    virtual bool                    IsDateDimension(tools::Long nDim) = 0;
    virtual sal_uInt32              GetNumberFormat(tools::Long nDim);
    sal_uInt32                      GetNumberFormatByIdx( NfIndexTableOffset );
    virtual void                    DisposeData() = 0;
    virtual void                    SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) = 0;
@@ -118,19 +119,19 @@ public:
    virtual void ReloadCacheTable() = 0;

                                    // override in ScDPGroupTableData:
    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;
    virtual bool                    IsBaseForGroup(tools::Long nDim) const;
    virtual tools::Long                    GetGroupBase(tools::Long nGroupDim) const;
    virtual bool                    IsNumOrDateGroup(tools::Long nDim) const;
    virtual bool                    IsInGroup( const ScDPItemData& rGroupData, tools::Long nGroupIndex,
                                               const ScDPItemData& rBaseData, tools::Long nBaseIndex ) const;
    virtual bool                    HasCommonElement( const ScDPItemData& rFirstData, tools::Long nFirstIndex,
                                                      const ScDPItemData& rSecondData, tools::Long nSecondIndex ) const;

    virtual long                            GetMembersCount( long nDim );
    const ScDPItemData*   GetMemberByIndex( long nDim, long nIndex );
    virtual const ScDPItemData*   GetMemberById( long nDim, long nId);
    virtual long                GetSourceDim( long nDim );
    virtual long                Compare( long nDim, long nDataId1, long nDataId2);
    virtual tools::Long                            GetMembersCount( tools::Long nDim );
    const ScDPItemData*   GetMemberByIndex( tools::Long nDim, tools::Long nIndex );
    virtual const ScDPItemData*   GetMemberById( tools::Long nDim, tools::Long nId);
    virtual tools::Long                GetSourceDim( tools::Long nDim );
    virtual tools::Long                Compare( tools::Long nDim, tools::Long nDataId1, tools::Long nDataId2);

#if DUMP_PIVOT_TABLE
    virtual void Dump() const;
diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx
index fc7b239..2ea654a 100644
--- a/sc/inc/dptabres.hxx
+++ b/sc/inc/dptabres.hxx
@@ -58,13 +58,13 @@ class ScDPInitState
public:
    struct Member
    {
        long mnSrcIndex;
        tools::Long mnSrcIndex;
        SCROW mnNameIndex;

        Member(long nSrcIndex, SCROW nNameIndex);
        Member(tools::Long nSrcIndex, SCROW nNameIndex);
    };

    void AddMember(long nSourceIndex, SCROW nMember);
    void AddMember(tools::Long nSourceIndex, SCROW nMember);
    void RemoveMember();

    const std::vector<Member>& GetMembers() const { return maMembers; }
@@ -82,8 +82,8 @@ struct ScDPSubTotalState
{
    ScSubTotalFunc eColForce;
    ScSubTotalFunc eRowForce;
    long nColSubTotalFunc;
    long nRowSubTotalFunc;
    tools::Long nColSubTotalFunc;
    tools::Long nRowSubTotalFunc;

    ScDPSubTotalState() :
        eColForce( SUBTOTAL_FUNC_NONE ),
@@ -117,8 +117,8 @@ public:
    const IndexArray& GetRowVisible() const { return maRowVisible;}
    const IndexArray& GetRowSorted() const { return maRowSorted;}

    void    AddColIndex( long nVisible, long nSorted );
    void    AddRowIndex( long nVisible, long nSorted );
    void    AddColIndex( tools::Long nVisible, tools::Long nSorted );
    void    AddRowIndex( tools::Long nVisible, tools::Long nSorted );
    void    RemoveColIndex();
    void    RemoveRowIndex();

@@ -134,10 +134,10 @@ private:

struct ScDPRelativePos
{
    long    nBasePos;       // simple count, without sort order applied
    long    nDirection;
    tools::Long    nBasePos;       // simple count, without sort order applied
    tools::Long    nDirection;

    ScDPRelativePos( long nBase, long nDir );
    ScDPRelativePos( tools::Long nBase, tools::Long nDir );
};

//  aggregated data
@@ -201,8 +201,8 @@ public:
            ScDPRowTotals();
            ~ScDPRowTotals();

    ScDPAggData*    GetRowTotal( long nMeasure );
    ScDPAggData*    GetGrandTotal( long nMeasure );
    ScDPAggData*    GetRowTotal( tools::Long nMeasure );
    ScDPAggData*    GetGrandTotal( tools::Long nMeasure );

    bool IsInColRoot() const { return bIsInColRoot; }
    void SetInColRoot(bool bSet) { bIsInColRoot = bSet; }
@@ -299,29 +299,29 @@ public:
    void                SetDataLayoutOrientation( css::sheet::DataPilotFieldOrientation nOrient );
    void                SetLateInit( bool bSet );

    long                GetMeasureCount() const { return maMeasureFuncs.size(); }
    ScSubTotalFunc      GetMeasureFunction(long nMeasure) const;
    OUString            GetMeasureString(long nMeasure, bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const;
    OUString            GetMeasureDimensionName(long nMeasure) const;
    const css::sheet::DataPilotFieldReference& GetMeasureRefVal(long nMeasure) const;
    css::sheet::DataPilotFieldOrientation      GetMeasureRefOrient(long nMeasure) const;
    tools::Long                GetMeasureCount() const { return maMeasureFuncs.size(); }
    ScSubTotalFunc      GetMeasureFunction(tools::Long nMeasure) const;
    OUString            GetMeasureString(tools::Long nMeasure, bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const;
    OUString            GetMeasureDimensionName(tools::Long nMeasure) const;
    const css::sheet::DataPilotFieldReference& GetMeasureRefVal(tools::Long nMeasure) const;
    css::sheet::DataPilotFieldOrientation      GetMeasureRefOrient(tools::Long nMeasure) const;

    bool                IsLateInit() const              { return bLateInit; }

    long                GetColStartMeasure() const;
    long                GetRowStartMeasure() const;
    tools::Long                GetColStartMeasure() const;
    tools::Long                GetRowStartMeasure() const;

    long                GetCountForMeasure( long nMeas ) const { return (nMeas == SC_DPMEASURE_ALL) ? maMeasureFuncs.size() : 1; }
    tools::Long                GetCountForMeasure( tools::Long nMeas ) const { return (nMeas == SC_DPMEASURE_ALL) ? maMeasureFuncs.size() : 1; }

    bool                IsBaseForGroup( long nDim ) const;              // any group
    long                GetGroupBase( long nGroupDim ) const;
    bool                IsNumOrDateGroup( long nDim ) const;
    bool                IsInGroup( SCROW nGroupDataId, long nGroupIndex,
                                   const ScDPItemData& rBaseData, long nBaseIndex ) const;
    bool                HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
                                          const ScDPItemData& rSecondData, long nSecondIndex ) const;
    bool                IsBaseForGroup( tools::Long nDim ) const;              // any group
    tools::Long                GetGroupBase( tools::Long nGroupDim ) const;
    bool                IsNumOrDateGroup( tools::Long nDim ) const;
    bool                IsInGroup( SCROW nGroupDataId, tools::Long nGroupIndex,
                                   const ScDPItemData& rBaseData, tools::Long nBaseIndex ) const;
    bool                HasCommonElement( SCROW nFirstDataId, tools::Long nFirstIndex,
                                          const ScDPItemData& rSecondData, tools::Long nSecondIndex ) const;

    ResultMembers&      GetDimResultMembers(long nDim, const ScDPDimension* pDim, ScDPLevel* pLevel) const;
    ResultMembers&      GetDimResultMembers(tools::Long nDim, const ScDPDimension* pDim, ScDPLevel* pLevel) const;

    const ScDPSource& GetSource() const { return mrSource;}
};
@@ -364,13 +364,13 @@ public:
    ScDPItemData FillItemData() const;
    bool IsValid() const;
    bool IsVisible() const;
    long                GetSize(long nMeasure) const;
    tools::Long                GetSize(tools::Long nMeasure) const;
    // bHasHiddenDetails is set only if the "show details" flag is off,
    // and there was a child dimension to skip
    bool HasHiddenDetails() const { return bHasHiddenDetails; }
    bool IsSubTotalInTitle(long nMeasure) const;
    bool IsSubTotalInTitle(tools::Long nMeasure) const;

    long                GetSubTotalCount( long* pUserSubStart = nullptr ) const;
    tools::Long                GetSubTotalCount( tools::Long* pUserSubStart = nullptr ) const;

    bool IsNamedItem( SCROW nIndex ) const;
    bool IsValidEntry( const ::std::vector< SCROW >& aMembers ) const;
@@ -384,16 +384,16 @@ public:
                                        const ::std::vector<ScDPValue>& aValues );
    void FillMemberResults(
        css::uno::Sequence< css::sheet::MemberResult>* pSequences,
        long& rPos, long nMeasure, bool bRoot, const OUString* pMemberName, const OUString* pMemberCaption );
        tools::Long& rPos, tools::Long nMeasure, bool bRoot, const OUString* pMemberName, const OUString* pMemberCaption );

    void FillDataResults(
        const ScDPResultMember* pRefMember,
        ScDPResultFilterContext& rFilterCxt,
        css::uno::Sequence< css::uno::Sequence<  css::sheet::DataResult> >& rSequence,
        long nMeasure) const;
        tools::Long nMeasure) const;

    void                UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const;
    void                UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
    void                UpdateDataResults( const ScDPResultMember* pRefMember, tools::Long nMeasure ) const;
    void                UpdateRunningTotals( const ScDPResultMember* pRefMember, tools::Long nMeasure,
                                                ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const;

    void                SortMembers( ScDPResultMember* pRefMember );
@@ -419,7 +419,7 @@ public:
    SCROW GetOrder() const { return aParentDimData.mnOrder; }         //! Ref
    bool IsRoot() const { return GetParentLevel() == nullptr; }
    SCROW                       GetDataId( ) const ;
    ScDPAggData*        GetColTotal( long nMeasure ) const;
    ScDPAggData*        GetColTotal( tools::Long nMeasure ) const;

    void                FillVisibilityData(ScDPResultVisibilityData& rData) const;
};
@@ -443,28 +443,28 @@ public:

    OUString GetName() const;
    bool IsVisible() const;
    bool HasData( long nMeasure, const ScDPSubTotalState& rSubState ) const;
    bool HasData( tools::Long nMeasure, const ScDPSubTotalState& rSubState ) const;

    bool IsNamedItem( SCROW nRow ) const;
    bool HasHiddenDetails() const;

    void                ProcessData( const ::std::vector< SCROW >& aChildMembers, const ::std::vector<ScDPValue>& aValues,
                                       const ScDPSubTotalState& rSubState );
    bool HasError( long nMeasure, const ScDPSubTotalState& rSubState ) const;
    double              GetAggregate( long nMeasure, const ScDPSubTotalState& rSubState ) const;
    const ScDPAggData*  GetConstAggData( long nMeasure, const ScDPSubTotalState& rSubState ) const;
    ScDPAggData*        GetAggData( long nMeasure, const ScDPSubTotalState& rSubState );
    bool HasError( tools::Long nMeasure, const ScDPSubTotalState& rSubState ) const;
    double              GetAggregate( tools::Long nMeasure, const ScDPSubTotalState& rSubState ) const;
    const ScDPAggData*  GetConstAggData( tools::Long nMeasure, const ScDPSubTotalState& rSubState ) const;
    ScDPAggData*        GetAggData( tools::Long nMeasure, const ScDPSubTotalState& rSubState );

    void FillDataRow(
        const ScDPResultMember* pRefMember,
        ScDPResultFilterContext& rFilterCxt,
        css::uno::Sequence<css::sheet::DataResult>& rSequence,
        long nMeasure, bool bIsSubTotalRow,
        tools::Long nMeasure, bool bIsSubTotalRow,
        const ScDPSubTotalState& rSubState) const;

    void UpdateDataRow( const ScDPResultMember* pRefMember, long nMeasure, bool bIsSubTotalRow,
    void UpdateDataRow( const ScDPResultMember* pRefMember, tools::Long nMeasure, bool bIsSubTotalRow,
                        const ScDPSubTotalState& rSubState );
    void UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure, bool bIsSubTotalRow,
    void UpdateRunningTotals( const ScDPResultMember* pRefMember, tools::Long nMeasure, bool bIsSubTotalRow,
                              const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
                              ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent );

@@ -495,7 +495,7 @@ private:
    MemberArray             maMemberArray;
    MemberHash              maMemberHash;
    OUString                aDimensionName;     //! or ptr to IntDimension?
    long                    nSortMeasure;
    tools::Long                    nSortMeasure;
    ScMemberSortOrder       aMemberOrder;       // used when sorted by measure
    bool                    bIsDataLayout:1;      //! or ptr to IntDimension?
    bool                    bSortByData:1;
@@ -503,8 +503,8 @@ private:
    bool                    bAutoShow:1;
    bool                    bAutoTopItems:1;
    bool                    bInitialized:1;
    long                    nAutoMeasure;
    long                    nAutoCount;
    tools::Long                    nAutoMeasure;
    tools::Long                    nAutoCount;

    ScDPResultMember*        FindMember(   SCROW  iData ) const;
    ScDPResultMember*        AddMember( const ScDPParentDimData& aData );
@@ -527,7 +527,7 @@ public:
                                        ScDPInitState& rInitState );
    void CheckShowEmpty( bool bShow = false );

    long                GetSize(long nMeasure) const;
    tools::Long                GetSize(tools::Long nMeasure) const;

    bool                IsValidEntry( const ::std::vector<SCROW>& aMembers ) const;

@@ -538,7 +538,7 @@ public:
                                     const ::std::vector<ScDPValue>& aValues ) const;   //! Test
    void                FillMemberResults( css::uno::Sequence<
                                                css::sheet::MemberResult>* pSequences,
                                            long nStart, long nMeasure );
                                            tools::Long nStart, tools::Long nMeasure );

    void FillDataResults(
        const ScDPResultMember* pRefMember,
@@ -546,14 +546,14 @@ public:
        css::uno::Sequence<
            css::uno::Sequence<
                css::sheet::DataResult> >& rSequence,
        long nMeasure) const;
        tools::Long nMeasure) const;

    void                UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const;
    void                UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
    void                UpdateDataResults( const ScDPResultMember* pRefMember, tools::Long nMeasure ) const;
    void                UpdateRunningTotals( const ScDPResultMember* pRefMember, tools::Long nMeasure,
                                            ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const;

    void                SortMembers( ScDPResultMember* pRefMember );
    long                GetSortedIndex( long nUnsorted ) const;
    tools::Long                GetSortedIndex( tools::Long nUnsorted ) const;

    void                DoAutoShow( ScDPResultMember* pRefMember );

@@ -562,12 +562,12 @@ public:
    //  called for the reference dimension
    ScDPDataMember* GetRowReferenceMember(
        const ScDPRelativePos* pMemberPos, const OUString* pName,
        const long* pRowIndexes, const long* pColIndexes ) const;
        const tools::Long* pRowIndexes, const tools::Long* pColIndexes ) const;

    // uses row root member from ScDPRunningTotalState
    static ScDPDataMember* GetColReferenceMember(
        const ScDPRelativePos* pMemberPos, const OUString* pName,
        long nRefDimPos, const ScDPRunningTotalState& rRunning );
        tools::Long nRefDimPos, const ScDPRunningTotalState& rRunning );

#if DUMP_PIVOT_TABLE
    void DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
@@ -575,9 +575,9 @@ public:
#endif

                        //  for ScDPDataDimension::InitFrom
    long                GetMemberCount() const;
    const ScDPResultMember* GetMember(long n) const;
    ScDPResultMember*       GetMember(long n);
    tools::Long                GetMemberCount() const;
    const ScDPResultMember* GetMember(tools::Long n) const;
    ScDPResultMember*       GetMember(tools::Long n);

    const ScMemberSortOrder& GetMemberOrder() const     { return aMemberOrder; }
    ScMemberSortOrder&  GetMemberOrder()                { return aMemberOrder; }
@@ -587,12 +587,12 @@ public:

    bool IsSortByData() const { return bSortByData; }
    bool IsSortAscending() const { return bSortAscending; }
    long                GetSortMeasure() const  { return nSortMeasure; }
    tools::Long                GetSortMeasure() const  { return nSortMeasure; }

    bool IsAutoShow() const { return bAutoShow; }
    bool IsAutoTopItems() const { return bAutoTopItems; }
    long                GetAutoMeasure() const  { return nAutoMeasure; }
    long                GetAutoCount() const    { return nAutoCount; }
    tools::Long                GetAutoMeasure() const  { return nAutoMeasure; }
    tools::Long                GetAutoCount() const    { return nAutoCount; }

    ScDPResultDimension* GetFirstChildDimension() const;

@@ -618,16 +618,16 @@ public:
        const ScDPResultDimension* pRefDim,
        ScDPResultFilterContext& rFilterCxt,
        css::uno::Sequence<css::sheet::DataResult>& rSequence,
        long nMeasure, bool bIsSubTotalRow, const ScDPSubTotalState& rSubState) const;
        tools::Long nMeasure, bool bIsSubTotalRow, const ScDPSubTotalState& rSubState) const;

    void                UpdateDataRow( const ScDPResultDimension* pRefDim, long nMeasure, bool bIsSubTotalRow,
    void                UpdateDataRow( const ScDPResultDimension* pRefDim, tools::Long nMeasure, bool bIsSubTotalRow,
                                    const ScDPSubTotalState& rSubState ) const;
    void                UpdateRunningTotals( const ScDPResultDimension* pRefDim, long nMeasure, bool bIsSubTotalRow,
    void                UpdateRunningTotals( const ScDPResultDimension* pRefDim, tools::Long nMeasure, bool bIsSubTotalRow,
                                    const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
                                    ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent ) const;

    void                SortMembers( ScDPResultDimension* pRefDim );
    long                GetSortedIndex( long nUnsorted ) const;
    tools::Long                GetSortedIndex( tools::Long nUnsorted ) const;

    void                DoAutoShow( ScDPResultDimension* pRefDim );

@@ -638,9 +638,9 @@ public:
    void Dump(int nIndent) const;
#endif

    long                GetMemberCount() const;
    const ScDPDataMember*     GetMember(long n) const;
    ScDPDataMember*     GetMember(long n);
    tools::Long                GetMemberCount() const;
    const ScDPDataMember*     GetMember(tools::Long n) const;
    ScDPDataMember*     GetMember(tools::Long n);
};

/**
diff --git a/sc/inc/dptabsrc.hxx b/sc/inc/dptabsrc.hxx
index c908abb..692eb2a 100644
--- a/sc/inc/dptabsrc.hxx
+++ b/sc/inc/dptabsrc.hxx
@@ -96,7 +96,7 @@ private:
    bool                    bIgnoreEmptyRows;
    bool                    bRepeatIfEmpty;

    long                    nDupCount;
    tools::Long                    nDupCount;

                                                // results:
    std::unique_ptr<ScDPResultData>   pResData;           // keep the rest in this!
@@ -128,7 +128,7 @@ private:
     */
    void FilterCacheByPageDimensions();

    void                    SetDupCount( long nNew );
    void                    SetDupCount( tools::Long nNew );

    OUString getDataDescription();       //! ???

@@ -148,27 +148,27 @@ public:
                            GetGrandTotalName() const;

    css::sheet::DataPilotFieldOrientation
                            GetOrientation(long nColumn);
    void                    SetOrientation(long nColumn, css::sheet::DataPilotFieldOrientation nNew);
    long                    GetPosition(long nColumn);
                            GetOrientation(tools::Long nColumn);
    void                    SetOrientation(tools::Long nColumn, css::sheet::DataPilotFieldOrientation nNew);
    tools::Long                    GetPosition(tools::Long nColumn);

    long                    GetDataDimensionCount() const;
    ScDPDimension*          GetDataDimension(long nIndex);
    OUString GetDataDimName(long nIndex);
    tools::Long                    GetDataDimensionCount() const;
    ScDPDimension*          GetDataDimension(tools::Long nIndex);
    OUString GetDataDimName(tools::Long nIndex);
    const ScDPCache* GetCache();
    const ScDPItemData*         GetItemDataById( long nDim, long nId );
    bool                        IsDataLayoutDimension(long nDim);
    const ScDPItemData*         GetItemDataById( tools::Long nDim, tools::Long nId );
    bool                        IsDataLayoutDimension(tools::Long nDim);
    css::sheet::DataPilotFieldOrientation
                                GetDataLayoutOrientation();

    bool                        IsDateDimension(long nDim);
    bool                        IsDateDimension(tools::Long nDim);

    bool                        SubTotalAllowed(long nColumn);      //! move to ScDPResultData
    bool                        SubTotalAllowed(tools::Long nColumn);      //! move to ScDPResultData

    ScDPDimension* AddDuplicated(const OUString& rNewName);
    long                    GetDupCount() const { return nDupCount; }
    tools::Long                    GetDupCount() const { return nDupCount; }

    long                    GetSourceDim(long nDim);
    tools::Long                    GetSourceDim(tools::Long nDim);

    const css::uno::Sequence<css::sheet::MemberResult>*
                            GetMemberResults( const ScDPLevel* pLevel );
@@ -228,7 +228,7 @@ class ScDPDimensions : public cppu::WeakImplHelper<
{
private:
    ScDPSource*         pSource;
    long                nDimCount;
    tools::Long                nDimCount;
    std::unique_ptr<rtl::Reference<ScDPDimension>[]>
                        ppDims;

@@ -252,8 +252,8 @@ public:
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;

    long            getCount() const;
    ScDPDimension*  getByIndex(long nIndex) const;
    tools::Long            getCount() const;
    ScDPDimension*  getByIndex(tools::Long nIndex) const;
};

class ScDPDimension : public cppu::WeakImplHelper<
@@ -264,13 +264,13 @@ class ScDPDimension : public cppu::WeakImplHelper<
                            css::lang::XServiceInfo >
{
    ScDPSource*         pSource;
    long                nDim;               // dimension index (== column ID)
    tools::Long                nDim;               // dimension index (== column ID)
    rtl::Reference<ScDPHierarchies> mxHierarchies;
    ScGeneralFunction   nFunction;
    OUString            aName;              // if empty, take from source
    std::optional<OUString> mpLayoutName;
    std::optional<OUString> mpSubtotalName;
    long                nSourceDim;         // >=0 if dup'ed
    tools::Long                nSourceDim;         // >=0 if dup'ed
    css::sheet::DataPilotFieldReference
                        aReferenceValue;    // settings for "show data as" / "displayed value"
    bool                bHasSelectedPage;
@@ -280,13 +280,13 @@ class ScDPDimension : public cppu::WeakImplHelper<
    bool                mbHasHiddenMember;

public:
                            ScDPDimension( ScDPSource* pSrc, long nD );
                            ScDPDimension( ScDPSource* pSrc, tools::Long nD );
    virtual                 ~ScDPDimension() override;
                            ScDPDimension(const ScDPDimension&) = delete;
    ScDPDimension&          operator=(const ScDPDimension&) = delete;

    long                    GetDimension() const    { return nDim; }        // dimension index in source
    long                    GetSourceDim() const    { return nSourceDim; }  // >=0 if dup'ed
    tools::Long                    GetDimension() const    { return nDim; }        // dimension index in source
    tools::Long                    GetSourceDim() const    { return nSourceDim; }  // >=0 if dup'ed

    ScDPDimension*          CreateCloneObject();
    ScDPHierarchies*        GetHierarchiesObject();
@@ -332,7 +332,7 @@ public:
    bool getIsDataLayoutDimension() const;
    ScGeneralFunction getFunction() const { return nFunction;}
    void setFunction(ScGeneralFunction nNew);       // for data dimension
    static long getUsedHierarchy() { return 0;}
    static tools::Long getUsedHierarchy() { return 0;}

    bool                        HasSelectedPage() const     { return bHasSelectedPage; }
    const ScDPItemData&         GetSelectedData();
@@ -346,15 +346,15 @@ class ScDPHierarchies : public cppu::WeakImplHelper<
{
private:
    ScDPSource*         pSource;
    long                nDim;
    tools::Long                nDim;
    //  date columns have 3 hierarchies (flat/quarter/week), other columns only one
    // #i52547# don't offer the incomplete date hierarchy implementation
    static const long   nHierCount = 1;
    static const tools::Long   nHierCount = 1;
    std::unique_ptr<rtl::Reference<ScDPHierarchy>[]>
                        ppHiers;

public:
                            ScDPHierarchies( ScDPSource* pSrc, long nD );
                            ScDPHierarchies( ScDPSource* pSrc, tools::Long nD );
    virtual                 ~ScDPHierarchies() override;

                            // XNameAccess
@@ -371,8 +371,8 @@ public:
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;

    static long     getCount();
    ScDPHierarchy*  getByIndex(long nIndex) const;
    static tools::Long     getCount();
    ScDPHierarchy*  getByIndex(tools::Long nIndex) const;
};

class ScDPHierarchy : public cppu::WeakImplHelper<
@@ -382,12 +382,12 @@ class ScDPHierarchy : public cppu::WeakImplHelper<
{
private:
    ScDPSource*     pSource;
    long            nDim;
    long            nHier;
    tools::Long            nDim;
    tools::Long            nHier;
    rtl::Reference<ScDPLevels> mxLevels;

public:
                            ScDPHierarchy( ScDPSource* pSrc, long nD, long nH );
                            ScDPHierarchy( ScDPSource* pSrc, tools::Long nD, tools::Long nH );
    virtual                 ~ScDPHierarchy() override;

    ScDPLevels*             GetLevelsObject();
@@ -412,14 +412,14 @@ class ScDPLevels : public cppu::WeakImplHelper<
{
private:
    ScDPSource*     pSource;
    long            nDim;
    long            nHier;
    long            nLevCount;
    tools::Long            nDim;
    tools::Long            nHier;
    tools::Long            nLevCount;
    std::unique_ptr<rtl::Reference<ScDPLevel>[]>
                    ppLevs;

public:
                            ScDPLevels( ScDPSource* pSrc, long nD, long nH );
                            ScDPLevels( ScDPSource* pSrc, tools::Long nD, tools::Long nH );
    virtual                 ~ScDPLevels() override;

                            // XNameAccess
@@ -436,8 +436,8 @@ public:
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;

    long            getCount() const;
    ScDPLevel*      getByIndex(long nIndex) const;
    tools::Long            getCount() const;
    ScDPLevel*      getByIndex(tools::Long nIndex) const;
};

class ScDPLevel : public cppu::WeakImplHelper<
@@ -449,9 +449,9 @@ class ScDPLevel : public cppu::WeakImplHelper<
{
private:
    ScDPSource*                 pSource;
    long                        nDim;
    long                        nHier;
    long                        nLev;
    tools::Long                        nDim;
    tools::Long                        nHier;
    tools::Long                        nLev;
    rtl::Reference<ScDPMembers> mxMembers;
    css::uno::Sequence<sal_Int16> aSubTotals;
    css::sheet::DataPilotFieldSortInfo     aSortInfo;      // stored user settings
@@ -459,14 +459,14 @@ private:
    css::sheet::DataPilotFieldLayoutInfo   aLayoutInfo;    // stored user settings
                                                    // valid only from result calculation:
    ::std::vector<sal_Int32>    aGlobalOrder;       // result of sorting by name or position
    long                        nSortMeasure;       // measure (index of data dimension) to sort by
    long                        nAutoMeasure;       // measure (index of data dimension) for AutoShow
    tools::Long                        nSortMeasure;       // measure (index of data dimension) to sort by
    tools::Long                        nAutoMeasure;       // measure (index of data dimension) for AutoShow
    bool                        bShowEmpty:1;
    bool                        bEnableLayout:1;      // enabled only for row fields, not for the innermost one
    bool                        bRepeatItemLabels:1;

public:
                            ScDPLevel( ScDPSource* pSrc, long nD, long nH, long nL );
                            ScDPLevel( ScDPSource* pSrc, tools::Long nD, tools::Long nH, tools::Long nL );
    virtual                 ~ScDPLevel() override;

    ScDPMembers*            GetMembersObject();
@@ -516,8 +516,8 @@ public:

    const ::std::vector<sal_Int32>& GetGlobalOrder() const      { return aGlobalOrder; }
    ::std::vector<sal_Int32>&  GetGlobalOrder()                 { return aGlobalOrder; }
    long                    GetSortMeasure() const              { return nSortMeasure; }
    long                    GetAutoMeasure() const              { return nAutoMeasure; }
    tools::Long                    GetSortMeasure() const              { return nSortMeasure; }
    tools::Long                    GetAutoMeasure() const              { return nAutoMeasure; }

    bool IsOutlineLayout() const
    {
@@ -551,15 +551,15 @@ class ScDPMembers : public cppu::WeakImplHelper<
private:
    typedef std::vector<rtl::Reference<ScDPMember> > MembersType;
    ScDPSource*     pSource;
    long            nDim;
    long            nHier;
    long            nLev;
    long            nMbrCount;
    tools::Long            nDim;
    tools::Long            nHier;
    tools::Long            nLev;
    tools::Long            nMbrCount;
    mutable MembersType maMembers;
    mutable ScDPMembersHashMap aHashMap;

public:
                            ScDPMembers( ScDPSource* pSrc, long nD, long nH, long nL );
                            ScDPMembers( ScDPSource* pSrc, tools::Long nD, tools::Long nH, tools::Long nL );
    virtual                 ~ScDPMembers() override;

                            // XMembersAccess
@@ -579,10 +579,10 @@ public:
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;

    long                    getCount() const { return nMbrCount;}
    ScDPMember*             getByIndex(long nIndex) const;
    tools::Long                    getCount() const { return nMbrCount;}
    ScDPMember*             getByIndex(tools::Long nIndex) const;

    long                    getMinMembers() const;
    tools::Long                    getMinMembers() const;

    sal_Int32               GetIndexFromName( const OUString& rName ) const;     // <0 if not found
    const ScDPItemData*     GetSrcItemDataByIndex(  SCROW nIndex);
@@ -599,9 +599,9 @@ class ScDPMember : public cppu::WeakImplHelper<
{
private:
    ScDPSource*     pSource;
    long            nDim;
    long            nHier;
    long            nLev;
    tools::Long            nDim;
    tools::Long            nHier;
    tools::Long            nLev;

    SCROW           mnDataId;
    std::optional<OUString> mpLayoutName;
@@ -611,7 +611,7 @@ private:
    bool            bShowDet;

public:
    ScDPMember(ScDPSource* pSrc, long nD, long nH, long nL, SCROW nIndex);
    ScDPMember(ScDPSource* pSrc, tools::Long nD, tools::Long nH, tools::Long nL, SCROW nIndex);
    virtual                 ~ScDPMember() override;
    ScDPMember(const ScDPMember&) = delete;
    ScDPMember& operator=(const ScDPMember&) = delete;
@@ -623,7 +623,7 @@ public:
    bool IsNamedItem(SCROW nIndex) const;

    const std::optional<OUString> & GetLayoutName() const;
    long GetDim() const { return nDim;}
    tools::Long GetDim() const { return nDim;}

    sal_Int32               Compare( const ScDPMember& rOther ) const;      // visible order

diff --git a/sc/inc/drwlayer.hxx b/sc/inc/drwlayer.hxx
index fa88a4a..c8fd1fc 100644
--- a/sc/inc/drwlayer.hxx
+++ b/sc/inc/drwlayer.hxx
@@ -166,7 +166,7 @@ public:
    SdrObject*      GetNamedObject( const OUString& rName, sal_uInt16 nId, SCTAB& rFoundTab ) const;
                    // if pnCounter != NULL, the search for a name starts with this index + 1,
                    // and the index really used is returned.
    OUString        GetNewGraphicName( long* pnCounter = nullptr ) const;
    OUString        GetNewGraphicName( tools::Long* pnCounter = nullptr ) const;
    void            EnsureGraphicNames();

    static bool IsCellAnchored( const SdrObject& rObj );
diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx
index 57bcfdd..f282491 100644
--- a/sc/inc/editutil.hxx
+++ b/sc/inc/editutil.hxx
@@ -208,8 +208,8 @@ struct ScHeaderFieldData
    OUString    aShortDocName;      // pure file name
    OUString    aTabName;
    DateTime    aDateTime;
    long        nPageNo;
    long        nTotalPages;
    tools::Long        nPageNo;
    tools::Long        nTotalPages;
    SvxNumType  eNumType;

    ScHeaderFieldData();
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index 118b5a1..84f0d9b 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -28,6 +28,7 @@
#include <com/sun/star/i18n/CollatorOptions.hpp>
#include "scdllapi.h"
#include <rtl/ustring.hxx>
#include <tools/long.hxx>

#include <atomic>
// HACK: <atomic> includes <stdbool.h>, which in some Clang versions does '#define bool bool',
@@ -105,9 +106,9 @@ const SCSIZE MAXSUBTOTAL        = 3;

namespace sc
{
    inline long TwipsToHMM( long nTwips )     { return (nTwips * 127 + 36) / 72; }
    inline long HMMToTwips( long nHMM )       { return (nHMM * 72 + 63) / 127; }
    inline long TwipsToEvenHMM( long nTwips ) { return ( (nTwips * 127 + 72) / 144 ) * 2; }
    inline ::tools::Long TwipsToHMM( ::tools::Long nTwips )     { return (nTwips * 127 + 36) / 72; }
    inline ::tools::Long HMMToTwips( ::tools::Long nHMM )       { return (nHMM * 72 + 63) / 127; }
    inline ::tools::Long TwipsToEvenHMM( ::tools::Long nTwips ) { return ( (nTwips * 127 + 72) / 144 ) * 2; }
}

                                    // standard size as OLE server (cells)
@@ -582,8 +583,8 @@ public:
    static sal_uInt16           nDefFontHeight;
    SC_DLLPUBLIC static sal_uInt16           nStdRowHeight;

    SC_DLLPUBLIC static long                nLastRowHeightExtra;
    static long             nLastColWidthExtra;
    SC_DLLPUBLIC static ::tools::Long                nLastRowHeightExtra;
    static ::tools::Long             nLastColWidthExtra;

    SC_DLLPUBLIC static void Init();                     // during start up
    static void             InitAddIns();
diff --git a/sc/inc/markarr.hxx b/sc/inc/markarr.hxx
index ac212b0..66c6114 100644
--- a/sc/inc/markarr.hxx
+++ b/sc/inc/markarr.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SC_INC_MARKARR_HXX

#include "address.hxx"
#include <tools/long.hxx>
#include <vector>

class ScRangeList;
@@ -72,7 +73,7 @@ public:
    SCROW   GetNextMarked( SCROW nRow, bool bUp ) const;
    SCROW   GetMarkEnd( SCROW nRow, bool bUp ) const;

    void    Shift( SCROW nStartRow, long nOffset );
    void    Shift( SCROW nStartRow, tools::Long nOffset );
    void    Intersect( const ScMarkArray& rOther );
};

diff --git a/sc/inc/markdata.hxx b/sc/inc/markdata.hxx
index 283202c..af4379f 100644
--- a/sc/inc/markdata.hxx
+++ b/sc/inc/markdata.hxx
@@ -142,8 +142,8 @@ public:
    void        InsertTab( SCTAB nTab );
    void        DeleteTab( SCTAB nTab );

    void        ShiftCols(const ScDocument& rDoc, SCCOL nStartCol, long nColOffset);
    void        ShiftRows(const ScDocument& rDoc, SCROW nStartRow, long nRowOffset);
    void        ShiftCols(const ScDocument& rDoc, SCCOL nStartCol, tools::Long nColOffset);
    void        ShiftRows(const ScDocument& rDoc, SCROW nStartRow, tools::Long nRowOffset);

    // Generate envelopes if multimarked and fills the passed ScRange object with
    // the smallest range that includes the marked area plus its envelopes.
diff --git a/sc/inc/markmulti.hxx b/sc/inc/markmulti.hxx
index c209018..7af1ce7 100644
--- a/sc/inc/markmulti.hxx
+++ b/sc/inc/markmulti.hxx
@@ -64,8 +64,8 @@ public:
    void Clear();
    void MarkAllCols( SCROW nStartRow, SCROW nEndRow );
    bool HasAnyMarks() const;
    void ShiftCols(SCCOL nStartCol, long nColOffset);
    void ShiftRows(SCROW nStartRow, long nRowOffset);
    void ShiftCols(SCCOL nStartCol, tools::Long nColOffset);
    void ShiftRows(SCROW nStartRow, tools::Long nRowOffset);

    // For faster access from within ScMarkData, instead of creating
    // ScMultiSelIter with ScFlatBoolRowSegments bottleneck.
diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx
index d6c21e0..63e854e 100644
--- a/sc/inc/patattr.hxx
+++ b/sc/inc/patattr.hxx
@@ -139,7 +139,7 @@ public:
    sal_uInt32              GetNumberFormat( SvNumberFormatter* pFormatter,
                                             const SfxItemSet* pCondSet ) const;

    long                    GetRotateVal( const SfxItemSet* pCondSet ) const;
    tools::Long                    GetRotateVal( const SfxItemSet* pCondSet ) const;
    ScRotateDir             GetRotateDir( const SfxItemSet* pCondSet ) const;

    void                    SetKey(sal_uInt64 nKey);
diff --git a/sc/inc/pivot.hxx b/sc/inc/pivot.hxx
index 6bdd243..690f0bc 100644
--- a/sc/inc/pivot.hxx
+++ b/sc/inc/pivot.hxx
@@ -37,6 +37,7 @@
#define INCLUDED_SC_INC_PIVOT_HXX

#include <rtl/ustring.hxx>
#include <tools/long.hxx>
#include "types.hxx"
#include "scdllapi.h"
#include "dpglobal.hxx"
@@ -69,7 +70,7 @@ struct ScDPLabelData
    OUString   maLayoutName;   ///< Layout name (display name)
    OUString   maSubtotalName;
    SCCOL      mnCol;          ///< 0-based field index (not the source column index)
    long       mnOriginalDim;  ///< original dimension index (>= 0 for duplicated dimension)
    tools::Long       mnOriginalDim;  ///< original dimension index (>= 0 for duplicated dimension)
    PivotFunc  mnFuncMask;     ///< Page/Column/Row subtotal function.
    sal_Int32  mnUsedHier;     ///< Used hierarchy.
    sal_Int32  mnFlags;        ///< Flags from the DataPilotSource dimension
@@ -116,14 +117,14 @@ struct ScPivotField
{
    css::sheet::DataPilotFieldReference maFieldRef;

    long        mnOriginalDim; ///< >= 0 for duplicated field.
    tools::Long        mnOriginalDim; ///< >= 0 for duplicated field.
    PivotFunc   nFuncMask;
    SCCOL       nCol;          ///< 0-based dimension index (not source column index)
    sal_uInt8   mnDupCount;

    explicit ScPivotField( SCCOL nNewCol = 0 );

    long getOriginalDim() const;
    tools::Long getOriginalDim() const;
};

typedef std::vector< ScPivotField > ScPivotFieldVector;
@@ -157,7 +158,7 @@ struct ScPivotFuncData
{
    css::sheet::DataPilotFieldReference maFieldRef;

    long       mnOriginalDim;
    tools::Long       mnOriginalDim;
    PivotFunc  mnFuncMask;
    SCCOL      mnCol;
    sal_uInt8  mnDupCount;
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index f360643..7feb1ea 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -461,12 +461,12 @@ public:

    virtual VclPtr<AbstractScMetricInputDlg> CreateScMetricInputDlg(weld::Window* pParent,
                                                                const OString&  sDialogName,
                                                                long            nCurrent,
                                                                long            nDefault,
                                                                tools::Long            nCurrent,
                                                                tools::Long            nDefault,
                                                                FieldUnit       eFUnit,
                                                                sal_uInt16      nDecimals,
                                                                long            nMaximum,
                                                                long            nMinimum  = 0 ) = 0;
                                                                tools::Long            nMaximum,
                                                                tools::Long            nMinimum  = 0 ) = 0;

    virtual VclPtr<AbstractScMoveTableDlg> CreateScMoveTableDlg(weld::Window * pParent,
        const OUString& rDefault) = 0;
diff --git a/sc/inc/scextopt.hxx b/sc/inc/scextopt.hxx
index 22c48d68..46cb735 100644
--- a/sc/inc/scextopt.hxx
+++ b/sc/inc/scextopt.hxx
@@ -56,8 +56,8 @@ struct ScExtTabSettings
    Point               maSplitPos;         ///< Position of split.
    ScExtPanePos        meActivePane;       ///< Active (focused) pane.
    Color               maGridColor;        ///< Grid color.
    long                mnNormalZoom;       ///< Zoom in percent for normal view.
    long                mnPageZoom;         ///< Zoom in percent for pagebreak preview.
    tools::Long                mnNormalZoom;       ///< Zoom in percent for normal view.
    tools::Long                mnPageZoom;         ///< Zoom in percent for pagebreak preview.
    bool                mbSelected;         ///< true = Sheet is selected.
    bool                mbFrozenPanes;      ///< true = Frozen panes; false = Normal splits.
    bool                mbPageMode;         ///< true = Pagebreak mode; false = Normal view mode.
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 3c2ab08..5a5bc55 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -786,7 +786,7 @@ public:
        sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow,
        ScProgress* pOuterProgress = nullptr, sal_uLong nProgressStart = 0 );

    long        GetNeededSize( SCCOL nCol, SCROW nRow,
    tools::Long        GetNeededSize( SCCOL nCol, SCROW nRow,
                                    OutputDevice* pDev,
                                    double nPPTX, double nPPTY,
                                    const Fraction& rZoomX, const Fraction& rZoomY,
diff --git a/sc/qa/extras/scannotationsobj.cxx b/sc/qa/extras/scannotationsobj.cxx
index 72fafc6..aba02c3 100644
--- a/sc/qa/extras/scannotationsobj.cxx
+++ b/sc/qa/extras/scannotationsobj.cxx
@@ -43,7 +43,7 @@ public:
    virtual void tearDown() override;

    virtual uno::Reference< uno::XInterface > init() override;
    virtual uno::Reference< sheet::XSheetAnnotations > getAnnotations(long nIndex) override;
    virtual uno::Reference< sheet::XSheetAnnotations > getAnnotations(tools::Long nIndex) override;

    CPPUNIT_TEST_SUITE(ScAnnontationsObj);

@@ -79,7 +79,7 @@ ScAnnontationsObj::ScAnnontationsObj()
{
}

uno::Reference< sheet::XSheetAnnotations> ScAnnontationsObj::getAnnotations(long nIndex)
uno::Reference< sheet::XSheetAnnotations> ScAnnontationsObj::getAnnotations(tools::Long nIndex)
{
    // get the sheet
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW);
diff --git a/sc/qa/unit/bugfix-test.cxx b/sc/qa/unit/bugfix-test.cxx
index df5817a..30164e9 100644
--- a/sc/qa/unit/bugfix-test.cxx
+++ b/sc/qa/unit/bugfix-test.cxx
@@ -175,8 +175,8 @@ void ScFiltersTest::testTdf91979()
    Point aPos = aViewData.GetScrPos(MAXCOL - 1, 10000, SC_SPLIT_TOPLEFT, true);
    int nColWidth = ScViewData::ToPixel(rDoc.GetColWidth(0, 0), aViewData.GetPPTX());
    int nRowHeight = ScViewData::ToPixel(rDoc.GetRowHeight(0, 0), aViewData.GetPPTY());
    CPPUNIT_ASSERT_EQUAL(static_cast<long>((MAXCOL - 1) * nColWidth), aPos.getX());
    CPPUNIT_ASSERT_EQUAL(static_cast<long>(10000 * nRowHeight), aPos.getY());
    CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>((MAXCOL - 1) * nColWidth), aPos.getX());
    CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(10000 * nRowHeight), aPos.getY());
}

/*
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index c537bae..8cf4795 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -488,7 +488,7 @@ void ScFiltersTest::testTdf79998()
    xDocSh->DoClose();
}

static void impl_testLegacyCellAnchoredRotatedShape( ScDocument& rDoc, const tools::Rectangle& aRect, const ScDrawObjData& aAnchor, long TOLERANCE = 30 /* 30 hmm */ )
static void impl_testLegacyCellAnchoredRotatedShape( ScDocument& rDoc, const tools::Rectangle& aRect, const ScDrawObjData& aAnchor, tools::Long TOLERANCE = 30 /* 30 hmm */ )
{
    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
    CPPUNIT_ASSERT_MESSAGE("No drawing layer.", pDrawLayer);
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 130ff02..1b0d5e3 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -95,7 +95,7 @@ const FileFormat ScBootstrapFixture::aFileFormats[] = {
    { "xltx", "Calc Office Open XML Template", "Office Open XML Spreadsheet Template", XLTX_FORMAT_TYPE }
};

bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol )
bool testEqualsWithTolerance( tools::Long nVal1, tools::Long nVal2, tools::Long nTol )
{
    return ( labs( nVal1 - nVal2 ) <= nTol );
}
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index 1a72128..d8ffa14 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -60,7 +60,7 @@ namespace utl { class TempFile; }

enum class StringType { PureString, StringValue };

SCQAHELPER_DLLPUBLIC bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol );
SCQAHELPER_DLLPUBLIC bool testEqualsWithTolerance( tools::Long nVal1, tools::Long nVal2, tools::Long nTol );

#define CHECK_OPTIMAL 0x1

diff --git a/sc/qa/unit/pivottable_filters_test.cxx b/sc/qa/unit/pivottable_filters_test.cxx
index 3e26fca..49248230 100644
--- a/sc/qa/unit/pivottable_filters_test.cxx
+++ b/sc/qa/unit/pivottable_filters_test.cxx
@@ -309,8 +309,8 @@ void ScPivotTableFiltersTest::testPivotTableNamedRangeSourceODS()
    CPPUNIT_ASSERT_EQUAL(OUString("MyRange"), pDesc->GetRangeName());

    css::sheet::DataPilotFieldOrientation nOrient;
    long nDim = pDP->GetHeaderDim(ScAddress(0, 1, 1), nOrient);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to detect header dimension.", long(0), nDim);
    tools::Long nDim = pDP->GetHeaderDim(ScAddress(0, 1, 1), nOrient);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to detect header dimension.", tools::Long(0), nDim);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("This dimension should be a page dimension.",
                                 sheet::DataPilotFieldOrientation_PAGE, nOrient);

@@ -403,7 +403,7 @@ void ScPivotTableFiltersTest::testPivotTableSharedCacheGroupODS()
    bool bHasMonths = false;
    std::vector<SCROW> aMemberIds;

    for (long nGrpDim = 9; nGrpDim <= 10; ++nGrpDim)
    for (tools::Long nGrpDim = 9; nGrpDim <= 10; ++nGrpDim)
    {
        nGrpType = pCache->GetGroupType(nGrpDim);
        switch (nGrpType)
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index bf015d9..a1a129e1 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -2570,7 +2570,7 @@ void ScExportTest::testExcelCellBorders( sal_uLong nFormatType )
    {
        SCROW mnRow;
        SvxBorderLineStyle mnStyle;
        long mnWidth;
        tools::Long mnWidth;
    } aChecks[] = {
        {  1, SvxBorderLineStyle::SOLID,         1 }, // hair
        {  3, SvxBorderLineStyle::DOTTED,       15 }, // dotted
@@ -2648,7 +2648,7 @@ void ScExportTest::testBordersExchangeXLSX()
    static struct
    {
        SvxBorderLineStyle BorderStyleTop, BorderStyleBottom;
        long                      WidthTop, WidthBottom;
        tools::Long                      WidthTop, WidthBottom;
    } aCheckBorderWidth[nMaxCol][nMaxRow] =
    {
/*  Line               1                                2                              3                            4                             5                                6                              7
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 5b61e28..3053f7b 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -1088,10 +1088,10 @@ struct Border
{
    sal_Int16 column;
    sal_Int32 row;
    long leftWidth;
    long topWidth;
    long rightWidth;
    long bottomWidth;
    tools::Long leftWidth;
    tools::Long topWidth;
    tools::Long rightWidth;
    tools::Long bottomWidth;
    sal_uInt16 lOutWidth;
    sal_uInt16 lInWidth;
    sal_uInt16 lDistance;
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 4e4b11a..78e2755 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -2797,7 +2797,7 @@ void Test::testGraphicsInGroup()
        m_pDoc->ShowRows(0, 100, 0, false);
        m_pDoc->SetDrawPageSize(0);

        const long TOLERANCE = 30; //30 hmm
        const tools::Long TOLERANCE = 30; //30 hmm

        CPPUNIT_ASSERT_MESSAGE("Left and Right should be unchanged",
            testEqualsWithTolerance(aOrigRect.Left(), rNewRect.Left(), TOLERANCE) &&
@@ -5706,7 +5706,7 @@ void Test::testAnchoredRotatedShape()
    SdrPage* pPage = pDrawLayer->GetPage(0);
    CPPUNIT_ASSERT_MESSAGE("must have a draw page", pPage != nullptr);
    m_pDoc->SetRowHeightRange( 0, MAXROW, 0, sc::HMMToTwips( 1000 ) );
    constexpr long TOLERANCE = 30; //30 hmm
    constexpr tools::Long TOLERANCE = 30; //30 hmm
    for ( SCCOL nCol = 0; nCol < MAXCOL; ++nCol )
        m_pDoc->SetColWidth( nCol, 0, sc::HMMToTwips( 1000 ) );
    {
diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx
index 3030880..ec9fc79 100644
--- a/sc/qa/unit/ucalc_pivottable.cxx
+++ b/sc/qa/unit/ucalc_pivottable.cxx
@@ -775,7 +775,7 @@ void Test::testPivotTableCache()

    ScDPCache aCache(*m_pDoc);
    aCache.InitFromDoc(*m_pDoc, aDataRange);
    long nDimCount = aCache.GetColumnCount();
    tools::Long nDimCount = aCache.GetColumnCount();
    CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong dimension count.", 3L, nDimCount);
    OUString aDimName = aCache.GetDimensionName(0);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong dimension name", OUString("F1"), aDimName);
@@ -790,7 +790,7 @@ void Test::testPivotTableCache()
    // exist.

    // Dimension 0 - a mix of strings and values.
    long nMemCount = aCache.GetDimMemberCount(0);
    tools::Long nMemCount = aCache.GetDimMemberCount(0);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong dimension member count", 6L, nMemCount);
    const ScDPItemData* pItem = aCache.GetItemDataById(0, 0);
    CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem &&
@@ -870,7 +870,7 @@ void Test::testPivotTableCache()
    {
        // Check the integrity of the source data.
        ScDPItemData aTest;
        long nDim;
        tools::Long nDim;

        {
            // Dimension 0: Z, R, A, F, Y, 12
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 6a6e598..b582ac2 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -206,9 +206,9 @@ bool ScAttrArray::Search( SCROW nRow, SCSIZE& nIndex ) const
        return true;
    }

    long nHi = static_cast<long>(mvData.size()) - 1;
    long i = 0;
    long nLo = 0;
    tools::Long nHi = static_cast<tools::Long>(mvData.size()) - 1;
    tools::Long i = 0;
    tools::Long nLo = 0;

    while ( nLo <= nHi )
    {
@@ -1726,7 +1726,7 @@ void ScAttrArray::ChangeIndent( SCROW nStartRow, SCROW nEndRow, bool bIncrement 
        sal_uInt16 nOldValue = rOldSet.Get( ATTR_INDENT ).GetValue();
        sal_uInt16 nNewValue = nOldValue;
        // To keep Increment indent from running outside the cell1659
        long nColWidth = static_cast<long>(rDocument.GetColWidth(nCol,nTab));
        tools::Long nColWidth = static_cast<tools::Long>(rDocument.GetColWidth(nCol,nTab));
        if ( bIncrement )
        {
            if ( nNewValue < nColWidth-SC_INDENT_STEP )
@@ -1770,7 +1770,7 @@ void ScAttrArray::ChangeIndent( SCROW nStartRow, SCROW nEndRow, bool bIncrement 

SCROW ScAttrArray::GetNextUnprotected( SCROW nRow, bool bUp ) const
{
    long nRet = nRow;
    tools::Long nRet = nRow;
    if (rDocument.ValidRow(nRow))
    {
        if ( mvData.empty() )
@@ -2389,13 +2389,13 @@ void ScAttrArray::MoveTo(SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray
 * Copy between documents (Clipboard)
 */
void ScAttrArray::CopyArea(
    SCROW nStartRow, SCROW nEndRow, long nDy, ScAttrArray& rAttrArray, ScMF nStripFlags) const
    SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray, ScMF nStripFlags) const
{
    nStartRow -= nDy;   // Source
    nEndRow -= nDy;

    SCROW nDestStart = std::max(static_cast<long>(static_cast<long>(nStartRow) + nDy), long(0));
    SCROW nDestEnd = std::min(static_cast<long>(static_cast<long>(nEndRow) + nDy), long(rDocument.MaxRow()));
    SCROW nDestStart = std::max(static_cast<tools::Long>(static_cast<tools::Long>(nStartRow) + nDy), tools::Long(0));
    SCROW nDestEnd = std::min(static_cast<tools::Long>(static_cast<tools::Long>(nEndRow) + nDy), tools::Long(rDocument.MaxRow()));

    ScDocumentPool* pSourceDocPool = rDocument.GetPool();
    ScDocumentPool* pDestDocPool = rAttrArray.rDocument.GetPool();
@@ -2452,7 +2452,7 @@ void ScAttrArray::CopyArea(

        // when pasting from clipboard and skipping filtered rows, the adjusted
        // end position can be negative
        nDestStart = std::max(static_cast<long>(nDestStart), static_cast<long>(mvData[i].nEndRow + nDy + 1));
        nDestStart = std::max(static_cast<tools::Long>(nDestStart), static_cast<tools::Long>(mvData[i].nEndRow + nDy + 1));
    }
}

@@ -2460,13 +2460,13 @@ void ScAttrArray::CopyArea(
 * Leave flags
 * summarized with CopyArea
 */
void ScAttrArray::CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttrArray& rAttrArray )
void ScAttrArray::CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray )
{
    nStartRow -= nDy;  // Source
    nEndRow -= nDy;

    SCROW nDestStart = std::max(static_cast<long>(static_cast<long>(nStartRow) + nDy), long(0));
    SCROW nDestEnd = std::min(static_cast<long>(static_cast<long>(nEndRow) + nDy), long(rDocument.MaxRow()));
    SCROW nDestStart = std::max(static_cast<tools::Long>(static_cast<tools::Long>(nStartRow) + nDy), tools::Long(0));
    SCROW nDestEnd = std::min(static_cast<tools::Long>(static_cast<tools::Long>(nEndRow) + nDy), tools::Long(rDocument.MaxRow()));

    if ( !rAttrArray.HasAttrib( nDestStart, nDestEnd, HasAttrFlags::Overlapped ) )
    {
@@ -2509,7 +2509,7 @@ void ScAttrArray::CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttr

        // when pasting from clipboard and skipping filtered rows, the adjusted
        // end position can be negative
        nDestStart = std::max(static_cast<long>(nDestStart), static_cast<long>(mvData[i].nEndRow + nDy + 1));
        nDestStart = std::max(static_cast<tools::Long>(nDestStart), static_cast<tools::Long>(mvData[i].nEndRow + nDy + 1));
    }
}

diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 013d6d4..886dab8 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -79,7 +79,7 @@ static bool IsAmbiguousScript( SvtScriptType nScript )

//  Data operations

long ScColumn::GetNeededSize(
tools::Long ScColumn::GetNeededSize(
    SCROW nRow, OutputDevice* pDev, double nPPTX, double nPPTY,
    const Fraction& rZoomX, const Fraction& rZoomY,
    bool bWidth, const ScNeededSizeOptions& rOptions,
@@ -98,12 +98,12 @@ long ScColumn::GetNeededSize(
        // Empty cell, or invalid row.
        return 0;

    long nValue = 0;
    tools::Long nValue = 0;
    ScRefCellValue aCell = GetCellValue(it, aPos.second);
    double nPPT = bWidth ? nPPTX : nPPTY;

    auto conditionalScaleFunc = [bInPrintTwips](long nMeasure, double fScale) {
        return bInPrintTwips ? nMeasure : static_cast<long>(nMeasure * fScale);
    auto conditionalScaleFunc = [bInPrintTwips](tools::Long nMeasure, double fScale) {
        return bInPrintTwips ? nMeasure : static_cast<tools::Long>(nMeasure * fScale);
    };

    const ScPatternAttr* pPattern = rOptions.pPattern;
@@ -212,7 +212,7 @@ long ScColumn::GetNeededSize(
    if ( bWidth && bBreak )     // after determining bAsianVertical (bBreak may be reset)
        return 0;

    long nRotate = 0;
    tools::Long nRotate = 0;
    SvxRotateMode eRotMode = SVX_ROTATE_MODE_STANDARD;
    if ( eOrient == SvxCellOrientation::Standard )
    {
@@ -294,7 +294,7 @@ long ScColumn::GetNeededSize(
            Size aSize( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() );
            if ( eOrient != SvxCellOrientation::Standard )
            {
                long nTemp = aSize.Width();
                tools::Long nTemp = aSize.Width();
                aSize.setWidth( aSize.Height() );
                aSize.setHeight( nTemp );
            }
@@ -305,10 +305,10 @@ long ScColumn::GetNeededSize(
                double nRealOrient = nRotate * F_PI18000;   // nRotate is in 1/100 Grad
                double nCosAbs = fabs( cos( nRealOrient ) );
                double nSinAbs = fabs( sin( nRealOrient ) );
                long nHeight = static_cast<long>( aSize.Height() * nCosAbs + aSize.Width() * nSinAbs );
                long nWidth;
                tools::Long nHeight = static_cast<tools::Long>( aSize.Height() * nCosAbs + aSize.Width() * nSinAbs );
                tools::Long nWidth;
                if ( eRotMode == SVX_ROTATE_MODE_STANDARD )
                    nWidth  = static_cast<long>( aSize.Width() * nCosAbs + aSize.Height() * nSinAbs );
                    nWidth  = static_cast<tools::Long>( aSize.Width() * nCosAbs + aSize.Height() * nSinAbs );
                else if ( rOptions.bTotalSize )
                {
                    nWidth = conditionalScaleFunc(rDocument.GetColWidth( nCol,nTab ), nPPT);
@@ -316,16 +316,16 @@ long ScColumn::GetNeededSize(
                    //  only to the right:
                    //TODO: differ on direction up/down (only Text/whole height)
                    if ( pPattern->GetRotateDir( pCondSet ) == ScRotateDir::Right )
                        nWidth += static_cast<long>( rDocument.GetRowHeight( nRow,nTab ) *
                        nWidth += static_cast<tools::Long>( rDocument.GetRowHeight( nRow,nTab ) *
                                            (bInPrintTwips ? 1.0 : nPPT) * nCosAbs / nSinAbs );
                }
                else
                    nWidth  = static_cast<long>( aSize.Height() / nSinAbs );   //TODO: limit?
                    nWidth  = static_cast<tools::Long>( aSize.Height() / nSinAbs );   //TODO: limit?

                if ( bBreak && !rOptions.bTotalSize )
                {
                    //  limit size for line break
                    long nCmp = pDev->GetFont().GetFontSize().Height() * SC_ROT_BREAK_FACTOR;
                    tools::Long nCmp = pDev->GetFont().GetFontSize().Height() * SC_ROT_BREAK_FACTOR;
                    if ( nHeight > nCmp )
                        nHeight = nCmp;
                }
@@ -355,7 +355,7 @@ long ScColumn::GetNeededSize(
                //  test with EditEngine the safety at 90%
                //  (due to rounding errors and because EditEngine formats partially differently)

                long nDocSize = conditionalScaleFunc((rDocument.GetColWidth( nCol,nTab ) -
                tools::Long nDocSize = conditionalScaleFunc((rDocument.GetColWidth( nCol,nTab ) -
                                    pMargin->GetLeftMargin() - pMargin->GetRightMargin() -
                                    nIndent), nPPTX);
                nDocSize = (nDocSize * 9) / 10;           // for safety
@@ -425,22 +425,22 @@ long ScColumn::GetNeededSize(
            }

            // use original width for hidden columns:
            long nDocWidth = static_cast<long>( rDocument.GetOriginalWidth(nCol,nTab) * fWidthFactor );
            tools::Long nDocWidth = static_cast<tools::Long>( rDocument.GetOriginalWidth(nCol,nTab) * fWidthFactor );
            SCCOL nColMerge = pMerge->GetColMerge();
            if (nColMerge > 1)
                for (SCCOL nColAdd=1; nColAdd<nColMerge; nColAdd++)
                    nDocWidth += static_cast<long>( rDocument.GetColWidth(nCol+nColAdd,nTab) * fWidthFactor );
            nDocWidth -= static_cast<long>( pMargin->GetLeftMargin() * fWidthFactor )
                       + static_cast<long>( pMargin->GetRightMargin() * fWidthFactor )
                    nDocWidth += static_cast<tools::Long>( rDocument.GetColWidth(nCol+nColAdd,nTab) * fWidthFactor );
            nDocWidth -= static_cast<tools::Long>( pMargin->GetLeftMargin() * fWidthFactor )
                       + static_cast<tools::Long>( pMargin->GetRightMargin() * fWidthFactor )
                       + 1;     // output size is width-1 pixel (due to gridline)
            if ( nIndent )
                nDocWidth -= static_cast<long>( nIndent * fWidthFactor );
                nDocWidth -= static_cast<tools::Long>( nIndent * fWidthFactor );

            // space for AutoFilter button:  20 * nZoom/100
            constexpr long nFilterButtonWidthPix = 20; // Autofilter pixel width at 100% zoom.
            constexpr tools::Long nFilterButtonWidthPix = 20; // Autofilter pixel width at 100% zoom.
            if ( pFlag->HasAutoFilter() && !bTextWysiwyg )
                nDocWidth -= bInPrintTwips ?
                        (nFilterButtonWidthPix * TWIPS_PER_PIXEL) : long(rZoomX * nFilterButtonWidthPix);
                        (nFilterButtonWidthPix * TWIPS_PER_PIXEL) : tools::Long(rZoomX * nFilterButtonWidthPix);

            aPaper.setWidth( nDocWidth );

@@ -486,20 +486,20 @@ long ScColumn::GetNeededSize(
            double nRealOrient = nRotate * F_PI18000;   // nRotate is in 1/100 Grad
            double nCosAbs = fabs( cos( nRealOrient ) );
            double nSinAbs = fabs( sin( nRealOrient ) );
            long nHeight = static_cast<long>( aSize.Height() * nCosAbs + aSize.Width() * nSinAbs );
            long nWidth;
            tools::Long nHeight = static_cast<tools::Long>( aSize.Height() * nCosAbs + aSize.Width() * nSinAbs );
            tools::Long nWidth;
            if ( eRotMode == SVX_ROTATE_MODE_STANDARD )
                nWidth  = static_cast<long>( aSize.Width() * nCosAbs + aSize.Height() * nSinAbs );
                nWidth  = static_cast<tools::Long>( aSize.Width() * nCosAbs + aSize.Height() * nSinAbs );
            else if ( rOptions.bTotalSize )
            {
                nWidth = conditionalScaleFunc(rDocument.GetColWidth( nCol,nTab ), nPPT);
                bAddMargin = false;
                if ( pPattern->GetRotateDir( pCondSet ) == ScRotateDir::Right )
                    nWidth += static_cast<long>( rDocument.GetRowHeight( nRow,nTab ) *
                    nWidth += static_cast<tools::Long>( rDocument.GetRowHeight( nRow,nTab ) *
                                        (bInPrintTwips ? 1.0 : nPPT) * nCosAbs / nSinAbs );
            }
            else
                nWidth  = static_cast<long>( aSize.Height() / nSinAbs );   //TODO: limit?
                nWidth  = static_cast<tools::Long>( aSize.Height() / nSinAbs );   //TODO: limit?
            aSize = Size( nWidth, nHeight );

            Size aTextSize = bInPrintTwips ?
@@ -515,7 +515,7 @@ long ScColumn::GetNeededSize(
                if ( bBreak && !rOptions.bTotalSize )
                {
                    //  limit size for line break
                    long nCmp = aOldFont.GetFontSize().Height() * SC_ROT_BREAK_FACTOR;
                    tools::Long nCmp = aOldFont.GetFontSize().Height() * SC_ROT_BREAK_FACTOR;
                    if ( nValue > nCmp )
                        nValue = nCmp;
                }
@@ -547,7 +547,7 @@ long ScColumn::GetNeededSize(
                pEngine->SetControlWord( nCtrl | EEControlBits::FORMAT100 );
                pEngine->QuickFormatDoc( true );
                aTextSize = Size(0, pEngine->GetTextHeight());
                long nSecondValue = bInPrintTwips ?
                tools::Long nSecondValue = bInPrintTwips ?
                        OutputDevice::LogicToLogic(aTextSize, aHMMMode, aTwipMode).Height() :
                        pDev->LogicToPixel(aTextSize, aHMMMode).Height();
                if ( nSecondValue > nValue )
@@ -572,7 +572,7 @@ long ScColumn::GetNeededSize(
                if ( bAsianVertical && pDev->GetOutDevType() != OUTDEV_PRINTER )
                {
                    //  add 1pt extra (default margin value) for line breaks with SetVertical
                    constexpr long nDefaultMarginInPoints = 1;
                    constexpr tools::Long nDefaultMarginInPoints = 1;
                    nValue += conditionalScaleFunc(nDefaultMarginInPoints * TWIPS_PER_POINT, nPPT);
                }
            }
@@ -592,11 +592,11 @@ long ScColumn::GetNeededSize(
        //      place for Autofilter Button
        //      20 * nZoom/100
        //      Conditional formatting is not interesting here
        constexpr long nFilterButtonWidthPix = 20; // Autofilter pixel width at 100% zoom.
        constexpr tools::Long nFilterButtonWidthPix = 20; // Autofilter pixel width at 100% zoom.
        ScMF nFlags = pPattern->GetItem(ATTR_MERGE_FLAG).GetValue();
        if (nFlags & ScMF::Auto)
            nValue += bInPrintTwips ?
                (nFilterButtonWidthPix * TWIPS_PER_PIXEL) : long(rZoomX * nFilterButtonWidthPix);
                (nFilterButtonWidthPix * TWIPS_PER_PIXEL) : tools::Long(rZoomX * nFilterButtonWidthPix);
    }

    return nValue;
@@ -692,8 +692,8 @@ sal_uInt16 ScColumn::GetOptimalColWidth(
        pPattern->GetFont( aFont, SC_AUTOCOL_BLACK, pDev, &rZoomX );
        pDev->SetFont( aFont );
        const SvxMarginItem* pMargin = &pPattern->GetItem(ATTR_MARGIN);
        long nMargin = static_cast<long>( pMargin->GetLeftMargin() * nPPTX ) +
                        static_cast<long>( pMargin->GetRightMargin() * nPPTX );
        tools::Long nMargin = static_cast<tools::Long>( pMargin->GetLeftMargin() * nPPTX ) +
                        static_cast<tools::Long>( pMargin->GetRightMargin() * nPPTX );

        // Try to find the row that has the longest string, and measure the width of that string.
        SvNumberFormatter* pFormatter = rDocument.GetFormatTable();
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 4142683..f1a621a 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1061,9 +1061,9 @@ class CopyAttrArrayByRange
{
    ScAttrArray& mrDestAttrArray;
    ScAttrArray& mrSrcAttrArray;
    long mnRowOffset;
    tools::Long mnRowOffset;
public:
    CopyAttrArrayByRange(ScAttrArray& rDestAttrArray, ScAttrArray& rSrcAttrArray, long nRowOffset) :
    CopyAttrArrayByRange(ScAttrArray& rDestAttrArray, ScAttrArray& rSrcAttrArray, tools::Long nRowOffset) :
        mrDestAttrArray(rDestAttrArray), mrSrcAttrArray(rSrcAttrArray), mnRowOffset(nRowOffset) {}

    void operator() (const sc::RowSpan& rSpan)
@@ -1082,7 +1082,7 @@ class CopyCellsFromClipHandler
    SCCOL mnCol;
    SCTAB mnSrcTab;
    SCCOL mnSrcCol;
    long mnRowOffset;
    tools::Long mnRowOffset;
    sc::ColumnBlockPosition maDestBlockPos;
    sc::ColumnBlockPosition* mpDestBlockPos; // to save it for next iteration.
    svl::SharedStringPool* mpSharedStringPool;
@@ -1108,7 +1108,7 @@ class CopyCellsFromClipHandler
    }

public:
    CopyCellsFromClipHandler(sc::CopyFromClipContext& rCxt, ScColumn& rSrcCol, ScColumn& rDestCol, SCTAB nDestTab, SCCOL nDestCol, long nRowOffset, svl::SharedStringPool* pSharedStringPool) :
    CopyCellsFromClipHandler(sc::CopyFromClipContext& rCxt, ScColumn& rSrcCol, ScColumn& rDestCol, SCTAB nDestTab, SCCOL nDestCol, tools::Long nRowOffset, svl::SharedStringPool* pSharedStringPool) :
        mrCxt(rCxt),
        mrSrcCol(rSrcCol),
        mrDestCol(rDestCol),
@@ -1388,7 +1388,7 @@ public:
//  nRow1, nRow2 = target position

void ScColumn::CopyFromClip(
    sc::CopyFromClipContext& rCxt, SCROW nRow1, SCROW nRow2, long nDy, ScColumn& rColumn )
    sc::CopyFromClipContext& rCxt, SCROW nRow1, SCROW nRow2, tools::Long nDy, ScColumn& rColumn )
{
    if ((rCxt.getInsertFlag() & InsertDeleteFlags::ATTRIB) != InsertDeleteFlags::NONE)
    {
diff --git a/sc/source/core/data/compressedarray.cxx b/sc/source/core/data/compressedarray.cxx
index 6a3d415..e585bed 100644
--- a/sc/source/core/data/compressedarray.cxx
+++ b/sc/source/core/data/compressedarray.cxx
@@ -42,23 +42,23 @@ size_t ScCompressedArray<A,D>::Search( A nAccess ) const
    if (nAccess == 0)
        return 0;

    long nLo    = 0;
    long nHi    = static_cast<long>(nCount) - 1;
    long nStart = 0;
    long i      = 0;
    tools::Long nLo    = 0;
    tools::Long nHi    = static_cast<tools::Long>(nCount) - 1;
    tools::Long nStart = 0;
    tools::Long i      = 0;
    bool bFound = (nCount == 1);
    while (!bFound && nLo <= nHi)
    {
        i = (nLo + nHi) / 2;
        if (i > 0)
            nStart = static_cast<long>(pData[i - 1].nEnd);
            nStart = static_cast<tools::Long>(pData[i - 1].nEnd);
        else
            nStart = -1;
        long nEnd = static_cast<long>(pData[i].nEnd);
        if (nEnd < static_cast<long>(nAccess))
        tools::Long nEnd = static_cast<tools::Long>(pData[i].nEnd);
        if (nEnd < static_cast<tools::Long>(nAccess))
            nLo = ++i;
        else
            if (nStart >= static_cast<long>(nAccess))
            if (nStart >= static_cast<tools::Long>(nAccess))
                nHi = --i;
            else
                bFound = true;
diff --git a/sc/source/core/data/dbdocutl.cxx b/sc/source/core/data/dbdocutl.cxx
index 07eca19..ff01e86 100644
--- a/sc/source/core/data/dbdocutl.cxx
+++ b/sc/source/core/data/dbdocutl.cxx
@@ -35,8 +35,8 @@ ScDatabaseDocUtil::StrData::StrData() :
}

void ScDatabaseDocUtil::PutData(ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab,
                                const uno::Reference<sdbc::XRow>& xRow, long nRowPos,
                                long nType, bool bCurrency, StrData* pStrData)
                                const uno::Reference<sdbc::XRow>& xRow, tools::Long nRowPos,
                                tools::Long nType, bool bCurrency, StrData* pStrData)
{
    OUString aString;
    double nVal = 0.0;
diff --git a/sc/source/core/data/docpool.cxx b/sc/source/core/data/docpool.cxx
index ad7e33a..01a821a 100644
--- a/sc/source/core/data/docpool.cxx
+++ b/sc/source/core/data/docpool.cxx
@@ -421,7 +421,7 @@ static bool lcl_HFPresentation
                sal_uInt16 nPropLeftMargin  = rLRItem.GetPropLeft();
                sal_uInt16 nPropRightMargin = rLRItem.GetPropRight();
                sal_uInt16 nLeftMargin, nRightMargin;
                long nTmp;
                tools::Long nTmp;
                nTmp = rLRItem.GetLeft();
                nLeftMargin = nTmp < 0 ? 0 : sal_uInt16(nTmp);
                nTmp = rLRItem.GetRight();
@@ -435,7 +435,7 @@ static bool lcl_HFPresentation
                }
                else
                {
                    aText += GetMetricText( static_cast<long>(nLeftMargin),
                    aText += GetMetricText( static_cast<tools::Long>(nLeftMargin),
                                           eCoreMetric, ePresentationMetric, &rIntl ) +
                        " " + EditResId(GetMetricId(ePresentationMetric));
                }
@@ -449,7 +449,7 @@ static bool lcl_HFPresentation
                }
                else
                {
                    aText += GetMetricText( static_cast<long>(nRightMargin),
                    aText += GetMetricText( static_cast<tools::Long>(nRightMargin),
                                            eCoreMetric, ePresentationMetric, &rIntl ) +
                        " " + EditResId(GetMetricId(ePresentationMetric));
                }
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 0c5c924..c2adce1 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1712,10 +1712,10 @@ tools::Rectangle ScDocument::GetEmbeddedRect() const // 1/100 mm
        aRect.SetBottom( aRect.Top() );
        aRect.AdjustBottom(pTable->GetRowHeight( aEmbedRange.aStart.Row(), aEmbedRange.aEnd.Row()) );

        aRect.SetLeft( static_cast<long>( aRect.Left()   * HMM_PER_TWIPS ) );
        aRect.SetRight( static_cast<long>( aRect.Right()  * HMM_PER_TWIPS ) );
        aRect.SetTop( static_cast<long>( aRect.Top()    * HMM_PER_TWIPS ) );
        aRect.SetBottom( static_cast<long>( aRect.Bottom() * HMM_PER_TWIPS ) );
        aRect.SetLeft( static_cast<tools::Long>( aRect.Left()   * HMM_PER_TWIPS ) );
        aRect.SetRight( static_cast<tools::Long>( aRect.Right()  * HMM_PER_TWIPS ) );
        aRect.SetTop( static_cast<tools::Long>( aRect.Top()    * HMM_PER_TWIPS ) );
        aRect.SetBottom( static_cast<tools::Long>( aRect.Bottom() * HMM_PER_TWIPS ) );
    }
    return aRect;
}
@@ -1736,7 +1736,7 @@ void ScDocument::ResetEmbedded()
    while result is less than nStopTwips.
    @return true if advanced at least one row.
 */
static bool lcl_AddTwipsWhile( long & rTwips, long nStopTwips, SCROW & rPosY, SCROW nEndRow, const ScTable * pTable, bool bHiddenAsZero )
static bool lcl_AddTwipsWhile( tools::Long & rTwips, tools::Long nStopTwips, SCROW & rPosY, SCROW nEndRow, const ScTable * pTable, bool bHiddenAsZero )
{
    SCROW nRow = rPosY;
    bool bAdded = false;
@@ -1766,7 +1766,7 @@ static bool lcl_AddTwipsWhile( long & rTwips, long nStopTwips, SCROW & rPosY, SC
                }
                bStop = true;
            }
            rTwips += static_cast<long>(nAdd);
            rTwips += static_cast<tools::Long>(nAdd);
            nRow += nRows;
        }
    }
@@ -1796,19 +1796,19 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool 
    if ( IsNegativePage( nTab ) )
        ScDrawLayer::MirrorRectRTL( aPosRect ); // Always with positive (LTR) values

    long nSize;
    long nTwips;
    long nAdd;
    tools::Long nSize;
    tools::Long nTwips;
    tools::Long nAdd;
    bool bEnd;

    nSize = 0;
    nTwips = static_cast<long>(aPosRect.Left() / HMM_PER_TWIPS);
    nTwips = static_cast<tools::Long>(aPosRect.Left() / HMM_PER_TWIPS);

    SCCOL nX1 = 0;
    bEnd = false;
    while (!bEnd)
    {
        nAdd = static_cast<long>(pTable->GetColWidth(nX1, bHiddenAsZero));
        nAdd = static_cast<tools::Long>(pTable->GetColWidth(nX1, bHiddenAsZero));
        if (nSize+nAdd <= nTwips+1 && nX1<MaxCol())
        {
            nSize += nAdd;
@@ -1823,10 +1823,10 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool 
    if (!aPosRect.IsEmpty())
    {
        bEnd = false;
        nTwips = static_cast<long>(aPosRect.Right() / HMM_PER_TWIPS);
        nTwips = static_cast<tools::Long>(aPosRect.Right() / HMM_PER_TWIPS);
        while (!bEnd)
        {
            nAdd = static_cast<long>(pTable->GetColWidth(nX2, bHiddenAsZero));
            nAdd = static_cast<tools::Long>(pTable->GetColWidth(nX2, bHiddenAsZero));
            if (nSize+nAdd < nTwips && nX2<MaxCol())
            {
                nSize += nAdd;
@@ -1838,7 +1838,7 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool 
    }

    nSize = 0;
    nTwips = static_cast<long>(aPosRect.Top() / HMM_PER_TWIPS);
    nTwips = static_cast<tools::Long>(aPosRect.Top() / HMM_PER_TWIPS);

    SCROW nY1 = 0;
    // Was if(nSize+nAdd<=nTwips+1) inside loop => if(nSize+nAdd<nTwips+2)
@@ -1848,7 +1848,7 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool 
    SCROW nY2 = nY1;
    if (!aPosRect.IsEmpty())
    {
        nTwips = static_cast<long>(aPosRect.Bottom() / HMM_PER_TWIPS);
        nTwips = static_cast<tools::Long>(aPosRect.Bottom() / HMM_PER_TWIPS);
        // Was if(nSize+nAdd<nTwips) inside loop => if(nSize+nAdd<nTwips)
        if (lcl_AddTwipsWhile( nSize, nTwips, nY2, MaxRow(), pTable, bHiddenAsZero) && nY2 < MaxRow())
            ++nY2;  // original loop ended on last matched +1 unless that was rDoc.MaxRow()
@@ -1991,10 +1991,10 @@ tools::Rectangle ScDocument::GetMMRect( SCCOL nStartCol, SCROW nStartRow, SCCOL 
        aRect.AdjustRight(GetColWidth(i,nTab, bHiddenAsZero) );
    aRect.AdjustBottom(GetRowHeight( nStartRow, nEndRow, nTab, bHiddenAsZero ) );

    aRect.SetLeft( static_cast<long>(aRect.Left()   * HMM_PER_TWIPS) );
    aRect.SetRight( static_cast<long>(aRect.Right()  * HMM_PER_TWIPS) );
    aRect.SetTop( static_cast<long>(aRect.Top()    * HMM_PER_TWIPS) );
    aRect.SetBottom( static_cast<long>(aRect.Bottom() * HMM_PER_TWIPS) );
    aRect.SetLeft( static_cast<tools::Long>(aRect.Left()   * HMM_PER_TWIPS) );
    aRect.SetRight( static_cast<tools::Long>(aRect.Right()  * HMM_PER_TWIPS) );
    aRect.SetTop( static_cast<tools::Long>(aRect.Top()    * HMM_PER_TWIPS) );
    aRect.SetBottom( static_cast<tools::Long>(aRect.Bottom() * HMM_PER_TWIPS) );

    if ( IsNegativePage( nTab ) )
        ScDrawLayer::MirrorRectRTL( aRect );
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 29da909..5e0e19f 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -1178,7 +1178,7 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
                aTabName +
                aTemplate.getToken( 0, '#', nIndex );
            ScProgress aProgress( GetDocumentShell(), aProText, 3*nThisEndRow, true );  // 2x FindOrder, 1x here
            long nProgressStart = 2*nThisEndRow;                    // start for here
            tools::Long nProgressStart = 2*nThisEndRow;                    // start for here

            std::unique_ptr<SCCOLROW[]> pTempRows(new SCCOLROW[nThisEndRow+1]);
            std::unique_ptr<SCCOLROW[]> pOtherRows(new SCCOLROW[nThisEndRow+1]);
diff --git a/sc/source/core/data/documen9.cxx b/sc/source/core/data/documen9.cxx
index daa2381..46d1b1c 100644
--- a/sc/source/core/data/documen9.cxx
+++ b/sc/source/core/data/documen9.cxx
@@ -448,16 +448,16 @@ bool ScDocument::IsPrintEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
        //  keep vertical part of aMMRect, only update horizontal position
        aMMRect = *pLastMM;

        long nLeft = 0;
        tools::Long nLeft = 0;
        SCCOL i;
        for (i=0; i<nStartCol; i++)
            nLeft += GetColWidth(i,nTab);
        long nRight = nLeft;
        tools::Long nRight = nLeft;
        for (i=nStartCol; i<=nEndCol; i++)
            nRight += GetColWidth(i,nTab);

        aMMRect.SetLeft( static_cast<long>(nLeft  * HMM_PER_TWIPS) );
        aMMRect.SetRight( static_cast<long>(nRight * HMM_PER_TWIPS) );
        aMMRect.SetLeft( static_cast<tools::Long>(nLeft  * HMM_PER_TWIPS) );
        aMMRect.SetRight( static_cast<tools::Long>(nRight * HMM_PER_TWIPS) );
    }
    else
        aMMRect = GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index d5f7d9e..c8d2d86 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -4250,7 +4250,7 @@ sal_uInt16 ScDocument::GetOptimalColWidth( SCCOL nCol, SCTAB nTab, OutputDevice*
    return 0;
}

long ScDocument::GetNeededSize( SCCOL nCol, SCROW nRow, SCTAB nTab,
tools::Long ScDocument::GetNeededSize( SCCOL nCol, SCROW nRow, SCTAB nTab,
                                    OutputDevice* pDev,
                                    double nPPTX, double nPPTY,
                                    const Fraction& rZoomX, const Fraction& rZoomY,
diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index 6a6cddb..02fc414 100644
--- a/sc/source/core/data/dpcache.cxx
+++ b/sc/source/core/data/dpcache.cxx
@@ -696,7 +696,7 @@ bool ScDPCache::ValidQuery( SCROW nRow, const ScQueryParam &rParam) const
    SCSIZE nEntryCount = rParam.GetEntryCount();
    std::vector<bool> aPassed(nEntryCount, false);

    long nPos = -1;
    tools::Long nPos = -1;
    CollatorWrapper* pCollator = (rParam.bCaseSens ? ScGlobal::GetCaseCollator() :
                                  ScGlobal::GetCollator() );
    ::utl::TransliterationWrapper* pTransliteration = (rParam.bCaseSens ?
@@ -875,7 +875,7 @@ bool ScDPCache::ValidQuery( SCROW nRow, const ScQueryParam &rParam) const
        }
    }

    for (long j=1; j <= nPos; j++)
    for (tools::Long j=1; j <= nPos; j++)
        aPassed[0] = aPassed[0] || aPassed[j];

    bool bRet = aPassed[0];
@@ -887,7 +887,7 @@ ScDocument& ScDPCache::GetDoc() const
    return mrDoc;
}

long ScDPCache::GetColumnCount() const
tools::Long ScDPCache::GetColumnCount() const
{
    return mnColumnCount;
}
@@ -899,17 +899,17 @@ bool ScDPCache::IsRowEmpty(SCROW nRow) const
    return bEmpty;
}

const ScDPCache::GroupItems* ScDPCache::GetGroupItems(long nDim) const
const ScDPCache::GroupItems* ScDPCache::GetGroupItems(tools::Long nDim) const
{
    if (nDim < 0)
        return nullptr;

    long nSourceCount = static_cast<long>(maFields.size());
    tools::Long nSourceCount = static_cast<tools::Long>(maFields.size());
    if (nDim < nSourceCount)
        return maFields[nDim]->mpGroup.get();

    nDim -= nSourceCount;
    if (nDim < static_cast<long>(maGroupFields.size()))
    if (nDim < static_cast<tools::Long>(maGroupFields.size()))
        return maGroupFields[nDim].get();

    return nullptr;
@@ -982,7 +982,7 @@ SCROW ScDPCache::GetItemDataId(sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty)
    return rField.maData[nRow];
}

const ScDPItemData* ScDPCache::GetItemDataById(long nDim, SCROW nId) const
const ScDPItemData* ScDPCache::GetItemDataById(tools::Long nDim, SCROW nId) const
{
    if (nDim < 0 || nId < 0)
        return nullptr;
@@ -1055,7 +1055,7 @@ const ScDPCache::ScDPItemDataVec& ScDPCache::GetDimMemberValues(SCCOL nDim) cons
    return maFields.at(nDim)->maItems;
}

sal_uInt32 ScDPCache::GetNumberFormat( long nDim ) const
sal_uInt32 ScDPCache::GetNumberFormat( tools::Long nDim ) const
{
    if ( nDim >= mnColumnCount )
        return 0;
@@ -1065,7 +1065,7 @@ sal_uInt32 ScDPCache::GetNumberFormat( long nDim ) const
    return maFields[nDim]->mnNumFormat;
}

bool ScDPCache::IsDateDimension( long nDim ) const
bool ScDPCache::IsDateDimension( tools::Long nDim ) const
{
    if (nDim >= mnColumnCount)
        return false;
@@ -1078,7 +1078,7 @@ bool ScDPCache::IsDateDimension( long nDim ) const
    return (eType == SvNumFormatType::DATE) || (eType == SvNumFormatType::DATETIME);
}

long ScDPCache::GetDimMemberCount(long nDim) const
tools::Long ScDPCache::GetDimMemberCount(tools::Long nDim) const
{
    OSL_ENSURE( nDim>=0 && nDim < mnColumnCount ," ScDPTableDataCache::GetDimMemberCount : out of bound ");
    return maFields[nDim]->maItems.size();
@@ -1121,7 +1121,7 @@ const ScDPCache::ScDPObjectSet& ScDPCache::GetAllReferences() const
    return maRefObjects;
}

SCROW ScDPCache::GetIdByItemData(long nDim, const ScDPItemData& rItem) const
SCROW ScDPCache::GetIdByItemData(tools::Long nDim, const ScDPItemData& rItem) const
{
    if (nDim < 0)
        return -1;
@@ -1207,7 +1207,7 @@ OUString ScDPCache::GetLocaleIndependentFormattedString( double fValue,
    return aStr;
}

OUString ScDPCache::GetFormattedString(long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const
OUString ScDPCache::GetFormattedString(tools::Long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const
{
    if (nDim < 0)
        return rItem.GetString();
@@ -1266,18 +1266,18 @@ SvNumberFormatter* ScDPCache::GetNumberFormatter() const
    return mrDoc.GetFormatTable();
}

long ScDPCache::AppendGroupField()
tools::Long ScDPCache::AppendGroupField()
{
    maGroupFields.push_back(std::make_unique<GroupItems>());
    return static_cast<long>(maFields.size() + maGroupFields.size() - 1);
    return static_cast<tools::Long>(maFields.size() + maGroupFields.size() - 1);
}

void ScDPCache::ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType)
void ScDPCache::ResetGroupItems(tools::Long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType)
{
    if (nDim < 0)
        return;

    long nSourceCount = static_cast<long>(maFields.size());
    tools::Long nSourceCount = static_cast<tools::Long>(maFields.size());
    if (nDim < nSourceCount)
    {
        maFields.at(nDim)->mpGroup.reset(new GroupItems(rNumInfo, nGroupType));
@@ -1285,7 +1285,7 @@ void ScDPCache::ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo, sal
    }

    nDim -= nSourceCount;
    if (nDim < static_cast<long>(maGroupFields.size()))
    if (nDim < static_cast<tools::Long>(maGroupFields.size()))
    {
        GroupItems& rGI = *maGroupFields[nDim];
        rGI.maItems.clear();
@@ -1294,12 +1294,12 @@ void ScDPCache::ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo, sal
    }
}

SCROW ScDPCache::SetGroupItem(long nDim, const ScDPItemData& rData)
SCROW ScDPCache::SetGroupItem(tools::Long nDim, const ScDPItemData& rData)
{
    if (nDim < 0)
        return -1;

    long nSourceCount = static_cast<long>(maFields.size());
    tools::Long nSourceCount = static_cast<tools::Long>(maFields.size());
    if (nDim < nSourceCount)
    {
        GroupItems& rGI = *maFields.at(nDim)->mpGroup;
@@ -1309,7 +1309,7 @@ SCROW ScDPCache::SetGroupItem(long nDim, const ScDPItemData& rData)
    }

    nDim -= nSourceCount;
    if (nDim < static_cast<long>(maGroupFields.size()))
    if (nDim < static_cast<tools::Long>(maGroupFields.size()))
    {
        ScDPItemDataVec& rItems = maGroupFields.at(nDim)->maItems;
        rItems.push_back(rData);
@@ -1319,12 +1319,12 @@ SCROW ScDPCache::SetGroupItem(long nDim, const ScDPItemData& rData)
    return -1;
}

void ScDPCache::GetGroupDimMemberIds(long nDim, std::vector<SCROW>& rIds) const
void ScDPCache::GetGroupDimMemberIds(tools::Long nDim, std::vector<SCROW>& rIds) const
{
    if (nDim < 0)
        return;

    long nSourceCount = static_cast<long>(maFields.size());
    tools::Long nSourceCount = static_cast<tools::Long>(maFields.size());
    if (nDim < nSourceCount)
    {
        if (!maFields.at(nDim)->mpGroup)
@@ -1339,7 +1339,7 @@ void ScDPCache::GetGroupDimMemberIds(long nDim, std::vector<SCROW>& rIds) const
    }

    nDim -= nSourceCount;
    if (nDim < static_cast<long>(maGroupFields.size()))
    if (nDim < static_cast<tools::Long>(maGroupFields.size()))
    {
        const ScDPItemDataVec& rGI = maGroupFields.at(nDim)->maItems;
        for (size_t i = 0, n = rGI.size(); i < n; ++i)
@@ -1370,12 +1370,12 @@ void ScDPCache::ClearAllFields()
    std::for_each(maFields.begin(), maFields.end(), ClearGroupItems());
}

const ScDPNumGroupInfo* ScDPCache::GetNumGroupInfo(long nDim) const
const ScDPNumGroupInfo* ScDPCache::GetNumGroupInfo(tools::Long nDim) const
{
    if (nDim < 0)
        return nullptr;

    long nSourceCount = static_cast<long>(maFields.size());
    tools::Long nSourceCount = static_cast<tools::Long>(maFields.size());
    if (nDim < nSourceCount)
    {
        if (!maFields.at(nDim)->mpGroup)
@@ -1385,18 +1385,18 @@ const ScDPNumGroupInfo* ScDPCache::GetNumGroupInfo(long nDim) const
    }

    nDim -= nSourceCount;
    if (nDim < static_cast<long>(maGroupFields.size()))
    if (nDim < static_cast<tools::Long>(maGroupFields.size()))
        return &maGroupFields.at(nDim)->maInfo;

    return nullptr;
}

sal_Int32 ScDPCache::GetGroupType(long nDim) const
sal_Int32 ScDPCache::GetGroupType(tools::Long nDim) const
{
    if (nDim < 0)
        return 0;

    long nSourceCount = static_cast<long>(maFields.size());
    tools::Long nSourceCount = static_cast<tools::Long>(maFields.size());
    if (nDim < nSourceCount)
    {
        if (!maFields.at(nDim)->mpGroup)
@@ -1406,7 +1406,7 @@ sal_Int32 ScDPCache::GetGroupType(long nDim) const
    }

    nDim -= nSourceCount;
    if (nDim < static_cast<long>(maGroupFields.size()))
    if (nDim < static_cast<tools::Long>(maGroupFields.size()))
        return maGroupFields.at(nDim)->mnGroupType;

    return 0;
@@ -1416,13 +1416,13 @@ sal_Int32 ScDPCache::GetGroupType(long nDim) const

namespace {

void dumpItems(const ScDPCache& rCache, long nDim, const ScDPCache::ScDPItemDataVec& rItems, size_t nOffset)
void dumpItems(const ScDPCache& rCache, tools::Long nDim, const ScDPCache::ScDPItemDataVec& rItems, size_t nOffset)
{
    for (size_t i = 0; i < rItems.size(); ++i)
        cout << "      " << (i+nOffset) << ": " << rCache.GetFormattedString(nDim, rItems[i], false) << endl;
}

void dumpSourceData(const ScDPCache& rCache, long nDim, const ScDPCache::ScDPItemDataVec& rItems, const ScDPCache::IndexArrayType& rArray)
void dumpSourceData(const ScDPCache& rCache, tools::Long nDim, const ScDPCache::ScDPItemDataVec& rItems, const ScDPCache::IndexArrayType& rArray)
{
    for (const auto& rIndex : rArray)
        cout << "      '" << rCache.GetFormattedString(nDim, rItems[rIndex], false) << "'" << endl;
diff --git a/sc/source/core/data/dpdimsave.cxx b/sc/source/core/data/dpdimsave.cxx
index 99a442a..e90a015 100644
--- a/sc/source/core/data/dpdimsave.cxx
+++ b/sc/source/core/data/dpdimsave.cxx
@@ -197,12 +197,12 @@ ScDPSaveGroupItem* ScDPSaveGroupDimension::GetNamedGroupAcc( const OUString& rGr
    return nullptr;        // none found
}

long ScDPSaveGroupDimension::GetGroupCount() const
tools::Long ScDPSaveGroupDimension::GetGroupCount() const
{
    return aGroups.size();
}

const ScDPSaveGroupItem& ScDPSaveGroupDimension::GetGroupByIndex( long nIndex ) const
const ScDPSaveGroupItem& ScDPSaveGroupDimension::GetGroupByIndex( tools::Long nIndex ) const
{
    return aGroups[nIndex];
}
@@ -265,7 +265,7 @@ bool isInteger(double fValue)
}

void fillDateGroupDimension(
    ScDPCache& rCache, ScDPNumGroupInfo& rDateInfo, long nSourceDim, long nGroupDim,
    ScDPCache& rCache, ScDPNumGroupInfo& rDateInfo, tools::Long nSourceDim, tools::Long nGroupDim,
    sal_Int32 nDatePart, const SvNumberFormatter* pFormatter)
{
    // Auto min/max is only used for "Years" part, but the loop is always
@@ -305,7 +305,7 @@ void fillDateGroupDimension(

    //TODO: if not automatic, limit fSourceMin/fSourceMax for list of year values?

    long nStart = 0, nEnd = 0; // end is inclusive
    tools::Long nStart = 0, nEnd = 0; // end is inclusive

    switch (nDatePart)
    {
@@ -327,7 +327,7 @@ void fillDateGroupDimension(
    // Now, populate the group items in the cache.
    rCache.ResetGroupItems(nGroupDim, rDateInfo, nDatePart);

    for (long nValue = nStart; nValue <= nEnd; ++nValue)
    for (tools::Long nValue = nStart; nValue <= nEnd; ++nValue)
        rCache.SetGroupItem(nGroupDim, ScDPItemData(nDatePart, nValue));

    // add first/last entry (min/max)
@@ -339,7 +339,7 @@ void fillDateGroupDimension(

void ScDPSaveGroupDimension::AddToData( ScDPGroupTableData& rData ) const
{
    long nSourceIndex = rData.GetDimensionIndex( aSourceDim );
    tools::Long nSourceIndex = rData.GetDimensionIndex( aSourceDim );
    if ( nSourceIndex < 0 )
        return;

@@ -363,11 +363,11 @@ void ScDPSaveGroupDimension::AddToData( ScDPGroupTableData& rData ) const

void ScDPSaveGroupDimension::AddToCache(ScDPCache& rCache) const
{
    long nSourceDim = rCache.GetDimensionIndex(aSourceDim);
    tools::Long nSourceDim = rCache.GetDimensionIndex(aSourceDim);
    if (nSourceDim < 0)
        return;

    long nDim = rCache.AppendGroupField();
    tools::Long nDim = rCache.AppendGroupField();
    SvNumberFormatter* pFormatter = rCache.GetDoc().GetFormatTable();

    if (nDatePart)
@@ -408,7 +408,7 @@ ScDPSaveNumGroupDimension::ScDPSaveNumGroupDimension( const OUString& rName, con

void ScDPSaveNumGroupDimension::AddToData( ScDPGroupTableData& rData ) const
{
    long nSource = rData.GetDimensionIndex( aDimensionName );
    tools::Long nSource = rData.GetDimensionIndex( aDimensionName );
    if ( nSource >= 0 )
    {
        ScDPNumGroupDimension aDim( aGroupInfo );           // aGroupInfo: value grouping
@@ -421,7 +421,7 @@ void ScDPSaveNumGroupDimension::AddToData( ScDPGroupTableData& rData ) const

void ScDPSaveNumGroupDimension::AddToCache(ScDPCache& rCache) const
{
    long nDim = rCache.GetDimensionIndex(aDimensionName);
    tools::Long nDim = rCache.GetDimensionIndex(aDimensionName);
    if (nDim < 0)
        return;

@@ -490,7 +490,7 @@ void ScDPSaveNumGroupDimension::AddToCache(ScDPCache& rCache) const

        //TODO: limit number of entries?

        long nLoopCount = 0;
        tools::Long nLoopCount = 0;
        double fLoop = aGroupInfo.mfStart;

        rCache.ResetGroupItems(nDim, aGroupInfo, 0);
diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx
index fe3f58d..fd9b909 100644
--- a/sc/source/core/data/dpgroup.cxx
+++ b/sc/source/core/data/dpgroup.cxx
@@ -329,7 +329,7 @@ void ScDPGroupItem::FillGroupFilter( ScDPFilteredCache::GroupFilter& rFilter ) c
        rFilter.addMatchItem(rElement);
}

ScDPGroupDimension::ScDPGroupDimension( long nSource, const OUString& rNewName ) :
ScDPGroupDimension::ScDPGroupDimension( tools::Long nSource, const OUString& rNewName ) :
    nSourceDim( nSource ),
    nGroupDim( -1 ),
    aGroupName( rNewName ),
@@ -366,7 +366,7 @@ void ScDPGroupDimension::AddItem( const ScDPGroupItem& rItem )
    aItems.push_back( rItem );
}

void ScDPGroupDimension::SetGroupDim( long nDim )
void ScDPGroupDimension::SetGroupDim( tools::Long nDim )
{
    nGroupDim = nDim;
}
@@ -483,7 +483,7 @@ void ScDPGroupTableData::AddGroupDimension( const ScDPGroupDimension& rGroup )
    aGroups.push_back( aNewGroup );
}

void ScDPGroupTableData::SetNumGroupDimension( long nIndex, const ScDPNumGroupDimension& rGroup )
void ScDPGroupTableData::SetNumGroupDimension( tools::Long nIndex, const ScDPNumGroupDimension& rGroup )
{
    if ( nIndex < nSourceCount )
    {
@@ -493,35 +493,35 @@ void ScDPGroupTableData::SetNumGroupDimension( long nIndex, const ScDPNumGroupDi
    }
}

long ScDPGroupTableData::GetDimensionIndex( const OUString& rName )
tools::Long ScDPGroupTableData::GetDimensionIndex( const OUString& rName )
{
    for (long i = 0; i < nSourceCount; ++i)                         // nSourceCount excludes data layout
    for (tools::Long i = 0; i < nSourceCount; ++i)                         // nSourceCount excludes data layout
        if (pSourceData->getDimensionName(i) == rName)        //TODO: ignore case?
            return i;
    return -1;  // none
}

long ScDPGroupTableData::GetColumnCount()
tools::Long ScDPGroupTableData::GetColumnCount()
{
    return nSourceCount + aGroups.size();
}

bool ScDPGroupTableData::IsNumGroupDimension( long nDimension ) const
bool ScDPGroupTableData::IsNumGroupDimension( tools::Long nDimension ) const
{
    return ( nDimension < nSourceCount && pNumGroups[nDimension].GetInfo().mbEnable );
}

void ScDPGroupTableData::GetNumGroupInfo(long nDimension, ScDPNumGroupInfo& rInfo)
void ScDPGroupTableData::GetNumGroupInfo(tools::Long nDimension, ScDPNumGroupInfo& rInfo)
{
    if ( nDimension < nSourceCount )
        rInfo = pNumGroups[nDimension].GetInfo();
}
long  ScDPGroupTableData::GetMembersCount( long nDim )
tools::Long  ScDPGroupTableData::GetMembersCount( tools::Long nDim )
{
    const std::vector< SCROW >&  members = GetColumnEntries( nDim );
    return members.size();
}
const std::vector< SCROW >& ScDPGroupTableData::GetColumnEntries( long  nColumn )
const std::vector< SCROW >& ScDPGroupTableData::GetColumnEntries( tools::Long  nColumn )
{
    if ( nColumn >= nSourceCount )
    {
@@ -544,12 +544,12 @@ const std::vector< SCROW >& ScDPGroupTableData::GetColumnEntries( long  nColumn 
    return pSourceData->GetColumnEntries( nColumn );
}

const ScDPItemData* ScDPGroupTableData::GetMemberById( long nDim, long nId )
const ScDPItemData* ScDPGroupTableData::GetMemberById( tools::Long nDim, tools::Long nId )
{
    return pSourceData->GetMemberById( nDim, nId );
}

OUString ScDPGroupTableData::getDimensionName(long nColumn)
OUString ScDPGroupTableData::getDimensionName(tools::Long nColumn)
{
    if ( nColumn >= nSourceCount )
    {
@@ -562,13 +562,13 @@ OUString ScDPGroupTableData::getDimensionName(long nColumn)
    return pSourceData->getDimensionName( nColumn );
}

bool ScDPGroupTableData::getIsDataLayoutDimension(long nColumn)
bool ScDPGroupTableData::getIsDataLayoutDimension(tools::Long nColumn)
{
    // position of data layout dimension is moved from source data
    return ( nColumn == sal::static_int_cast<long>( nSourceCount + aGroups.size() ) );    // data layout dimension?
}

bool ScDPGroupTableData::IsDateDimension(long nDim)
bool ScDPGroupTableData::IsDateDimension(tools::Long nDim)
{
    if ( nDim >= nSourceCount )
    {
@@ -581,7 +581,7 @@ bool ScDPGroupTableData::IsDateDimension(long nDim)
    return pSourceData->IsDateDimension( nDim );
}

sal_uInt32 ScDPGroupTableData::GetNumberFormat(long nDim)
sal_uInt32 ScDPGroupTableData::GetNumberFormat(tools::Long nDim)
{
    if ( nDim >= nSourceCount )
    {
@@ -599,7 +599,7 @@ void ScDPGroupTableData::DisposeData()
    for ( auto& rGroup : aGroups )
        rGroup.DisposeData();

    for ( long i=0; i<nSourceCount; i++ )
    for ( tools::Long i=0; i<nSourceCount; i++ )
        pNumGroups[i].DisposeData();

    pSourceData->DisposeData();
@@ -700,8 +700,8 @@ void ScDPGroupTableData::ModifyFilterCriteria(vector<ScDPFilteredCache::Criterio
            // This is an ordinary group field or external number group field.

            const ScDPGroupDimension* pGrpDim = itrGrp->second;
            long nSrcDim = pGrpDim->GetSourceDim();
            long nGrpDim = pGrpDim->GetGroupDim();
            tools::Long nSrcDim = pGrpDim->GetSourceDim();
            tools::Long nGrpDim = pGrpDim->GetGroupDim();
            const ScDPNumGroupInfo* pNumInfo = rCache.GetNumGroupInfo(nGrpDim);

            if (pGrpDim->IsDateDimension() && pNumInfo)
@@ -803,15 +803,15 @@ void ScDPGroupTableData::ReloadCacheTable()

void ScDPGroupTableData::FillGroupValues(vector<SCROW>& rItems, const vector<long>& rDims)
{
    long nGroupedColumns = aGroups.size();
    tools::Long nGroupedColumns = aGroups.size();

    const ScDPCache& rCache = GetCacheTable().getCache();
    size_t i = 0;
    for (long nColumn : rDims)
    for (tools::Long nColumn : rDims)
    {
        bool bDateDim = false;

        long nSourceDim = nColumn;
        tools::Long nSourceDim = nColumn;
        if ( nColumn >= nSourceCount && nColumn < nSourceCount + nGroupedColumns )
        {
            const ScDPGroupDimension& rGroupDim = aGroups[nColumn - nSourceCount];
@@ -871,13 +871,13 @@ void ScDPGroupTableData::FillGroupValues(vector<SCROW>& rItems, const vector<lon
    }
}

bool ScDPGroupTableData::IsBaseForGroup(long nDim) const
bool ScDPGroupTableData::IsBaseForGroup(tools::Long nDim) const
{
    return std::any_of(aGroups.begin(), aGroups.end(),
        [&nDim](const ScDPGroupDimension& rDim) { return rDim.GetSourceDim() == nDim; });
}

long ScDPGroupTableData::GetGroupBase(long nGroupDim) const
tools::Long ScDPGroupTableData::GetGroupBase(tools::Long nGroupDim) const
{
    auto aIter = std::find_if(aGroups.begin(), aGroups.end(),
        [&nGroupDim](const ScDPGroupDimension& rDim) { return rDim.GetGroupDim() == nGroupDim; });
@@ -887,7 +887,7 @@ long ScDPGroupTableData::GetGroupBase(long nGroupDim) const
    return -1;      // none
}

bool ScDPGroupTableData::IsNumOrDateGroup(long nDimension) const
bool ScDPGroupTableData::IsNumOrDateGroup(tools::Long nDimension) const
{
    // Virtual method from ScDPTableData, used in result data to force text labels.

@@ -905,8 +905,8 @@ bool ScDPGroupTableData::IsNumOrDateGroup(long nDimension) const
    return false;
}

bool ScDPGroupTableData::IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
                                    const ScDPItemData& rBaseData, long nBaseIndex ) const
bool ScDPGroupTableData::IsInGroup( const ScDPItemData& rGroupData, tools::Long nGroupIndex,
                                    const ScDPItemData& rBaseData, tools::Long nBaseIndex ) const
{
    auto aIter = std::find_if(aGroups.begin(), aGroups.end(),
        [&nGroupIndex, &nBaseIndex](const ScDPGroupDimension& rDim) {
@@ -933,8 +933,8 @@ bool ScDPGroupTableData::IsInGroup( const ScDPItemData& rGroupData, long nGroupI
    return true;
}

bool ScDPGroupTableData::HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
                                         const ScDPItemData& rSecondData, long nSecondIndex ) const
bool ScDPGroupTableData::HasCommonElement( const ScDPItemData& rFirstData, tools::Long nFirstIndex,
                                         const ScDPItemData& rSecondData, tools::Long nSecondIndex ) const
{
    const ScDPGroupDimension* pFirstDim = nullptr;
    const ScDPGroupDimension* pSecondDim = nullptr;
@@ -990,11 +990,11 @@ bool ScDPGroupTableData::HasCommonElement( const ScDPItemData& rFirstData, long 
    return true;
}

long ScDPGroupTableData::GetSourceDim( long nDim )
tools::Long ScDPGroupTableData::GetSourceDim( tools::Long nDim )
{
    if ( getIsDataLayoutDimension( nDim ) )
        return nSourceCount;
    if (  nDim >= nSourceCount && nDim < nSourceCount +static_cast<long>(aGroups.size())  )
    if (  nDim >= nSourceCount && nDim < nSourceCount +static_cast<tools::Long>(aGroups.size())  )
    {
        const ScDPGroupDimension& rGroupDim = aGroups[nDim - nSourceCount];
        return  rGroupDim.GetSourceDim();
@@ -1002,7 +1002,7 @@ long ScDPGroupTableData::GetSourceDim( long nDim )
    return nDim;
}

long ScDPGroupTableData::Compare(long nDim, long nDataId1, long nDataId2)
tools::Long ScDPGroupTableData::Compare(tools::Long nDim, tools::Long nDataId1, tools::Long nDataId2)
{
    if ( getIsDataLayoutDimension(nDim) )
        return 0;
@@ -1018,7 +1018,7 @@ long ScDPGroupTableData::Compare(long nDim, long nDataId1, long nDataId2)
void ScDPGroupTableData::Dump() const
{
    cout << "--- ScDPGroupTableData" << endl;
    for (long i = 0; i < nSourceCount; ++i)
    for (tools::Long i = 0; i < nSourceCount; ++i)
    {
        cout << "* dimension: " << i << endl;
        const ScDPNumGroupDimension& rGrp = pNumGroups[i];
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index d36e25b..99c974f 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -123,9 +123,9 @@ public:

    bool isValid() const;

    virtual void getValue(long nCol, ScDPItemData &rData, SvNumFormatType& rNumType) const override;
    virtual OUString getColumnLabel(long nCol) const override;
    virtual long getColumnCount() const override;
    virtual void getValue(tools::Long nCol, ScDPItemData &rData, SvNumFormatType& rNumType) const override;
    virtual OUString getColumnLabel(tools::Long nCol) const override;
    virtual tools::Long getColumnCount() const override;
    virtual bool first() override;
    virtual bool next() override;
    virtual void finish() override;
@@ -161,17 +161,17 @@ void DBConnector::finish()
    mxRowSet->beforeFirst();
}

long DBConnector::getColumnCount() const
tools::Long DBConnector::getColumnCount() const
{
    return mxMetaData->getColumnCount();
}

OUString DBConnector::getColumnLabel(long nCol) const
OUString DBConnector::getColumnLabel(tools::Long nCol) const
{
    return mxMetaData->getColumnLabel(nCol+1);
}

void DBConnector::getValue(long nCol, ScDPItemData &rData, SvNumFormatType& rNumType) const
void DBConnector::getValue(tools::Long nCol, ScDPItemData &rData, SvNumFormatType& rNumType) const
{
    rNumType = SvNumFormatType::NUMBER;
    sal_Int32 nType = mxMetaData->getColumnType(nCol+1);
@@ -501,7 +501,7 @@ bool ScDPObject::IsDataDescriptionCell(const ScAddress& rPos)
    if (!pSaveData)
        return false;

    long nDataDimCount = pSaveData->GetDataDimensionCount();
    tools::Long nDataDimCount = pSaveData->GetDataDimensionCount();
    if (nDataDimCount != 1)
        // There has to be exactly one data dimension for the description to
        // appear at top-left corner.
@@ -528,19 +528,19 @@ void ScDPObject::CreateOutput()
    pOutput.reset( new ScDPOutput( pDoc, xSource, aOutRange.aStart, bFilterButton ) );
    pOutput->SetHeaderLayout ( mbHeaderLayout );

    long nOldRows = nHeaderRows;
    tools::Long nOldRows = nHeaderRows;
    nHeaderRows = pOutput->GetHeaderRows();

    if ( !(bAllowMove && nHeaderRows != nOldRows) )
        return;

    long nDiff = nOldRows - nHeaderRows;
    tools::Long nDiff = nOldRows - nHeaderRows;
    if ( nOldRows == 0 )
        --nDiff;
    if ( nHeaderRows == 0 )
        ++nDiff;

    long nNewRow = aOutRange.aStart.Row() + nDiff;
    tools::Long nNewRow = aOutRange.aStart.Row() + nDiff;
    if ( nNewRow < 0 )
        nNewRow = 0;

@@ -1193,7 +1193,7 @@ bool ScDPObject::IsDimNameInUse(const OUString& rName) const
    return false;
}

OUString ScDPObject::GetDimName( long nDim, bool& rIsDataLayout, sal_Int32* pFlags )
OUString ScDPObject::GetDimName( tools::Long nDim, bool& rIsDataLayout, sal_Int32* pFlags )
{
    rIsDataLayout = false;
    OUString aRet;
@@ -1202,7 +1202,7 @@ OUString ScDPObject::GetDimName( long nDim, bool& rIsDataLayout, sal_Int32* pFla
    {
        uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
        uno::Reference<container::XIndexAccess> xDims = new ScNameToIndexAccess( xDimsName );
        long nDimCount = xDims->getCount();
        tools::Long nDimCount = xDims->getCount();
        if ( nDim < nDimCount )
        {
            uno::Reference<uno::XInterface> xIntDim(xDims->getByIndex(nDim), uno::UNO_QUERY);
@@ -1242,14 +1242,14 @@ OUString ScDPObject::GetDimName( long nDim, bool& rIsDataLayout, sal_Int32* pFla
    return aRet;
}

bool ScDPObject::IsDuplicated( long nDim )
bool ScDPObject::IsDuplicated( tools::Long nDim )
{
    bool bDuplicated = false;
    if ( xSource.is() )
    {
        uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
        uno::Reference<container::XIndexAccess> xDims = new ScNameToIndexAccess( xDimsName );
        long nDimCount = xDims->getCount();
        tools::Long nDimCount = xDims->getCount();
        if ( nDim < nDimCount )
        {
            uno::Reference<beans::XPropertySet> xDimProp(xDims->getByIndex(nDim), uno::UNO_QUERY);
@@ -1271,9 +1271,9 @@ bool ScDPObject::IsDuplicated( long nDim )
    return bDuplicated;
}

long ScDPObject::GetDimCount()
tools::Long ScDPObject::GetDimCount()
{
    long nRet = 0;
    tools::Long nRet = 0;
    if ( xSource.is() )
    {
        try
@@ -1404,22 +1404,22 @@ bool ScDPObject::IsFilterButton( const ScAddress& rPos )
    return pOutput->IsFilterButton( rPos );
}

long ScDPObject::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrientation& rOrient )
tools::Long ScDPObject::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrientation& rOrient )
{
    CreateOutput();             // create xSource and pOutput if not already done

    return pOutput->GetHeaderDim( rPos, rOrient );
}

bool ScDPObject::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMouseTop, long nDragDim,
                                tools::Rectangle& rPosRect, sheet::DataPilotFieldOrientation& rOrient, long& rDimPos )
bool ScDPObject::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMouseTop, tools::Long nDragDim,
                                tools::Rectangle& rPosRect, sheet::DataPilotFieldOrientation& rOrient, tools::Long& rDimPos )
{
    CreateOutput();             // create xSource and pOutput if not already done

    return pOutput->GetHeaderDrag( rPos, bMouseLeft, bMouseTop, nDragDim, rPosRect, rOrient, rDimPos );
}

void ScDPObject::GetMemberResultNames(ScDPUniqueStringSet& rNames, long nDimension)
void ScDPObject::GetMemberResultNames(ScDPUniqueStringSet& rNames, tools::Long nDimension)
{
    CreateOutput();             // create xSource and pOutput if not already done

@@ -1432,7 +1432,7 @@ OUString ScDPObject::GetFormattedString(const OUString& rDimName, const double f
    if(!pTableData)
        return OUString();

    long nDim;
    tools::Long nDim;
    for (nDim = 0; nDim < pTableData->GetColumnCount(); ++nDim)
    {
        if(rDimName == pTableData->getDimensionName(nDim))
@@ -1993,7 +1993,7 @@ void ScDPObject::ToggleDetails(const DataPilotTableHeaderData& rElemDesc, ScDPOb
    uno::Reference<container::XNamed> xDim;
    uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
    uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
    long nIntCount = xIntDims->getCount();
    tools::Long nIntCount = xIntDims->getCount();
    if ( rElemDesc.Dimension < nIntCount )
    {
        xDim.set(xIntDims->getByIndex(rElemDesc.Dimension), uno::UNO_QUERY);
@@ -2014,7 +2014,7 @@ void ScDPObject::ToggleDetails(const DataPilotTableHeaderData& rElemDesc, ScDPOb

    //  query old state

    long nHierCount = 0;
    tools::Long nHierCount = 0;
    uno::Reference<container::XIndexAccess> xHiers;
    uno::Reference<sheet::XHierarchiesSupplier> xHierSupp( xDim, uno::UNO_QUERY );
    if ( xHierSupp.is() )
@@ -2029,7 +2029,7 @@ void ScDPObject::ToggleDetails(const DataPilotTableHeaderData& rElemDesc, ScDPOb
    OSL_ENSURE( xHier.is(), "hierarchy not found" );
    if ( !xHier.is() ) return;

    long nLevCount = 0;
    tools::Long nLevCount = 0;
    uno::Reference<container::XIndexAccess> xLevels;
    uno::Reference<sheet::XLevelsSupplier> xLevSupp( xHier, uno::UNO_QUERY );
    if ( xLevSupp.is() )
@@ -2094,7 +2094,7 @@ static PivotFunc lcl_FirstSubTotal( const uno::Reference<beans::XPropertySet>& x
    if ( xDimProp.is() && xDimSupp.is() )
    {
        uno::Reference<container::XIndexAccess> xHiers = new ScNameToIndexAccess( xDimSupp->getHierarchies() );
        long nHierarchy = ScUnoHelpFunctions::GetLongProperty( xDimProp,
        tools::Long nHierarchy = ScUnoHelpFunctions::GetLongProperty( xDimProp,
                                SC_UNO_DP_USEDHIERARCHY );
        if ( nHierarchy >= xHiers->getCount() )
            nHierarchy = 0;
@@ -2163,8 +2163,8 @@ static void lcl_FillOldFields( ScPivotFieldVector& rFields,

    uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
    uno::Reference<container::XIndexAccess> xDims = new ScNameToIndexAccess( xDimsName );
    long nDimCount = xDims->getCount();
    for (long nDim = 0; nDim < nDimCount; ++nDim)
    tools::Long nDimCount = xDims->getCount();
    for (tools::Long nDim = 0; nDim < nDimCount; ++nDim)
    {
        // dimension properties
        uno::Reference<beans::XPropertySet> xDimProp(xDims->getByIndex(nDim), uno::UNO_QUERY);
@@ -2200,7 +2200,7 @@ static void lcl_FillOldFields( ScPivotFieldVector& rFields,
                xDimProp, SC_UNO_DP_ISDATALAYOUT);

            // is this dimension cloned?
            long nDupSource = -1;
            tools::Long nDupSource = -1;
            try
            {
                uno::Any aOrigAny = xDimProp->getPropertyValue(SC_UNO_DP_ORIGINAL_POS);
@@ -2243,7 +2243,7 @@ static void lcl_FillOldFields( ScPivotFieldVector& rFields,

            rField.nFuncMask = nMask;
            rField.mnDupCount = nDupCount;
            long nPos = ScUnoHelpFunctions::GetLongProperty(
            tools::Long nPos = ScUnoHelpFunctions::GetLongProperty(
                xDimProp, SC_UNO_DP_POSITION);
            aPos.push_back(nPos);

@@ -2335,7 +2335,7 @@ static void lcl_FillLabelData( ScDPLabelData& rData, const uno::Reference< beans
        return;

    uno::Reference<container::XIndexAccess> xHiers = new ScNameToIndexAccess( xDimSupp->getHierarchies() );
    long nHierarchy = ScUnoHelpFunctions::GetLongProperty(
    tools::Long nHierarchy = ScUnoHelpFunctions::GetLongProperty(
        xDimProp, SC_UNO_DP_USEDHIERARCHY);
    if ( nHierarchy >= xHiers->getCount() )
        nHierarchy = 0;
@@ -2420,7 +2420,7 @@ void ScDPObject::FillLabelDataForDimension(
    if (bData)
        return;

    rLabelData.mnOriginalDim = static_cast<long>(nOrigPos);
    rLabelData.mnOriginalDim = static_cast<tools::Long>(nOrigPos);
    rLabelData.maLayoutName = aLayoutName;
    rLabelData.maSubtotalName = aSubtotalName;
    if (nOrigPos >= 0)
@@ -2551,14 +2551,14 @@ bool ScDPObject::GetMembersNA( sal_Int32 nDim, sal_Int32 nHier, uno::Reference< 

namespace {

OUString lcl_GetDimName( const uno::Reference<sheet::XDimensionsSupplier>& xSource, long nDim )
OUString lcl_GetDimName( const uno::Reference<sheet::XDimensionsSupplier>& xSource, tools::Long nDim )
{
    OUString aName;
    if ( xSource.is() )
    {
        uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
        uno::Reference<container::XIndexAccess> xDims = new ScNameToIndexAccess( xDimsName );
        long nDimCount = xDims->getCount();
        tools::Long nDimCount = xDims->getCount();
        if ( nDim < nDimCount )
        {
            uno::Reference<container::XNamed> xDimName(xDims->getByIndex(nDim), uno::UNO_QUERY);
@@ -2590,9 +2590,9 @@ bool hasFieldColumn(const vector<ScPivotField>* pRefFields, SCCOL nCol)

class FindByOriginalDim
{
    long mnDim;
    tools::Long mnDim;
public:
    explicit FindByOriginalDim(long nDim) : mnDim(nDim) {}
    explicit FindByOriginalDim(tools::Long nDim) : mnDim(nDim) {}
    bool operator() (const ScPivotField& r) const
    {
        return mnDim == r.getOriginalDim();
@@ -2614,7 +2614,7 @@ void ScDPObject::ConvertOrientation(
    {
        const ScPivotField& rField = *itr;

        long nCol = rField.getOriginalDim();
        tools::Long nCol = rField.getOriginalDim();
        PivotFunc nFuncs = rField.nFuncMask;
        const sheet::DataPilotFieldReference& rFieldRef = rField.maFieldRef;

diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index b44b2a1..718a032 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -75,10 +75,10 @@ using ::com::sun::star::sheet::DataPilotTableResultData;

struct ScDPOutLevelData
{
    long                                mnDim;
    long                                mnHier;
    long                                mnLevel;
    long                                mnDimPos;
    tools::Long                                mnDim;
    tools::Long                                mnHier;
    tools::Long                                mnLevel;
    tools::Long                                mnDimPos;
    sal_uInt32 mnSrcNumFmt; /// Prevailing number format used in the source data.
    uno::Sequence<sheet::MemberResult>  maResult;
    OUString                            maName;     /// Name is the internal field name.
@@ -87,7 +87,7 @@ struct ScDPOutLevelData
    bool                                mbDataLayout:1;
    bool                                mbPageDim:1;

    ScDPOutLevelData(long nDim, long nHier, long nLevel, long nDimPos, sal_uInt32 nSrcNumFmt, const uno::Sequence<sheet::MemberResult>  &aResult,
    ScDPOutLevelData(tools::Long nDim, tools::Long nHier, tools::Long nLevel, tools::Long nDimPos, sal_uInt32 nSrcNumFmt, const uno::Sequence<sheet::MemberResult>  &aResult,
                       const OUString &aName, const OUString &aCaption, bool bHasHiddenMember, bool bDataLayout, bool bPageDim) :
        mnDim(nDim), mnHier(nHier), mnLevel(nLevel), mnDimPos(nDimPos), mnSrcNumFmt(nSrcNumFmt), maResult(aResult),
        maName(aName), maCaption(aCaption), mbHasHiddenMember(bHasHiddenMember), mbDataLayout(bDataLayout),
@@ -330,7 +330,7 @@ void lcl_SetFrame( ScDocument* pDoc, SCTAB nTab,
    pDoc->ApplyFrameAreaTab(ScRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab), aBox, aBoxInfo);
}

void lcl_FillNumberFormats( std::unique_ptr<sal_uInt32[]>& rFormats, long& rCount,
void lcl_FillNumberFormats( std::unique_ptr<sal_uInt32[]>& rFormats, tools::Long& rCount,
                            const uno::Reference<sheet::XDataPilotMemberResults>& xLevRes,
                            const uno::Reference<container::XIndexAccess>& xDims )
{
@@ -342,7 +342,7 @@ void lcl_FillNumberFormats( std::unique_ptr<sal_uInt32[]>& rFormats, long& rCoun

    uno::Sequence<sheet::MemberResult> aResult = xLevRes->getResults();

    long nSize = aResult.getLength();
    tools::Long nSize = aResult.getLength();
    if (!nSize)
        return;

@@ -367,7 +367,7 @@ void lcl_FillNumberFormats( std::unique_ptr<sal_uInt32[]>& rFormats, long& rCoun
            if ( eDimOrient == sheet::DataPilotFieldOrientation_DATA )
            {
                aDataNames.push_back(xDimName->getName());
                long nFormat = ScUnoHelpFunctions::GetLongProperty(
                tools::Long nFormat = ScUnoHelpFunctions::GetLongProperty(
                                        xDimProp,
                                        SC_UNONAME_NUMFMT );
                aDataFormats.push_back(nFormat);
@@ -385,13 +385,13 @@ void lcl_FillNumberFormats( std::unique_ptr<sal_uInt32[]>& rFormats, long& rCoun
    if (aDataFormats.size() == 1)
    {
        //  only one data dimension -> use its numberformat everywhere
        long nFormat = aDataFormats[0];
        for (long nPos=0; nPos<nSize; nPos++)
        tools::Long nFormat = aDataFormats[0];
        for (tools::Long nPos=0; nPos<nSize; nPos++)
            pNumFmt[nPos] = nFormat;
    }
    else
    {
        for (long nPos=0; nPos<nSize; nPos++)
        for (tools::Long nPos=0; nPos<nSize; nPos++)
        {
            //  if CONTINUE bit is set, keep previous name
            //TODO: keep number format instead!
@@ -415,8 +415,8 @@ void lcl_FillNumberFormats( std::unique_ptr<sal_uInt32[]>& rFormats, long& rCoun

sal_uInt32 lcl_GetFirstNumberFormat( const uno::Reference<container::XIndexAccess>& xDims )
{
    long nDimCount = xDims->getCount();
    for (long nDim=0; nDim<nDimCount; nDim++)
    tools::Long nDimCount = xDims->getCount();
    for (tools::Long nDim=0; nDim<nDimCount; nDim++)
    {
        uno::Reference<beans::XPropertySet> xDimProp(xDims->getByIndex(nDim), uno::UNO_QUERY);
        if ( xDimProp.is() )
@@ -427,7 +427,7 @@ sal_uInt32 lcl_GetFirstNumberFormat( const uno::Reference<container::XIndexAcces
                    sheet::DataPilotFieldOrientation_HIDDEN );
            if ( eDimOrient == sheet::DataPilotFieldOrientation_DATA )
            {
                long nFormat = ScUnoHelpFunctions::GetLongProperty(
                tools::Long nFormat = ScUnoHelpFunctions::GetLongProperty(
                                        xDimProp,
                                        SC_UNONAME_NUMFMT );

@@ -526,8 +526,8 @@ ScDPOutput::ScDPOutput( ScDocument* pD, const uno::Reference<sheet::XDimensionsS

        uno::Reference<container::XIndexAccess> xDims =
                new ScNameToIndexAccess( xSource->getDimensions() );
        long nDimCount = xDims->getCount();
        for (long nDim=0; nDim<nDimCount; nDim++)
        tools::Long nDimCount = xDims->getCount();
        for (tools::Long nDim=0; nDim<nDimCount; nDim++)
        {
            uno::Reference<uno::XInterface> xDim(xDims->getByIndex(nDim), uno::UNO_QUERY);
            uno::Reference<beans::XPropertySet> xDimProp( xDim, uno::UNO_QUERY );
@@ -538,7 +538,7 @@ ScDPOutput::ScDPOutput( ScDocument* pD, const uno::Reference<sheet::XDimensionsS
                    ScUnoHelpFunctions::GetEnumProperty(
                        xDimProp, SC_UNO_DP_ORIENTATION,
                        sheet::DataPilotFieldOrientation_HIDDEN );
                long nDimPos = ScUnoHelpFunctions::GetLongProperty( xDimProp,
                tools::Long nDimPos = ScUnoHelpFunctions::GetLongProperty( xDimProp,
                        SC_UNO_DP_POSITION );
                bool bIsDataLayout = ScUnoHelpFunctions::GetBoolProperty(
                    xDimProp, SC_UNO_DP_ISDATALAYOUT);
@@ -551,7 +551,7 @@ ScDPOutput::ScDPOutput( ScDocument* pD, const uno::Reference<sheet::XDimensionsS
                {
                    uno::Reference<container::XIndexAccess> xHiers =
                            new ScNameToIndexAccess( xDimSupp->getHierarchies() );
                    long nHierarchy = ScUnoHelpFunctions::GetLongProperty(
                    tools::Long nHierarchy = ScUnoHelpFunctions::GetLongProperty(
                                            xDimProp,
                                            SC_UNO_DP_USEDHIERARCHY );
                    if ( nHierarchy >= xHiers->getCount() )
@@ -563,8 +563,8 @@ ScDPOutput::ScDPOutput( ScDocument* pD, const uno::Reference<sheet::XDimensionsS
                    {
                        uno::Reference<container::XIndexAccess> xLevels =
                                new ScNameToIndexAccess( xHierSupp->getLevels() );
                        long nLevCount = xLevels->getCount();
                        for (long nLev=0; nLev<nLevCount; nLev++)
                        tools::Long nLevCount = xLevels->getCount();
                        for (tools::Long nLev=0; nLev<nLevCount; nLev++)
                        {
                            uno::Reference<uno::XInterface> xLevel(xLevels->getByIndex(nLev),
                                                                   uno::UNO_QUERY);
@@ -688,7 +688,7 @@ void ScDPOutput::SetPosition( const ScAddress& rPos )

void ScDPOutput::DataCell( SCCOL nCol, SCROW nRow, SCTAB nTab, const sheet::DataResult& rData )
{
    long nFlags = rData.Flags;
    tools::Long nFlags = rData.Flags;
    if ( nFlags & sheet::DataResultFlags::ERROR )
    {
        pDoc->SetError( nCol, nRow, nTab, FormulaError::NoValue );
@@ -706,7 +706,7 @@ void ScDPOutput::DataCell( SCCOL nCol, SCROW nRow, SCTAB nTab, const sheet::Data
        {
            if ( nCol >= nDataStartCol )
            {
                long nIndex = nCol - nDataStartCol;
                tools::Long nIndex = nCol - nDataStartCol;
                if ( nIndex < nColFmtCount )
                {
                    nFormat = pColNumFmt[nIndex];
@@ -718,7 +718,7 @@ void ScDPOutput::DataCell( SCCOL nCol, SCROW nRow, SCTAB nTab, const sheet::Data
        {
            if ( nRow >= nDataStartRow )
            {
                long nIndex = nRow - nDataStartRow;
                tools::Long nIndex = nRow - nDataStartRow;
                if ( nIndex < nRowFmtCount )
                {
                    nFormat = pRowNumFmt[nIndex];
@@ -739,9 +739,9 @@ void ScDPOutput::DataCell( SCCOL nCol, SCROW nRow, SCTAB nTab, const sheet::Data
}

void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
                             const sheet::MemberResult& rData, bool bColHeader, long nLevel )
                             const sheet::MemberResult& rData, bool bColHeader, tools::Long nLevel )
{
    long nFlags = rData.Flags;
    tools::Long nFlags = rData.Flags;

    if ( nFlags & sheet::MemberResultFlags::HASMEMBER )
    {
@@ -848,7 +848,7 @@ void ScDPOutput::CalcSizes()

    //  calculate output positions and sizes

    long nPageSize = 0;     // use page fields!
    tools::Long nPageSize = 0;     // use page fields!
    if ( bDoFilter || !pPageFields.empty() )
    {
        nPageSize += pPageFields.size() + 1;   // plus one empty row
@@ -856,7 +856,7 @@ void ScDPOutput::CalcSizes()
            ++nPageSize;        //  filter button above the page fields
    }

    if ( aStartPos.Col() + static_cast<long>(pRowFields.size()) + nColCount - 1 > MAXCOL ||
    if ( aStartPos.Col() + static_cast<tools::Long>(pRowFields.size()) + nColCount - 1 > MAXCOL ||
         aStartPos.Row() + nPageSize + nHeaderSize + pColFields.size() + nRowCount > MAXROW )
    {
        bSizeOverflow = true;
@@ -1003,16 +1003,16 @@ void ScDPOutput::Output()
        SCROW nRowPos = nMemberStartRow + static_cast<SCROW>(nField);                //TODO: check for overflow
        const uno::Sequence<sheet::MemberResult> rSequence = pColFields[nField].maResult;
        const sheet::MemberResult* pArray = rSequence.getConstArray();
        long nThisColCount = rSequence.getLength();
        tools::Long nThisColCount = rSequence.getLength();
        OSL_ENSURE( nThisColCount == nColCount, "count mismatch" );     //TODO: ???
        for (long nCol=0; nCol<nThisColCount; nCol++)
        for (tools::Long nCol=0; nCol<nThisColCount; nCol++)
        {
            SCCOL nColPos = nDataStartCol + static_cast<SCCOL>(nCol);                //TODO: check for overflow
            HeaderCell( nColPos, nRowPos, nTab, pArray[nCol], true, nField );
            if ( ( pArray[nCol].Flags & sheet::MemberResultFlags::HASMEMBER ) &&
                !( pArray[nCol].Flags & sheet::MemberResultFlags::SUBTOTAL ) )
            {
                long nEnd = nCol;
                tools::Long nEnd = nCol;
                while ( nEnd+1 < nThisColCount && ( pArray[nEnd+1].Flags & sheet::MemberResultFlags::CONTINUE ) )
                    ++nEnd;
                SCCOL nEndColPos = nDataStartCol + static_cast<SCCOL>(nEnd);     //TODO: check for overflow
@@ -1054,9 +1054,9 @@ void ScDPOutput::Output()
        SCCOL nColPos = nMemberStartCol + static_cast<SCCOL>(nField);                //TODO: check for overflow
        const uno::Sequence<sheet::MemberResult> rSequence = pRowFields[nField].maResult;
        const sheet::MemberResult* pArray = rSequence.getConstArray();
        long nThisRowCount = rSequence.getLength();
        tools::Long nThisRowCount = rSequence.getLength();
        OSL_ENSURE( nThisRowCount == nRowCount, "count mismatch" );     //TODO: ???
        for (long nRow=0; nRow<nThisRowCount; nRow++)
        for (tools::Long nRow=0; nRow<nThisRowCount; nRow++)
        {
            SCROW nRowPos = nDataStartRow + static_cast<SCROW>(nRow);                //TODO: check for overflow
            HeaderCell( nColPos, nRowPos, nTab, pArray[nRow], false, nField );
@@ -1065,7 +1065,7 @@ void ScDPOutput::Output()
            {
                if ( nField+1 < pRowFields.size() )
                {
                    long nEnd = nRow;
                    tools::Long nEnd = nRow;
                    while ( nEnd+1 < nThisRowCount && ( pArray[nEnd+1].Flags & sheet::MemberResultFlags::CONTINUE ) )
                        ++nEnd;
                    SCROW nEndRowPos = nDataStartRow + static_cast<SCROW>(nEnd);     //TODO: check for overflow
@@ -1104,13 +1104,13 @@ void ScDPOutput::Output()

    //  output data results:

    for (long nRow=0; nRow<nRowCount; nRow++)
    for (tools::Long nRow=0; nRow<nRowCount; nRow++)
    {
        SCROW nRowPos = nDataStartRow + static_cast<SCROW>(nRow);                    //TODO: check for overflow
        const sheet::DataResult* pColAry = pRowAry[nRow].getConstArray();
        long nThisColCount = pRowAry[nRow].getLength();
        tools::Long nThisColCount = pRowAry[nRow].getLength();
        OSL_ENSURE( nThisColCount == nColCount, "count mismatch" );     //TODO: ???
        for (long nCol=0; nCol<nThisColCount; nCol++)
        for (tools::Long nCol=0; nCol<nThisColCount; nCol++)
        {
            SCCOL nColPos = nDataStartCol + static_cast<SCCOL>(nCol);                //TODO: check for overflow
            DataCell( nColPos, nRowPos, nTab, pColAry[nCol] );
@@ -1147,7 +1147,7 @@ bool ScDPOutput::HasError()
    return bSizeOverflow || bResultsError;
}

long ScDPOutput::GetHeaderRows() const
tools::Long ScDPOutput::GetHeaderRows() const
{
    return pPageFields.size() + ( bDoFilter ? 1 : 0 );
}
@@ -1164,7 +1164,7 @@ namespace
    }
}

void ScDPOutput::GetMemberResultNames(ScDPUniqueStringSet& rNames, long nDimension)
void ScDPOutput::GetMemberResultNames(ScDPUniqueStringSet& rNames, tools::Long nDimension)
{
    //  Return the list of all member names in a dimension's MemberResults.
    //  Only the dimension has to be compared because this is only used with table data,
@@ -1227,8 +1227,8 @@ void lcl_GetTableVars( sal_Int32& rGrandTotalCols, sal_Int32& rGrandTotalRows, s
    sal_Int32 nDataCount = 0;

    uno::Reference<container::XIndexAccess> xDims = new ScNameToIndexAccess( xSource->getDimensions() );
    long nDimCount = xDims->getCount();
    for (long nDim=0; nDim<nDimCount; nDim++)
    tools::Long nDimCount = xDims->getCount();
    for (tools::Long nDim=0; nDim<nDimCount; nDim++)
    {
        uno::Reference<uno::XInterface> xDim(xDims->getByIndex(nDim), uno::UNO_QUERY);
        uno::Reference<beans::XPropertySet> xDimProp( xDim, uno::UNO_QUERY );
@@ -1328,7 +1328,7 @@ void ScDPOutput::GetPositionData(const ScAddress& rPos, DataPilotTablePositionDa
        }
        case DataPilotTablePositionType::COLUMN_HEADER:
        {
            long nField = nRow - nTabStartRow - 1; // 1st line is used for the buttons
            tools::Long nField = nRow - nTabStartRow - 1; // 1st line is used for the buttons
            if (nField < 0)
                break;

@@ -1337,7 +1337,7 @@ void ScDPOutput::GetPositionData(const ScAddress& rPos, DataPilotTablePositionDa
                break;
            const sheet::MemberResult* pArray = rSequence.getConstArray();

            long nItem = nCol - nDataStartCol;
            tools::Long nItem = nCol - nDataStartCol;
            //  get origin of "continue" fields
            while (nItem > 0 && ( pArray[nItem].Flags & sheet::MemberResultFlags::CONTINUE) )
                --nItem;
@@ -1357,7 +1357,7 @@ void ScDPOutput::GetPositionData(const ScAddress& rPos, DataPilotTablePositionDa
        }
        case DataPilotTablePositionType::ROW_HEADER:
        {
            long nField = nCol - nTabStartCol;
            tools::Long nField = nCol - nTabStartCol;
            if (nField < 0)
                break;

@@ -1366,7 +1366,7 @@ void ScDPOutput::GetPositionData(const ScAddress& rPos, DataPilotTablePositionDa
                break;
            const sheet::MemberResult* pArray = rSequence.getConstArray();

            long nItem = nRow - nDataStartRow;
            tools::Long nItem = nRow - nDataStartRow;
            //  get origin of "continue" fields
            while ( nItem > 0 && (pArray[nItem].Flags & sheet::MemberResultFlags::CONTINUE) )
                --nItem;
@@ -1442,7 +1442,7 @@ bool ScDPOutput::GetDataResultPositionData(vector<sheet::DataPilotFieldFilter>& 

        OSL_ENSURE(nDataStartCol + rSequence.getLength() - 1 == nTabEndCol, "ScDPOutput::GetDataFieldCellData: error in geometric assumption");

        long nItem = nCol - nDataStartCol;
        tools::Long nItem = nCol - nDataStartCol;
                //  get origin of "continue" fields
        while ( nItem > 0 && (pArray[nItem].Flags & sheet::MemberResultFlags::CONTINUE) )
            --nItem;
@@ -1466,7 +1466,7 @@ bool ScDPOutput::GetDataResultPositionData(vector<sheet::DataPilotFieldFilter>& 

        OSL_ENSURE(nDataStartRow + rSequence.getLength() - 1 == nTabEndRow, "ScDPOutput::GetDataFieldCellData: error in geometric assumption");

        long nItem = nRow - nDataStartRow;
        tools::Long nItem = nRow - nDataStartRow;
            //  get origin of "continue" fields
        while ( nItem > 0 && (pArray[nItem].Flags & sheet::MemberResultFlags::CONTINUE) )
            --nItem;
@@ -1545,7 +1545,7 @@ bool ScDPOutput::IsFilterButton( const ScAddress& rPos )
    return ( nCol == aStartPos.Col() && nRow == aStartPos.Row() );
}

long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrientation& rOrient )
tools::Long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrientation& rOrient )
{
    SCCOL nCol = rPos.Col();
    SCROW nRow = rPos.Row();
@@ -1562,7 +1562,7 @@ long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrien
    if ( nRow == nTabStartRow && nCol >= nDataStartCol && o3tl::make_unsigned(nCol) < nDataStartCol + pColFields.size())
    {
        rOrient = sheet::DataPilotFieldOrientation_COLUMN;
        long nField = nCol - nDataStartCol;
        tools::Long nField = nCol - nDataStartCol;
        return pColFields[nField].mnDim;
    }

@@ -1571,7 +1571,7 @@ long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrien
    if ( nRow+1 == nDataStartRow && nCol >= nTabStartCol && o3tl::make_unsigned(nCol) < nTabStartCol + pRowFields.size() )
    {
        rOrient = sheet::DataPilotFieldOrientation_ROW;
        long nField = nCol - nTabStartCol;
        tools::Long nField = nCol - nTabStartCol;
        return pRowFields[nField].mnDim;
    }

@@ -1581,7 +1581,7 @@ long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrien
    if ( nCol == aStartPos.Col() && nRow >= nPageStartRow && o3tl::make_unsigned(nRow) < nPageStartRow + pPageFields.size() )
    {
        rOrient = sheet::DataPilotFieldOrientation_PAGE;
        long nField = nRow - nPageStartRow;
        tools::Long nField = nRow - nPageStartRow;
        return pPageFields[nField].mnDim;
    }

@@ -1592,8 +1592,8 @@ long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrien
}

bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMouseTop,
                                long nDragDim,
                                tools::Rectangle& rPosRect, sheet::DataPilotFieldOrientation& rOrient, long& rDimPos )
                                tools::Long nDragDim,
                                tools::Rectangle& rPosRect, sheet::DataPilotFieldOrientation& rOrient, tools::Long& rDimPos )
{
    //  Rectangle instead of ScRange for rPosRect to allow for negative values

@@ -1612,7 +1612,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
    if ( nCol >= nDataStartCol && nCol <= nTabEndCol &&
            nRow + 1 >= nMemberStartRow && o3tl::make_unsigned(nRow) < nMemberStartRow + pColFields.size())
    {
        long nField = nRow - nMemberStartRow;
        tools::Long nField = nRow - nMemberStartRow;
        if (nField < 0)
        {
            nField = 0;
@@ -1626,7 +1626,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
        bool bFound = false;            // is this within the same orientation?
        bool bBeforeDrag = false;
        bool bAfterDrag = false;
        for (long nPos=0; o3tl::make_unsigned(nPos)<pColFields.size() && !bFound; nPos++)
        for (tools::Long nPos=0; o3tl::make_unsigned(nPos)<pColFields.size() && !bFound; nPos++)
        {
            if (pColFields[nPos].mnDim == nDragDim)
            {
@@ -1671,7 +1671,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
    if ( bSpecial || ( nRow+1 >= nDataStartRow && nRow <= nTabEndRow &&
                        nCol + 1 >= nTabStartCol && o3tl::make_unsigned(nCol) < nTabStartCol + pRowFields.size() ) )
    {
        long nField = nCol - nTabStartCol;
        tools::Long nField = nCol - nTabStartCol;
        //TODO: find start of dimension

        rPosRect = tools::Rectangle( nTabStartCol + nField, nDataStartRow - 1,
@@ -1680,7 +1680,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
        bool bFound = false;            // is this within the same orientation?
        bool bBeforeDrag = false;
        bool bAfterDrag = false;
        for (long nPos=0; o3tl::make_unsigned(nPos)<pRowFields.size() && !bFound; nPos++)
        for (tools::Long nPos=0; o3tl::make_unsigned(nPos)<pRowFields.size() && !bFound; nPos++)
        {
            if (pRowFields[nPos].mnDim == nDragDim)
            {
@@ -1722,7 +1722,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
    if ( nCol >= aStartPos.Col() && nCol <= nTabEndCol &&
            nRow + 1 >= nPageStartRow && o3tl::make_unsigned(nRow) < nPageStartRow + pPageFields.size() )
    {
        long nField = nRow - nPageStartRow;
        tools::Long nField = nRow - nPageStartRow;
        if (nField < 0)
        {
            nField = 0;
@@ -1736,7 +1736,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
        bool bFound = false;            // is this within the same orientation?
        bool bBeforeDrag = false;
        bool bAfterDrag = false;
        for (long nPos=0; o3tl::make_unsigned(nPos)<pPageFields.size() && !bFound; nPos++)
        for (tools::Long nPos=0; o3tl::make_unsigned(nPos)<pPageFields.size() && !bFound; nPos++)
        {
            if (pPageFields[nPos].mnDim == nDragDim)
            {
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index 8ae1f8b..7dc080a 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -345,7 +345,7 @@ void ScDPSaveDimension::SetFunction(ScGeneralFunction nNew)
    nFunction = nNew;
}

void ScDPSaveDimension::SetUsedHierarchy(long nNew)
void ScDPSaveDimension::SetUsedHierarchy(tools::Long nNew)
{
    nUsedHierarchy = nNew;
}
@@ -511,9 +511,9 @@ void ScDPSaveDimension::WriteToSource( const uno::Reference<uno::XInterface>& xD
    // Level loop outside of maMemberList loop
    // because SubTotals have to be set independently of known members

    long nCount = maMemberHash.size();
    tools::Long nCount = maMemberHash.size();

    long nHierCount = 0;
    tools::Long nHierCount = 0;
    uno::Reference<container::XIndexAccess> xHiers;
    uno::Reference<sheet::XHierarchiesSupplier> xHierSupp( xDim, uno::UNO_QUERY );
    if ( xHierSupp.is() )
@@ -525,9 +525,9 @@ void ScDPSaveDimension::WriteToSource( const uno::Reference<uno::XInterface>& xD

    bool bHasHiddenMember = false;

    for (long nHier=0; nHier<nHierCount; nHier++)
    for (tools::Long nHier=0; nHier<nHierCount; nHier++)
    {
        long nLevCount = 0;
        tools::Long nLevCount = 0;
        uno::Reference<container::XIndexAccess> xLevels;
        uno::Reference<sheet::XLevelsSupplier> xLevSupp(xHiers->getByIndex(nHier), uno::UNO_QUERY);
        if ( xLevSupp.is() )
@@ -537,7 +537,7 @@ void ScDPSaveDimension::WriteToSource( const uno::Reference<uno::XInterface>& xD
            nLevCount = xLevels->getCount();
        }

        for (long nLev=0; nLev<nLevCount; nLev++)
        for (tools::Long nLev=0; nLev<nLevCount; nLev++)
        {
            uno::Reference<uno::XInterface> xLevel(xLevels->getByIndex(nLev), uno::UNO_QUERY);
            uno::Reference<beans::XPropertySet> xLevProp( xLevel, uno::UNO_QUERY );
@@ -939,9 +939,9 @@ ScDPSaveDimension* ScDPSaveData::GetFirstDimension(sheet::DataPilotFieldOrientat
    return nullptr;
}

long ScDPSaveData::GetDataDimensionCount() const
tools::Long ScDPSaveData::GetDataDimensionCount() const
{
    long nDataCount = 0;
    tools::Long nDataCount = 0;

    for (auto const& iter : m_DimList)
    {
@@ -952,7 +952,7 @@ long ScDPSaveData::GetDataDimensionCount() const
    return nDataCount;
}

void ScDPSaveData::SetPosition( ScDPSaveDimension* pDim, long nNew )
void ScDPSaveData::SetPosition( ScDPSaveDimension* pDim, tools::Long nNew )
{
    // position (nNew) is counted within dimensions of the same orientation

@@ -1014,8 +1014,8 @@ static void lcl_ResetOrient( const uno::Reference<sheet::XDimensionsSupplier>& x
{
    uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
    uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
    long nIntCount = xIntDims->getCount();
    for (long nIntDim=0; nIntDim<nIntCount; nIntDim++)
    tools::Long nIntCount = xIntDims->getCount();
    for (tools::Long nIntDim=0; nIntDim<nIntCount; nIntDim++)
    {
        uno::Reference<beans::XPropertySet> xDimProp(xIntDims->getByIndex(nIntDim), uno::UNO_QUERY);
        if (xDimProp.is())
@@ -1070,7 +1070,7 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie

        uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
        uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
        long nIntCount = xIntDims->getCount();
        tools::Long nIntCount = xIntDims->getCount();

        for (const auto& rxDim : m_DimList)
        {
@@ -1084,7 +1084,7 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie
            //TODO: getByName for ScDPSource, including DataLayoutDimension !!!!!!!!

            bool bFound = false;
            for (long nIntDim=0; nIntDim<nIntCount && !bFound; nIntDim++)
            for (tools::Long nIntDim=0; nIntDim<nIntCount && !bFound; nIntDim++)
            {
                uno::Reference<uno::XInterface> xIntDim(xIntDims->getByIndex(nIntDim),
                                                        uno::UNO_QUERY);
@@ -1215,8 +1215,8 @@ void ScDPSaveData::BuildAllDimensionMembers(ScDPTableData* pData)
    // First, build a dimension name-to-index map.
    typedef std::unordered_map<OUString, long> NameIndexMap;
    NameIndexMap aMap;
    long nColCount = pData->GetColumnCount();
    for (long i = 0; i < nColCount; ++i)
    tools::Long nColCount = pData->GetColumnCount();
    for (tools::Long i = 0; i < nColCount; ++i)
        aMap.emplace(pData->getDimensionName(i), i);

    NameIndexMap::const_iterator itrEnd = aMap.end();
@@ -1233,7 +1233,7 @@ void ScDPSaveData::BuildAllDimensionMembers(ScDPTableData* pData)
            // dimension name not in the data. This should never happen!
            continue;

        long nDimIndex = itr->second;
        tools::Long nDimIndex = itr->second;
        const std::vector<SCROW>& rMembers = pData->GetColumnEntries(nDimIndex);
        size_t nMemberCount = rMembers.size();
        for (size_t j = 0; j < nMemberCount; ++j)
@@ -1259,8 +1259,8 @@ void ScDPSaveData::SyncAllDimensionMembers(ScDPTableData* pData)

    // First, build a dimension name-to-index map.
    NameIndexMap aMap;
    long nColCount = pData->GetColumnCount();
    for (long i = 0; i < nColCount; ++i)
    tools::Long nColCount = pData->GetColumnCount();
    for (tools::Long i = 0; i < nColCount; ++i)
        aMap.emplace(pData->getDimensionName(i), i);

    NameIndexMap::const_iterator itMapEnd = aMap.end();
@@ -1278,7 +1278,7 @@ void ScDPSaveData::SyncAllDimensionMembers(ScDPTableData* pData)
            continue;

        ScDPSaveDimension::MemberSetType aMemNames;
        long nDimIndex = itMap->second;
        tools::Long nDimIndex = itMap->second;
        const std::vector<SCROW>& rMembers = pData->GetColumnEntries(nDimIndex);
        size_t nMemberCount = rMembers.size();
        for (size_t j = 0; j < nMemberCount; ++j)
diff --git a/sc/source/core/data/dpsdbtab.cxx b/sc/source/core/data/dpsdbtab.cxx
index 00a47857..910e917 100644
--- a/sc/source/core/data/dpsdbtab.cxx
+++ b/sc/source/core/data/dpsdbtab.cxx
@@ -77,13 +77,13 @@ void ScDatabaseDPData::DisposeData()
    aCacheTable.clear();
}

long ScDatabaseDPData::GetColumnCount()
tools::Long ScDatabaseDPData::GetColumnCount()
{
    CreateCacheTable();
    return GetCacheTable().getColSize();
}

OUString ScDatabaseDPData::getDimensionName(long nColumn)
OUString ScDatabaseDPData::getDimensionName(tools::Long nColumn)
{
    if (getIsDataLayoutDimension(nColumn))
    {
@@ -96,12 +96,12 @@ OUString ScDatabaseDPData::getDimensionName(long nColumn)
    return aCacheTable.getFieldName(static_cast<SCCOL>(nColumn));
}

bool ScDatabaseDPData::getIsDataLayoutDimension(long nColumn)
bool ScDatabaseDPData::getIsDataLayoutDimension(tools::Long nColumn)
{
    return ( nColumn == GetCacheTable().getColSize());
}

bool ScDatabaseDPData::IsDateDimension(long /* nDim */)
bool ScDatabaseDPData::IsDateDimension(tools::Long /* nDim */)
{
    //TODO: later...
    return false;
diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx
index 17b7731..607c558 100644
--- a/sc/source/core/data/dpshttab.cxx
+++ b/sc/source/core/data/dpshttab.cxx
@@ -73,13 +73,13 @@ void ScSheetDPData::DisposeData()
    aCacheTable.clear();
}

long ScSheetDPData::GetColumnCount()
tools::Long ScSheetDPData::GetColumnCount()
{
    CreateCacheTable();
    return aCacheTable.getColSize();
}

OUString ScSheetDPData::getDimensionName(long nColumn)
OUString ScSheetDPData::getDimensionName(tools::Long nColumn)
{
    CreateCacheTable();
    if (getIsDataLayoutDimension(nColumn))
@@ -99,10 +99,10 @@ OUString ScSheetDPData::getDimensionName(long nColumn)
    }
}

bool ScSheetDPData::IsDateDimension(long nDim)
bool ScSheetDPData::IsDateDimension(tools::Long nDim)
{
    CreateCacheTable();
    long nColCount = aCacheTable.getColSize();
    tools::Long nColCount = aCacheTable.getColSize();
    if (getIsDataLayoutDimension(nDim))
    {
        return false;
@@ -118,7 +118,7 @@ bool ScSheetDPData::IsDateDimension(long nDim)
    }
}

sal_uInt32 ScSheetDPData::GetNumberFormat(long nDim)
sal_uInt32 ScSheetDPData::GetNumberFormat(tools::Long nDim)
{
    CreateCacheTable();
    if (getIsDataLayoutDimension(nDim))
@@ -146,10 +146,10 @@ sal_uInt32  ScDPTableData::GetNumberFormatByIdx( NfIndexTableOffset eIdx )
    return 0;
}

bool ScSheetDPData::getIsDataLayoutDimension(long nColumn)
bool ScSheetDPData::getIsDataLayoutDimension(tools::Long nColumn)
{
    CreateCacheTable();
    return (nColumn ==static_cast<long>( aCacheTable.getColSize()));
    return (nColumn ==static_cast<tools::Long>( aCacheTable.getColSize()));
}

void ScSheetDPData::SetEmptyFlags( bool bIgnoreEmptyRowsP, bool bRepeatIfEmptyP )
diff --git a/sc/source/core/data/dptabdat.cxx b/sc/source/core/data/dptabdat.cxx
index 88677ea..c0b39a4 100644
--- a/sc/source/core/data/dptabdat.cxx
+++ b/sc/source/core/data/dptabdat.cxx
@@ -48,13 +48,13 @@ ScDPTableData::~ScDPTableData()
{
}

OUString ScDPTableData::GetFormattedString(long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const
OUString ScDPTableData::GetFormattedString(tools::Long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const
{
    const ScDPCache& rCache = GetCacheTable().getCache();
    return rCache.GetFormattedString(nDim, rItem, bLocaleIndependent);
}

long ScDPTableData::GetDatePart( long nDateVal, long nHierarchy, long nLevel )
tools::Long ScDPTableData::GetDatePart( tools::Long nDateVal, tools::Long nHierarchy, tools::Long nLevel )
{
    if ( nDateVal == nLastDateVal && nHierarchy == nLastHier && nLevel == nLastLevel )
        return nLastRet;
@@ -62,7 +62,7 @@ long ScDPTableData::GetDatePart( long nDateVal, long nHierarchy, long nLevel )
    Date aDate( 30,12,1899 );                   //TODO: get from source data (and cache here)
    aDate.AddDays( nDateVal);

    long nRet = 0;
    tools::Long nRet = 0;
    switch (nHierarchy)
    {
        case SC_DAPI_HIERARCHY_QUARTER:
@@ -82,7 +82,7 @@ long ScDPTableData::GetDatePart( long nDateVal, long nHierarchy, long nLevel )
                //TODO: use settings for different definitions
                case 0: nRet = aDate.GetYear();                 break;      //!...
                case 1: nRet = aDate.GetWeekOfYear();           break;
                case 2: nRet = static_cast<long>(aDate.GetDayOfWeek());      break;
                case 2: nRet = static_cast<tools::Long>(aDate.GetDayOfWeek());      break;
                default:
                    OSL_FAIL("GetDatePart: wrong level");
            }
@@ -104,35 +104,35 @@ bool ScDPTableData::IsRepeatIfEmpty()
    return false;
}

sal_uInt32 ScDPTableData::GetNumberFormat(long)
sal_uInt32 ScDPTableData::GetNumberFormat(tools::Long)
{
    return 0;           // default format
}

bool ScDPTableData::IsBaseForGroup(long) const
bool ScDPTableData::IsBaseForGroup(tools::Long) const
{
    return false;       // always false
}

long ScDPTableData::GetGroupBase(long) const
tools::Long ScDPTableData::GetGroupBase(tools::Long) const
{
    return -1;          // always none
}

bool ScDPTableData::IsNumOrDateGroup(long) const
bool ScDPTableData::IsNumOrDateGroup(tools::Long) const
{
    return false;       // always false
}

bool ScDPTableData::IsInGroup( const ScDPItemData&, long,
                               const ScDPItemData&, long ) const
bool ScDPTableData::IsInGroup( const ScDPItemData&, tools::Long,
                               const ScDPItemData&, tools::Long ) const
{
    OSL_FAIL("IsInGroup shouldn't be called for non-group data");
    return false;
}

bool ScDPTableData::HasCommonElement( const ScDPItemData&, long,
                                      const ScDPItemData&, long ) const
bool ScDPTableData::HasCommonElement( const ScDPItemData&, tools::Long,
                                      const ScDPItemData&, tools::Long ) const
{
    OSL_FAIL("HasCommonElement shouldn't be called for non-group data");
    return false;
@@ -149,11 +149,11 @@ void ScDPTableData::FillRowDataFromCacheTable(sal_Int32 nRow, const ScDPFiltered
    // page dimensions
    GetItemData(rCacheTable, nRow, rInfo.aPageDims, rData.aPageData);

    long nCacheColumnCount = rCacheTable.getCache().GetColumnCount();
    tools::Long nCacheColumnCount = rCacheTable.getCache().GetColumnCount();
    sal_Int32 n = rInfo.aDataSrcCols.size();
    for (sal_Int32 i = 0; i < n; ++i)
    {
        long nDim = rInfo.aDataSrcCols[i];
        tools::Long nDim = rInfo.aDataSrcCols[i];
        rData.aValues.emplace_back( );
        // #i111435# GetItemData needs dimension indexes including groups,
        // so the index must be checked here (groups aren't useful as data fields).
@@ -221,7 +221,7 @@ void ScDPTableData::GetItemData(const ScDPFilteredCache& rCacheTable, sal_Int32 
    rItemData.reserve(rItemData.size() + nDimSize);
    for (sal_Int32 i = 0; i < nDimSize; ++i)
    {
        long nDim = rDims[i];
        tools::Long nDim = rDims[i];

        if (getIsDataLayoutDimension(nDim))
        {
@@ -238,14 +238,14 @@ void ScDPTableData::GetItemData(const ScDPFilteredCache& rCacheTable, sal_Int32 
    }
}

long ScDPTableData::GetMembersCount( long nDim )
tools::Long ScDPTableData::GetMembersCount( tools::Long nDim )
{
    if ( nDim > MAXCOL )
        return 0;
    return GetCacheTable().getFieldEntries( nDim ).size();
}

const ScDPItemData* ScDPTableData::GetMemberByIndex( long nDim, long nIndex )
const ScDPItemData* ScDPTableData::GetMemberByIndex( tools::Long nDim, tools::Long nIndex )
{
    if ( nIndex >= GetMembersCount( nDim ) )
        return nullptr;
@@ -255,23 +255,23 @@ const ScDPItemData* ScDPTableData::GetMemberByIndex( long nDim, long nIndex )
    return GetCacheTable().getCache().GetItemDataById( static_cast<SCCOL>(nDim), static_cast<SCROW>(nMembers[nIndex]) );
}

const ScDPItemData* ScDPTableData::GetMemberById( long nDim, long nId)
const ScDPItemData* ScDPTableData::GetMemberById( tools::Long nDim, tools::Long nId)
{
    return GetCacheTable().getCache().GetItemDataById(nDim, static_cast<SCROW>(nId));
}

const std::vector< SCROW >& ScDPTableData::GetColumnEntries( long nColumn )
const std::vector< SCROW >& ScDPTableData::GetColumnEntries( tools::Long nColumn )
{
    return GetCacheTable().getFieldEntries( nColumn );
}

long ScDPTableData::GetSourceDim( long nDim )
tools::Long ScDPTableData::GetSourceDim( tools::Long nDim )
{
    return nDim;

}

long ScDPTableData::Compare( long nDim, long nDataId1, long nDataId2)
tools::Long ScDPTableData::Compare( tools::Long nDim, tools::Long nDataId1, tools::Long nDataId2)
{
    if ( getIsDataLayoutDimension(nDim) )
        return 0;
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index 0fa8647..4fa7764 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -135,11 +135,11 @@ public:
class ScDPRowMembersOrder
{
    ScDPResultDimension& rDimension;
    long                 nMeasure;
    tools::Long                 nMeasure;
    bool                 bAscending;

public:
            ScDPRowMembersOrder( ScDPResultDimension& rDim, long nM, bool bAsc ) :
            ScDPRowMembersOrder( ScDPResultDimension& rDim, tools::Long nM, bool bAsc ) :
                rDimension(rDim),
                nMeasure(nM),
                bAscending(bAsc)
@@ -151,11 +151,11 @@ public:
class ScDPColMembersOrder
{
    ScDPDataDimension& rDimension;
    long               nMeasure;
    tools::Long               nMeasure;
    bool               bAscending;

public:
            ScDPColMembersOrder( ScDPDataDimension& rDim, long nM, bool bAsc ) :
            ScDPColMembersOrder( ScDPDataDimension& rDim, tools::Long nM, bool bAsc ) :
                rDimension(rDim),
                nMeasure(nM),
                bAscending(bAsc)
@@ -166,7 +166,7 @@ public:

}

static bool lcl_IsLess( const ScDPDataMember* pDataMember1, const ScDPDataMember* pDataMember2, long nMeasure, bool bAscending )
static bool lcl_IsLess( const ScDPDataMember* pDataMember1, const ScDPDataMember* pDataMember2, tools::Long nMeasure, bool bAscending )
{
    // members can be NULL if used for rows

@@ -192,7 +192,7 @@ static bool lcl_IsLess( const ScDPDataMember* pDataMember1, const ScDPDataMember
    }
}

static bool lcl_IsEqual( const ScDPDataMember* pDataMember1, const ScDPDataMember* pDataMember2, long nMeasure )
static bool lcl_IsEqual( const ScDPDataMember* pDataMember1, const ScDPDataMember* pDataMember2, tools::Long nMeasure )
{
    // members can be NULL if used for rows

@@ -249,10 +249,10 @@ bool ScDPColMembersOrder::operator()( sal_Int32 nIndex1, sal_Int32 nIndex2 ) con
    return lcl_IsLess( pDataMember1, pDataMember2, nMeasure, bAscending );
}

ScDPInitState::Member::Member(long nSrcIndex, SCROW nNameIndex) :
ScDPInitState::Member::Member(tools::Long nSrcIndex, SCROW nNameIndex) :
    mnSrcIndex(nSrcIndex), mnNameIndex(nNameIndex) {}

void ScDPInitState::AddMember( long nSourceIndex, SCROW nMember )
void ScDPInitState::AddMember( tools::Long nSourceIndex, SCROW nMember )
{
    maMembers.emplace_back(nSourceIndex, nMember);
}
@@ -314,7 +314,7 @@ ScDPRunningTotalState::ScDPRunningTotalState( ScDPResultMember* pColRoot, ScDPRe
    maRowSorted.push_back(-1);
}

void ScDPRunningTotalState::AddColIndex( long nVisible, long nSorted )
void ScDPRunningTotalState::AddColIndex( tools::Long nVisible, tools::Long nSorted )
{
    maColVisible.back() = nVisible;
    maColVisible.push_back(-1);
@@ -323,7 +323,7 @@ void ScDPRunningTotalState::AddColIndex( long nVisible, long nSorted )
    maColSorted.push_back(-1);
}

void ScDPRunningTotalState::AddRowIndex( long nVisible, long nSorted )
void ScDPRunningTotalState::AddRowIndex( tools::Long nVisible, tools::Long nSorted )
{
    maRowVisible.back() = nVisible;
    maRowVisible.push_back(-1);
@@ -364,7 +364,7 @@ void ScDPRunningTotalState::RemoveRowIndex()
    }
}

ScDPRelativePos::ScDPRelativePos( long nBase, long nDir ) :
ScDPRelativePos::ScDPRelativePos( tools::Long nBase, tools::Long nDir ) :
    nBasePos( nBase ),
    nDirection( nDir )
{
@@ -696,16 +696,16 @@ ScDPRowTotals::~ScDPRowTotals()
{
}

static ScDPAggData* lcl_GetChildTotal( ScDPAggData* pFirst, long nMeasure )
static ScDPAggData* lcl_GetChildTotal( ScDPAggData* pFirst, tools::Long nMeasure )
{
    OSL_ENSURE( nMeasure >= 0, "GetColTotal: no measure" );

    ScDPAggData* pAgg = pFirst;
    long nSkip = nMeasure;
    tools::Long nSkip = nMeasure;

    // subtotal settings are ignored - column/row totals exist once per measure

    for ( long nPos=0; nPos<nSkip; nPos++ )
    for ( tools::Long nPos=0; nPos<nSkip; nPos++ )
        pAgg = pAgg->GetChild();    // column total is constructed empty - children need to be created

    if ( !pAgg->IsCalculated() )
@@ -718,17 +718,17 @@ static ScDPAggData* lcl_GetChildTotal( ScDPAggData* pFirst, long nMeasure )
    return pAgg;
}

ScDPAggData* ScDPRowTotals::GetRowTotal( long nMeasure )
ScDPAggData* ScDPRowTotals::GetRowTotal( tools::Long nMeasure )
{
    return lcl_GetChildTotal( &aRowTotal, nMeasure );
}

ScDPAggData* ScDPRowTotals::GetGrandTotal( long nMeasure )
ScDPAggData* ScDPRowTotals::GetGrandTotal( tools::Long nMeasure )
{
    return lcl_GetChildTotal( &aGrandTotal, nMeasure );
}

static ScSubTotalFunc lcl_GetForceFunc( const ScDPLevel* pLevel, long nFuncNo )
static ScSubTotalFunc lcl_GetForceFunc( const ScDPLevel* pLevel, tools::Long nFuncNo )
{
    ScSubTotalFunc eRet = SUBTOTAL_FUNC_NONE;
    if ( pLevel )
@@ -736,7 +736,7 @@ static ScSubTotalFunc lcl_GetForceFunc( const ScDPLevel* pLevel, long nFuncNo )
        //TODO: direct access via ScDPLevel

        uno::Sequence<sal_Int16> aSeq = pLevel->getSubTotals();
        long nSequence = aSeq.getLength();
        tools::Long nSequence = aSeq.getLength();
        if ( nSequence && aSeq[0] != sheet::GeneralFunction2::AUTO )
        {
            // For manual subtotals, "automatic" is added as first function.
@@ -802,7 +802,7 @@ void ScDPResultData::SetLateInit( bool bSet )
    bLateInit = bSet;
}

long ScDPResultData::GetColStartMeasure() const
tools::Long ScDPResultData::GetColStartMeasure() const
{
    if (maMeasureFuncs.size() == 1)
        return 0;
@@ -810,7 +810,7 @@ long ScDPResultData::GetColStartMeasure() const
    return bDataAtCol ? SC_DPMEASURE_ALL : SC_DPMEASURE_ANY;
}

long ScDPResultData::GetRowStartMeasure() const
tools::Long ScDPResultData::GetRowStartMeasure() const
{
    if (maMeasureFuncs.size() == 1)
        return 0;
@@ -818,25 +818,25 @@ long ScDPResultData::GetRowStartMeasure() const
    return bDataAtRow ? SC_DPMEASURE_ALL : SC_DPMEASURE_ANY;
}

ScSubTotalFunc ScDPResultData::GetMeasureFunction(long nMeasure) const
ScSubTotalFunc ScDPResultData::GetMeasureFunction(tools::Long nMeasure) const
{
    OSL_ENSURE(o3tl::make_unsigned(nMeasure) < maMeasureFuncs.size(), "bumm");
    return maMeasureFuncs[nMeasure];
}

const sheet::DataPilotFieldReference& ScDPResultData::GetMeasureRefVal(long nMeasure) const
const sheet::DataPilotFieldReference& ScDPResultData::GetMeasureRefVal(tools::Long nMeasure) const
{
    OSL_ENSURE(o3tl::make_unsigned(nMeasure) < maMeasureRefs.size(), "bumm");
    return maMeasureRefs[nMeasure];
}

sheet::DataPilotFieldOrientation ScDPResultData::GetMeasureRefOrient(long nMeasure) const
sheet::DataPilotFieldOrientation ScDPResultData::GetMeasureRefOrient(tools::Long nMeasure) const
{
    OSL_ENSURE(o3tl::make_unsigned(nMeasure) < maMeasureRefOrients.size(), "bumm");
    return maMeasureRefOrients[nMeasure];
}

OUString ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const
OUString ScDPResultData::GetMeasureString(tools::Long nMeasure, bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const
{
    //  with bForce==true, return function instead of "result" for single measure
    //  with eForceFunc != SUBTOTAL_FUNC_NONE, always use eForceFunc
@@ -870,7 +870,7 @@ OUString ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotal
    }
}

OUString ScDPResultData::GetMeasureDimensionName(long nMeasure) const
OUString ScDPResultData::GetMeasureDimensionName(tools::Long nMeasure) const
{
    if ( nMeasure < 0 )
    {
@@ -881,23 +881,23 @@ OUString ScDPResultData::GetMeasureDimensionName(long nMeasure) const
    return mrSource.GetDataDimName(nMeasure);
}

bool ScDPResultData::IsBaseForGroup( long nDim ) const
bool ScDPResultData::IsBaseForGroup( tools::Long nDim ) const
{
    return mrSource.GetData()->IsBaseForGroup(nDim);
}

long ScDPResultData::GetGroupBase( long nGroupDim ) const
tools::Long ScDPResultData::GetGroupBase( tools::Long nGroupDim ) const
{
    return mrSource.GetData()->GetGroupBase(nGroupDim);
}

bool ScDPResultData::IsNumOrDateGroup( long nDim ) const
bool ScDPResultData::IsNumOrDateGroup( tools::Long nDim ) const
{
    return mrSource.GetData()->IsNumOrDateGroup(nDim);
}

bool ScDPResultData::IsInGroup( SCROW nGroupDataId, long nGroupIndex,
                                const ScDPItemData& rBaseData, long nBaseIndex ) const
bool ScDPResultData::IsInGroup( SCROW nGroupDataId, tools::Long nGroupIndex,
                                const ScDPItemData& rBaseData, tools::Long nBaseIndex ) const
{
    const ScDPItemData* pGroupData = mrSource.GetItemDataById(nGroupIndex , nGroupDataId);
    if ( pGroupData )
@@ -906,8 +906,8 @@ bool ScDPResultData::IsInGroup( SCROW nGroupDataId, long nGroupIndex,
        return false;
}

bool ScDPResultData::HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
                                       const ScDPItemData& rSecondData, long nSecondIndex ) const
bool ScDPResultData::HasCommonElement( SCROW nFirstDataId, tools::Long nFirstIndex,
                                       const ScDPItemData& rSecondData, tools::Long nSecondIndex ) const
{
    const ScDPItemData* pFirstData = mrSource.GetItemDataById(nFirstIndex , nFirstDataId);
    if ( pFirstData )
@@ -916,12 +916,12 @@ bool ScDPResultData::HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
        return false;
}

ResultMembers& ScDPResultData::GetDimResultMembers(long nDim, const ScDPDimension* pDim, ScDPLevel* pLevel) const
ResultMembers& ScDPResultData::GetDimResultMembers(tools::Long nDim, const ScDPDimension* pDim, ScDPLevel* pLevel) const
{
    if (nDim < static_cast<long>(maDimMembers.size()) && maDimMembers[nDim])
    if (nDim < static_cast<tools::Long>(maDimMembers.size()) && maDimMembers[nDim])
        return *maDimMembers[nDim];

    if (nDim >= static_cast<long>(maDimMembers.size()))
    if (nDim >= static_cast<tools::Long>(maDimMembers.size()))
        maDimMembers.resize(nDim+1);

    std::unique_ptr<ResultMembers> pResultMembers(new ResultMembers());
@@ -929,10 +929,10 @@ ResultMembers& ScDPResultData::GetDimResultMembers(long nDim, const ScDPDimensio
    const ScMemberSortOrder& rGlobalOrder = pLevel->GetGlobalOrder();

    ScDPMembers* pMembers = pLevel->GetMembersObject();
    long nMembCount = pMembers->getCount();
    for (long i = 0; i < nMembCount; ++i)
    tools::Long nMembCount = pMembers->getCount();
    for (tools::Long i = 0; i < nMembCount; ++i)
    {
        long nSorted = rGlobalOrder.empty() ? i : rGlobalOrder[i];
        tools::Long nSorted = rGlobalOrder.empty() ? i : rGlobalOrder[i];
        ScDPMember* pMember = pMembers->getByIndex(nSorted);
        if (!pResultMembers->FindMember(pMember->GetItemDataId()))
        {
@@ -992,7 +992,7 @@ OUString ScDPResultMember::GetDisplayName( bool bLocaleIndependent ) const
    ScDPItemData aItem(pDPMember->FillItemData());
    if (aParentDimData.mpParentDim)
    {
        long nDim = aParentDimData.mpParentDim->GetDimension();
        tools::Long nDim = aParentDimData.mpParentDim->GetDimension();
        return pResultData->GetSource().GetData()->GetFormattedString(nDim, aItem, bLocaleIndependent);
    }

@@ -1131,14 +1131,14 @@ void ScDPResultMember::LateInitFrom(
    }
}

bool ScDPResultMember::IsSubTotalInTitle(long nMeasure) const
bool ScDPResultMember::IsSubTotalInTitle(tools::Long nMeasure) const
{
    bool bRet = false;
    if ( pChildDimension && /*pParentLevel*/GetParentLevel() &&
         /*pParentLevel*/GetParentLevel()->IsOutlineLayout() && /*pParentLevel*/GetParentLevel()->IsSubtotalsAtTop() )
    {
        long nUserSubStart;
        long nSubTotals = GetSubTotalCount( &nUserSubStart );
        tools::Long nUserSubStart;
        tools::Long nSubTotals = GetSubTotalCount( &nUserSubStart );
        nSubTotals -= nUserSubStart;            // visible count
        if ( nSubTotals )
        {
@@ -1153,12 +1153,12 @@ bool ScDPResultMember::IsSubTotalInTitle(long nMeasure) const
    return bRet;
}

long ScDPResultMember::GetSize(long nMeasure) const
tools::Long ScDPResultMember::GetSize(tools::Long nMeasure) const
{
    if ( !IsVisible() )
        return 0;
    const ScDPLevel*       pParentLevel = GetParentLevel();
    long nExtraSpace = 0;
    tools::Long nExtraSpace = 0;
    if ( pParentLevel && pParentLevel->IsAddEmpty() )
        ++nExtraSpace;

@@ -1168,9 +1168,9 @@ long ScDPResultMember::GetSize(long nMeasure) const
        if ( pParentLevel && pParentLevel->IsOutlineLayout() && !IsSubTotalInTitle( nMeasure ) )
            ++nExtraSpace;

        long nSize = pChildDimension->GetSize(nMeasure);
        long nUserSubStart;
        long nUserSubCount = GetSubTotalCount( &nUserSubStart );
        tools::Long nSize = pChildDimension->GetSize(nMeasure);
        tools::Long nUserSubStart;
        tools::Long nUserSubCount = GetSubTotalCount( &nUserSubStart );
        nUserSubCount -= nUserSubStart;     // for output size, use visible count
        if ( nUserSubCount )
        {
@@ -1223,7 +1223,7 @@ bool ScDPResultMember::IsValid() const
    return true;
}

long ScDPResultMember::GetSubTotalCount( long* pUserSubStart ) const
tools::Long ScDPResultMember::GetSubTotalCount( tools::Long* pUserSubStart ) const
{
    if ( pUserSubStart )
        *pUserSubStart = 0;     // default
@@ -1237,7 +1237,7 @@ long ScDPResultMember::GetSubTotalCount( long* pUserSubStart ) const
        //TODO: direct access via ScDPLevel

        uno::Sequence<sal_Int16> aSeq = pParentLevel->getSubTotals();
        long nSequence = aSeq.getLength();
        tools::Long nSequence = aSeq.getLength();
        if ( nSequence && aSeq[0] != sheet::GeneralFunction2::AUTO )
        {
            // For manual subtotals, always add "automatic" as first function
@@ -1270,7 +1270,7 @@ void ScDPResultMember::ProcessData( const vector< SCROW >& aChildMembers, const 

    ScDPSubTotalState aSubState;        // initial state

    long nUserSubCount = GetSubTotalCount();
    tools::Long nUserSubCount = GetSubTotalCount();

    // Calculate at least automatic if no subtotals are selected,
    // show only own values if there's no child dimension (innermost).
@@ -1279,7 +1279,7 @@ void ScDPResultMember::ProcessData( const vector< SCROW >& aChildMembers, const 

    const ScDPLevel*    pParentLevel = GetParentLevel();

    for (long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
    for (tools::Long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
    {
        // #i68338# if nUserSubCount is 1 (automatic only), don't set nRowSubTotalFunc
        if ( pChildDimension && nUserSubCount > 1 )
@@ -1320,7 +1320,7 @@ static OUString lcl_parseSubtotalName(const OUString& rSubStr, const OUString& r
}

void ScDPResultMember::FillMemberResults(
    uno::Sequence<sheet::MemberResult>* pSequences, long& rPos, long nMeasure, bool bRoot,
    uno::Sequence<sheet::MemberResult>* pSequences, tools::Long& rPos, tools::Long nMeasure, bool bRoot,
    const OUString* pMemberName, const OUString* pMemberCaption )
{
    //  IsVisible() test is in ScDPResultDimension::FillMemberResults
@@ -1330,7 +1330,7 @@ void ScDPResultMember::FillMemberResults(
        // empty sequence.  Bail out.
        return;

    long nSize = GetSize(nMeasure);
    tools::Long nSize = GetSize(nMeasure);
    sheet::MemberResult* pArray = pSequences->getArray();
    OSL_ENSURE( rPos+nSize <= pSequences->getLength(), "bumm" );

@@ -1347,12 +1347,12 @@ void ScDPResultMember::FillMemberResults(
        ScDPItemData aItemData(FillItemData());
        if (aParentDimData.mpParentDim)
        {
            long nDim = aParentDimData.mpParentDim->GetDimension();
            tools::Long nDim = aParentDimData.mpParentDim->GetDimension();
            aName = pResultData->GetSource().GetData()->GetFormattedString(nDim, aItemData, false);
        }
        else
        {
            long nDim = -1;
            tools::Long nDim = -1;
            const ScDPMember* pMem = GetDPMember();
            if (pMem)
                nDim = pMem->GetDim();
@@ -1407,14 +1407,14 @@ void ScDPResultMember::FillMemberResults(
        pArray[rPos].Value   = fValue;

        //  set "continue" flag (removed for subtotals later)
        for (long i=1; i<nSize; i++)
        for (tools::Long i=1; i<nSize; i++)
            pArray[rPos+i].Flags |= sheet::MemberResultFlags::CONTINUE;
        if ( pParentLevel && pParentLevel->getRepeatItemLabels() )
        {
            long nSizeNonEmpty = nSize;
            tools::Long nSizeNonEmpty = nSize;
            if ( pParentLevel->IsAddEmpty() )
                --nSizeNonEmpty;
            for (long i=1; i<nSizeNonEmpty; i++)
            for (tools::Long i=1; i<nSizeNonEmpty; i++)
            {
                pArray[rPos+i].Name = aName;
                pArray[rPos+i].Caption = aCaption;
@@ -1424,7 +1424,7 @@ void ScDPResultMember::FillMemberResults(
        }
    }

    long nExtraSpace = 0;
    tools::Long nExtraSpace = 0;
    if ( pParentLevel && pParentLevel->IsAddEmpty() )
        ++nExtraSpace;

@@ -1453,20 +1453,20 @@ void ScDPResultMember::FillMemberResults(

    rPos += nSize;

    long nUserSubStart;
    long nUserSubCount = GetSubTotalCount(&nUserSubStart);
    tools::Long nUserSubStart;
    tools::Long nUserSubCount = GetSubTotalCount(&nUserSubStart);
    if ( !nUserSubCount || !pChildDimension || bSubTotalInTitle )
        return;

    long nMemberMeasure = nMeasure;
    long nSubSize = pResultData->GetCountForMeasure(nMeasure);
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nSubSize = pResultData->GetCountForMeasure(nMeasure);

    rPos -= nSubSize * (nUserSubCount - nUserSubStart);     // GetSize includes space for SubTotal
    rPos -= nExtraSpace;                                    // GetSize includes the empty line

    for (long nUserPos=nUserSubStart; nUserPos<nUserSubCount; nUserPos++)
    for (tools::Long nUserPos=nUserSubStart; nUserPos<nUserSubCount; nUserPos++)
    {
        for ( long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
        for ( tools::Long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
        {
            if ( nMeasure == SC_DPMEASURE_ALL )
                nMemberMeasure = nSubCount;
@@ -1537,7 +1537,7 @@ void ScDPResultMember::FillMemberResults(
void ScDPResultMember::FillDataResults(
    const ScDPResultMember* pRefMember,
    ScDPResultFilterContext& rFilterCxt, uno::Sequence<uno::Sequence<sheet::DataResult> >& rSequence,
    long nMeasure) const
    tools::Long nMeasure) const
{
    std::unique_ptr<FilterStack> pFilterStack;
    const ScDPMember* pDPMember = GetDPMember();
@@ -1551,9 +1551,9 @@ void ScDPResultMember::FillDataResults(
    //  IsVisible() test is in ScDPResultDimension::FillDataResults
    //  (not on data layout dimension)
    const ScDPLevel*     pParentLevel = GetParentLevel();
    long nStartRow = rFilterCxt.mnRow;
    tools::Long nStartRow = rFilterCxt.mnRow;

    long nExtraSpace = 0;
    tools::Long nExtraSpace = 0;
    if ( pParentLevel && pParentLevel->IsAddEmpty() )
        ++nExtraSpace;

@@ -1569,7 +1569,7 @@ void ScDPResultMember::FillDataResults(
        if ( bTitleLine )           // in tabular layout the title is on a separate row
            ++rFilterCxt.mnRow;                 // -> fill child dimension one row below

        long nOldRow = rFilterCxt.mnRow;
        tools::Long nOldRow = rFilterCxt.mnRow;
        pChildDimension->FillDataResults(pRefMember, rFilterCxt, rSequence, nMeasure);
        rFilterCxt.mnRow = nOldRow; // Revert to the original row before the call.

@@ -1579,8 +1579,8 @@ void ScDPResultMember::FillDataResults(
            --rFilterCxt.mnRow;                 // positions are calculated with the normal values
    }

    long nUserSubStart;
    long nUserSubCount = GetSubTotalCount(&nUserSubStart);
    tools::Long nUserSubStart;
    tools::Long nUserSubCount = GetSubTotalCount(&nUserSubStart);
    if ( !nUserSubCount && bHasChild )
        return;

@@ -1592,15 +1592,15 @@ void ScDPResultMember::FillDataResults(
        nUserSubStart = 0;
    }

    long nMemberMeasure = nMeasure;
    long nSubSize = pResultData->GetCountForMeasure(nMeasure);
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nSubSize = pResultData->GetCountForMeasure(nMeasure);
    if (bHasChild)
    {
        rFilterCxt.mnRow -= nSubSize * ( nUserSubCount - nUserSubStart );   // GetSize includes space for SubTotal
        rFilterCxt.mnRow -= nExtraSpace;                                    // GetSize includes the empty line
    }

    long nMoveSubTotal = 0;
    tools::Long nMoveSubTotal = 0;
    if ( bSubTotalInTitle )
    {
        nMoveSubTotal = rFilterCxt.mnRow - nStartRow;   // force to first (title) row
@@ -1611,7 +1611,7 @@ void ScDPResultMember::FillDataResults(
    {
        ScDPSubTotalState aSubState;        // initial state

        for (long nUserPos=nUserSubStart; nUserPos<nUserSubCount; nUserPos++)
        for (tools::Long nUserPos=nUserSubStart; nUserPos<nUserSubCount; nUserPos++)
        {
            if ( bHasChild && nUserSubCount > 1 )
            {
@@ -1619,7 +1619,7 @@ void ScDPResultMember::FillDataResults(
                aSubState.eRowForce = lcl_GetForceFunc( /*pParentLevel*/GetParentLevel() , nUserPos );
            }

            for ( long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
            for ( tools::Long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
            {
                if ( nMeasure == SC_DPMEASURE_ALL )
                    nMemberMeasure = nSubCount;
@@ -1646,14 +1646,14 @@ void ScDPResultMember::FillDataResults(
    rFilterCxt.mnRow += nMoveSubTotal;
}

void ScDPResultMember::UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const
void ScDPResultMember::UpdateDataResults( const ScDPResultMember* pRefMember, tools::Long nMeasure ) const
{
    //  IsVisible() test is in ScDPResultDimension::FillDataResults
    //  (not on data layout dimension)

    bool bHasChild = ( pChildDimension != nullptr );

    long nUserSubCount = GetSubTotalCount();
    tools::Long nUserSubCount = GetSubTotalCount();

    // process subtotals even if not shown

@@ -1662,14 +1662,14 @@ void ScDPResultMember::UpdateDataResults( const ScDPResultMember* pRefMember, lo
    if (!nUserSubCount || !bHasChild)
        nUserSubCount = 1;

    long nMemberMeasure = nMeasure;
    long nSubSize = pResultData->GetCountForMeasure(nMeasure);
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nSubSize = pResultData->GetCountForMeasure(nMeasure);

    if (pDataRoot)
    {
        ScDPSubTotalState aSubState;        // initial state

        for (long nUserPos = 0; nUserPos < nUserSubCount; ++nUserPos)   // including hidden "automatic"
        for (tools::Long nUserPos = 0; nUserPos < nUserSubCount; ++nUserPos)   // including hidden "automatic"
        {
            if (bHasChild && nUserSubCount > 1)
            {
@@ -1677,7 +1677,7 @@ void ScDPResultMember::UpdateDataResults( const ScDPResultMember* pRefMember, lo
                aSubState.eRowForce = lcl_GetForceFunc(GetParentLevel(), nUserPos);
            }

            for (long nSubCount = 0; nSubCount < nSubSize; ++nSubCount)
            for (tools::Long nSubCount = 0; nSubCount < nSubSize; ++nSubCount)
            {
                if (nMeasure == SC_DPMEASURE_ALL)
                    nMemberMeasure = nSubCount;
@@ -1734,7 +1734,7 @@ void ScDPResultMember::ResetResults()
        pChildDimension->ResetResults();
}

void ScDPResultMember::UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
void ScDPResultMember::UpdateRunningTotals( const ScDPResultMember* pRefMember, tools::Long nMeasure,
                                            ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const
{
    //  IsVisible() test is in ScDPResultDimension::FillDataResults
@@ -1744,7 +1744,7 @@ void ScDPResultMember::UpdateRunningTotals( const ScDPResultMember* pRefMember, 

    bool bHasChild = ( pChildDimension != nullptr );

    long nUserSubCount = GetSubTotalCount();
    tools::Long nUserSubCount = GetSubTotalCount();
    //if ( nUserSubCount || !bHasChild )
    {
        // Calculate at least automatic if no subtotals are selected,
@@ -1752,14 +1752,14 @@ void ScDPResultMember::UpdateRunningTotals( const ScDPResultMember* pRefMember, 
        if ( !nUserSubCount || !bHasChild )
            nUserSubCount = 1;

        long nMemberMeasure = nMeasure;
        long nSubSize = pResultData->GetCountForMeasure(nMeasure);
        tools::Long nMemberMeasure = nMeasure;
        tools::Long nSubSize = pResultData->GetCountForMeasure(nMeasure);

        if ( pDataRoot )
        {
            ScDPSubTotalState aSubState;        // initial state

            for (long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
            for (tools::Long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
            {
                if ( bHasChild && nUserSubCount > 1 )
                {
@@ -1767,7 +1767,7 @@ void ScDPResultMember::UpdateRunningTotals( const ScDPResultMember* pRefMember, 
                    aSubState.eRowForce = lcl_GetForceFunc(GetParentLevel(), nUserPos);
                }

                for ( long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
                for ( tools::Long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
                {
                    if ( nMeasure == SC_DPMEASURE_ALL )
                        nMemberMeasure = nSubCount;
@@ -1823,7 +1823,7 @@ void ScDPResultMember::Dump(int nIndent) const
}
#endif

ScDPAggData* ScDPResultMember::GetColTotal( long nMeasure ) const
ScDPAggData* ScDPResultMember::GetColTotal( tools::Long nMeasure ) const
{
    return lcl_GetChildTotal( const_cast<ScDPAggData*>(&aColTotal), nMeasure );
}
@@ -1884,10 +1884,10 @@ void ScDPDataMember::InitFrom( const ScDPResultDimension* pDim )
    pChildDimension->InitFrom(pDim);
}

const long SC_SUBTOTALPOS_AUTO = -1;    // default
const long SC_SUBTOTALPOS_SKIP = -2;    // don't use
const tools::Long SC_SUBTOTALPOS_AUTO = -1;    // default
const tools::Long SC_SUBTOTALPOS_SKIP = -2;    // don't use

static long lcl_GetSubTotalPos( const ScDPSubTotalState& rSubState )
static tools::Long lcl_GetSubTotalPos( const ScDPSubTotalState& rSubState )
{
    if ( rSubState.nColSubTotalFunc >= 0 && rSubState.nRowSubTotalFunc >= 0 &&
         rSubState.nColSubTotalFunc != rSubState.nRowSubTotalFunc )
@@ -1898,7 +1898,7 @@ static long lcl_GetSubTotalPos( const ScDPSubTotalState& rSubState )
        return SC_SUBTOTALPOS_SKIP;
    }

    long nRet = SC_SUBTOTALPOS_AUTO;
    tools::Long nRet = SC_SUBTOTALPOS_AUTO;
    if ( rSubState.nColSubTotalFunc >= 0 ) nRet = rSubState.nColSubTotalFunc;
    if ( rSubState.nRowSubTotalFunc >= 0 ) nRet = rSubState.nRowSubTotalFunc;
    return nRet;
@@ -1910,13 +1910,13 @@ void ScDPDataMember::UpdateValues( const vector<ScDPValue>& aValues, const ScDPS

    ScDPAggData* pAgg = &aAggregate;

    long nSubPos = lcl_GetSubTotalPos(rSubState);
    tools::Long nSubPos = lcl_GetSubTotalPos(rSubState);
    if (nSubPos == SC_SUBTOTALPOS_SKIP)
        return;
    if (nSubPos > 0)
    {
        long nSkip = nSubPos * pResultData->GetMeasureCount();
        for (long i=0; i<nSkip; i++)
        tools::Long nSkip = nSubPos * pResultData->GetMeasureCount();
        for (tools::Long i=0; i<nSkip; i++)
            pAgg = pAgg->GetChild();        // created if not there
    }

@@ -1939,7 +1939,7 @@ void ScDPDataMember::ProcessData( const vector< SCROW >& aChildMembers, const ve
        InitFrom( pResultMember->GetChildDimension() );
    }

    long nUserSubCount = pResultMember ? pResultMember->GetSubTotalCount() : 0;
    tools::Long nUserSubCount = pResultMember ? pResultMember->GetSubTotalCount() : 0;

    // Calculate at least automatic if no subtotals are selected,
    // show only own values if there's no child dimension (innermost).
@@ -1947,7 +1947,7 @@ void ScDPDataMember::ProcessData( const vector< SCROW >& aChildMembers, const ve
        nUserSubCount = 1;

    ScDPSubTotalState aLocalSubState = rSubState;        // keep row state, modify column
    for (long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
    for (tools::Long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
    {
        if ( pChildDimension && nUserSubCount > 1 )
        {
@@ -1963,7 +1963,7 @@ void ScDPDataMember::ProcessData( const vector< SCROW >& aChildMembers, const ve
        pChildDimension->ProcessData( aChildMembers, aValues, rSubState );      // with unmodified subtotal state
}

bool ScDPDataMember::HasData( long nMeasure, const ScDPSubTotalState& rSubState ) const
bool ScDPDataMember::HasData( tools::Long nMeasure, const ScDPSubTotalState& rSubState ) const
{
    if ( rSubState.eColForce != SUBTOTAL_FUNC_NONE && rSubState.eRowForce != SUBTOTAL_FUNC_NONE &&
                                                        rSubState.eColForce != rSubState.eRowForce )
@@ -1978,7 +1978,7 @@ bool ScDPDataMember::HasData( long nMeasure, const ScDPSubTotalState& rSubState 
    return pAgg->HasData();
}

bool ScDPDataMember::HasError( long nMeasure, const ScDPSubTotalState& rSubState ) const
bool ScDPDataMember::HasError( tools::Long nMeasure, const ScDPSubTotalState& rSubState ) const
{
    const ScDPAggData* pAgg = GetConstAggData( nMeasure, rSubState );
    if (!pAgg)
@@ -1987,7 +1987,7 @@ bool ScDPDataMember::HasError( long nMeasure, const ScDPSubTotalState& rSubState
    return pAgg->HasError();
}

double ScDPDataMember::GetAggregate( long nMeasure, const ScDPSubTotalState& rSubState ) const
double ScDPDataMember::GetAggregate( tools::Long nMeasure, const ScDPSubTotalState& rSubState ) const
{
    const ScDPAggData* pAgg = GetConstAggData( nMeasure, rSubState );
    if (!pAgg)
@@ -1996,37 +1996,37 @@ double ScDPDataMember::GetAggregate( long nMeasure, const ScDPSubTotalState& rSu
    return pAgg->GetResult();
}

ScDPAggData* ScDPDataMember::GetAggData( long nMeasure, const ScDPSubTotalState& rSubState )
ScDPAggData* ScDPDataMember::GetAggData( tools::Long nMeasure, const ScDPSubTotalState& rSubState )
{
    OSL_ENSURE( nMeasure >= 0, "GetAggData: no measure" );

    ScDPAggData* pAgg = &aAggregate;
    long nSkip = nMeasure;
    long nSubPos = lcl_GetSubTotalPos(rSubState);
    tools::Long nSkip = nMeasure;
    tools::Long nSubPos = lcl_GetSubTotalPos(rSubState);
    if (nSubPos == SC_SUBTOTALPOS_SKIP)
        return nullptr;
    if (nSubPos > 0)
        nSkip += nSubPos * pResultData->GetMeasureCount();

    for ( long nPos=0; nPos<nSkip; nPos++ )
    for ( tools::Long nPos=0; nPos<nSkip; nPos++ )
        pAgg = pAgg->GetChild();        //TODO: need to create children here?

    return pAgg;
}

const ScDPAggData* ScDPDataMember::GetConstAggData( long nMeasure, const ScDPSubTotalState& rSubState ) const
const ScDPAggData* ScDPDataMember::GetConstAggData( tools::Long nMeasure, const ScDPSubTotalState& rSubState ) const
{
    OSL_ENSURE( nMeasure >= 0, "GetConstAggData: no measure" );

    const ScDPAggData* pAgg = &aAggregate;
    long nSkip = nMeasure;
    long nSubPos = lcl_GetSubTotalPos(rSubState);
    tools::Long nSkip = nMeasure;
    tools::Long nSubPos = lcl_GetSubTotalPos(rSubState);
    if (nSubPos == SC_SUBTOTALPOS_SKIP)
        return nullptr;
    if (nSubPos > 0)
        nSkip += nSubPos * pResultData->GetMeasureCount();

    for ( long nPos=0; nPos<nSkip; nPos++ )
    for ( tools::Long nPos=0; nPos<nSkip; nPos++ )
    {
        pAgg = pAgg->GetExistingChild();
        if (!pAgg)
@@ -2038,7 +2038,7 @@ const ScDPAggData* ScDPDataMember::GetConstAggData( long nMeasure, const ScDPSub

void ScDPDataMember::FillDataRow(
    const ScDPResultMember* pRefMember, ScDPResultFilterContext& rFilterCxt,
    uno::Sequence<sheet::DataResult>& rSequence, long nMeasure, bool bIsSubTotalRow,
    uno::Sequence<sheet::DataResult>& rSequence, tools::Long nMeasure, bool bIsSubTotalRow,
    const ScDPSubTotalState& rSubState) const
{
    std::unique_ptr<FilterStack> pFilterStack;
@@ -2053,14 +2053,14 @@ void ScDPDataMember::FillDataRow(

    OSL_ENSURE( pRefMember == pResultMember || !pResultMember, "bla" );

    long nStartCol = rFilterCxt.mnCol;
    tools::Long nStartCol = rFilterCxt.mnCol;

    const ScDPDataDimension* pDataChild = GetChildDimension();
    const ScDPResultDimension* pRefChild = pRefMember->GetChildDimension();

    const ScDPLevel* pRefParentLevel = pRefMember->GetParentLevel();

    long nExtraSpace = 0;
    tools::Long nExtraSpace = 0;
    if ( pRefParentLevel && pRefParentLevel->IsAddEmpty() )
        ++nExtraSpace;

@@ -2081,7 +2081,7 @@ void ScDPDataMember::FillDataRow(

        if ( pDataChild )
        {
            long nOldCol = rFilterCxt.mnCol;
            tools::Long nOldCol = rFilterCxt.mnCol;
            pDataChild->FillDataRow(pRefChild, rFilterCxt, rSequence, nMeasure, bIsSubTotalRow, rSubState);
            rFilterCxt.mnCol = nOldCol; // Revert to the old column value before the call.
        }
@@ -2091,8 +2091,8 @@ void ScDPDataMember::FillDataRow(
            --rFilterCxt.mnCol;                 // positions are calculated with the normal values
    }

    long nUserSubStart;
    long nUserSubCount = pRefMember->GetSubTotalCount(&nUserSubStart);
    tools::Long nUserSubStart;
    tools::Long nUserSubCount = pRefMember->GetSubTotalCount(&nUserSubStart);
    if ( !nUserSubCount && bHasChild )
        return;

@@ -2106,22 +2106,22 @@ void ScDPDataMember::FillDataRow(

    ScDPSubTotalState aLocalSubState(rSubState);        // keep row state, modify column

    long nMemberMeasure = nMeasure;
    long nSubSize = pResultData->GetCountForMeasure(nMeasure);
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nSubSize = pResultData->GetCountForMeasure(nMeasure);
    if (bHasChild)
    {
        rFilterCxt.mnCol -= nSubSize * ( nUserSubCount - nUserSubStart );   // GetSize includes space for SubTotal
        rFilterCxt.mnCol -= nExtraSpace;                                    // GetSize includes the empty line
    }

    long nMoveSubTotal = 0;
    tools::Long nMoveSubTotal = 0;
    if ( bSubTotalInTitle )
    {
        nMoveSubTotal = rFilterCxt.mnCol - nStartCol;   // force to first (title) column
        rFilterCxt.mnCol = nStartCol;
    }

    for (long nUserPos=nUserSubStart; nUserPos<nUserSubCount; nUserPos++)
    for (tools::Long nUserPos=nUserSubStart; nUserPos<nUserSubCount; nUserPos++)
    {
        if ( pChildDimension && nUserSubCount > 1 )
        {
@@ -2130,7 +2130,7 @@ void ScDPDataMember::FillDataRow(
            aLocalSubState.eColForce = lcl_GetForceFunc( pForceLevel, nUserPos );
        }

        for ( long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
        for ( tools::Long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
        {
            if ( nMeasure == SC_DPMEASURE_ALL )
                nMemberMeasure = nSubCount;
@@ -2167,7 +2167,7 @@ void ScDPDataMember::FillDataRow(
}

void ScDPDataMember::UpdateDataRow(
    const ScDPResultMember* pRefMember, long nMeasure, bool bIsSubTotalRow,
    const ScDPResultMember* pRefMember, tools::Long nMeasure, bool bIsSubTotalRow,
    const ScDPSubTotalState& rSubState )
{
    OSL_ENSURE( pRefMember == pResultMember || !pResultMember, "bla" );
@@ -2181,7 +2181,7 @@ void ScDPDataMember::UpdateDataRow(
    bool bHasChild = ( pRefChild != nullptr );

    // process subtotals even if not shown
    long nUserSubCount = pRefMember->GetSubTotalCount();
    tools::Long nUserSubCount = pRefMember->GetSubTotalCount();

    // Calculate at least automatic if no subtotals are selected,
    // show only own values if there's no child dimension (innermost).
@@ -2190,10 +2190,10 @@ void ScDPDataMember::UpdateDataRow(

    ScDPSubTotalState aLocalSubState(rSubState);        // keep row state, modify column

    long nMemberMeasure = nMeasure;
    long nSubSize = pResultData->GetCountForMeasure(nMeasure);
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nSubSize = pResultData->GetCountForMeasure(nMeasure);

    for (long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
    for (tools::Long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
    {
        if ( pChildDimension && nUserSubCount > 1 )
        {
@@ -2202,7 +2202,7 @@ void ScDPDataMember::UpdateDataRow(
            aLocalSubState.eColForce = lcl_GetForceFunc( pForceLevel, nUserPos );
        }

        for ( long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
        for ( tools::Long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
        {
            if ( nMeasure == SC_DPMEASURE_ALL )
                nMemberMeasure = nSubCount;
@@ -2275,7 +2275,7 @@ void ScDPDataMember::ResetResults()
}

void ScDPDataMember::UpdateRunningTotals(
    const ScDPResultMember* pRefMember, long nMeasure, bool bIsSubTotalRow,
    const ScDPResultMember* pRefMember, tools::Long nMeasure, bool bIsSubTotalRow,
    const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
    ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent )
{
@@ -2290,7 +2290,7 @@ void ScDPDataMember::UpdateRunningTotals(
    //  (pDataChild is null then, this happens when no values for it are in this row)
    bool bHasChild = ( pRefChild != nullptr );

    long nUserSubCount = pRefMember->GetSubTotalCount();
    tools::Long nUserSubCount = pRefMember->GetSubTotalCount();
    {
        // Calculate at least automatic if no subtotals are selected,
        // show only own values if there's no child dimension (innermost).
@@ -2299,10 +2299,10 @@ void ScDPDataMember::UpdateRunningTotals(

        ScDPSubTotalState aLocalSubState(rSubState);        // keep row state, modify column

        long nMemberMeasure = nMeasure;
        long nSubSize = pResultData->GetCountForMeasure(nMeasure);
        tools::Long nMemberMeasure = nMeasure;
        tools::Long nSubSize = pResultData->GetCountForMeasure(nMeasure);

        for (long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
        for (tools::Long nUserPos=0; nUserPos<nUserSubCount; nUserPos++)   // including hidden "automatic"
        {
            if ( pChildDimension && nUserSubCount > 1 )
            {
@@ -2311,7 +2311,7 @@ void ScDPDataMember::UpdateRunningTotals(
                aLocalSubState.eColForce = lcl_GetForceFunc( pForceLevel, nUserPos );
            }

            for ( long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
            for ( tools::Long nSubCount=0; nSubCount<nSubSize; nSubCount++ )
            {
                if ( nMeasure == SC_DPMEASURE_ALL )
                    nMemberMeasure = nSubCount;
@@ -2332,7 +2332,7 @@ void ScDPDataMember::UpdateRunningTotals(
                        bool bRunningTotal = ( eRefType == sheet::DataPilotFieldReferenceType::RUNNING_TOTAL );
                        bool bRelative =
                            ( aReferenceValue.ReferenceItemType != sheet::DataPilotFieldReferenceItemType::NAMED && !bRunningTotal );
                        long nRelativeDir = bRelative ?
                        tools::Long nRelativeDir = bRelative ?
                            ( ( aReferenceValue.ReferenceItemType == sheet::DataPilotFieldReferenceItemType::PREVIOUS ) ? -1 : 1 ) : 0;

                        const ScDPRunningTotalState::IndexArray& rColVisible = rRunning.GetColVisible();
@@ -2348,8 +2348,8 @@ void ScDPDataMember::UpdateRunningTotals(
                        bool bRefDimInRow = ( nRefOrient == sheet::DataPilotFieldOrientation_ROW );

                        ScDPResultDimension* pSelectDim = nullptr;
                        long nRowPos = 0;
                        long nColPos = 0;
                        tools::Long nRowPos = 0;
                        tools::Long nColPos = 0;

                        //  find the reference field in column or row dimensions

@@ -2358,7 +2358,7 @@ void ScDPDataMember::UpdateRunningTotals(
                            pSelectDim = rRunning.GetRowResRoot()->GetChildDimension();
                            while ( pSelectDim && pSelectDim->GetName() != aRefFieldName )
                            {
                                long nIndex = rRowSorted[nRowPos];
                                tools::Long nIndex = rRowSorted[nRowPos];
                                if ( nIndex >= 0 && nIndex < pSelectDim->GetMemberCount() )
                                    pSelectDim = pSelectDim->GetMember(nIndex)->GetChildDimension();
                                else
@@ -2375,7 +2375,7 @@ void ScDPDataMember::UpdateRunningTotals(
                            pSelectDim = rRunning.GetColResRoot()->GetChildDimension();
                            while ( pSelectDim && pSelectDim->GetName() != aRefFieldName )
                            {
                                long nIndex = rColSorted[nColPos];
                                tools::Long nIndex = rColSorted[nColPos];
                                if ( nIndex >= 0 && nIndex < pSelectDim->GetMemberCount() )
                                    pSelectDim = pSelectDim->GetMember(nIndex)->GetChildDimension();
                                else
@@ -2395,7 +2395,7 @@ void ScDPDataMember::UpdateRunningTotals(
                            //  don't show or sum up the value. Otherwise, for following members,
                            //  the running totals of details and subtotals wouldn't match.

                            long nMyIndex = bRefDimInCol ? rColSorted[nColPos] : rRowSorted[nRowPos];
                            tools::Long nMyIndex = bRefDimInCol ? rColSorted[nColPos] : rRowSorted[nRowPos];
                            if ( nMyIndex >= 0 && nMyIndex < pSelectDim->GetMemberCount() )
                            {
                                const ScDPResultMember* pMyRefMember = pSelectDim->GetMember(nMyIndex);
@@ -2447,8 +2447,8 @@ void ScDPDataMember::UpdateRunningTotals(
                                                                    nColPos, rRunning );
                                else
                                {
                                    const long* pRowSorted = rRowSorted.data();
                                    const long* pColSorted = rColSorted.data();
                                    const tools::Long* pRowSorted = rRowSorted.data();
                                    const tools::Long* pColSorted = rColSorted.data();
                                    pRowSorted += nRowPos + 1; // including the reference dimension
                                    pSelectMember = pSelectDim->GetRowReferenceMember(
                                        nullptr, nullptr, pRowSorted, pColSorted);
@@ -2506,8 +2506,8 @@ void ScDPDataMember::UpdateRunningTotals(
                                else
                                {
                                    aRefItemPos.nBasePos = rRowVisible[nRowPos];    // without sort order applied
                                    const long* pRowSorted = rRowSorted.data();
                                    const long* pColSorted = rColSorted.data();
                                    const tools::Long* pRowSorted = rRowSorted.data();
                                    const tools::Long* pColSorted = rColSorted.data();
                                    pRowSorted += nRowPos + 1; // including the reference dimension
                                    pSelectMember = pSelectDim->GetRowReferenceMember(
                                        pRefPos, pRefName, pRowSorted, pColSorted);
@@ -2685,12 +2685,12 @@ class ScDPGroupCompare
private:
    const ScDPResultData* pResultData;
    const ScDPInitState& rInitState;
    long                 nDimSource;
    tools::Long                 nDimSource;
    bool                 bIncludeAll;
    bool                 bIsBase;
    long                 nGroupBase;
    tools::Long                 nGroupBase;
public:
            ScDPGroupCompare( const ScDPResultData* pData, const ScDPInitState& rState, long nDimension );
            ScDPGroupCompare( const ScDPResultData* pData, const ScDPInitState& rState, tools::Long nDimension );

    bool    IsIncluded( const ScDPMember& rMember )     { return bIncludeAll || TestIncluded( rMember ); }
    bool    TestIncluded( const ScDPMember& rMember );
@@ -2698,7 +2698,7 @@ public:

}

ScDPGroupCompare::ScDPGroupCompare( const ScDPResultData* pData, const ScDPInitState& rState, long nDimension ) :
ScDPGroupCompare::ScDPGroupCompare( const ScDPResultData* pData, const ScDPInitState& rState, tools::Long nDimension ) :
    pResultData( pData ),
    rInitState( rState ),
    nDimSource( nDimension )
@@ -2831,15 +2831,15 @@ void ScDPResultDimension::InitFrom(
    // global order is used to initialize aMembers, so it doesn't have to be looked at later
    const ScMemberSortOrder& rGlobalOrder = pThisLevel->GetGlobalOrder();

    long nDimSource = pThisDim->GetDimension();     //TODO: check GetSourceDim?
    tools::Long nDimSource = pThisDim->GetDimension();     //TODO: check GetSourceDim?
    ScDPGroupCompare aCompare( pResultData, rInitState, nDimSource );

    // Now, go through all members and initialize them.
    ScDPMembers* pMembers = pThisLevel->GetMembersObject();
    long nMembCount = pMembers->getCount();
    for ( long i=0; i<nMembCount; i++ )
    tools::Long nMembCount = pMembers->getCount();
    for ( tools::Long i=0; i<nMembCount; i++ )
    {
        long nSorted = rGlobalOrder.empty() ? i : rGlobalOrder[i];
        tools::Long nSorted = rGlobalOrder.empty() ? i : rGlobalOrder[i];

        ScDPMember* pMember = pMembers->getByIndex(nSorted);
        if ( aCompare.IsIncluded( *pMember ) )
@@ -2872,7 +2872,7 @@ void ScDPResultDimension::LateInitFrom(
    if (!pThisDim || !pThisLevel)
        return;

    long nDimSource = pThisDim->GetDimension();     //TODO: check GetSourceDim?
    tools::Long nDimSource = pThisDim->GetDimension();     //TODO: check GetSourceDim?

    bool bShowEmpty = pThisLevel->getShowEmpty();

@@ -2923,10 +2923,10 @@ void ScDPResultDimension::LateInitFrom(

            ScDPGroupCompare aCompare( pResultData, rInitState, nDimSource );
            ScDPMembers* pMembers = pThisLevel->GetMembersObject();
            long nMembCount = pMembers->getCount();
            for ( long i=0; i<nMembCount; i++ )
            tools::Long nMembCount = pMembers->getCount();
            for ( tools::Long i=0; i<nMembCount; i++ )
            {
                long nSorted = rGlobalOrder.empty() ? i : rGlobalOrder[i];
                tools::Long nSorted = rGlobalOrder.empty() ? i : rGlobalOrder[i];

                ScDPMember* pMember = pMembers->getByIndex(nSorted);
                if ( aCompare.IsIncluded( *pMember ) )
@@ -2940,8 +2940,8 @@ void ScDPResultDimension::LateInitFrom(
        //  initialize only specific member (or all if "show empty" flag is set)
        if ( bLateInitAllMembers  )
        {
            long nCount = maMemberArray.size();
            for (long i=0; i<nCount; i++)
            tools::Long nCount = maMemberArray.size();
            for (tools::Long i=0; i<nCount; i++)
            {
                ScDPResultMember* pResultMember = maMemberArray[i].get();

@@ -2972,10 +2972,10 @@ void ScDPResultDimension::LateInitFrom(
        InitWithMembers( rParams, pItemData, nPos, rInitState );
}

long ScDPResultDimension::GetSize(long nMeasure) const
tools::Long ScDPResultDimension::GetSize(tools::Long nMeasure) const
{
    long nTotal = 0;
    long nMemberCount = maMemberArray.size();
    tools::Long nTotal = 0;
    tools::Long nMemberCount = maMemberArray.size();
    if (bIsDataLayout)
    {
        OSL_ENSURE(nMeasure == SC_DPMEASURE_ALL || pResultData->GetMeasureCount() == 1,
@@ -2986,7 +2986,7 @@ long ScDPResultDimension::GetSize(long nMeasure) const
    else
    {
        //  add all members
        for (long nMem=0; nMem<nMemberCount; nMem++)
        for (tools::Long nMem=0; nMem<nMemberCount; nMem++)
            nTotal += maMemberArray[nMem]->GetSize(nMeasure);
    }
    return nTotal;
@@ -3031,14 +3031,14 @@ void ScDPResultDimension::ProcessData( const vector< SCROW >& aMembers,
}

void ScDPResultDimension::FillMemberResults( uno::Sequence<sheet::MemberResult>* pSequences,
                                                long nStart, long nMeasure )
                                                tools::Long nStart, tools::Long nMeasure )
{
    long nPos = nStart;
    long nCount = maMemberArray.size();
    tools::Long nPos = nStart;
    tools::Long nCount = maMemberArray.size();

    for (long i=0; i<nCount; i++)
    for (tools::Long i=0; i<nCount; i++)
    {
        long nSorted = aMemberOrder.empty() ? i : aMemberOrder[i];
        tools::Long nSorted = aMemberOrder.empty() ? i : aMemberOrder[i];

        ScDPResultMember* pMember = maMemberArray[nSorted].get();
        //  in data layout dimension, use first member with different measures/names
@@ -3059,16 +3059,16 @@ void ScDPResultDimension::FillMemberResults( uno::Sequence<sheet::MemberResult>*

void ScDPResultDimension::FillDataResults(
    const ScDPResultMember* pRefMember, ScDPResultFilterContext& rFilterCxt,
    uno::Sequence< uno::Sequence<sheet::DataResult> >& rSequence, long nMeasure) const
    uno::Sequence< uno::Sequence<sheet::DataResult> >& rSequence, tools::Long nMeasure) const
{
    FilterStack aFilterStack(rFilterCxt.maFilters);
    aFilterStack.pushDimName(GetName(), bIsDataLayout);

    long nMemberMeasure = nMeasure;
    long nCount = maMemberArray.size();
    for (long i=0; i<nCount; i++)
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nCount = maMemberArray.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        long nSorted = aMemberOrder.empty() ? i : aMemberOrder[i];
        tools::Long nSorted = aMemberOrder.empty() ? i : aMemberOrder[i];

        const ScDPResultMember* pMember;
        if (bIsDataLayout)
@@ -3086,11 +3086,11 @@ void ScDPResultDimension::FillDataResults(
    }
}

void ScDPResultDimension::UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const
void ScDPResultDimension::UpdateDataResults( const ScDPResultMember* pRefMember, tools::Long nMeasure ) const
{
    long nMemberMeasure = nMeasure;
    long nCount = maMemberArray.size();
    for (long i=0; i<nCount; i++)
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nCount = maMemberArray.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        const ScDPResultMember* pMember;
        if (bIsDataLayout)
@@ -3110,7 +3110,7 @@ void ScDPResultDimension::UpdateDataResults( const ScDPResultMember* pRefMember,

void ScDPResultDimension::SortMembers( ScDPResultMember* pRefMember )
{
    long nCount = maMemberArray.size();
    tools::Long nCount = maMemberArray.size();

    if ( bSortByData )
    {
@@ -3118,7 +3118,7 @@ void ScDPResultDimension::SortMembers( ScDPResultMember* pRefMember )

        OSL_ENSURE( aMemberOrder.empty(), "sort twice?" );
        aMemberOrder.resize( nCount );
        for (long nPos=0; nPos<nCount; nPos++)
        for (tools::Long nPos=0; nPos<nCount; nPos++)
            aMemberOrder[nPos] = nPos;

        ScDPRowMembersOrder aComp( *this, nSortMeasure, bSortAscending );
@@ -3128,8 +3128,8 @@ void ScDPResultDimension::SortMembers( ScDPResultMember* pRefMember )
    // handle children

    // for data layout, call only once - sorting measure is always taken from settings
    long nLoopCount = bIsDataLayout ? 1 : nCount;
    for (long i=0; i<nLoopCount; i++)
    tools::Long nLoopCount = bIsDataLayout ? 1 : nCount;
    for (tools::Long i=0; i<nLoopCount; i++)
    {
        ScDPResultMember* pMember = maMemberArray[i].get();
        if ( pMember->IsVisible() )
@@ -3139,13 +3139,13 @@ void ScDPResultDimension::SortMembers( ScDPResultMember* pRefMember )

void ScDPResultDimension::DoAutoShow( ScDPResultMember* pRefMember )
{
    long nCount = maMemberArray.size();
    tools::Long nCount = maMemberArray.size();

    // handle children first, before changing the visible state

    // for data layout, call only once - sorting measure is always taken from settings
    long nLoopCount = bIsDataLayout ? 1 : nCount;
    for (long i=0; i<nLoopCount; i++)
    tools::Long nLoopCount = bIsDataLayout ? 1 : nCount;
    for (tools::Long i=0; i<nLoopCount; i++)
    {
        ScDPResultMember* pMember = maMemberArray[i].get();
        if ( pMember->IsVisible() )
@@ -3159,7 +3159,7 @@ void ScDPResultDimension::DoAutoShow( ScDPResultMember* pRefMember )

    ScMemberSortOrder aAutoOrder;
    aAutoOrder.resize( nCount );
    long nPos;
    tools::Long nPos;
    for (nPos=0; nPos<nCount; nPos++)
        aAutoOrder[nPos] = nPos;

@@ -3168,7 +3168,7 @@ void ScDPResultDimension::DoAutoShow( ScDPResultMember* pRefMember )

    // look for equal values to the last included one

    long nIncluded = nAutoCount;
    tools::Long nIncluded = nAutoCount;
    const ScDPResultMember* pMember1 = maMemberArray[aAutoOrder[nIncluded - 1]].get();
    const ScDPDataMember* pDataMember1 = pMember1->IsVisible() ? pMember1->GetDataRoot() : nullptr;
    bool bContinue = true;
@@ -3199,8 +3199,8 @@ void ScDPResultDimension::DoAutoShow( ScDPResultMember* pRefMember )

void ScDPResultDimension::ResetResults()
{
    long nCount = maMemberArray.size();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = maMemberArray.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        // sort order doesn't matter
        ScDPResultMember* pMember = maMemberArray[bIsDataLayout ? 0 : i].get();
@@ -3208,20 +3208,20 @@ void ScDPResultDimension::ResetResults()
    }
}

long ScDPResultDimension::GetSortedIndex( long nUnsorted ) const
tools::Long ScDPResultDimension::GetSortedIndex( tools::Long nUnsorted ) const
{
    return aMemberOrder.empty() ? nUnsorted : aMemberOrder[nUnsorted];
}

void ScDPResultDimension::UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
void ScDPResultDimension::UpdateRunningTotals( const ScDPResultMember* pRefMember, tools::Long nMeasure,
                                                ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const
{
    const ScDPResultMember* pMember;
    long nMemberMeasure = nMeasure;
    long nCount = maMemberArray.size();
    for (long i=0; i<nCount; i++)
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nCount = maMemberArray.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        long nSorted = aMemberOrder.empty() ? i : aMemberOrder[i];
        tools::Long nSorted = aMemberOrder.empty() ? i : aMemberOrder[i];

        if (bIsDataLayout)
        {
@@ -3247,7 +3247,7 @@ void ScDPResultDimension::UpdateRunningTotals( const ScDPResultMember* pRefMembe

ScDPDataMember* ScDPResultDimension::GetRowReferenceMember(
    const ScDPRelativePos* pRelativePos, const OUString* pName,
    const long* pRowIndexes, const long* pColIndexes ) const
    const tools::Long* pRowIndexes, const tools::Long* pColIndexes ) const
{
    // get named, previous/next, or first member of this dimension (first existing if pRelativePos and pName are NULL)

@@ -3256,9 +3256,9 @@ ScDPDataMember* ScDPResultDimension::GetRowReferenceMember(
    ScDPDataMember* pColMember = nullptr;

    bool bFirstExisting = ( pRelativePos == nullptr && pName == nullptr );
    long nMemberCount = maMemberArray.size();
    long nMemberIndex = 0;      // unsorted
    long nDirection = 1;        // forward if no relative position is used
    tools::Long nMemberCount = maMemberArray.size();
    tools::Long nMemberIndex = 0;      // unsorted
    tools::Long nDirection = 1;        // forward if no relative position is used
    if ( pRelativePos )
    {
        nDirection = pRelativePos->nDirection;
@@ -3290,7 +3290,7 @@ ScDPDataMember* ScDPResultDimension::GetRowReferenceMember(

        // get child members by given indexes

        const long* pNextRowIndex = pRowIndexes;
        const tools::Long* pNextRowIndex = pRowIndexes;
        while ( *pNextRowIndex >= 0 && pRowMember )
        {
            const ScDPResultDimension* pRowChild = pRowMember->GetChildDimension();
@@ -3315,7 +3315,7 @@ ScDPDataMember* ScDPResultDimension::GetRowReferenceMember(
        {
            pColMember = pRowMember->GetDataRoot();

            const long* pNextColIndex = pColIndexes;
            const tools::Long* pNextColIndex = pColIndexes;
            while ( *pNextColIndex >= 0 && pColMember )
            {
                ScDPDataDimension* pColChild = pColMember->GetChildDimension();
@@ -3337,19 +3337,19 @@ ScDPDataMember* ScDPResultDimension::GetRowReferenceMember(

ScDPDataMember* ScDPResultDimension::GetColReferenceMember(
    const ScDPRelativePos* pRelativePos, const OUString* pName,
    long nRefDimPos, const ScDPRunningTotalState& rRunning )
    tools::Long nRefDimPos, const ScDPRunningTotalState& rRunning )
{
    OSL_ENSURE( pRelativePos == nullptr || pName == nullptr, "can't use position and name" );

    const long* pColIndexes = rRunning.GetColSorted().data();
    const long* pRowIndexes = rRunning.GetRowSorted().data();
    const tools::Long* pColIndexes = rRunning.GetColSorted().data();
    const tools::Long* pRowIndexes = rRunning.GetRowSorted().data();

    // get own row member using all indexes

    const ScDPResultMember* pRowMember = rRunning.GetRowResRoot();
    ScDPDataMember* pColMember = nullptr;

    const long* pNextRowIndex = pRowIndexes;
    const tools::Long* pNextRowIndex = pRowIndexes;
    while ( *pNextRowIndex >= 0 && pRowMember )
    {
        const ScDPResultDimension* pRowChild = pRowMember->GetChildDimension();
@@ -3367,8 +3367,8 @@ ScDPDataMember* ScDPResultDimension::GetColReferenceMember(
    {
        pColMember = pRowMember->GetDataRoot();

        const long* pNextColIndex = pColIndexes;
        long nColSkipped = 0;
        const tools::Long* pNextColIndex = pColIndexes;
        tools::Long nColSkipped = 0;
        while ( *pNextColIndex >= 0 && pColMember && nColSkipped < nRefDimPos )
        {
            ScDPDataDimension* pColChild = pColMember->GetChildDimension();
@@ -3388,11 +3388,11 @@ ScDPDataMember* ScDPResultDimension::GetColReferenceMember(
        ScDPDataDimension* pReferenceDim = pColMember->GetChildDimension();
        if ( pReferenceDim )
        {
            long nReferenceCount = pReferenceDim->GetMemberCount();
            tools::Long nReferenceCount = pReferenceDim->GetMemberCount();

            bool bFirstExisting = ( pRelativePos == nullptr && pName == nullptr );
            long nMemberIndex = 0;      // unsorted
            long nDirection = 1;        // forward if no relative position is used
            tools::Long nMemberIndex = 0;      // unsorted
            tools::Long nDirection = 1;        // forward if no relative position is used
            pColMember = nullptr;          // don't use parent dimension's member if none found
            if ( pRelativePos )
            {
@@ -3423,7 +3423,7 @@ ScDPDataMember* ScDPResultDimension::GetColReferenceMember(

                // get column members below the reference field

                const long* pNextColIndex = pColIndexes + nRefDimPos + 1;
                const tools::Long* pNextColIndex = pColIndexes + nRefDimPos + 1;
                while ( *pNextColIndex >= 0 && pColMember )
                {
                    ScDPDataDimension* pColChild = pColMember->GetChildDimension();
@@ -3464,8 +3464,8 @@ void ScDPResultDimension::DumpState( const ScDPResultMember* pRefMember, ScDocum

    SCROW nStartRow = rPos.Row();

    long nCount = bIsDataLayout ? 1 : maMemberArray.size();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = bIsDataLayout ? 1 : maMemberArray.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        const ScDPResultMember* pMember = maMemberArray[i].get();
        pMember->DumpState( pRefMember, pDoc, rPos );
@@ -3486,16 +3486,16 @@ void ScDPResultDimension::Dump(int nIndent) const
}
#endif

long ScDPResultDimension::GetMemberCount() const
tools::Long ScDPResultDimension::GetMemberCount() const
{
    return maMemberArray.size();
}

const ScDPResultMember* ScDPResultDimension::GetMember(long n) const
const ScDPResultMember* ScDPResultDimension::GetMember(tools::Long n) const
{
    return maMemberArray[n].get();
}
ScDPResultMember* ScDPResultDimension::GetMember(long n)
ScDPResultMember* ScDPResultDimension::GetMember(tools::Long n)
{
    return maMemberArray[n].get();
}
@@ -3546,8 +3546,8 @@ void ScDPDataDimension::InitFrom( const ScDPResultDimension* pDim )

    // Go through all result members under the given result dimension, and
    // create a new data member instance for each result member.
    long nCount = pDim->GetMemberCount();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = pDim->GetMemberCount();
    for (tools::Long i=0; i<nCount; i++)
    {
        const ScDPResultMember* pResMem = pDim->GetMember(i);

@@ -3571,8 +3571,8 @@ void ScDPDataDimension::ProcessData( const vector< SCROW >& aDataMembers, const 
{
    // the ScDPItemData array must contain enough entries for all dimensions - this isn't checked

    long nCount = maMembers.size();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = maMembers.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        ScDPDataMember* pMember = maMembers[static_cast<sal_uInt16>(i)].get();

@@ -3595,7 +3595,7 @@ void ScDPDataDimension::ProcessData( const vector< SCROW >& aDataMembers, const 

void ScDPDataDimension::FillDataRow(
    const ScDPResultDimension* pRefDim, ScDPResultFilterContext& rFilterCxt,
    uno::Sequence<sheet::DataResult>& rSequence, long nMeasure, bool bIsSubTotalRow,
    uno::Sequence<sheet::DataResult>& rSequence, tools::Long nMeasure, bool bIsSubTotalRow,
    const ScDPSubTotalState& rSubState) const
{
    OUString aDimName;
@@ -3614,13 +3614,13 @@ void ScDPDataDimension::FillDataRow(

    const ScMemberSortOrder& rMemberOrder = pRefDim->GetMemberOrder();

    long nMemberMeasure = nMeasure;
    long nCount = maMembers.size();
    for (long i=0; i<nCount; i++)
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nCount = maMembers.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        long nSorted = rMemberOrder.empty() ? i : rMemberOrder[i];
        tools::Long nSorted = rMemberOrder.empty() ? i : rMemberOrder[i];

        long nMemberPos = nSorted;
        tools::Long nMemberPos = nSorted;
        if (bIsDataLayout)
        {
            OSL_ENSURE(nMeasure == SC_DPMEASURE_ALL || pResultData->GetMeasureCount() == 1,
@@ -3639,17 +3639,17 @@ void ScDPDataDimension::FillDataRow(
}

void ScDPDataDimension::UpdateDataRow( const ScDPResultDimension* pRefDim,
                                    long nMeasure, bool bIsSubTotalRow,
                                    tools::Long nMeasure, bool bIsSubTotalRow,
                                    const ScDPSubTotalState& rSubState ) const
{
    OSL_ENSURE( pRefDim && static_cast<size_t>(pRefDim->GetMemberCount()) == maMembers.size(), "dimensions don't match" );
    OSL_ENSURE( pRefDim == pResultDimension, "wrong dim" );

    long nMemberMeasure = nMeasure;
    long nCount = maMembers.size();
    for (long i=0; i<nCount; i++)
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nCount = maMembers.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        long nMemberPos = i;
        tools::Long nMemberPos = i;
        if (bIsDataLayout)
        {
            OSL_ENSURE(nMeasure == SC_DPMEASURE_ALL || pResultData->GetMeasureCount() == 1,
@@ -3667,7 +3667,7 @@ void ScDPDataDimension::UpdateDataRow( const ScDPResultDimension* pRefDim,

void ScDPDataDimension::SortMembers( ScDPResultDimension* pRefDim )
{
    long nCount = maMembers.size();
    tools::Long nCount = maMembers.size();

    if ( pRefDim->IsSortByData() )
    {
@@ -3676,7 +3676,7 @@ void ScDPDataDimension::SortMembers( ScDPResultDimension* pRefDim )
        ScMemberSortOrder& rMemberOrder = pRefDim->GetMemberOrder();
        OSL_ENSURE( rMemberOrder.empty(), "sort twice?" );
        rMemberOrder.resize( nCount );
        for (long nPos=0; nPos<nCount; nPos++)
        for (tools::Long nPos=0; nPos<nCount; nPos++)
            rMemberOrder[nPos] = nPos;

        ScDPColMembersOrder aComp( *this, pRefDim->GetSortMeasure(), pRefDim->IsSortAscending() );
@@ -3689,8 +3689,8 @@ void ScDPDataDimension::SortMembers( ScDPResultDimension* pRefDim )
    OSL_ENSURE( pRefDim == pResultDimension, "wrong dim" );

    // for data layout, call only once - sorting measure is always taken from settings
    long nLoopCount = bIsDataLayout ? 1 : nCount;
    for (long i=0; i<nLoopCount; i++)
    tools::Long nLoopCount = bIsDataLayout ? 1 : nCount;
    for (tools::Long i=0; i<nLoopCount; i++)
    {
        ScDPResultMember* pRefMember = pRefDim->GetMember(i);
        if ( pRefMember->IsVisible() )  //TODO: here or in ScDPDataMember ???
@@ -3703,7 +3703,7 @@ void ScDPDataDimension::SortMembers( ScDPResultDimension* pRefDim )

void ScDPDataDimension::DoAutoShow( ScDPResultDimension* pRefDim )
{
    long nCount = maMembers.size();
    tools::Long nCount = maMembers.size();

    // handle children first, before changing the visible state

@@ -3711,8 +3711,8 @@ void ScDPDataDimension::DoAutoShow( ScDPResultDimension* pRefDim )
    OSL_ENSURE( pRefDim == pResultDimension, "wrong dim" );

    // for data layout, call only once - sorting measure is always taken from settings
    long nLoopCount = bIsDataLayout ? 1 : nCount;
    for (long i=0; i<nLoopCount; i++)
    tools::Long nLoopCount = bIsDataLayout ? 1 : nCount;
    for (tools::Long i=0; i<nLoopCount; i++)
    {
        ScDPResultMember* pRefMember = pRefDim->GetMember(i);
        if ( pRefMember->IsVisible() )  //TODO: here or in ScDPDataMember ???
@@ -3729,7 +3729,7 @@ void ScDPDataDimension::DoAutoShow( ScDPResultDimension* pRefDim )

    ScMemberSortOrder aAutoOrder;
    aAutoOrder.resize( nCount );
    long nPos;
    tools::Long nPos;
    for (nPos=0; nPos<nCount; nPos++)
        aAutoOrder[nPos] = nPos;

@@ -3738,7 +3738,7 @@ void ScDPDataDimension::DoAutoShow( ScDPResultDimension* pRefDim )

    // look for equal values to the last included one

    long nIncluded = pRefDim->GetAutoCount();
    tools::Long nIncluded = pRefDim->GetAutoCount();
    ScDPDataMember* pDataMember1 = maMembers[aAutoOrder[nIncluded - 1]].get();
    if ( !pDataMember1->IsVisible() )
        pDataMember1 = nullptr;
@@ -3771,18 +3771,18 @@ void ScDPDataDimension::DoAutoShow( ScDPResultDimension* pRefDim )

void ScDPDataDimension::ResetResults()
{
    long nCount = maMembers.size();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = maMembers.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        //  sort order doesn't matter

        long nMemberPos = bIsDataLayout ? 0 : i;
        tools::Long nMemberPos = bIsDataLayout ? 0 : i;
        ScDPDataMember* pDataMember = maMembers[nMemberPos].get();
        pDataMember->ResetResults();
    }
}

long ScDPDataDimension::GetSortedIndex( long nUnsorted ) const
tools::Long ScDPDataDimension::GetSortedIndex( tools::Long nUnsorted ) const
{
    if (!pResultDimension)
       return nUnsorted;
@@ -3792,21 +3792,21 @@ long ScDPDataDimension::GetSortedIndex( long nUnsorted ) const
}

void ScDPDataDimension::UpdateRunningTotals( const ScDPResultDimension* pRefDim,
                                    long nMeasure, bool bIsSubTotalRow,
                                    tools::Long nMeasure, bool bIsSubTotalRow,
                                    const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
                                    ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent ) const
{
    OSL_ENSURE( pRefDim && static_cast<size_t>(pRefDim->GetMemberCount()) == maMembers.size(), "dimensions don't match" );
    OSL_ENSURE( pRefDim == pResultDimension, "wrong dim" );

    long nMemberMeasure = nMeasure;
    long nCount = maMembers.size();
    for (long i=0; i<nCount; i++)
    tools::Long nMemberMeasure = nMeasure;
    tools::Long nCount = maMembers.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        const ScMemberSortOrder& rMemberOrder = pRefDim->GetMemberOrder();
        long nSorted = rMemberOrder.empty() ? i : rMemberOrder[i];
        tools::Long nSorted = rMemberOrder.empty() ? i : rMemberOrder[i];

        long nMemberPos = nSorted;
        tools::Long nMemberPos = nSorted;
        if (bIsDataLayout)
        {
            OSL_ENSURE(nMeasure == SC_DPMEASURE_ALL || pResultData->GetMeasureCount() == 1,
@@ -3840,8 +3840,8 @@ void ScDPDataDimension::DumpState( const ScDPResultDimension* pRefDim, ScDocumen

    SCROW nStartRow = rPos.Row();

    long nCount = bIsDataLayout ? 1 : maMembers.size();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = bIsDataLayout ? 1 : maMembers.size();
    for (tools::Long i=0; i<nCount; i++)
    {
        const ScDPResultMember* pRefMember = pRefDim->GetMember(i);
        const ScDPDataMember* pDataMember = maMembers[i].get();
@@ -3861,17 +3861,17 @@ void ScDPDataDimension::Dump(int nIndent) const
}
#endif

long ScDPDataDimension::GetMemberCount() const
tools::Long ScDPDataDimension::GetMemberCount() const
{
    return maMembers.size();
}

const ScDPDataMember* ScDPDataDimension::GetMember(long n) const
const ScDPDataMember* ScDPDataDimension::GetMember(tools::Long n) const
{
    return maMembers[n].get();
}

ScDPDataMember* ScDPDataDimension::GetMember(long n)
ScDPDataMember* ScDPDataDimension::GetMember(tools::Long n)
{
    return maMembers[n].get();
}
@@ -3909,8 +3909,8 @@ void ScDPResultVisibilityData::fillFieldFilters(vector<ScDPFilteredCache::Criter
    typedef std::unordered_map<OUString, long> FieldNameMapType;
    FieldNameMapType aFieldNames;
    ScDPTableData* pData = mpSource->GetData();
    long nColumnCount = pData->GetColumnCount();
    for (long i = 0; i < nColumnCount; ++i)
    tools::Long nColumnCount = pData->GetColumnCount();
    for (tools::Long i = 0; i < nColumnCount; ++i)
    {
        aFieldNames.emplace(pData->getDimensionName(i), i);
    }
@@ -3924,7 +3924,7 @@ void ScDPResultVisibilityData::fillFieldFilters(vector<ScDPFilteredCache::Criter
            // This should never happen!
            continue;

        long nDimIndex = itrField->second;
        tools::Long nDimIndex = itrField->second;
        aCri.mnFieldIndex = static_cast<sal_Int32>(nDimIndex);
        aCri.mpFilter = std::make_shared<ScDPFilteredCache::GroupFilter>();

@@ -3997,7 +3997,7 @@ void ScDPResultDimension::InitWithMembers(
    if (!(pThisDim && pThisLevel))
        return;

    long nDimSource = pThisDim->GetDimension();     //TODO: check GetSourceDim?
    tools::Long nDimSource = pThisDim->GetDimension();     //TODO: check GetSourceDim?

    //  create all members at the first call (preserve order)
    ResultMembers& rMembers = pResultData->GetDimResultMembers(nDimSource, pThisDim, pThisLevel);
@@ -4075,9 +4075,9 @@ bool LateInitParams::IsEnd( size_t nPos ) const

void ScDPResultDimension::CheckShowEmpty( bool bShow )
{
    long nCount = maMemberArray.size();
    tools::Long nCount = maMemberArray.size();

    for (long i=0; i<nCount; i++)
    for (tools::Long i=0; i<nCount; i++)
    {
        ScDPResultMember* pMember = maMemberArray.at(i).get();
        pMember->CheckShowEmpty(bShow);
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index c7c51de..667d60a 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -123,7 +123,7 @@ const std::optional<OUString> & ScDPSource::GetGrandTotalName() const
    return mpGrandTotalName;
}

sheet::DataPilotFieldOrientation ScDPSource::GetOrientation(long nColumn)
sheet::DataPilotFieldOrientation ScDPSource::GetOrientation(tools::Long nColumn)
{
    if (std::find(maColDims.begin(), maColDims.end(), nColumn) != maColDims.end())
        return sheet::DataPilotFieldOrientation_COLUMN;
@@ -140,21 +140,21 @@ sheet::DataPilotFieldOrientation ScDPSource::GetOrientation(long nColumn)
    return sheet::DataPilotFieldOrientation_HIDDEN;
}

long ScDPSource::GetDataDimensionCount() const
tools::Long ScDPSource::GetDataDimensionCount() const
{
    return maDataDims.size();
}

ScDPDimension* ScDPSource::GetDataDimension(long nIndex)
ScDPDimension* ScDPSource::GetDataDimension(tools::Long nIndex)
{
    if (nIndex < 0 || o3tl::make_unsigned(nIndex) >= maDataDims.size())
        return nullptr;

    long nDimIndex = maDataDims[nIndex];
    tools::Long nDimIndex = maDataDims[nIndex];
    return GetDimensionsObject()->getByIndex(nDimIndex);
}

OUString ScDPSource::GetDataDimName(long nIndex)
OUString ScDPSource::GetDataDimName(tools::Long nIndex)
{
    OUString aRet;
    ScDPDimension* pDim = GetDataDimension(nIndex);
@@ -163,7 +163,7 @@ OUString ScDPSource::GetDataDimName(long nIndex)
    return aRet;
}

long ScDPSource::GetPosition(long nColumn)
tools::Long ScDPSource::GetPosition(tools::Long nColumn)
{
    std::vector<long>::const_iterator it, itBeg = maColDims.begin(), itEnd = maColDims.end();
    it = std::find(itBeg, itEnd, nColumn);
@@ -193,7 +193,7 @@ long ScDPSource::GetPosition(long nColumn)

namespace {

bool testSubTotal( bool& rAllowed, long nColumn, const std::vector<long>& rDims, ScDPSource* pSource )
bool testSubTotal( bool& rAllowed, tools::Long nColumn, const std::vector<long>& rDims, ScDPSource* pSource )
{
    rAllowed = true;
    std::vector<long>::const_iterator it = rDims.begin(), itEnd = rDims.end();
@@ -222,7 +222,7 @@ bool testSubTotal( bool& rAllowed, long nColumn, const std::vector<long>& rDims,
    return false;
}

void removeDim( long nRemove, std::vector<long>& rDims )
void removeDim( tools::Long nRemove, std::vector<long>& rDims )
{
    std::vector<long>::iterator it = std::find(rDims.begin(), rDims.end(), nRemove);
    if (it != rDims.end())
@@ -231,7 +231,7 @@ void removeDim( long nRemove, std::vector<long>& rDims )

}

bool ScDPSource::SubTotalAllowed(long nColumn)
bool ScDPSource::SubTotalAllowed(tools::Long nColumn)
{
    //TODO: cache this at ScDPResultData
    bool bAllowed = true;
@@ -242,7 +242,7 @@ bool ScDPSource::SubTotalAllowed(long nColumn)
    return bAllowed;
}

void ScDPSource::SetOrientation(long nColumn, sheet::DataPilotFieldOrientation nNew)
void ScDPSource::SetOrientation(tools::Long nColumn, sheet::DataPilotFieldOrientation nNew)
{
    //TODO: change to no-op if new orientation is equal to old?

@@ -276,7 +276,7 @@ void ScDPSource::SetOrientation(long nColumn, sheet::DataPilotFieldOrientation n
    }
}

bool ScDPSource::IsDataLayoutDimension(long nDim)
bool ScDPSource::IsDataLayoutDimension(tools::Long nDim)
{
    return nDim == pData->GetColumnCount();
}
@@ -286,7 +286,7 @@ sheet::DataPilotFieldOrientation ScDPSource::GetDataLayoutOrientation()
    return GetOrientation(pData->GetColumnCount());
}

bool ScDPSource::IsDateDimension(long nDim)
bool ScDPSource::IsDateDimension(tools::Long nDim)
{
    return pData->IsDateDimension(nDim);
}
@@ -305,7 +305,7 @@ uno::Reference<container::XNameAccess> SAL_CALL ScDPSource::getDimensions()
    return GetDimensionsObject();
}

void ScDPSource::SetDupCount( long nNew )
void ScDPSource::SetDupCount( tools::Long nNew )
{
    nDupCount = nNew;
}
@@ -316,8 +316,8 @@ ScDPDimension* ScDPSource::AddDuplicated(const OUString& rNewName)

    //  re-use

    long nOldDimCount = pDimensions->getCount();
    for (long i=0; i<nOldDimCount; i++)
    tools::Long nOldDimCount = pDimensions->getCount();
    for (tools::Long i=0; i<nOldDimCount; i++)
    {
        ScDPDimension* pDim = pDimensions->getByIndex(i);
        if (pDim && pDim->getName() == rNewName)
@@ -333,7 +333,7 @@ ScDPDimension* ScDPSource::AddDuplicated(const OUString& rNewName)
    return pDimensions->getByIndex( pDimensions->getCount() - 1 );
}

long ScDPSource::GetSourceDim(long nDim)
tools::Long ScDPSource::GetSourceDim(tools::Long nDim)
{
    //  original source dimension or data layout dimension?
    if ( nDim <= pData->GetColumnCount() )
@@ -344,7 +344,7 @@ long ScDPSource::GetSourceDim(long nDim)
        ScDPDimension* pDimObj = pDimensions->getByIndex( nDim );
        if ( pDimObj )
        {
            long nSource = pDimObj->GetSourceDim();
            tools::Long nSource = pDimObj->GetSourceDim();
            if ( nSource >= 0 )
                return nSource;
        }
@@ -364,15 +364,15 @@ uno::Sequence< uno::Sequence<sheet::DataResult> > SAL_CALL ScDPSource::getResult
        throw uno::RuntimeException();
    }

    long nColCount = pColResRoot->GetSize(pResData->GetColStartMeasure());
    long nRowCount = pRowResRoot->GetSize(pResData->GetRowStartMeasure());
    tools::Long nColCount = pColResRoot->GetSize(pResData->GetColStartMeasure());
    tools::Long nRowCount = pRowResRoot->GetSize(pResData->GetRowStartMeasure());

    //  allocate full sequence
    //TODO: leave out empty rows???

    uno::Sequence< uno::Sequence<sheet::DataResult> > aSeq( nRowCount );
    uno::Sequence<sheet::DataResult>* pRowAry = aSeq.getArray();
    for (long nRow = 0; nRow < nRowCount; nRow++)
    for (tools::Long nRow = 0; nRow < nRowCount; nRow++)
    {
        uno::Sequence<sheet::DataResult> aColSeq( nColCount );
        //  use default values of DataResult
@@ -438,13 +438,13 @@ void SAL_CALL ScDPSource::removeRefreshListener( const uno::Reference<util::XRef

Sequence< Sequence<Any> > SAL_CALL ScDPSource::getDrillDownData(const Sequence<sheet::DataPilotFieldFilter>& aFilters)
{
    long nColumnCount = GetData()->GetColumnCount();
    tools::Long nColumnCount = GetData()->GetColumnCount();

    vector<ScDPFilteredCache::Criterion> aFilterCriteria;
    for (const sheet::DataPilotFieldFilter& rFilter : aFilters)
    {
        const OUString& aFieldName = rFilter.FieldName;
        for (long nCol = 0; nCol < nColumnCount; ++nCol)
        for (tools::Long nCol = 0; nCol < nColumnCount; ++nCol)
        {
            if (aFieldName == pData->getDimensionName(nCol))
            {
@@ -535,15 +535,15 @@ void ScDPSource::disposeData()
    bResultOverflow = false;
}

static long lcl_CountMinMembers(const vector<ScDPDimension*>& ppDim, const vector<ScDPLevel*>& ppLevel, long nLevels )
static tools::Long lcl_CountMinMembers(const vector<ScDPDimension*>& ppDim, const vector<ScDPLevel*>& ppLevel, tools::Long nLevels )
{
    //  Calculate the product of the member count for those consecutive levels that
    //  have the "show all" flag, one following level, and the data layout dimension.

    long nTotal = 1;
    long nDataCount = 1;
    tools::Long nTotal = 1;
    tools::Long nDataCount = 1;
    bool bWasShowAll = true;
    long nPos = nLevels;
    tools::Long nPos = nLevels;
    while ( nPos > 0 )
    {
        --nPos;
@@ -573,7 +573,7 @@ static long lcl_CountMinMembers(const vector<ScDPDimension*>& ppDim, const vecto
        }
        if ( bDo )
        {
            long nThisCount = ppLevel[nPos]->GetMembersObject()->getMinMembers();
            tools::Long nThisCount = ppLevel[nPos]->GetMembersObject()->getMinMembers();
            if ( nThisCount == 0 )
            {
                nTotal = 1;         //  empty level -> start counting from here
@@ -602,18 +602,18 @@ void ScDPSource::FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool 
    for (const auto& rDimIndex : rDims)
    {
        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(rDimIndex);
        long nHierarchy = ScDPDimension::getUsedHierarchy();
        tools::Long nHierarchy = ScDPDimension::getUsedHierarchy();
        if ( nHierarchy >= ScDPHierarchies::getCount() )
            nHierarchy = 0;
        ScDPLevels* pLevels = pDim->GetHierarchiesObject()->getByIndex(nHierarchy)->GetLevelsObject();
        long nCount = pLevels->getCount();
        tools::Long nCount = pLevels->getCount();

        //TODO: Test
        if (pDim->getIsDataLayoutDimension() && maDataDims.size() < 2)
            nCount = 0;
        //TODO: Test

        for (long j = 0; j < nCount; ++j)
        for (tools::Long j = 0; j < nCount; ++j)
        {
            ScDPLevel* pLevel = pLevels->getByIndex(j);
            pLevel->EvaluateSortOrder();
@@ -653,7 +653,7 @@ public:
        mrSource(rSource),
        mrCatDims(rCatDims) {}

    void operator() (long nDim)
    void operator() (tools::Long nDim)
    {
        if (!mrSource.IsDataLayoutDimension(nDim))
            mrCatDims.insert(nDim);
@@ -696,18 +696,18 @@ void ScDPSource::FilterCacheByPageDimensions()
    for (const auto& rDimIndex : maPageDims)
    {
        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(rDimIndex);
        long nField = pDim->GetDimension();
        tools::Long nField = pDim->GetDimension();

        ScDPMembers* pMems = pDim->GetHierarchiesObject()->getByIndex(0)->
            GetLevelsObject()->getByIndex(0)->GetMembersObject();

        long nMemCount = pMems->getCount();
        tools::Long nMemCount = pMems->getCount();
        ScDPFilteredCache::Criterion aFilter;
        aFilter.mnFieldIndex = static_cast<sal_Int32>(nField);
        aFilter.mpFilter = std::make_shared<ScDPFilteredCache::GroupFilter>();
        ScDPFilteredCache::GroupFilter* pGrpFilter =
            static_cast<ScDPFilteredCache::GroupFilter*>(aFilter.mpFilter.get());
        for (long j = 0; j < nMemCount; ++j)
        for (tools::Long j = 0; j < nMemCount; ++j)
        {
            ScDPMember* pMem = pMems->getByIndex(j);
            if (pMem->isVisible())
@@ -769,7 +769,7 @@ void ScDPSource::CreateRes_Impl()
    // Go through all data dimensions (i.e. fields) and build their meta data
    // so that they can be passed on to ScDPResultData instance later.
    // TODO: aggregate all of data dimension info into a structure.
    for (const long nDimIndex : maDataDims)
    for (const tools::Long nDimIndex : maDataDims)
    {
        // Get function for each data field.
        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(nDimIndex);
@@ -792,7 +792,7 @@ void ScDPSource::CreateRes_Impl()
             eRefType == sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE ||
             eRefType == sheet::DataPilotFieldReferenceType::RUNNING_TOTAL )
        {
            long nColumn = comphelper::findValue(
            tools::Long nColumn = comphelper::findValue(
                GetDimensionsObject()->getElementNames(), aDataRefValues.back().ReferenceField);
            if ( nColumn >= 0 )
            {
@@ -817,7 +817,7 @@ void ScDPSource::CreateRes_Impl()

        //TODO: the complete name (function and field) must be stored at the dimension

        long nSource = pDim->GetSourceDim();
        tools::Long nSource = pDim->GetSourceDim();
        if (nSource >= 0)
            aInfo.aDataSrcCols.push_back(nSource);
        else
@@ -847,21 +847,21 @@ void ScDPSource::CreateRes_Impl()
    // Show grand total columns only when the option is set *and* there is at
    // least one column field.  Same for the grand total rows.
    sheet::DataPilotFieldOrientation nDataLayoutOrient = GetDataLayoutOrientation();
    long nColDimCount2 = maColDims.size() - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_COLUMN ? 1 : 0);
    long nRowDimCount2 = maRowDims.size() - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_ROW ? 1 : 0);
    tools::Long nColDimCount2 = maColDims.size() - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_COLUMN ? 1 : 0);
    tools::Long nRowDimCount2 = maRowDims.size() - (nDataLayoutOrient == sheet::DataPilotFieldOrientation_ROW ? 1 : 0);
    bool bShowColGrand = bColumnGrand && nColDimCount2 > 0;
    bool bShowRowGrand = bRowGrand && nRowDimCount2 > 0;
    pColResRoot.reset( new ScDPResultMember(pResData.get(), bShowColGrand) );
    pRowResRoot.reset( new ScDPResultMember(pResData.get(), bShowRowGrand) );

    FillCalcInfo(false, aInfo, bHasAutoShow);
    long nColLevelCount = aInfo.aColLevels.size();
    tools::Long nColLevelCount = aInfo.aColLevels.size();

    pColResRoot->InitFrom( aInfo.aColDims, aInfo.aColLevels, 0, aInitState );
    pColResRoot->SetHasElements();

    FillCalcInfo(true, aInfo, bHasAutoShow);
    long nRowLevelCount = aInfo.aRowLevels.size();
    tools::Long nRowLevelCount = aInfo.aRowLevels.size();

    if ( nRowLevelCount > 0 )
    {
@@ -876,21 +876,21 @@ void ScDPSource::CreateRes_Impl()
    for (const auto& rDimIndex : maPageDims)
    {
        ScDPDimension* pDim = GetDimensionsObject()->getByIndex(rDimIndex);
        long nHierarchy = ScDPDimension::getUsedHierarchy();
        tools::Long nHierarchy = ScDPDimension::getUsedHierarchy();
        if ( nHierarchy >= ScDPHierarchies::getCount() )
            nHierarchy = 0;

        ScDPLevels* pLevels = pDim->GetHierarchiesObject()->getByIndex(nHierarchy)->GetLevelsObject();
        long nCount = pLevels->getCount();
        for (long j=0; j<nCount; j++)
        tools::Long nCount = pLevels->getCount();
        for (tools::Long j=0; j<nCount; j++)
            pLevels->getByIndex(j)->GetMembersObject();             // initialize for groups
    }

    //  pre-check: calculate minimum number of result columns / rows from
    //  levels that have the "show all" flag set

    long nMinColMembers = lcl_CountMinMembers( aInfo.aColDims, aInfo.aColLevels, nColLevelCount );
    long nMinRowMembers = lcl_CountMinMembers( aInfo.aRowDims, aInfo.aRowLevels, nRowLevelCount );
    tools::Long nMinColMembers = lcl_CountMinMembers( aInfo.aColDims, aInfo.aColLevels, nColLevelCount );
    tools::Long nMinRowMembers = lcl_CountMinMembers( aInfo.aRowDims, aInfo.aRowLevels, nRowLevelCount );

    if ( nMinColMembers > MAXCOLCOUNT/*SC_MINCOUNT_LIMIT*/ || nMinRowMembers > SC_MINCOUNT_LIMIT )
    {
@@ -989,13 +989,13 @@ void ScDPSource::FillLevelList( sheet::DataPilotFieldOrientation nOrientation, s
        OSL_ENSURE( pDim->getOrientation() == nOrientation, "orientations are wrong" );

        ScDPHierarchies* pHiers = pDim->GetHierarchiesObject();
        long nHierarchy = ScDPDimension::getUsedHierarchy();
        tools::Long nHierarchy = ScDPDimension::getUsedHierarchy();
        if ( nHierarchy >= ScDPHierarchies::getCount() )
            nHierarchy = 0;
        ScDPHierarchy* pHier = pHiers->getByIndex(nHierarchy);
        ScDPLevels* pLevels = pHier->GetLevelsObject();
        long nLevCount = pLevels->getCount();
        for (long nLev=0; nLev<nLevCount; nLev++)
        tools::Long nLevCount = pLevels->getCount();
        for (tools::Long nLev=0; nLev<nLevCount; nLev++)
        {
            ScDPLevel* pLevel = pLevels->getByIndex(nLev);
            rList.push_back(pLevel);
@@ -1018,29 +1018,29 @@ void ScDPSource::FillMemberResults()
    }

    FillLevelList( sheet::DataPilotFieldOrientation_COLUMN, aColLevelList );
    long nColLevelCount = aColLevelList.size();
    tools::Long nColLevelCount = aColLevelList.size();
    if (nColLevelCount)
    {
        long nColDimSize = pColResRoot->GetSize(pResData->GetColStartMeasure());
        tools::Long nColDimSize = pColResRoot->GetSize(pResData->GetColStartMeasure());
        pColResults.reset(new uno::Sequence<sheet::MemberResult>[nColLevelCount]);
        for (long i=0; i<nColLevelCount; i++)
        for (tools::Long i=0; i<nColLevelCount; i++)
            pColResults[i].realloc(nColDimSize);

        long nPos = 0;
        tools::Long nPos = 0;
        pColResRoot->FillMemberResults( pColResults.get(), nPos, pResData->GetColStartMeasure(),
                                        true, nullptr, nullptr );
    }

    FillLevelList( sheet::DataPilotFieldOrientation_ROW, aRowLevelList );
    long nRowLevelCount = aRowLevelList.size();
    tools::Long nRowLevelCount = aRowLevelList.size();
    if (nRowLevelCount)
    {
        long nRowDimSize = pRowResRoot->GetSize(pResData->GetRowStartMeasure());
        tools::Long nRowDimSize = pRowResRoot->GetSize(pResData->GetRowStartMeasure());
        pRowResults.reset( new uno::Sequence<sheet::MemberResult>[nRowLevelCount] );
        for (long i=0; i<nRowLevelCount; i++)
        for (tools::Long i=0; i<nRowLevelCount; i++)
            pRowResults[i].realloc(nRowDimSize);

        long nPos = 0;
        tools::Long nPos = 0;
        pRowResRoot->FillMemberResults( pRowResults.get(), nPos, pResData->GetRowStartMeasure(),
                                        true, nullptr, nullptr );
    }
@@ -1050,15 +1050,15 @@ const uno::Sequence<sheet::MemberResult>* ScDPSource::GetMemberResults( const Sc
{
    FillMemberResults();

    long i = 0;
    long nColCount = aColLevelList.size();
    tools::Long i = 0;
    tools::Long nColCount = aColLevelList.size();
    for (i=0; i<nColCount; i++)
    {
        ScDPLevel* pColLevel = aColLevelList[i];
        if ( pColLevel == pLevel )
            return &pColResults[i];
    }
    long nRowCount = aRowLevelList.size();
    tools::Long nRowCount = aRowLevelList.size();
    for (i=0; i<nRowCount; i++)
    {
        ScDPLevel* pRowLevel = aRowLevelList[i];
@@ -1177,11 +1177,11 @@ ScDPDimensions::~ScDPDimensions()
void ScDPDimensions::CountChanged()
{
    // include data layout dimension and duplicated dimensions
    long nNewCount = pSource->GetData()->GetColumnCount() + 1 + pSource->GetDupCount();
    tools::Long nNewCount = pSource->GetData()->GetColumnCount() + 1 + pSource->GetDupCount();
    if ( ppDims )
    {
        long i;
        long nCopy = std::min( nNewCount, nDimCount );
        tools::Long i;
        tools::Long nCopy = std::min( nNewCount, nDimCount );
        rtl::Reference<ScDPDimension>* ppNew = new rtl::Reference<ScDPDimension>[nNewCount];

        for (i=0; i<nCopy; i++)             // copy existing dims
@@ -1198,8 +1198,8 @@ void ScDPDimensions::CountChanged()

uno::Any SAL_CALL ScDPDimensions::getByName( const OUString& aName )
{
    long nCount = getCount();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = getCount();
    for (tools::Long i=0; i<nCount; i++)
        if ( getByIndex(i)->getName() == aName )
        {
            uno::Reference<container::XNamed> xNamed = getByIndex(i);
@@ -1214,18 +1214,18 @@ uno::Any SAL_CALL ScDPDimensions::getByName( const OUString& aName )

uno::Sequence<OUString> SAL_CALL ScDPDimensions::getElementNames()
{
    long nCount = getCount();
    tools::Long nCount = getCount();
    uno::Sequence<OUString> aSeq(nCount);
    OUString* pArr = aSeq.getArray();
    for (long i=0; i<nCount; i++)
    for (tools::Long i=0; i<nCount; i++)
        pArr[i] = getByIndex(i)->getName();
    return aSeq;
}

sal_Bool SAL_CALL ScDPDimensions::hasByName( const OUString& aName )
{
    long nCount = getCount();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = getCount();
    for (tools::Long i=0; i<nCount; i++)
        if ( getByIndex(i)->getName() == aName )
            return true;
    return false;
@@ -1243,21 +1243,21 @@ sal_Bool SAL_CALL ScDPDimensions::hasElements()

// end of XNameAccess implementation

long ScDPDimensions::getCount() const
tools::Long ScDPDimensions::getCount() const
{
    //  in tabular data, every column of source data is a dimension

    return nDimCount;
}

ScDPDimension* ScDPDimensions::getByIndex(long nIndex) const
ScDPDimension* ScDPDimensions::getByIndex(tools::Long nIndex) const
{
    if ( nIndex >= 0 && nIndex < nDimCount )
    {
        if ( !ppDims )
        {
            const_cast<ScDPDimensions*>(this)->ppDims.reset(new rtl::Reference<ScDPDimension>[nDimCount] );
            for (long i=0; i<nDimCount; i++)
            for (tools::Long i=0; i<nDimCount; i++)
                ppDims[i] = nullptr;
        }
        if ( !ppDims[nIndex].is() )
@@ -1271,7 +1271,7 @@ ScDPDimension* ScDPDimensions::getByIndex(long nIndex) const
    return nullptr;    //TODO: exception?
}

ScDPDimension::ScDPDimension( ScDPSource* pSrc, long nD ) :
ScDPDimension::ScDPDimension( ScDPSource* pSrc, tools::Long nD ) :
    pSource( pSrc ),
    nDim( nD ),
    nFunction( ScGeneralFunction::SUM ),     // sum is default
@@ -1366,20 +1366,20 @@ const ScDPItemData& ScDPDimension::GetSelectedData()
    {
        // find the named member to initialize pSelectedData from it, with name and value

        long nLevel = 0;
        tools::Long nLevel = 0;

        long nHierarchy = getUsedHierarchy();
        tools::Long nHierarchy = getUsedHierarchy();
        if ( nHierarchy >= ScDPHierarchies::getCount() )
            nHierarchy = 0;
        ScDPLevels* pLevels = GetHierarchiesObject()->getByIndex(nHierarchy)->GetLevelsObject();
        long nLevCount = pLevels->getCount();
        tools::Long nLevCount = pLevels->getCount();
        if ( nLevel < nLevCount )
        {
            ScDPMembers* pMembers = pLevels->getByIndex(nLevel)->GetMembersObject();

            //TODO: merge with ScDPMembers::getByName
            long nCount = pMembers->getCount();
            for (long i=0; i<nCount && !pSelectedData; i++)
            tools::Long nCount = pMembers->getCount();
            for (tools::Long i=0; i<nCount && !pSelectedData; i++)
            {
                ScDPMember* pMember = pMembers->getByIndex(i);
                if (aSelectedPage == pMember->GetNameStr(false))
@@ -1609,7 +1609,7 @@ uno::Any SAL_CALL ScDPDimension::getPropertyValue( const OUString& aPropertyName

SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDPDimension )

ScDPHierarchies::ScDPHierarchies( ScDPSource* pSrc, long nD ) :
ScDPHierarchies::ScDPHierarchies( ScDPSource* pSrc, tools::Long nD ) :
    pSource( pSrc ),
    nDim( nD )
{
@@ -1625,8 +1625,8 @@ ScDPHierarchies::~ScDPHierarchies()

uno::Any SAL_CALL ScDPHierarchies::getByName( const OUString& aName )
{
    long nCount = getCount();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = getCount();
    for (tools::Long i=0; i<nCount; i++)
        if ( getByIndex(i)->getName() == aName )
        {
            uno::Reference<container::XNamed> xNamed = getByIndex(i);
@@ -1640,18 +1640,18 @@ uno::Any SAL_CALL ScDPHierarchies::getByName( const OUString& aName )

uno::Sequence<OUString> SAL_CALL ScDPHierarchies::getElementNames()
{
    long nCount = getCount();
    tools::Long nCount = getCount();
    uno::Sequence<OUString> aSeq(nCount);
    OUString* pArr = aSeq.getArray();
    for (long i=0; i<nCount; i++)
    for (tools::Long i=0; i<nCount; i++)
        pArr[i] = getByIndex(i)->getName();
    return aSeq;
}

sal_Bool SAL_CALL ScDPHierarchies::hasByName( const OUString& aName )
{
    long nCount = getCount();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = getCount();
    for (tools::Long i=0; i<nCount; i++)
        if ( getByIndex(i)->getName() == aName )
            return true;
    return false;
@@ -1669,12 +1669,12 @@ sal_Bool SAL_CALL ScDPHierarchies::hasElements()

// end of XNameAccess implementation

long ScDPHierarchies::getCount()
tools::Long ScDPHierarchies::getCount()
{
    return nHierCount;
}

ScDPHierarchy* ScDPHierarchies::getByIndex(long nIndex) const
ScDPHierarchy* ScDPHierarchies::getByIndex(tools::Long nIndex) const
{
    //  pass hierarchy index to new object in case the implementation
    //  will be extended to more than one hierarchy
@@ -1684,7 +1684,7 @@ ScDPHierarchy* ScDPHierarchies::getByIndex(long nIndex) const
        if ( !ppHiers )
        {
            const_cast<ScDPHierarchies*>(this)->ppHiers.reset( new rtl::Reference<ScDPHierarchy>[nHierCount] );
            for (long i=0; i<nHierCount; i++)
            for (tools::Long i=0; i<nHierCount; i++)
                ppHiers[i] = nullptr;
        }
        if ( !ppHiers[nIndex].is() )
@@ -1698,7 +1698,7 @@ ScDPHierarchy* ScDPHierarchies::getByIndex(long nIndex) const
    return nullptr;    //TODO: exception?
}

ScDPHierarchy::ScDPHierarchy( ScDPSource* pSrc, long nD, long nH ) :
ScDPHierarchy::ScDPHierarchy( ScDPSource* pSrc, tools::Long nD, tools::Long nH ) :
    pSource( pSrc ),
    nDim( nD ),
    nHier( nH )
@@ -1751,7 +1751,7 @@ void SAL_CALL ScDPHierarchy::setName( const OUString& /* rNewName */ )
    OSL_FAIL("not implemented");        //TODO: exception?
}

ScDPLevels::ScDPLevels( ScDPSource* pSrc, long nD, long nH ) :
ScDPLevels::ScDPLevels( ScDPSource* pSrc, tools::Long nD, tools::Long nH ) :
    pSource( pSrc ),
    nDim( nD ),
    nHier( nH )
@@ -1760,7 +1760,7 @@ ScDPLevels::ScDPLevels( ScDPSource* pSrc, long nD, long nH ) :

    //  text columns have only one level

    long nSrcDim = pSource->GetSourceDim( nDim );
    tools::Long nSrcDim = pSource->GetSourceDim( nDim );
    if ( pSource->IsDateDimension( nSrcDim ) )
    {
        switch ( nHier )
@@ -1786,8 +1786,8 @@ ScDPLevels::~ScDPLevels()

uno::Any SAL_CALL ScDPLevels::getByName( const OUString& aName )
{
    long nCount = getCount();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = getCount();
    for (tools::Long i=0; i<nCount; i++)
        if ( getByIndex(i)->getName() == aName )
        {
            uno::Reference<container::XNamed> xNamed = getByIndex(i);
@@ -1801,18 +1801,18 @@ uno::Any SAL_CALL ScDPLevels::getByName( const OUString& aName )

uno::Sequence<OUString> SAL_CALL ScDPLevels::getElementNames()
{
    long nCount = getCount();
    tools::Long nCount = getCount();
    uno::Sequence<OUString> aSeq(nCount);
    OUString* pArr = aSeq.getArray();
    for (long i=0; i<nCount; i++)
    for (tools::Long i=0; i<nCount; i++)
        pArr[i] = getByIndex(i)->getName();
    return aSeq;
}

sal_Bool SAL_CALL ScDPLevels::hasByName( const OUString& aName )
{
    long nCount = getCount();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = getCount();
    for (tools::Long i=0; i<nCount; i++)
        if ( getByIndex(i)->getName() == aName )
            return true;
    return false;
@@ -1830,19 +1830,19 @@ sal_Bool SAL_CALL ScDPLevels::hasElements()

// end of XNameAccess implementation

long ScDPLevels::getCount() const
tools::Long ScDPLevels::getCount() const
{
    return nLevCount;
}

ScDPLevel* ScDPLevels::getByIndex(long nIndex) const
ScDPLevel* ScDPLevels::getByIndex(tools::Long nIndex) const
{
    if ( nIndex >= 0 && nIndex < nLevCount )
    {
        if ( !ppLevs )
        {
            const_cast<ScDPLevels*>(this)->ppLevs.reset(new rtl::Reference<ScDPLevel>[nLevCount] );
            for (long i=0; i<nLevCount; i++)
            for (tools::Long i=0; i<nLevCount; i++)
                ppLevs[i] = nullptr;
        }
        if ( !ppLevs[nIndex].is() )
@@ -1888,7 +1888,7 @@ bool ScDPGlobalMembersOrder::operator()( sal_Int32 nIndex1, sal_Int32 nIndex2 ) 
    return bAscending ? (nCompare < 0) : (nCompare > 0);
}

ScDPLevel::ScDPLevel( ScDPSource* pSrc, long nD, long nH, long nL ) :
ScDPLevel::ScDPLevel( ScDPSource* pSrc, tools::Long nD, tools::Long nH, tools::Long nL ) :
    pSource( pSrc ),
    nDim( nD ),
    nHier( nH ),
@@ -1917,8 +1917,8 @@ void ScDPLevel::EvaluateSortOrder()
            {
                // find index of measure (index among data dimensions)

                long nMeasureCount = pSource->GetDataDimensionCount();
                for (long nMeasure=0; nMeasure<nMeasureCount; nMeasure++)
                tools::Long nMeasureCount = pSource->GetDataDimensionCount();
                for (tools::Long nMeasure=0; nMeasure<nMeasureCount; nMeasure++)
                {
                    if (pSource->GetDataDimName(nMeasure) == aSortInfo.Field)
                    {
@@ -1934,10 +1934,10 @@ void ScDPLevel::EvaluateSortOrder()
        case sheet::DataPilotFieldSortMode::NAME:
            {
                ScDPMembers* pLocalMembers = GetMembersObject();
                long nCount = pLocalMembers->getCount();
                tools::Long nCount = pLocalMembers->getCount();

                aGlobalOrder.resize( nCount );
                for (long nPos=0; nPos<nCount; nPos++)
                for (tools::Long nPos=0; nPos<nCount; nPos++)
                    aGlobalOrder[nPos] = nPos;

                // allow manual or name (manual is always ascending)
@@ -1953,8 +1953,8 @@ void ScDPLevel::EvaluateSortOrder()

    // find index of measure (index among data dimensions)

    long nMeasureCount = pSource->GetDataDimensionCount();
    for (long nMeasure=0; nMeasure<nMeasureCount; nMeasure++)
    tools::Long nMeasureCount = pSource->GetDataDimensionCount();
    for (tools::Long nMeasure=0; nMeasure<nMeasureCount; nMeasure++)
    {
        if (pSource->GetDataDimName(nMeasure) == aAutoShowInfo.DataField)
        {
@@ -1996,7 +1996,7 @@ uno::Sequence<sheet::MemberResult> SAL_CALL ScDPLevel::getResults()

OUString SAL_CALL ScDPLevel::getName()
{
    long nSrcDim = pSource->GetSourceDim( nDim );
    tools::Long nSrcDim = pSource->GetSourceDim( nDim );
    if ( pSource->IsDateDimension( nSrcDim ) )
    {
        OUString aRet;        //TODO: globstr-ID !!!!
@@ -2060,7 +2060,7 @@ uno::Sequence<sal_Int16> ScDPLevel::getSubTotals() const
{
    //TODO: separate functions for settings and evaluation?

    long nSrcDim = pSource->GetSourceDim( nDim );
    tools::Long nSrcDim = pSource->GetSourceDim( nDim );
    if ( !pSource->SubTotalAllowed( nSrcDim ) )
        return uno::Sequence<sal_Int16>(0);

@@ -2154,7 +2154,7 @@ uno::Any SAL_CALL ScDPLevel::getPropertyValue( const OUString& aPropertyName )
    else if (aPropertyName == SC_UNO_DP_LAYOUTNAME)
    {
        // read only property
        long nSrcDim = pSource->GetSourceDim(nDim);
        tools::Long nSrcDim = pSource->GetSourceDim(nDim);
        ScDPDimension* pDim = pSource->GetDimensionsObject()->getByIndex(nSrcDim);
        if (!pDim)
            return aRet;
@@ -2174,7 +2174,7 @@ uno::Any SAL_CALL ScDPLevel::getPropertyValue( const OUString& aPropertyName )

SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDPLevel )

ScDPMembers::ScDPMembers( ScDPSource* pSrc, long nD, long nH, long nL ) :
ScDPMembers::ScDPMembers( ScDPSource* pSrc, tools::Long nD, tools::Long nH, tools::Long nL ) :
    pSource( pSrc ),
    nDim( nD ),
    nHier( nH ),
@@ -2182,7 +2182,7 @@ ScDPMembers::ScDPMembers( ScDPSource* pSrc, long nD, long nH, long nL ) :
{
    //TODO: hold pSource

    long nSrcDim = pSource->GetSourceDim( nDim );
    tools::Long nSrcDim = pSource->GetSourceDim( nDim );
    if ( pSource->IsDataLayoutDimension(nSrcDim) )
        nMbrCount = pSource->GetDataDimensionCount();
    else if ( nHier != SC_DAPI_HIERARCHY_FLAT && pSource->IsDateDimension( nSrcDim ) )
@@ -2210,11 +2210,11 @@ ScDPMembers::ScDPMembers( ScDPSource* pSrc, long nD, long nH, long nL ) :
                            double fFirstVal = pFirstData->GetValue();
                            double fLastVal = pLastNumData->GetValue();

                            long nFirstYear = pSource->GetData()->GetDatePart(
                                        static_cast<long>(::rtl::math::approxFloor( fFirstVal )),
                            tools::Long nFirstYear = pSource->GetData()->GetDatePart(
                                        static_cast<tools::Long>(::rtl::math::approxFloor( fFirstVal )),
                                        nHier, nLev );
                            long nLastYear = pSource->GetData()->GetDatePart(
                                        static_cast<long>(::rtl::math::approxFloor( fLastVal )),
                            tools::Long nLastYear = pSource->GetData()->GetDatePart(
                                        static_cast<tools::Long>(::rtl::math::approxFloor( fLastVal )),
                                        nHier, nLev );

                            nMbrCount = nLastYear + 1 - nFirstYear;
@@ -2329,19 +2329,19 @@ uno::Sequence<OUString> ScDPMembers::getElementNames( bool bLocaleIndependent ) 
    const std::vector<sal_Int32>& rGlobalOrder = pLevel->GetGlobalOrder();
    bool bSort = !rGlobalOrder.empty();

    long nCount = getCount();
    tools::Long nCount = getCount();
    uno::Sequence<OUString> aSeq(nCount);
    OUString* pArr = aSeq.getArray();
    for (long i=0; i<nCount; i++)
    for (tools::Long i=0; i<nCount; i++)
        pArr[i] = getByIndex(bSort ? rGlobalOrder[i] : i)->GetNameStr( bLocaleIndependent);
    return aSeq;
}

long ScDPMembers::getMinMembers() const
tools::Long ScDPMembers::getMinMembers() const
{
    // used in lcl_CountMinMembers

    long nVisCount = 0;
    tools::Long nVisCount = 0;
    if (!maMembers.empty())
    {
        nVisCount = std::count_if(maMembers.begin(), maMembers.end(), [](const rtl::Reference<ScDPMember>& pMbr) {
@@ -2354,7 +2354,7 @@ long ScDPMembers::getMinMembers() const
    return nVisCount;
}

ScDPMember* ScDPMembers::getByIndex(long nIndex) const
ScDPMember* ScDPMembers::getByIndex(tools::Long nIndex) const
{
    //  result of GetColumnEntries must not change between ScDPMembers ctor
    //  and all calls to getByIndex
@@ -2367,7 +2367,7 @@ ScDPMember* ScDPMembers::getByIndex(long nIndex) const
        if (!maMembers[nIndex])
        {
            rtl::Reference<ScDPMember> pNew;
            long nSrcDim = pSource->GetSourceDim( nDim );
            tools::Long nSrcDim = pSource->GetSourceDim( nDim );
            if ( pSource->IsDataLayoutDimension(nSrcDim) )
            {
                // empty name (never shown, not used for lookup)
@@ -2384,8 +2384,8 @@ ScDPMember* ScDPMembers::getByIndex(long nIndex) const
                    //TODO: cache year range here!

                    double fFirstVal = pSource->GetData()->GetMemberByIndex( nSrcDim, 0 )->GetValue();
                    long nFirstYear = pSource->GetData()->GetDatePart(
                                        static_cast<long>(::rtl::math::approxFloor( fFirstVal )),
                    tools::Long nFirstYear = pSource->GetData()->GetDatePart(
                                        static_cast<tools::Long>(::rtl::math::approxFloor( fFirstVal )),
                                        nHier, nLev );

                    nVal = nFirstYear + nIndex;
@@ -2448,7 +2448,7 @@ ScDPMember* ScDPMembers::getByIndex(long nIndex) const
}

ScDPMember::ScDPMember(
    ScDPSource* pSrc, long nD, long nH, long nL, SCROW nIndex) :
    ScDPSource* pSrc, tools::Long nD, tools::Long nH, tools::Long nL, SCROW nIndex) :
    pSource( pSrc ),
    nDim( nD ),
    nHier( nH ),
@@ -2468,14 +2468,14 @@ ScDPMember::~ScDPMember()

bool ScDPMember::IsNamedItem(SCROW nIndex) const
{
    long nSrcDim = pSource->GetSourceDim( nDim );
    tools::Long nSrcDim = pSource->GetSourceDim( nDim );
    if ( nHier != SC_DAPI_HIERARCHY_FLAT && pSource->IsDateDimension( nSrcDim ) )
    {
        const ScDPItemData* pData = pSource->GetCache()->GetItemDataById(nDim, nIndex);
        if (pData->IsValue())
        {
            long nComp = pSource->GetData()->GetDatePart(
                static_cast<long>(::rtl::math::approxFloor( pData->GetValue() )),
            tools::Long nComp = pSource->GetData()->GetDatePart(
                static_cast<tools::Long>(::rtl::math::approxFloor( pData->GetValue() )),
                nHier, nLev );
            //  fValue is converted from integer, so simple comparison works
            const ScDPItemData* pData2 = GetItemData();
@@ -2614,7 +2614,7 @@ const ScDPItemData* ScDPMember::GetItemData() const
    return pData;
}

const ScDPItemData* ScDPSource::GetItemDataById(long nDim, long nId)
const ScDPItemData* ScDPSource::GetItemDataById(tools::Long nDim, tools::Long nId)
{
    return GetData()->GetMemberById(nDim, nId);
}
@@ -2622,7 +2622,7 @@ const ScDPItemData* ScDPSource::GetItemDataById(long nDim, long nId)
const ScDPItemData* ScDPMembers::GetSrcItemDataByIndex(SCROW nIndex)
{
    const std::vector< SCROW >& memberIds = pSource->GetData()->GetColumnEntries( nDim );
    if ( nIndex >= static_cast<long>(memberIds.size()) || nIndex < 0 )
    if ( nIndex >= static_cast<tools::Long>(memberIds.size()) || nIndex < 0 )
        return nullptr;
    SCROW nId =  memberIds[ nIndex ];
    return pSource->GetItemDataById( nDim, nId );
diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx
index 01145c6..46fa54a 100644
--- a/sc/source/core/data/dputil.cxx
+++ b/sc/source/core/data/dputil.cxx
@@ -121,7 +121,7 @@ OUString ScDPUtil::getDateGroupName(
        {
            Date aDate(1, 1, SC_DP_LEAPYEAR);
            aDate.AddDays(nValue - 1);            // nValue is 1-based
            long nDays = aDate - pFormatter->GetNullDate();
            tools::Long nDays = aDate - pFormatter->GetNullDate();

            const sal_uInt32 nFormat = pFormatter->GetFormatIndex(NF_DATE_SYS_DDMMM, ScGlobal::eLnge);
            const Color* pColor;
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 3a22bc3..87b29f5 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -199,15 +199,15 @@ ScTabSizeChangedHint::~ScTabSizeChangedHint()

#define MAXMM   10000000

static long TwipsToHmm (long nVal)
static tools::Long TwipsToHmm (tools::Long nVal)
{
    return static_cast< long >( vcl::ConvertDoubleValue (static_cast<sal_Int64>(nVal), 0, 0,
    return static_cast< tools::Long >( vcl::ConvertDoubleValue (static_cast<sal_Int64>(nVal), 0, 0,
            FieldUnit::TWIP, FieldUnit::MM_100TH) );
}

static long HmmToTwips (long nVal)
static tools::Long HmmToTwips (tools::Long nVal)
{
    return static_cast< long > ( vcl::ConvertDoubleValue (static_cast<sal_Int64>(nVal), 0, 0,
    return static_cast< tools::Long > ( vcl::ConvertDoubleValue (static_cast<sal_Int64>(nVal), 0, 0,
            FieldUnit::MM_100TH, FieldUnit::TWIP) );
}

@@ -611,8 +611,8 @@ namespace
    Point lcl_calcAvailableDiff(const ScDocument &rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, const Point &aWantedDiff)
    {
        Point aAvailableDiff(aWantedDiff);
        long nHeight = static_cast<long>(rDoc.GetRowHeight( nRow, nTab ) * HMM_PER_TWIPS);
        long nWidth  = static_cast<long>(rDoc.GetColWidth(  nCol, nTab ) * HMM_PER_TWIPS);
        tools::Long nHeight = static_cast<tools::Long>(rDoc.GetRowHeight( nRow, nTab ) * HMM_PER_TWIPS);
        tools::Long nWidth  = static_cast<tools::Long>(rDoc.GetColWidth(  nCol, nTab ) * HMM_PER_TWIPS);
        if (aAvailableDiff.Y() > nHeight)
            aAvailableDiff.setY( nHeight );
        if (aAvailableDiff.X() > nWidth)
@@ -624,8 +624,8 @@ namespace
    {
        rCalcPoly.setB2DPoint(nWhichPoint, basegfx::B2DPoint(rPos.X(), rPos.Y()));
        basegfx::B2DRange aRange(basegfx::utils::getRange(rCalcPoly));
        return tools::Rectangle(static_cast<long>(aRange.getMinX()), static_cast<long>(aRange.getMinY()),
            static_cast<long>(aRange.getMaxX()), static_cast<long>(aRange.getMaxY()));
        return tools::Rectangle(static_cast<tools::Long>(aRange.getMinX()), static_cast<tools::Long>(aRange.getMinY()),
            static_cast<tools::Long>(aRange.getMaxX()), static_cast<tools::Long>(aRange.getMaxY()));
    }
}

@@ -674,10 +674,10 @@ void ScDrawLayer::ResizeLastRectFromAnchor(const SdrObject* pObj, ScDrawObjData&
            // as much as the cell was scaled.
            // Still, we keep the image in its current cell (to keep start anchor == end anchor)
            const tools::Rectangle aCurrentCellRect(GetCellRect(*GetDocument(), rData.maStart, true));
            long nCurrentWidth(aCurrentCellRect.GetWidth());
            long nCurrentHeight(aCurrentCellRect.GetHeight());
            const long nLastWidth(aLastCellRect.GetWidth());
            const long nLastHeight(aLastCellRect.GetHeight());
            tools::Long nCurrentWidth(aCurrentCellRect.GetWidth());
            tools::Long nCurrentHeight(aCurrentCellRect.GetHeight());
            const tools::Long nLastWidth(aLastCellRect.GetWidth());
            const tools::Long nLastHeight(aLastCellRect.GetHeight());

            // tdf#116931 Avoid and correct nifty numerical problems with the integer
            // based and converted values (GetCellRect uses multiplies with HMM_PER_TWIPS)
@@ -710,11 +710,11 @@ void ScDrawLayer::ResizeLastRectFromAnchor(const SdrObject* pObj, ScDrawObjData&
                tools::Rectangle aRectIncludingOffset = aRect;
                aRectIncludingOffset.setWidth(aRect.GetWidth() + rData.maStartOffset.X());
                aRectIncludingOffset.setHeight(aRect.GetHeight() + rData.maStartOffset.Y());
                long nWidth = aRectIncludingOffset.GetWidth();
                tools::Long nWidth = aRectIncludingOffset.GetWidth();
                assert(nWidth && "div-by-zero");
                double fMaxWidthFactor = static_cast<double>(nCurrentWidth)
                                         / static_cast<double>(nWidth);
                long nHeight = aRectIncludingOffset.GetHeight();
                tools::Long nHeight = aRectIncludingOffset.GetHeight();
                assert(nHeight && "div-by-zero");
                double fMaxHeightFactor = static_cast<double>(nCurrentHeight)
                                          / static_cast<double>(nHeight);
@@ -1024,8 +1024,8 @@ void ScDrawLayer::RecalcPos( SdrObject* pObj, ScDrawObjData& rData, bool bNegati

                if (bRecording)
                    AddCalcUndo( std::make_unique<SdrUndoGeoObj>( *pObj ) );
                long nOldWidth = aOld.GetWidth();
                long nOldHeight = aOld.GetHeight();
                tools::Long nOldWidth = aOld.GetWidth();
                tools::Long nOldHeight = aOld.GetHeight();
                if (pObj->IsPolyObj() && nOldWidth && nOldHeight)
                {
                    // Polyline objects need special treatment.
@@ -1091,10 +1091,10 @@ bool ScDrawLayer::GetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) co
    bool bNegativePage = pDoc->IsNegativePage( nTab );

    bool bAny = false;
    long nEndX = 0;
    long nEndY = 0;
    long nStartX = LONG_MAX;
    long nStartY = LONG_MAX;
    tools::Long nEndX = 0;
    tools::Long nEndY = 0;
    tools::Long nStartX = LONG_MAX;
    tools::Long nStartY = LONG_MAX;

    // Calculate borders

@@ -1179,7 +1179,7 @@ bool ScDrawLayer::GetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) co
        {
            nStartX = HmmToTwips( nStartX );
            nEndX = HmmToTwips( nEndX );
            long nWidth;
            tools::Long nWidth;

            nWidth = 0;
            rRange.aStart.SetCol( 0 );
@@ -1673,13 +1673,13 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const
    // first mirror, then move
    Size aMove( rDestRange.Left() - aMirroredSource.Left(), rDestRange.Top() - aMirroredSource.Top() );

    long nDestWidth = rDestRange.GetWidth();
    long nDestHeight = rDestRange.GetHeight();
    long nSourceWidth = rSourceRange.GetWidth();
    long nSourceHeight = rSourceRange.GetHeight();
    tools::Long nDestWidth = rDestRange.GetWidth();
    tools::Long nDestHeight = rDestRange.GetHeight();
    tools::Long nSourceWidth = rSourceRange.GetWidth();
    tools::Long nSourceHeight = rSourceRange.GetHeight();

    long nWidthDiff = nDestWidth - nSourceWidth;
    long nHeightDiff = nDestHeight - nSourceHeight;
    tools::Long nWidthDiff = nDestWidth - nSourceWidth;
    tools::Long nHeightDiff = nDestHeight - nSourceHeight;

    Fraction aHorFract(1,1);
    Fraction aVerFract(1,1);
@@ -1840,7 +1840,7 @@ void ScDrawLayer::MirrorRTL( SdrObject* pObj )
void ScDrawLayer::MirrorRectRTL( tools::Rectangle& rRect )
{
    //  mirror and swap left/right
    long nTemp = rRect.Left();
    tools::Long nTemp = rRect.Left();
    rRect.SetLeft( -rRect.Right() );
    rRect.SetRight( -nTemp );
}
@@ -1874,10 +1874,10 @@ tools::Rectangle ScDrawLayer::GetCellRect( const ScDocument& rDoc, const ScAddre
        aBotRight.AdjustY(rDoc.GetRowHeight( rPos.Row(), aEndPos.Row(), rPos.Tab() ) );

        // twips -> 1/100 mm
        aTopLeft.setX( static_cast< long >( aTopLeft.X() * HMM_PER_TWIPS ) );
        aTopLeft.setY( static_cast< long >( aTopLeft.Y() * HMM_PER_TWIPS ) );
        aBotRight.setX( static_cast< long >( aBotRight.X() * HMM_PER_TWIPS ) );
        aBotRight.setY( static_cast< long >( aBotRight.Y() * HMM_PER_TWIPS ) );
        aTopLeft.setX( static_cast< tools::Long >( aTopLeft.X() * HMM_PER_TWIPS ) );
        aTopLeft.setY( static_cast< tools::Long >( aTopLeft.Y() * HMM_PER_TWIPS ) );
        aBotRight.setX( static_cast< tools::Long >( aBotRight.X() * HMM_PER_TWIPS ) );
        aBotRight.setY( static_cast< tools::Long >( aBotRight.Y() * HMM_PER_TWIPS ) );

        aCellRect = tools::Rectangle( aTopLeft, aBotRight );
        if( rDoc.IsNegativePage( rPos.Tab() ) )
@@ -1940,14 +1940,14 @@ SdrObject* ScDrawLayer::GetNamedObject( const OUString& rName, sal_uInt16 nId, S
    return nullptr;
}

OUString ScDrawLayer::GetNewGraphicName( long* pnCounter ) const
OUString ScDrawLayer::GetNewGraphicName( tools::Long* pnCounter ) const
{
    OUString aBase = ScResId(STR_GRAPHICNAME) + " ";

    bool bThere = true;
    OUString aGraphicName;
    SCTAB nDummy;
    long nId = pnCounter ? *pnCounter : 0;
    tools::Long nId = pnCounter ? *pnCounter : 0;
    while (bThere)
    {
        ++nId;
@@ -1978,7 +1978,7 @@ void ScDrawLayer::EnsureGraphicNames()
            /* The index passed to GetNewGraphicName() will be set to
                the used index in each call. This prevents the repeated search
                for all names from 1 to current index. */
            long nCounter = 0;
            tools::Long nCounter = 0;

            while (pObject)
            {
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 7040729..3507a4f 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -971,33 +971,33 @@ void ScDocument::FillInfo(
                // additional space before first column
                if( nFirstCol == 0 )
                {
                    long nSize = 0;
                    tools::Long nSize = 0;
                    for( SCCOL nDocCol = nFirstRealDocCol; nDocCol < nFirstDocCol; ++nDocCol )
                        nSize += std::max( static_cast< long >( GetColWidth( nDocCol, nTab ) * fColScale ), 1L );
                        nSize += std::max( static_cast< tools::Long >( GetColWidth( nDocCol, nTab ) * fColScale ), 1L );
                    rArray.SetAddMergedLeftSize( nCol, nRow, nSize );
                }
                // additional space after last column
                if( nLastCol + 1 == nColCount )
                {
                    long nSize = 0;
                    tools::Long nSize = 0;
                    for( SCCOL nDocCol = nLastDocCol + 1; nDocCol <= nLastRealDocCol; ++nDocCol )
                        nSize += std::max( static_cast< long >( GetColWidth( nDocCol, nTab ) * fColScale ), 1L );
                        nSize += std::max( static_cast< tools::Long >( GetColWidth( nDocCol, nTab ) * fColScale ), 1L );
                    rArray.SetAddMergedRightSize( nCol, nRow, nSize );
                }
                // additional space above first row
                if( nFirstRow == 0 )
                {
                    long nSize = 0;
                    tools::Long nSize = 0;
                    for( SCROW nDocRow = nFirstRealDocRow; nDocRow < nFirstDocRow; ++nDocRow )
                        nSize += std::max( static_cast< long >( GetRowHeight( nDocRow, nTab ) * fRowScale ), 1L );
                        nSize += std::max( static_cast< tools::Long >( GetRowHeight( nDocRow, nTab ) * fRowScale ), 1L );
                    rArray.SetAddMergedTopSize( nCol, nRow, nSize );
                }
                // additional space beyond last row
                if( nLastRow + 1 == nRowCount )
                {
                    long nSize = 0;
                    tools::Long nSize = 0;
                    for( SCROW nDocRow = nLastDocRow + 1; nDocRow <= nLastRealDocRow; ++nDocRow )
                        nSize += std::max( static_cast< long >( GetRowHeight( nDocRow, nTab ) * fRowScale ), 1L );
                        nSize += std::max( static_cast< tools::Long >( GetRowHeight( nDocRow, nTab ) * fRowScale ), 1L );
                    rArray.SetAddMergedBottomSize( nCol, nRow, nSize );
                }

diff --git a/sc/source/core/data/funcdesc.cxx b/sc/source/core/data/funcdesc.cxx
index 154ef0d..9efd334 100644
--- a/sc/source/core/data/funcdesc.cxx
+++ b/sc/source/core/data/funcdesc.cxx
@@ -958,8 +958,8 @@ ScFunctionList::ScFunctionList()
    // StarOne AddIns

    ScUnoAddInCollection* pUnoAddIns = ScGlobal::GetAddInCollection();
    long nUnoCount = pUnoAddIns->GetFuncCount();
    for (long nFunc=0; nFunc<nUnoCount; nFunc++)
    tools::Long nUnoCount = pUnoAddIns->GetFuncCount();
    for (tools::Long nFunc=0; nFunc<nUnoCount; nFunc++)
    {
        pDesc = new ScFuncDesc;
        pDesc->nFIndex = nNextId++;
diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx
index 4c389e2d..8b1dafe 100644
--- a/sc/source/core/data/global.cxx
+++ b/sc/source/core/data/global.cxx
@@ -105,8 +105,8 @@ double          ScGlobal::nScreenPPTY           = 96.0;
sal_uInt16          ScGlobal::nDefFontHeight        = 225;
sal_uInt16          ScGlobal::nStdRowHeight         = 256;

long            ScGlobal::nLastRowHeightExtra   = 0;
long            ScGlobal::nLastColWidthExtra    = STD_EXTRA_WIDTH;
tools::Long            ScGlobal::nLastRowHeightExtra   = 0;
tools::Long            ScGlobal::nLastColWidthExtra    = STD_EXTRA_WIDTH;

SfxViewShell* pScActiveViewShell = nullptr; //FIXME: Make this a member
sal_uInt16 nScClickMouseModifier = 0;    //FIXME: This too
diff --git a/sc/source/core/data/markarr.cxx b/sc/source/core/data/markarr.cxx
index 87dc032..3c2083a 100644
--- a/sc/source/core/data/markarr.cxx
+++ b/sc/source/core/data/markarr.cxx
@@ -332,7 +332,7 @@ SCROW ScMarkArray::GetMarkEnd( SCROW nRow, bool bUp ) const
    return nRet;
}

void ScMarkArray::Shift(SCROW nStartRow, long nOffset)
void ScMarkArray::Shift(SCROW nStartRow, tools::Long nOffset)
{
    if (nOffset == 0 || nStartRow > mrSheetLimits.mnMaxRow)
        return;
diff --git a/sc/source/core/data/markdata.cxx b/sc/source/core/data/markdata.cxx
index f44a33c..937fdf8 100644
--- a/sc/source/core/data/markdata.cxx
+++ b/sc/source/core/data/markdata.cxx
@@ -648,7 +648,7 @@ void ScMarkData::DeleteTab( SCTAB nTab )
    maTabMarked.swap(tabMarked);
}

void ScMarkData::ShiftCols(const ScDocument& rDoc, SCCOL nStartCol, long nColOffset)
void ScMarkData::ShiftCols(const ScDocument& rDoc, SCCOL nStartCol, tools::Long nColOffset)
{
    if (bMarked)
    {
@@ -661,7 +661,7 @@ void ScMarkData::ShiftCols(const ScDocument& rDoc, SCCOL nStartCol, long nColOff
    }
}

void ScMarkData::ShiftRows(const ScDocument& rDoc, SCROW nStartRow, long nRowOffset)
void ScMarkData::ShiftRows(const ScDocument& rDoc, SCROW nStartRow, tools::Long nRowOffset)
{
    if (bMarked)
    {
diff --git a/sc/source/core/data/markmulti.cxx b/sc/source/core/data/markmulti.cxx
index 95c52bc..d3e323c 100644
--- a/sc/source/core/data/markmulti.cxx
+++ b/sc/source/core/data/markmulti.cxx
@@ -341,7 +341,7 @@ bool ScMultiSel::HasAnyMarks() const
    return false;
}

void ScMultiSel::ShiftCols(SCCOL nStartCol, long nColOffset)
void ScMultiSel::ShiftCols(SCCOL nStartCol, tools::Long nColOffset)
{
    if (nStartCol > mrSheetLimits.mnMaxCol)
        return;
@@ -388,11 +388,11 @@ void ScMultiSel::ShiftCols(SCCOL nStartCol, long nColOffset)
    rNewCol.Intersect(rPrevPos);
    if (nStartCol + nColOffset >= static_cast<SCCOL>(aNewMultiSel.aMultiSelContainer.size()))
        aNewMultiSel.aMultiSelContainer.resize(nStartCol + nColOffset, ScMarkArray(mrSheetLimits));
    for (long i = 1; i < nColOffset; ++i)
    for (tools::Long i = 1; i < nColOffset; ++i)
        aMultiSelContainer[nStartCol + i] = rNewCol;
}

void ScMultiSel::ShiftRows(SCROW nStartRow, long nRowOffset)
void ScMultiSel::ShiftRows(SCROW nStartRow, tools::Long nRowOffset)
{
    for (auto& aPair: aMultiSelContainer)
        aPair.Shift(nStartRow, nRowOffset);
diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index 9ba0d85..9d0245d 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -345,7 +345,7 @@ void ScPatternAttr::GetFont(
        Fraction aFraction( 1,1 );
        if (pScale)
            aFraction = *pScale;
        Size aSize( 0, static_cast<long>(nFontHeight) );
        Size aSize( 0, static_cast<tools::Long>(nFontHeight) );
        MapMode aDestMode = pOutDev->GetMapMode();
        MapMode aSrcMode( MapUnit::MapTwip, Point(), aFraction, aFraction );
        if (aDestMode.GetMapUnit() == MapUnit::MapPixel && pOutDev->GetDPIX() > 0)
@@ -361,7 +361,7 @@ void ScPatternAttr::GetFont(
    }
    else /* if pOutDev != NULL */
    {
        rFont.SetFontSize( Size( 0, static_cast<long>(nFontHeight) ) );
        rFont.SetFontSize( Size( 0, static_cast<tools::Long>(nFontHeight) ) );
    }

    //  determine effective font color
@@ -558,7 +558,7 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& r
    std::unique_ptr<SvxFontItem> aFontItem(std::make_unique<SvxFontItem>(EE_CHAR_FONTINFO));            // use item as-is
    std::unique_ptr<SvxFontItem> aCjkFontItem(std::make_unique<SvxFontItem>(EE_CHAR_FONTINFO_CJK));            // use item as-is
    std::unique_ptr<SvxFontItem> aCtlFontItem(std::make_unique<SvxFontItem>(EE_CHAR_FONTINFO_CTL));            // use item as-is
    long            nTHeight, nCjkTHeight, nCtlTHeight;     // Twips
    tools::Long            nTHeight, nCjkTHeight, nCtlTHeight;     // Twips
    FontWeight      eWeight, eCjkWeight, eCtlWeight;
    std::unique_ptr<SvxUnderlineItem> aUnderlineItem(std::make_unique<SvxUnderlineItem>(LINESTYLE_NONE, EE_CHAR_UNDERLINE));
    std::unique_ptr<SvxOverlineItem> aOverlineItem(std::make_unique<SvxOverlineItem>(LINESTYLE_NONE, EE_CHAR_OVERLINE));
@@ -712,9 +712,9 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& r

    // Expect to be compatible to LogicToLogic, ie. 2540/1440 = 127/72, and round

    long nHeight = TwipsToHMM(nTHeight);
    long nCjkHeight = TwipsToHMM(nCjkTHeight);
    long nCtlHeight = TwipsToHMM(nCtlTHeight);
    tools::Long nHeight = TwipsToHMM(nTHeight);
    tools::Long nCjkHeight = TwipsToHMM(nCjkTHeight);
    tools::Long nCtlHeight = TwipsToHMM(nCtlTHeight);

    //  put items into EditEngine ItemSet

@@ -1312,9 +1312,9 @@ const SfxPoolItem& ScPatternAttr::GetItem( sal_uInt16 nSubWhich, const SfxItemSe

//  GetRotateVal is tested before ATTR_ORIENTATION

long ScPatternAttr::GetRotateVal( const SfxItemSet* pCondSet ) const
tools::Long ScPatternAttr::GetRotateVal( const SfxItemSet* pCondSet ) const
{
    long nAttrRotate = 0;
    tools::Long nAttrRotate = 0;
    if ( GetCellOrientation() == SvxCellOrientation::Standard )
    {
        bool bRepeat = ( GetItem(ATTR_HOR_JUSTIFY, pCondSet).
@@ -1330,7 +1330,7 @@ ScRotateDir ScPatternAttr::GetRotateDir( const SfxItemSet* pCondSet ) const
{
    ScRotateDir nRet = ScRotateDir::NONE;

    long nAttrRotate = GetRotateVal( pCondSet );
    tools::Long nAttrRotate = GetRotateVal( pCondSet );
    if ( nAttrRotate )
    {
        SvxRotateMode eRotMode = GetItem(ATTR_ROTATE_MODE, pCondSet).GetValue();
@@ -1341,7 +1341,7 @@ ScRotateDir ScPatternAttr::GetRotateDir( const SfxItemSet* pCondSet ) const
            nRet = ScRotateDir::Center;
        else if ( eRotMode == SVX_ROTATE_MODE_TOP || eRotMode == SVX_ROTATE_MODE_BOTTOM )
        {
            long nRot180 = nAttrRotate % 18000;     // 1/100 degrees
            tools::Long nRot180 = nAttrRotate % 18000;     // 1/100 degrees
            if ( nRot180 == 9000 )
                nRet = ScRotateDir::Center;
            else if ( ( eRotMode == SVX_ROTATE_MODE_TOP && nRot180 < 9000 ) ||
diff --git a/sc/source/core/data/pivot2.cxx b/sc/source/core/data/pivot2.cxx
index 111df0a..7544e6e 100644
--- a/sc/source/core/data/pivot2.cxx
+++ b/sc/source/core/data/pivot2.cxx
@@ -80,9 +80,9 @@ ScPivotField::ScPivotField(SCCOL nNewCol) :
    mnDupCount(0)
{}

long ScPivotField::getOriginalDim() const
tools::Long ScPivotField::getOriginalDim() const
{
    return mnOriginalDim >= 0 ? mnOriginalDim : static_cast<long>(nCol);
    return mnOriginalDim >= 0 ? mnOriginalDim : static_cast<tools::Long>(nCol);
}

// ScPivotParam
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index 8d0d3e6..342e4f5 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -55,13 +55,13 @@ using namespace com::sun::star;

namespace {

const long SC_NOTECAPTION_WIDTH             =  2900;    /// Default width of note caption textbox.
const long SC_NOTECAPTION_MAXWIDTH_TEMP     = 12000;    /// Maximum width of temporary note caption textbox.
const long SC_NOTECAPTION_HEIGHT            =  1800;    /// Default height of note caption textbox.
const long SC_NOTECAPTION_CELLDIST          =   600;    /// Default distance of note captions to border of anchor cell.
const long SC_NOTECAPTION_OFFSET_Y          = -1500;    /// Default Y offset of note captions to top border of anchor cell.
const long SC_NOTECAPTION_OFFSET_X          =  1500;    /// Default X offset of note captions to left border of anchor cell.
const long SC_NOTECAPTION_BORDERDIST_TEMP   =   100;    /// Distance of temporary note captions to visible sheet area.
const tools::Long SC_NOTECAPTION_WIDTH             =  2900;    /// Default width of note caption textbox.
const tools::Long SC_NOTECAPTION_MAXWIDTH_TEMP     = 12000;    /// Maximum width of temporary note caption textbox.
const tools::Long SC_NOTECAPTION_HEIGHT            =  1800;    /// Default height of note caption textbox.
const tools::Long SC_NOTECAPTION_CELLDIST          =   600;    /// Default distance of note captions to border of anchor cell.
const tools::Long SC_NOTECAPTION_OFFSET_Y          = -1500;    /// Default Y offset of note captions to top border of anchor cell.
const tools::Long SC_NOTECAPTION_OFFSET_X          =  1500;    /// Default X offset of note captions to left border of anchor cell.
const tools::Long SC_NOTECAPTION_BORDERDIST_TEMP   =   100;    /// Distance of temporary note captions to visible sheet area.

/** Static helper functions for caption objects. */
class ScCaptionUtil
@@ -263,18 +263,18 @@ void ScCaptionCreator::AutoPlaceCaption( const tools::Rectangle* pVisRect )

    // caption rectangle
    tools::Rectangle aCaptRect = mxCaption->GetLogicRect();
    long nWidth = aCaptRect.GetWidth();
    long nHeight = aCaptRect.GetHeight();
    tools::Long nWidth = aCaptRect.GetWidth();
    tools::Long nHeight = aCaptRect.GetHeight();

    // n***Space contains available space between border of visible area and cell
    long nLeftSpace = maCellRect.Left() - rVisRect.Left() + 1;
    long nRightSpace = rVisRect.Right() - maCellRect.Right() + 1;
    long nTopSpace = maCellRect.Top() - rVisRect.Top() + 1;
    long nBottomSpace = rVisRect.Bottom() - maCellRect.Bottom() + 1;
    tools::Long nLeftSpace = maCellRect.Left() - rVisRect.Left() + 1;
    tools::Long nRightSpace = rVisRect.Right() - maCellRect.Right() + 1;
    tools::Long nTopSpace = maCellRect.Top() - rVisRect.Top() + 1;
    tools::Long nBottomSpace = rVisRect.Bottom() - maCellRect.Bottom() + 1;

    // nNeeded*** contains textbox dimensions plus needed distances to cell or border of visible area
    long nNeededSpaceX = nWidth + SC_NOTECAPTION_CELLDIST;
    long nNeededSpaceY = nHeight + SC_NOTECAPTION_CELLDIST;
    tools::Long nNeededSpaceX = nWidth + SC_NOTECAPTION_CELLDIST;
    tools::Long nNeededSpaceY = nHeight + SC_NOTECAPTION_CELLDIST;

    // bFitsWidth*** == true means width of textbox fits into horizontal free space of visible area
    bool bFitsWidthLeft = nNeededSpaceX <= nLeftSpace;      // text box width fits into the width left of cell
@@ -338,9 +338,9 @@ void ScCaptionCreator::UpdateCaptionPos()
            pDrawLayer->AddCalcUndo( std::make_unique<SdrUndoGeoObj>( *mxCaption ) );
        // calculate new caption rectangle (#i98141# handle LTR<->RTL switch correctly)
        tools::Rectangle aCaptRect = mxCaption->GetLogicRect();
        long nDiffX = (rOldTailPos.X() >= 0) ? (aCaptRect.Left() - rOldTailPos.X()) : (rOldTailPos.X() - aCaptRect.Right());
        tools::Long nDiffX = (rOldTailPos.X() >= 0) ? (aCaptRect.Left() - rOldTailPos.X()) : (rOldTailPos.X() - aCaptRect.Right());
        if( mbNegPage ) nDiffX = -nDiffX - aCaptRect.GetWidth();
        long nDiffY = aCaptRect.Top() - rOldTailPos.Y();
        tools::Long nDiffY = aCaptRect.Top() - rOldTailPos.Y();
        aCaptRect.SetPos( aTailPos + Point( nDiffX, nDiffY ) );
        // set new tail position and caption rectangle
        mxCaption->SetTailPos( aTailPos );
@@ -1072,8 +1072,8 @@ void ScPostIt::CreateCaptionFromInitData( const ScAddress& rPos ) const
    {
        tools::Rectangle aCellRect = ScDrawLayer::GetCellRect( mrDoc, rPos, true );
        bool bNegPage = mrDoc.IsNegativePage( rPos.Tab() );
        long nPosX = bNegPage ? (aCellRect.Left() - xInitData->maCaptionOffset.X()) : (aCellRect.Right() + xInitData->maCaptionOffset.X());
        long nPosY = aCellRect.Top() + xInitData->maCaptionOffset.Y();
        tools::Long nPosX = bNegPage ? (aCellRect.Left() - xInitData->maCaptionOffset.X()) : (aCellRect.Right() + xInitData->maCaptionOffset.X());
        tools::Long nPosY = aCellRect.Top() + xInitData->maCaptionOffset.Y();
        tools::Rectangle aCaptRect( Point( nPosX, nPosY ), xInitData->maCaptionSize );
        maNoteData.mxCaption->SetLogicRect( aCaptRect );
        aCreator.FitCaptionToRect();
@@ -1207,7 +1207,7 @@ ScCaptionPtr ScNoteUtil::CreateTempCaption(
        pCaption->SetText( aBuffer.makeStringAndClear() );
        ScCaptionUtil::SetDefaultItems( *pCaption, rDoc, nullptr );
        // adjust caption size to text size
        long nMaxWidth = ::std::min< long >( aVisRect.GetWidth() * 2 / 3, SC_NOTECAPTION_MAXWIDTH_TEMP );
        tools::Long nMaxWidth = ::std::min< long >( aVisRect.GetWidth() * 2 / 3, SC_NOTECAPTION_MAXWIDTH_TEMP );
        pCaption->SetMergedItem( makeSdrTextAutoGrowWidthItem( true ) );
        pCaption->SetMergedItem( makeSdrTextMinFrameWidthItem( SC_NOTECAPTION_WIDTH ) );
        pCaption->SetMergedItem( makeSdrTextMaxFrameWidthItem( nMaxWidth ) );
diff --git a/sc/source/core/data/stlsheet.cxx b/sc/source/core/data/stlsheet.cxx
index 1fc3a54..adf1cba 100644
--- a/sc/source/core/data/stlsheet.cxx
+++ b/sc/source/core/data/stlsheet.cxx
@@ -163,7 +163,7 @@ SfxItemSet& ScStyleSheet::GetItemSet()
                        SfxItemSet&     rHFSet = aHFSetItem.GetItemSet();
                        SvxSizeItem     aHFSizeItem( // 0,5 cm + distance
                                            ATTR_PAGE_SIZE,
                                            Size( 0, long( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );
                                            Size( 0, tools::Long( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );

                        SvxULSpaceItem  aHFDistItem ( HFDIST_CM,// nUp
                                                      HFDIST_CM,// nLow
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 898ca28..f994024 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -430,7 +430,7 @@ sal_uInt16 ScTable::GetOptimalColWidth( SCCOL nCol, OutputDevice* pDev,
        bFormula, STD_COL_WIDTH - STD_EXTRA_WIDTH, pMarkData, pParam );
}

long ScTable::GetNeededSize( SCCOL nCol, SCROW nRow,
tools::Long ScTable::GetNeededSize( SCCOL nCol, SCROW nRow,
                                OutputDevice* pDev,
                                double nPPTX, double nPPTY,
                                const Fraction& rZoomX, const Fraction& rZoomY,
@@ -2059,7 +2059,7 @@ void ScTable::MaybeAddExtraColumn(SCCOL& rCol, SCROW nRow, OutputDevice* pDev, d
    if (!aCell.hasString())
        return;

    long nPixel = rColumn.GetTextWidth(nRow);
    tools::Long nPixel = rColumn.GetTextWidth(nRow);

    // Width already calculated in Idle-Handler ?
    if ( TEXTWIDTH_DIRTY == nPixel )
@@ -2076,10 +2076,10 @@ void ScTable::MaybeAddExtraColumn(SCCOL& rCol, SCROW nRow, OutputDevice* pDev, d
        rColumn.SetTextWidth(nRow, static_cast<sal_uInt16>(nPixel));
    }

    long nTwips = static_cast<long>(nPixel / nPPTX);
    long nDocW = GetColWidth( rCol );
    tools::Long nTwips = static_cast<tools::Long>(nPixel / nPPTX);
    tools::Long nDocW = GetColWidth( rCol );

    long nMissing = nTwips - nDocW;
    tools::Long nMissing = nTwips - nDocW;
    if ( nMissing > 0 )
    {
        //  look at alignment
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index cb0d31a..02f40b6 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2172,7 +2172,7 @@ SCSIZE ScTable::FillMaxRot( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCO
            double nFactor = 0.0;
            if ( nCol > nX2+1 )
            {
                long nRotVal = pPattern->
                tools::Long nRotVal = pPattern->
                        GetItem( ATTR_ROTATE_VALUE, pCondSet ).GetValue();
                double nRealOrient = nRotVal * F_PI18000;   // 1/100 degree
                double nCos = cos( nRealOrient );
@@ -2195,7 +2195,7 @@ SCSIZE ScTable::FillMaxRot( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCCO
                        // Does the rotated cell extend into the visible range?

                        SCCOL nTouchedCol = nCol;
                        long nWidth = static_cast<long>(mpRowHeights->getValue(nRow) * nFactor);
                        tools::Long nWidth = static_cast<tools::Long>(mpRowHeights->getValue(nRow) * nFactor);
                        OSL_ENSURE(nWidth <= 0, "Wrong direction");
                        while ( nWidth < 0 && nTouchedCol > 0 )
                        {
@@ -3013,7 +3013,7 @@ bool lcl_pixelSizeChanged(
    ScFlatUInt16RowSegments& rRowHeights, SCROW nStartRow, SCROW nEndRow,
    sal_uInt16 nNewHeight, double nPPTY)
{
    long nNewPix = static_cast<long>(nNewHeight * nPPTY);
    tools::Long nNewPix = static_cast<tools::Long>(nNewHeight * nPPTY);

    ScFlatUInt16RowSegments::ForwardIterator aFwdIter(rRowHeights);
    for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
@@ -3024,7 +3024,7 @@ bool lcl_pixelSizeChanged(

        if (nHeight != nNewHeight)
        {
            bool bChanged = (nNewPix != static_cast<long>(nHeight * nPPTY));
            bool bChanged = (nNewPix != static_cast<tools::Long>(nHeight * nPPTY));
            if (bChanged)
                return true;
        }
@@ -3910,11 +3910,11 @@ void ScTable::SetDrawPageSize(bool bResetStreamValid, bool bUpdateNoteCaptionPos
    {
        double fValX = GetColOffset( rDocument.MaxCol() + 1 ) * HMM_PER_TWIPS;
        double fValY = GetRowOffset( rDocument.MaxRow() + 1 ) * HMM_PER_TWIPS;
        const long nMax = ::std::numeric_limits<long>::max();
        const tools::Long nMax = ::std::numeric_limits<long>::max();
        // #i113884# Avoid int32 overflow with possible negative results than can cause bad effects.
        // If the draw page size is smaller than all rows, only the bottom of the sheet is affected.
        long x = ( fValX > static_cast<double>(nMax) ) ? nMax : static_cast<long>(fValX);
        long y = ( fValY > static_cast<double>(nMax) ) ? nMax : static_cast<long>(fValY);
        tools::Long x = ( fValX > static_cast<double>(nMax) ) ? nMax : static_cast<tools::Long>(fValX);
        tools::Long y = ( fValY > static_cast<double>(nMax) ) ? nMax : static_cast<tools::Long>(fValY);

        if ( IsLayoutRTL() )        // IsNegativePage
            x = -x;
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 2135a6d..a528117 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2748,7 +2748,7 @@ bool ScTable::ValidQuery(
    bool* pPasst = ( nEntryCount <= nFixedBools ? &aBool[0] : new bool[nEntryCount] );
    bool* pTest = ( nEntryCount <= nFixedBools ? &aTest[0] : new bool[nEntryCount] );

    long    nPos = -1;
    tools::Long    nPos = -1;
    QueryEvaluator aEval(rDocument, *this, rParam, pbTestEqualCondition != nullptr);
    ScQueryParam::const_iterator it, itBeg = rParam.begin(), itEnd = rParam.end();
    for (it = itBeg; it != itEnd && (*it)->bDoQuery; ++it)
@@ -2843,7 +2843,7 @@ bool ScTable::ValidQuery(
        }
    }

    for ( long j=1; j <= nPos; j++ )
    for ( tools::Long j=1; j <= nPos; j++ )
    {
        pPasst[0] = pPasst[0] || pPasst[j];
        pTest[0] = pTest[0] || pTest[j];
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 427169b..37c4cb4 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -308,9 +308,9 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                {
                    if (nValueCount >= 2)
                    {
                        long nCmpInc = 0;
                        tools::Long nCmpInc = 0;
                        FillDateCmd eType = FILL_YEAR;  // just some temporary default values
                        long nDDiff = 0, nMDiff = 0, nYDiff = 0; // to avoid warnings
                        tools::Long nDDiff = 0, nMDiff = 0, nYDiff = 0; // to avoid warnings
                        Date aNullDate = rDocument.GetFormatTable()->GetNullDate();
                        Date aCurrDate = aNullDate, aPrevDate = aNullDate;
                        aCurrDate.AddDays(aCurrCell.mfValue);
@@ -326,11 +326,11 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                                aCurrDate = aNullDate + static_cast<sal_Int32>(aCurrCell.mfValue);
                                if (eType != FILL_DAY) {
                                    nDDiff = aCurrDate.GetDay()
                                             - static_cast<long>(aPrevDate.GetDay());
                                             - static_cast<tools::Long>(aPrevDate.GetDay());
                                    nMDiff = aCurrDate.GetMonth()
                                             - static_cast<long>(aPrevDate.GetMonth());
                                             - static_cast<tools::Long>(aPrevDate.GetMonth());
                                    nYDiff = aCurrDate.GetYear()
                                             - static_cast<long>(aPrevDate.GetYear());
                                             - static_cast<tools::Long>(aPrevDate.GetYear());
                                }
                                if (i == 1)
                                {
@@ -447,11 +447,11 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                aDate2.AddDays(nVal);
                if ( aDate1 != aDate2 )
                {
                    long nCmpInc = 0;
                    tools::Long nCmpInc = 0;
                    FillDateCmd eType;
                    long nDDiff = aDate2.GetDay()   - static_cast<long>(aDate1.GetDay());
                    long nMDiff = aDate2.GetMonth() - static_cast<long>(aDate1.GetMonth());
                    long nYDiff = aDate2.GetYear()  - static_cast<long>(aDate1.GetYear());
                    tools::Long nDDiff = aDate2.GetDay()   - static_cast<tools::Long>(aDate1.GetDay());
                    tools::Long nMDiff = aDate2.GetMonth() - static_cast<tools::Long>(aDate1.GetMonth());
                    tools::Long nYDiff = aDate2.GetYear()  - static_cast<tools::Long>(aDate1.GetYear());
                    if ( nDDiff )
                    {
                        eType = FILL_DAY;
@@ -480,9 +480,9 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                            }
                            else
                            {
                                nDDiff = aDate2.GetDay()   - static_cast<long>(aDate1.GetDay());
                                nMDiff = aDate2.GetMonth() - static_cast<long>(aDate1.GetMonth());
                                nYDiff = aDate2.GetYear()  - static_cast<long>(aDate1.GetYear());
                                nDDiff = aDate2.GetDay()   - static_cast<tools::Long>(aDate1.GetDay());
                                nMDiff = aDate2.GetMonth() - static_cast<tools::Long>(aDate1.GetMonth());
                                nYDiff = aDate2.GetYear()  - static_cast<tools::Long>(aDate1.GetYear());
                                if (nDDiff || ( nMDiff + 12 * nYDiff != nCmpInc ))
                                    bVal = false;
                            }
@@ -1064,7 +1064,7 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
    SCCOL nCol2 = rSource.aEnd.Col();
    SCROW nRow2 = rSource.aEnd.Row();
    bool bOk = true;
    long nIndex = 0;
    tools::Long nIndex = 0;
    sal_uLong nSrcCount = 0;
    FillDir eFillDir = FILL_TO_BOTTOM;
    if ( nEndX == nCol2 && nEndY == nRow2 )     // empty
@@ -1073,7 +1073,7 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
    {
        nCol2 = nCol1;                          // use only first column
        nSrcCount = nRow2 - nRow1 + 1;
        nIndex = static_cast<long>(nEndY) - nRow1;         // can be negative
        nIndex = static_cast<tools::Long>(nEndY) - nRow1;         // can be negative
        if ( nEndY >= nRow1 )
            eFillDir = FILL_TO_BOTTOM;
        else
@@ -1083,7 +1083,7 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
    {
        nEndY = nRow2 = nRow1;                  // use only first row
        nSrcCount = nCol2 - nCol1 + 1;
        nIndex = static_cast<long>(nEndX) - nCol1;         // can be negative
        nIndex = static_cast<tools::Long>(nEndX) - nCol1;         // can be negative
        if ( nEndX >= nCol1 )
            eFillDir = FILL_TO_RIGHT;
        else
@@ -1126,8 +1126,8 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
        {
            if ((eFillDir == FILL_TO_BOTTOM)||(eFillDir == FILL_TO_TOP))
            {
                long nBegin = 0;
                long nEnd = 0;
                tools::Long nBegin = 0;
                tools::Long nEnd = 0;
                if (nEndY > nRow1)
                {
                    nBegin = nRow2+1;
@@ -1139,8 +1139,8 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
                    nEnd = nRow1 -1;
                }

                long nNonFiltered = CountNonFilteredRows(nBegin, nEnd);
                long nFiltered = nEnd + 1 - nBegin - nNonFiltered;
                tools::Long nNonFiltered = CountNonFilteredRows(nBegin, nEnd);
                tools::Long nFiltered = nEnd + 1 - nBegin - nNonFiltered;

                if (nIndex > 0)
                    nIndex = nIndex - nFiltered;
@@ -1148,7 +1148,7 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
                    nIndex = nIndex + nFiltered;
            }

            long nPosIndex = nIndex;
            tools::Long nPosIndex = nIndex;
            while ( nPosIndex < 0 )
                nPosIndex += nSrcCount;
            sal_uLong nPos = nPosIndex % nSrcCount;
@@ -1289,7 +1289,7 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
                    nIndex = -nIndex;
                    nInc = -nInc;
                }
                for (long i=0; i<nIndex; i++)
                for (tools::Long i=0; i<nIndex; i++)
                    IncDate( nStart, nDayOfMonth, nInc, eDateCmd );
            }

@@ -1341,7 +1341,7 @@ void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillD
    const sal_uInt16 nMinYear = 1583;
    const sal_uInt16 nMaxYear = 9956;

    long nInc = static_cast<long>(nStep);       // upper/lower limits ?
    tools::Long nInc = static_cast<tools::Long>(nStep);       // upper/lower limits ?
    Date aNullDate = rDocument.GetFormatTable()->GetNullDate();
    Date aDate = aNullDate;
    aDate.AddDays(rVal);
@@ -1371,8 +1371,8 @@ void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillD
            {
                if ( nDayOfMonth == 0 )
                    nDayOfMonth = aDate.GetDay();       // init
                long nMonth = aDate.GetMonth();
                long nYear = aDate.GetYear();
                tools::Long nMonth = aDate.GetMonth();
                tools::Long nYear = aDate.GetYear();

                nMonth += nInc;

@@ -1380,7 +1380,7 @@ void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillD
                {
                    if (nMonth > 12)
                    {
                        long nYAdd = (nMonth-1) / 12;
                        tools::Long nYAdd = (nMonth-1) / 12;
                        nMonth -= nYAdd * 12;
                        nYear += nYAdd;
                    }
@@ -1389,7 +1389,7 @@ void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillD
                {
                    if (nMonth < 1)
                    {
                        long nYAdd = 1 - nMonth / 12;       // positive
                        tools::Long nYAdd = 1 - nMonth / 12;       // positive
                        nMonth += nYAdd * 12;
                        nYear -= nYAdd;
                    }
@@ -1409,7 +1409,7 @@ void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillD
            break;
        case FILL_YEAR:
            {
                long nYear = aDate.GetYear();
                tools::Long nYear = aDate.GetYear();
                nYear += nInc;
                if ( nYear < nMinYear )
                    aDate = Date( 1,1, nMinYear );
@@ -2118,7 +2118,7 @@ void ScTable::FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                const double nStartVal = (eCellType == CELLTYPE_VALUE ? aSrcCell.mfValue :
                        aSrcCell.mpFormula->GetValue());
                double nVal = nStartVal;
                long nIndex = 0;
                tools::Long nIndex = 0;

                bool bError = false;
                bool bOverflow = false;
@@ -2222,7 +2222,7 @@ void ScTable::FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                {
                    const double nStartVal = static_cast<double>(nStringValue);
                    double nVal = nStartVal;
                    long nIndex = 0;
                    tools::Long nIndex = 0;
                    bool bError = false;
                    bool bOverflow = false;

diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 71e15e2..06465db 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -138,8 +138,8 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
         }
    }

    long nPageSizeX = aPageSizeTwips.Width();
    long nPageSizeY = aPageSizeTwips.Height();
    tools::Long nPageSizeX = aPageSizeTwips.Width();
    tools::Long nPageSizeY = aPageSizeTwips.Height();

        //  Beginning: Remove breaks

@@ -156,11 +156,11 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )

    bool bRepeatCol = ( nRepeatStartX != SCCOL_REPEAT_NONE );
    bool bColFound = false;
    long nSizeX = 0;
    tools::Long nSizeX = 0;
    for (SCCOL nX=nStartCol; nX<=nEndCol; nX++)
    {
        bool bStartOfPage = false;
        long nThisX = ColHidden(nX) ? 0 : mpColWidth->GetValue(nX);
        tools::Long nThisX = ColHidden(nX) ? 0 : mpColWidth->GetValue(nX);
        bool bManualBreak = HasColManualBreak(nX);
        if ( (nSizeX+nThisX > nPageSizeX) || (bManualBreak && !bSkipColBreaks) )
        {
@@ -192,7 +192,7 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
    // And set new page breaks.
    bool bRepeatRow = ( nRepeatStartY != SCROW_REPEAT_NONE );
    bool bRowFound = false;
    long nSizeY = 0;
    tools::Long nSizeY = 0;
    ScFlatBoolRowSegments::ForwardIterator aIterHidden(*mpHiddenRows);
    ScFlatUInt16RowSegments::ForwardIterator aIterHeights(*mpRowHeights);
    SCROW nNextManualBreak = GetNextManualBreak(nStartRow); // -1 => no more manual breaks
@@ -202,14 +202,14 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
        bool bThisRowHidden = false;
        const bool bHasValue = aIterHidden.getValue(nY, bThisRowHidden);
        assert(bHasValue); (void)bHasValue;
        long nThisY = 0;
        tools::Long nThisY = 0;
        if (!bThisRowHidden)
        {
            sal_uInt16 nTmp;
            const bool bHasHeight = aIterHeights.getValue(nY, nTmp);
            assert(bHasHeight);
            if (bHasHeight)
                nThisY = static_cast<long>(nTmp);
                nThisY = static_cast<tools::Long>(nTmp);
        }

        bool bManualBreak = false;
@@ -266,8 +266,8 @@ void ScTable::UpdatePageBreaks( const ScRange* pUserArea )

            if (nLastCommon > nY)
            {
                long nMaxMultiple = static_cast<long>(nLastCommon - nY);
                long nMultiple = (nPageSizeY - nSizeY) / nThisY;
                tools::Long nMaxMultiple = static_cast<tools::Long>(nLastCommon - nY);
                tools::Long nMultiple = (nPageSizeY - nSizeY) / nThisY;
                if (nMultiple > nMaxMultiple)
                    nMultiple = nMaxMultiple;
                if (nMultiple > 1)
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index fbc9ac2..daba608 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -71,8 +71,8 @@ ScUnoAddInFuncData::ScUnoAddInFuncData( const OUString& rNam, const OUString& rL
                                        sal_uInt16 nCat, const OString& sHelp,
                                        const uno::Reference<reflection::XIdlMethod>& rFunc,
                                        const uno::Any& rO,
                                        long nAC, const ScAddInArgDesc* pAD,
                                        long nCP ) :
                                        tools::Long nAC, const ScAddInArgDesc* pAD,
                                        tools::Long nCP ) :
    aOriginalName( rNam ),
    aLocalName( rLoc ),
    aUpperName( rNam ),
@@ -89,7 +89,7 @@ ScUnoAddInFuncData::ScUnoAddInFuncData( const OUString& rNam, const OUString& rL
    if ( nArgCount )
    {
        pArgDescs.reset( new ScAddInArgDesc[nArgCount] );
        for (long i=0; i<nArgCount; i++)
        for (tools::Long i=0; i<nArgCount; i++)
            pArgDescs[i] = pAD[i];
    }

@@ -194,20 +194,20 @@ void ScUnoAddInFuncData::SetFunction( const uno::Reference< reflection::XIdlMeth
    aObject = rNewObj;
}

void ScUnoAddInFuncData::SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs )
void ScUnoAddInFuncData::SetArguments( tools::Long nNewCount, const ScAddInArgDesc* pNewDescs )
{
    nArgCount = nNewCount;
    if ( nArgCount )
    {
        pArgDescs.reset( new ScAddInArgDesc[nArgCount] );
        for (long i=0; i<nArgCount; i++)
        for (tools::Long i=0; i<nArgCount; i++)
            pArgDescs[i] = pNewDescs[i];
    }
    else
        pArgDescs.reset();
}

void ScUnoAddInFuncData::SetCallerPos( long nNewPos )
void ScUnoAddInFuncData::SetCallerPos( tools::Long nNewPos )
{
    nCallerPos = nNewPos;
}
@@ -362,12 +362,12 @@ void ScUnoAddInCollection::ReadConfiguration()

        // allocate pointers

        long nOld = nFuncCount;
        tools::Long nOld = nFuncCount;
        nFuncCount = nNewCount+nOld;
        if ( nOld )
        {
            std::unique_ptr<std::unique_ptr<ScUnoAddInFuncData>[]> ppNew(new std::unique_ptr<ScUnoAddInFuncData>[nFuncCount]);
            for (long i=0; i<nOld; i++)
            for (tools::Long i=0; i<nOld; i++)
                ppNew[i] = std::move(ppFuncData[i]);
            ppFuncData = std::move(ppNew);
        }
@@ -449,7 +449,7 @@ void ScUnoAddInCollection::ReadConfiguration()
                // get argument info

                std::unique_ptr<ScAddInArgDesc[]> pVisibleArgs;
                long nVisibleCount = 0;
                tools::Long nVisibleCount = 0;

                OUString aArgumentsPath(aFuncPropPath + CFGSTR_PARAMETERS);

@@ -573,7 +573,7 @@ bool ScUnoAddInCollection::GetCalcName( const OUString& rExcelName, OUString& rR

    OUString aUpperCmp = ScGlobal::getCharClassPtr()->uppercase(rExcelName);

    for (long i=0; i<nFuncCount; i++)
    for (tools::Long i=0; i<nFuncCount; i++)
    {
        ScUnoAddInFuncData* pFuncData = ppFuncData[i].get();
        if ( pFuncData )
@@ -724,16 +724,16 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&

    uno::Sequence< uno::Reference<reflection::XIdlMethod> > aMethods =
            xAcc->getMethods( beans::MethodConcept::ALL );
    long nNewCount = aMethods.getLength();
    tools::Long nNewCount = aMethods.getLength();
    if ( !nNewCount )
        return;

    long nOld = nFuncCount;
    tools::Long nOld = nFuncCount;
    nFuncCount = nNewCount+nOld;
    if ( nOld )
    {
        std::unique_ptr<std::unique_ptr<ScUnoAddInFuncData>[]> ppNew(new std::unique_ptr<ScUnoAddInFuncData>[nFuncCount]);
        for (long i=0; i<nOld; i++)
        for (tools::Long i=0; i<nOld; i++)
            ppNew[i] = std::move(ppFuncData[i]);
        ppFuncData = std::move(ppNew);
    }
@@ -749,7 +749,7 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
        pLocalHashMap.reset( new ScAddInHashMap );

    const uno::Reference<reflection::XIdlMethod>* pArray = aMethods.getConstArray();
    for (long nFuncPos=0; nFuncPos<nNewCount; nFuncPos++)
    for (tools::Long nFuncPos=0; nFuncPos<nNewCount; nFuncPos++)
    {
        ppFuncData[nFuncPos+nOld] = nullptr;

@@ -789,14 +789,14 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
                OUString aFuncName = aServiceName + "." + aFuncU;

                bool bValid = true;
                long nVisibleCount = 0;
                long nCallerPos = SC_CALLERPOS_NONE;
                tools::Long nVisibleCount = 0;
                tools::Long nCallerPos = SC_CALLERPOS_NONE;

                uno::Sequence<reflection::ParamInfo> aParams =
                        xFunc->getParameterInfos();
                long nParamCount = aParams.getLength();
                tools::Long nParamCount = aParams.getLength();
                const reflection::ParamInfo* pParArr = aParams.getConstArray();
                long nParamPos;
                tools::Long nParamPos;
                for (nParamPos=0; nParamPos<nParamCount; nParamPos++)
                {
                    if ( pParArr[nParamPos].aMode != reflection::ParamMode_IN )
@@ -845,7 +845,7 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
                    {
                        ScAddInArgDesc aDesc;
                        pVisibleArgs.reset(new ScAddInArgDesc[nVisibleCount]);
                        long nDestPos = 0;
                        tools::Long nDestPos = 0;
                        for (nParamPos=0; nParamPos<nParamCount; nParamPos++)
                        {
                            uno::Reference<reflection::XIdlClass> xParClass =
@@ -932,9 +932,9 @@ static void lcl_UpdateFunctionList( const ScFunctionList& rFunctionList, const S

static const ScAddInArgDesc* lcl_FindArgDesc( const ScUnoAddInFuncData& rFuncData, const OUString& rArgIntName )
{
    long nArgCount = rFuncData.GetArgumentCount();
    tools::Long nArgCount = rFuncData.GetArgumentCount();
    const ScAddInArgDesc* pArguments = rFuncData.GetArguments();
    for (long nPos=0; nPos<nArgCount; nPos++)
    for (tools::Long nPos=0; nPos<nArgCount; nPos++)
    {
        if ( pArguments[nPos].aInternalName == rArgIntName )
            return &pArguments[nPos];
@@ -994,14 +994,14 @@ void ScUnoAddInCollection::UpdateFromAddIn( const uno::Reference<uno::XInterface
                // internal argument name.

                bool bValid = true;
                long nVisibleCount = 0;
                long nCallerPos = SC_CALLERPOS_NONE;
                tools::Long nVisibleCount = 0;
                tools::Long nCallerPos = SC_CALLERPOS_NONE;

                const uno::Sequence<reflection::ParamInfo> aParams =
                        xFunc->getParameterInfos();
                long nParamCount = aParams.getLength();
                tools::Long nParamCount = aParams.getLength();
                const reflection::ParamInfo* pParArr = aParams.getConstArray();
                for (long nParamPos=0; nParamPos<nParamCount; nParamPos++)
                for (tools::Long nParamPos=0; nParamPos<nParamCount; nParamPos++)
                {
                    if ( pParArr[nParamPos].aMode != reflection::ParamMode_IN )
                        bValid = false;
@@ -1022,7 +1022,7 @@ void ScUnoAddInCollection::UpdateFromAddIn( const uno::Reference<uno::XInterface
                    {
                        ScAddInArgDesc aDesc;
                        pVisibleArgs.reset(new ScAddInArgDesc[nVisibleCount]);
                        long nDestPos = 0;
                        tools::Long nDestPos = 0;
                        for (const auto& rParam : aParams)
                        {
                            uno::Reference<reflection::XIdlClass> xParClass =
@@ -1123,7 +1123,7 @@ const ScUnoAddInFuncData* ScUnoAddInCollection::GetFuncData( const OUString& rNa
    return nullptr;
}

const ScUnoAddInFuncData* ScUnoAddInCollection::GetFuncData( long nIndex )
const ScUnoAddInFuncData* ScUnoAddInCollection::GetFuncData( tools::Long nIndex )
{
    if (!bInitialized)
        Initialize();
@@ -1145,7 +1145,7 @@ void ScUnoAddInCollection::LocalizeString( OUString& rName )
        rName = iLook->second->GetUpperLocal();         //TODO: upper?
}

long ScUnoAddInCollection::GetFuncCount()
tools::Long ScUnoAddInCollection::GetFuncCount()
{
    if (!bInitialized)
        Initialize();
@@ -1153,7 +1153,7 @@ long ScUnoAddInCollection::GetFuncCount()
    return nFuncCount;
}

bool ScUnoAddInCollection::FillFunctionDesc( long nFunc, ScFuncDesc& rDesc )
bool ScUnoAddInCollection::FillFunctionDesc( tools::Long nFunc, ScFuncDesc& rDesc )
{
    if (!bInitialized)
        Initialize();
@@ -1172,7 +1172,7 @@ bool ScUnoAddInCollection::FillFunctionDescFromData( const ScUnoAddInFuncData& r

    bool bIncomplete = !rFuncData.GetFunction().is();       //TODO: extra flag?

    long nArgCount = rFuncData.GetArgumentCount();
    tools::Long nArgCount = rFuncData.GetArgumentCount();
    if ( nArgCount > SAL_MAX_UINT16 )
        return false;

@@ -1203,7 +1203,7 @@ bool ScUnoAddInCollection::FillFunctionDescFromData( const ScUnoAddInFuncData& r
        rDesc.maDefArgDescs.clear();
        rDesc.maDefArgDescs.resize(nArgCount);
        rDesc.pDefArgFlags   = new ScFuncDesc::ParameterFlags[nArgCount];
        for ( long nArg=0; nArg<nArgCount; nArg++ )
        for ( tools::Long nArg=0; nArg<nArgCount; nArg++ )
        {
            rDesc.maDefArgNames[nArg] = pArgs[nArg].aName;
            rDesc.maDefArgDescs[nArg] = pArgs[nArg].aDescription;
@@ -1231,7 +1231,7 @@ bool ScUnoAddInCollection::FillFunctionDescFromData( const ScUnoAddInFuncData& r
}

ScUnoAddInCall::ScUnoAddInCall( ScUnoAddInCollection& rColl, const OUString& rName,
                                long nParamCount ) :
                                tools::Long nParamCount ) :
    bValidCount( false ),
    nErrCode( FormulaError::NoCode ),      // before function was called
    bHasString( true ),
@@ -1243,14 +1243,14 @@ ScUnoAddInCall::ScUnoAddInCall( ScUnoAddInCollection& rColl, const OUString& rNa
    if ( !pFuncData )
        return;

    long nDescCount = pFuncData->GetArgumentCount();
    tools::Long nDescCount = pFuncData->GetArgumentCount();
    const ScAddInArgDesc* pArgs = pFuncData->GetArguments();

    //  is aVarArg sequence needed?
    if ( nParamCount >= nDescCount && nDescCount > 0 &&
         pArgs[nDescCount-1].eType == SC_ADDINARG_VARARGS )
    {
        long nVarCount = nParamCount - ( nDescCount - 1 );  // size of last argument
        tools::Long nVarCount = nParamCount - ( nDescCount - 1 );  // size of last argument
        aVarArg.realloc( nVarCount );
        bValidCount = true;
    }
@@ -1258,7 +1258,7 @@ ScUnoAddInCall::ScUnoAddInCall( ScUnoAddInCollection& rColl, const OUString& rNa
    {
        //  all args behind nParamCount must be optional
        bValidCount = true;
        for (long i=nParamCount; i<nDescCount; i++)
        for (tools::Long i=nParamCount; i<nDescCount; i++)
            if ( !pArgs[i].bOptional )
                bValidCount = false;
    }
@@ -1273,11 +1273,11 @@ ScUnoAddInCall::~ScUnoAddInCall()
    // pFuncData is deleted with ScUnoAddInCollection
}

ScAddInArgumentType ScUnoAddInCall::GetArgType( long nPos )
ScAddInArgumentType ScUnoAddInCall::GetArgType( tools::Long nPos )
{
    if ( pFuncData )
    {
        long nCount = pFuncData->GetArgumentCount();
        tools::Long nCount = pFuncData->GetArgumentCount();
        const ScAddInArgDesc* pArgs = pFuncData->GetArguments();

        // if last arg is sequence, use "any" type
@@ -1309,16 +1309,16 @@ void ScUnoAddInCall::SetCallerFromObjectShell( const SfxObjectShell* pObjSh )
    }
}

void ScUnoAddInCall::SetParam( long nPos, const uno::Any& rValue )
void ScUnoAddInCall::SetParam( tools::Long nPos, const uno::Any& rValue )
{
    if ( !pFuncData )
        return;

    long nCount = pFuncData->GetArgumentCount();
    tools::Long nCount = pFuncData->GetArgumentCount();
    const ScAddInArgDesc* pArgs = pFuncData->GetArguments();
    if ( nCount > 0 && nPos >= nCount-1 && pArgs[nCount-1].eType == SC_ADDINARG_VARARGS )
    {
        long nVarPos = nPos-(nCount-1);
        tools::Long nVarPos = nPos-(nCount-1);
        if ( nVarPos < aVarArg.getLength() )
            aVarArg.getArray()[nVarPos] = rValue;
        else
@@ -1339,7 +1339,7 @@ void ScUnoAddInCall::ExecuteCall()
    if ( !pFuncData )
        return;

    long nCount = pFuncData->GetArgumentCount();
    tools::Long nCount = pFuncData->GetArgumentCount();
    const ScAddInArgDesc* pArgs = pFuncData->GetArguments();
    if ( nCount > 0 && pArgs[nCount-1].eType == SC_ADDINARG_VARARGS )
    {
@@ -1355,15 +1355,15 @@ void ScUnoAddInCall::ExecuteCall()
        uno::Any aCallerAny;
        aCallerAny <<= xCaller;

        long nUserLen = aArgs.getLength();
        long nCallPos = pFuncData->GetCallerPos();
        tools::Long nUserLen = aArgs.getLength();
        tools::Long nCallPos = pFuncData->GetCallerPos();
        if (nCallPos>nUserLen)                          // should not happen
        {
            OSL_FAIL("wrong CallPos");
            nCallPos = nUserLen;
        }

        long nDestLen = nUserLen + 1;
        tools::Long nDestLen = nUserLen + 1;
        uno::Sequence<uno::Any> aRealArgs( nDestLen );
        uno::Any* pDest = aRealArgs.getArray();

@@ -1424,7 +1424,7 @@ void ScUnoAddInCall::ExecuteCallWithArgs(uno::Sequence<uno::Any>& rCallArgs)
}

template <typename T>
static long lcl_GetMaxColCount(const uno::Sequence< uno::Sequence<T> >* pRowSeq)
static tools::Long lcl_GetMaxColCount(const uno::Sequence< uno::Sequence<T> >* pRowSeq)
{
    if (!pRowSeq->hasElements())
        return 0;
@@ -1499,23 +1499,23 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )

                if ( pRowSeq )
                {
                    long nRowCount = pRowSeq->getLength();
                    long nMaxColCount = lcl_GetMaxColCount(pRowSeq);
                    tools::Long nRowCount = pRowSeq->getLength();
                    tools::Long nMaxColCount = lcl_GetMaxColCount(pRowSeq);
                    if ( nMaxColCount && nRowCount )
                    {
                        const uno::Sequence<sal_Int32>* pRowArr = pRowSeq->getConstArray();
                        xMatrix = new ScMatrix(
                                static_cast<SCSIZE>(nMaxColCount),
                                static_cast<SCSIZE>(nRowCount), 0.0);
                        for (long nRow=0; nRow<nRowCount; nRow++)
                        for (tools::Long nRow=0; nRow<nRowCount; nRow++)
                        {
                            long nColCount = pRowArr[nRow].getLength();
                            tools::Long nColCount = pRowArr[nRow].getLength();
                            const sal_Int32* pColArr = pRowArr[nRow].getConstArray();
                            for (long nCol=0; nCol<nColCount; nCol++)
                            for (tools::Long nCol=0; nCol<nColCount; nCol++)
                                xMatrix->PutDouble( pColArr[nCol],
                                        static_cast<SCSIZE>(nCol),
                                        static_cast<SCSIZE>(nRow) );
                            for (long nCol=nColCount; nCol<nMaxColCount; nCol++)
                            for (tools::Long nCol=nColCount; nCol<nMaxColCount; nCol++)
                                xMatrix->PutDouble( 0.0,
                                        static_cast<SCSIZE>(nCol),
                                        static_cast<SCSIZE>(nRow) );
@@ -1534,23 +1534,23 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )

                if ( pRowSeq )
                {
                    long nRowCount = pRowSeq->getLength();
                    long nMaxColCount = lcl_GetMaxColCount(pRowSeq);
                    tools::Long nRowCount = pRowSeq->getLength();
                    tools::Long nMaxColCount = lcl_GetMaxColCount(pRowSeq);
                    if ( nMaxColCount && nRowCount )
                    {
                        const uno::Sequence<double>* pRowArr = pRowSeq->getConstArray();
                        xMatrix = new ScMatrix(
                                static_cast<SCSIZE>(nMaxColCount),
                                static_cast<SCSIZE>(nRowCount), 0.0);
                        for (long nRow=0; nRow<nRowCount; nRow++)
                        for (tools::Long nRow=0; nRow<nRowCount; nRow++)
                        {
                            long nColCount = pRowArr[nRow].getLength();
                            tools::Long nColCount = pRowArr[nRow].getLength();
                            const double* pColArr = pRowArr[nRow].getConstArray();
                            for (long nCol=0; nCol<nColCount; nCol++)
                            for (tools::Long nCol=0; nCol<nColCount; nCol++)
                                xMatrix->PutDouble( pColArr[nCol],
                                        static_cast<SCSIZE>(nCol),
                                        static_cast<SCSIZE>(nRow) );
                            for (long nCol=nColCount; nCol<nMaxColCount; nCol++)
                            for (tools::Long nCol=nColCount; nCol<nMaxColCount; nCol++)
                                xMatrix->PutDouble( 0.0,
                                        static_cast<SCSIZE>(nCol),
                                        static_cast<SCSIZE>(nRow) );
@@ -1569,25 +1569,25 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )

                if ( pRowSeq )
                {
                    long nRowCount = pRowSeq->getLength();
                    long nMaxColCount = lcl_GetMaxColCount(pRowSeq);
                    tools::Long nRowCount = pRowSeq->getLength();
                    tools::Long nMaxColCount = lcl_GetMaxColCount(pRowSeq);
                    if ( nMaxColCount && nRowCount )
                    {
                        const uno::Sequence<OUString>* pRowArr = pRowSeq->getConstArray();
                        xMatrix = new ScMatrix(
                                static_cast<SCSIZE>(nMaxColCount),
                                static_cast<SCSIZE>(nRowCount), 0.0);
                        for (long nRow=0; nRow<nRowCount; nRow++)
                        for (tools::Long nRow=0; nRow<nRowCount; nRow++)
                        {
                            long nColCount = pRowArr[nRow].getLength();
                            tools::Long nColCount = pRowArr[nRow].getLength();
                            const OUString* pColArr = pRowArr[nRow].getConstArray();
                            for (long nCol=0; nCol<nColCount; nCol++)
                            for (tools::Long nCol=0; nCol<nColCount; nCol++)
                            {
                                xMatrix->PutString(
                                    svl::SharedString(pColArr[nCol]),
                                    static_cast<SCSIZE>(nCol), static_cast<SCSIZE>(nRow));
                            }
                            for (long nCol=nColCount; nCol<nMaxColCount; nCol++)
                            for (tools::Long nCol=nColCount; nCol<nMaxColCount; nCol++)
                            {
                                xMatrix->PutString(
                                    svl::SharedString(EMPTY_OUSTRING),
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 0a75ff0..a1cae3f 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -133,9 +133,9 @@ const sal_Unicode* parseQuotedName( const sal_Unicode* p, OUString& rName )

}

static long int sal_Unicode_strtol ( const sal_Unicode*  p, const sal_Unicode** pEnd )
static tools::Long sal_Unicode_strtol ( const sal_Unicode*  p, const sal_Unicode** pEnd )
{
    long int accum = 0, prev = 0;
    tools::Long accum = 0, prev = 0;
    bool is_neg = false;

    if( *p == '-' )
@@ -660,7 +660,7 @@ static const sal_Unicode* lcl_r1c1_get_col( const sal_Unicode* p,
                                            ScAddress* pAddr, ScRefFlags* nFlags )
{
    const sal_Unicode *pEnd;
    long int n;
    tools::Long n;
    bool isRelative;

    if( p[0] == '\0' )
@@ -708,7 +708,7 @@ static const sal_Unicode* lcl_r1c1_get_row(
                                    ScAddress* pAddr, ScRefFlags* nFlags )
{
    const sal_Unicode *pEnd;
    long int n;
    tools::Long n;
    bool isRelative;

    if( p[0] == '\0' )
@@ -941,7 +941,7 @@ static const sal_Unicode* lcl_a1_get_row( const ScDocument& rDoc,
                                                 const OUString* pErrRef )
{
    const sal_Unicode *pEnd;
    long int n;
    tools::Long n;

    if( *p == '$' )
    {
@@ -1330,7 +1330,7 @@ static ScRefFlags lcl_ScAddress_Parse_OOo( const sal_Unicode* p, const ScDocumen
            }
            else
            {
                long n = rtl_ustr_toInt32( p, 10 ) - 1;
                tools::Long n = rtl_ustr_toInt32( p, 10 ) - 1;
                while (rtl::isAsciiDigit( *p ))
                    p++;
                const SCROW nMaxRow = rDoc.MaxRow();
diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx
index f66134c..d3b56af 100644
--- a/sc/source/core/tool/appoptio.cxx
+++ b/sc/source/core/tool/appoptio.cxx
@@ -145,13 +145,13 @@ static void lcl_SetLastFunctions( ScAppOptions& rOpt, const Any& rValue )

static void lcl_GetLastFunctions( Any& rDest, const ScAppOptions& rOpt )
{
    long nCount = rOpt.GetLRUFuncListCount();
    tools::Long nCount = rOpt.GetLRUFuncListCount();
    sal_uInt16* pUShorts = rOpt.GetLRUFuncList();
    if ( nCount && pUShorts )
    {
        Sequence<sal_Int32> aSeq( nCount );
        sal_Int32* pArray = aSeq.getArray();
        for (long i=0; i<nCount; i++)
        for (tools::Long i=0; i<nCount; i++)
            pArray[i] = pUShorts[i];
        rDest <<= aSeq;
    }
@@ -165,7 +165,7 @@ static void lcl_SetSortList( const Any& rValue )
    if ( !(rValue >>= aSeq) )
        return;

    long nCount = aSeq.getLength();
    tools::Long nCount = aSeq.getLength();
    const OUString* pArray = aSeq.getConstArray();
    ScUserList aList;

diff --git a/sc/source/core/tool/autoform.cxx b/sc/source/core/tool/autoform.cxx
index 073c17f..699c8ce 100644
--- a/sc/source/core/tool/autoform.cxx
+++ b/sc/source/core/tool/autoform.cxx
@@ -856,7 +856,7 @@ void ScAutoFormat::Load()
                    (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
            {
                sal_uInt8 nChrSet, nCnt;
                long nPos = rStream.Tell();
                tools::Long nPos = rStream.Tell();
                rStream.ReadUChar( nCnt ).ReadUChar( nChrSet );
                if( rStream.Tell() != sal_uLong(nPos + nCnt) )
                {
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index e235e19..97a9bf2 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -139,8 +139,8 @@ void ScCompiler::fillFromAddInMap( const NonConstOpCodeMapPtr& xMap,FormulaGramm
void ScCompiler::fillFromAddInCollectionUpperName( const NonConstOpCodeMapPtr& xMap ) const
{
    ScUnoAddInCollection* pColl = ScGlobal::GetAddInCollection();
    long nCount = pColl->GetFuncCount();
    for (long i=0; i < nCount; ++i)
    tools::Long nCount = pColl->GetFuncCount();
    for (tools::Long i=0; i < nCount; ++i)
    {
        const ScUnoAddInFuncData* pFuncData = pColl->GetFuncData(i);
        if (pFuncData)
@@ -152,8 +152,8 @@ void ScCompiler::fillFromAddInCollectionUpperName( const NonConstOpCodeMapPtr& x
void ScCompiler::fillFromAddInCollectionEnglishName( const NonConstOpCodeMapPtr& xMap ) const
{
    ScUnoAddInCollection* pColl = ScGlobal::GetAddInCollection();
    long nCount = pColl->GetFuncCount();
    for (long i=0; i < nCount; ++i)
    tools::Long nCount = pColl->GetFuncCount();
    for (tools::Long i=0; i < nCount; ++i)
    {
        const ScUnoAddInFuncData* pFuncData = pColl->GetFuncData(i);
        if (pFuncData)
@@ -3650,9 +3650,9 @@ bool ScCompiler::IsColRowName( const OUString& rName )
    }
    if ( !bInList && rDoc.GetDocOptions().IsLookUpColRowNames() )
    {   // search in current sheet
        long nDistance = 0, nMax = 0;
        long nMyCol = static_cast<long>(aPos.Col());
        long nMyRow = static_cast<long>(aPos.Row());
        tools::Long nDistance = 0, nMax = 0;
        tools::Long nMyCol = static_cast<tools::Long>(aPos.Col());
        tools::Long nMyRow = static_cast<tools::Long>(aPos.Row());
        bool bTwo = false;
        ScAddress aOne( 0, 0, aPos.Tab() );
        ScAddress aTwo( rDoc.MaxCol(), rDoc.MaxRow(), aPos.Tab() );
@@ -3672,7 +3672,7 @@ bool ScCompiler::IsColRowName( const OUString& rName )
            {
                if ( bFound )
                {   // stop if everything else is further away
                    if ( nMax < static_cast<long>(aAddress.Col()) )
                    if ( nMax < static_cast<tools::Long>(aAddress.Col()) )
                        break;      // aIter
                }
                if ( aAddress != aPos )
@@ -3681,11 +3681,11 @@ bool ScCompiler::IsColRowName( const OUString& rName )

                    SCCOL nCol = aAddress.Col();
                    SCROW nRow = aAddress.Row();
                    long nC = nMyCol - nCol;
                    long nR = nMyRow - nRow;
                    tools::Long nC = nMyCol - nCol;
                    tools::Long nR = nMyRow - nRow;
                    if ( bFound )
                    {
                        long nD = nC * nC + nR * nR;
                        tools::Long nD = nC * nC + nR * nR;
                        if ( nD < nDistance )
                        {
                            if ( nC < 0 || nR < 0 )
@@ -3695,7 +3695,7 @@ bool ScCompiler::IsColRowName( const OUString& rName )
                                nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
                                nDistance = nD;
                            }
                            else if ( nRow >= aOne.Row() || nMyRow < static_cast<long>(aOne.Row()) )
                            else if ( nRow >= aOne.Row() || nMyRow < static_cast<tools::Long>(aOne.Row()) )
                            {
                                // upper left, only if not further up than the
                                // current entry and nMyRow is below (CellIter
@@ -3725,7 +3725,7 @@ bool ScCompiler::IsColRowName( const OUString& rName )
            {
                if ( bFound )
                {   // stop if everything else is further away
                    if ( nMax < static_cast<long>(aIter.GetPos().Col()) )
                    if ( nMax < static_cast<tools::Long>(aIter.GetPos().Col()) )
                        break;      // aIter
                }
                CellType eType = aIter.getType();
@@ -3745,11 +3745,11 @@ bool ScCompiler::IsColRowName( const OUString& rName )
                    {
                        SCCOL nCol = aIter.GetPos().Col();
                        SCROW nRow = aIter.GetPos().Row();
                        long nC = nMyCol - nCol;
                        long nR = nMyRow - nRow;
                        tools::Long nC = nMyCol - nCol;
                        tools::Long nR = nMyRow - nRow;
                        if ( bFound )
                        {
                            long nD = nC * nC + nR * nR;
                            tools::Long nD = nC * nC + nR * nR;
                            if ( nD < nDistance )
                            {
                                if ( nC < 0 || nR < 0 )
@@ -3759,7 +3759,7 @@ bool ScCompiler::IsColRowName( const OUString& rName )
                                    nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
                                    nDistance = nD;
                                }
                                else if ( nRow >= aOne.Row() || nMyRow < static_cast<long>(aOne.Row()) )
                                else if ( nRow >= aOne.Row() || nMyRow < static_cast<tools::Long>(aOne.Row()) )
                                {
                                    // upper left, only if not further up than the
                                    // current entry and nMyRow is below (CellIter
@@ -3788,23 +3788,23 @@ bool ScCompiler::IsColRowName( const OUString& rName )
            ScAddress aAdr;
            if ( bTwo )
            {
                if ( nMyCol >= static_cast<long>(aOne.Col()) && nMyRow >= static_cast<long>(aOne.Row()) )
                if ( nMyCol >= static_cast<tools::Long>(aOne.Col()) && nMyRow >= static_cast<tools::Long>(aOne.Row()) )
                    aAdr = aOne;        // upper left takes precedence
                else
                {
                    if ( nMyCol < static_cast<long>(aOne.Col()) )
                    if ( nMyCol < static_cast<tools::Long>(aOne.Col()) )
                    {   // two to the right
                        if ( nMyRow >= static_cast<long>(aTwo.Row()) )
                        if ( nMyRow >= static_cast<tools::Long>(aTwo.Row()) )
                            aAdr = aTwo;        // directly right
                        else
                            aAdr = aOne;
                    }
                    else
                    {   // two below or below and right, take the nearest
                        long nC1 = nMyCol - aOne.Col();
                        long nR1 = nMyRow - aOne.Row();
                        long nC2 = nMyCol - aTwo.Col();
                        long nR2 = nMyRow - aTwo.Row();
                        tools::Long nC1 = nMyCol - aOne.Col();
                        tools::Long nR1 = nMyRow - aOne.Row();
                        tools::Long nC2 = nMyCol - aTwo.Col();
                        tools::Long nR2 = nMyRow - aTwo.Row();
                        if ( nC1 * nC1 + nR1 * nR1 <= nC2 * nC2 + nR2 * nR2 )
                            aAdr = aOne;
                        else
@@ -5377,8 +5377,8 @@ void ScCompiler::fillAddInToken(::std::vector< css::sheet::FormulaOpCodeMapEntry
    aEntry.Token.OpCode = ocExternal;

    ScUnoAddInCollection* pColl = ScGlobal::GetAddInCollection();
    const long nCount = pColl->GetFuncCount();
    for (long i=0; i < nCount; ++i)
    const tools::Long nCount = pColl->GetFuncCount();
    for (tools::Long i=0; i < nCount; ++i)
    {
        const ScUnoAddInFuncData* pFuncData = pColl->GetFuncData(i);
        if (pFuncData)
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index 57295be..5a6a284 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -344,11 +344,11 @@ void ScDBData::SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW 

void ScDBData::MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
{
    long nDifX = static_cast<long>(nCol1) - static_cast<long>(nStartCol);
    long nDifY = static_cast<long>(nRow1) - static_cast<long>(nStartRow);
    tools::Long nDifX = static_cast<tools::Long>(nCol1) - static_cast<tools::Long>(nStartCol);
    tools::Long nDifY = static_cast<tools::Long>(nRow1) - static_cast<tools::Long>(nStartRow);

    long nSortDif = bByRow ? nDifX : nDifY;
    long nSortEnd = bByRow ? static_cast<long>(nCol2) : static_cast<long>(nRow2);
    tools::Long nSortDif = bByRow ? nDifX : nDifY;
    tools::Long nSortEnd = bByRow ? static_cast<tools::Long>(nCol2) : static_cast<tools::Long>(nRow2);

    for (sal_uInt16 i=0; i<mpSortParam->GetSortKeyCount(); i++)
    {
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index 823f433..b008cec 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -334,8 +334,8 @@ Point ScDetectiveFunc::GetDrawPos( SCCOL nCol, SCROW nRow, DrawPosMode eMode ) c
        aPos.AdjustX(rDoc.GetColWidth( i, nTab ) );
    aPos.AdjustY(rDoc.GetRowHeight( 0, nRow - 1, nTab ) );

    aPos.setX( static_cast< long >( aPos.X() * HMM_PER_TWIPS ) );
    aPos.setY( static_cast< long >( aPos.Y() * HMM_PER_TWIPS ) );
    aPos.setX( static_cast< tools::Long >( aPos.X() * HMM_PER_TWIPS ) );
    aPos.setY( static_cast< tools::Long >( aPos.Y() * HMM_PER_TWIPS ) );

    if ( rDoc.IsNegativePage( nTab ) )
        aPos.setX( aPos.X() * -1 );
@@ -483,7 +483,7 @@ void ScDetectiveFunc::InsertArrow( SCCOL nCol, SCROW nRow,
    if (bFromOtherTab)
    {
        bool bNegativePage = rDoc.IsNegativePage( nTab );
        long nPageSign = bNegativePage ? -1 : 1;
        tools::Long nPageSign = bNegativePage ? -1 : 1;

        aStartPos = Point( aEndPos.X() - 1000 * nPageSign, aEndPos.Y() - 1000 );
        if (aStartPos.X() * nPageSign < 0)
@@ -555,7 +555,7 @@ void ScDetectiveFunc::InsertToOtherTab( SCCOL nStartCol, SCROW nStartRow,
    }

    bool bNegativePage = rDoc.IsNegativePage( nTab );
    long nPageSign = bNegativePage ? -1 : 1;
    tools::Long nPageSign = bNegativePage ? -1 : 1;

    Point aStartPos = GetDrawPos( nStartCol, nStartRow, DrawPosMode::DetectiveArrow );
    Point aEndPos( aStartPos.X() + 1000 * nPageSign, aStartPos.Y() - 1000 );
@@ -1360,7 +1360,7 @@ bool ScDetectiveFunc::MarkInvalid(bool& rOverflow)
    bool bDeleted = DeleteAll( ScDetectiveDelete::Circles );        // just circles

    ScDetectiveData aData( pModel );
    long nInsCount = 0;
    tools::Long nInsCount = 0;

    //  search for valid places
    ScDocAttrIterator aAttrIter( rDoc, nTab, 0,0,rDoc.MaxCol(),rDoc.MaxRow() );
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index cc1233b..d415e08 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -293,31 +293,31 @@ tools::Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, bool bF
    Point aStartPos = aCellPos;

    bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    const ScMergeAttr* pMerge = &pPattern->GetItem(ATTR_MERGE);
    long nCellX = pDoc->GetColWidth(nCol,nTab);
    tools::Long nCellX = pDoc->GetColWidth(nCol,nTab);
    if (!bInPrintTwips)
        nCellX = static_cast<long>( nCellX * nPPTX );
        nCellX = static_cast<tools::Long>( nCellX * nPPTX );
    if ( pMerge->GetColMerge() > 1 )
    {
        SCCOL nCountX = pMerge->GetColMerge();
        for (SCCOL i=1; i<nCountX; i++)
        {
            long nColWidth = pDoc->GetColWidth(nCol+i,nTab);
            nCellX += (bInPrintTwips ? nColWidth : static_cast<long>( nColWidth * nPPTX ));
            tools::Long nColWidth = pDoc->GetColWidth(nCol+i,nTab);
            nCellX += (bInPrintTwips ? nColWidth : static_cast<tools::Long>( nColWidth * nPPTX ));
        }
    }
    long nCellY = pDoc->GetRowHeight(nRow,nTab);
    tools::Long nCellY = pDoc->GetRowHeight(nRow,nTab);
    if (!bInPrintTwips)
        nCellY = static_cast<long>( nCellY * nPPTY );
        nCellY = static_cast<tools::Long>( nCellY * nPPTY );
    if ( pMerge->GetRowMerge() > 1 )
    {
        SCROW nCountY = pMerge->GetRowMerge();
        if (bInPrintTwips)
            nCellY += pDoc->GetRowHeight(nRow + 1, nRow + nCountY - 1, nTab);
        else
            nCellY += static_cast<long>(pDoc->GetScaledRowHeight( nRow+1, nRow+nCountY-1, nTab, nPPTY));
            nCellY += static_cast<tools::Long>(pDoc->GetScaledRowHeight( nRow+1, nRow+nCountY-1, nTab, nPPTY));
    }

    const SvxMarginItem* pMargin = &pPattern->GetItem(ATTR_MARGIN);
@@ -325,19 +325,19 @@ tools::Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, bool bF
    if ( pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue() ==
                SvxCellHorJustify::Left )
        nIndent = pPattern->GetItem(ATTR_INDENT).GetValue();
    long nDifX = pMargin->GetLeftMargin() + nIndent;
    tools::Long nDifX = pMargin->GetLeftMargin() + nIndent;
    if (!bInPrintTwips)
        nDifX = static_cast<long>( nDifX * nPPTX );
        nDifX = static_cast<tools::Long>( nDifX * nPPTX );
    aStartPos.AdjustX(nDifX * nLayoutSign );
    nCellX -= nDifX + (bInPrintTwips ? pMargin->GetRightMargin() :
            static_cast<long>( pMargin->GetRightMargin() * nPPTX ));     // due to line feed, etc.
            static_cast<tools::Long>( pMargin->GetRightMargin() * nPPTX ));     // due to line feed, etc.

    //  align vertical position to the one in the table

    long nDifY;
    long nTopMargin = pMargin->GetTopMargin();
    tools::Long nDifY;
    tools::Long nTopMargin = pMargin->GetTopMargin();
    if (!bInPrintTwips)
        nTopMargin = static_cast<long>( nTopMargin * nPPTY );
        nTopMargin = static_cast<tools::Long>( nTopMargin * nPPTY );
    SvxCellVerJustify eJust = pPattern->GetItem(ATTR_VER_JUSTIFY).GetValue();

    //  asian vertical is always edited top-aligned
@@ -352,7 +352,7 @@ tools::Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, bool bF
        MapMode aMode = pDev->GetMapMode();
        pDev->SetMapMode(MapMode(bInPrintTwips ? MapUnit::MapTwip : MapUnit::MapPixel));

        long nTextHeight = pDoc->GetNeededSize( nCol, nRow, nTab,
        tools::Long nTextHeight = pDoc->GetNeededSize( nCol, nRow, nTab,
                                                pDev, nPPTX, nPPTY, aZoomX, aZoomY, false /* bWidth */,
                                                false /* bTotalSize */, bInPrintTwips );
        if (!nTextHeight)
@@ -363,7 +363,7 @@ tools::Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, bool bF
            pDev->SetFont(aFont);
            nTextHeight = pDev->GetTextHeight() + nTopMargin +
                            (bInPrintTwips ? pMargin->GetBottomMargin() :
                                static_cast<long>( pMargin->GetBottomMargin() * nPPTY ));
                                static_cast<tools::Long>( pMargin->GetBottomMargin() * nPPTY ));
        }

        pDev->SetMapMode(aMode);
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 9eeddab..3268efd 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -2363,7 +2363,7 @@ void ScInterpreter::ScCell()
            // font color doesn't matter here
            mrDoc.GetDefPattern()->GetFont( aDefFont, SC_AUTOCOL_BLACK, pPrinter );
            pPrinter->SetFont( aDefFont );
            long nZeroWidth = pPrinter->GetTextWidth( OUString( '0' ) );
            tools::Long nZeroWidth = pPrinter->GetTextWidth( OUString( '0' ) );
            pPrinter->SetFont( aOldFont );
            pPrinter->SetMapMode( aOldMode );
            int nZeroCount = static_cast<int>(mrDoc.GetColWidth( aCellPos.Col(), aCellPos.Tab() ) / nZeroWidth);
@@ -8387,8 +8387,8 @@ void ScInterpreter::ScOffset()
        PopSingleRef(nCol1, nRow1, nTab1);
        if (!bNewWidth && !bNewHeight)
        {
            nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1) + nColPlus);
            nRow1 = static_cast<SCROW>(static_cast<long>(nRow1) + nRowPlus);
            nCol1 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1) + nColPlus);
            nRow1 = static_cast<SCROW>(static_cast<tools::Long>(nRow1) + nRowPlus);
            if (!mrDoc.ValidCol(nCol1) || !mrDoc.ValidRow(nRow1))
                PushIllegalArgument();
            else
@@ -8396,10 +8396,10 @@ void ScInterpreter::ScOffset()
        }
        else
        {
            nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColPlus);
            nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus);
            nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1);
            nRow2 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowNew-1);
            nCol1 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1)+nColPlus);
            nRow1 = static_cast<SCROW>(static_cast<tools::Long>(nRow1)+nRowPlus);
            nCol2 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1)+nColNew-1);
            nRow2 = static_cast<SCROW>(static_cast<tools::Long>(nRow1)+nRowNew-1);
            if (!mrDoc.ValidCol(nCol1) || !mrDoc.ValidRow(nRow1) ||
                !mrDoc.ValidCol(nCol2) || !mrDoc.ValidRow(nRow2))
                PushIllegalArgument();
@@ -8421,8 +8421,8 @@ void ScInterpreter::ScOffset()

        if (!bNewWidth && !bNewHeight)
        {
            nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1) + nColPlus);
            nRow1 = static_cast<SCROW>(static_cast<long>(nRow1) + nRowPlus);
            nCol1 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1) + nColPlus);
            nRow1 = static_cast<SCROW>(static_cast<tools::Long>(nRow1) + nRowPlus);
            if (!mrDoc.ValidCol(nCol1) || !mrDoc.ValidRow(nRow1))
                PushIllegalArgument();
            else
@@ -8430,10 +8430,10 @@ void ScInterpreter::ScOffset()
        }
        else
        {
            nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColPlus);
            nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus);
            nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1);
            nRow2 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowNew-1);
            nCol1 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1)+nColPlus);
            nRow1 = static_cast<SCROW>(static_cast<tools::Long>(nRow1)+nRowPlus);
            nCol2 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1)+nColNew-1);
            nRow2 = static_cast<SCROW>(static_cast<tools::Long>(nRow1)+nRowNew-1);
            nTab2 = nTab1;
            if (!mrDoc.ValidCol(nCol1) || !mrDoc.ValidRow(nRow1) ||
                !mrDoc.ValidCol(nCol2) || !mrDoc.ValidRow(nRow2))
@@ -8450,10 +8450,10 @@ void ScInterpreter::ScOffset()
            nColNew = nCol2 - nCol1 + 1;
        if (!bNewHeight)
            nRowNew = nRow2 - nRow1 + 1;
        nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColPlus);
        nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus);
        nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1);
        nRow2 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowNew-1);
        nCol1 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1)+nColPlus);
        nRow1 = static_cast<SCROW>(static_cast<tools::Long>(nRow1)+nRowPlus);
        nCol2 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1)+nColNew-1);
        nRow2 = static_cast<SCROW>(static_cast<tools::Long>(nRow1)+nRowNew-1);
        if (!mrDoc.ValidCol(nCol1) || !mrDoc.ValidRow(nRow1) ||
            !mrDoc.ValidCol(nCol2) || !mrDoc.ValidRow(nRow2) || nTab1 != nTab2)
            PushIllegalArgument();
@@ -8478,10 +8478,10 @@ void ScInterpreter::ScOffset()
            nColNew = nCol2 - nCol1 + 1;
        if (!bNewHeight)
            nRowNew = nRow2 - nRow1 + 1;
        nCol1 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColPlus);
        nRow1 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowPlus);
        nCol2 = static_cast<SCCOL>(static_cast<long>(nCol1)+nColNew-1);
        nRow2 = static_cast<SCROW>(static_cast<long>(nRow1)+nRowNew-1);
        nCol1 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1)+nColPlus);
        nRow1 = static_cast<SCROW>(static_cast<tools::Long>(nRow1)+nRowPlus);
        nCol2 = static_cast<SCCOL>(static_cast<tools::Long>(nCol1)+nColNew-1);
        nRow2 = static_cast<SCROW>(static_cast<tools::Long>(nRow1)+nRowNew-1);
        if (!mrDoc.ValidCol(nCol1) || !mrDoc.ValidRow(nRow1) ||
            !mrDoc.ValidCol(nCol2) || !mrDoc.ValidRow(nRow2) || nTab1 != nTab2)
            PushIllegalArgument();
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 49d6bfc..f7fd4a9 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -107,7 +107,7 @@ void ScInterpreter::ScGetActDate()
{
    nFuncFmtType = SvNumFormatType::DATE;
    Date aActDate( Date::SYSTEM );
    long nDiff = aActDate - pFormatter->GetNullDate();
    tools::Long nDiff = aActDate - pFormatter->GetNullDate();
    PushDouble(static_cast<double>(nDiff));
}

@@ -115,7 +115,7 @@ void ScInterpreter::ScGetActTime()
{
    nFuncFmtType = SvNumFormatType::DATETIME;
    DateTime aActTime( DateTime::SYSTEM );
    long nDiff = aActTime - pFormatter->GetNullDate();
    tools::Long nDiff = aActTime - pFormatter->GetNullDate();
    double fTime = aActTime.GetHour()    / static_cast<double>(::tools::Time::hourPerDay)   +
                   aActTime.GetMin()     / static_cast<double>(::tools::Time::minutePerDay) +
                   aActTime.GetSec()     / static_cast<double>(::tools::Time::secondPerDay) +
@@ -876,7 +876,7 @@ void ScInterpreter::ScGetDateDif()
        // to 2011-03-01 so the result is 0. Same for day 31 in months with
        // only 30 days.

        long nd;
        tools::Long nd;
        if (d1 <= d2)
            nd = d2 - d1;
        else
@@ -2668,9 +2668,9 @@ void ScInterpreter::ScStyle()
        OUString aStyle2;                           // Template after timer
        if (nParamCount >= 3)
            aStyle2 = GetString().getString();
        long nTimeOut = 0;                          // timeout
        tools::Long nTimeOut = 0;                          // timeout
        if (nParamCount >= 2)
            nTimeOut = static_cast<long>(GetDouble()*1000.0);
            nTimeOut = static_cast<tools::Long>(GetDouble()*1000.0);
        OUString aStyle1 = GetString().getString(); // Template for immediate

        if (nTimeOut < 0)
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 4b8f55b..9f9f071 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -4141,7 +4141,7 @@ void ScInterpreter::GetSortArray( sal_uInt8 nParamCount, vector<double>& rSortAr
        QuickSort( rSortArray, pIndexOrder);
}

static void lcl_QuickSort( long nLo, long nHi, vector<double>& rSortArray, vector<long>* pIndexOrder )
static void lcl_QuickSort( tools::Long nLo, tools::Long nHi, vector<double>& rSortArray, vector<long>* pIndexOrder )
{
    // If pIndexOrder is not NULL, we assume rSortArray.size() == pIndexOrder->size().

@@ -4158,8 +4158,8 @@ static void lcl_QuickSort( long nLo, long nHi, vector<double>& rSortArray, vecto
        return;
    }

    long ni = nLo;
    long nj = nHi;
    tools::Long ni = nLo;
    tools::Long nj = nHi;
    do
    {
        double fLo = rSortArray[nLo];
@@ -4194,13 +4194,13 @@ static void lcl_QuickSort( long nLo, long nHi, vector<double>& rSortArray, vecto

void ScInterpreter::QuickSort( vector<double>& rSortArray, vector<long>* pIndexOrder )
{
    long n = static_cast<long>(rSortArray.size());
    tools::Long n = static_cast<tools::Long>(rSortArray.size());

    if (pIndexOrder)
    {
        pIndexOrder->clear();
        pIndexOrder->reserve(n);
        for (long i = 0; i < n; ++i)
        for (tools::Long i = 0; i < n; ++i)
            pIndexOrder->push_back(i);
    }

diff --git a/sc/source/core/tool/parclass.cxx b/sc/source/core/tool/parclass.cxx
index b2f0914..9764141 100644
--- a/sc/source/core/tool/parclass.cxx
+++ b/sc/source/core/tool/parclass.cxx
@@ -442,7 +442,7 @@ formula::ParamClass ScParameterClassification::GetExternalParameterType( const f
            ScGlobal::GetAddInCollection()->GetFuncData( aUnoName, true );      // need fully initialized data
        if ( pFuncData )
        {
            long nCount = pFuncData->GetArgumentCount();
            tools::Long nCount = pFuncData->GetArgumentCount();
            if ( nCount <= 0 )
                eRet = Bounds;
            else
diff --git a/sc/source/core/tool/rangeseq.cxx b/sc/source/core/tool/rangeseq.cxx
index 04b4750..45b3aeb 100644
--- a/sc/source/core/tool/rangeseq.cxx
+++ b/sc/source/core/tool/rangeseq.cxx
@@ -49,12 +49,12 @@ static bool lcl_HasErrors( ScDocument& rDoc, const ScRange& rRange )
    return false;   // no error found
}

static long lcl_DoubleToLong( double fVal )
static tools::Long lcl_DoubleToLong( double fVal )
{
    double fInt = (fVal >= 0.0) ? ::rtl::math::approxFloor( fVal ) :
                                  ::rtl::math::approxCeil( fVal );
    if ( o3tl::convertsToAtLeast(fInt, LONG_MIN) && o3tl::convertsToAtMost(fInt, LONG_MAX) )
        return static_cast<long>(fInt);
        return static_cast<tools::Long>(fInt);
    else
        return 0;       // out of range
}
@@ -64,16 +64,16 @@ bool ScRangeToSequence::FillLongArray( uno::Any& rAny, ScDocument& rDoc, const S
    SCTAB nTab = rRange.aStart.Tab();
    SCCOL nStartCol = rRange.aStart.Col();
    SCROW nStartRow = rRange.aStart.Row();
    long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
    long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
    tools::Long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
    tools::Long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();

    uno::Sequence< uno::Sequence<sal_Int32> > aRowSeq( nRowCount );
    uno::Sequence<sal_Int32>* pRowAry = aRowSeq.getArray();
    for (long nRow = 0; nRow < nRowCount; nRow++)
    for (tools::Long nRow = 0; nRow < nRowCount; nRow++)
    {
        uno::Sequence<sal_Int32> aColSeq( nColCount );
        sal_Int32* pColAry = aColSeq.getArray();
        for (long nCol = 0; nCol < nColCount; nCol++)
        for (tools::Long nCol = 0; nCol < nColCount; nCol++)
            pColAry[nCol] = lcl_DoubleToLong( rDoc.GetValue(
                ScAddress( static_cast<SCCOL>(nStartCol+nCol), static_cast<SCROW>(nStartRow+nRow), nTab ) ) );

@@ -117,16 +117,16 @@ bool ScRangeToSequence::FillDoubleArray( uno::Any& rAny, ScDocument& rDoc, const
    SCTAB nTab = rRange.aStart.Tab();
    SCCOL nStartCol = rRange.aStart.Col();
    SCROW nStartRow = rRange.aStart.Row();
    long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
    long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
    tools::Long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
    tools::Long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();

    uno::Sequence< uno::Sequence<double> > aRowSeq( nRowCount );
    uno::Sequence<double>* pRowAry = aRowSeq.getArray();
    for (long nRow = 0; nRow < nRowCount; nRow++)
    for (tools::Long nRow = 0; nRow < nRowCount; nRow++)
    {
        uno::Sequence<double> aColSeq( nColCount );
        double* pColAry = aColSeq.getArray();
        for (long nCol = 0; nCol < nColCount; nCol++)
        for (tools::Long nCol = 0; nCol < nColCount; nCol++)
            pColAry[nCol] = rDoc.GetValue(
                ScAddress( static_cast<SCCOL>(nStartCol+nCol), static_cast<SCROW>(nStartRow+nRow), nTab ) );

@@ -170,18 +170,18 @@ bool ScRangeToSequence::FillStringArray( uno::Any& rAny, ScDocument& rDoc, const
    SCTAB nTab = rRange.aStart.Tab();
    SCCOL nStartCol = rRange.aStart.Col();
    SCROW nStartRow = rRange.aStart.Row();
    long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
    long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
    tools::Long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
    tools::Long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();

    bool bHasErrors = false;

    uno::Sequence< uno::Sequence<OUString> > aRowSeq( nRowCount );
    uno::Sequence<OUString>* pRowAry = aRowSeq.getArray();
    for (long nRow = 0; nRow < nRowCount; nRow++)
    for (tools::Long nRow = 0; nRow < nRowCount; nRow++)
    {
        uno::Sequence<OUString> aColSeq( nColCount );
        OUString* pColAry = aColSeq.getArray();
        for (long nCol = 0; nCol < nColCount; nCol++)
        for (tools::Long nCol = 0; nCol < nColCount; nCol++)
        {
            FormulaError nErrCode = rDoc.GetStringForFormula(
                        ScAddress(static_cast<SCCOL>(nStartCol+nCol), static_cast<SCROW>(nStartRow+nRow), nTab),
@@ -242,18 +242,18 @@ bool ScRangeToSequence::FillMixedArray( uno::Any& rAny, ScDocument& rDoc, const 
    SCTAB nTab = rRange.aStart.Tab();
    SCCOL nStartCol = rRange.aStart.Col();
    SCROW nStartRow = rRange.aStart.Row();
    long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
    long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();
    tools::Long nColCount = rRange.aEnd.Col() + 1 - rRange.aStart.Col();
    tools::Long nRowCount = rRange.aEnd.Row() + 1 - rRange.aStart.Row();

    bool bHasErrors = false;

    uno::Sequence< uno::Sequence<uno::Any> > aRowSeq( nRowCount );
    uno::Sequence<uno::Any>* pRowAry = aRowSeq.getArray();
    for (long nRow = 0; nRow < nRowCount; nRow++)
    for (tools::Long nRow = 0; nRow < nRowCount; nRow++)
    {
        uno::Sequence<uno::Any> aColSeq( nColCount );
        uno::Any* pColAry = aColSeq.getArray();
        for (long nCol = 0; nCol < nColCount; nCol++)
        for (tools::Long nCol = 0; nCol < nColCount; nCol++)
        {
            uno::Any& rElement = pColAry[nCol];

diff --git a/sc/source/core/tool/unitconv.cxx b/sc/source/core/tool/unitconv.cxx
index 9fc54aa..4068fcb 100644
--- a/sc/source/core/tool/unitconv.cxx
+++ b/sc/source/core/tool/unitconv.cxx
@@ -56,7 +56,7 @@ ScUnitConverter::ScUnitConverter()
    // empty node name -> use the config item's path itself
    const Sequence<OUString> aNodeNames = aConfigItem.GetNodeNames( "" );

    long nNodeCount = aNodeNames.getLength();
    tools::Long nNodeCount = aNodeNames.getLength();
    if ( !nNodeCount )
        return;

@@ -64,7 +64,7 @@ ScUnitConverter::ScUnitConverter()
    OUString* pValNameArray = aValNames.getArray();
    const OUString sSlash('/');

    long nIndex = 0;
    tools::Long nIndex = 0;
    for (const OUString& rNode : aNodeNames)
    {
        OUString sPrefix = rNode + sSlash;
@@ -86,7 +86,7 @@ ScUnitConverter::ScUnitConverter()
    double fFactor = 0;

    nIndex = 0;
    for (long i=0; i<nNodeCount; i++)
    for (tools::Long i=0; i<nNodeCount; i++)
    {
        pProperties[nIndex++] >>= sFromUnit;
        pProperties[nIndex++] >>= sToUnit;
diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx
index 65c9ac9..5b2fa7c 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -644,7 +644,7 @@ void ImportExcel::DefColWidth()
    }

    // #i3006# additional space for default width - Excel adds space depending on font size
    long nFontHt = GetFontBuffer().GetAppFontData().mnHeight;
    tools::Long nFontHt = GetFontBuffer().GetAppFontData().mnHeight;
    fDefWidth += XclTools::GetXclDefColWidthCorrection( nFontHt );

    sal_uInt16 nScWidth = XclTools::GetScColumnWidth( limit_cast< sal_uInt16 >( fDefWidth ), GetCharWidth() );
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index a2a69ae..c104a97 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -94,9 +94,9 @@ using namespace oox;
namespace
{

long lcl_hmm2px(long nPixel)
tools::Long lcl_hmm2px(tools::Long nPixel)
{
    return static_cast<long>(nPixel*PIXEL_PER_INCH/1000.0/CM_PER_INCH + 0.5);
    return static_cast<tools::Long>(nPixel*PIXEL_PER_INCH/1000.0/CM_PER_INCH + 0.5);
}

const char *ToHorizAlign( SdrTextHorzAdjust eAdjust )
@@ -147,7 +147,7 @@ void lcl_WriteAnchorVertex( sax_fastparser::FSHelperPtr const & rComments, const
    rComments->endElement( FSNS( XML_xdr, XML_rowOff ) );
}

long lcl_hmm2output(long value, bool bInEMU)
tools::Long lcl_hmm2output(tools::Long value, bool bInEMU)
{
    if (bInEMU)
        return oox::drawingml::convertHmmToEmu(value);
diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx
index 0d8909b..2a962da 100644
--- a/sc/source/filter/excel/xepivot.cxx
+++ b/sc/source/filter/excel/xepivot.cxx
@@ -366,7 +366,7 @@ void XclExpPCField::InitStdGroupField( const XclExpPCField& rBaseField, const Sc
    maGroupOrder.resize( maFieldInfo.mnBaseItems, EXC_PC_NOITEM );

    // loop over all groups of this field
    for( long nGroupIdx = 0, nGroupCount = rGroupDim.GetGroupCount(); nGroupIdx < nGroupCount; ++nGroupIdx )
    for( tools::Long nGroupIdx = 0, nGroupCount = rGroupDim.GetGroupCount(); nGroupIdx < nGroupCount; ++nGroupIdx )
    {
        const ScDPSaveGroupItem& rGroupItem = rGroupDim.GetGroupByIndex( nGroupIdx );
        // the index of the new item containing the grouping name
@@ -523,7 +523,7 @@ void XclExpPCField::InsertNumDateGroupItems( const ScDPObject& rDPObj, const ScD
        return;

    ScSheetDPData aDPData(&GetDoc(), *pSrcDesc, *pCache);
    long nDim = GetFieldIndex();
    tools::Long nDim = GetFieldIndex();
    // get the string collection with generated grouping elements
    ScDPNumGroupDimension aTmpDim( rNumInfo );
    if( nDatePart != 0 )
@@ -1021,7 +1021,7 @@ void XclExpPTField::SetPropertiesFromDim( const ScDPSaveDimension& rSaveDim )
    // subtotals
    XclPTSubtotalVec aSubtotals;
    aSubtotals.reserve( static_cast< size_t >( rSaveDim.GetSubTotalsCount() ) );
    for( long nSubtIdx = 0, nSubtCount = rSaveDim.GetSubTotalsCount(); nSubtIdx < nSubtCount; ++nSubtIdx )
    for( tools::Long nSubtIdx = 0, nSubtCount = rSaveDim.GetSubTotalsCount(); nSubtIdx < nSubtCount; ++nSubtIdx )
        aSubtotals.push_back( rSaveDim.GetSubTotalFunc( nSubtIdx ) );
    maFieldInfo.SetSubtotals( aSubtotals );

diff --git a/sc/source/filter/excel/xepivotxml.cxx b/sc/source/filter/excel/xepivotxml.cxx
index c0e840c..b69e4b34 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -50,7 +50,7 @@ void savePivotCacheRecordsXml( XclExpXmlStream& rStrm, const ScDPCache& rCache )
    pRecStrm->startElement(XML_pivotCacheRecords,
        XML_xmlns, rStrm.getNamespaceURL(OOX_NS(xls)).toUtf8(),
        FSNS(XML_xmlns, XML_r), rStrm.getNamespaceURL(OOX_NS(officeRel)).toUtf8(),
        XML_count, OString::number(static_cast<long>(nCount)));
        XML_count, OString::number(static_cast<tools::Long>(nCount)));

    for (SCROW i = 0; i < nCount; ++i)
    {
@@ -209,7 +209,7 @@ OUString GetExcelFormattedDate( double fSerialDateTime, const SvNumberFormatter&
// Since ScDPItemData::DateFirst is -1, ScDPItemData::DateLast is 10000, and other date group
// items would fit between those in order (like 0 = Jan, 1 = Feb, etc.), we can simply sort
// the items by value.
std::vector<OUString> SortGroupItems(const ScDPCache& rCache, long nDim)
std::vector<OUString> SortGroupItems(const ScDPCache& rCache, tools::Long nDim)
{
    struct ItemData
    {
@@ -280,7 +280,7 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( XclExpXmlStream& rStrm, const Entr
    size_t nCount = rCache.GetFieldCount();
    const size_t nGroupFieldCount = rCache.GetGroupFieldCount();
    pDefStrm->startElement(XML_cacheFields,
        XML_count, OString::number(static_cast<long>(nCount + nGroupFieldCount)));
        XML_count, OString::number(static_cast<tools::Long>(nCount + nGroupFieldCount)));

    auto WriteFieldGroup = [this, &rCache, pDefStrm](size_t i, size_t base) {
        const sal_Int32 nDatePart = rCache.GetGroupType(i);
@@ -450,7 +450,7 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( XclExpXmlStream& rStrm, const Entr

        //if (bListItems) // see TODO above
        {
            pAttList->add(XML_count, OString::number(static_cast<long>(rFieldItems.size())));
            pAttList->add(XML_count, OString::number(static_cast<tools::Long>(rFieldItems.size())));
        }

        if (isLongText)
@@ -662,10 +662,10 @@ namespace {

struct DataField
{
    long mnPos; // field index in pivot cache.
    tools::Long mnPos; // field index in pivot cache.
    const ScDPSaveDimension* mpDim;

    DataField( long nPos, const ScDPSaveDimension* pDim ) : mnPos(nPos), mpDim(pDim) {}
    DataField( tools::Long nPos, const ScDPSaveDimension* pDim ) : mnPos(nPos), mpDim(pDim) {}
};

/** Returns an OOXML subtotal function name string. See ECMA-376-1:2016 18.18.43 */
@@ -774,7 +774,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
    std::vector<long> aPageFields;
    std::vector<DataField> aDataFields;

    long nDataDimCount = rSaveData.GetDataDimensionCount();
    tools::Long nDataDimCount = rSaveData.GetDataDimensionCount();
    // Use dimensions in the save data to get their correct ordering.
    // Dimension order here is significant as they specify the order of
    // appearance in each axis.
@@ -784,7 +784,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
    {
        const ScDPSaveDimension& rDim = *i;

        long nPos = -1; // position in cache
        tools::Long nPos = -1; // position in cache
        if (rDim.IsDataLayout())
            nPos = -2; // Excel uses an index of -2 to indicate a data layout field.
        else
@@ -873,7 +873,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP

    if (!aPageFields.empty())
    {
        rStrm.WriteAttributes(XML_rowPageCount, OUString::number(static_cast<long>(aPageFields.size())));
        rStrm.WriteAttributes(XML_rowPageCount, OUString::number(static_cast<tools::Long>(aPageFields.size())));
        rStrm.WriteAttributes(XML_colPageCount, OUString::number(1));
    }

@@ -884,7 +884,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
    // they appear in the cache.

    pPivotStrm->startElement(XML_pivotFields,
        XML_count, OString::number(static_cast<long>(aCachedDims.size())));
        XML_count, OString::number(static_cast<tools::Long>(aCachedDims.size())));

    for (size_t i = 0; i < nFieldCount; ++i)
    {
@@ -1009,10 +1009,10 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
        pAttList->add(XML_compact, ToPsz10(false));
        pAttList->add(XML_showAll, ToPsz10(false));

        long nSubTotalCount = pDim->GetSubTotalsCount();
        tools::Long nSubTotalCount = pDim->GetSubTotalsCount();
        std::vector<OString> aSubtotalSequence;
        bool bHasDefaultSubtotal = false;
        for (long nSubTotal = 0; nSubTotal < nSubTotalCount; ++nSubTotal)
        for (tools::Long nSubTotal = 0; nSubTotal < nSubTotalCount; ++nSubTotal)
        {
            ScGeneralFunction eFunc = pDim->GetSubTotalFunc(nSubTotal);
            aSubtotalSequence.push_back(GetSubtotalFuncName(eFunc));
@@ -1032,14 +1032,14 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
        pPivotStrm->startElement(XML_pivotField, xAttributeList);

        pPivotStrm->startElement(XML_items,
            XML_count, OString::number(static_cast<long>(aMemberSequence.size() + aSubtotalSequence.size())));
            XML_count, OString::number(static_cast<tools::Long>(aMemberSequence.size() + aSubtotalSequence.size())));

        for (const auto & nMember : aMemberSequence)
        {
            auto pItemAttList = sax_fastparser::FastSerializerHelper::createAttrList();
            if (nMember.second)
                pItemAttList->add(XML_h, ToPsz10(true));
            pItemAttList->add(XML_x, OString::number(static_cast<long>(nMember.first)));
            pItemAttList->add(XML_x, OString::number(static_cast<tools::Long>(nMember.first)));
            sax_fastparser::XFastAttributeListRef xItemAttributeList(pItemAttList);
            pPivotStrm->singleElement(XML_item, xItemAttributeList);
        }
@@ -1060,7 +1060,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
    if (!aRowFields.empty())
    {
        pPivotStrm->startElement(XML_rowFields,
            XML_count, OString::number(static_cast<long>(aRowFields.size())));
            XML_count, OString::number(static_cast<tools::Long>(aRowFields.size())));

        for (const auto& rRowField : aRowFields)
        {
@@ -1077,7 +1077,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
    if (!aColFields.empty())
    {
        pPivotStrm->startElement(XML_colFields,
            XML_count, OString::number(static_cast<long>(aColFields.size())));
            XML_count, OString::number(static_cast<tools::Long>(aColFields.size())));

        for (const auto& rColField : aColFields)
        {
@@ -1094,7 +1094,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
    if (!aPageFields.empty())
    {
        pPivotStrm->startElement(XML_pageFields,
            XML_count, OString::number(static_cast<long>(aPageFields.size())));
            XML_count, OString::number(static_cast<tools::Long>(aPageFields.size())));

        for (const auto& rPageField : aPageFields)
        {
@@ -1115,11 +1115,11 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
            xDimsByName = xDimSupplier->getDimensions();

        pPivotStrm->startElement(XML_dataFields,
            XML_count, OString::number(static_cast<long>(aDataFields.size())));
            XML_count, OString::number(static_cast<tools::Long>(aDataFields.size())));

        for (const auto& rDataField : aDataFields)
        {
            long nDimIdx = rDataField.mnPos;
            tools::Long nDimIdx = rDataField.mnPos;
            assert(aCachedDims[nDimIdx]); // the loop above should have screened for NULL's.
            const ScDPSaveDimension& rDim = *rDataField.mpDim;
            std::optional<OUString> pName = rDim.GetLayoutName();
diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index 3118834..d57bec0 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -1456,7 +1456,7 @@ bool XclExpCellAlign::FillFromItemSet(
        case EXC_BIFF8: // attributes new in BIFF8
        {
            // text indent
            long nTmpIndent = rItemSet.Get( ATTR_INDENT ).GetValue();
            tools::Long nTmpIndent = rItemSet.Get( ATTR_INDENT ).GetValue();
            nTmpIndent = (nTmpIndent + 100) / 200; // 1 Excel unit == 10 pt == 200 twips
            mnIndent = limit_cast< sal_uInt8 >( nTmpIndent, 0, 15 );
            bUsed |= ScfTools::CheckItem( rItemSet, ATTR_INDENT, bStyle );
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index bc9b550..219110c 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1555,7 +1555,7 @@ double lclGetCChCorrection(const XclExpRoot& rRoot)
    // 5 pixels are added to the base width: 2 for margin padding on each side, plus 1 for gridline
    // So this should depend on rRoot.GetCharWidth(), not on font height

    long nFontHt = rRoot.GetFontBuffer().GetAppFontData().mnHeight;
    tools::Long nFontHt = rRoot.GetFontBuffer().GetAppFontData().mnHeight;
    return XclTools::GetXclDefColWidthCorrection(nFontHt) / 256.0;
}

diff --git a/sc/source/filter/excel/xeview.cxx b/sc/source/filter/excel/xeview.cxx
index 5d4acc7..d94a944 100644
--- a/sc/source/filter/excel/xeview.cxx
+++ b/sc/source/filter/excel/xeview.cxx
@@ -275,7 +275,7 @@ void XclExpTabBgColor::WriteBody( XclExpStream& rStrm )
namespace {

/** Converts a Calc zoom factor into an Excel zoom factor. Returns 0 for a default zoom value. */
sal_uInt16 lclGetXclZoom( long nScZoom, sal_uInt16 nDefXclZoom )
sal_uInt16 lclGetXclZoom( tools::Long nScZoom, sal_uInt16 nDefXclZoom )
{
    sal_uInt16 nXclZoom = limit_cast< sal_uInt16 >( nScZoom, EXC_ZOOM_MIN, EXC_ZOOM_MAX );
    return (nXclZoom == nDefXclZoom) ? 0 : nXclZoom;
diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx
index 2cb9f02..16b64c8 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -328,7 +328,7 @@ css::awt::Rectangle XclImpChRoot::CalcHmmFromChartRect( const XclChRectangle& rR

double XclImpChRoot::CalcRelativeFromHmmX( sal_Int32 nPosX ) const
{
    const long nWidth = mxChData->maChartRect.GetWidth();
    const tools::Long nWidth = mxChData->maChartRect.GetWidth();
    if (!nWidth)
        throw o3tl::divide_by_zero();
    return static_cast<double>(nPosX) / nWidth;
@@ -336,7 +336,7 @@ double XclImpChRoot::CalcRelativeFromHmmX( sal_Int32 nPosX ) const

double XclImpChRoot::CalcRelativeFromHmmY( sal_Int32 nPosY ) const
{
    const long nHeight = mxChData->maChartRect.GetHeight();
    const tools::Long nHeight = mxChData->maChartRect.GetHeight();
    if (!nHeight)
        throw o3tl::divide_by_zero();
    return static_cast<double >(nPosY) / nHeight;
@@ -4268,10 +4268,10 @@ tools::Rectangle XclImpChartDrawing::CalcAnchorRect( const XclObjAnchor& rAnchor
        in the cell address components of the client anchor. In old BIFF3-BIFF5
        objects, the position is stored in the offset components of the anchor. */
    tools::Rectangle aRect(
        static_cast< long >( static_cast< double >( bDffAnchor ? rAnchor.maFirst.mnCol : rAnchor.mnLX ) / EXC_CHART_TOTALUNITS * maChartRect.GetWidth()  + 0.5 ),
        static_cast< long >( static_cast< double >( bDffAnchor ? rAnchor.maFirst.mnRow : rAnchor.mnTY ) / EXC_CHART_TOTALUNITS * maChartRect.GetHeight() + 0.5 ),
        static_cast< long >( static_cast< double >( bDffAnchor ? rAnchor.maLast.mnCol  : rAnchor.mnRX ) / EXC_CHART_TOTALUNITS * maChartRect.GetWidth()  + 0.5 ),
        static_cast< long >( static_cast< double >( bDffAnchor ? rAnchor.maLast.mnRow  : rAnchor.mnBY ) / EXC_CHART_TOTALUNITS * maChartRect.GetHeight() + 0.5 ) );
        static_cast< tools::Long >( static_cast< double >( bDffAnchor ? rAnchor.maFirst.mnCol : rAnchor.mnLX ) / EXC_CHART_TOTALUNITS * maChartRect.GetWidth()  + 0.5 ),
        static_cast< tools::Long >( static_cast< double >( bDffAnchor ? rAnchor.maFirst.mnRow : rAnchor.mnTY ) / EXC_CHART_TOTALUNITS * maChartRect.GetHeight() + 0.5 ),
        static_cast< tools::Long >( static_cast< double >( bDffAnchor ? rAnchor.maLast.mnCol  : rAnchor.mnRX ) / EXC_CHART_TOTALUNITS * maChartRect.GetWidth()  + 0.5 ),
        static_cast< tools::Long >( static_cast< double >( bDffAnchor ? rAnchor.maLast.mnRow  : rAnchor.mnBY ) / EXC_CHART_TOTALUNITS * maChartRect.GetHeight() + 0.5 ) );
    aRect.Justify();
    // move shapes into chart area for sheet charts
    if( mbOwnTab )
diff --git a/sc/source/filter/excel/xiescher.cxx b/sc/source/filter/excel/xiescher.cxx
index c0d63ee..ecb113d 100644
--- a/sc/source/filter/excel/xiescher.cxx
+++ b/sc/source/filter/excel/xiescher.cxx
@@ -637,7 +637,7 @@ void XclImpDrawObjBase::ConvertLineStyle( SdrObject& rSdrObj, const XclObjLineDa
    }
    else
    {
        long nLineWidth = 35 * ::std::min( rLineData.mnWidth, EXC_OBJ_LINE_THICK );
        tools::Long nLineWidth = 35 * ::std::min( rLineData.mnWidth, EXC_OBJ_LINE_THICK );
        rSdrObj.SetMergedItem( XLineWidthItem( nLineWidth ) );
        rSdrObj.SetMergedItem( XLineColorItem( EMPTY_OUSTRING, GetPalette().GetColor( rLineData.mnColorIdx ) ) );
        rSdrObj.SetMergedItem( XLineJointItem( css::drawing::LineJoint_MITER ) );
@@ -1169,7 +1169,7 @@ SdrObjectUniquePtr XclImpLineObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, 
#undef EXC_ARROW_POINT

        ::basegfx::B2DPolyPolygon aArrowPolyPoly( aArrowPoly );
        long nWidth = static_cast< long >( 125 * fArrowWidth );
        tools::Long nWidth = static_cast< tools::Long >( 125 * fArrowWidth );
        if( bLineStart )
        {
            xSdrObj->SetMergedItem( XLineStartItem( EMPTY_OUSTRING, aArrowPolyPoly ) );
@@ -1289,8 +1289,8 @@ void XclImpArcObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uIn
SdrObjectUniquePtr XclImpArcObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
    tools::Rectangle aNewRect = rAnchorRect;
    long nStartAngle = 0;
    long nEndAngle = 0;
    tools::Long nStartAngle = 0;
    tools::Long nEndAngle = 0;
    switch( mnQuadrant )
    {
        default:
@@ -1804,8 +1804,8 @@ void XclImpChartObj::FinalizeTabChart()
    const XclPageData& rPageData = GetPageSettings().GetPageData();
    Size aPaperSize = rPageData.GetScPaperSize();

    long nWidth = XclTools::GetHmmFromTwips( aPaperSize.Width() );
    long nHeight = XclTools::GetHmmFromTwips( aPaperSize.Height() );
    tools::Long nWidth = XclTools::GetHmmFromTwips( aPaperSize.Width() );
    tools::Long nHeight = XclTools::GetHmmFromTwips( aPaperSize.Height() );

    // subtract page margins, give some more extra space
    nWidth -= (XclTools::GetHmmFromInch( rPageData.mfLeftMargin + rPageData.mfRightMargin ) + 2000);
diff --git a/sc/source/filter/excel/xipage.cxx b/sc/source/filter/excel/xipage.cxx
index b33371c..c3b1853 100644
--- a/sc/source/filter/excel/xipage.cxx
+++ b/sc/source/filter/excel/xipage.cxx
@@ -311,7 +311,7 @@ void XclImpPageSettings::Finalize()
            -> set fixed header height to get correct sheet data position. */
        ScfTools::PutItem( rHdrItemSet, SfxBoolItem( ATTR_PAGE_DYNAMIC, false ), true );
        // shrink header height
        long nHdrHeight = XclTools::GetTwipsFromInch( fHeaderHeight + fHeaderDist );
        tools::Long nHdrHeight = XclTools::GetTwipsFromInch( fHeaderHeight + fHeaderDist );
        ScfTools::PutItem( rHdrItemSet, SvxSizeItem( ATTR_PAGE_SIZE, Size( 0, nHdrHeight ) ), true );
        lclPutMarginItem( rHdrItemSet, EXC_ID_BOTTOMMARGIN, 0.0 );
    }
@@ -347,7 +347,7 @@ void XclImpPageSettings::Finalize()
            -> set fixed footer height to get correct sheet data end position. */
        ScfTools::PutItem( rFtrItemSet, SfxBoolItem( ATTR_PAGE_DYNAMIC, false ), true );
        // shrink footer height
        long nFtrHeight = XclTools::GetTwipsFromInch( fFooterHeight + fFooterDist );
        tools::Long nFtrHeight = XclTools::GetTwipsFromInch( fFooterHeight + fFooterDist );
        ScfTools::PutItem( rFtrItemSet, SvxSizeItem( ATTR_PAGE_SIZE, Size( 0, nFtrHeight ) ), true );
        lclPutMarginItem( rFtrItemSet, EXC_ID_TOPMARGIN, 0.0 );
    }
diff --git a/sc/source/filter/excel/xiview.cxx b/sc/source/filter/excel/xiview.cxx
index 11c698c4..49878de 100644
--- a/sc/source/filter/excel/xiview.cxx
+++ b/sc/source/filter/excel/xiview.cxx
@@ -80,9 +80,9 @@ void XclImpDocViewSettings::Finalize()

namespace {

long lclGetScZoom( sal_uInt16 nXclZoom, sal_uInt16 nDefZoom )
tools::Long lclGetScZoom( sal_uInt16 nXclZoom, sal_uInt16 nDefZoom )
{
    return static_cast< long >( nXclZoom ? nXclZoom : nDefZoom );
    return static_cast< tools::Long >( nXclZoom ? nXclZoom : nDefZoom );
}

} // namespace
@@ -259,8 +259,8 @@ void XclImpTabViewSettings::Finalize()
    else
    {
        // split window: position is in twips
        rTabSett.maSplitPos.setX( static_cast< long >( maData.mnSplitX ) );
        rTabSett.maSplitPos.setY( static_cast< long >( maData.mnSplitY ) );
        rTabSett.maSplitPos.setX( static_cast< tools::Long >( maData.mnSplitX ) );
        rTabSett.maSplitPos.setY( static_cast< tools::Long >( maData.mnSplitY ) );
    }

    // grid color
diff --git a/sc/source/filter/excel/xlescher.cxx b/sc/source/filter/excel/xlescher.cxx
index a2c24a1..bb59b85 100644
--- a/sc/source/filter/excel/xlescher.cxx
+++ b/sc/source/filter/excel/xlescher.cxx
@@ -60,18 +60,18 @@ double lclGetTwipsScale( MapUnit eMapUnit )
}

/** Calculates a drawing layer X position (in twips) from an object column position. */
long lclGetXFromCol( const ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclCol, sal_uInt16 nOffset, double fScale )
tools::Long lclGetXFromCol( const ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclCol, sal_uInt16 nOffset, double fScale )
{
    SCCOL nScCol = static_cast< SCCOL >( nXclCol );
    return static_cast< long >( fScale * (rDoc.GetColOffset( nScCol, nScTab ) +
    return static_cast< tools::Long >( fScale * (rDoc.GetColOffset( nScCol, nScTab ) +
        ::std::min( nOffset / 1024.0, 1.0 ) * rDoc.GetColWidth( nScCol, nScTab )) + 0.5 );
}

/** Calculates a drawing layer Y position (in twips) from an object row position. */
long lclGetYFromRow( const ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclRow, sal_uInt16 nOffset, double fScale )
tools::Long lclGetYFromRow( const ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclRow, sal_uInt16 nOffset, double fScale )
{
    SCROW nScRow = static_cast< SCROW >( nXclRow );
    return static_cast< long >( fScale * (rDoc.GetRowOffset( nScRow, nScTab ) +
    return static_cast< tools::Long >( fScale * (rDoc.GetRowOffset( nScRow, nScTab ) +
        ::std::min( nOffset / 256.0, 1.0 ) * rDoc.GetRowHeight( nScRow, nScTab )) + 0.5 );
}

@@ -79,11 +79,11 @@ long lclGetYFromRow( const ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclRow, s
void lclGetColFromX(
        const ScDocument& rDoc, SCTAB nScTab, sal_uInt16& rnXclCol,
        sal_uInt16& rnOffset, sal_uInt16 nXclStartCol, sal_uInt16 nXclMaxCol,
        long& rnStartW, long nX, double fScale )
        tools::Long& rnStartW, tools::Long nX, double fScale )
{
    // rnStartW in conjunction with nXclStartCol is used as buffer for previously calculated width
    long nTwipsX = static_cast< long >( nX / fScale + 0.5 );
    long nColW = 0;
    tools::Long nTwipsX = static_cast< tools::Long >( nX / fScale + 0.5 );
    tools::Long nColW = 0;
    for( rnXclCol = nXclStartCol; rnXclCol <= nXclMaxCol; ++rnXclCol )
    {
        nColW = rDoc.GetColWidth( static_cast< SCCOL >( rnXclCol ), nScTab );
@@ -98,11 +98,11 @@ void lclGetColFromX(
void lclGetRowFromY(
        const ScDocument& rDoc, SCTAB nScTab, sal_uInt32& rnXclRow,
        sal_uInt32& rnOffset, sal_uInt32 nXclStartRow, sal_uInt32 nXclMaxRow,
        long& rnStartH, long nY, double fScale )
        tools::Long& rnStartH, tools::Long nY, double fScale )
{
    // rnStartH in conjunction with nXclStartRow is used as buffer for previously calculated height
    long nTwipsY = static_cast< long >( nY / fScale + 0.5 );
    long nRowH = 0;
    tools::Long nTwipsY = static_cast< tools::Long >( nY / fScale + 0.5 );
    tools::Long nRowH = 0;
    bool bFound = false;
    for( sal_uInt32 nRow = nXclStartRow; nRow <= nXclMaxRow; ++nRow )
    {
@@ -123,12 +123,12 @@ void lclGetRowFromY(
/** Mirrors a rectangle (from LTR to RTL layout or vice versa). */
void lclMirrorRectangle( tools::Rectangle& rRect )
{
    long nLeft = rRect.Left();
    tools::Long nLeft = rRect.Left();
    rRect.SetLeft( -rRect.Right() );
    rRect.SetRight( -nLeft );
}

sal_uInt16 lclGetEmbeddedScale( long nPageSize, sal_Int32 nPageScale, long nPos, double fPosScale )
sal_uInt16 lclGetEmbeddedScale( tools::Long nPageSize, sal_Int32 nPageScale, tools::Long nPos, double fPosScale )
{
    return static_cast< sal_uInt16 >( nPos * fPosScale / nPageSize * nPageScale + 0.5 );
}
@@ -171,7 +171,7 @@ void XclObjAnchor::SetRect( const XclRoot& rRoot, SCTAB nScTab, const tools::Rec
        lclMirrorRectangle( aRect );

    double fScale = lclGetTwipsScale( eMapUnit );
    long nDummy = 0;
    tools::Long nDummy = 0;
    lclGetColFromX( rDoc, nScTab, maFirst.mnCol, mnLX, 0,             nXclMaxCol, nDummy, aRect.Left(),   fScale );
    lclGetColFromX( rDoc, nScTab, maLast.mnCol,  mnRX, maFirst.mnCol, nXclMaxCol, nDummy, aRect.Right(),  fScale );
    nDummy = 0;
diff --git a/sc/source/filter/excel/xlpage.cxx b/sc/source/filter/excel/xlpage.cxx
index 3f13bef..1f5f72c 100644
--- a/sc/source/filter/excel/xlpage.cxx
+++ b/sc/source/filter/excel/xlpage.cxx
@@ -30,21 +30,21 @@ namespace{
struct XclPaperSize
{
    Paper               mePaper;            /// SVX paper size identifier.
    long                mnWidth;            /// Paper width in twips.
    long                mnHeight;           /// Paper height in twips.
    tools::Long                mnWidth;            /// Paper width in twips.
    tools::Long                mnHeight;           /// Paper height in twips.
};

constexpr long in2twips(double n_inch)
constexpr tools::Long in2twips(double n_inch)
{
    return static_cast<long>( (n_inch * EXC_TWIPS_PER_INCH) + 0.5);
    return static_cast<tools::Long>( (n_inch * EXC_TWIPS_PER_INCH) + 0.5);
}
constexpr long mm2twips(double n_mm)
constexpr tools::Long mm2twips(double n_mm)
{
    return static_cast<long>( (n_mm * EXC_TWIPS_PER_INCH / CM_PER_INCH / 10.0) + 0.5);
    return static_cast<tools::Long>( (n_mm * EXC_TWIPS_PER_INCH / CM_PER_INCH / 10.0) + 0.5);
}
constexpr long twips2mm(long n_twips)
constexpr tools::Long twips2mm(tools::Long n_twips)
{
    return static_cast<long>((static_cast<double>(n_twips) - 0.5) / EXC_TWIPS_PER_INCH * CM_PER_INCH * 10.0);
    return static_cast<tools::Long>((static_cast<double>(n_twips) - 0.5) / EXC_TWIPS_PER_INCH * CM_PER_INCH * 10.0);
}

constexpr XclPaperSize pPaperSizeTable[] =
@@ -221,7 +221,7 @@ Size XclPageData::GetScPaperSize() const
    if( !mbPortrait )
    {
        // swap width and height
        long n = aSize.Width();
        tools::Long n = aSize.Width();
        aSize.setWidth(aSize.Height());
        aSize.setHeight(n);
    }
@@ -233,10 +233,10 @@ void XclPageData::SetScPaperSize( const Size& rSize, bool bPortrait, bool bStric
{
    mbPortrait = bPortrait;
    mnPaperSize = 0;
    long nWidth = bPortrait ? rSize.Width() : rSize.Height();
    long nHeight = bPortrait ? rSize.Height() : rSize.Width();
    long nMaxWDiff = 80;
    long nMaxHDiff = 50;
    tools::Long nWidth = bPortrait ? rSize.Width() : rSize.Height();
    tools::Long nHeight = bPortrait ? rSize.Height() : rSize.Width();
    tools::Long nMaxWDiff = 80;
    tools::Long nMaxHDiff = 50;

    mnPaperWidth = twips2mm( nWidth );
    mnPaperHeight = twips2mm( nHeight );
@@ -253,8 +253,8 @@ void XclPageData::SetScPaperSize( const Size& rSize, bool bPortrait, bool bStric

    for( const auto &rEntry : pPaperSizeTable)
    {
        long nWDiff = std::abs( rEntry.mnWidth - nWidth );
        long nHDiff = std::abs( rEntry.mnHeight - nHeight );
        tools::Long nWDiff = std::abs( rEntry.mnWidth - nWidth );
        tools::Long nHDiff = std::abs( rEntry.mnHeight - nHeight );
        if( ((nWDiff <= nMaxWDiff) && (nHDiff < nMaxHDiff)) ||
            ((nWDiff < nMaxWDiff) && (nHDiff <= nMaxHDiff)) )
        {
diff --git a/sc/source/filter/excel/xltools.cxx b/sc/source/filter/excel/xltools.cxx
index 454de576..1de11ca 100644
--- a/sc/source/filter/excel/xltools.cxx
+++ b/sc/source/filter/excel/xltools.cxx
@@ -302,13 +302,13 @@ sal_Int32 XclTools::GetHmmFromTwips( sal_Int32 nTwips )
    return GetHmmFromInch( GetInchFromTwips( nTwips ) );
}

sal_uInt16 XclTools::GetScColumnWidth( sal_uInt16 nXclWidth, long nScCharWidth )
sal_uInt16 XclTools::GetScColumnWidth( sal_uInt16 nXclWidth, tools::Long nScCharWidth )
{
    double fScWidth = static_cast< double >( nXclWidth ) / 256.0 * nScCharWidth - 0.5;
    return limit_cast< sal_uInt16 >( fScWidth );
}

sal_uInt16 XclTools::GetXclColumnWidth( sal_uInt16 nScWidth, long nScCharWidth )
sal_uInt16 XclTools::GetXclColumnWidth( sal_uInt16 nScWidth, tools::Long nScCharWidth )
{
    double fXclWidth = ( static_cast< double >( nScWidth ) + 0.5 ) * 256.0 / nScCharWidth;
    return limit_cast< sal_uInt16 >( fXclWidth );
@@ -316,7 +316,7 @@ sal_uInt16 XclTools::GetXclColumnWidth( sal_uInt16 nScWidth, long nScCharWidth )

// takes font height in twips (1/20 pt = 1/1440 in)
// returns correction value in 1/256th of *digit width* of default font
double XclTools::GetXclDefColWidthCorrection( long nXclDefFontHeight )
double XclTools::GetXclDefColWidthCorrection( tools::Long nXclDefFontHeight )
{
    // Excel uses *max digit width of default font* (W) as cell width unit. Also it has 5-pixel
    // "correction" to cell widths (ECMA-376-1:2016 18.3.1.81): each cell has 1-pixel padding, then
diff --git a/sc/source/filter/html/htmlimp.cxx b/sc/source/filter/html/htmlimp.cxx
index 6e1076c..4a9a3a9 100644
--- a/sc/source/filter/html/htmlimp.cxx
+++ b/sc/source/filter/html/htmlimp.cxx
@@ -71,11 +71,11 @@ ScHTMLImport::ScHTMLImport( ScDocument* pDocP, const OUString& rBaseURL, const S
    {
        const SfxItemSet& rSet = pStyleSheet->GetItemSet();
        const SvxLRSpaceItem* pLRItem = &rSet.Get( ATTR_LRSPACE );
        long nLeftMargin   = pLRItem->GetLeft();
        long nRightMargin  = pLRItem->GetRight();
        tools::Long nLeftMargin   = pLRItem->GetLeft();
        tools::Long nRightMargin  = pLRItem->GetRight();
        const SvxULSpaceItem* pULItem = &rSet.Get( ATTR_ULSPACE );
        long nTopMargin    = pULItem->GetUpper();
        long nBottomMargin = pULItem->GetLower();
        tools::Long nTopMargin    = pULItem->GetUpper();
        tools::Long nBottomMargin = pULItem->GetLower();
        aPageSize = rSet.Get(ATTR_PAGE_SIZE).GetSize();
        if ( !aPageSize.Width() || !aPageSize.Height() )
        {
diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx
index f632d87..5490c49 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -413,7 +413,7 @@ void ScHTMLLayoutParser::ModifyOffset( ScHTMLColOffset* pOffset, sal_uInt16& nOl
        nNewOffset = static_cast<sal_uInt16>((*pOffset)[nPos2]);
        return ;
    }
    long nDiff = nNewOffset - nOldOffset;
    tools::Long nDiff = nNewOffset - nOldOffset;
    if ( nDiff < 0 )
    {
        do
@@ -1299,22 +1299,22 @@ void ScHTMLLayoutParser::Image( HtmlImportInfo* pInfo )
            break;
            case HtmlOptionId::WIDTH:
            {
                pImage->aSize.setWidth( static_cast<long>(rOption.GetNumber()) );
                pImage->aSize.setWidth( static_cast<tools::Long>(rOption.GetNumber()) );
            }
            break;
            case HtmlOptionId::HEIGHT:
            {
                pImage->aSize.setHeight( static_cast<long>(rOption.GetNumber()) );
                pImage->aSize.setHeight( static_cast<tools::Long>(rOption.GetNumber()) );
            }
            break;
            case HtmlOptionId::HSPACE:
            {
                pImage->aSpace.setX( static_cast<long>(rOption.GetNumber()) );
                pImage->aSpace.setX( static_cast<tools::Long>(rOption.GetNumber()) );
            }
            break;
            case HtmlOptionId::VSPACE:
            {
                pImage->aSpace.setY( static_cast<long>(rOption.GetNumber()) );
                pImage->aSpace.setY( static_cast<tools::Long>(rOption.GetNumber()) );
            }
            break;
            default: break;
@@ -1350,7 +1350,7 @@ void ScHTMLLayoutParser::Image( HtmlImportInfo* pInfo )
    if (mxActEntry->maImageList.empty())
        return;

    long nWidth = 0;
    tools::Long nWidth = 0;
    for (const std::unique_ptr<ScHTMLImage> & pI : mxActEntry->maImageList)
    {
        if ( pI->nDir & nHorizontal )
@@ -2232,8 +2232,8 @@ void ScHTMLTable::ApplyCellBorders( ScDocument* pDoc, const ScAddress& rFirstPos
    {
        const SCCOL nLastCol = maSize.mnCols - 1;
        const SCROW nLastRow = maSize.mnRows - 1;
        const long nOuterLine = DEF_LINE_WIDTH_2;
        const long nInnerLine = DEF_LINE_WIDTH_0;
        const tools::Long nOuterLine = DEF_LINE_WIDTH_2;
        const tools::Long nInnerLine = DEF_LINE_WIDTH_0;
        SvxBorderLine aOuterLine(nullptr, nOuterLine, SvxBorderLineStyle::SOLID);
        SvxBorderLine aInnerLine(nullptr, nInnerLine, SvxBorderLineStyle::SOLID);
        SvxBoxItem aBorderItem( ATTR_BORDER );
diff --git a/sc/source/filter/inc/formel.hxx b/sc/source/filter/inc/formel.hxx
index 3dea5ea..3445e07 100644
--- a/sc/source/filter/inc/formel.hxx
+++ b/sc/source/filter/inc/formel.hxx
@@ -108,7 +108,7 @@ protected:
    SvStream&           aIn;
    sal_Int32           nBytesLeft;

    inline void         Ignore( const long nSeekRel );
    inline void         Ignore( const tools::Long nSeekRel );
    inline void         Read( sal_uInt8& nByte );
    inline void         Read( sal_uInt16& nUINT16 );
    inline void         Read( sal_Int16& nINT16 );
@@ -129,7 +129,7 @@ protected:
    using               ConverterBase::Reset;
};

inline void LotusConverterBase::Ignore( const long nSeekRel )
inline void LotusConverterBase::Ignore( const tools::Long nSeekRel )
{
    aIn.SeekRel( nSeekRel );
    nBytesLeft -= nSeekRel;
diff --git a/sc/source/filter/inc/xlroot.hxx b/sc/source/filter/inc/xlroot.hxx
index 781a9b6..204e686 100644
--- a/sc/source/filter/inc/xlroot.hxx
+++ b/sc/source/filter/inc/xlroot.hxx
@@ -22,6 +22,7 @@

#include <i18nlangtag/lang.h>
#include <tools/ref.hxx>
#include <tools/long.hxx>
#include "xlconst.hxx"
#include <memory>

@@ -103,7 +104,7 @@ struct XclRootData

    double              mfScreenPixelX;     /// Width of a screen pixel (1/100 mm).
    double              mfScreenPixelY;     /// Height of a screen pixel (1/100 mm).
    long                mnCharWidth;        /// Width of '0' in default font (twips).
    tools::Long                mnCharWidth;        /// Width of '0' in default font (twips).
    SCTAB               mnScTab;            /// Current Calc sheet index.
    const bool          mbExport;           /// false = Import, true = Export.

@@ -153,7 +154,7 @@ public:
    /** Returns the default script type, e.g. for blank cells. */
    sal_Int16    GetDefApiScript() const { return mrData.mnDefApiScript; }
    /** Returns the width of the '0' character (default font) for the current printer (twips). */
    long         GetCharWidth() const { return mrData.mnCharWidth; }
    tools::Long         GetCharWidth() const { return mrData.mnCharWidth; }
    /** Returns the current Calc sheet index. */
    bool         IsInGlobals() const { return mrData.mnScTab == SCTAB_GLOBAL; }
    /** Returns the current Calc sheet index. */
diff --git a/sc/source/filter/inc/xltools.hxx b/sc/source/filter/inc/xltools.hxx
index 212d9e4..0b58753 100644
--- a/sc/source/filter/inc/xltools.hxx
+++ b/sc/source/filter/inc/xltools.hxx
@@ -146,14 +146,14 @@ public:
    /** Returns the Calc column width (twips) for the passed Excel width.
     *  Excel Column width is stored as 1/256th of a character.
        @param nScCharWidth  Width of the '0' character in Calc (twips). */
    static sal_uInt16       GetScColumnWidth( sal_uInt16 nXclWidth, long nScCharWidth );
    static sal_uInt16       GetScColumnWidth( sal_uInt16 nXclWidth, tools::Long nScCharWidth );
    /** Returns the Excel column width for the passed Calc width (twips).
        @param nScCharWidth  Width of the '0' character in Calc (twips). */
    static sal_uInt16   GetXclColumnWidth( sal_uInt16 nScWidth, long nScCharWidth );
    static sal_uInt16   GetXclColumnWidth( sal_uInt16 nScWidth, tools::Long nScCharWidth );

    /** Returns a correction value to convert column widths from/to default column widths.
        @param nXclDefFontHeight  Excel height of application default font. */
    static double       GetXclDefColWidthCorrection( long nXclDefFontHeight );
    static double       GetXclDefColWidthCorrection( tools::Long nXclDefFontHeight );

    // formatting -------------------------------------------------------------

diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx
index ee426a1..7bf9bd0 100644
--- a/sc/source/filter/orcus/interface.cxx
+++ b/sc/source/filter/orcus/interface.cxx
@@ -1194,7 +1194,7 @@ void ScOrcusSheet::set_date_time(
    sal_uInt32 nSec = floor(second);
    sal_uInt32 nNanoSec = (second - nSec) * ::tools::Time::nanoSecPerSec;
    tools::Time aTime(hour, minute, nSec, nNanoSec);
    long nDateDiff = aDate - pFormatter->GetNullDate();
    tools::Long nDateDiff = aDate - pFormatter->GetNullDate();

    double fTime =
        static_cast<double>(aTime.GetNanoSec()) / ::tools::Time::nanoSecPerSec +
diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx
index 46bc08a..9cb698a 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -484,7 +484,7 @@ bool ScEEImport::GraphicSize( SCCOL nCol, SCROW nRow, ScEEParseEntry* pE )
        return false;
    bool bHasGraphics = false;
    OutputDevice* pDefaultDev = Application::GetDefaultDevice();
    long nWidth, nHeight;
    tools::Long nWidth, nHeight;
    nWidth = nHeight = 0;
    char nDir = nHorizontal;
    for (const std::unique_ptr<ScHTMLImage> & pImage : pE->maImageList)
@@ -508,11 +508,11 @@ bool ScEEImport::GraphicSize( SCCOL nCol, SCROW nRow, ScEEParseEntry* pE )
    }
    // Column widths
    ColWidthsMap& rColWidths = mpParser->GetColWidths();
    long nThisWidth = 0;
    tools::Long nThisWidth = 0;
    ColWidthsMap::const_iterator it = rColWidths.find( nCol );
    if ( it != rColWidths.end() )
        nThisWidth = it->second;
    long nColWidths = nThisWidth;
    tools::Long nColWidths = nThisWidth;
    SCCOL nColSpanCol = nCol + pE->nColOverlap;
    for ( SCCOL nC = nCol + 1; nC < nColSpanCol; nC++ )
    {
@@ -532,7 +532,7 @@ bool ScEEImport::GraphicSize( SCCOL nCol, SCROW nRow, ScEEParseEntry* pE )
    for ( SCROW nR = nRow; nR < nRow + nRowSpan; nR++ )
    {
        RowHeightMap::const_iterator it2 = maRowHeights.find( nR );
        long nRowHeight = it2 == maRowHeights.end() ? 0 : it2->second;
        tools::Long nRowHeight = it2 == maRowHeights.end() ? 0 : it2->second;
        if ( nHeight > nRowHeight )
        {
            maRowHeights[ nR ] = nHeight;
@@ -556,8 +556,8 @@ void ScEEImport::InsertGraphic( SCCOL nCol, SCROW nRow, SCTAB nTab,
    OutputDevice* pDefaultDev = Application::GetDefaultDevice();

    Point aCellInsertPos(
        static_cast<long>(static_cast<double>(mpDoc->GetColOffset( nCol, nTab )) * HMM_PER_TWIPS),
        static_cast<long>(static_cast<double>(mpDoc->GetRowOffset( nRow, nTab )) * HMM_PER_TWIPS) );
        static_cast<tools::Long>(static_cast<double>(mpDoc->GetColOffset( nCol, nTab )) * HMM_PER_TWIPS),
        static_cast<tools::Long>(static_cast<double>(mpDoc->GetRowOffset( nRow, nTab )) * HMM_PER_TWIPS) );

    Point aInsertPos( aCellInsertPos );
    Point aSpace;
diff --git a/sc/source/filter/rtf/rtfparse.cxx b/sc/source/filter/rtf/rtfparse.cxx
index 3fe14db..1666992 100644
--- a/sc/source/filter/rtf/rtfparse.cxx
+++ b/sc/source/filter/rtf/rtfparse.cxx
@@ -42,7 +42,7 @@ ScRTFParser::ScRTFParser( EditEngine* pEditP ) :
        bNewDef( false )
{
    // RTF default FontSize 12Pt
    long nMM = OutputDevice::LogicToLogic( 12, MapUnit::MapPoint, MapUnit::Map100thMM );
    tools::Long nMM = OutputDevice::LogicToLogic( 12, MapUnit::MapPoint, MapUnit::Map100thMM );
    pPool->SetPoolDefaultItem( SvxFontHeightItem( nMM, 100, EE_CHAR_FONTHEIGHT ) );
    // Free-flying pInsDefault
    pInsDefault.reset( new ScRTFCellDefault( pPool ) );
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index 4bf9b3a..9a11002 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -875,7 +875,7 @@ XclTxo::XclTxo( const XclExpRoot& rRoot, const SdrTextObj& rTextObj ) :
    SetVerAlign( lcl_GetVerAlignFromItemSet( rItemSet ) );

    // rotation
    long nAngle = rTextObj.GetRotateAngle();
    tools::Long nAngle = rTextObj.GetRotateAngle();
    if( (4500 < nAngle) && (nAngle < 13500) )
        mnRotation = EXC_OBJ_ORIENT_90CCW;
    else if( (22500 < nAngle) && (nAngle < 31500) )
diff --git a/sc/source/ui/Accessibility/AccessibleCell.cxx b/sc/source/ui/Accessibility/AccessibleCell.cxx
index d400e11..61cb5a9 100644
--- a/sc/source/ui/Accessibility/AccessibleCell.cxx
+++ b/sc/source/ui/Accessibility/AccessibleCell.cxx
@@ -166,7 +166,7 @@ tools::Rectangle ScAccessibleCell::GetBoundingBox() const
    tools::Rectangle aCellRect;
    if (mpViewShell)
    {
        long nSizeX, nSizeY;
        tools::Long nSizeX, nSizeY;
        mpViewShell->GetViewData().GetMergeSizePixel(
            maCellAddress.Col(), maCellAddress.Row(), nSizeX, nSizeY);
        aCellRect.SetSize(Size(nSizeX, nSizeY));
diff --git a/sc/source/ui/Accessibility/AccessibleDocument.cxx b/sc/source/ui/Accessibility/AccessibleDocument.cxx
index 1efcd40..1015063d 100644
--- a/sc/source/ui/Accessibility/AccessibleDocument.cxx
+++ b/sc/source/ui/Accessibility/AccessibleDocument.cxx
@@ -215,7 +215,7 @@ public:
    virtual bool ReplaceChild (
        ::accessibility::AccessibleShape* pCurrentChild,
        const css::uno::Reference< css::drawing::XShape >& _rxShape,
        const long _nIndex,
        const tools::Long _nIndex,
        const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo
    ) override;

@@ -418,7 +418,7 @@ void ScChildrenShapes::Notify(SfxBroadcaster&, const SfxHint& rHint)

bool ScChildrenShapes::ReplaceChild (::accessibility::AccessibleShape* pCurrentChild,
        const css::uno::Reference< css::drawing::XShape >& _rxShape,
        const long /*_nIndex*/, const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo)
        const tools::Long /*_nIndex*/, const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo)
{
    // create the new child
    rtl::Reference< ::accessibility::AccessibleShape > pReplacement(::accessibility::ShapeTypeHandler::Instance().CreateAccessibleObject (
diff --git a/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx b/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx
index d7a9ebb..568b4a2 100644
--- a/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx
+++ b/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx
@@ -653,7 +653,7 @@ public:
    virtual bool ReplaceChild (
        ::accessibility::AccessibleShape* pCurrentChild,
        const css::uno::Reference< css::drawing::XShape >& _rxShape,
        const long _nIndex,
        const tools::Long _nIndex,
        const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo
    ) override;

@@ -802,7 +802,7 @@ void ScShapeChildren::VisAreaChanged() const

bool ScShapeChildren::ReplaceChild (::accessibility::AccessibleShape* /* pCurrentChild */,
    const css::uno::Reference< css::drawing::XShape >& /* _rxShape */,
        const long /* _nIndex */, const ::accessibility::AccessibleShapeTreeInfo& /* _rShapeTreeInfo */)
        const tools::Long /* _nIndex */, const ::accessibility::AccessibleShapeTreeInfo& /* _rShapeTreeInfo */)
{
    OSL_FAIL("should not be called in the page preview");
    return false;
@@ -1079,18 +1079,18 @@ struct ScPagePreviewCountData
    //  order is background shapes, header, table or notes, footer, foreground shapes, controls

    tools::Rectangle aVisRect;
    long nBackShapes;
    long nHeaders;
    long nTables;
    long nNoteParagraphs;
    long nFooters;
    long nForeShapes;
    long nControls;
    tools::Long nBackShapes;
    tools::Long nHeaders;
    tools::Long nTables;
    tools::Long nNoteParagraphs;
    tools::Long nFooters;
    tools::Long nForeShapes;
    tools::Long nControls;

    ScPagePreviewCountData( const ScPreviewLocationData& rData, const vcl::Window* pSizeWindow,
        const ScNotesChildren* pNotesChildren, const ScShapeChildren* pShapeChildren );

    long GetTotal() const
    tools::Long GetTotal() const
    {
        return nBackShapes + nHeaders + nTables + nNoteParagraphs + nFooters + nForeShapes + nControls;
    }
@@ -1347,7 +1347,7 @@ sal_Int32 SAL_CALL ScAccessibleDocumentPagePreview::getAccessibleChildCount()
    SolarMutexGuard aGuard;
    IsObjectValid();

    long nRet = 0;
    tools::Long nRet = 0;
    if ( mpViewShell )
    {
        ScPagePreviewCountData aCount( mpViewShell->GetLocationData(), mpViewShell->GetWindow(), GetNotesChildren(), GetShapeChildren() );
diff --git a/sc/source/ui/Accessibility/AccessiblePreviewTable.cxx b/sc/source/ui/Accessibility/AccessiblePreviewTable.cxx
index bd47bf5..5db9a20 100644
--- a/sc/source/ui/Accessibility/AccessiblePreviewTable.cxx
+++ b/sc/source/ui/Accessibility/AccessiblePreviewTable.cxx
@@ -290,7 +290,7 @@ uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewTable::getAccessibleCe
    if ( mpTableInfo && nColumn >= 0 && nRow >= 0 && nColumn < mpTableInfo->GetCols() && nRow < mpTableInfo->GetRows() )
    {
        //  index iterates horizontally
        long nNewIndex = nRow * mpTableInfo->GetCols() + nColumn;
        tools::Long nNewIndex = nRow * mpTableInfo->GetCols() + nColumn;

        const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[nColumn];
        const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[nRow];
@@ -460,7 +460,7 @@ sal_Int32 SAL_CALL ScAccessiblePreviewTable::getAccessibleChildCount()

    FillTableInfo();

    long nRet = 0;
    tools::Long nRet = 0;
    if ( mpTableInfo )
        nRet = static_cast<sal_Int32>(mpTableInfo->GetCols()) * mpTableInfo->GetRows();
    return nRet;
@@ -476,12 +476,12 @@ uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewTable::getAccessibleCh
    uno::Reference<XAccessible> xRet;
    if ( mpTableInfo )
    {
        long nColumns = mpTableInfo->GetCols();
        tools::Long nColumns = mpTableInfo->GetCols();
        if ( nColumns > 0 )
        {
            // nCol, nRow are within the visible table, not the document
            long nCol = nIndex % nColumns;
            long nRow = nIndex / nColumns;
            tools::Long nCol = nIndex % nColumns;
            tools::Long nRow = nIndex / nColumns;

            xRet = getAccessibleCellAt( nRow, nCol );
        }
diff --git a/sc/source/ui/Accessibility/AccessibleText.cxx b/sc/source/ui/Accessibility/AccessibleText.cxx
index fd43850..3166fbd 100644
--- a/sc/source/ui/Accessibility/AccessibleText.cxx
+++ b/sc/source/ui/Accessibility/AccessibleText.cxx
@@ -488,14 +488,14 @@ SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
    if ( pDocShell && pEditEngine && mpViewShell )
    {
        ScDocument& rDoc = pDocShell->GetDocument();
        long nSizeX, nSizeY;
        tools::Long nSizeX, nSizeY;
        mpViewShell->GetViewData().GetMergeSizePixel(
            aCellPos.Col(), aCellPos.Row(), nSizeX, nSizeY);

        Size aSize(nSizeX, nSizeY);

        // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
        long nIndent = 0;
        tools::Long nIndent = 0;
        const SvxHorJustifyItem* pHorJustifyItem = rDoc.GetAttr( aCellPos, ATTR_HOR_JUSTIFY );
        SvxCellHorJustify eHorJust = pHorJustifyItem ? pHorJustifyItem->GetValue() : SvxCellHorJustify::Standard;
        if ( eHorJust == SvxCellHorJustify::Left )
@@ -503,7 +503,7 @@ SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
            const ScIndentItem* pIndentItem = rDoc.GetAttr( aCellPos, ATTR_INDENT );
            if ( pIndentItem )
            {
                nIndent = static_cast< long >( pIndentItem->GetValue() );
                nIndent = static_cast< tools::Long >( pIndentItem->GetValue() );
            }
        }

@@ -511,11 +511,11 @@ SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
        ScViewData& rViewData = mpViewShell->GetViewData();
        double nPPTX = rViewData.GetPPTX();
        double nPPTY = rViewData.GetPPTY();
        long nLeftM = ( pMarginItem ? static_cast< long >( ( pMarginItem->GetLeftMargin() + nIndent ) * nPPTX ) : 0 );
        long nTopM = ( pMarginItem ? static_cast< long >( pMarginItem->GetTopMargin() * nPPTY ) : 0 );
        long nRightM = ( pMarginItem ? static_cast< long >( pMarginItem->GetRightMargin() * nPPTX ) : 0 );
        long nBottomM = ( pMarginItem ? static_cast< long >( pMarginItem->GetBottomMargin() * nPPTY ) : 0 );
        long nWidth = aSize.getWidth() - nLeftM - nRightM;
        tools::Long nLeftM = ( pMarginItem ? static_cast< tools::Long >( ( pMarginItem->GetLeftMargin() + nIndent ) * nPPTX ) : 0 );
        tools::Long nTopM = ( pMarginItem ? static_cast< tools::Long >( pMarginItem->GetTopMargin() * nPPTY ) : 0 );
        tools::Long nRightM = ( pMarginItem ? static_cast< tools::Long >( pMarginItem->GetRightMargin() * nPPTX ) : 0 );
        tools::Long nBottomM = ( pMarginItem ? static_cast< tools::Long >( pMarginItem->GetBottomMargin() * nPPTY ) : 0 );
        tools::Long nWidth = aSize.getWidth() - nLeftM - nRightM;
        aSize.setWidth( nWidth );
        aSize.setHeight( aSize.getHeight() - nTopM - nBottomM );

@@ -539,7 +539,7 @@ SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
        if( pItem && (pItem->GetValue() != 0) )
        {
            pEditEngine->SetPaperSize( Size( LONG_MAX, aSize.getHeight() ) );
            long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
            tools::Long nTxtWidth = static_cast< tools::Long >( pEditEngine->CalcTextWidth() );
            aSize.setWidth( std::max( aSize.getWidth(), nTxtWidth + 2 ) );
        }
        else
@@ -549,7 +549,7 @@ SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
            bool bLineBreak = ( pLineBreakItem && pLineBreakItem->GetValue() );
            if ( !bLineBreak )
            {
                long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
                tools::Long nTxtWidth = static_cast< tools::Long >( pEditEngine->CalcTextWidth() );
                aSize.setWidth( ::std::max( aSize.getWidth(), nTxtWidth ) );
            }
        }
@@ -567,11 +567,11 @@ SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
        {
            aTextSize = pWin->LogicToPixel( Size( pEditEngine->CalcTextWidth(), pEditEngine->GetTextHeight() ), pEditEngine->GetRefMapMode() );
        }
        long nTextWidth = aTextSize.Width();
        long nTextHeight = aTextSize.Height();
        tools::Long nTextWidth = aTextSize.Width();
        tools::Long nTextHeight = aTextSize.Height();

        long nOffsetX = nLeftM;
        long nDiffX = nTextWidth - nWidth;
        tools::Long nOffsetX = nLeftM;
        tools::Long nDiffX = nTextWidth - nWidth;
        if ( nDiffX > 0 )
        {
            switch ( eHorJust )
@@ -593,7 +593,7 @@ SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
            }
        }

        long nOffsetY = 0;
        tools::Long nOffsetY = 0;
        const SvxVerJustifyItem* pVerJustifyItem = rDoc.GetAttr( aCellPos, ATTR_VER_JUSTIFY );
        SvxCellVerJustify eVerJust = ( pVerJustifyItem ? pVerJustifyItem->GetValue() : SvxCellVerJustify::Standard );
        switch ( eVerJust )
diff --git a/sc/source/ui/app/client.cxx b/sc/source/ui/app/client.cxx
index a121531..ac6b0e1 100644
--- a/sc/source/ui/app/client.cxx
+++ b/sc/source/ui/app/client.cxx
@@ -110,26 +110,26 @@ void ScClient::RequestNewObjectArea( tools::Rectangle& aLogicRect )

    if (aLogicRect.Right() > aPageRect.Right())
    {
        long nDiff = aLogicRect.Right() - aPageRect.Right();
        tools::Long nDiff = aLogicRect.Right() - aPageRect.Right();
        aLogicRect.AdjustLeft( -nDiff );
        aLogicRect.AdjustRight( -nDiff );
    }
    if (aLogicRect.Bottom() > aPageRect.Bottom())
    {
        long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
        tools::Long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
        aLogicRect.AdjustTop( -nDiff );
        aLogicRect.AdjustBottom( -nDiff );
    }

    if (aLogicRect.Left() < aPageRect.Left())
    {
        long nDiff = aLogicRect.Left() - aPageRect.Left();
        tools::Long nDiff = aLogicRect.Left() - aPageRect.Left();
        aLogicRect.AdjustRight( -nDiff );
        aLogicRect.AdjustLeft( -nDiff );
    }
    if (aLogicRect.Top() < aPageRect.Top())
    {
        long nDiff = aLogicRect.Top() - aPageRect.Top();
        tools::Long nDiff = aLogicRect.Top() - aPageRect.Top();
        aLogicRect.AdjustBottom( -nDiff );
        aLogicRect.AdjustTop( -nDiff );
    }
@@ -206,7 +206,7 @@ void ScClient::ViewChanged()
    tools::Rectangle aLogicRect = pDrawObj->GetLogicRect();
    Fraction aFractX = GetScaleWidth() * aVisSize.Width();
    Fraction aFractY = GetScaleHeight() * aVisSize.Height();
    aVisSize = Size( static_cast<long>(aFractX), static_cast<long>(aFractY) ); // Scaled for Draw model
    aVisSize = Size( static_cast<tools::Long>(aFractX), static_cast<tools::Long>(aFractY) ); // Scaled for Draw model

    //  pClientData->SetObjArea before pDrawObj->SetLogicRect, so that we don't
    //  calculate wrong scalings:
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 2359dc3..075e012 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -429,8 +429,8 @@ handle_r1c1:
}

ReferenceMark ScInputHandler::GetReferenceMark( const ScViewData& rViewData, ScDocShell* pDocSh,
                                    long nX1, long nX2, long nY1, long nY2,
                                    long nTab, const Color& rColor )
                                    tools::Long nX1, tools::Long nX2, tools::Long nY1, tools::Long nY2,
                                    tools::Long nTab, const Color& rColor )
{
    ScSplitPos eWhich = rViewData.GetActivePart();

@@ -447,15 +447,15 @@ ReferenceMark ScInputHandler::GetReferenceMark( const ScViewData& rViewData, ScD

        Point aTopLeft = rViewData.GetPrintTwipsPos(nCol1, nRow1);
        Point aBottomRight = rViewData.GetPrintTwipsPos(nCol2 + 1, nRow2 + 1);
        long nSizeX = aBottomRight.X() - aTopLeft.X() - 1;
        long nSizeY = aBottomRight.Y() - aTopLeft.Y() - 1;
        tools::Long nSizeX = aBottomRight.X() - aTopLeft.X() - 1;
        tools::Long nSizeY = aBottomRight.Y() - aTopLeft.Y() - 1;

        return ReferenceMark(aTopLeft.X(), aTopLeft.Y(), nSizeX, nSizeY, nTab, rColor);
    }

    Point aScrPos = rViewData.GetScrPos( nX1, nY1, eWhich );
    long nScrX = aScrPos.X();
    long nScrY = aScrPos.Y();
    tools::Long nScrX = aScrPos.X();
    tools::Long nScrY = aScrPos.Y();

    double nPPTX = rViewData.GetPPTX();
    double nPPTY = rViewData.GetPPTY();
@@ -505,11 +505,11 @@ void ScInputHandler::UpdateLokReferenceMarks()

        const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig();
        Color aRefColor( rColorCfg.GetColorValue( svtools::CALCREFERENCE ).nColor );
        long nX1 = rViewData.GetRefStartX();
        long nX2 = rViewData.GetRefEndX();
        long nY1 = rViewData.GetRefStartY();
        long nY2 = rViewData.GetRefEndY();
        long nTab = rViewData.GetTabNo();
        tools::Long nX1 = rViewData.GetRefStartX();
        tools::Long nX2 = rViewData.GetRefEndX();
        tools::Long nY1 = rViewData.GetRefStartY();
        tools::Long nY2 = rViewData.GetRefEndY();
        tools::Long nTab = rViewData.GetTabNo();

        PutInOrder(nX1, nX2);
        PutInOrder(nY1, nY2);
@@ -532,11 +532,11 @@ void ScInputHandler::UpdateLokReferenceMarks()
            ScRange aRef = rData.aRef;
            aRef.PutInOrder();

            long nX1 = aRef.aStart.Col();
            long nX2 = aRef.aEnd.Col();
            long nY1 = aRef.aStart.Row();
            long nY2 = aRef.aEnd.Row();
            long nTab = aRef.aStart.Tab();
            tools::Long nX1 = aRef.aStart.Col();
            tools::Long nX2 = aRef.aEnd.Col();
            tools::Long nY1 = aRef.aStart.Row();
            tools::Long nY2 = aRef.aEnd.Row();
            tools::Long nTab = aRef.aStart.Tab();

            aReferenceMarks[i + nAdditionalMarks] = ScInputHandler::GetReferenceMark( rViewData, pDocSh,
                                                                          nX1, nX2, nY1, nY2,
@@ -613,7 +613,7 @@ void ScInputHandler::UpdateRange( sal_uInt16 nIndex, const ScRange& rNew )
        DataChanged();
        bInRangeUpdate = false;

        long nDiff = aNewStr.getLength() - static_cast<long>(nOldEnd-nOldStart);
        tools::Long nDiff = aNewStr.getLength() - static_cast<tools::Long>(nOldEnd-nOldStart);

        rData.aRef = rNew;
        rData.nSelEnd = rData.nSelEnd + nDiff;
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index ea7ba58..3116116 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -75,13 +75,13 @@

namespace com::sun::star::accessibility { class XAccessible; }

const long THESIZE = 1000000;            // Should be more than enough!
const long INPUTLINE_INSET_MARGIN = 2;   // Space between border and interior widgets of input line
const long LEFT_OFFSET = 5;              // Left offset of input line
const tools::Long THESIZE = 1000000;            // Should be more than enough!
const tools::Long INPUTLINE_INSET_MARGIN = 2;   // Space between border and interior widgets of input line
const tools::Long LEFT_OFFSET = 5;              // Left offset of input line
//TODO const long BUTTON_OFFSET = 2;            // Space between input line and button to expand/collapse
const long INPUTWIN_MULTILINES = 6;      // Initial number of lines within multiline dropdown
const long TOOLBOX_WINDOW_HEIGHT = 22;   // Height of toolbox window in pixels - TODO: The same on all systems?
const long POSITION_COMBOBOX_WIDTH = 18; // Width of position combobox in characters
const tools::Long INPUTWIN_MULTILINES = 6;      // Initial number of lines within multiline dropdown
const tools::Long TOOLBOX_WINDOW_HEIGHT = 22;   // Height of toolbox window in pixels - TODO: The same on all systems?
const tools::Long POSITION_COMBOBOX_WIDTH = 18; // Width of position combobox in characters

using com::sun::star::uno::Reference;
using com::sun::star::uno::UNO_QUERY;
@@ -482,7 +482,7 @@ void ScInputWindow::Resize()
    Size aSize = GetSizePixel();

    //(-10) to allow margin between sidebar and formulabar
    long margin = (comphelper::LibreOfficeKit::isActive()) ? 10 : 0;
    tools::Long margin = (comphelper::LibreOfficeKit::isActive()) ? 10 : 0;
    Size aTextWindowSize(aSize.Width() - mxTextWindow->GetPosPixel().X() - LEFT_OFFSET - margin,
                         mxTextWindow->GetPixelHeightForLines());
    mxTextWindow->SetSizePixel(aTextWindowSize);
@@ -749,7 +749,7 @@ void ScInputWindow::MouseMove( const MouseEvent& rMEvt )
    if (bInResize)
    {
        // detect direction
        long nResizeThreshold = long(TOOLBOX_WINDOW_HEIGHT * 0.7);
        tools::Long nResizeThreshold = tools::Long(TOOLBOX_WINDOW_HEIGHT * 0.7);
        bool bResetPointerPos = false;

        // Detect attempt to expand toolbar too much
@@ -1096,8 +1096,8 @@ void ScInputBarGroup::TextGrabFocus()
    mxTextWndGroup->TextGrabFocus();
}

constexpr long gnBorderWidth = INPUTLINE_INSET_MARGIN + 1;
constexpr long gnBorderHeight = INPUTLINE_INSET_MARGIN + 1;
constexpr tools::Long gnBorderWidth = INPUTLINE_INSET_MARGIN + 1;
constexpr tools::Long gnBorderHeight = INPUTLINE_INSET_MARGIN + 1;

ScTextWndGroup::ScTextWndGroup(ScInputBarGroup& rParent, ScTabViewShell* pViewSh)
    : mxTextWnd(new ScTextWnd(*this, pViewSh))
@@ -1122,17 +1122,17 @@ EditView* ScTextWndGroup::GetEditView()
    return mxTextWnd->GetEditView();
}

long ScTextWndGroup::GetLastNumExpandedLines() const
tools::Long ScTextWndGroup::GetLastNumExpandedLines() const
{
    return mxTextWnd->GetLastNumExpandedLines();
}

long ScTextWndGroup::GetNumLines() const
tools::Long ScTextWndGroup::GetNumLines() const
{
    return mxTextWnd->GetNumLines();
}

int ScTextWndGroup::GetPixelHeightForLines(long nLines)
int ScTextWndGroup::GetPixelHeightForLines(tools::Long nLines)
{
    return mxTextWnd->GetPixelHeightForLines(nLines) + 2 * gnBorderHeight;
}
@@ -1175,7 +1175,7 @@ void ScTextWndGroup::SetScrollPolicy()
        mxScrollWin->set_vpolicy(VclPolicyType::NEVER);
}

void ScTextWndGroup::SetNumLines(long nLines)
void ScTextWndGroup::SetNumLines(tools::Long nLines)
{
    mxTextWnd->SetNumLines(nLines);
}
@@ -1238,14 +1238,14 @@ EditView* ScTextWnd::GetEditView()

bool ScTextWnd::HasEditView() const { return m_xEditView != nullptr; }

int ScTextWnd::GetPixelHeightForLines(long nLines)
int ScTextWnd::GetPixelHeightForLines(tools::Long nLines)
{
    // add padding (for the borders of the window)
    OutputDevice& rDevice = GetDrawingArea()->get_ref_device();
    return rDevice.LogicToPixel(Size(0, nLines * rDevice.GetTextHeight())).Height() + 1;
}

void ScTextWnd::SetNumLines(long nLines)
void ScTextWnd::SetNumLines(tools::Long nLines)
{
    mnLines = nLines;
    if ( nLines > 1 )
@@ -1265,7 +1265,7 @@ void ScTextWnd::Resize()
        m_xEditView->SetOutputArea( aOutputArea );

        // Don't leave an empty area at the bottom if we can move the text down.
        long nMaxVisAreaTop = m_xEditEngine->GetTextHeight() - aOutputArea.GetHeight();
        tools::Long nMaxVisAreaTop = m_xEditEngine->GetTextHeight() - aOutputArea.GetHeight();
        if (m_xEditView->GetVisArea().Top() > nMaxVisAreaTop)
        {
            m_xEditView->Scroll(0, m_xEditView->GetVisArea().Top() - nMaxVisAreaTop);
@@ -1401,7 +1401,7 @@ static void lcl_ModifyRTLVisArea( EditView* pEditView )
{
    tools::Rectangle aVisArea = pEditView->GetVisArea();
    Size aPaper = pEditView->GetEditEngine()->GetPaperSize();
    long nDiff = aPaper.Width() - aVisArea.Right();
    tools::Long nDiff = aPaper.Width() - aVisArea.Right();
    aVisArea.AdjustLeft(nDiff );
    aVisArea.AdjustRight(nDiff );
    pEditView->SetVisArea(aVisArea);
@@ -1851,23 +1851,23 @@ void ScTextWnd::SetTextString( const OUString& rNewString )
            }
            else
            {
                long nTextSize = 0;
                tools::Long nTextSize = 0;
                sal_Int32 nDifPos;
                if (rNewString.getLength() > aString.getLength())
                    nDifPos = findFirstNonMatchingChar(rNewString, aString);
                else
                    nDifPos = findFirstNonMatchingChar(aString, rNewString);

                long nSize1 = GetTextWidth(aString);
                long nSize2 = GetTextWidth(rNewString);
                tools::Long nSize1 = GetTextWidth(aString);
                tools::Long nSize2 = GetTextWidth(rNewString);
                if ( nSize1>0 && nSize2>0 )
                    nTextSize = std::max( nSize1, nSize2 );
                else
                    nTextSize = GetOutputSizePixel().Width(); // Overflow

                Point aLogicStart = GetDrawingArea()->get_ref_device().PixelToLogic(Point(0,0));
                long nStartPos = aLogicStart.X();
                long nInvPos = nStartPos;
                tools::Long nStartPos = aLogicStart.X();
                tools::Long nInvPos = nStartPos;
                if (nDifPos)
                    nInvPos += GetTextWidth(aString.copy(0,nDifPos));

diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index ff50f6f..1b11a56 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -763,36 +763,36 @@ void ScTransferObj::InitDocShell(bool bLimitToPageSize)
    //      Size
    //! get while copying sizes

    long nPosX = 0;
    long nPosY = 0;
    tools::Long nPosX = 0;
    tools::Long nPosY = 0;

    for (nCol=0; nCol<nStartX; nCol++)
        nPosX += rDestDoc.GetColWidth( nCol, 0 );
    nPosY += rDestDoc.GetRowHeight( 0, nStartY-1, 0 );
    nPosX = static_cast<long>( nPosX * HMM_PER_TWIPS );
    nPosY = static_cast<long>( nPosY * HMM_PER_TWIPS );
    nPosX = static_cast<tools::Long>( nPosX * HMM_PER_TWIPS );
    nPosY = static_cast<tools::Long>( nPosY * HMM_PER_TWIPS );

    aPaperSize.setWidth( aPaperSize.Width() * 2 );       // limit OLE object to double of page size
    aPaperSize.setHeight( aPaperSize.Height() * 2 );

    long nSizeX = 0;
    long nSizeY = 0;
    tools::Long nSizeX = 0;
    tools::Long nSizeY = 0;
    for (nCol=nStartX; nCol<=nEndX; nCol++)
    {
        long nAdd = rDestDoc.GetColWidth( nCol, 0 );
        tools::Long nAdd = rDestDoc.GetColWidth( nCol, 0 );
        if ( bLimitToPageSize && nSizeX+nAdd > aPaperSize.Width() && nSizeX )   // above limit?
            break;
        nSizeX += nAdd;
    }
    for (SCROW nRow=nStartY; nRow<=nEndY; nRow++)
    {
        long nAdd = rDestDoc.GetRowHeight( nRow, 0 );
        tools::Long nAdd = rDestDoc.GetRowHeight( nRow, 0 );
        if ( bLimitToPageSize && nSizeY+nAdd > aPaperSize.Height() && nSizeY )  // above limit?
            break;
        nSizeY += nAdd;
    }
    nSizeX = static_cast<long>( nSizeX * HMM_PER_TWIPS );
    nSizeY = static_cast<long>( nSizeY * HMM_PER_TWIPS );
    nSizeX = static_cast<tools::Long>( nSizeX * HMM_PER_TWIPS );
    nSizeY = static_cast<tools::Long>( nSizeY * HMM_PER_TWIPS );

//      pDocSh->SetVisAreaSize( Size(nSizeX,nSizeY) );

diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx
index fc68fdc..40dc203 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -1063,12 +1063,12 @@ VclPtr<AbstractScLinkedAreaDlg> ScAbstractDialogFactory_Impl::CreateScLinkedArea

VclPtr<AbstractScMetricInputDlg> ScAbstractDialogFactory_Impl::CreateScMetricInputDlg(weld::Window* pParent,
                                                                const OString& sDialogName,
                                                                long            nCurrent,
                                                                long            nDefault,
                                                                tools::Long            nCurrent,
                                                                tools::Long            nDefault,
                                                                FieldUnit       eFUnit,
                                                                sal_uInt16      nDecimals,
                                                                long            nMaximum ,
                                                                long            nMinimum )
                                                                tools::Long            nMaximum ,
                                                                tools::Long            nMinimum )
{
    return VclPtr<AbstractScMetricInputDlg_Impl>::Create(std::make_unique<ScMetricInputDlg>(pParent, sDialogName, nCurrent ,nDefault, eFUnit,
        nDecimals, nMaximum , nMinimum));
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index fc2e992..1e3be87c 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -734,12 +734,12 @@ public:

    virtual VclPtr<AbstractScMetricInputDlg> CreateScMetricInputDlg(weld::Window* pParent,
                                                                const OString&  sDialogName,
                                                                long            nCurrent,
                                                                long            nDefault,
                                                                tools::Long            nCurrent,
                                                                tools::Long            nDefault,
                                                                FieldUnit       eFUnit,
                                                                sal_uInt16      nDecimals,
                                                                long            nMaximum,
                                                                long            nMinimum  = 0 ) override;
                                                                tools::Long            nMaximum,
                                                                tools::Long            nMinimum  = 0 ) override;

    virtual VclPtr<AbstractScMoveTableDlg> CreateScMoveTableDlg(weld::Window * pParent,
        const OUString& rDefault) override;
diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx
index 3d27f8b..07eb9b4 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -1322,7 +1322,7 @@ void ScCheckListMenuControl::launch(const tools::Rectangle& rRect)
    if (maConfig.mbRTL)
    {
        // In RTL mode, the logical "left" is visual "right".
        long nLeft = aRect.Left() - aRect.GetWidth();
        tools::Long nLeft = aRect.Left() - aRect.GetWidth();
        aRect.SetLeft( nLeft );
    }
    else if (mnWndWidth < aRect.GetWidth())
@@ -1330,7 +1330,7 @@ void ScCheckListMenuControl::launch(const tools::Rectangle& rRect)
        // Target rectangle (i.e. cell width) is wider than the window.
        // Simulate right-aligned launch by modifying the target rectangle
        // size.
        long nDiff = aRect.GetWidth() - mnWndWidth;
        tools::Long nDiff = aRect.GetWidth() - mnWndWidth;
        aRect.AdjustLeft(nDiff );
    }

diff --git a/sc/source/ui/cctrl/dpcontrol.cxx b/sc/source/ui/cctrl/dpcontrol.cxx
index 2ca4130..24620cd 100644
--- a/sc/source/ui/cctrl/dpcontrol.cxx
+++ b/sc/source/ui/cctrl/dpcontrol.cxx
@@ -123,7 +123,7 @@ void ScDPFieldButton::draw()
        mpOutDev->SetTextColor(mpStyle->GetButtonTextColor());

        Point aTextPos = maPos;
        long nTHeight = mpOutDev->GetTextHeight();
        tools::Long nTHeight = mpOutDev->GetTextHeight();
        aTextPos.setX(maPos.getX() + 2); // 2 = Margin
        aTextPos.setY(maPos.getY() + (maSize.Height()-nTHeight)/2);

@@ -141,10 +141,10 @@ void ScDPFieldButton::getPopupBoundingBox(Point& rPos, Size& rSize) const
{
    float fScaleFactor = mpOutDev->GetDPIScaleFactor();

    long nMaxSize = 18 * fScaleFactor; // Button max size in either dimension
    tools::Long nMaxSize = 18 * fScaleFactor; // Button max size in either dimension

    long nW = std::min(maSize.getWidth() / 2, nMaxSize);
    long nH = std::min(maSize.getHeight(),    nMaxSize);
    tools::Long nW = std::min(maSize.getWidth() / 2, nMaxSize);
    tools::Long nH = std::min(maSize.getHeight(),    nMaxSize);

    // #i114944# AutoFilter button is left-aligned in RTL.
    // DataPilot button is always right-aligned for now, so text output isn't affected.
diff --git a/sc/source/ui/cctrl/tbzoomsliderctrl.cxx b/sc/source/ui/cctrl/tbzoomsliderctrl.cxx
index 37335bbc..416a2ba 100644
--- a/sc/source/ui/cctrl/tbzoomsliderctrl.cxx
+++ b/sc/source/ui/cctrl/tbzoomsliderctrl.cxx
@@ -116,21 +116,21 @@ struct ScZoomSlider::ScZoomSliderWnd_Impl

constexpr sal_uInt16 gnSliderCenter(100);

const long nButtonWidth     = 10;
const long nButtonHeight    = 10;
const long nIncDecWidth     = 11;
const long nIncDecHeight    = 11;
const long nSliderHeight    = 2;
const long nSliderWidth     = 4;
const long nSnappingHeight  = 4;
const long nSliderXOffset   = 20;
const long nSnappingEpsilon = 5; // snapping epsilon in pixels
const long nSnappingPointsMinDist = nSnappingEpsilon; // minimum distance of two adjacent snapping points
const tools::Long nButtonWidth     = 10;
const tools::Long nButtonHeight    = 10;
const tools::Long nIncDecWidth     = 11;
const tools::Long nIncDecHeight    = 11;
const tools::Long nSliderHeight    = 2;
const tools::Long nSliderWidth     = 4;
const tools::Long nSnappingHeight  = 4;
const tools::Long nSliderXOffset   = 20;
const tools::Long nSnappingEpsilon = 5; // snapping epsilon in pixels
const tools::Long nSnappingPointsMinDist = nSnappingEpsilon; // minimum distance of two adjacent snapping points

sal_uInt16 ScZoomSlider::Offset2Zoom( long nOffset ) const
sal_uInt16 ScZoomSlider::Offset2Zoom( tools::Long nOffset ) const
{
    Size aSliderWindowSize = GetOutputSizePixel();
    const long nControlWidth = aSliderWindowSize.Width();
    const tools::Long nControlWidth = aSliderWindowSize.Width();
    sal_uInt16 nRet = 0;

    if( nOffset < nSliderXOffset )
@@ -140,7 +140,7 @@ sal_uInt16 ScZoomSlider::Offset2Zoom( long nOffset ) const

    // check for snapping points:
    auto aSnappingPointIter = std::find_if(mpImpl->maSnappingPointOffsets.begin(), mpImpl->maSnappingPointOffsets.end(),
        [nOffset](const long nCurrent) { return std::abs(nCurrent - nOffset) < nSnappingEpsilon; });
        [nOffset](const tools::Long nCurrent) { return std::abs(nCurrent - nOffset) < nSnappingEpsilon; });
    if (aSnappingPointIter != mpImpl->maSnappingPointOffsets.end())
    {
        nOffset = *aSnappingPointIter;
@@ -153,19 +153,19 @@ sal_uInt16 ScZoomSlider::Offset2Zoom( long nOffset ) const
        if( nOffset < nControlWidth / 2 )
        {
            // first half of slider
            const long nFirstHalfRange      = gnSliderCenter - mpImpl->mnMinZoom;
            const long nHalfSliderWidth     = nControlWidth/2 - nSliderXOffset;
            const long nZoomPerSliderPixel  = (1000 * nFirstHalfRange) / nHalfSliderWidth;
            const long nOffsetToSliderLeft  = nOffset - nSliderXOffset;
            const tools::Long nFirstHalfRange      = gnSliderCenter - mpImpl->mnMinZoom;
            const tools::Long nHalfSliderWidth     = nControlWidth/2 - nSliderXOffset;
            const tools::Long nZoomPerSliderPixel  = (1000 * nFirstHalfRange) / nHalfSliderWidth;
            const tools::Long nOffsetToSliderLeft  = nOffset - nSliderXOffset;
            nRet = mpImpl->mnMinZoom + sal_uInt16( nOffsetToSliderLeft * nZoomPerSliderPixel / 1000 );
        }
        else
        {
            // second half of slider
            const long nSecondHalfRange         = mpImpl->mnMaxZoom - gnSliderCenter;
            const long nHalfSliderWidth         = nControlWidth/2 - nSliderXOffset;
            const long nZoomPerSliderPixel      = 1000 * nSecondHalfRange / nHalfSliderWidth;
            const long nOffsetToSliderCenter    = nOffset - nControlWidth/2;
            const tools::Long nSecondHalfRange         = mpImpl->mnMaxZoom - gnSliderCenter;
            const tools::Long nHalfSliderWidth         = nControlWidth/2 - nSliderXOffset;
            const tools::Long nZoomPerSliderPixel      = 1000 * nSecondHalfRange / nHalfSliderWidth;
            const tools::Long nOffsetToSliderCenter    = nOffset - nControlWidth/2;
            nRet = gnSliderCenter + sal_uInt16( nOffsetToSliderCenter * nZoomPerSliderPixel / 1000 );
        }
    }
@@ -179,27 +179,27 @@ sal_uInt16 ScZoomSlider::Offset2Zoom( long nOffset ) const
    return nRet;
}

long ScZoomSlider::Zoom2Offset( sal_uInt16 nCurrentZoom ) const
tools::Long ScZoomSlider::Zoom2Offset( sal_uInt16 nCurrentZoom ) const
{
    Size aSliderWindowSize = GetOutputSizePixel();
    const long nControlWidth = aSliderWindowSize.Width();
    long  nRect = nSliderXOffset;
    const tools::Long nControlWidth = aSliderWindowSize.Width();
    tools::Long  nRect = nSliderXOffset;

    const long nHalfSliderWidth = nControlWidth/2 - nSliderXOffset;
    const tools::Long nHalfSliderWidth = nControlWidth/2 - nSliderXOffset;
    if( nCurrentZoom <= gnSliderCenter )
    {
        nCurrentZoom = nCurrentZoom - mpImpl->mnMinZoom;
        const long nFirstHalfRange = gnSliderCenter - mpImpl->mnMinZoom;
        const long nSliderPixelPerZoomPercent = 1000 * nHalfSliderWidth  / nFirstHalfRange;
        const long nOffset = (nSliderPixelPerZoomPercent * nCurrentZoom) / 1000;
        const tools::Long nFirstHalfRange = gnSliderCenter - mpImpl->mnMinZoom;
        const tools::Long nSliderPixelPerZoomPercent = 1000 * nHalfSliderWidth  / nFirstHalfRange;
        const tools::Long nOffset = (nSliderPixelPerZoomPercent * nCurrentZoom) / 1000;
        nRect += nOffset;
    }
    else
    {
        nCurrentZoom = nCurrentZoom - gnSliderCenter;
        const long nSecondHalfRange = mpImpl->mnMaxZoom - gnSliderCenter;
        const long nSliderPixelPerZoomPercent = 1000 * nHalfSliderWidth  / nSecondHalfRange;
        const long nOffset = (nSliderPixelPerZoomPercent * nCurrentZoom) / 1000;
        const tools::Long nSecondHalfRange = mpImpl->mnMaxZoom - gnSliderCenter;
        const tools::Long nSliderPixelPerZoomPercent = 1000 * nHalfSliderWidth  / nSecondHalfRange;
        const tools::Long nOffset = (nSliderPixelPerZoomPercent * nCurrentZoom) / 1000;
        nRect += nHalfSliderWidth + nOffset;
    }
    return nRect;
@@ -248,10 +248,10 @@ bool ScZoomSlider::MouseButtonDown( const MouseEvent& rMEvt )

    const Point aPoint = rMEvt.GetPosPixel();

    const long nButtonLeftOffset    = ( nSliderXOffset - nIncDecWidth )/2;
    const long nButtonRightOffset   = ( nSliderXOffset + nIncDecWidth )/2;
    const tools::Long nButtonLeftOffset    = ( nSliderXOffset - nIncDecWidth )/2;
    const tools::Long nButtonRightOffset   = ( nSliderXOffset + nIncDecWidth )/2;

    const long nOldZoom = mpImpl->mnCurrentZoom;
    const tools::Long nOldZoom = mpImpl->mnCurrentZoom;

    // click to - button
    if ( aPoint.X() >= nButtonLeftOffset && aPoint.X() <= nButtonRightOffset )
@@ -300,7 +300,7 @@ bool ScZoomSlider::MouseButtonDown( const MouseEvent& rMEvt )
bool ScZoomSlider::MouseMove( const MouseEvent& rMEvt )
{
    Size aSliderWindowSize   = GetOutputSizePixel();
    const long nControlWidth = aSliderWindowSize.Width();
    const tools::Long nControlWidth = aSliderWindowSize.Width();
    const short nButtons     = rMEvt.GetButtons();

    // check mouse move with button pressed
@@ -364,11 +364,11 @@ void ScZoomSlider::UpdateFromItem(const SvxZoomSliderItem* pZoomSliderItem)
            [](const sal_Int32 nSnappingPoint) -> sal_uInt16 { return static_cast<sal_uInt16>(nSnappingPoint); });

        // remove snapping points that are too close to each other:
        long nLastOffset = 0;
        tools::Long nLastOffset = 0;

        for ( const sal_uInt16 nCurrent : aTmpSnappingPoints )
        {
            const long nCurrentOffset = Zoom2Offset( nCurrent );
            const tools::Long nCurrentOffset = Zoom2Offset( nCurrent );

            if ( nCurrentOffset - nLastOffset >= nSnappingPointsMinDist )
            {
diff --git a/sc/source/ui/dbgui/pvfundlg.cxx b/sc/source/ui/dbgui/pvfundlg.cxx
index 2456d40..5af5a68 100644
--- a/sc/source/ui/dbgui/pvfundlg.cxx
+++ b/sc/source/ui/dbgui/pvfundlg.cxx
@@ -131,7 +131,7 @@ const sal_uInt16 SC_BASEITEM_USER_POS = 2;
const sal_uInt16 SC_SORTNAME_POS = 0;
const sal_uInt16 SC_SORTDATA_POS = 1;

const long SC_SHOW_DEFAULT = 10;
const tools::Long SC_SHOW_DEFAULT = 10;

} // namespace

@@ -750,7 +750,7 @@ void ScDPSubtotalOptDlg::Init( const ScDPNameVec& rDataFields, bool bEnableLayou
    m_xCbShow->connect_clicked( LINK( this, ScDPSubtotalOptDlg, CheckHdl ) );

    m_xLbShowFrom->set_active(FromDataPilotFieldShowItemsMode(maLabelData.maShowInfo.ShowItemsMode));
    long nCount = static_cast< long >( maLabelData.maShowInfo.ItemCount );
    tools::Long nCount = static_cast< tools::Long >( maLabelData.maShowInfo.ItemCount );
    if( nCount < 1 )
        nCount = SC_SHOW_DEFAULT;
    m_xNfShow->set_value( nCount );
@@ -853,8 +853,8 @@ ScDPShowDetailDlg::ScDPShowDetailDlg(weld::Window* pParent, ScDPObject& rDPObj, 
    , mxLbDims(m_xBuilder->weld_tree_view("dimsTreeview"))
{
    ScDPSaveData* pSaveData = rDPObj.GetSaveData();
    long nDimCount = rDPObj.GetDimCount();
    for (long nDim=0; nDim<nDimCount; nDim++)
    tools::Long nDimCount = rDPObj.GetDimCount();
    for (tools::Long nDim=0; nDim<nDimCount; nDim++)
    {
        bool bIsDataLayout;
        sal_Int32 nDimFlags = 0;
@@ -900,7 +900,7 @@ OUString ScDPShowDetailDlg::GetDimensionName() const
        // This should never happen!
        return aSelectedName;

    long nDim = itr->second;
    tools::Long nDim = itr->second;
    bool bIsDataLayout = false;
    return mrDPObj.GetDimName(nDim, bIsDataLayout);
}
diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx
index 462d60e..769f92c 100644
--- a/sc/source/ui/dbgui/tpsort.cxx
+++ b/sc/source/ui/dbgui/tpsort.cxx
@@ -888,7 +888,7 @@ void ScTabPageSortOptions::FillAlgor()
        lang::Locale aLocale( LanguageTag::convertToLocale( eLang ));
        const uno::Sequence<OUString> aAlgos = m_xColWrap->listCollatorAlgorithms( aLocale );

        long nCount = aAlgos.getLength();
        tools::Long nCount = aAlgos.getLength();
        for (const OUString& sAlg : aAlgos)
        {
            OUString sUser = m_xColRes->GetTranslation( sAlg );
diff --git a/sc/source/ui/docshell/dbdocimp.cxx b/sc/source/ui/docshell/dbdocimp.cxx
index a49b925..7a5036d 100644
--- a/sc/source/ui/docshell/dbdocimp.cxx
+++ b/sc/source/ui/docshell/dbdocimp.cxx
@@ -233,7 +233,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam,

            //  get column descriptions

            long nColCount = 0;
            tools::Long nColCount = 0;
            uno::Reference<sdbc::XResultSetMetaData> xMeta;
            uno::Reference<sdbc::XResultSetMetaDataSupplier> xMetaSupp( xRowSet, uno::UNO_QUERY );
            if ( xMetaSupp.is() )
@@ -267,7 +267,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam,
                uno::Sequence<sal_Bool> aColCurr( nColCount );      // currency flag is not in types
                sal_Int32* pTypeArr = aColTypes.getArray();
                sal_Bool* pCurrArr = aColCurr.getArray();
                for (long i=0; i<nColCount; i++)
                for (tools::Long i=0; i<nColCount; i++)
                {
                    pTypeArr[i] = xMeta->getColumnType( i+1 );
                    pCurrArr[i] = xMeta->isCurrency( i+1 );
@@ -275,7 +275,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam,

                // read column names
                nCol = rParam.nCol1;
                for (long i=0; i<nColCount; i++)
                for (tools::Long i=0; i<nColCount; i++)
                {
                    pImportDoc->SetString( nCol, nRow, nTab,
                                            xMeta->getColumnLabel( i+1 ) );
@@ -328,7 +328,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam,
                        if ( rDoc.ValidRow(nRow) )
                        {
                            nCol = rParam.nCol1;
                            for (long i=0; i<nColCount; i++)
                            for (tools::Long i=0; i<nColCount; i++)
                            {
                                ScDatabaseDocUtil::PutData( *pImportDoc, nCol, nRow, nTab,
                                                xRow, i+1, pTypeArr[i], pCurrArr[i] );
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 358fb13..617937c 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -2704,8 +2704,8 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark, 
    {
        ScRange aRange = qDecreaseRange.back();

        long nDecreaseRowCount = 0;
        long nDecreaseColCount = 0;
        tools::Long nDecreaseRowCount = 0;
        tools::Long nDecreaseColCount = 0;
        if( eCmd == DelCellCmd::CellsUp || eCmd == DelCellCmd::Rows )
        {
            if( nStartRow >= aRange.aStart.Row() && nStartRow <= aRange.aEnd.Row() && nEndRow>= aRange.aStart.Row() && nEndRow <= aRange.aEnd.Row() )
diff --git a/sc/source/ui/docshell/docsh2.cxx b/sc/source/ui/docshell/docsh2.cxx
index 1c819a0..0c8da05 100644
--- a/sc/source/ui/docshell/docsh2.cxx
+++ b/sc/source/ui/docshell/docsh2.cxx
@@ -46,8 +46,8 @@ bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
    //  Additional tables are created by the first View, if bIsEmpty is still sal_True
    if( bRet )
    {
        Size aSize( long( STD_COL_WIDTH           * HMM_PER_TWIPS * OLE_STD_CELLS_X ),
                    static_cast<long>( ScGlobal::nStdRowHeight * HMM_PER_TWIPS * OLE_STD_CELLS_Y ) );
        Size aSize( tools::Long( STD_COL_WIDTH           * HMM_PER_TWIPS * OLE_STD_CELLS_X ),
                    static_cast<tools::Long>( ScGlobal::nStdRowHeight * HMM_PER_TWIPS * OLE_STD_CELLS_Y ) );
        // Also adjust start here
        SetVisAreaOrSize( tools::Rectangle( Point(), aSize ) );
    }
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index 271d630..42f952f 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -367,8 +367,8 @@ void ScDocShell::CalcOutputFactor()

    OUString aTestString(
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789");
    long nPrinterWidth = 0;
    long nWindowWidth = 0;
    tools::Long nPrinterWidth = 0;
    tools::Long nWindowWidth = 0;
    const ScPatternAttr* pPattern = &m_aDocument.GetPool()->GetDefaultItem(ATTR_PATTERN);

    vcl::Font aDefFont;
@@ -388,7 +388,7 @@ void ScDocShell::CalcOutputFactor()
    pPattern->GetFont(aDefFont, SC_AUTOCOL_BLACK, pVirtWindow);    // font color doesn't matter here
    pVirtWindow->SetFont(aDefFont);
    nWindowWidth = pVirtWindow->GetTextWidth(aTestString);
    nWindowWidth = static_cast<long>( nWindowWidth / ScGlobal::nScreenPPTX * HMM_PER_TWIPS );
    nWindowWidth = static_cast<tools::Long>( nWindowWidth / ScGlobal::nScreenPPTX * HMM_PER_TWIPS );

    if (nPrinterWidth && nWindowWidth)
        m_nPrtToScreenFactor = nPrinterWidth / static_cast<double>(nWindowWidth);
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index d8ed50e..c2d1c504 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -1651,9 +1651,9 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )

        sal_uInt16 nNewScale = nOldScale;

        long nBlkTwipsX = 0;
        tools::Long nBlkTwipsX = 0;
        if (bHeaders)
            nBlkTwipsX += long(PRINT_HEADER_WIDTH);
            nBlkTwipsX += tools::Long(PRINT_HEADER_WIDTH);
        SCCOL nStartCol = rRange.aStart.Col();
        SCCOL nEndCol = rRange.aEnd.Col();
        if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
@@ -1669,9 +1669,9 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
                nBlkTwipsX += m_aDocument.GetColWidth( i, nTab );
        }

        long nBlkTwipsY = 0;
        tools::Long nBlkTwipsY = 0;
        if (bHeaders)
            nBlkTwipsY += long(PRINT_HEADER_HEIGHT);
            nBlkTwipsY += tools::Long(PRINT_HEADER_HEIGHT);
        SCROW nStartRow = rRange.aStart.Row();
        SCROW nEndRow = rRange.aEnd.Row();
        if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
@@ -1684,7 +1684,7 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
        nBlkTwipsY += m_aDocument.GetRowHeight( nStartRow, nEndRow, nTab );

        Size aPhysPage;
        long nHdr, nFtr;
        tools::Long nHdr, nFtr;
        ScPrintFunc aOldPrFunc( this, GetPrinter(), nTab );
        aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr );
        nBlkTwipsY += nHdr + nFtr;
@@ -1694,11 +1694,11 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
        if ( nBlkTwipsY == 0 )
            nBlkTwipsY = 1;

        long nNeeded = std::min( aPhysPage.Width()  * 100 / nBlkTwipsX,
        tools::Long nNeeded = std::min( aPhysPage.Width()  * 100 / nBlkTwipsX,
                            aPhysPage.Height() * 100 / nBlkTwipsY );
        if ( nNeeded < ZOOM_MIN )
            nNeeded = ZOOM_MIN;         // boundary
        if ( nNeeded < static_cast<long>(nNewScale) )
        if ( nNeeded < static_cast<tools::Long>(nNewScale) )
            nNewScale = static_cast<sal_uInt16>(nNeeded);

        bChange = ( nNewScale != nOldScale || nOldPages != 0 );
@@ -2171,8 +2171,8 @@ tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
            const_cast<ScDocShell*>(this)->m_aDocument.SetVisibleTab(nVisTab);
        }
        Size aSize = m_aDocument.GetPageSize(nVisTab);
        const long SC_PREVIEW_SIZE_X = 10000;
        const long SC_PREVIEW_SIZE_Y = 12400;
        const tools::Long SC_PREVIEW_SIZE_X = 10000;
        const tools::Long SC_PREVIEW_SIZE_Y = 12400;
        tools::Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X, SC_PREVIEW_SIZE_Y);
        if (aSize.Width() > aSize.Height())
        {
@@ -2217,14 +2217,14 @@ tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
namespace {

[[nodiscard]]
long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, long nVal, SCCOL& rStartCol )
tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCCOL& rStartCol )
{
    SCCOL nCol = 0;
    long nTwips = static_cast<long>(nVal / HMM_PER_TWIPS);
    long nSnap = 0;
    tools::Long nTwips = static_cast<tools::Long>(nVal / HMM_PER_TWIPS);
    tools::Long nSnap = 0;
    while ( nCol<rDoc.MaxCol() )
    {
        long nAdd = rDoc.GetColWidth(nCol, nTab);
        tools::Long nAdd = rDoc.GetColWidth(nCol, nTab);
        if ( nSnap + nAdd/2 < nTwips || nCol < rStartCol )
        {
            nSnap += nAdd;
@@ -2233,17 +2233,17 @@ long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, long nVal, SCCOL& rStar
        else
            break;
    }
    nVal = static_cast<long>( nSnap * HMM_PER_TWIPS );
    nVal = static_cast<tools::Long>( nSnap * HMM_PER_TWIPS );
    rStartCol = nCol;
    return nVal;
}

[[nodiscard]]
long SnapVertical( const ScDocument& rDoc, SCTAB nTab, long nVal, SCROW& rStartRow )
tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCROW& rStartRow )
{
    SCROW nRow = 0;
    long nTwips = static_cast<long>(nVal / HMM_PER_TWIPS);
    long nSnap = 0;
    tools::Long nTwips = static_cast<tools::Long>(nVal / HMM_PER_TWIPS);
    tools::Long nSnap = 0;

    bool bFound = false;
    for (SCROW i = nRow; i <= rDoc.MaxRow(); ++i)
@@ -2256,7 +2256,7 @@ long SnapVertical( const ScDocument& rDoc, SCTAB nTab, long nVal, SCROW& rStartR
        }

        nRow = i;
        long nAdd = rDoc.GetRowHeight(i, nTab);
        tools::Long nAdd = rDoc.GetRowHeight(i, nTab);
        if ( nSnap + nAdd/2 < nTwips || nRow < rStartRow )
        {
            nSnap += nAdd;
@@ -2271,7 +2271,7 @@ long SnapVertical( const ScDocument& rDoc, SCTAB nTab, long nVal, SCROW& rStartR
    if (!bFound)
        nRow = rDoc.MaxRow();  // all hidden down to the bottom

    nVal = static_cast<long>( nSnap * HMM_PER_TWIPS );
    nVal = static_cast<tools::Long>( nSnap * HMM_PER_TWIPS );
    rStartRow = nRow;
    return nVal;
}
@@ -2281,24 +2281,24 @@ long SnapVertical( const ScDocument& rDoc, SCTAB nTab, long nVal, SCROW& rStartR
void ScDocShell::SnapVisArea( tools::Rectangle& rRect ) const
{
    SCTAB nTab = m_aDocument.GetVisibleTab();
    long nOrigTop = rRect.Top();
    long nOrigLeft = rRect.Left();
    tools::Long nOrigTop = rRect.Top();
    tools::Long nOrigLeft = rRect.Left();
    bool bNegativePage = m_aDocument.IsNegativePage( nTab );
    if ( bNegativePage )
        ScDrawLayer::MirrorRectRTL( rRect );        // calculate with positive (LTR) values

    SCCOL nCol = m_aDocument.GetPosLeft();
    long nSetLeft = SnapHorizontal( m_aDocument, nTab, rRect.Left(), nCol );
    tools::Long nSetLeft = SnapHorizontal( m_aDocument, nTab, rRect.Left(), nCol );
    rRect.SetLeft( nSetLeft );
    ++nCol;                                         // at least one column
    long nCorrectionLeft = (nOrigLeft == 0 && nCol > 0) ? nSetLeft : 0; // initial correction
    tools::Long nCorrectionLeft = (nOrigLeft == 0 && nCol > 0) ? nSetLeft : 0; // initial correction
    rRect.SetRight( SnapHorizontal( m_aDocument, nTab, rRect.Right() + nCorrectionLeft, nCol ));

    SCROW nRow = m_aDocument.GetPosTop();
    long nSetTop = SnapVertical( m_aDocument, nTab, rRect.Top(), nRow );
    tools::Long nSetTop = SnapVertical( m_aDocument, nTab, rRect.Top(), nRow );
    rRect.SetTop( nSetTop );
    ++nRow;                                         // at least one row
    long nCorrectionTop = (nOrigTop == 0 && nRow > 0) ? nSetTop : 0; // initial correction
    tools::Long nCorrectionTop = (nOrigTop == 0 && nRow > 0) ? nSetTop : 0; // initial correction
    rRect.SetBottom( SnapVertical( m_aDocument, nTab, rRect.Bottom() + nCorrectionTop, nRow ));

    if ( bNegativePage )
@@ -2501,7 +2501,7 @@ void ScDocShell::LOKCommentNotify(LOKCommentNotificationType nType, const ScDocu
            if (bInPrintTwips)
            {
                Point aTopLeft = pViewData->GetPrintTwipsPos(rPos.Col(), rPos.Row());
                long nSizeX, nSizeY;
                tools::Long nSizeX, nSizeY;
                pViewData->GetMergeSizePrintTwips(rPos.Col(), rPos.Row(), nSizeX, nSizeY);
                aRectString = tools::Rectangle(aTopLeft, Size(nSizeX - 1, nSizeY - 1)).toString();
            }
@@ -2509,7 +2509,7 @@ void ScDocShell::LOKCommentNotify(LOKCommentNotificationType nType, const ScDocu
            {
                Point aTopLeft = pViewData->GetScrPos(rPos.Col(), rPos.Row(),
                        pViewData->GetActivePart(), true);
                long nSizeXPix, nSizeYPix;
                tools::Long nSizeXPix, nSizeYPix;
                pViewData->GetMergeSizePixel(rPos.Col(), rPos.Row(), nSizeXPix, nSizeYPix);
                const double fPPTX = pViewData->GetPPTX();
                const double fPPTY = pViewData->GetPPTY();
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index cbdc901..85e6202 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -295,7 +295,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
                pUndoColl.reset( new ScDBCollection( *pColl ) );   // Undo for import range

                OUString aImport = ScResId( STR_DBNAME_IMPORT );
                long nCount = 0;
                tools::Long nCount = 0;
                const ScDBData* pDummy = nullptr;
                ScDBCollection::NamedDBs& rDBs = pColl->getNamedDBs();
                OUString aNewName;
diff --git a/sc/source/ui/docshell/docsh6.cxx b/sc/source/ui/docshell/docsh6.cxx
index f3b1a90..ac31371 100644
--- a/sc/source/ui/docshell/docsh6.cxx
+++ b/sc/source/ui/docshell/docsh6.cxx
@@ -85,15 +85,15 @@ void ScDocShell::SetVisAreaOrSize( const tools::Rectangle& rVisArea )
            //  Move the VisArea, otherwise only the upper left position would
            //  be changed in SnapVisArea, and the size would be wrong.

            Point aNewPos( 0, std::max( aArea.Top(), long(0) ) );
            Point aNewPos( 0, std::max( aArea.Top(), tools::Long(0) ) );
            if ( bNegativePage )
            {
                aNewPos.setX( std::min( aArea.Right(), long(0) ) );
                aNewPos.setX( std::min( aArea.Right(), tools::Long(0) ) );
                lcl_SetTopRight( aArea, aNewPos );
            }
            else
            {
                aNewPos.setX( std::max( aArea.Left(), long(0) ) );
                aNewPos.setX( std::max( aArea.Left(), tools::Long(0) ) );
                aArea.SetPos( aNewPos );
            }
        }
diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx
index 9b5ba3f..9afb24e 100644
--- a/sc/source/ui/docshell/docsh8.cxx
+++ b/sc/source/ui/docshell/docsh8.cxx
@@ -286,8 +286,8 @@ ErrCode ScDocShell::DBaseImport( const OUString& rFullFileName, rtl_TextEncoding

    try
    {
        long i;
        long nColCount = 0;
        tools::Long i;
        tools::Long nColCount = 0;
        OUString aTabName;
        uno::Reference<sdbc::XDriverManager2> xDrvMan;
        uno::Reference<sdbc::XConnection> xConnection;
@@ -364,8 +364,8 @@ ErrCode ScDocShell::DBaseImport( const OUString& rFullFileName, rtl_TextEncoding
                    break;
                case sdbc::DataType::DECIMAL:
                    {
                        long nPrec = xMeta->getPrecision( i+1 );
                        long nScale = xMeta->getScale( i+1 );
                        tools::Long nPrec = xMeta->getPrecision( i+1 );
                        tools::Long nScale = xMeta->getScale( i+1 );
                        aHeader += ",N," +
                                    OUString::number(
                                        SvDbaseConverter::ConvertPrecisionToDbase(
@@ -457,7 +457,7 @@ void lcl_GetColumnTypes(
    typedef std::unordered_set<OUString> StrSetType;
    StrSetType aFieldNames;

    long nField = 0;
    tools::Long nField = 0;
    SCROW nFirstDataRow = ( bHasFieldNames ? nFirstRow + 1 : nFirstRow );
    for ( SCCOL nCol = nFirstCol; nCol <= nLastCol; nCol++ )
    {
@@ -762,7 +762,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
            bHasFieldNames = false;
    }

    long nColCount = nLastCol - nFirstCol + 1;
    tools::Long nColCount = nLastCol - nFirstCol + 1;
    uno::Sequence<OUString> aColNames( nColCount );
    uno::Sequence<sal_Int32> aColTypes( nColCount );
    uno::Sequence<sal_Int32> aColLengths( nColCount );
@@ -838,7 +838,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding
        const sal_Int32* pColTypes     = aColTypes.getConstArray();
        const sal_Int32* pColLengths   = aColLengths.getConstArray();
        const sal_Int32* pColScales    = aColScales.getConstArray();
        long nCol;
        tools::Long nCol;

        for (nCol=0; nCol<nColCount; nCol++)
        {
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index e13fdb7..e737373 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1322,7 +1322,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
    sal_uInt16  nInfoCount      = pExtOptions->GetInfoCount();
    const sal_Int32* pColStart  = pExtOptions->GetColStart();
    const sal_uInt8* pColFormat = pExtOptions->GetColFormat();
    long nSkipLines             = pExtOptions->GetStartRow();
    tools::Long nSkipLines             = pExtOptions->GetStartRow();

    LanguageType eDocLang = pExtOptions->GetLanguage();
    SvNumberFormatter aNumFormatter( comphelper::getProcessComponentContext(), eDocLang);
diff --git a/sc/source/ui/docshell/pagedata.cxx b/sc/source/ui/docshell/pagedata.cxx
index a756048..4ab70ed 100644
--- a/sc/source/ui/docshell/pagedata.cxx
+++ b/sc/source/ui/docshell/pagedata.cxx
@@ -88,10 +88,10 @@ void ScPageBreakData::AddPages()
{
    if ( nUsed > 1 )
    {
        long nPage = pData[0].GetFirstPage();
        tools::Long nPage = pData[0].GetFirstPage();
        for (size_t i=0; i+1<nUsed; i++)
        {
            nPage += static_cast<long>(pData[i].GetPagesX())*pData[i].GetPagesY();
            nPage += static_cast<tools::Long>(pData[i].GetPagesX())*pData[i].GetPagesY();
            pData[i+1].SetFirstPage( nPage );
        }
    }
diff --git a/sc/source/ui/drawfunc/fuconrec.cxx b/sc/source/ui/drawfunc/fuconrec.cxx
index cc0aaa0..edb82a6 100644
--- a/sc/source/ui/drawfunc/fuconrec.cxx
+++ b/sc/source/ui/drawfunc/fuconrec.cxx
@@ -63,8 +63,8 @@ namespace {
    if( pLineEndList.is() )
    {
        OUString aArrowName( SvxResId(pResId) );
        long nCount = pLineEndList->Count();
        long nIndex;
        tools::Long nCount = pLineEndList->Count();
        tools::Long nIndex;
        for( nIndex = 0; nIndex < nCount; nIndex++ )
        {
            const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
@@ -255,12 +255,12 @@ void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal
    }

    SfxItemSet aSet( rModel.GetItemPool() );
    long nWidth = 200; // (1/100th mm)
    tools::Long nWidth = 200; // (1/100th mm)

    // determine line width and calculate with it the line end width
    if( aSet.GetItemState( XATTR_LINEWIDTH ) != SfxItemState::DONTCARE )
    {
        long nValue = aSet.Get( XATTR_LINEWIDTH ).GetValue();
        tools::Long nValue = aSet.Get( XATTR_LINEWIDTH ).GetValue();
        if( nValue > 0 )
            nWidth = nValue * 3;
    }
diff --git a/sc/source/ui/drawfunc/fudraw.cxx b/sc/source/ui/drawfunc/fudraw.cxx
index 7017901..d71e2eb 100644
--- a/sc/source/ui/drawfunc/fudraw.cxx
+++ b/sc/source/ui/drawfunc/fudraw.cxx
@@ -405,8 +405,8 @@ bool FuDraw::KeyInput(const KeyEvent& rKEvt)
                        break;
                }

                long nX = 0;
                long nY = 0;
                tools::Long nX = 0;
                tools::Long nY = 0;
                sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();

                if (nCode == KEY_UP)
diff --git a/sc/source/ui/drawfunc/fuins1.cxx b/sc/source/ui/drawfunc/fuins1.cxx
index bd2bbeb..617532f 100644
--- a/sc/source/ui/drawfunc/fuins1.cxx
+++ b/sc/source/ui/drawfunc/fuins1.cxx
@@ -76,12 +76,12 @@ void ScLimitSizeOnDrawPage( Size& rSize, Point& rPos, const Size& rPage )
        if ( fX < fY )
        {
            rSize.setWidth( aPageSize.Width() );
            rSize.setHeight( static_cast<long>( rSize.Height() * fX ) );
            rSize.setHeight( static_cast<tools::Long>( rSize.Height() * fX ) );
        }
        else
        {
            rSize.setHeight( aPageSize.Height() );
            rSize.setWidth( static_cast<long>( rSize.Width() * fY ) );
            rSize.setWidth( static_cast<tools::Long>( rSize.Width() * fY ) );
        }

        if (!rSize.Width())
diff --git a/sc/source/ui/drawfunc/fusel2.cxx b/sc/source/ui/drawfunc/fusel2.cxx
index 12024f2..cd84fbc 100644
--- a/sc/source/ui/drawfunc/fusel2.cxx
+++ b/sc/source/ui/drawfunc/fusel2.cxx
@@ -32,11 +32,11 @@
#include <drawview.hxx>
#include <svx/sdrhittesthelper.hxx>

static long Diff( const Point& rP1, const Point& rP2 )
static tools::Long Diff( const Point& rP1, const Point& rP2 )
{
    long nX = rP1.X() - rP2.X();
    tools::Long nX = rP1.X() - rP2.X();
    if (nX<0) nX = -nX;
    long nY = rP1.Y() - rP2.Y();
    tools::Long nY = rP1.Y() - rP2.Y();
    if (nY<0) nY = -nY;
    return nX+nY;
}
diff --git a/sc/source/ui/inc/asciiopt.hxx b/sc/source/ui/inc/asciiopt.hxx
index 3c73ee2..ad8b919 100644
--- a/sc/source/ui/inc/asciiopt.hxx
+++ b/sc/source/ui/inc/asciiopt.hxx
@@ -41,7 +41,7 @@ private:
    rtl_TextEncoding eCharSet;
    LanguageType eLang;
    bool        bCharSetSystem;
    long        nStartRow;
    tools::Long        nStartRow;
    std::vector<sal_Int32> mvColStart;
    std::vector<sal_uInt8> mvColFormat;

@@ -65,7 +65,7 @@ public:
    sal_uInt16          GetInfoCount() const    { return mvColStart.size(); }
    const sal_Int32*    GetColStart() const     { return mvColStart.data(); }
    const sal_uInt8*    GetColFormat() const    { return mvColFormat.data(); }
    long                GetStartRow() const     { return nStartRow; }
    tools::Long                GetStartRow() const     { return nStartRow; }
    LanguageType        GetLanguage() const     { return eLang; }

    void    SetCharSet( rtl_TextEncoding eNew ) { eCharSet = eNew; }
@@ -78,7 +78,7 @@ public:
    void    SetDetectSpecialNumber(bool bSet)   { bDetectSpecialNumber = bSet; }
    void    SetSkipEmptyCells(bool bSet)        { bSkipEmptyCells = bSet; }
    void    SetTextSep( sal_Unicode c )         { cTextSep = c; }
    void    SetStartRow( long nRow)             { nStartRow= nRow; }
    void    SetStartRow( tools::Long nRow)             { nStartRow= nRow; }
    void    SetLanguage(LanguageType e)         { eLang = e; }

    void    SetColumnInfo( const ScCsvExpDataVec& rDataVec );
diff --git a/sc/source/ui/inc/autofmt.hxx b/sc/source/ui/inc/autofmt.hxx
index 682aa01..37de70a 100644
--- a/sc/source/ui/inc/autofmt.hxx
+++ b/sc/source/ui/inc/autofmt.hxx
@@ -55,10 +55,10 @@ private:
    svx::frame::Array       maArray;            /// Implementation to draw the frame borders.
    bool                    mbRTL;
    Size                    aPrvSize;
    long                    mnLabelColWidth;
    long                    mnDataColWidth1;
    long                    mnDataColWidth2;
    long                    mnRowHeight;
    tools::Long                    mnLabelColWidth;
    tools::Long                    mnDataColWidth1;
    tools::Long                    mnDataColWidth2;
    tools::Long                    mnRowHeight;
    const OUString          aStrJan;
    const OUString          aStrFeb;
    const OUString          aStrMar;
diff --git a/sc/source/ui/inc/colrowba.hxx b/sc/source/ui/inc/colrowba.hxx
index bfbb5cb..dae356f 100644
--- a/sc/source/ui/inc/colrowba.hxx
+++ b/sc/source/ui/inc/colrowba.hxx
@@ -52,9 +52,9 @@ public:
    virtual bool        IsDisabled() const override;
    virtual bool        ResizeAllowed() const override;

    virtual void        DrawInvert( long nDragPos ) override;
    virtual void        DrawInvert( tools::Long nDragPos ) override;

    virtual OUString    GetDragHelp( long nVal ) override;
    virtual OUString    GetDragHelp( tools::Long nVal ) override;
};

class ScRowBar : public ScHeaderControl
@@ -83,9 +83,9 @@ public:
    virtual bool        IsDisabled() const override;
    virtual bool        ResizeAllowed() const override;

    virtual void        DrawInvert( long nDragPos ) override;
    virtual void        DrawInvert( tools::Long nDragPos ) override;

    virtual OUString    GetDragHelp( long nVal ) override;
    virtual OUString    GetDragHelp( tools::Long nVal ) override;
};

#endif
diff --git a/sc/source/ui/inc/dbfunc.hxx b/sc/source/ui/inc/dbfunc.hxx
index 3ebff62..f7cd3d1 100644
--- a/sc/source/ui/inc/dbfunc.hxx
+++ b/sc/source/ui/inc/dbfunc.hxx
@@ -35,7 +35,7 @@ struct ScSubTotalParam;
class SAL_DLLPUBLIC_RTTI ScDBFunc : public ScViewFunc
{
private:
    void GetSelectedMemberList(ScDPUniqueStringSet& rEntries, long& rDimension);
    void GetSelectedMemberList(ScDPUniqueStringSet& rEntries, tools::Long& rDimension);

public:
                    ScDBFunc( vcl::Window* pParent, ScDocShell& rDocSh, ScTabViewShell* pViewShell );
@@ -81,7 +81,7 @@ public:
    void            UngroupDataPilot();
    void DataPilotInput( const ScAddress& rPos, const OUString& rString );

    void            DataPilotSort(ScDPObject* pDPObject, long nDimIndex, bool bAscending, const sal_uInt16* pUserListId = nullptr);
    void            DataPilotSort(ScDPObject* pDPObject, tools::Long nDimIndex, bool bAscending, const sal_uInt16* pUserListId = nullptr);
    bool            DataPilotMove( const ScRange& rSource, const ScAddress& rDest );

    bool HasSelectionForDrillDown( css::sheet::DataPilotFieldOrientation& rOrientation );
diff --git a/sc/source/ui/inc/gridmerg.hxx b/sc/source/ui/inc/gridmerg.hxx
index a6c484a..82fec23 100644
--- a/sc/source/ui/inc/gridmerg.hxx
+++ b/sc/source/ui/inc/gridmerg.hxx
@@ -26,24 +26,24 @@ class ScGridMerger
{
private:
    VclPtr<OutputDevice> pDev;
    long            nOneX;
    long            nOneY;
    long            nFixStart;
    long            nFixEnd;
    long            nVarStart;
    long            nVarDiff;
    long            nCount;
    tools::Long            nOneX;
    tools::Long            nOneY;
    tools::Long            nFixStart;
    tools::Long            nFixEnd;
    tools::Long            nVarStart;
    tools::Long            nVarDiff;
    tools::Long            nCount;
    bool            bVertical;
    bool            bOptimize;

    void        AddLine( long nStart, long nEnd, long nPos );
    void        AddLine( tools::Long nStart, tools::Long nEnd, tools::Long nPos );

public:
                ScGridMerger( OutputDevice* pOutDev, long nOnePixelX, long nOnePixelY );
                ScGridMerger( OutputDevice* pOutDev, tools::Long nOnePixelX, tools::Long nOnePixelY );
                ~ScGridMerger();

    void        AddHorLine(bool bWorksInPixels, long nX1, long nX2, long nY, bool bDashed = false);
    void        AddVerLine(bool bWorksInPixels, long nX, long nY1, long nY2, bool bDashed = false);
    void        AddHorLine(bool bWorksInPixels, tools::Long nX1, tools::Long nX2, tools::Long nY, bool bDashed = false);
    void        AddVerLine(bool bWorksInPixels, tools::Long nX, tools::Long nY1, tools::Long nY2, bool bDashed = false);
    void        Flush();
};

diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 8a5a0a7..74b3356 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -169,7 +169,7 @@ class SAL_DLLPUBLIC_RTTI ScGridWindow : public vcl::Window, public DropTargetHel
    enum class ScNestedButtonState { NONE, Down, Up };
    ScNestedButtonState     nNestedButtonState;     // track nested button up/down calls

    long                    nDPField;
    tools::Long                    nDPField;
    ScDPObject*             pDragDPObj; //! name?

    sal_uInt16              nRFIndex;
@@ -349,7 +349,7 @@ public:
    void            PaintTile( VirtualDevice& rDevice,
                               int nOutputWidth, int nOutputHeight,
                               int nTilePosX, int nTilePosY,
                               long nTileWidth, long nTileHeight );
                               tools::Long nTileWidth, tools::Long nTileHeight );

    /// @see Window::LogicInvalidate().
    void LogicInvalidate(const tools::Rectangle* pRectangle) override;
@@ -374,7 +374,7 @@ public:

    void            MoveMouseStatus( ScGridWindow &rDestWin );

    void            ScrollPixel( long nDifX, long nDifY );
    void            ScrollPixel( tools::Long nDifX, tools::Long nDifY );
    void            UpdateEditViewPos();

    void            UpdateFormulas(SCCOL nX1 = -1, SCROW nY1 = -1, SCCOL nX2 = -1, SCROW nY2 = -1);
@@ -394,7 +394,7 @@ public:
    css::sheet::DataPilotFieldOrientation GetDPFieldOrientation( SCCOL nCol, SCROW nRow ) const;

    void DPLaunchFieldPopupMenu(const Point& rScrPos, const Size& rScrSize,
                                long nDimIndex, ScDPObject* pDPObj);
                                tools::Long nDimIndex, ScDPObject* pDPObj);

    void DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& rTabInfo, OutputDevice* pContentDev);

diff --git a/sc/source/ui/inc/hdrcont.hxx b/sc/source/ui/inc/hdrcont.hxx
index 08be7eb..3bb0e42 100644
--- a/sc/source/ui/inc/hdrcont.hxx
+++ b/sc/source/ui/inc/hdrcont.hxx
@@ -42,9 +42,9 @@ private:

    bool            bVertical;              // Vertical = Row header

    long            nWidth;
    long            nSmallWidth;
    long            nBigWidth;
    tools::Long            nWidth;
    tools::Long            nSmallWidth;
    tools::Long            nBigWidth;

    SCCOLROW        nSize;

@@ -54,8 +54,8 @@ private:

    bool            bDragging;              // Resizing
    SCCOLROW        nDragNo;
    long            nDragStart;
    long            nDragPos;
    tools::Long            nDragStart;
    tools::Long            nDragPos;
    void*           nTipVisible;
    bool            bDragMoved;

@@ -63,7 +63,7 @@ private:

    bool            bInRefMode;

    long            GetScrPos( SCCOLROW nEntryNo ) const;
    tools::Long            GetScrPos( SCCOLROW nEntryNo ) const;
    SCCOLROW        GetMousePos( const MouseEvent& rMEvt, bool& rBorder ) const;
    bool            IsSelectionAllowed(SCCOLROW nPos) const;
    void            ShowDragHelp();
@@ -101,9 +101,9 @@ protected:
    virtual void    SelectWindow();
    virtual bool    IsDisabled() const;
    virtual bool    ResizeAllowed() const;
    virtual OUString  GetDragHelp( long nVal );
    virtual OUString  GetDragHelp( tools::Long nVal );

    virtual void    DrawInvert( long nDragPos );
    virtual void    DrawInvert( tools::Long nDragPos );
    virtual void    Command( const CommandEvent& rCEvt ) override;

public:
@@ -117,10 +117,10 @@ public:

    void    SetMark( bool bNewSet, SCCOLROW nNewStart, SCCOLROW nNewEnd );

    long    GetWidth() const                    { return nWidth; }
    long    GetSmallWidth() const               { return nSmallWidth; }
    long    GetBigWidth() const                 { return nBigWidth; }
    void    SetWidth( long nNew );
    tools::Long    GetWidth() const                    { return nWidth; }
    tools::Long    GetSmallWidth() const               { return nSmallWidth; }
    tools::Long    GetBigWidth() const                 { return nBigWidth; }
    void    SetWidth( tools::Long nNew );
    void    GetMarkRange(SCCOLROW& rStart, SCCOLROW& rEnd) const;
};

diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx
index b18e111..c99589f 100644
--- a/sc/source/ui/inc/inputhdl.hxx
+++ b/sc/source/ui/inc/inputhdl.hxx
@@ -285,8 +285,8 @@ public:
    static void     SetAutoComplete(bool bSet)  { bAutoComplete = bSet; }

    static ReferenceMark GetReferenceMark( const ScViewData& rViewData, ScDocShell* pDocSh,
                                    long nX1, long nX2, long nY1, long nY2,
                                    long nTab, const Color& rColor );
                                    tools::Long nX1, tools::Long nX2, tools::Long nY1, tools::Long nY2,
                                    tools::Long nTab, const Color& rColor );

    void            LOKPasteFunctionData(const OUString& rFunctionName);
};
diff --git a/sc/source/ui/inc/inputwin.hxx b/sc/source/ui/inc/inputwin.hxx
index ccc07b4..1646810 100644
--- a/sc/source/ui/inc/inputwin.hxx
+++ b/sc/source/ui/inc/inputwin.hxx
@@ -64,7 +64,7 @@ public:
    virtual void            SetFormulaMode( bool bSet ) = 0;
    virtual bool            IsInputActive() = 0;
    virtual void            TextGrabFocus() = 0;
    virtual long            GetNumLines() const = 0;
    virtual tools::Long            GetNumLines() const = 0;
    virtual ~ScTextWndBase() {}
};

@@ -105,12 +105,12 @@ public:

    virtual void            Resize() override;

    int GetPixelHeightForLines(long nLines);
    int GetPixelHeightForLines(tools::Long nLines);
    int GetEditEngTxtHeight() const;

    virtual long GetNumLines() const override { return mnLines; }
    void SetNumLines(long nLines);
    long GetLastNumExpandedLines() const { return mnLastExpandedLines; }
    virtual tools::Long GetNumLines() const override { return mnLines; }
    void SetNumLines(tools::Long nLines);
    tools::Long GetLastNumExpandedLines() const { return mnLastExpandedLines; }

    void DoScroll();

@@ -158,8 +158,8 @@ private:

    ScTabViewShell* mpViewShell;
    ScTextWndGroup& mrGroupBar;
    long mnLines;
    long mnLastExpandedLines;
    tools::Long mnLines;
    tools::Long mnLastExpandedLines;
    bool mbInvalidate;
};

@@ -209,9 +209,9 @@ public:

    virtual void            InsertAccessibleTextData(ScAccessibleEditLineTextData& rTextData) override;
    virtual EditView*       GetEditView() override;
    long                    GetLastNumExpandedLines() const;
    virtual long            GetNumLines() const override;
    int                     GetPixelHeightForLines(long nLines);
    tools::Long                    GetLastNumExpandedLines() const;
    virtual tools::Long            GetNumLines() const override;
    int                     GetPixelHeightForLines(tools::Long nLines);
    weld::ScrolledWindow&   GetScrollWin();
    virtual const OUString& GetTextString() const override;
    virtual bool            HasEditView() const override;
@@ -219,7 +219,7 @@ public:
    virtual void            MakeDialogEditView() override;
    virtual void            RemoveAccessibleTextData(ScAccessibleEditLineTextData& rTextData) override;
    void                    SetScrollPolicy();
    void                    SetNumLines(long nLines);
    void                    SetNumLines(tools::Long nLines);
    virtual void            SetFormulaMode(bool bSet) override;
    virtual void            SetTextString(const OUString& rString) override;
    virtual void            StartEditEngine() override;
@@ -261,8 +261,8 @@ public:
    bool                    IsInputActive() override;
    void                    IncrementVerticalSize();
    void                    DecrementVerticalSize();
    virtual long            GetNumLines() const override { return mxTextWndGroup->GetNumLines(); }
    long                    GetVertOffset() const { return  mnVertOffset; }
    virtual tools::Long            GetNumLines() const override { return mxTextWndGroup->GetNumLines(); }
    tools::Long                    GetVertOffset() const { return  mnVertOffset; }

    int GetPixelHeightForLines() const
    {
@@ -278,7 +278,7 @@ private:
    std::unique_ptr<ScTextWndGroup> mxTextWndGroup;
    std::unique_ptr<weld::Button> mxButtonUp;
    std::unique_ptr<weld::Button> mxButtonDown;
    long                   mnVertOffset;
    tools::Long                   mnVertOffset;

    DECL_LINK(ClickHdl, weld::Button&, void);
};
@@ -344,7 +344,7 @@ private:
    VclPtr<ScInputBarGroup> mxTextWindow;
    ScInputHandler* pInputHdl;
    ScTabViewShell* mpViewShell;
    long            mnMaxY;
    tools::Long            mnMaxY;
    bool            bIsOkCancelMode;
    bool            bInResize;
};
diff --git a/sc/source/ui/inc/mtrindlg.hxx b/sc/source/ui/inc/mtrindlg.hxx
index 59b41f2..55596d8 100644
--- a/sc/source/ui/inc/mtrindlg.hxx
+++ b/sc/source/ui/inc/mtrindlg.hxx
@@ -27,12 +27,12 @@ class ScMetricInputDlg : public weld::GenericDialogController
public:
    ScMetricInputDlg( weld::Window*   pParent,
                      const OString& sDialogName,
                      long           nCurrent,
                      long           nDefault,
                      tools::Long           nCurrent,
                      tools::Long           nDefault,
                      FieldUnit      eFUnit,
                      sal_uInt16     nDecimals,
                      long           nMaximum,
                      long           nMinimum);
                      tools::Long           nMaximum,
                      tools::Long           nMinimum);
    virtual ~ScMetricInputDlg() override;

    int GetInputValue() const;
diff --git a/sc/source/ui/inc/olinewin.hxx b/sc/source/ui/inc/olinewin.hxx
index 9c8e796..9a56152 100644
--- a/sc/source/ui/inc/olinewin.hxx
+++ b/sc/source/ui/inc/olinewin.hxx
@@ -40,10 +40,10 @@ private:
    bool                        mbMirrorLevels;     /// true = mirror the order of levels, including the border

    Color                       maLineColor;        /// Line color for expanded groups.
    long                        mnHeaderSize;       /// Size of the header area in entry direction.
    long                        mnHeaderPos;        /// Position of the header area in entry direction.
    long                        mnMainFirstPos;     /// First position of main area in entry direction.
    long                        mnMainLastPos;      /// Last position of main area in entry direction.
    tools::Long                        mnHeaderSize;       /// Size of the header area in entry direction.
    tools::Long                        mnHeaderPos;        /// Position of the header area in entry direction.
    tools::Long                        mnMainFirstPos;     /// First position of main area in entry direction.
    tools::Long                        mnMainLastPos;      /// Last position of main area in entry direction.

    size_t                      mnMTLevel;          /// Mouse tracking: Level of active button.
    size_t                      mnMTEntry;          /// Mouse tracking: Entry index of active button.
@@ -65,12 +65,12 @@ public:
    virtual void                dispose() override;

    /** Sets the size of the header area (width/height dep. on window type). */
    void                        SetHeaderSize( long nNewSize );
    void                        SetHeaderSize( tools::Long nNewSize );
    /** Returns the width/height the window needs to show all levels. */
    long                        GetDepthSize() const;
    tools::Long                        GetDepthSize() const;

    /** Scrolls the window content by the specified amount of pixels. */
    void                        ScrollPixel( long nDiff );
    void                        ScrollPixel( tools::Long nDiff );

    using Window::ShowFocus;

@@ -97,33 +97,33 @@ private:
    void                        GetVisibleRange( SCCOLROW& rnColRowStart, SCCOLROW& rnColRowEnd ) const;

    /** Returns the point in the window of the specified position. */
    Point                       GetPoint( long nLevelPos, long nEntryPos ) const;
    Point                       GetPoint( tools::Long nLevelPos, tools::Long nEntryPos ) const;
    /** Returns the rectangle in the window of the specified position. */
    tools::Rectangle                   GetRectangle(
                                    long nLevelStart, long nEntryStart,
                                    long nLevelEnd, long nEntryEnd ) const;
                                    tools::Long nLevelStart, tools::Long nEntryStart,
                                    tools::Long nLevelEnd, tools::Long nEntryEnd ) const;

    /** Returns the window size for the level coordinate. */
    long                        GetOutputSizeLevel() const;
    tools::Long                        GetOutputSizeLevel() const;
    /** Returns the window size for the entry coordinate. */
    long                        GetOutputSizeEntry() const;
    tools::Long                        GetOutputSizeEntry() const;

    /** Returns the count of levels of the outline array. 0 means no outlines. */
    size_t                      GetLevelCount() const;
    /** Returns the pixel position of the specified level. */
    long                        GetLevelPos( size_t nLevel ) const;
    tools::Long                        GetLevelPos( size_t nLevel ) const;
    /** Returns the level of the passed pixel position. */
    size_t                      GetLevelFromPos( long nLevelPos ) const;
    size_t                      GetLevelFromPos( tools::Long nLevelPos ) const;

    /** Returns the start coordinate of the specified column/row in the window. */
    long                        GetColRowPos( SCCOLROW nColRowIndex ) const;
    tools::Long                        GetColRowPos( SCCOLROW nColRowIndex ) const;
    /** Returns the entry position of header images. */
    long                        GetHeaderEntryPos() const;
    tools::Long                        GetHeaderEntryPos() const;
    /** Calculates the coordinates the outline entry takes in the window.
        @return  false = no part of the group is visible (outside window or collapsed by parent group). */
    bool                        GetEntryPos(
                                    size_t nLevel, size_t nEntry,
                                    long& rnStartPos, long& rnEndPos, long& rnImagePos ) const;
                                    tools::Long& rnStartPos, tools::Long& rnEndPos, tools::Long& rnImagePos ) const;
    /** Calculates the absolute position of the image of the specified outline entry.
        @param nLevel  The level of the entry.
        @param nEntry  The entry index or SC_OL_HEADERENTRY for the header image.
@@ -187,14 +187,14 @@ private:
    void                        SetEntryAreaClipRegion();
    /** Converts coordinates to real window points and draws the line. */
    void                        DrawLineRel(
                                    long nLevelStart, long nEntryStart,
                                    long nLevelEnd, long nEntryEnd );
                                    tools::Long nLevelStart, tools::Long nEntryStart,
                                    tools::Long nLevelEnd, tools::Long nEntryEnd );
    /** Converts coordinates to real window points and draws the rectangle. */
    void                        DrawRectRel(
                                    long nLevelStart, long nEntryStart,
                                    long nLevelEnd, long nEntryEnd );
                                    tools::Long nLevelStart, tools::Long nEntryStart,
                                    tools::Long nLevelEnd, tools::Long nEntryEnd );
    /** Draws the specified image unpressed. */
    void                        DrawImageRel(long nLevelPos, long nEntryPos, const OUString& rId);
    void                        DrawImageRel(tools::Long nLevelPos, tools::Long nEntryPos, const OUString& rId);
    /** Draws a pressed or unpressed border. */
    void                        DrawBorderRel(size_t nLevel, size_t nEntry, bool bPressed);

@@ -204,7 +204,7 @@ private:
    void                        HideFocus();

    /** Scrolls the specified range of the window in entry-relative direction. */
    void                        ScrollRel( long nEntryDiff, long nEntryStart, long nEntryEnd );
    void                        ScrollRel( tools::Long nEntryDiff, tools::Long nEntryStart, tools::Long nEntryEnd );

protected:
    virtual void                Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
diff --git a/sc/source/ui/inc/optsolver.hxx b/sc/source/ui/inc/optsolver.hxx
index 313a7e2..ed9860e 100644
--- a/sc/source/ui/inc/optsolver.hxx
+++ b/sc/source/ui/inc/optsolver.hxx
@@ -110,7 +110,7 @@ private:
    bool            mbDlgLostFocus;

    std::vector<ScOptConditionRow> maConditions;
    long            nScrollPos;
    tools::Long            nScrollPos;

    css::uno::Sequence<OUString> maImplNames;
    css::uno::Sequence<OUString> maDescriptions;
diff --git a/sc/source/ui/inc/output.hxx b/sc/source/ui/inc/output.hxx
index 7f84f00..a5de8bb 100644
--- a/sc/source/ui/inc/output.hxx
+++ b/sc/source/ui/inc/output.hxx
@@ -60,11 +60,11 @@ typedef std::unique_ptr<ClearableClipRegion, o3tl::default_delete<ClearableClipR

/// Describes reference mark to be drawn, position & size in TWIPs
struct ReferenceMark {
    long nX;
    long nY;
    long nWidth;
    long nHeight;
    long nTab;
    tools::Long nX;
    tools::Long nY;
    tools::Long nWidth;
    tools::Long nHeight;
    tools::Long nTab;
    Color aColor;

    ReferenceMark()
@@ -75,11 +75,11 @@ struct ReferenceMark {
        , nTab( 0 )
        , aColor( COL_AUTO ) {}

    ReferenceMark( long aX,
                   long aY,
                   long aWidth,
                   long aHeight,
                   long aTab,
    ReferenceMark( tools::Long aX,
                   tools::Long aY,
                   tools::Long aWidth,
                   tools::Long aHeight,
                   tools::Long aTab,
                   const Color& rColor )
        : nX( aX )
        , nY( aY )
@@ -100,9 +100,9 @@ private:
    {
        tools::Rectangle   maAlignRect;
        tools::Rectangle   maClipRect;
        long        mnColWidth;
        long        mnLeftClipLength; /// length of the string getting cut off on the left.
        long        mnRightClipLength; /// length of the string getting cut off on the right.
        tools::Long        mnColWidth;
        tools::Long        mnLeftClipLength; /// length of the string getting cut off on the left.
        tools::Long        mnRightClipLength; /// length of the string getting cut off on the right.
        bool        mbLeftClip;
        bool        mbRightClip;
    };
@@ -121,9 +121,9 @@ private:
        SCCOL                   mnX;
        SCCOL                   mnCellX;
        SCROW                   mnCellY;
        long                    mnPosX;
        long                    mnPosY;
        long                    mnInitPosX;
        tools::Long                    mnPosX;
        tools::Long                    mnPosY;
        tools::Long                    mnInitPosX;
        bool                    mbBreak:1;
        bool                    mbCellIsValue:1;
        bool                    mbAsianVertical:1;
@@ -144,9 +144,9 @@ private:

        bool readCellContent(const ScDocument* pDoc, bool bShowNullValues, bool bShowFormulas, bool bSyntaxMode, bool bUseStyleColor, bool bForceAutoColor, bool& rWrapFields);
        void setPatternToEngine(bool bUseStyleColor);
        void calcMargins(long& rTop, long& rLeft, long& rBottom, long& rRight, double nPPTX, double nPPTY) const;
        void calcMargins(tools::Long& rTop, tools::Long& rLeft, tools::Long& rBottom, tools::Long& rRight, double nPPTX, double nPPTY) const;
        void calcPaperSize(Size& rPaperSize, const tools::Rectangle& rAlignRect, double nPPTX, double nPPTY) const;
        void getEngineSize(ScFieldEditEngine* pEngine, long& rWidth, long& rHeight) const;
        void getEngineSize(ScFieldEditEngine* pEngine, tools::Long& rWidth, tools::Long& rHeight) const;
        bool hasLineBreak() const;
        bool isHyperlinkCell() const;

@@ -165,7 +165,7 @@ private:
         *                    finished, this parameter will store the new
         *                    position.
         */
        void calcStartPosForVertical(Point& rLogicStart, long nCellWidth, long nEngineWidth, long nTopM, const OutputDevice* pRefDevice);
        void calcStartPosForVertical(Point& rLogicStart, tools::Long nCellWidth, tools::Long nEngineWidth, tools::Long nTopM, const OutputDevice* pRefDevice);

        void setAlignmentToEngine();
        bool adjustHorAlignment(ScFieldEditEngine* pEngine);
@@ -180,11 +180,11 @@ private:
    SCSIZE nArrCount;           // occupied lines in info block
    ScDocument* mpDoc;          // Document
    SCTAB nTab;                 // sheet
    long nScrX;                 // Output Startpos. (Pixel)
    long nScrY;
    long nScrW;                 // Output size (Pixel)
    long nScrH;
    long nMirrorW;              // Visible output width for mirroring (default: nScrW)
    tools::Long nScrX;                 // Output Startpos. (Pixel)
    tools::Long nScrY;
    tools::Long nScrW;                 // Output size (Pixel)
    tools::Long nScrH;
    tools::Long nMirrorW;              // Visible output width for mirroring (default: nScrW)
    SCCOL nX1;                  // Start-/End coordinates
    SCROW nY1;                  //  ( incl. hidden )
    SCCOL nX2;
@@ -246,17 +246,17 @@ private:

    bool IsAvailable( SCCOL nX, SCROW nY );

    void            GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY,
                                   SCCOL nCellX, SCROW nCellY, long nNeeded,
    void            GetOutputArea( SCCOL nX, SCSIZE nArrY, tools::Long nPosX, tools::Long nPosY,
                                   SCCOL nCellX, SCROW nCellY, tools::Long nNeeded,
                                   const ScPatternAttr& rPattern,
                                   sal_uInt16 nHorJustify, bool bCellIsValue,
                                   bool bBreak, bool bOverwrite,
                                   OutputAreaParam& rParam );

    void            ShrinkEditEngine( EditEngine& rEngine, const tools::Rectangle& rAlignRect,
                                    long nLeftM, long nTopM, long nRightM, long nBottomM,
                                    bool bWidth, SvxCellOrientation nOrient, long nAttrRotate, bool bPixelToLogic,
                                    long& rEngineWidth, long& rEngineHeight, long& rNeededPixel,
                                    tools::Long nLeftM, tools::Long nTopM, tools::Long nRightM, tools::Long nBottomM,
                                    bool bWidth, SvxCellOrientation nOrient, tools::Long nAttrRotate, bool bPixelToLogic,
                                    tools::Long& rEngineWidth, tools::Long& rEngineHeight, tools::Long& rNeededPixel,
                                    bool& rLeftClip, bool& rRightClip );

    void SetSyntaxColor( vcl::Font* pFont, const ScRefCellValue& rCell );
@@ -276,15 +276,15 @@ private:

    std::unique_ptr<ScFieldEditEngine> CreateOutputEditEngine();

    void ShowClipMarks( DrawEditParam& rParam, long nEngineHeight, const Size& aCellSize,
    void ShowClipMarks( DrawEditParam& rParam, tools::Long nEngineHeight, const Size& aCellSize,
                        bool bMerged, OutputAreaParam& aAreaParam );

    ClearableClipRegionPtr Clip(DrawEditParam& rParam, const Size& aCellSize, OutputAreaParam& aAreaParam,
                                long nEngineHeight, bool bWrapFields);
                                tools::Long nEngineHeight, bool bWrapFields);

    bool AdjustAreaParamClipRect(OutputAreaParam& rAreaParam);
    long SetEngineTextAndGetWidth( DrawEditParam& rParam, const OUString& rSetString,
                                   long& rNeededPixel, long nAddWidthPixels );
    tools::Long SetEngineTextAndGetWidth( DrawEditParam& rParam, const OUString& rSetString,
                                   tools::Long& rNeededPixel, tools::Long nAddWidthPixels );

    // Check for and set cell rotations at OutputData to have it available
    // in the svx tooling to render the borders. Moved to private section
@@ -300,7 +300,7 @@ public:
     */
                    ScOutputData( OutputDevice* pNewDev, ScOutputType eNewType,
                                    ScTableInfo& rTabInfo, ScDocument* pNewDoc,
                                    SCTAB nNewTab, long nNewScrX, long nNewScrY,
                                    SCTAB nNewTab, tools::Long nNewScrX, tools::Long nNewScrY,
                                    SCCOL nNewX1, SCROW nNewY1, SCCOL nNewX2, SCROW nNewY2,
                                    double nPixelPerTwipsX, double nPixelPerTwipsY,
                                    const Fraction* pZoomX = nullptr,
@@ -328,9 +328,9 @@ public:
    void    SetShowNullValues ( bool bSet );
    void    SetShowFormulas   ( bool bSet );
    void    SetShowSpellErrors( bool bSet );
    void    SetMirrorWidth( long nNew );
    long    GetScrW() const     { return nScrW; }
    long    GetScrH() const     { return nScrH; }
    void    SetMirrorWidth( tools::Long nNew );
    tools::Long    GetScrW() const     { return nScrW; }
    tools::Long    GetScrH() const     { return nScrH; }

    void    SetSnapPixel();

@@ -353,7 +353,7 @@ public:
    void    DrawClear();

    // #i72502# printer only command set
    Point   PrePrintDrawingLayer(long nLogStX, long nLogStY );
    Point   PrePrintDrawingLayer(tools::Long nLogStX, tools::Long nLogStY );
    void    PostPrintDrawingLayer(const Point& rMMOffset); // #i74768# need offset for FormLayer
    void    PrintDrawingLayer(SdrLayerID nLayer, const Point& rMMOffset);

diff --git a/sc/source/ui/inc/pagedata.hxx b/sc/source/ui/inc/pagedata.hxx
index 81a277c..14405f0 100644
--- a/sc/source/ui/inc/pagedata.hxx
+++ b/sc/source/ui/inc/pagedata.hxx
@@ -20,6 +20,7 @@
#ifndef INCLUDED_SC_SOURCE_UI_INC_PAGEDATA_HXX
#define INCLUDED_SC_SOURCE_UI_INC_PAGEDATA_HXX

#include <tools/long.hxx>
#include <address.hxx>
#include <memory>
#include <vector>
@@ -32,7 +33,7 @@ private:
                mvPageEndX;
    std::vector<SCROW>
                mvPageEndY;
    long        nFirstPage;
    tools::Long        nFirstPage;
    bool        bTopDown;
    bool        bAutomatic;

@@ -51,8 +52,8 @@ public:
    size_t          GetPagesY() const       { return mvPageEndY.size();   }
    const SCROW*    GetPageEndY() const     { return mvPageEndY.data(); }

    void            SetFirstPage( long nNew )   { nFirstPage = nNew; }
    long            GetFirstPage() const        { return nFirstPage; }
    void            SetFirstPage( tools::Long nNew )   { nFirstPage = nNew; }
    tools::Long            GetFirstPage() const        { return nFirstPage; }
    void            SetTopDown( bool bSet )     { bTopDown = bSet; }
    bool            IsTopDown() const           { return bTopDown; }
    void            SetAutomatic( bool bSet )   { bAutomatic = bSet; }
diff --git a/sc/source/ui/inc/pfuncache.hxx b/sc/source/ui/inc/pfuncache.hxx
index 762e346..888c60c 100644
--- a/sc/source/ui/inc/pfuncache.hxx
+++ b/sc/source/ui/inc/pfuncache.hxx
@@ -68,14 +68,14 @@ public:

struct ScPrintPageLocation
{
    long        nPage;
    tools::Long        nPage;
    ScRange     aCellRange;
    tools::Rectangle   aRectangle;     // pixels

    ScPrintPageLocation() :
        nPage(-1) {}            // default: invalid

    ScPrintPageLocation( long nP, const ScRange& rRange, const tools::Rectangle& rRect ) :
    ScPrintPageLocation( tools::Long nP, const ScRange& rRange, const tools::Rectangle& rRect ) :
        nPage(nP), aCellRange(rRange), aRectangle(rRect) {}
};

@@ -86,7 +86,7 @@ class ScPrintFuncCache
{
    ScPrintSelectionStatus  aSelection;
    ScDocShell*             pDocSh;
    long                    nTotalPages;
    tools::Long                    nTotalPages;
    std::vector<long>       nPages;
    std::vector<long>       nFirstAttr;
    std::vector<ScPrintPageLocation> aLocations;
@@ -102,11 +102,11 @@ public:
    void    InitLocations( const ScMarkData& rMark, OutputDevice* pDev );
    bool    FindLocation( const ScAddress& rCell, ScPrintPageLocation& rLocation ) const;

    long    GetPageCount() const                { return nTotalPages; }
    long    GetFirstAttr( SCTAB nTab ) const    { return nFirstAttr[nTab]; }
    SCTAB   GetTabForPage( long nPage ) const;
    long    GetTabStart( SCTAB nTab ) const;
    long    GetDisplayStart( SCTAB nTab ) const;
    tools::Long    GetPageCount() const                { return nTotalPages; }
    tools::Long    GetFirstAttr( SCTAB nTab ) const    { return nFirstAttr[nTab]; }
    SCTAB   GetTabForPage( tools::Long nPage ) const;
    tools::Long    GetTabStart( SCTAB nTab ) const;
    tools::Long    GetDisplayStart( SCTAB nTab ) const;
};

#endif
diff --git a/sc/source/ui/inc/preview.hxx b/sc/source/ui/inc/preview.hxx
index 5459718..ecb6a96 100644
--- a/sc/source/ui/inc/preview.hxx
+++ b/sc/source/ui/inc/preview.hxx
@@ -34,7 +34,7 @@ class SAL_DLLPUBLIC_RTTI ScPreview : public vcl::Window
private:
    ScMarkData::MarkedTabsType maSelectedTabs;
                                        // set:
    long            nPageNo;            // Pages in document
    tools::Long            nPageNo;            // Pages in document
    sal_uInt16          nZoom;              // set Zoom
    Point           aOffset;            // positive

@@ -44,11 +44,11 @@ private:
    std::vector<long>       nPages;
    std::vector<long>       nFirstAttr;
    SCTAB           nTab;               // Sheet
    long            nTabPage;           // Page of sheet
    long            nTabStart;          // First (real) page of the sheet
    long            nDisplayStart;      // same as above, relative to the start of counting
    tools::Long            nTabPage;           // Page of sheet
    tools::Long            nTabStart;          // First (real) page of the sheet
    tools::Long            nDisplayStart;      // same as above, relative to the start of counting
    DateTime        aDateTime;
    long            nTotalPages;
    tools::Long            nTotalPages;
    ScPrintState    aState;
    std::unique_ptr<ScPreviewLocationData> pLocationData;   // stores table layout for accessibility API
    std::unique_ptr<FmFormView> pDrawView;
@@ -81,14 +81,14 @@ private:

    ScRange         aPageArea;
    std::vector<long> mvRight;
    long            nLeftPosition;
    long            mnScale;
    tools::Long            nLeftPosition;
    tools::Long            mnScale;
    SCCOL           nColNumberButtonDown;
    Point           aButtonDownChangePoint;
    Point           aButtonDownPt;
    Point           aButtonUpPt;
    long            nHeaderHeight;
    long            nFooterHeight;
    tools::Long            nHeaderHeight;
    tools::Long            nFooterHeight;

    void    TestLastPage();
    void    CalcPages();
@@ -123,31 +123,31 @@ public:
    SC_DLLPUBLIC void    DataChanged(bool bNewTime);             //  Instead of calling Invalidate
    void    DoInvalidate();

    void    SetXOffset( long nX );
    void    SetYOffset( long nY );
    void    SetXOffset( tools::Long nX );
    void    SetYOffset( tools::Long nY );
    void    SetZoom(sal_uInt16 nNewZoom);
    SC_DLLPUBLIC void    SetPageNo( long nPage );
    SC_DLLPUBLIC void    SetPageNo( tools::Long nPage );

    bool    GetPageMargins() const { return bPageMargin; }
    void    SetPageMargins( bool bVal )  { bPageMargin = bVal; }
    void    DrawInvert( long nDragPos, PointerStyle nFlags );
    void    DragMove( long nDragMovePos, PointerStyle nFlags );
    void    DrawInvert( tools::Long nDragPos, PointerStyle nFlags );
    void    DragMove( tools::Long nDragMovePos, PointerStyle nFlags );

    const ScPreviewLocationData& GetLocationData();

    OUString  GetPosString();

    long    GetPageNo() const   { return nPageNo; }
    tools::Long    GetPageNo() const   { return nPageNo; }
    sal_uInt16  GetZoom() const     { return nZoom; }
    const Point& GetOffset() const   { return aOffset; }

    SCTAB   GetTab()            { if (!bValid) { CalcPages(); RecalcPages(); } return nTab; }
    long    GetTotalPages()     { if (!bValid) { CalcPages(); RecalcPages(); } return nTotalPages; }
    tools::Long    GetTotalPages()     { if (!bValid) { CalcPages(); RecalcPages(); } return nTotalPages; }

    bool    AllTested() const   { return bValid && nTabsTested >= nTabCount; }

    sal_uInt16  GetOptimalZoom(bool bWidthOnly);
    SC_DLLPUBLIC long    GetFirstPage(SCTAB nTab);
    SC_DLLPUBLIC tools::Long    GetFirstPage(SCTAB nTab);

    void    CalcAll()           { CalcPages(); }
    void    SetInGetState(bool bSet) { bInGetState = bSet; }
diff --git a/sc/source/ui/inc/prevloc.hxx b/sc/source/ui/inc/prevloc.hxx
index 34aa81b..5aa8033 100644
--- a/sc/source/ui/inc/prevloc.hxx
+++ b/sc/source/ui/inc/prevloc.hxx
@@ -45,10 +45,10 @@ struct ScPreviewColRowInfo
{
    bool    bIsHeader;
    SCCOLROW    nDocIndex;
    long    nPixelStart;
    long    nPixelEnd;
    tools::Long    nPixelStart;
    tools::Long    nPixelEnd;

    void Set( bool bHeader, SCCOLROW nIndex, long nStart, long nEnd )
    void Set( bool bHeader, SCCOLROW nIndex, tools::Long nStart, tools::Long nEnd )
    {
        bIsHeader   = bHeader;
        nDocIndex   = nIndex;
@@ -128,8 +128,8 @@ public:
    bool    IsHeaderLeft() const;
    bool    IsFooterLeft() const;

    long    GetNoteCountInRange( const tools::Rectangle& rVisiblePixel, bool bNoteMarks ) const;
    bool    GetNoteInRange( const tools::Rectangle& rVisiblePixel, long nIndex, bool bNoteMarks,
    tools::Long    GetNoteCountInRange( const tools::Rectangle& rVisiblePixel, bool bNoteMarks ) const;
    bool    GetNoteInRange( const tools::Rectangle& rVisiblePixel, tools::Long nIndex, bool bNoteMarks,
                            ScAddress& rCellPos, tools::Rectangle& rNoteRect ) const;
    tools::Rectangle GetNoteInRangeOutputRect(const tools::Rectangle& rVisiblePixel, bool bNoteMarks,
                            const ScAddress& aCellPos) const;
diff --git a/sc/source/ui/inc/prevwsh.hxx b/sc/source/ui/inc/prevwsh.hxx
index 5f2a9e8..d23eca0 100644
--- a/sc/source/ui/inc/prevwsh.hxx
+++ b/sc/source/ui/inc/prevwsh.hxx
@@ -49,7 +49,7 @@ class SC_DLLPUBLIC ScPreviewShell: public SfxViewShell

    TriState        nSourceDesignMode;      // form design mode from TabView
    SvxZoomType     eZoom;
    long            nMaxVertPos;
    tools::Long            nMaxVertPos;

    std::unique_ptr<SfxBroadcaster> pAccessibilityBroadcaster;
    bool            GetPageSize( Size& aPageSize );
diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx
index 96a8715..f59804e 100644
--- a/sc/source/ui/inc/printfun.hxx
+++ b/sc/source/ui/inc/printfun.hxx
@@ -51,8 +51,8 @@ struct ScPrintHFParam
    bool                bEnable;
    bool                bDynamic;
    bool                bShared;
    long                nHeight;            // in total (height + distance + frames)
    long                nManHeight;         // set size (min when dynamic)
    tools::Long                nHeight;            // in total (height + distance + frames)
    tools::Long                nManHeight;         // set size (min when dynamic)
    sal_uInt16          nDistance;
    sal_uInt16          nLeft;              // edges
    sal_uInt16          nRight;
@@ -154,10 +154,10 @@ struct ScPrintState                         //  Save Variables from ScPrintFunc
    sal_uInt16  nZoom;
    size_t  nPagesX;
    size_t  nPagesY;
    long    nTabPages;
    long    nTotalPages;
    long    nPageStart;
    long    nDocPages;
    tools::Long    nTabPages;
    tools::Long    nTotalPages;
    tools::Long    nPageStart;
    tools::Long    nDocPages;

    // Additional state of page ranges
    bool bSavedStateRanges;
@@ -205,8 +205,8 @@ private:
    bool                bIsRender;

    SCTAB               nPrintTab;
    long                nPageStart;         //  Offset for the first page
    long                nDocPages;          //  Number of Pages in Document
    tools::Long                nPageStart;         //  Offset for the first page
    tools::Long                nDocPages;          //  Number of Pages in Document

    const ScRange*      pUserArea;          //  Selection, if set in dialog

@@ -240,8 +240,8 @@ private:
    bool                bPrintCurrentTable;
    bool                bMultiArea;
    bool                mbHasPrintRange;
    long                nTabPages;
    long                nTotalPages;
    tools::Long                nTabPages;
    tools::Long                nTotalPages;

    tools::Rectangle           aPageRect;          // Document Twips

@@ -275,7 +275,7 @@ private:

public:
                    ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab,
                                 long nPage = 0, long nDocP = 0,
                                 tools::Long nPage = 0, tools::Long nDocP = 0,
                                 const ScRange* pArea = nullptr,
                                 const ScPrintOptions* pOptions = nullptr,
                                 ScPageBreakData* pData = nullptr );
@@ -286,7 +286,7 @@ public:
                    // ctors for device other than printer - for preview and pdf:

                    ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
                                 long nPage = 0, long nDocP = 0,
                                 tools::Long nPage = 0, tools::Long nDocP = 0,
                                 const ScRange* pArea = nullptr,
                                 const ScPrintOptions* pOptions = nullptr );

@@ -314,18 +314,18 @@ public:
    bool            UpdatePages();

    void            ApplyPrintSettings();       // Already called from DoPrint()
    long            DoPrint( const MultiSelection& rPageRanges,
                                long nStartPage, long nDisplayStart, bool bDoPrint,
    tools::Long            DoPrint( const MultiSelection& rPageRanges,
                                tools::Long nStartPage, tools::Long nDisplayStart, bool bDoPrint,
                                ScPreviewLocationData* pLocationData );

                    // Query values - immediately

    const Size&     GetPageSize() const { return aPageSize; }
    Size            GetDataSize() const;
    void            GetScaleData( Size& rPhysSize, long& rDocHdr, long& rDocFtr );
    long            GetFirstPageNo() const  { return aTableParam.nFirstPageNo; }
    void            GetScaleData( Size& rPhysSize, tools::Long& rDocHdr, tools::Long& rDocFtr );
    tools::Long            GetFirstPageNo() const  { return aTableParam.nFirstPageNo; }

    long            GetTotalPages() const { return nTotalPages; }
    tools::Long            GetTotalPages() const { return nTotalPages; }
    sal_uInt16      GetZoom() const { return nZoom; }

    void            ResetBreaks( SCTAB nTab );
@@ -346,45 +346,45 @@ private:
    void            InitParam( const ScPrintOptions* pOptions );
    void            CalcZoom( sal_uInt16 nRangeNo );
    void            CalcPages();
    long            CountPages();
    long            CountNotePages();
    tools::Long            CountPages();
    tools::Long            CountNotePages();

    bool            AdjustPrintArea( bool bNew );

    Size            GetDocPageSize();

    long            TextHeight( const EditTextObject* pObject );
    tools::Long            TextHeight( const EditTextObject* pObject );
    void            MakeEditEngine();
    void            UpdateHFHeight( ScPrintHFParam& rParam );

    void            InitModes();

    bool            IsLeft( long nPageNo );
    bool            IsMirror( long nPageNo );
    bool            IsLeft( tools::Long nPageNo );
    bool            IsMirror( tools::Long nPageNo );
    void            MakeTableString();                  // sets aTableStr

    void            PrintPage( long nPageNo,
    void            PrintPage( tools::Long nPageNo,
                                    SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
                                    bool bDoPrint, ScPreviewLocationData* pLocationData );
    void            PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
                                    long nScrX, long nScrY,
                                    tools::Long nScrX, tools::Long nScrY,
                                    bool bShLeft, bool bShTop, bool bShRight, bool bShBottom );
    void            LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
                                    long nScrX, long nScrY, bool bRepCol, bool bRepRow,
                                    tools::Long nScrX, tools::Long nScrY, bool bRepCol, bool bRepRow,
                                    ScPreviewLocationData& rLocationData );
    void            PrintColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY );
    void            PrintRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY );
    void            LocateColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY,
    void            PrintColHdr( SCCOL nX1, SCCOL nX2, tools::Long nScrX, tools::Long nScrY );
    void            PrintRowHdr( SCROW nY1, SCROW nY2, tools::Long nScrX, tools::Long nScrY );
    void            LocateColHdr( SCCOL nX1, SCCOL nX2, tools::Long nScrX, tools::Long nScrY,
                                bool bRepCol, ScPreviewLocationData& rLocationData );
    void            LocateRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY,
    void            LocateRowHdr( SCROW nY1, SCROW nY2, tools::Long nScrX, tools::Long nScrY,
                                bool bRepRow, ScPreviewLocationData& rLocationData );
    void            PrintHF( long nPageNo, bool bHeader, long nStartY,
    void            PrintHF( tools::Long nPageNo, bool bHeader, tools::Long nStartY,
                                    bool bDoPrint, ScPreviewLocationData* pLocationData );

    long            PrintNotes( long nPageNo, long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
    long            DoNotes( long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
    tools::Long            PrintNotes( tools::Long nPageNo, tools::Long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
    tools::Long            DoNotes( tools::Long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );

    void            DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH,
    void            DrawBorder( tools::Long nScrX, tools::Long nScrY, tools::Long nScrW, tools::Long nScrH,
                                    const SvxBoxItem* pBorderData,
                                    const SvxBrushItem* pBackground,
                                    const SvxShadowItem* pShadow );
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index 25e5445..97a1edc 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -176,7 +176,7 @@ private:
    OUString                sTipString;
    VclPtr<vcl::Window>     sTopParent;

    long                nPrevDragPos;
    tools::Long                nPrevDragPos;

    BlockMode           meBlockMode;           // Marks block

@@ -218,20 +218,20 @@ private:

    void            DoAddWin( ScGridWindow* pWin );

    void            InitScrollBar( ScrollBar& rScrollBar, long nMaxVal );
    void            InitScrollBar( ScrollBar& rScrollBar, tools::Long nMaxVal );
    DECL_LINK(ScrollHdl, ScrollBar*, void );
    DECL_LINK(EndScrollHdl, ScrollBar*, void );

    DECL_LINK(SplitHdl, Splitter*, void);
    void            DoHSplit(long nSplitPos);
    void            DoVSplit(long nSplitPos);
    void            DoHSplit(tools::Long nSplitPos);
    void            DoVSplit(tools::Long nSplitPos);

    DECL_LINK( TimerHdl, Timer*, void );

    void            UpdateVarZoom();

    static void     SetScrollBar( ScrollBar& rScroll, long nRangeMax, long nVisible, long nPos, bool bLayoutRTL );
    static long     GetScrollBarPos( const ScrollBar& rScroll );
    static void     SetScrollBar( ScrollBar& rScroll, tools::Long nRangeMax, tools::Long nVisible, tools::Long nPos, bool bLayoutRTL );
    static tools::Long     GetScrollBarPos( const ScrollBar& rScroll );

    void            GetAreaMoveEndPosition(SCCOL nMovX, SCROW nMovY, ScFollowMode eMode,
                                           SCCOL& rAreaX, SCROW& rAreaY, ScFollowMode& rMode);
@@ -293,7 +293,7 @@ public:

    DECL_LINK( TabBarResize, ::TabBar*, void );
    /** Sets an absolute tab bar width (in pixels). */
    void            SetTabBarWidth( long nNewWidth );
    void            SetTabBarWidth( tools::Long nNewWidth );
    /** Sets a relative tab bar width.
        @param fRelTabBarWidth  Tab bar width relative to frame window width (0.0 ... 1.0). */
    SC_DLLPUBLIC void            SetRelTabBarWidth( double fRelTabBarWidth );
@@ -301,7 +301,7 @@ public:
        @param fRelTabBarWidth  Tab bar width relative to frame window width (0.0 ... 1.0). */
    void            SetPendingRelTabBarWidth( double fRelTabBarWidth );
    /** Returns the current tab bar width in pixels. */
    long            GetTabBarWidth() const;
    tools::Long            GetTabBarWidth() const;
    /** Returns the current tab bar width relative to the frame window width (0.0 ... 1.0). */
    SC_DLLPUBLIC static double   GetRelTabBarWidth();
    /** Returns the pending tab bar width relative to the frame window width (0.0 ... 1.0). */
@@ -386,8 +386,8 @@ public:

    void            CheckSelectionTransfer();

    void            InvertHorizontal( ScVSplitPos eWhich, long nDragPos );
    void            InvertVertical( ScHSplitPos eWhich, long nDragPos );
    void            InvertHorizontal( ScVSplitPos eWhich, tools::Long nDragPos );
    void            InvertVertical( ScHSplitPos eWhich, tools::Long nDragPos );

    Point           GetInsertPos() const;

@@ -448,9 +448,9 @@ public:
    void            SetTimer( ScGridWindow* pWin, const MouseEvent& rMEvt );
    void            ResetTimer();

    void            ScrollX( long nDeltaX, ScHSplitPos eWhich, bool bUpdBars = true );
    void            ScrollY( long nDeltaY, ScVSplitPos eWhich, bool bUpdBars = true );
    SC_DLLPUBLIC void           ScrollLines( long nDeltaX, long nDeltaY );              // active
    void            ScrollX( tools::Long nDeltaX, ScHSplitPos eWhich, bool bUpdBars = true );
    void            ScrollY( tools::Long nDeltaY, ScVSplitPos eWhich, bool bUpdBars = true );
    SC_DLLPUBLIC void           ScrollLines( tools::Long nDeltaX, tools::Long nDeltaY );              // active

    bool            ScrollCommand( const CommandEvent& rCEvt, ScSplitPos ePos );

@@ -486,15 +486,15 @@ public:
    void            CheckNeedsRepaint();
    bool            NeedsRepaint();

    void            PaintRangeFinder( long nNumber );
    void            PaintRangeFinder( tools::Long nNumber );
    void            AddHighlightRange( const ScRange& rRange, const Color& rColor );
    void            ClearHighlightRanges();

    void            DoChartSelection( const css::uno::Sequence< css::chart2::data::HighlightedRange > & rHilightRanges );
    void            DoDPFieldPopup(OUString const & rPivotTableName, sal_Int32 nDimensionIndex, Point aPoint, Size aSize);

    long            GetGridWidth( ScHSplitPos eWhich );
    long            GetGridHeight( ScVSplitPos eWhich );
    tools::Long            GetGridWidth( ScHSplitPos eWhich );
    tools::Long            GetGridHeight( ScVSplitPos eWhich );

    void            UpdateScrollBars( HeaderType eHeaderType = BOTH_HEADERS );
    void            SetNewVisArea();
diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index 3f1342b..02b27c5 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -298,7 +298,7 @@ public:

    ObjectSelectionType GetCurObjectSelectionType() const { return eCurOST; }

    virtual ErrCode DoVerb(long nVerb) override;
    virtual ErrCode DoVerb(tools::Long nVerb) override;

    void            StopEditShell();
    bool            IsDrawTextShell() const;
@@ -321,7 +321,7 @@ public:
    virtual std::unique_ptr<SfxTabPage> CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rOptions) override;

    void            ConnectObject( const SdrOle2Obj* pObj );
    void            ActivateObject( SdrOle2Obj* pObj, long nVerb );
    void            ActivateObject( SdrOle2Obj* pObj, tools::Long nVerb );

    void            DeactivateOle();

diff --git a/sc/source/ui/inc/tbzoomsliderctrl.hxx b/sc/source/ui/inc/tbzoomsliderctrl.hxx
index bb3660f..944f9c8 100644
--- a/sc/source/ui/inc/tbzoomsliderctrl.hxx
+++ b/sc/source/ui/inc/tbzoomsliderctrl.hxx
@@ -47,8 +47,8 @@ private:
    std::unique_ptr<ScZoomSliderWnd_Impl> mpImpl;
    css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider;

    sal_uInt16 Offset2Zoom(long nOffset) const;
    long Zoom2Offset(sal_uInt16 nZoom) const;
    sal_uInt16 Offset2Zoom(tools::Long nOffset) const;
    tools::Long Zoom2Offset(sal_uInt16 nZoom) const;

    void DoPaint(vcl::RenderContext& rRenderContext);
public:
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 2b98731..1895799 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -140,14 +140,14 @@ public:
    ScPositionHelper(const ScDocument *pDoc, bool bColumn);
    void setDocument(const ScDocument& rDoc, bool bColumn);

    void insert(index_type nIndex, long nPos);
    void insert(index_type nIndex, tools::Long nPos);
    void removeByIndex(index_type nIndex);
    void invalidateByIndex(index_type nIndex);
    void invalidateByPosition(long nPos);
    void invalidateByPosition(tools::Long nPos);
    const value_type& getNearestByIndex(index_type nIndex) const;
    const value_type& getNearestByPosition(long nPos) const;
    long getPosition(index_type nIndex) const;
    long computePosition(index_type nIndex, const std::function<long (index_type)>& getSizePx);
    const value_type& getNearestByPosition(tools::Long nPos) const;
    tools::Long getPosition(index_type nIndex) const;
    tools::Long computePosition(index_type nIndex, const std::function<long (index_type)>& getSizePx);
};

class ScBoundsProvider
@@ -164,43 +164,43 @@ class ScBoundsProvider
    double mfPPTY;
    index_type nFirstIndex;
    index_type nSecondIndex;
    long nFirstPositionPx;
    long nSecondPositionPx;
    tools::Long nFirstPositionPx;
    tools::Long nSecondPositionPx;

public:
    ScBoundsProvider(const ScViewData &rView, SCTAB nT, bool bColumnHeader);

    void GetStartIndexAndPosition(SCCOL& nIndex, long& nPosition) const;
    void GetEndIndexAndPosition(SCCOL& nIndex, long& nPosition) const;
    void GetStartIndexAndPosition(SCROW& nIndex, long& nPosition) const;
    void GetEndIndexAndPosition(SCROW& nIndex, long& nPosition) const;
    void GetStartIndexAndPosition(SCCOL& nIndex, tools::Long& nPosition) const;
    void GetEndIndexAndPosition(SCCOL& nIndex, tools::Long& nPosition) const;
    void GetStartIndexAndPosition(SCROW& nIndex, tools::Long& nPosition) const;
    void GetEndIndexAndPosition(SCROW& nIndex, tools::Long& nPosition) const;

    void Compute(value_type aFirstNearest, value_type aSecondNearest,
                 long nFirstBound, long nSecondBound);
                 tools::Long nFirstBound, tools::Long nSecondBound);

    void EnlargeStartBy(long nOffset);
    void EnlargeStartBy(tools::Long nOffset);

    void EnlargeEndBy(long nOffset);
    void EnlargeEndBy(tools::Long nOffset);

    void EnlargeBy(long nOffset)
    void EnlargeBy(tools::Long nOffset)
    {
        EnlargeStartBy(nOffset);
        EnlargeEndBy(nOffset);
    }

private:
    long GetSize(index_type nIndex) const;
    tools::Long GetSize(index_type nIndex) const;

    void GetIndexAndPos(index_type nNearestIndex, long nNearestPosition,
                        long nBound, index_type& nFoundIndex, long& nPosition,
                        bool bTowards, long nDiff);
    void GetIndexAndPos(index_type nNearestIndex, tools::Long nNearestPosition,
                        tools::Long nBound, index_type& nFoundIndex, tools::Long& nPosition,
                        bool bTowards, tools::Long nDiff);

    void GeIndexBackwards(index_type nNearestIndex, long nNearestPosition,
                          long nBound, index_type& nFoundIndex, long& nPosition,
    void GeIndexBackwards(index_type nNearestIndex, tools::Long nNearestPosition,
                          tools::Long nBound, index_type& nFoundIndex, tools::Long& nPosition,
                          bool bTowards);

    void GetIndexTowards(index_type nNearestIndex, long nNearestPosition,
                         long nBound, index_type& nFoundIndex, long& nPosition,
    void GetIndexTowards(index_type nNearestIndex, tools::Long nNearestPosition,
                         tools::Long nBound, index_type& nFoundIndex, tools::Long& nPosition,
                         bool bTowards);
};

@@ -214,14 +214,14 @@ private:
    Fraction        aPageZoomX;                 // zoom in page break preview mode
    Fraction        aPageZoomY;

    long            nTPosX[2];                  // MapMode - Offset (Twips)
    long            nTPosY[2];
    long            nMPosX[2];                  // MapMode - Offset (1/100 mm)
    long            nMPosY[2];
    long            nPixPosX[2];                // Offset in Pixels
    long            nPixPosY[2];
    long            nHSplitPos;
    long            nVSplitPos;
    tools::Long            nTPosX[2];                  // MapMode - Offset (Twips)
    tools::Long            nTPosY[2];
    tools::Long            nMPosX[2];                  // MapMode - Offset (1/100 mm)
    tools::Long            nMPosY[2];
    tools::Long            nPixPosX[2];                // Offset in Pixels
    tools::Long            nPixPosY[2];
    tools::Long            nHSplitPos;
    tools::Long            nVSplitPos;

    ScSplitMode     eHSplitMode;
    ScSplitMode     eVSplitMode;
@@ -331,7 +331,7 @@ private:

    bool                bGrowing;

    long                m_nLOKPageUpDownOffset;
    tools::Long                m_nLOKPageUpDownOffset;
    tools::Rectangle    maLOKVisibleArea;///< The visible area in the LibreOfficeKit client.

    DECL_DLLPRIVATE_LINK( EditEngineHdl, EditStatus&, void );
@@ -404,8 +404,8 @@ public:
    SCROW           GetCurYForTab( SCTAB nTabIndex ) const;
    SCCOL           GetOldCurX() const;
    SCROW           GetOldCurY() const;
    long            GetLOKDocWidthPixel() const             { return pThisTab->aWidthHelper.getPosition(pThisTab->nMaxTiledCol); }
    long            GetLOKDocHeightPixel() const            { return pThisTab->aHeightHelper.getPosition(pThisTab->nMaxTiledRow); }
    tools::Long            GetLOKDocWidthPixel() const             { return pThisTab->aWidthHelper.getPosition(pThisTab->nMaxTiledCol); }
    tools::Long            GetLOKDocHeightPixel() const            { return pThisTab->aHeightHelper.getPosition(pThisTab->nMaxTiledRow); }

    ScPositionHelper& GetLOKWidthHelper()                   { return pThisTab->aWidthHelper; }
    ScPositionHelper& GetLOKHeightHelper()                  { return pThisTab->aHeightHelper; }
@@ -415,8 +415,8 @@ public:

    ScSplitMode     GetHSplitMode() const                   { return pThisTab->eHSplitMode; }
    ScSplitMode     GetVSplitMode() const                   { return pThisTab->eVSplitMode; }
    long            GetHSplitPos() const                    { return pThisTab->nHSplitPos; }
    long            GetVSplitPos() const                    { return pThisTab->nVSplitPos; }
    tools::Long            GetHSplitPos() const                    { return pThisTab->nHSplitPos; }
    tools::Long            GetVSplitPos() const                    { return pThisTab->nVSplitPos; }
    SCCOL           GetFixPosX() const                      { return pThisTab->nFixPosX; }
    SCROW           GetFixPosY() const                      { return pThisTab->nFixPosY; }
    SCCOL           GetMaxTiledCol() const                  { return pThisTab->nMaxTiledCol; }
@@ -437,8 +437,8 @@ public:

    void            SetHSplitMode( ScSplitMode eMode )              { pThisTab->eHSplitMode = eMode; }
    void            SetVSplitMode( ScSplitMode eMode )              { pThisTab->eVSplitMode = eMode; }
    void            SetHSplitPos( long nPos )                       { pThisTab->nHSplitPos = nPos; }
    void            SetVSplitPos( long nPos )                       { pThisTab->nVSplitPos = nPos; }
    void            SetHSplitPos( tools::Long nPos )                       { pThisTab->nHSplitPos = nPos; }
    void            SetVSplitPos( tools::Long nPos )                       { pThisTab->nVSplitPos = nPos; }
    void            SetFixPosX( SCCOL nPos )                        { pThisTab->nFixPosX = nPos; }
    void            SetFixPosY( SCROW nPos )                        { pThisTab->nFixPosY = nPos; }
    void            SetMaxTiledCol( SCCOL nCol );
@@ -502,9 +502,9 @@ public:
    void            SetEditAdjust( SvxAdjust eNewEditAdjust ) { eEditAdjust = eNewEditAdjust; }

                    // TRUE: Cell is merged
    bool            GetMergeSizePixel( SCCOL nX, SCROW nY, long& rSizeXPix, long& rSizeYPix ) const;
    bool            GetMergeSizePrintTwips( SCCOL nX, SCROW nY, long& rSizeXTwips, long& rSizeYTwips ) const;
    void            GetPosFromPixel( long nClickX, long nClickY, ScSplitPos eWhich,
    bool            GetMergeSizePixel( SCCOL nX, SCROW nY, tools::Long& rSizeXPix, tools::Long& rSizeYPix ) const;
    bool            GetMergeSizePrintTwips( SCCOL nX, SCROW nY, tools::Long& rSizeXTwips, tools::Long& rSizeYTwips ) const;
    void            GetPosFromPixel( tools::Long nClickX, tools::Long nClickY, ScSplitPos eWhich,
                                        SCCOL& rPosX, SCROW& rPosY,
                                        bool bTestMerge = true, bool bRepair = false, SCTAB nForTab = -1 );
    void            GetMouseQuadrant( const Point& rClickPos, ScSplitPos eWhich,
@@ -548,8 +548,8 @@ public:
    bool    IsOutlineMode   () const            { return maOptions.GetOption(VOPT_OUTLINER); }

    /// Force page size for PgUp/PgDown to overwrite the computation based on m_aVisArea.
    void ForcePageUpDownOffset(long nTwips) { m_nLOKPageUpDownOffset = nTwips; }
    long GetPageUpDownOffset() const { return m_nLOKPageUpDownOffset; }
    void ForcePageUpDownOffset(tools::Long nTwips) { m_nLOKPageUpDownOffset = nTwips; }
    tools::Long GetPageUpDownOffset() const { return m_nLOKPageUpDownOffset; }

    /// The visible area in the client (set by setClientVisibleArea).
    const tools::Rectangle& getLOKVisibleArea() const { return maLOKVisibleArea; }
@@ -656,16 +656,16 @@ public:
    void            DeriveLOKFreezeIfNeeded(SCTAB nForTab);
    void            OverrideWithLOKFreeze(ScSplitMode& eExHSplitMode, ScSplitMode& eExVSplitMode,
                                          SCCOL& nExFixPosX, SCROW& nExFixPosY,
                                          long& nExHSplitPos, long& nExVSplitPos, SCTAB nForTab) const;
                                          tools::Long& nExHSplitPos, tools::Long& nExVSplitPos, SCTAB nForTab) const;

    static inline long ToPixel( sal_uInt16 nTwips, double nFactor );
    static inline tools::Long ToPixel( sal_uInt16 nTwips, double nFactor );

    /** while (rScrY <= nEndPixels && rPosY <= nEndRow) add pixels of row
        heights converted with nPPTY to rScrY, optimized for row height
        segments. Upon return rPosY is the last row evaluated <= nEndRow, rScrY
        may be > nEndPixels!
     */
    static void     AddPixelsWhile( long & rScrY, long nEndPixels,
    static void     AddPixelsWhile( tools::Long & rScrY, tools::Long nEndPixels,
                                    SCROW & rPosY, SCROW nEndRow, double nPPTY,
                                    const ScDocument * pDoc, SCTAB nTabNo );

@@ -674,14 +674,14 @@ public:
        segments. Upon return rPosY is the last row evaluated >= nStartRow,
        rScrY may be > nEndPixels!
     */
    static void     AddPixelsWhileBackward( long & rScrY, long nEndPixels,
    static void     AddPixelsWhileBackward( tools::Long & rScrY, tools::Long nEndPixels,
                                    SCROW & rPosY, SCROW nStartRow, double nPPTY,
                                    const ScDocument * pDoc, SCTAB nTabNo );
};

inline long ScViewData::ToPixel( sal_uInt16 nTwips, double nFactor )
inline tools::Long ScViewData::ToPixel( sal_uInt16 nTwips, double nFactor )
{
    long nRet = static_cast<long>( nTwips * nFactor );
    tools::Long nRet = static_cast<tools::Long>( nTwips * nFactor );
    if ( !nRet && nTwips )
        nRet = 1;
    return nRet;
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index 5a7ad68..bb0644b 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -338,8 +338,8 @@ public:
                                    sal_uInt16 aColLength);
    void            UpdateSelectionArea( const ScMarkData& rSel, ScPatternAttr* pAttr = nullptr );

    void            OnLOKInsertDeleteColumn(SCCOL nStartCol, long nOffset);
    void            OnLOKInsertDeleteRow(SCROW nStartRow, long nOffset);
    void            OnLOKInsertDeleteColumn(SCCOL nStartCol, tools::Long nOffset);
    void            OnLOKInsertDeleteRow(SCROW nStartRow, tools::Long nOffset);
    void            OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth);

                                                // Internal helper functions
diff --git a/sc/source/ui/miscdlgs/crnrdlg.cxx b/sc/source/ui/miscdlgs/crnrdlg.cxx
index 82f42c1..c037405 100644
--- a/sc/source/ui/miscdlgs/crnrdlg.cxx
+++ b/sc/source/ui/miscdlgs/crnrdlg.cxx
@@ -742,7 +742,7 @@ IMPL_LINK_NOARG(ScColRowNameRangesDlg, ColClickHdl, weld::Button&, void)
        m_xEdAssign->SetText( aStr );
    }
    ScRange aRange( theCurData );
    aRange.aStart.SetRow( std::min( static_cast<long>(theCurArea.aEnd.Row() + 1), static_cast<long>(rDoc.MaxRow()) ) );
    aRange.aStart.SetRow( std::min( static_cast<tools::Long>(theCurArea.aEnd.Row() + 1), static_cast<tools::Long>(rDoc.MaxRow()) ) );
    aRange.aEnd.SetRow( rDoc.MaxRow() );
    AdjustColRowData( aRange );
}
@@ -760,7 +760,7 @@ IMPL_LINK_NOARG(ScColRowNameRangesDlg, RowClickHdl, weld::Button&, void)
        m_xEdAssign->SetText( aStr );
    }
    ScRange aRange( theCurData );
    aRange.aStart.SetCol( static_cast<SCCOL>(std::min( static_cast<long>(theCurArea.aEnd.Col() + 1), static_cast<long>(rDoc.MaxCol()) )) );
    aRange.aStart.SetCol( static_cast<SCCOL>(std::min( static_cast<tools::Long>(theCurArea.aEnd.Col() + 1), static_cast<tools::Long>(rDoc.MaxCol()) )) );
    aRange.aEnd.SetCol( rDoc.MaxCol() );
    AdjustColRowData( aRange );
}
diff --git a/sc/source/ui/miscdlgs/mtrindlg.cxx b/sc/source/ui/miscdlgs/mtrindlg.cxx
index 3e6aa2d..4226be6 100644
--- a/sc/source/ui/miscdlgs/mtrindlg.cxx
+++ b/sc/source/ui/miscdlgs/mtrindlg.cxx
@@ -23,12 +23,12 @@

ScMetricInputDlg::ScMetricInputDlg( weld::Window*         pParent,
                                    const OString&  sDialogName,
                                    long            nCurrent,
                                    long            nDefault,
                                    tools::Long            nCurrent,
                                    tools::Long            nDefault,
                                    FieldUnit       eFUnit,
                                    sal_uInt16      nDecimals,
                                    long            nMaximum,
                                    long            nMinimum)
                                    tools::Long            nMaximum,
                                    tools::Long            nMinimum)

    : GenericDialogController(pParent, OStringToOUString("modules/scalc/ui/" +
        sDialogName.toAsciiLowerCase() + ".ui", RTL_TEXTENCODING_UTF8), sDialogName)
diff --git a/sc/source/ui/miscdlgs/optsolver.cxx b/sc/source/ui/miscdlgs/optsolver.cxx
index 2da4898..e3c6b1d 100644
--- a/sc/source/ui/miscdlgs/optsolver.cxx
+++ b/sc/source/ui/miscdlgs/optsolver.cxx
@@ -374,11 +374,11 @@ void ScOptSolverDlg::ReadConditions()
        aRowEntry.aRightStr = mpRightEdit[nRow]->GetText();
        aRowEntry.nOperator = mpOperator[nRow]->get_active();

        long nVecPos = nScrollPos + nRow;
        if ( nVecPos >= static_cast<long>(maConditions.size()) && !aRowEntry.IsDefault() )
        tools::Long nVecPos = nScrollPos + nRow;
        if ( nVecPos >= static_cast<tools::Long>(maConditions.size()) && !aRowEntry.IsDefault() )
            maConditions.resize( nVecPos + 1 );

        if ( nVecPos < static_cast<long>(maConditions.size()) )
        if ( nVecPos < static_cast<tools::Long>(maConditions.size()) )
            maConditions[nVecPos] = aRowEntry;

        // remove default entries at the end
@@ -395,8 +395,8 @@ void ScOptSolverDlg::ShowConditions()
    {
        ScOptConditionRow aRowEntry;

        long nVecPos = nScrollPos + nRow;
        if ( nVecPos < static_cast<long>(maConditions.size()) )
        tools::Long nVecPos = nScrollPos + nRow;
        if ( nVecPos < static_cast<tools::Long>(maConditions.size()) )
            aRowEntry = maConditions[nVecPos];

        mpLeftEdit[nRow]->SetRefString( aRowEntry.aLeftStr );
@@ -405,8 +405,8 @@ void ScOptSolverDlg::ShowConditions()
    }

    // allow to scroll one page behind the visible or stored rows
    long nVisible = nScrollPos + EDIT_ROW_COUNT;
    long nMax = std::max( nVisible, static_cast<long>(maConditions.size()) );
    tools::Long nVisible = nScrollPos + EDIT_ROW_COUNT;
    tools::Long nMax = std::max( nVisible, static_cast<tools::Long>(maConditions.size()) );
    m_xScrollBar->vadjustment_configure(nScrollPos, 0, nMax + EDIT_ROW_COUNT, 1,
                                        EDIT_ROW_COUNT - 1, EDIT_ROW_COUNT);

@@ -417,8 +417,8 @@ void ScOptSolverDlg::EnableButtons()
{
    for ( sal_uInt16 nRow = 0; nRow < EDIT_ROW_COUNT; ++nRow )
    {
        long nVecPos = nScrollPos + nRow;
        mpDelButton[nRow]->set_sensitive(nVecPos < static_cast<long>(maConditions.size()));
        tools::Long nVecPos = nScrollPos + nRow;
        mpDelButton[nRow]->set_sensitive(nVecPos < static_cast<tools::Long>(maConditions.size()));
    }
}

@@ -626,8 +626,8 @@ IMPL_LINK(ScOptSolverDlg, DelBtnHdl, weld::Button&, rBtn, void)
            bool bHadFocus = rBtn.has_focus();

            ReadConditions();
            long nVecPos = nScrollPos + nRow;
            if ( nVecPos < static_cast<long>(maConditions.size()) )
            tools::Long nVecPos = nScrollPos + nRow;
            if ( nVecPos < static_cast<tools::Long>(maConditions.size()) )
            {
                maConditions.erase( maConditions.begin() + nVecPos );
                ShowConditions();
diff --git a/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx b/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
index 90e72f5..daae959 100644
--- a/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
+++ b/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
@@ -350,7 +350,7 @@ void AlignmentPropertyPanel::NotifyItemUpdate(
    case SID_ATTR_ALIGN_DEGREES:
        if (eState >= SfxItemState::DEFAULT)
        {
            long nTmp = static_cast<const ScRotateValueItem*>(pState)->GetValue();
            tools::Long nTmp = static_cast<const ScRotateValueItem*>(pState)->GetValue();
            mxMtrAngle->set_value(nTmp / 100, FieldUnit::DEGREE);
        }
        else
diff --git a/sc/source/ui/sidebar/CellLineStyleValueSet.cxx b/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
index 624df48..a47c1d1 100644
--- a/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
+++ b/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
@@ -75,8 +75,8 @@ void CellLineStyleValueSet::UserDraw( const UserDrawEvent& rUDEvt )
    vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
    sal_uInt16  nItemId = rUDEvt.GetItemId();

    long nRectHeight = aRect.GetHeight();
    long nRectWidth = aRect.GetWidth();
    tools::Long nRectHeight = aRect.GetHeight();
    tools::Long nRectWidth = aRect.GetWidth();
    Point aBLPos = aRect.TopLeft();

    vcl::Font aOldFont = pDev->GetFont();
@@ -111,9 +111,9 @@ void CellLineStyleValueSet::UserDraw( const UserDrawEvent& rUDEvt )
        aFont.SetColor(rStyleSettings.GetFieldTextColor()); //high contrast

    pDev->SetFont(aFont);
    long nTextWidth = pDev->GetTextWidth(maStrUnit[nItemId - 1]);
    long nTLX = aBLPos.X() + 5,  nTLY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
    long nTRX = aBLPos.X() + nRectWidth - nTextWidth - 15, nTRY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
    tools::Long nTextWidth = pDev->GetTextWidth(maStrUnit[nItemId - 1]);
    tools::Long nTLX = aBLPos.X() + 5,  nTLY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
    tools::Long nTRX = aBLPos.X() + nRectWidth - nTextWidth - 15, nTRY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
    Point aStart(aBLPos.X() + nRectWidth - nTextWidth - 5 , aBLPos.Y() + nRectHeight/6);
    pDev->DrawText(aStart, maStrUnit[nItemId - 1]); //can't set DrawTextFlags::EndEllipsis here, or the text will disappear

diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index be9e606..f6d2c1b 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -172,7 +172,7 @@ void ScUndoInsertCells::DoChange( const bool bUndo )

                if (pViewShell)
                {
                    const long nSign = bUndo ? -1 : 1;
                    const tools::Long nSign = bUndo ? -1 : 1;
                    pViewShell->OnLOKInsertDeleteRow(aEffRange.aStart.Row(), nSign * (aEffRange.aEnd.Row()-aEffRange.aStart.Row()+1));
                }
            }
@@ -191,7 +191,7 @@ void ScUndoInsertCells::DoChange( const bool bUndo )

                if (pViewShell)
                {
                    const long nSign = bUndo ? -1 : 1;
                    const tools::Long nSign = bUndo ? -1 : 1;
                    pViewShell->OnLOKInsertDeleteColumn(aEffRange.aStart.Col(), nSign * (aEffRange.aEnd.Col()-aEffRange.aStart.Col()+1));
                }
            }
@@ -420,7 +420,7 @@ void ScUndoDeleteCells::DoChange( const bool bUndo )

                if (pViewShell)
                {
                    const long nSign = bUndo ? 1 : -1;
                    const tools::Long nSign = bUndo ? 1 : -1;
                    pViewShell->OnLOKInsertDeleteRow(aEffRange.aStart.Row(), nSign * (aEffRange.aEnd.Row()-aEffRange.aStart.Row()+1));
                }
            }
@@ -438,7 +438,7 @@ void ScUndoDeleteCells::DoChange( const bool bUndo )

                if (pViewShell)
                {
                    const long nSign = bUndo ? 1 : -1;
                    const tools::Long nSign = bUndo ? 1 : -1;
                    pViewShell->OnLOKInsertDeleteColumn(aEffRange.aStart.Col(), nSign * (aEffRange.aEnd.Col()-aEffRange.aStart.Col()+1));
                }
            }
diff --git a/sc/source/ui/unoobj/ChartTools.cxx b/sc/source/ui/unoobj/ChartTools.cxx
index 5bb960d..b176369 100644
--- a/sc/source/ui/unoobj/ChartTools.cxx
+++ b/sc/source/ui/unoobj/ChartTools.cxx
@@ -117,7 +117,7 @@ SdrOle2Obj* findChartsByName(ScDocShell* pDocShell, SCTAB nTab, OUString const &
    return nullptr;
}

SdrOle2Obj* getChartByIndex(ScDocShell* pDocShell, SCTAB nTab, long nIndex, ChartSourceType eChartSourceType)
SdrOle2Obj* getChartByIndex(ScDocShell* pDocShell, SCTAB nTab, ::tools::Long nIndex, ChartSourceType eChartSourceType)
{
    if (!pDocShell)
        return nullptr;
@@ -125,7 +125,7 @@ SdrOle2Obj* getChartByIndex(ScDocShell* pDocShell, SCTAB nTab, long nIndex, Char
    ChartIterator aIterator(pDocShell, nTab, eChartSourceType);

    SdrOle2Obj* pObject = aIterator.next();
    long i = 0;
    ::tools::Long i = 0;
    while (pObject)
    {
        if (i == nIndex)
diff --git a/sc/source/ui/unoobj/PivotTableDataProvider.cxx b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
index ae1fb2c73..8288be2 100644
--- a/sc/source/ui/unoobj/PivotTableDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
@@ -369,7 +369,7 @@ void PivotTableDataProvider::collectPivotTableData()

        uno::Reference<container::XIndexAccess> xLevels = new ScNameToIndexAccess(xLevelsSupplier->getLevels());

        for (long nLevel = 0; nLevel < xLevels->getCount(); nLevel++)
        for (tools::Long nLevel = 0; nLevel < xLevels->getCount(); nLevel++)
        {
            uno::Reference<uno::XInterface> xLevel(xLevels->getByIndex(nLevel), uno::UNO_QUERY);
            uno::Reference<container::XNamed> xLevelName(xLevel, uno::UNO_QUERY);
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 8e56678..f760656 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -1115,8 +1115,8 @@ static bool lcl_PutDataArray( ScDocShell& rDocShell, const ScRange& rRange,
        return false;
    }

    long nCols = 0;
    long nRows = aData.getLength();
    tools::Long nCols = 0;
    tools::Long nRows = aData.getLength();
    if ( nRows )
        nCols = aData[0].getLength();

@@ -1250,8 +1250,8 @@ static bool lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRange,
        return false;
    }

    long nCols = 0;
    long nRows = aData.getLength();
    tools::Long nCols = 0;
    tools::Long nRows = aData.getLength();
    if ( nRows )
        nCols = aData[0].getLength();

@@ -2985,7 +2985,7 @@ uno::Sequence< uno::Sequence<double> > SAL_CALL ScCellRangesBase::getData()
    return uno::Sequence< uno::Sequence<double> >(0);
}

ScRangeListRef ScCellRangesBase::GetLimitedChartRanges_Impl( long nDataColumns, long nDataRows ) const
ScRangeListRef ScCellRangesBase::GetLimitedChartRanges_Impl( tools::Long nDataColumns, tools::Long nDataRows ) const
{
    if ( aRanges.size() == 1 )
    {
@@ -2998,13 +2998,13 @@ ScRangeListRef ScCellRangesBase::GetLimitedChartRanges_Impl( long nDataColumns, 

            SCTAB nTab = rRange.aStart.Tab();

            long nEndColumn = nDataColumns - 1 + ( bChartColAsHdr ? 1 : 0 );
            tools::Long nEndColumn = nDataColumns - 1 + ( bChartColAsHdr ? 1 : 0 );
            if ( nEndColumn < 0 )
                nEndColumn = 0;
            if ( nEndColumn > rDoc.MaxCol() )
                nEndColumn = rDoc.MaxCol();

            long nEndRow = nDataRows - 1 + ( bChartRowAsHdr ? 1 : 0 );
            tools::Long nEndRow = nDataRows - 1 + ( bChartRowAsHdr ? 1 : 0 );
            if ( nEndRow < 0 )
                nEndRow = 0;
            if ( nEndRow > rDoc.MaxRow() )
@@ -3022,8 +3022,8 @@ void SAL_CALL ScCellRangesBase::setData( const uno::Sequence< uno::Sequence<doub
{
    SolarMutexGuard aGuard;
    bool bDone = false;
    long nRowCount = aData.getLength();
    long nColCount = nRowCount ? aData[0].getLength() : 0;
    tools::Long nRowCount = aData.getLength();
    tools::Long nColCount = nRowCount ? aData[0].getLength() : 0;
    ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, nRowCount );
    if ( pDocShell && xChartRanges.is() )
    {
@@ -3036,12 +3036,12 @@ void SAL_CALL ScCellRangesBase::setData( const uno::Sequence< uno::Sequence<doub
            if ( pPosMap->GetColCount() == static_cast<SCCOL>(nColCount) &&
                 pPosMap->GetRowCount() == static_cast<SCROW>(nRowCount) )
            {
                for (long nRow=0; nRow<nRowCount; nRow++)
                for (tools::Long nRow=0; nRow<nRowCount; nRow++)
                {
                    const uno::Sequence<double>& rRowSeq = aData[nRow];
                    const double* pArray = rRowSeq.getConstArray();
                    nColCount = rRowSeq.getLength();
                    for (long nCol=0; nCol<nColCount; nCol++)
                    for (tools::Long nCol=0; nCol<nColCount; nCol++)
                    {
                        const ScAddress* pPos = pPosMap->GetPosition(
                                sal::static_int_cast<SCCOL>(nCol),
@@ -3094,7 +3094,7 @@ void SAL_CALL ScCellRangesBase::setRowDescriptions(
    bool bDone = false;
    if ( bChartColAsHdr )
    {
        long nRowCount = aRowDescriptions.getLength();
        tools::Long nRowCount = aRowDescriptions.getLength();
        ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( 1, nRowCount );
        if ( pDocShell && xChartRanges.is() )
        {
@@ -3107,7 +3107,7 @@ void SAL_CALL ScCellRangesBase::setRowDescriptions(
                if ( pPosMap->GetRowCount() == static_cast<SCROW>(nRowCount) )
                {
                    const OUString* pArray = aRowDescriptions.getConstArray();
                    for (long nRow=0; nRow<nRowCount; nRow++)
                    for (tools::Long nRow=0; nRow<nRowCount; nRow++)
                    {
                        const ScAddress* pPos = pPosMap->GetRowHeaderPosition(
                                static_cast<SCSIZE>(nRow) );
@@ -3163,7 +3163,7 @@ void SAL_CALL ScCellRangesBase::setColumnDescriptions(
    bool bDone = false;
    if ( bChartRowAsHdr )
    {
        long nColCount = aColumnDescriptions.getLength();
        tools::Long nColCount = aColumnDescriptions.getLength();
        ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, 1 );
        if ( pDocShell && xChartRanges.is() )
        {
@@ -3176,7 +3176,7 @@ void SAL_CALL ScCellRangesBase::setColumnDescriptions(
                if ( pPosMap->GetColCount() == static_cast<SCCOL>(nColCount) )
                {
                    const OUString* pArray = aColumnDescriptions.getConstArray();
                    for (long nCol=0; nCol<nColCount; nCol++)
                    for (tools::Long nCol=0; nCol<nColCount; nCol++)
                    {
                        const ScAddress* pPos = pPosMap->GetColHeaderPosition(
                            sal::static_int_cast<SCCOL>(nCol) );
@@ -8863,7 +8863,7 @@ void ScCellFormatsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    }
}

ScCellRangeObj* ScCellFormatsObj::GetObjectByIndex_Impl(long nIndex) const
ScCellRangeObj* ScCellFormatsObj::GetObjectByIndex_Impl(tools::Long nIndex) const
{
    //! access the AttrArrays directly !!!!

@@ -8871,7 +8871,7 @@ ScCellRangeObj* ScCellFormatsObj::GetObjectByIndex_Impl(long nIndex) const
    if (pDocShell)
    {
        ScDocument& rDoc = pDocShell->GetDocument();
        long nPos = 0;
        tools::Long nPos = 0;
        ScAttrRectIterator aIter( rDoc, aTotalRange.aStart.Tab(),
                                    aTotalRange.aStart.Col(), aTotalRange.aStart.Row(),
                                    aTotalRange.aEnd.Col(), aTotalRange.aEnd.Row() );
@@ -8903,7 +8903,7 @@ sal_Int32 SAL_CALL ScCellFormatsObj::getCount()

    //! access the AttrArrays directly !!!!

    long nCount = 0;
    tools::Long nCount = 0;
    if (pDocShell)
    {
        ScDocument& rDoc = pDocShell->GetDocument();
diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx
index 419c373..638d517 100644
--- a/sc/source/ui/unoobj/chartuno.cxx
+++ b/sc/source/ui/unoobj/chartuno.cxx
@@ -81,7 +81,7 @@ void ScChartsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    }
}

ScChartObj* ScChartsObj::GetObjectByIndex_Impl(long nIndex) const
ScChartObj* ScChartsObj::GetObjectByIndex_Impl(tools::Long nIndex) const
{
    OUString aName;
    if ( pDocShell )
@@ -94,7 +94,7 @@ ScChartObj* ScChartsObj::GetObjectByIndex_Impl(long nIndex) const
            OSL_ENSURE(pPage, "Page not found");
            if (pPage)
            {
                long nPos = 0;
                tools::Long nPos = 0;
                SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
                SdrObject* pObject = aIter.Next();
                while (pObject)
@@ -354,11 +354,11 @@ uno::Sequence<OUString> SAL_CALL ScChartsObj::getElementNames()
    {
        ScDocument& rDoc = pDocShell->GetDocument();

        long nCount = getCount();
        tools::Long nCount = getCount();
        uno::Sequence<OUString> aSeq(nCount);
        OUString* pAry = aSeq.getArray();

        long nPos = 0;
        tools::Long nPos = 0;
        ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
        if (pDrawLayer)
        {
diff --git a/sc/source/ui/unoobj/cursuno.cxx b/sc/source/ui/unoobj/cursuno.cxx
index c94d977..a301be0 100644
--- a/sc/source/ui/unoobj/cursuno.cxx
+++ b/sc/source/ui/unoobj/cursuno.cxx
@@ -197,8 +197,8 @@ void SAL_CALL ScCellCursorObj::collapseToSize( sal_Int32 nColumns, sal_Int32 nRo
        aNewRange.PutInOrder();    //! really?

        const auto & rDoc = GetDocShell()->GetDocument();
        long nEndX = aNewRange.aStart.Col() + nColumns - 1;
        long nEndY = aNewRange.aStart.Row() + nRows - 1;
        tools::Long nEndX = aNewRange.aStart.Col() + nColumns - 1;
        tools::Long nEndY = aNewRange.aStart.Row() + nRows - 1;
        if ( nEndX < 0 )      nEndX = 0;
        if ( nEndX > rDoc.MaxCol() ) nEndX = rDoc.MaxCol();
        if ( nEndY < 0 )      nEndY = 0;
diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index 2104eec..76ae587 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -2005,7 +2005,7 @@ sal_Int16 ScDataPilotFieldObj::getFunction() const
        if( pDim->GetOrientation() != DataPilotFieldOrientation_DATA )
        {
            // for non-data fields, property Function is the subtotals
            long nSubCount = pDim->GetSubTotalsCount();
            tools::Long nSubCount = pDim->GetSubTotalsCount();
            if ( nSubCount > 0 )
                eRet = static_cast<sal_Int16>(pDim->GetSubTotalFunc(0));    // always use the first one
            // else keep NONE
@@ -2488,8 +2488,8 @@ Reference< XDataPilotField > SAL_CALL ScDataPilotFieldObj::createNameGroup( cons
                //! Also do this when removing groups?
                //! Handle this case dynamically with automatic groups?

                long nGroupCount = pBaseGroupDim->GetGroupCount();
                for ( long nGroup = 0; nGroup < nGroupCount; nGroup++ )
                tools::Long nGroupCount = pBaseGroupDim->GetGroupCount();
                for ( tools::Long nGroup = 0; nGroup < nGroupCount; nGroup++ )
                {
                    const ScDPSaveGroupItem& rBaseGroup = pBaseGroupDim->GetGroupByIndex( nGroup );

diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 55d16e0..1fbbf37 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -530,7 +530,7 @@ static ScViewData* lcl_getViewMatchingDocZoomTab(const Fraction& rZoomX,
void ScModelObj::paintTile( VirtualDevice& rDevice,
                            int nOutputWidth, int nOutputHeight,
                            int nTilePosX, int nTilePosY,
                            long nTileWidth, long nTileHeight )
                            tools::Long nTileWidth, tools::Long nTileHeight )
{
    ScTabViewShell* pViewShell = pDocShell->GetBestViewShell(false);

@@ -539,8 +539,8 @@ void ScModelObj::paintTile( VirtualDevice& rDevice,
        return;

    ScViewData* pActiveViewData = &pViewShell->GetViewData();
    Fraction aFracX(long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth);
    Fraction aFracY(long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight);
    Fraction aFracX(tools::Long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth);
    Fraction aFracY(tools::Long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight);

    // Try to find a view that matches the tile-zoom requested by iterating over
    // first few shells. This is to avoid switching of zooms in ScGridWindow::PaintTile
@@ -671,8 +671,8 @@ Size ScModelObj::getDocumentSize()
        return ScViewData::ToPixel(nSize, fPPTX);
    };

    long nDocWidthPixel = pViewData->GetLOKWidthHelper().computePosition(nEndCol, GetColWidthPx);
    long nDocHeightPixel = pThisDoc->GetScaledRowHeight(0, nEndRow, nTab, fPPTY);
    tools::Long nDocWidthPixel = pViewData->GetLOKWidthHelper().computePosition(nEndCol, GetColWidthPx);
    tools::Long nDocHeightPixel = pThisDoc->GetScaledRowHeight(0, nEndRow, nTab, fPPTY);

    if (nDocWidthPixel > 0 && nDocHeightPixel > 0)
    {
@@ -1100,8 +1100,8 @@ void ScModelObj::getPostIts(tools::JsonWriter& rJsonWriter)
            SCCOL nX = aNote.maPos.Col();
            SCROW nY = aNote.maPos.Row();
            Point aScrPos = pViewData->GetScrPos(nX, nY, pViewData->GetActivePart(), true);
            long nSizeXPix;
            long nSizeYPix;
            tools::Long nSizeXPix;
            tools::Long nSizeYPix;
            pViewData->GetMergeSizePixel(nX, nY, nSizeXPix, nSizeYPix);

            double fPPTX = pViewData->GetPPTX();
@@ -1139,8 +1139,8 @@ void ScModelObj::getPostItsPos(tools::JsonWriter& rJsonWriter)
            SCCOL nX = aNote.maPos.Col();
            SCROW nY = aNote.maPos.Row();
            Point aScrPos = pViewData->GetScrPos(nX, nY, pViewData->GetActivePart(), true);
            long nSizeXPix;
            long nSizeYPix;
            tools::Long nSizeXPix;
            tools::Long nSizeYPix;
            pViewData->GetMergeSizePixel(nX, nY, nSizeXPix, nSizeYPix);

            double fPPTX = pViewData->GetPPTX();
@@ -1751,7 +1751,7 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 
    ScPrintSelectionStatus aStatus;
    OUString aPagesStr;
    // #i115266# if FillRenderMarkData fails, keep nTotalPages at 0, but still handle getRenderer(0) below
    long nTotalPages = 0;
    tools::Long nTotalPages = 0;
    bool bRenderToGraphic = false;
    bool bSinglePageSheets = false;
    if ( FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr, bRenderToGraphic ) )
@@ -1934,8 +1934,8 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 
        else
            aPage.Select( nRenderer+1 );

        long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
        long nTabStart = pPrintFuncCache->GetTabStart( nTab );
        tools::Long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
        tools::Long nTabStart = pPrintFuncCache->GetTabStart( nTab );

        (void)pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart, false, nullptr );

@@ -1952,7 +1952,7 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 
        aPageSize.Height = TwipsToHMM( aTwips.Height());
    }

    long nPropCount = bWasCellRange ? 5 : 4;
    tools::Long nPropCount = bWasCellRange ? 5 : 4;
    uno::Sequence<beans::PropertyValue> aSequence(nPropCount);
    beans::PropertyValue* pArray = aSequence.getArray();
    pArray[0].Name = SC_UNONAME_PAGESIZE;
@@ -2010,7 +2010,7 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
    {
        pPrintFuncCache.reset(new ScPrintFuncCache( pDocShell, aMark, aStatus ));
    }
    long nTotalPages = pPrintFuncCache->GetPageCount();
    tools::Long nTotalPages = pPrintFuncCache->GetPageCount();

    for ( const auto& rValue : rOptions)
    {
@@ -2167,8 +2167,8 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
    else
        aPage.Select( nRenderer+1 );

    long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
    long nTabStart = pPrintFuncCache->GetTabStart( nTab );
    tools::Long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
    tools::Long nTabStart = pPrintFuncCache->GetTabStart( nTab );

    vcl::PDFExtOutDevData* pPDFData = dynamic_cast< vcl::PDFExtOutDevData* >(pDev->GetExtOutDevData() );
    if ( nRenderer == nTabStart )
@@ -2261,10 +2261,10 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
                        Fraction aScaleX( aLocationPixel.GetWidth(), aLocationMM.GetWidth() );
                        Fraction aScaleY( aLocationPixel.GetHeight(), aLocationMM.GetHeight() );

                        long nX1 = aLocationPixel.Left() + static_cast<long>( Fraction( aTargetRect.Left() - aLocationMM.Left(), 1 ) * aScaleX );
                        long nX2 = aLocationPixel.Left() + static_cast<long>( Fraction( aTargetRect.Right() - aLocationMM.Left(), 1 ) * aScaleX );
                        long nY1 = aLocationPixel.Top() + static_cast<long>( Fraction( aTargetRect.Top() - aLocationMM.Top(), 1 ) * aScaleY );
                        long nY2 = aLocationPixel.Top() + static_cast<long>( Fraction( aTargetRect.Bottom() - aLocationMM.Top(), 1 ) * aScaleY );
                        tools::Long nX1 = aLocationPixel.Left() + static_cast<tools::Long>( Fraction( aTargetRect.Left() - aLocationMM.Left(), 1 ) * aScaleX );
                        tools::Long nX2 = aLocationPixel.Left() + static_cast<tools::Long>( Fraction( aTargetRect.Right() - aLocationMM.Left(), 1 ) * aScaleX );
                        tools::Long nY1 = aLocationPixel.Top() + static_cast<tools::Long>( Fraction( aTargetRect.Top() - aLocationMM.Top(), 1 ) * aScaleY );
                        tools::Long nY2 = aLocationPixel.Top() + static_cast<tools::Long>( Fraction( aTargetRect.Bottom() - aLocationMM.Top(), 1 ) * aScaleY );

                        if ( nX1 > aLocationPixel.Right() ) nX1 = aLocationPixel.Right();
                        if ( nX2 > aLocationPixel.Right() ) nX2 = aLocationPixel.Right();
diff --git a/sc/source/ui/unoobj/fmtuno.cxx b/sc/source/ui/unoobj/fmtuno.cxx
index 48caa4b..7497cd7 100644
--- a/sc/source/ui/unoobj/fmtuno.cxx
+++ b/sc/source/ui/unoobj/fmtuno.cxx
@@ -406,8 +406,8 @@ uno::Any SAL_CALL ScTableConditionalFormat::getByName( const OUString& aName )
    SolarMutexGuard aGuard;

    uno::Reference<sheet::XSheetConditionalEntry> xEntry;
    long nCount = maEntries.size();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = maEntries.size();
    for (tools::Long i=0; i<nCount; i++)
        if ( aName == lcl_GetEntryNameFromIndex(i) )
        {
            xEntry.set(GetObjectByIndex_Impl(static_cast<sal_uInt16>(i)));
@@ -424,10 +424,10 @@ uno::Sequence<OUString> SAL_CALL ScTableConditionalFormat::getElementNames()
{
    SolarMutexGuard aGuard;

    long nCount = maEntries.size();
    tools::Long nCount = maEntries.size();
    uno::Sequence<OUString> aNames(nCount);
    OUString* pArray = aNames.getArray();
    for (long i=0; i<nCount; i++)
    for (tools::Long i=0; i<nCount; i++)
        pArray[i] = lcl_GetEntryNameFromIndex(i);

    return aNames;
@@ -437,8 +437,8 @@ sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const OUString& aName )
{
    SolarMutexGuard aGuard;

    long nCount = maEntries.size();
    for (long i=0; i<nCount; i++)
    tools::Long nCount = maEntries.size();
    for (tools::Long i=0; i<nCount; i++)
        if ( aName == lcl_GetEntryNameFromIndex(i) )
            return true;

diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx
index 6f26b0b..34de496 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -309,7 +309,7 @@ static bool lcl_AddFunctionToken( ScTokenArray& rArray, const OUString& rName,co
    return false;       // no valid function name
}

static void lcl_AddRef( ScTokenArray& rArray, long nStartRow, long nColCount, long nRowCount )
static void lcl_AddRef( ScTokenArray& rArray, tools::Long nStartRow, tools::Long nColCount, tools::Long nRowCount )
{
    ScComplexRefData aRef;
    aRef.InitRange(ScRange(0,nStartRow,0,nColCount-1,nStartRow+nRowCount-1,0));
@@ -332,19 +332,19 @@ public:
    // the other types methods are here just to reflect the orig code and for
    // completeness.

    void visitElem( long nCol, long nRow, sal_Int16 elem )
    void visitElem( tools::Long nCol, tools::Long nRow, sal_Int16 elem )
    {
        mpDoc->SetValue( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), 0, elem );
    }
    void visitElem( long nCol, long nRow, sal_Int32 elem )
    void visitElem( tools::Long nCol, tools::Long nRow, sal_Int32 elem )
    {
        mpDoc->SetValue( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), 0, elem );
    }
    void visitElem( long nCol, long nRow, const double& elem )
    void visitElem( tools::Long nCol, tools::Long nRow, const double& elem )
    {
        mpDoc->SetValue( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), 0, elem );
    }
    void visitElem( long nCol, long nRow, const OUString& elem )
    void visitElem( tools::Long nCol, tools::Long nRow, const OUString& elem )
    {
        if (!elem.isEmpty())
        {
@@ -353,7 +353,7 @@ public:
            mpDoc->SetString(ScAddress(nCol,nRow,0), elem, &aParam);
        }
    }
    void visitElem( long nCol, long nRow, const uno::Any& rElement )
    void visitElem( tools::Long nCol, tools::Long nRow, const uno::Any& rElement )
    {
        uno::TypeClass eElemClass = rElement.getValueTypeClass();
        if ( eElemClass == uno::TypeClass_VOID )
@@ -391,14 +391,14 @@ class SequencesContainer
{
    uno::Sequence< uno::Sequence< seq > > maSeq;

    long& mrDocRow;
    tools::Long& mrDocRow;
    bool mbOverflow;
    bool mbArgError;
    ScDocument* mpDoc;
    ScTokenArray& mrTokenArr;

public:
    SequencesContainer( const uno::Any& rArg, ScTokenArray& rTokenArr, long& rDocRow, ScDocument* pDoc ) :
    SequencesContainer( const uno::Any& rArg, ScTokenArray& rTokenArr, tools::Long& rDocRow, ScDocument* pDoc ) :
        mrDocRow( rDocRow ), mbOverflow(false), mbArgError(false), mpDoc( pDoc ), mrTokenArr( rTokenArr )
    {
        rArg >>= maSeq;
@@ -407,16 +407,16 @@ public:
    void process()
    {
        SimpleVisitor aVisitor(mpDoc);
        long nStartRow = mrDocRow;
        long nRowCount = maSeq.getLength();
        long nMaxColCount = 0;
        tools::Long nStartRow = mrDocRow;
        tools::Long nRowCount = maSeq.getLength();
        tools::Long nMaxColCount = 0;
        for ( const uno::Sequence< seq >& rRow : maSeq )
        {
            long nColCount = rRow.getLength();
            tools::Long nColCount = rRow.getLength();
            if ( nColCount > nMaxColCount )
                nMaxColCount = nColCount;
            const seq* pColArr = rRow.getConstArray();
            for (long nCol=0; nCol<nColCount; nCol++)
            for (tools::Long nCol=0; nCol<nColCount; nCol++)
                if ( nCol <= mpDoc->MaxCol() && mrDocRow <= mpDoc->MaxRow() )
                    aVisitor.visitElem( nCol, mrDocRow, pColArr[ nCol ] );
                else
@@ -436,7 +436,7 @@ class ArrayOfArrayProc
{
public:
static void processSequences( ScDocument* pDoc, const uno::Any& rArg, ScTokenArray& rTokenArr,
                                long& rDocRow, bool& rArgErr, bool& rOverflow )
                                tools::Long& rDocRow, bool& rArgErr, bool& rOverflow )
{
    SequencesContainer< T > aContainer( rArg, rTokenArr, rDocRow, pDoc );
    aContainer.process();
@@ -487,13 +487,13 @@ uno::Any SAL_CALL ScFunctionAccess::callFunction( const OUString& aName,

    bool bArgErr = false;
    bool bOverflow = false;
    long nDocRow = 0;
    long nArgCount = aArguments.getLength();
    tools::Long nDocRow = 0;
    tools::Long nArgCount = aArguments.getLength();
    const uno::Any* pArgArr = aArguments.getConstArray();

    svl::SharedStringPool& rSPool = pDoc->GetSharedStringPool();
    aTokenArr.AddOpCode(ocOpen);
    for (long nPos=0; nPos<nArgCount; nPos++)
    for (tools::Long nPos=0; nPos<nArgCount; nPos++)
    {
        if ( nPos > 0 )
            aTokenArr.AddOpCode(ocSep);
@@ -557,9 +557,9 @@ uno::Any SAL_CALL ScFunctionAccess::callFunction( const OUString& aName,
                {
                    ScRange const & rSrcRange = rRanges[ 0 ];

                    long nStartRow = nDocRow;
                    long nColCount = rSrcRange.aEnd.Col() - rSrcRange.aStart.Col() + 1;
                    long nRowCount = rSrcRange.aEnd.Row() - rSrcRange.aStart.Row() + 1;
                    tools::Long nStartRow = nDocRow;
                    tools::Long nColCount = rSrcRange.aEnd.Col() - rSrcRange.aStart.Col() + 1;
                    tools::Long nRowCount = rSrcRange.aEnd.Row() - rSrcRange.aStart.Row() + 1;

                    if ( nStartRow + nRowCount > pDoc->GetSheetLimits().GetMaxRowCount() )
                        bOverflow = true;
diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx
index 4dafd1d..26b1636 100644
--- a/sc/source/ui/unoobj/nameuno.cxx
+++ b/sc/source/ui/unoobj/nameuno.cxx
@@ -579,7 +579,7 @@ uno::Reference<container::XEnumeration> SAL_CALL ScNamedRangesObj::createEnumera
sal_Int32 SAL_CALL ScNamedRangesObj::getCount()
{
    SolarMutexGuard aGuard;
    long nRet = 0;
    tools::Long nRet = 0;
    if (pDocShell)
    {
        ScRangeName* pNames = GetRangeName_Impl();
@@ -662,7 +662,7 @@ uno::Sequence<OUString> SAL_CALL ScNamedRangesObj::getElementNames()
        ScRangeName* pNames = GetRangeName_Impl();
        if (pNames)
        {
            long nVisCount = getCount();            // names with lcl_UserVisibleName
            tools::Long nVisCount = getCount();            // names with lcl_UserVisibleName
            uno::Sequence<OUString> aSeq(nVisCount);
            OUString* pAry = aSeq.getArray();
            sal_uInt16 nVisPos = 0;
diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx
index 2d63065..feea0f8 100644
--- a/sc/source/ui/unoobj/viewuno.cxx
+++ b/sc/source/ui/unoobj/viewuno.cxx
@@ -199,7 +199,7 @@ void SAL_CALL ScViewPaneBase::setFirstVisibleColumn(sal_Int32 nFirstVisibleColum
                                static_cast<ScSplitPos>(nPane);
        ScHSplitPos eWhichH = WhichH( eWhich );

        long nDeltaX = static_cast<long>(nFirstVisibleColumn) - rViewData.GetPosX( eWhichH );
        tools::Long nDeltaX = static_cast<tools::Long>(nFirstVisibleColumn) - rViewData.GetPosX( eWhichH );
        pViewShell->ScrollX( nDeltaX, eWhichH );
    }
}
@@ -232,7 +232,7 @@ void SAL_CALL ScViewPaneBase::setFirstVisibleRow( sal_Int32 nFirstVisibleRow )
                                static_cast<ScSplitPos>(nPane);
        ScVSplitPos eWhichV = WhichV( eWhich );

        long nDeltaY = static_cast<long>(nFirstVisibleRow) - rViewData.GetPosY( eWhichV );
        tools::Long nDeltaY = static_cast<tools::Long>(nFirstVisibleRow) - rViewData.GetPosY( eWhichV );
        pViewShell->ScrollY( nDeltaY, eWhichV );
    }
}
@@ -766,12 +766,12 @@ sal_Bool SAL_CALL ScTabViewObj::select( const uno::Any& aSelection )
                //  and select all objects on that sheet
                //!?throw exception when objects are on different sheets?

                long nCount = xShapeColl->getCount();
                tools::Long nCount = xShapeColl->getCount();
                if (nCount)
                {
                    SdrPageView* pPV = nullptr;
                    bool bAllMarked(true);
                    for ( long i = 0; i < nCount; i++ )
                    for ( tools::Long i = 0; i < nCount; i++ )
                    {
                        uno::Reference<drawing::XShape> xShapeInt(xShapeColl->getByIndex(i), uno::UNO_QUERY);
                        if (xShapeInt.is())
@@ -1368,7 +1368,7 @@ sal_Int16 ScTabViewObj::GetZoom() const
    if (pViewSh)
    {
        const Fraction& rZoomY = pViewSh->GetViewData().GetZoomY();    // Y will be shown
        return static_cast<sal_Int16>(long( rZoomY * 100 ));
        return static_cast<sal_Int16>(tools::Long( rZoomY * 100 ));
    }
    return 0;
}
@@ -1549,7 +1549,7 @@ sal_Int32 SAL_CALL ScTabViewObj::getSplitColumn()
        ScViewData& rViewData = pViewSh->GetViewData();
        if ( rViewData.GetHSplitMode() != SC_SPLIT_NONE )
        {
            long nSplit = rViewData.GetHSplitPos();
            tools::Long nSplit = rViewData.GetHSplitPos();

            ScSplitPos ePos = SC_SPLIT_BOTTOMLEFT;
            if ( rViewData.GetVSplitMode() != SC_SPLIT_NONE )
@@ -1574,7 +1574,7 @@ sal_Int32 SAL_CALL ScTabViewObj::getSplitRow()
        ScViewData& rViewData = pViewSh->GetViewData();
        if ( rViewData.GetVSplitMode() != SC_SPLIT_NONE )
        {
            long nSplit = rViewData.GetVSplitPos();
            tools::Long nSplit = rViewData.GetVSplitPos();

            // split vertically
            SCCOL nCol;
diff --git a/sc/source/ui/vba/vbahyperlink.hxx b/sc/source/ui/vba/vbahyperlink.hxx
index 93c686c..047a5cb 100644
--- a/sc/source/ui/vba/vbahyperlink.hxx
+++ b/sc/source/ui/vba/vbahyperlink.hxx
@@ -23,6 +23,7 @@
#include <ooo/vba/excel/XHyperlink.hpp>

#include <vbahelper/vbahelperinterface.hxx>
#include <tools/long.hxx>

namespace ooo::vba::excel { class XRange; }
namespace com::sun::star::beans { class XPropertySet; }
@@ -80,7 +81,7 @@ private:
    css::uno::Reference< css::table::XCell > mxCell;
    css::uno::Reference< css::beans::XPropertySet > mxTextField;
    OUString maScreenTip;
    long mnType;
    tools::Long mnType;
};

#endif // INCLUDED_SC_SOURCE_UI_VBA_VBAHYPERLINK_HXX
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index 510a0d4..019a0d8 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -185,7 +185,7 @@ static double lcl_TwipsToPoints( sal_uInt16 nVal )
static double lcl_Round2DecPlaces( double nVal )
{
    nVal  = (nVal * double(100));
    long tmp = static_cast<long>(nVal);
    tools::Long tmp = static_cast<tools::Long>(nVal);
    if ( ( nVal - tmp ) >= 0.5 )
        ++tmp;
    nVal = double(tmp)/100;
@@ -489,7 +489,7 @@ public:
    }
    uno::Reference< beans::XPropertySet > getNumberProps()
    {
        long nIndexKey = 0;
        tools::Long nIndexKey = 0;
        uno::Any aValue = mxRangeProps->getPropertyValue( "NumberFormat" );
        aValue >>= nIndexKey;

@@ -2021,7 +2021,7 @@ ScVbaRange::Characters(const uno::Any& Start, const uno::Any& Length)
        return xRange->Characters( Start, Length );
    }

    long nIndex = 0, nCount = 0;
    tools::Long nIndex = 0, nCount = 0;
    OUString rString;
    uno::Reference< text::XTextRange > xTextRange(mxRange, ::uno::UNO_QUERY_THROW );
    rString = xTextRange->getString();
@@ -2591,7 +2591,7 @@ ScVbaRange::getNumberFormat()
uno::Reference< excel::XRange >
ScVbaRange::Resize( const uno::Any &RowSize, const uno::Any &ColumnSize )
{
    long nRowSize = 0, nColumnSize = 0;
    tools::Long nRowSize = 0, nColumnSize = 0;
    bool bIsRowChanged = ( RowSize >>= nRowSize ), bIsColumnChanged = ( ColumnSize >>= nColumnSize );
    uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, ::uno::UNO_QUERY_THROW);
    uno::Reference< sheet::XSheetCellRange > xSheetRange(mxRange, ::uno::UNO_QUERY_THROW);
@@ -3746,7 +3746,7 @@ static double getDefaultCharWidth( ScDocShell* pDocShell )
    vcl::Font aDefFont;
    pAttr->GetFont( aDefFont, SC_AUTOCOL_BLACK, pRefDevice );
    pRefDevice->SetFont( aDefFont );
    long nCharWidth = pRefDevice->GetTextWidth( OUString( '0' ) );        // 1/100th mm
    tools::Long nCharWidth = pRefDevice->GetTextWidth( OUString( '0' ) );        // 1/100th mm
    return lcl_hmmToPoints( nCharWidth );
}

diff --git a/sc/source/ui/vba/vbaworksheets.cxx b/sc/source/ui/vba/vbaworksheets.cxx
index 616440a..5ff95d7 100644
--- a/sc/source/ui/vba/vbaworksheets.cxx
+++ b/sc/source/ui/vba/vbaworksheets.cxx
@@ -523,7 +523,7 @@ void ScVbaWorksheets::PrintPreview( const css::uno::Any& /*EnableChanges*/ )
    // force update
    pPrvView->DataChanged(false);
    // set sensible first page
    long nPage = pPrvView->GetFirstPage( 1 );
    tools::Long nPage = pPrvView->GetFirstPage( 1 );
    pPrvView->SetPageNo( nPage );
    WaitUntilPreviewIsClosed( pViewFrame );
    // restore old tab selection
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index 538f8a4..924ce27 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -704,7 +704,7 @@ void ScCellShell::Execute( SfxRequest& rReq )

                    if ( pDlg->Execute() == RET_OK )
                    {
                        long nVal = pDlg->GetInputValue();
                        tools::Long nVal = pDlg->GetInputValue();
                        pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, static_cast<sal_uInt16>(nVal) );

                        // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
@@ -740,7 +740,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                        ScGlobal::nLastRowHeightExtra, 0, eMetric, 1, MAX_EXTRA_HEIGHT));
                    if ( pDlg->Execute() == RET_OK )
                    {
                        long nVal = pDlg->GetInputValue();
                        tools::Long nVal = pDlg->GetInputValue();
                        pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL, static_cast<sal_uInt16>(nVal) );
                        ScGlobal::nLastRowHeightExtra = nVal;

@@ -801,7 +801,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                        STD_COL_WIDTH, eMetric, 2, MAX_COL_WIDTH));
                    if ( pDlg->Execute() == RET_OK )
                    {
                        long nVal = pDlg->GetInputValue();
                        tools::Long nVal = pDlg->GetInputValue();
                        pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, static_cast<sal_uInt16>(nVal) );

                        // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
@@ -837,7 +837,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                        ScGlobal::nLastColWidthExtra, STD_EXTRA_WIDTH, eMetric, 1, MAX_EXTRA_WIDTH));
                    if ( pDlg->Execute() == RET_OK )
                    {
                        long nVal = pDlg->GetInputValue();
                        tools::Long nVal = pDlg->GetInputValue();
                        pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, static_cast<sal_uInt16>(nVal) );
                        ScGlobal::nLastColWidthExtra = nVal;

diff --git a/sc/source/ui/view/colrowba.cxx b/sc/source/ui/view/colrowba.cxx
index 69e6118..f8d711e 100644
--- a/sc/source/ui/view/colrowba.cxx
+++ b/sc/source/ui/view/colrowba.cxx
@@ -31,7 +31,7 @@
#include <tabview.hxx>
#include <columnspanset.hxx>

static OUString lcl_MetricString( long nTwips, const OUString& rText )
static OUString lcl_MetricString( tools::Long nTwips, const OUString& rText )
{
    if ( nTwips <= 0 )
        return ScResId(STR_TIP_HIDE);
@@ -187,7 +187,7 @@ bool ScColBar::ResizeAllowed() const
    return !rViewData.HasEditView( rViewData.GetActivePart() );
}

void ScColBar::DrawInvert( long nDragPosP )
void ScColBar::DrawInvert( tools::Long nDragPosP )
{
    tools::Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 );
    PaintImmediately();
@@ -196,9 +196,9 @@ void ScColBar::DrawInvert( long nDragPosP )
    pTabView->GetViewData().GetView()->InvertVertical(meWhich,nDragPosP);
}

OUString ScColBar::GetDragHelp( long nVal )
OUString ScColBar::GetDragHelp( tools::Long nVal )
{
    long nTwips = static_cast<long>( nVal / pTabView->GetViewData().GetPPTX() );
    tools::Long nTwips = static_cast<tools::Long>( nVal / pTabView->GetViewData().GetPPTX() );
    return lcl_MetricString( nTwips, ScResId(STR_TIP_WIDTH) );
}

@@ -347,7 +347,7 @@ bool ScRowBar::ResizeAllowed() const
    return !rViewData.HasEditView( rViewData.GetActivePart() );
}

void ScRowBar::DrawInvert( long nDragPosP )
void ScRowBar::DrawInvert( tools::Long nDragPosP )
{
    tools::Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 );
    PaintImmediately();
@@ -356,9 +356,9 @@ void ScRowBar::DrawInvert( long nDragPosP )
    pTabView->GetViewData().GetView()->InvertHorizontal(meWhich,nDragPosP);
}

OUString ScRowBar::GetDragHelp( long nVal )
OUString ScRowBar::GetDragHelp( tools::Long nVal )
{
    long nTwips = static_cast<long>( nVal / pTabView->GetViewData().GetPPTY() );
    tools::Long nTwips = static_cast<tools::Long>( nVal / pTabView->GetViewData().GetPPTY() );
    return lcl_MetricString( nTwips, ScResId(STR_TIP_HEIGHT) );
}

diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index 2226311..55b308d 100644
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -739,16 +739,16 @@ void ScDBFunc::RecalcPivotTable()
        ErrorMessage(STR_PIVOT_NOTFOUND);
}

void ScDBFunc::GetSelectedMemberList(ScDPUniqueStringSet& rEntries, long& rDimension)
void ScDBFunc::GetSelectedMemberList(ScDPUniqueStringSet& rEntries, tools::Long& rDimension)
{
    ScDPObject* pDPObj = GetViewData().GetDocument().GetDPAtCursor( GetViewData().GetCurX(),
                                        GetViewData().GetCurY(), GetViewData().GetTabNo() );
    if ( !pDPObj )
        return;

    long nStartDimension = -1;
    long nStartHierarchy = -1;
    long nStartLevel     = -1;
    tools::Long nStartDimension = -1;
    tools::Long nStartHierarchy = -1;
    tools::Long nStartLevel     = -1;

    ScRangeListRef xRanges;
    GetViewData().GetMultiArea( xRanges );         // incl. cursor if nothing is selected
@@ -816,7 +816,7 @@ bool ScDBFunc::HasSelectionForDateGroup( ScDPNumGroupInfo& rOldInfo, sal_Int32& 
    if ( pDPObj )
    {
        ScDPUniqueStringSet aEntries;
        long nSelectDimension = -1;
        tools::Long nSelectDimension = -1;
        GetSelectedMemberList( aEntries, nSelectDimension );

        if (!aEntries.empty())
@@ -929,7 +929,7 @@ bool ScDBFunc::HasSelectionForNumGroup( ScDPNumGroupInfo& rOldInfo )
    if ( pDPObj )
    {
        ScDPUniqueStringSet aEntries;
        long nSelectDimension = -1;
        tools::Long nSelectDimension = -1;
        GetSelectedMemberList( aEntries, nSelectDimension );

        if (!aEntries.empty())
@@ -990,7 +990,7 @@ void ScDBFunc::DateGroupDataPilot( const ScDPNumGroupInfo& rInfo, sal_Int32 nPar
        return;

    ScDPUniqueStringSet aEntries;
    long nSelectDimension = -1;
    tools::Long nSelectDimension = -1;
    GetSelectedMemberList( aEntries, nSelectDimension );

    if (aEntries.empty())
@@ -1088,7 +1088,7 @@ void ScDBFunc::NumGroupDataPilot( const ScDPNumGroupInfo& rInfo )
        return;

    ScDPUniqueStringSet aEntries;
    long nSelectDimension = -1;
    tools::Long nSelectDimension = -1;
    GetSelectedMemberList( aEntries, nSelectDimension );

    if (aEntries.empty())
@@ -1130,7 +1130,7 @@ void ScDBFunc::GroupDataPilot()
        return;

    ScDPUniqueStringSet aEntries;
    long nSelectDimension = -1;
    tools::Long nSelectDimension = -1;
    GetSelectedMemberList( aEntries, nSelectDimension );

    if (aEntries.empty())
@@ -1195,8 +1195,8 @@ void ScDBFunc::GroupDataPilot()
            //! Also do this when removing groups?
            //! Handle this case dynamically with automatic groups?

            long nGroupCount = pBaseGroupDim->GetGroupCount();
            for ( long nGroup = 0; nGroup < nGroupCount; nGroup++ )
            tools::Long nGroupCount = pBaseGroupDim->GetGroupCount();
            for ( tools::Long nGroup = 0; nGroup < nGroupCount; nGroup++ )
            {
                const ScDPSaveGroupItem& rBaseGroup = pBaseGroupDim->GetGroupByIndex( nGroup );

@@ -1265,7 +1265,7 @@ void ScDBFunc::UngroupDataPilot()
        return;

    ScDPUniqueStringSet aEntries;
    long nSelectDimension = -1;
    tools::Long nSelectDimension = -1;
    GetSelectedMemberList( aEntries, nSelectDimension );

    if (aEntries.empty())
@@ -1402,7 +1402,7 @@ void ScDBFunc::DataPilotInput( const ScAddress& rPos, const OUString& rString )
    bool bNeedReloadGroups = false;

    DataPilotFieldOrientation nOrient = DataPilotFieldOrientation_HIDDEN;
    long nField = pDPObj->GetHeaderDim( rPos, nOrient );
    tools::Long nField = pDPObj->GetHeaderDim( rPos, nOrient );
    if ( nField >= 0 )
    {
        // changing a field title
@@ -1534,7 +1534,7 @@ void ScDBFunc::DataPilotInput( const ScAddress& rPos, const OUString& rString )
            else if (aPosData.Dimension >= 0 && !aPosData.MemberName.isEmpty())
            {
                bool bDataLayout = false;
                OUString aDimName = pDPObj->GetDimName(static_cast<long>(aPosData.Dimension), bDataLayout);
                OUString aDimName = pDPObj->GetDimName(static_cast<tools::Long>(aPosData.Dimension), bDataLayout);
                if (bDataLayout)
                {
                    // data dimension
@@ -1688,7 +1688,7 @@ struct ScOUStringCollate

}

void ScDBFunc::DataPilotSort(ScDPObject* pDPObj, long nDimIndex, bool bAscending, const sal_uInt16* pUserListId)
void ScDBFunc::DataPilotSort(ScDPObject* pDPObj, tools::Long nDimIndex, bool bAscending, const sal_uInt16* pUserListId)
{
    if (!pDPObj)
        return;
@@ -1913,7 +1913,7 @@ bool ScDBFunc::HasSelectionForDrillDown( css::sheet::DataPilotFieldOrientation& 
    if ( pDPObj )
    {
        ScDPUniqueStringSet aEntries;
        long nSelectDimension = -1;
        tools::Long nSelectDimension = -1;
        GetSelectedMemberList( aEntries, nSelectDimension );

        if (!aEntries.empty())
@@ -1949,7 +1949,7 @@ void ScDBFunc::SetDataPilotDetails(bool bShow, const OUString* pNewDimensionName
        return;

    ScDPUniqueStringSet aEntries;
    long nSelectDimension = -1;
    tools::Long nSelectDimension = -1;
    GetSelectedMemberList( aEntries, nSelectDimension );

    if (aEntries.empty())
@@ -1979,7 +1979,7 @@ void ScDBFunc::SetDataPilotDetails(bool bShow, const OUString* pNewDimensionName
        css::sheet::DataPilotFieldOrientation nOrientation = pDim->GetOrientation();
        pNewDim->SetOrientation( nOrientation );

        long nPosition = LONG_MAX;
        tools::Long nPosition = LONG_MAX;
        aData.SetPosition( pNewDim, nPosition );

        ScDPSaveDimension* pDataLayout = aData.GetDataLayoutDimension();
diff --git a/sc/source/ui/view/drawutil.cxx b/sc/source/ui/view/drawutil.cxx
index 52f8c7a..3a6f145 100644
--- a/sc/source/ui/view/drawutil.cxx
+++ b/sc/source/ui/view/drawutil.cxx
@@ -31,14 +31,14 @@ void ScDrawUtil::CalcScale( const ScDocument& rDoc, SCTAB nTab,
                            double nPPTX, double nPPTY,
                            Fraction& rScaleX, Fraction& rScaleY )
{
    long nPixelX = 0;
    long nTwipsX = 0;
    long nPixelY = 0;
    long nTwipsY = 0;
    tools::Long nPixelX = 0;
    tools::Long nTwipsX = 0;
    tools::Long nPixelY = 0;
    tools::Long nTwipsY = 0;
    for (SCCOL i=nStartCol; i<nEndCol; i++)
    {
        sal_uInt16 nWidth = rDoc.GetColWidth(i,nTab);
        nTwipsX += static_cast<long>(nWidth);
        nTwipsX += static_cast<tools::Long>(nWidth);
        nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
    }

@@ -52,7 +52,7 @@ void ScDrawUtil::CalcScale( const ScDocument& rDoc, SCTAB nTab,
        }

        sal_uInt16 nHeight = rDoc.GetRowHeight(nRow, nTab);
        nTwipsY += static_cast<long>(nHeight);
        nTwipsY += static_cast<tools::Long>(nHeight);
        nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
    }

diff --git a/sc/source/ui/view/drawvie4.cxx b/sc/source/ui/view/drawvie4.cxx
index 3584e27..bce240b1 100644
--- a/sc/source/ui/view/drawvie4.cxx
+++ b/sc/source/ui/view/drawvie4.cxx
@@ -434,7 +434,7 @@ void ScDrawView::SetMarkedOriginalSize()
    std::unique_ptr<SdrUndoGroup> pUndoGroup(new SdrUndoGroup(*GetModel()));

    const SdrMarkList& rMarkList = GetMarkedObjectList();
    long nDone = 0;
    tools::Long nDone = 0;
    const size_t nCount = rMarkList.GetMarkCount();
    for (size_t i=0; i<nCount; ++i)
    {
@@ -553,10 +553,10 @@ void ScDrawView::FitToCellSize()
    // For graphic objects, we want to keep the aspect ratio
    if (pObj->shouldKeepAspectRatio())
    {
        long nWidth = aGraphicRect.GetWidth();
        tools::Long nWidth = aGraphicRect.GetWidth();
        assert(nWidth && "div-by-zero");
        double fScaleX = static_cast<double>(aCellRect.GetWidth()) / static_cast<double>(nWidth);
        long nHeight = aGraphicRect.GetHeight();
        tools::Long nHeight = aGraphicRect.GetHeight();
        assert(nHeight && "div-by-zero");
        double fScaleY = static_cast<double>(aCellRect.GetHeight()) / static_cast<double>(nHeight);
        double fScaleMin = std::min(fScaleX, fScaleY);
diff --git a/sc/source/ui/view/gridmerg.cxx b/sc/source/ui/view/gridmerg.cxx
index a079372..a21be85 100644
--- a/sc/source/ui/view/gridmerg.cxx
+++ b/sc/source/ui/view/gridmerg.cxx
@@ -28,7 +28,7 @@
#define PAGEBREAK_LINE_DASH_LEN_PIXEL 5
#define PAGEBREAK_LINE_DASH_COUNT 1

ScGridMerger::ScGridMerger( OutputDevice* pOutDev, long nOnePixelX, long nOnePixelY )
ScGridMerger::ScGridMerger( OutputDevice* pOutDev, tools::Long nOnePixelX, tools::Long nOnePixelY )
    : pDev(pOutDev)
    , nOneX(nOnePixelX)
    , nOneY(nOnePixelY)
@@ -50,7 +50,7 @@ ScGridMerger::~ScGridMerger()
    Flush();
}

void ScGridMerger::AddLine( long nStart, long nEnd, long nPos )
void ScGridMerger::AddLine( tools::Long nStart, tools::Long nEnd, tools::Long nPos )
{
    if ( nCount )
    {
@@ -93,7 +93,7 @@ void ScGridMerger::AddLine( long nStart, long nEnd, long nPos )
    }
}

void ScGridMerger::AddHorLine(bool bWorksInPixels, long nX1, long nX2, long nY, bool bDashed)
void ScGridMerger::AddHorLine(bool bWorksInPixels, tools::Long nX1, tools::Long nX2, tools::Long nY, bool bDashed)
{
    if ( bWorksInPixels )
    {
@@ -137,7 +137,7 @@ void ScGridMerger::AddHorLine(bool bWorksInPixels, long nX1, long nX2, long nY, 
        pDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
}

void ScGridMerger::AddVerLine(bool bWorksInPixels, long nX, long nY1, long nY2, bool bDashed)
void ScGridMerger::AddVerLine(bool bWorksInPixels, tools::Long nX, tools::Long nY1, tools::Long nY2, bool bDashed)
{
    if (bWorksInPixels)
    {
@@ -192,7 +192,7 @@ void ScGridMerger::Flush()
            pDev->DrawLine( Point( nVarStart, nFixStart ), Point( nVarStart, nFixEnd ) );
        else
        {
            long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
            tools::Long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
            if ( nVarDiff < 0 )
            {
                //  nVarDiff is negative in RTL layout mode
@@ -200,7 +200,7 @@ void ScGridMerger::Flush()
                //  (nVarStart / nVarDiff can be modified, aren't used after Flush)

                nVarDiff = -nVarDiff;
                long nTemp = nVarStart;
                tools::Long nTemp = nVarStart;
                nVarStart = nVarEnd;
                nVarEnd = nTemp;
            }
@@ -215,7 +215,7 @@ void ScGridMerger::Flush()
            pDev->DrawLine( Point( nFixStart, nVarStart ), Point( nFixEnd, nVarStart ) );
        else
        {
            long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
            tools::Long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
            pDev->DrawGrid( tools::Rectangle( nFixStart, nVarStart, nFixEnd, nVarEnd ),
                            Size( nFixEnd - nFixStart, nVarDiff ),
                            DrawGridFlags::HorzLines );
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 291e210..5c45e2e 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -648,8 +648,8 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow)
    pData->maPos = ScAddress(nCol, nRow, nTab);

    Point aPos = mrViewData.GetScrPos(nCol, nRow, eWhich);
    long nSizeX  = 0;
    long nSizeY  = 0;
    tools::Long nSizeX  = 0;
    tools::Long nSizeY  = 0;
    mrViewData.GetMergeSizePixel(nCol, nRow, nSizeX, nSizeY);
    if (bLOKActive)
    {
@@ -897,7 +897,7 @@ void getCellGeometry(Point& rScrPos, Size& rScrSize, const ScViewData& rViewData
    rScrPos = rViewData.GetScrPos(nCol, nRow, eWhich);

    // Get the screen size of the cell.
    long nSizeX, nSizeY;
    tools::Long nSizeX, nSizeY;
    rViewData.GetMergeSizePixel(nCol, nRow, nSizeX, nSizeY);
    rScrSize = Size(nSizeX-1, nSizeY-1);
}
@@ -941,7 +941,7 @@ void ScGridWindow::ShowFilterMenu(const tools::Rectangle& rCellRect, bool bLayou
    // minimum width in pixel
    if (comphelper::LibreOfficeKit::isActive())
    {
        const long nMinLOKWinWidth = static_cast<long>(1.3 * STD_COL_WIDTH / TWIPS_PER_PIXEL);
        const tools::Long nMinLOKWinWidth = static_cast<tools::Long>(1.3 * STD_COL_WIDTH / TWIPS_PER_PIXEL);
        if (nSizeX < nMinLOKWinWidth)
            nSizeX = nMinLOKWinWidth;
    }
@@ -968,8 +968,8 @@ void ScGridWindow::ShowFilterMenu(const tools::Rectangle& rCellRect, bool bLayou
    if (!bLayoutRTL && aSize.Width() > nSizeX)
    {
        //  move popup position
        long nDiff = aSize.Width() - nSizeX;
        long nNewX = aCellRect.Left() - nDiff;
        tools::Long nDiff = aSize.Width() - nSizeX;
        tools::Long nNewX = aCellRect.Left() - nDiff;
        if ( nNewX < 0 )
            nNewX = 0;
        aCellRect.SetLeft( nNewX );
@@ -1003,8 +1003,8 @@ void ScGridWindow::DoScenarioMenu( const ScRange& rScenRange )
    SCTAB nTab = mrViewData.GetTabNo();
    bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );

    long nSizeX  = 0;
    long nSizeY  = 0;
    tools::Long nSizeX  = 0;
    tools::Long nSizeY  = 0;
    mrViewData.GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
    // The button height should not use the merged cell height, should still use single row height
    nSizeY = ScViewData::ToPixel(rDoc.GetRowHeight(nRow, nTab), mrViewData.GetPPTY());
@@ -1081,8 +1081,8 @@ void ScGridWindow::LaunchDataSelectMenu( SCCOL nCol, SCROW nRow )
    SCTAB nTab = mrViewData.GetTabNo();
    bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );

    long nSizeX  = 0;
    long nSizeY  = 0;
    tools::Long nSizeX  = 0;
    tools::Long nSizeY  = 0;
    mrViewData.GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
    Point aPos = mrViewData.GetScrPos( nCol, nRow, eWhich );
    bool bLOKActive = comphelper::LibreOfficeKit::isActive();
@@ -1467,7 +1467,7 @@ bool ScGridWindow::IsCellCoveredByText(SCCOL nPosX, SCROW nPosY, SCTAB nTab, SCC
    SCROW nTextEndY;

    // test the rightmost position of the text bounding box
    long nMiddle = (aRect.Top() + aRect.Bottom()) / 2;
    tools::Long nMiddle = (aRect.Top() + aRect.Bottom()) / 2;
    mrViewData.GetPosFromPixel(aRect.Right(), nMiddle, eWhich, nTextEndX, nTextEndY);
    if (nTextEndX >= nPosX)
    {
@@ -3005,8 +3005,8 @@ void ScGridWindow::Command( const CommandEvent& rCEvt )
        SCCOL nCurX = mrViewData.GetCurX();
        SCROW nCurY = mrViewData.GetCurY();
        aMenuPos = mrViewData.GetScrPos( nCurX, nCurY, eWhich, true );
        long nSizeXPix;
        long nSizeYPix;
        tools::Long nSizeXPix;
        tools::Long nSizeYPix;
        mrViewData.GetMergeSizePixel( nCurX, nCurY, nSizeXPix, nSizeYPix );
        // fdo#55432 take the correct position for RTL sheet
        aMenuPos.AdjustX(bLayoutIsRTL ? -nSizeXPix : nSizeXPix );
@@ -3066,7 +3066,7 @@ void ScGridWindow::SelectForContextMenu( const Point& rPosPixel, SCCOL nCellX, S
            if ( pEditEngine->IsVertical() )            // have to manually transform position
            {
                aTextPos -= aOutputArea.TopRight();
                long nTemp = -aTextPos.X();
                tools::Long nTemp = -aTextPos.X();
                aTextPos.setX( aTextPos.Y() );
                aTextPos.setY( nTemp );
            }
@@ -3115,7 +3115,7 @@ void ScGridWindow::SelectForContextMenu( const Point& rPosPixel, SCCOL nCellX, S
            if ( pOutliner->IsVertical() )              // have to manually transform position
            {
                aTextPos -= aOutputArea.TopRight();
                long nTemp = -aTextPos.X();
                tools::Long nTemp = -aTextPos.X();
                aTextPos.setX( aTextPos.Y() );
                aTextPos.setY( nTemp );
            }
@@ -3609,8 +3609,8 @@ sal_Int8 ScGridWindow::AcceptPrivateDrop( const AcceptDropEvent& rEvt )
        {
            if ( &rThisDoc == pSourceDoc && nTab == aSourceRange.aStart.Tab() )
            {
                long nDeltaX = labs( static_cast< long >( nNewDragX - nSourceStartX ) );
                long nDeltaY = labs( static_cast< long >( nNewDragY - nSourceStartY ) );
                tools::Long nDeltaX = labs( static_cast< tools::Long >( nNewDragX - nSourceStartX ) );
                tools::Long nDeltaY = labs( static_cast< tools::Long >( nNewDragY - nSourceStartY ) );
                if ( nDeltaX <= nDeltaY )
                {
                    eDragInsertMode = INS_CELLSDOWN;
@@ -3637,7 +3637,7 @@ sal_Int8 ScGridWindow::AcceptPrivateDrop( const AcceptDropEvent& rEvt )
            }
            else
            {
                if ( static_cast< long >( nSizeX ) >= static_cast< long >( nSizeY ) )
                if ( static_cast< tools::Long >( nSizeX ) >= static_cast< tools::Long >( nSizeY ) )
                {
                    eDragInsertMode = INS_CELLSDOWN;

@@ -4523,7 +4523,7 @@ void ScGridWindow::UpdateEditViewPos()
    if (bHide)
    {
        tools::Rectangle aRect = pView->GetOutputArea();
        long nHeight = aRect.Bottom() - aRect.Top();
        tools::Long nHeight = aRect.Bottom() - aRect.Top();
        aRect.SetTop( PixelToLogic(GetOutputSizePixel(), mrViewData.GetLogicMode()).
                        Height() * 2 );
        aRect.SetBottom( aRect.Top() + nHeight );
@@ -4555,7 +4555,7 @@ void ScGridWindow::UpdateEditViewPos()
    }
}

void ScGridWindow::ScrollPixel( long nDifX, long nDifY )
void ScGridWindow::ScrollPixel( tools::Long nDifX, tools::Long nDifY )
{
    ClickExtern();
    HideNoteMarker();
@@ -4630,17 +4630,17 @@ void ScGridWindow::UpdateFormulas(SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2)
    }

    Point aScrPos = mrViewData.GetScrPos( nX1, nY1, eWhich );
    long nMirrorWidth = GetSizePixel().Width();
    tools::Long nMirrorWidth = GetSizePixel().Width();
    bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
    if ( bLayoutRTL )
    {
        long nEndPixel = mrViewData.GetScrPos( nX2+1, nPosY, eWhich ).X();
        tools::Long nEndPixel = mrViewData.GetScrPos( nX2+1, nPosY, eWhich ).X();
        nMirrorWidth = aScrPos.X() - nEndPixel;
        aScrPos.setX( nEndPixel + 1 );
    }

    long nScrX = aScrPos.X();
    long nScrY = aScrPos.Y();
    tools::Long nScrX = aScrPos.X();
    tools::Long nScrY = aScrPos.Y();

    double nPPTX = mrViewData.GetPPTX();
    double nPPTY = mrViewData.GetPPTY();
@@ -4797,7 +4797,7 @@ bool ScGridWindow::HitRangeFinder( const Point& rMouse, RfCorner& rCorner,
            ScDocument& rDoc = mrViewData.GetDocument();
            SCTAB nTab = mrViewData.GetTabNo();
            bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
            long nLayoutSign = bLayoutRTL ? -1 : 1;
            tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

            SCCOL nPosX;
            SCROW nPosY;
@@ -4807,8 +4807,8 @@ bool ScGridWindow::HitRangeFinder( const Point& rMouse, RfCorner& rCorner,

            Point aCellStart = mrViewData.GetScrPos( nPosX, nPosY, eWhich, true );
            Point aCellEnd = aCellStart;
            long nSizeXPix;
            long nSizeYPix;
            tools::Long nSizeXPix;
            tools::Long nSizeYPix;
            mrViewData.GetMergeSizePixel( nPosX, nPosY, nSizeXPix, nSizeYPix );

            aCellEnd.AdjustX(nSizeXPix * nLayoutSign );
@@ -5114,17 +5114,17 @@ void ScGridWindow::RFMouseMove( const MouseEvent& rMEvt, bool bUp )
    else
    {
        ScDocument& rDoc = mrViewData.GetDocument();
        long nStartX = nPosX - nRFAddX;
        tools::Long nStartX = nPosX - nRFAddX;
        if ( nStartX < 0 ) nStartX = 0;
        long nStartY = nPosY - nRFAddY;
        tools::Long nStartY = nPosY - nRFAddY;
        if ( nStartY < 0 ) nStartY = 0;
        long nEndX = nStartX + aOld.aEnd.Col() - aOld.aStart.Col();
        tools::Long nEndX = nStartX + aOld.aEnd.Col() - aOld.aStart.Col();
        if ( nEndX > rDoc.MaxCol() )
        {
            nStartX -= ( nEndX - rDoc.MaxRow() );
            nEndX = rDoc.MaxCol();
        }
        long nEndY = nStartY + aOld.aEnd.Row() - aOld.aStart.Row();
        tools::Long nEndY = nStartY + aOld.aEnd.Row() - aOld.aStart.Row();
        if ( nEndY > rDoc.MaxRow() )
        {
            nStartY -= ( nEndY - rDoc.MaxRow() );
@@ -5279,12 +5279,12 @@ bool ScGridWindow::GetEditUrl( const Point& rPos,

    MapMode aEditMode = mrViewData.GetLogicMode(eWhich);            // without draw scaling
    tools::Rectangle aLogicEdit = PixelToLogic( aEditRect, aEditMode );
    long nThisColLogic = aLogicEdit.Right() - aLogicEdit.Left() + 1;
    tools::Long nThisColLogic = aLogicEdit.Right() - aLogicEdit.Left() + 1;
    Size aPaperSize( 1000000, 1000000 );
    if (aCell.meType == CELLTYPE_FORMULA)
    {
        long nSizeX  = 0;
        long nSizeY  = 0;
        tools::Long nSizeX  = 0;
        tools::Long nSizeY  = 0;
        mrViewData.GetMergeSizePixel( nPosX, nPosY, nSizeX, nSizeY );
        aPaperSize = Size(nSizeX, nSizeY );
        aPaperSize = PixelToLogic(aPaperSize);
@@ -5323,10 +5323,10 @@ bool ScGridWindow::GetEditUrl( const Point& rPos,
            pEngine->SetTextCurrentDefaults(*pTextObj);
    }

    long nStartX = aLogicEdit.Left();
    tools::Long nStartX = aLogicEdit.Left();

    long nTextWidth = pEngine->CalcTextWidth();
    long nTextHeight = pEngine->GetTextHeight();
    tools::Long nTextWidth = pEngine->CalcTextWidth();
    tools::Long nTextHeight = pEngine->GetTextHeight();
    if ( nTextWidth < nThisColLogic )
    {
        if (eHorJust == SvxCellHorJustify::Right)
@@ -5406,7 +5406,7 @@ bool ScGridWindow::IsSpellErrorAtPos( const Point& rPos, SCCOL nCol1, SCROW nRow
    else
        pEngine->SetTextCurrentDefaults(aCell.mpString->getString());

    long nTextWidth = static_cast<long>(pEngine->CalcTextWidth());
    tools::Long nTextWidth = static_cast<tools::Long>(pEngine->CalcTextWidth());

    MapMode aEditMode = mrViewData.GetLogicMode(eWhich);
    tools::Rectangle aLogicEdit = PixelToLogic(aEditRect, aEditMode);
@@ -5436,11 +5436,11 @@ bool ScGridWindow::HasScenarioButton( const Point& rPosPixel, ScRange& rScenRang
        bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );

        Size aButSize = mrViewData.GetScenButSize();
        long nBWidth  = aButSize.Width();
        tools::Long nBWidth  = aButSize.Width();
        if (!nBWidth)
            return false;                   // No Button drawn yet -> there is none
        long nBHeight = aButSize.Height();
        long nHSpace  = static_cast<long>( SC_SCENARIO_HSPACE * mrViewData.GetPPTX() );
        tools::Long nBHeight = aButSize.Height();
        tools::Long nHSpace  = static_cast<tools::Long>( SC_SCENARIO_HSPACE * mrViewData.GetPPTX() );

        //! cache the Ranges in Table!!!!

@@ -5926,8 +5926,8 @@ void ScGridWindow::UpdateCopySourceOverlay()
        Point aClipStartScrPos = mrViewData.GetScrPos( nClipStartX, nClipStartY, eWhich );
        Point aClipEndScrPos   = mrViewData.GetScrPos( nClipEndX + 1, nClipEndY + 1, eWhich );
        aClipStartScrPos -= Point(1, 1);
        long nSizeXPix = aClipEndScrPos.X() - aClipStartScrPos.X();
        long nSizeYPix = aClipEndScrPos.Y() - aClipStartScrPos.Y();
        tools::Long nSizeXPix = aClipEndScrPos.X() - aClipStartScrPos.X();
        tools::Long nSizeYPix = aClipEndScrPos.Y() - aClipStartScrPos.Y();

        tools::Rectangle aRect( aClipStartScrPos, Size(nSizeXPix, nSizeYPix) );

@@ -6206,8 +6206,8 @@ void ScGridWindow::UpdateCursorOverlay()
        // in the tiled rendering case, don't limit to the screen size
        if (bMaybeVisible || comphelper::LibreOfficeKit::isActive())
        {
            long nSizeXPix;
            long nSizeYPix;
            tools::Long nSizeXPix;
            tools::Long nSizeYPix;
            mrViewData.GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );

            if (bLayoutRTL)
@@ -6218,7 +6218,7 @@ void ScGridWindow::UpdateCursorOverlay()

            float fScaleFactor = GetDPIScaleFactor();

            long aCursorWidth = 1 * fScaleFactor;
            tools::Long aCursorWidth = 1 * fScaleFactor;

            tools::Rectangle aLeft = aRect;
            aLeft.AdjustTop( -aCursorWidth );
@@ -6431,8 +6431,8 @@ void ScGridWindow::UpdateAutoFillOverlay()
    Size aFillHandleSize(6 * fScaleFactor, 6 * fScaleFactor);

    Point aFillPos = mrViewData.GetScrPos( nX, nY, eWhich, true );
    long nSizeXPix;
    long nSizeYPix;
    tools::Long nSizeXPix;
    tools::Long nSizeYPix;
    mrViewData.GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );

    if (bLayoutRTL)
@@ -6519,15 +6519,15 @@ void ScGridWindow::UpdateDragRectOverlay()

        Point aScrPos( mrViewData.GetScrPos( nX1, nY1, eWhich ) );

        long nSizeXPix=0;
        long nSizeYPix=0;
        tools::Long nSizeXPix=0;
        tools::Long nSizeYPix=0;
        ScDocument& rDoc = mrViewData.GetDocument();
        double nPPTX = mrViewData.GetPPTX();
        double nPPTY = mrViewData.GetPPTY();
        SCCOLROW i;

        bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
        long nLayoutSign = bLayoutRTL ? -1 : 1;
        tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

        if (rDoc.ValidCol(nX2) && nX2>=nX1)
            for (i=nX1; i<=nX2; i++)
diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx
index 90c3e08..0d1ef7e 100644
--- a/sc/source/ui/view/gridwin2.cxx
+++ b/sc/source/ui/view/gridwin2.cxx
@@ -65,7 +65,7 @@ DataPilotFieldOrientation ScGridWindow::GetDPFieldOrientation( SCCOL nCol, SCROW
    if (nCol > 0)
    {
        // look for the dimension header left of the drop-down arrow
        long nField = pDPObj->GetHeaderDim( ScAddress( nCol-1, nRow, nTab ), nOrient );
        tools::Long nField = pDPObj->GetHeaderDim( ScAddress( nCol-1, nRow, nTab ), nOrient );
        if ( nField >= 0 && nOrient == DataPilotFieldOrientation_PAGE )
        {
            bool bIsDataLayout = false;
@@ -78,7 +78,7 @@ DataPilotFieldOrientation ScGridWindow::GetDPFieldOrientation( SCCOL nCol, SCROW
    nOrient = DataPilotFieldOrientation_HIDDEN;

    // Now, check for row/column field.
    long nField = pDPObj->GetHeaderDim(ScAddress(nCol, nRow, nTab), nOrient);
    tools::Long nField = pDPObj->GetHeaderDim(ScAddress(nCol, nRow, nTab), nOrient);
    if (nField >= 0 && (nOrient == DataPilotFieldOrientation_COLUMN || nOrient == DataPilotFieldOrientation_ROW) )
    {
        bool bIsDataLayout = false;
@@ -113,7 +113,7 @@ bool ScGridWindow::DoAutoFilterButton( SCCOL nCol, SCROW nRow, const MouseEvent&
    if ( bLayoutRTL )
        aDiffPix.setX( -aDiffPix.X() );

    long nSizeX, nSizeY;
    tools::Long nSizeX, nSizeY;
    mrViewData.GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
    // The button height should not use the merged cell height, should still use single row height
    nSizeY = ScViewData::ToPixel(rDoc.GetRowHeight(nRow, nTab), mrViewData.GetPPTY());
@@ -161,7 +161,7 @@ void ScGridWindow::DoPushPivotButton( SCCOL nCol, SCROW nRow, const MouseEvent& 
            // For page field selection cell, the real field position is to the left.
            aDimPos.IncCol(-1);

        long nField = pDPObj->GetHeaderDim(aDimPos, nOrient);
        tools::Long nField = pDPObj->GetHeaderDim(aDimPos, nOrient);
        if ( nField >= 0 )
        {
            bDPMouse   = false;
@@ -273,7 +273,7 @@ void ScGridWindow::DPTestMouse( const MouseEvent& rMEvt, bool bMove )

    tools::Rectangle aPosRect;
    DataPilotFieldOrientation nOrient;
    long nDimPos;
    tools::Long nDimPos;
    bool bHasRange = pDragDPObj->GetHeaderDrag( aPos, bMouseLeft, bMouseTop, nDPField,
                                                aPosRect, nOrient, nDimPos );
    UpdateDragRect( bHasRange && bMove, aPosRect );
@@ -346,7 +346,7 @@ bool ScGridWindow::DPTestFieldPopupArrow(

    // Get the geometry of the cell.
    Point aScrPos = mrViewData.GetScrPos(rPos.Col(), rPos.Row(), eWhich);
    long nSizeX, nSizeY;
    tools::Long nSizeX, nSizeY;
    mrViewData.GetMergeSizePixel(rPos.Col(), rPos.Row(), nSizeX, nSizeY);
    Size aScrSize(nSizeX-1, nSizeY-1);

@@ -374,7 +374,7 @@ struct DPFieldPopupData : public ScCheckListMenuControl::ExtendedData
{
    ScDPLabelData   maLabels;
    ScDPObject*     mpDPObj;
    long            mnDim;
    tools::Long            mnDim;
};

class DPFieldPopupOKAction : public ScCheckListMenuControl::Action
@@ -396,7 +396,7 @@ class PopupSortAction : public ScCheckListMenuControl::Action
public:
    enum SortType { ASCENDING, DESCENDING, CUSTOM };

    explicit PopupSortAction(ScDPObject* pDPObject, long nDimIndex, SortType eType,
    explicit PopupSortAction(ScDPObject* pDPObject, tools::Long nDimIndex, SortType eType,
                             sal_uInt16 nUserListIndex, ScTabViewShell* pViewShell)
        : mpDPObject(pDPObject)
        , mnDimIndex(nDimIndex)
@@ -425,7 +425,7 @@ public:

private:
    ScDPObject*     mpDPObject;
    long            mnDimIndex;
    tools::Long            mnDimIndex;
    SortType        meType;
    sal_uInt16      mnUserListIndex;
    ScTabViewShell* mpViewShell;
@@ -437,13 +437,13 @@ void ScGridWindow::DPLaunchFieldPopupMenu(const Point& rScreenPosition, const Si
                                          const ScAddress& rAddress, ScDPObject* pDPObject)
{
    DataPilotFieldOrientation nOrient;
    long nDimIndex = pDPObject->GetHeaderDim(rAddress, nOrient);
    tools::Long nDimIndex = pDPObject->GetHeaderDim(rAddress, nOrient);

    DPLaunchFieldPopupMenu(rScreenPosition, rScreenSize, nDimIndex, pDPObject);
}

void ScGridWindow::DPLaunchFieldPopupMenu(const Point& rScrPos, const Size& rScrSize,
                                          long nDimIndex, ScDPObject* pDPObj)
                                          tools::Long nDimIndex, ScDPObject* pDPObj)
{
    std::unique_ptr<DPFieldPopupData> pDPData(new DPFieldPopupData);
    pDPData->mnDim = nDimIndex;
@@ -704,8 +704,8 @@ sal_uInt16 ScGridWindow::HitPageBreak( const Point& rMouse, ScRange* pSource,
        SCCOL nHitX = 0;
        SCROW nHitY = 0;

        long nMouseX = rMouse.X();
        long nMouseY = rMouse.Y();
        tools::Long nMouseX = rMouse.X();
        tools::Long nMouseY = rMouse.Y();
        SCCOL nPosX;
        SCROW nPosY;
        mrViewData.GetPosFromPixel( nMouseX, nMouseY, eWhich, nPosX, nPosY );
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 724d840..cc3fa9c 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -103,8 +103,8 @@ static void lcl_DrawOneFrame( vcl::RenderContext* pDev, const tools::Rectangle& 
    lcl_LimitRect( aInner, aVisible );

    tools::Rectangle aOuter = aInner;
    long nHor = static_cast<long>( SC_SCENARIO_HSPACE * nPPTX );
    long nVer = static_cast<long>( SC_SCENARIO_VSPACE * nPPTY );
    tools::Long nHor = static_cast<tools::Long>( SC_SCENARIO_HSPACE * nPPTX );
    tools::Long nVer = static_cast<tools::Long>( SC_SCENARIO_VSPACE * nPPTY );
    aOuter.AdjustLeft( -nHor );
    aOuter.AdjustRight(nHor );
    aOuter.AdjustTop( -nVer );
@@ -137,18 +137,18 @@ static void lcl_DrawOneFrame( vcl::RenderContext* pDev, const tools::Rectangle& 
    pDev->DrawRect( tools::Rectangle( aInner.Right(), aOuter.Top(),    aOuter.Right(), aOuter.Bottom() ) );
    pDev->DrawRect( tools::Rectangle( aOuter.Left(),  aInner.Bottom(), aOuter.Right(), aOuter.Bottom() ) );

    long nButtonY = bTextBelow ? aInner.Bottom() : aOuter.Top();
    tools::Long nButtonY = bTextBelow ? aInner.Bottom() : aOuter.Top();

    ScDDComboBoxButton aComboButton(pDev);
    aComboButton.SetOptSizePixel();
    long nBWidth  = long(aComboButton.GetSizePixel().Width() * rZoomY);
    long nBHeight = nVer + aTextSize.Height() + 1;
    tools::Long nBWidth  = tools::Long(aComboButton.GetSizePixel().Width() * rZoomY);
    tools::Long nBHeight = nVer + aTextSize.Height() + 1;
    Size aButSize( nBWidth, nBHeight );
    long nButtonPos = bLayoutRTL ? aOuter.Left() : aOuter.Right()-nBWidth+1;
    tools::Long nButtonPos = bLayoutRTL ? aOuter.Left() : aOuter.Right()-nBWidth+1;
    aComboButton.Draw( Point(nButtonPos, nButtonY), aButSize );
    rButtonViewData.SetScenButSize( aButSize );

    long nTextStart = bLayoutRTL ? aInner.Right() - aTextSize.Width() + 1 : aInner.Left();
    tools::Long nTextStart = bLayoutRTL ? aInner.Right() - aTextSize.Width() + 1 : aInner.Left();

    bool bWasClip = false;
    vcl::Region aOldClip;
@@ -160,8 +160,8 @@ static void lcl_DrawOneFrame( vcl::RenderContext* pDev, const tools::Rectangle& 
            bWasClip = true;
            aOldClip = pDev->GetActiveClipRegion();
        }
        long nClipStartX = bLayoutRTL ? aOuter.Left() + nBWidth : aInner.Left();
        long nClipEndX = bLayoutRTL ? aInner.Right() : aOuter.Right() - nBWidth;
        tools::Long nClipStartX = bLayoutRTL ? aOuter.Left() + nBWidth : aInner.Left();
        tools::Long nClipEndX = bLayoutRTL ? aInner.Right() : aOuter.Right() - nBWidth;
        pDev->SetClipRegion( vcl::Region(tools::Rectangle( nClipStartX, nButtonY + nVer/2,
                            nClipEndX, nButtonY + nVer/2 + aTextSize.Height())) );
    }
@@ -208,7 +208,7 @@ static void lcl_DrawScenarioFrames( OutputDevice* pDev, ScViewData& rViewData, S
    aMarks.FillRangeListWithMarks( xRanges.get(), false );

    bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    for (size_t j = 0, n = xRanges->size(); j < n; ++j)
    {
@@ -401,12 +401,12 @@ void ScGridWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const tools::R
    if ( rDoc.IsLayoutRTL( nTab ) )
    {
        //  mirror and swap
        long nWidth = GetSizePixel().Width();
        tools::Long nWidth = GetSizePixel().Width();
        aMirroredPixel.SetLeft( nWidth - 1 - aPixRect.Right() );
        aMirroredPixel.SetRight( nWidth - 1 - aPixRect.Left() );
    }

    long nScrX = ScViewData::ToPixel( rDoc.GetColWidth( nX1, nTab ), nPPTX );
    tools::Long nScrX = ScViewData::ToPixel( rDoc.GetColWidth( nX1, nTab ), nPPTX );
    while ( nScrX <= aMirroredPixel.Left() && nX1 < rDoc.MaxCol() )
    {
        ++nX1;
@@ -419,7 +419,7 @@ void ScGridWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const tools::R
        nScrX += ScViewData::ToPixel( rDoc.GetColWidth( nX2, nTab ), nPPTX );
    }

    long nScrY = 0;
    tools::Long nScrY = 0;
    ScViewData::AddPixelsWhile( nScrY, aPixRect.Top(), nY1, rDoc.MaxRow(), nPPTY, &rDoc, nTab);
    SCROW nY2 = nY1;
    if (nScrY <= aPixRect.Bottom() && nY2 < rDoc.MaxRow())
@@ -484,17 +484,17 @@ void ScGridWindow::Draw( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, ScUpdateMod
    rDoc.ExtendHidden( nX1, nY1, nX2, nY2, nTab );

    Point aScrPos = mrViewData.GetScrPos( nX1, nY1, eWhich );
    long nMirrorWidth = GetSizePixel().Width();
    tools::Long nMirrorWidth = GetSizePixel().Width();
    bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
    if ( bLayoutRTL )
    {
        long nEndPixel = mrViewData.GetScrPos( nX2+1, maVisibleRange.mnRow1, eWhich ).X();
        tools::Long nEndPixel = mrViewData.GetScrPos( nX2+1, maVisibleRange.mnRow1, eWhich ).X();
        nMirrorWidth = aScrPos.X() - nEndPixel;
        aScrPos.setX( nEndPixel + 1 );
    }

    long nScrX = aScrPos.X();
    long nScrY = aScrPos.Y();
    tools::Long nScrX = aScrPos.X();
    tools::Long nScrY = aScrPos.Y();

    SCCOL nCurX = mrViewData.GetCurX();
    SCROW nCurY = mrViewData.GetCurY();
@@ -616,8 +616,8 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
    SCROW nY1 = aOutputData.nY1;
    SCCOL nX2 = aOutputData.nX2;
    SCROW nY2 = aOutputData.nY2;
    long nScrX = aOutputData.nScrX;
    long nScrY = aOutputData.nScrY;
    tools::Long nScrX = aOutputData.nScrX;
    tools::Long nScrY = aOutputData.nScrY;

    const svtools::ColorConfig& rColorCfg = pScMod->GetColorConfig();
    Color aGridColor( rColorCfg.GetColorValue( svtools::CALCGRID, false ).nColor );
@@ -1002,8 +1002,8 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
                        EditView* pOtherEditView = rOtherViewData.GetEditView(eOtherWhich);
                        if (pOtherEditView)
                        {
                            long nScreenX = aOutputData.nScrX;
                            long nScreenY = aOutputData.nScrY;
                            tools::Long nScreenX = aOutputData.nScrX;
                            tools::Long nScreenY = aOutputData.nScrY;

                            rDevice.SetLineColor();
                            rDevice.SetFillColor(pOtherEditView->GetBackgroundColor());
@@ -1011,7 +1011,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
                            Point aEnd = mrViewData.GetScrPos( nCol2+1, nRow2+1, eOtherWhich );

                            // don't overwrite grid
                            long nLayoutSign = bLayoutRTL ? -1 : 1;
                            tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
                            aEnd.AdjustX( -(2 * nLayoutSign) );
                            aEnd.AdjustY( -2 );

@@ -1088,7 +1088,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI
        Point aEnd = mrViewData.GetScrPos( nCol2+1, nRow2+1, eWhich );

        // don't overwrite grid
        long nLayoutSign = bLayoutRTL ? -1 : 1;
        tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
        aEnd.AdjustX( -(2 * nLayoutSign) );
        aEnd.AdjustY( -2 );

@@ -1222,7 +1222,7 @@ namespace
{
    template<typename IndexType>
    void lcl_getBoundingRowColumnforTile(ScViewData& rViewData,
            long nTileStartPosPx, long nTileEndPosPx,
            tools::Long nTileStartPosPx, tools::Long nTileEndPosPx,
            sal_Int32& nTopLeftTileOffset, sal_Int32& nTopLeftTileOrigin,
            sal_Int32& nTopLeftTileIndex, sal_Int32& nBottomRightTileIndex)
    {
@@ -1232,8 +1232,8 @@ namespace

        IndexType nStartIndex = -1;
        IndexType nEndIndex = -1;
        long nStartPosPx = 0;
        long nEndPosPx = 0;
        tools::Long nStartPosPx = 0;
        tools::Long nEndPosPx = 0;

        ScPositionHelper& rPositionHelper =
                bColumnHeader ? rViewData.GetLOKWidthHelper() : rViewData.GetLOKHeightHelper();
@@ -1312,7 +1312,7 @@ namespace
void ScGridWindow::PaintTile( VirtualDevice& rDevice,
                              int nOutputWidth, int nOutputHeight,
                              int nTilePosX, int nTilePosY,
                              long nTileWidth, long nTileHeight )
                              tools::Long nTileWidth, tools::Long nTileHeight )
{
    Fraction origZoomX = mrViewData.GetZoomX();
    Fraction origZoomY = mrViewData.GetZoomY();
@@ -1332,8 +1332,8 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
    // Similarly to Writer, we should set the mapmode once on the rDevice, and
    // not care about any zoom settings.

    Fraction aFracX(long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth);
    Fraction aFracY(long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight);
    Fraction aFracX(tools::Long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth);
    Fraction aFracY(tools::Long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight);

    const bool bChangeZoom = (aFracX !=  origZoomX || aFracY != origZoomY);

@@ -1716,18 +1716,18 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, 
                            Point aPageEnd = mrViewData.GetScrPos(
                                                    nPrEndX+1,nPrEndY+1, eWhich, true );

                            long nPageNo = rData.GetFirstPage();
                            tools::Long nPageNo = rData.GetFirstPage();
                            if ( rData.IsTopDown() )
                                nPageNo += static_cast<long>(nColPos)*nRowBreaks+nRowPos;
                                nPageNo += static_cast<tools::Long>(nColPos)*nRowBreaks+nRowPos;
                            else
                                nPageNo += static_cast<long>(nRowPos)*nColBreaks+nColPos;
                                nPageNo += static_cast<tools::Long>(nRowPos)*nColBreaks+nColPos;

                            OUString aThisPageStr = aPageStr.replaceFirst("%1", OUString::number(nPageNo));

                            if ( pEditEng )
                            {
                                //  find right font size with EditEngine
                                long nHeight = 100;
                                tools::Long nHeight = 100;
                                pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
                                pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
                                pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CTL ) );
@@ -1735,8 +1735,8 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, 
                                Size aSize100( pEditEng->CalcTextWidth(), pEditEng->GetTextHeight() );

                                //  40% of width or 60% of height
                                long nSizeX = 40 * ( aPageEnd.X() - aPageStart.X() ) / aSize100.Width();
                                long nSizeY = 60 * ( aPageEnd.Y() - aPageStart.Y() ) / aSize100.Height();
                                tools::Long nSizeX = 40 * ( aPageEnd.X() - aPageStart.X() ) / aSize100.Width();
                                tools::Long nSizeY = 60 * ( aPageEnd.Y() - aPageStart.Y() ) / aSize100.Height();
                                nHeight = std::min(nSizeX,nSizeY);
                                pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
                                pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
@@ -1756,8 +1756,8 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, 
                                Size aSize100(rRenderContext.GetTextWidth( aThisPageStr ), rRenderContext.GetTextHeight() );

                                //  40% of width or 60% of height
                                long nSizeX = 40 * ( aPageEnd.X() - aPageStart.X() ) / aSize100.Width();
                                long nSizeY = 60 * ( aPageEnd.Y() - aPageStart.Y() ) / aSize100.Height();
                                tools::Long nSizeX = 40 * ( aPageEnd.X() - aPageStart.X() ) / aSize100.Width();
                                tools::Long nSizeY = 60 * ( aPageEnd.Y() - aPageStart.Y() ) / aSize100.Height();
                                aFont.SetFontSize( Size( 0,std::min(nSizeX,nSizeY) ) );
                                rRenderContext.SetFont( aFont );

@@ -1863,8 +1863,8 @@ void ScGridWindow::DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& rTabInfo
                        }

                    bool bArrowState = bSimpleQuery && bColumnFound;
                    long    nSizeX;
                    long    nSizeY;
                    tools::Long    nSizeX;
                    tools::Long    nSizeY;
                    SCCOL nStartCol= nCol;
                    SCROW nStartRow = nRow;
                    //if address(nCol,nRow) is not the start pos of the merge area, the value of the nSizeX will be incorrect, it will be the length of the cell.
@@ -1895,11 +1895,11 @@ void ScGridWindow::DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& rTabInfo
                    continue;

                Point aScrPos = mrViewData.GetScrPos( nCol, nRow, eWhich );
                long nSizeX;
                long nSizeY;
                tools::Long nSizeX;
                tools::Long nSizeY;
                mrViewData.GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
                long nPosX = aScrPos.X();
                long nPosY = aScrPos.Y();
                tools::Long nPosX = aScrPos.X();
                tools::Long nPosY = aScrPos.Y();
                // bLayoutRTL is handled in setBoundingBox

                OUString aStr = rDoc.GetString(nCol, nRow, nTab);
@@ -1935,7 +1935,7 @@ tools::Rectangle ScGridWindow::GetListValButtonRect( const ScAddress& rButtonPos
    ScDocument& rDoc = mrViewData.GetDocument();
    SCTAB nTab = mrViewData.GetTabNo();
    bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    ScDDComboBoxButton aButton( this );             // for optimal size
    Size aBtnSize = aButton.GetSizePixel();
@@ -1943,13 +1943,13 @@ tools::Rectangle ScGridWindow::GetListValButtonRect( const ScAddress& rButtonPos
    SCCOL nCol = rButtonPos.Col();
    SCROW nRow = rButtonPos.Row();

    long nCellSizeX;    // width of this cell, including merged
    long nDummy;
    tools::Long nCellSizeX;    // width of this cell, including merged
    tools::Long nDummy;
    mrViewData.GetMergeSizePixel( nCol, nRow, nCellSizeX, nDummy );

    // for height, only the cell's row is used, excluding merged cells
    long nCellSizeY = ScViewData::ToPixel( rDoc.GetRowHeight( nRow, nTab ), mrViewData.GetPPTY() );
    long nAvailable = nCellSizeX;
    tools::Long nCellSizeY = ScViewData::ToPixel( rDoc.GetRowHeight( nRow, nTab ), mrViewData.GetPPTY() );
    tools::Long nAvailable = nCellSizeX;

    //  left edge of next cell if there is a non-hidden next column
    SCCOL nNextCol = nCol + 1;
@@ -2045,7 +2045,7 @@ void ScGridWindow::GetRectsAnyFor(const ScMarkData &rMarkData,
    SCTAB nTab = mrViewData.GetTabNo();

    bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
    if ( !aMultiMark.IsMultiMarked() )
        return;
    ScRange aMultiRange;
@@ -2113,7 +2113,7 @@ void ScGridWindow::GetRectsAnyFor(const ScMarkData &rMarkData,

    Point aScrPos = bInPrintTwips ? mrViewData.GetPrintTwipsPos(nX1, nY1) :
            mrViewData.GetScrPos(nX1, nY1, eWhich);
    long nScrY = aScrPos.Y();
    tools::Long nScrY = aScrPos.Y();
    bool bWasHidden = false;
    for (SCROW nY=nY1; nY<=nY2; nY++)
    {
@@ -2150,19 +2150,19 @@ void ScGridWindow::GetRectsAnyFor(const ScMarkData &rMarkData,
                    nLoopEndX = nX1;
            }

            const long nHeight = bInPrintTwips ?
            const tools::Long nHeight = bInPrintTwips ?
                    nHeightTwips : ScViewData::ToPixel(nHeightTwips, nPPTY);
            long nEndY = nScrY + nHeight - 1;
            long nScrX = aScrPos.X();
            tools::Long nEndY = nScrY + nHeight - 1;
            tools::Long nScrX = aScrPos.X();
            for (SCCOL nX=nX1; nX<=nLoopEndX; nX++)
            {
                long nWidth = rDoc.GetColWidth(nX, nTab);
                tools::Long nWidth = rDoc.GetColWidth(nX, nTab);
                if (!bInPrintTwips)
                    nWidth = ScViewData::ToPixel(nWidth, nPPTX);

                if ( nWidth > 0 )
                {
                    long nEndX = nScrX + ( nWidth - 1 ) * nLayoutSign;
                    tools::Long nEndX = nScrX + ( nWidth - 1 ) * nLayoutSign;

                    SCROW nThisY = nY;
                    const ScPatternAttr* pPattern = rDoc.GetPattern( nX, nY, nTab );
diff --git a/sc/source/ui/view/gridwin_dbgutil.cxx b/sc/source/ui/view/gridwin_dbgutil.cxx
index de7ac8a..fe4c6f5 100644
--- a/sc/source/ui/view/gridwin_dbgutil.cxx
+++ b/sc/source/ui/view/gridwin_dbgutil.cxx
@@ -46,7 +46,7 @@ void ScGridWindow::dumpColumnInformationPixel()
    for (SCCOL nCol = 0; nCol <= 20; ++nCol)
    {
        sal_uInt16 nWidth = rDoc.GetColWidth(nCol, nTab);
        long nPixel = LogicToPixel(Point(nWidth, 0), MapMode(MapUnit::MapTwip)).getX();
        tools::Long nPixel = LogicToPixel(Point(nWidth, 0), MapMode(MapUnit::MapTwip)).getX();
        std::cout << "Column: " << nCol << ", Width: " << nPixel << "px" << std::endl;
    }
}
@@ -58,7 +58,7 @@ void ScGridWindow::dumpColumnInformationHmm()
    for (SCCOL nCol = 0; nCol <= 20; ++nCol)
    {
        sal_uInt16 nWidth = rDoc.GetColWidth(nCol, nTab);
        long nPixel = LogicToLogic(Point(nWidth, 0), MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM)).getX();
        tools::Long nPixel = LogicToLogic(Point(nWidth, 0), MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM)).getX();
        std::cout << "Column: " << nCol << ", Width: " << nPixel << "hmm" << std::endl;
    }
}
diff --git a/sc/source/ui/view/hdrcont.cxx b/sc/source/ui/view/hdrcont.cxx
index 85c9e13..12f4ad7 100644
--- a/sc/source/ui/view/hdrcont.cxx
+++ b/sc/source/ui/view/hdrcont.cxx
@@ -91,7 +91,7 @@ ScHeaderControl::ScHeaderControl( vcl::Window* pParent, SelectionEngine* pSelect
    SetBackground();
}

void ScHeaderControl::SetWidth( long nNew )
void ScHeaderControl::SetWidth( tools::Long nNew )
{
    OSL_ENSURE( bVertical, "SetWidth works only on row headers" );
    if ( nNew != nWidth )
@@ -112,7 +112,7 @@ ScHeaderControl::~ScHeaderControl()
void ScHeaderControl::DoPaint( SCCOLROW nStart, SCCOLROW nEnd )
{
    bool bLayoutRTL = IsLayoutRTL();
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    tools::Rectangle aRect( Point(0,0), GetOutputSizePixel() );
    if ( bVertical )
@@ -171,11 +171,11 @@ void ScHeaderControl::SetMark( bool bNewSet, SCCOLROW nNewStart, SCCOLROW nNewEn
        DoPaint( nOldStart, nOldEnd );          //  cancel selection
}

long ScHeaderControl::GetScrPos( SCCOLROW nEntryNo ) const
tools::Long ScHeaderControl::GetScrPos( SCCOLROW nEntryNo ) const
{
    long nScrPos;
    tools::Long nScrPos;

    long nMax = ( bVertical ? GetOutputSizePixel().Height() : GetOutputSizePixel().Width() ) + 1;
    tools::Long nMax = ( bVertical ? GetOutputSizePixel().Height() : GetOutputSizePixel().Width() ) + 1;
    if (nEntryNo >= nSize)
        nScrPos = nMax;
    else
@@ -224,7 +224,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const tools
    aSelLineColor.Merge( COL_BLACK, 0xe0 );        // darken just a little bit

    bool bLayoutRTL = IsLayoutRTL();
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
    bool bMirrored = IsMirrored();

    OUString            aString;
@@ -239,16 +239,16 @@ void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const tools

    SCCOLROW    nPos = GetPos();

    long nPStart = bVertical ? rRect.Top() : rRect.Left();
    long nPEnd = bVertical ? rRect.Bottom() : rRect.Right();
    tools::Long nPStart = bVertical ? rRect.Top() : rRect.Left();
    tools::Long nPEnd = bVertical ? rRect.Bottom() : rRect.Right();

    long nTransStart = nPEnd + 1;
    long nTransEnd = 0;
    tools::Long nTransStart = nPEnd + 1;
    tools::Long nTransEnd = 0;

    long nInitScrPos = 0;
    tools::Long nInitScrPos = 0;
    if ( bLayoutRTL )
    {
        long nTemp = nPStart;       // swap nPStart / nPEnd
        tools::Long nTemp = nPStart;       // swap nPStart / nPEnd
        nPStart = nPEnd;
        nPEnd = nTemp;
        nTemp = nTransStart;        // swap nTransStart / nTransEnd
@@ -263,7 +263,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const tools
    // complete the painting of the outer lines
    // first find the end of the last cell

    long nLineEnd = nInitScrPos - nLayoutSign;
    tools::Long nLineEnd = nInitScrPos - nLayoutSign;

    for (SCCOLROW i=nPos; i<nSize; i++)
    {
@@ -274,7 +274,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const tools

            if ( bMarkRange && i >= nMarkStart && i <= nMarkEnd )
            {
                long nLineStart = nLineEnd - ( nSizePix - 1 ) * nLayoutSign;
                tools::Long nLineStart = nLineEnd - ( nSizePix - 1 ) * nLayoutSign;
                if ( nLineStart * nLayoutSign < nTransStart * nLayoutSign )
                    nTransStart = nLineStart;
                if ( nLineEnd * nLayoutSign > nTransEnd * nLayoutSign )
@@ -351,7 +351,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const tools
        SetLineColor( rStyleSettings.GetDarkShadowColor() );
        if (bVertical)
        {
            long nDarkPos = bMirrored ? 0 : nBarSize-1;
            tools::Long nDarkPos = bMirrored ? 0 : nBarSize-1;
            DrawLine( Point( nDarkPos, nPStart ), Point( nDarkPos, nLineEnd ) );
        }
        else
@@ -363,7 +363,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const tools
            SetLineColor( aSelLineColor );
            if (bVertical)
            {
                long nDarkPos = bMirrored ? 0 : nBarSize-1;
                tools::Long nDarkPos = bMirrored ? 0 : nBarSize-1;
                DrawLine( Point( nDarkPos, nTransStart ), Point( nDarkPos, nTransEnd ) );
            }
            else
@@ -417,7 +417,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const tools
        }

        SCCOLROW    nCount=0;
        long    nScrPos=nInitScrPos;
        tools::Long    nScrPos=nInitScrPos;
        do
        {
            if (bVertical)
@@ -527,15 +527,15 @@ SCCOLROW ScHeaderControl::GetMousePos( const MouseEvent& rMEvt, bool& rBorder ) 
    SCCOLROW    nPos = GetPos();
    SCCOLROW    nHitNo = nPos;
    SCCOLROW    nEntryNo = 1 + nPos;
    long    nScrPos;
    long    nMousePos = bVertical ? rMEvt.GetPosPixel().Y() : rMEvt.GetPosPixel().X();
    long    nDif;
    tools::Long    nScrPos;
    tools::Long    nMousePos = bVertical ? rMEvt.GetPosPixel().Y() : rMEvt.GetPosPixel().X();
    tools::Long    nDif;
    Size    aSize = GetOutputSizePixel();
    long    nWinSize = bVertical ? aSize.Height() : aSize.Width();
    tools::Long    nWinSize = bVertical ? aSize.Height() : aSize.Width();

    bool bLayoutRTL = IsLayoutRTL();
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    long nEndPos = bLayoutRTL ? -1 : nWinSize;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nEndPos = bLayoutRTL ? -1 : nWinSize;

    nScrPos = GetScrPos( nPos ) - nLayoutSign;
    do
@@ -720,10 +720,10 @@ void ScHeaderControl::MouseButtonUp( const MouseEvent& rMEvt )
        }
        bDragging = false;

        long nScrPos    = GetScrPos( nDragNo );
        long nMousePos  = bVertical ? rMEvt.GetPosPixel().Y() : rMEvt.GetPosPixel().X();
        tools::Long nScrPos    = GetScrPos( nDragNo );
        tools::Long nMousePos  = bVertical ? rMEvt.GetPosPixel().Y() : rMEvt.GetPosPixel().X();
        bool bLayoutRTL = IsLayoutRTL();
        long nNewWidth  = bLayoutRTL ? ( nScrPos - nMousePos + 1 )
        tools::Long nNewWidth  = bLayoutRTL ? ( nScrPos - nMousePos + 1 )
                                     : ( nMousePos + 2 - nScrPos );

        if ( nNewWidth < 0 /* && !IsSelected(nDragNo) */ )
@@ -783,7 +783,7 @@ void ScHeaderControl::MouseMove( const MouseEvent& rMEvt )

    if ( bDragging )
    {
        long nNewPos = bVertical ? rMEvt.GetPosPixel().Y() : rMEvt.GetPosPixel().X();
        tools::Long nNewPos = bVertical ? rMEvt.GetPosPixel().Y() : rMEvt.GetPosPixel().X();
        if ( nNewPos != nDragPos )
        {
            DrawInvert( nDragPos );
@@ -907,9 +907,9 @@ void ScHeaderControl::ShowDragHelp()
    if (!Help::IsQuickHelpEnabled())
        return;

    long nScrPos    = GetScrPos( nDragNo );
    tools::Long nScrPos    = GetScrPos( nDragNo );
    bool bLayoutRTL = IsLayoutRTL();
    long nVal = bLayoutRTL ? ( nScrPos - nDragPos + 1 )
    tools::Long nVal = bLayoutRTL ? ( nScrPos - nDragPos + 1 )
                           : ( nDragPos + 2 - nScrPos );

    OUString aHelpStr = GetDragHelp( nVal );
@@ -989,11 +989,11 @@ void ScHeaderControl::SelectWindow()
{
}

void ScHeaderControl::DrawInvert( long /* nDragPos */ )
void ScHeaderControl::DrawInvert( tools::Long /* nDragPos */ )
{
}

OUString ScHeaderControl::GetDragHelp( long /* nVal */ )
OUString ScHeaderControl::GetDragHelp( tools::Long /* nVal */ )
{
    return EMPTY_OUSTRING;
}
diff --git a/sc/source/ui/view/olinewin.cxx b/sc/source/ui/view/olinewin.cxx
index 2925f2d..9bc743e 100644
--- a/sc/source/ui/view/olinewin.cxx
+++ b/sc/source/ui/view/olinewin.cxx
@@ -30,8 +30,8 @@
#include <dbfunc.hxx>
#include <bitmaps.hlst>

const long SC_OL_BITMAPSIZE                 = 12;
const long SC_OL_POSOFFSET                  = 2;
const tools::Long SC_OL_BITMAPSIZE                 = 12;
const tools::Long SC_OL_POSOFFSET                  = 2;

const size_t SC_OL_NOLEVEL                  = static_cast< size_t >( -1 );
const size_t SC_OL_HEADERENTRY              = static_cast< size_t >( -1 );
@@ -80,7 +80,7 @@ void ScOutlineWindow::dispose()
    vcl::Window::dispose();
}

void ScOutlineWindow::SetHeaderSize( long nNewSize )
void ScOutlineWindow::SetHeaderSize( tools::Long nNewSize )
{
    bool bLayoutRTL = GetDoc().IsLayoutRTL( GetTab() );
    mbMirrorEntries = bLayoutRTL && mbHoriz;
@@ -95,23 +95,23 @@ void ScOutlineWindow::SetHeaderSize( long nNewSize )
        Invalidate();
}

long ScOutlineWindow::GetDepthSize() const
tools::Long ScOutlineWindow::GetDepthSize() const
{
    long nSize = GetLevelCount() * SC_OL_BITMAPSIZE;
    tools::Long nSize = GetLevelCount() * SC_OL_BITMAPSIZE;
    if ( nSize > 0 )
        nSize += 2 * SC_OL_POSOFFSET + 1;
    return nSize;
}

void ScOutlineWindow::ScrollPixel( long nDiff )
void ScOutlineWindow::ScrollPixel( tools::Long nDiff )
{
    HideFocus();
    mbDontDrawFocus = true;

    long nStart = mnMainFirstPos;
    long nEnd = mnMainLastPos;
    tools::Long nStart = mnMainFirstPos;
    tools::Long nEnd = mnMainLastPos;

    long nInvStart, nInvEnd;
    tools::Long nInvStart, nInvEnd;
    if (nDiff < 0)
    {
        nStart -= nDiff;
@@ -135,7 +135,7 @@ void ScOutlineWindow::ScrollPixel( long nDiff )
    ShowFocus();
}

void ScOutlineWindow::ScrollRel( long nEntryDiff, long nEntryStart, long nEntryEnd )
void ScOutlineWindow::ScrollRel( tools::Long nEntryDiff, tools::Long nEntryStart, tools::Long nEntryEnd )
{
    tools::Rectangle aRect( GetRectangle( 0, nEntryStart, GetOutputSizeLevel() - 1, nEntryEnd ) );
    if ( mbHoriz )
@@ -206,24 +206,24 @@ void ScOutlineWindow::GetVisibleRange( SCCOLROW& rnColRowStart, SCCOLROW& rnColR
        --rnColRowStart;
}

Point ScOutlineWindow::GetPoint( long nLevelPos, long nEntryPos ) const
Point ScOutlineWindow::GetPoint( tools::Long nLevelPos, tools::Long nEntryPos ) const
{
    return mbHoriz ? Point( nEntryPos, nLevelPos ) : Point( nLevelPos, nEntryPos );
}

tools::Rectangle ScOutlineWindow::GetRectangle(
        long nLevelStart, long nEntryStart, long nLevelEnd, long nEntryEnd ) const
        tools::Long nLevelStart, tools::Long nEntryStart, tools::Long nLevelEnd, tools::Long nEntryEnd ) const
{
    return tools::Rectangle( GetPoint( nLevelStart, nEntryStart ), GetPoint( nLevelEnd, nEntryEnd ) );
}

long ScOutlineWindow::GetOutputSizeLevel() const
tools::Long ScOutlineWindow::GetOutputSizeLevel() const
{
    Size aSize( GetOutputSizePixel() );
    return mbHoriz ? aSize.Height() : aSize.Width();
}

long ScOutlineWindow::GetOutputSizeEntry() const
tools::Long ScOutlineWindow::GetOutputSizeEntry() const
{
    Size aSize( GetOutputSizePixel() );
    return mbHoriz ? aSize.Width() : aSize.Height();
@@ -236,38 +236,38 @@ size_t ScOutlineWindow::GetLevelCount() const
    return nLevelCount ? (nLevelCount + 1) : 0;
}

long ScOutlineWindow::GetLevelPos( size_t nLevel ) const
tools::Long ScOutlineWindow::GetLevelPos( size_t nLevel ) const
{
    // #i51970# must always return the *left* edge of the area used by a level
    long nPos = static_cast< long >( SC_OL_POSOFFSET + nLevel * SC_OL_BITMAPSIZE );
    tools::Long nPos = static_cast< tools::Long >( SC_OL_POSOFFSET + nLevel * SC_OL_BITMAPSIZE );
    return mbMirrorLevels ? (GetOutputSizeLevel() - nPos - SC_OL_BITMAPSIZE) : nPos;
}

size_t ScOutlineWindow::GetLevelFromPos( long nLevelPos ) const
size_t ScOutlineWindow::GetLevelFromPos( tools::Long nLevelPos ) const
{
    if( mbMirrorLevels ) nLevelPos = GetOutputSizeLevel() - nLevelPos - 1;
    long nStart = SC_OL_POSOFFSET;
    tools::Long nStart = SC_OL_POSOFFSET;
    if ( nLevelPos < nStart ) return SC_OL_NOLEVEL;
    size_t nLevel = static_cast< size_t >( (nLevelPos - nStart) / SC_OL_BITMAPSIZE );
    return (nLevel < GetLevelCount()) ? nLevel : SC_OL_NOLEVEL;
}

long ScOutlineWindow::GetColRowPos( SCCOLROW nColRowIndex ) const
tools::Long ScOutlineWindow::GetColRowPos( SCCOLROW nColRowIndex ) const
{
    long nDocPos = mbHoriz ?
    tools::Long nDocPos = mbHoriz ?
        mrViewData.GetScrPos( static_cast<SCCOL>(nColRowIndex), 0, meWhich, true ).X() :
        mrViewData.GetScrPos( 0, static_cast<SCROW>(nColRowIndex), meWhich, true ).Y();
    return mnMainFirstPos + nDocPos;
}

long ScOutlineWindow::GetHeaderEntryPos() const
tools::Long ScOutlineWindow::GetHeaderEntryPos() const
{
    return mnHeaderPos + (mnHeaderSize - SC_OL_BITMAPSIZE) / 2;
}

bool ScOutlineWindow::GetEntryPos(
        size_t nLevel, size_t nEntry,
        long& rnStartPos, long& rnEndPos, long& rnImagePos ) const
        tools::Long& rnStartPos, tools::Long& rnEndPos, tools::Long& rnImagePos ) const
{
    const ScOutlineEntry* pEntry = GetOutlineEntry( nLevel, nEntry );
    if ( !pEntry || !pEntry->IsVisible() )
@@ -276,7 +276,7 @@ bool ScOutlineWindow::GetEntryPos(
    SCCOLROW nStart = pEntry->GetStart();
    SCCOLROW nEnd = pEntry->GetEnd();

    long nEntriesSign = mbMirrorEntries ? -1 : 1;
    tools::Long nEntriesSign = mbMirrorEntries ? -1 : 1;

    // --- common calculation ---

@@ -287,7 +287,7 @@ bool ScOutlineWindow::GetEntryPos(
    rnImagePos = bHidden ?
                (rnStartPos - ( SC_OL_BITMAPSIZE / 2 ) * nEntriesSign) :
                rnStartPos + nEntriesSign;
    long nCenter = (rnStartPos + rnEndPos - SC_OL_BITMAPSIZE * nEntriesSign +
    tools::Long nCenter = (rnStartPos + rnEndPos - SC_OL_BITMAPSIZE * nEntriesSign +
                        ( mbMirrorEntries ? 1 : 0 )) / 2;
    rnImagePos = mbMirrorEntries ? std::max( rnImagePos, nCenter ) : std::min( rnImagePos, nCenter );

@@ -337,12 +337,12 @@ bool ScOutlineWindow::GetImagePos( size_t nLevel, size_t nEntry, Point& rPos ) c
    bool bRet = nLevel < GetLevelCount();
    if ( bRet )
    {
        long nLevelPos = GetLevelPos( nLevel );
        tools::Long nLevelPos = GetLevelPos( nLevel );
        if ( nEntry == SC_OL_HEADERENTRY )
            rPos = GetPoint( nLevelPos, GetHeaderEntryPos() );
        else
        {
            long nStartPos, nEndPos, nImagePos;
            tools::Long nStartPos, nEndPos, nImagePos;
            bRet = GetEntryPos( nLevel, nEntry, nStartPos, nEndPos, nImagePos );
            rPos = GetPoint( nLevelPos, nImagePos );
        }
@@ -380,13 +380,13 @@ bool ScOutlineWindow::ItemHit( const Point& rPos, size_t& rnLevel, size_t& rnEnt
    if ( nLevel == SC_OL_NOLEVEL )
        return false;

    long nEntryMousePos = mbHoriz ? rPos.X() : rPos.Y();
    tools::Long nEntryMousePos = mbHoriz ? rPos.X() : rPos.Y();

    // --- level buttons ---

    if ( mnHeaderSize > 0 )
    {
        long nImagePos = GetHeaderEntryPos();
        tools::Long nImagePos = GetHeaderEntryPos();
        if ( (nImagePos <= nEntryMousePos) && (nEntryMousePos < nImagePos + SC_OL_BITMAPSIZE) )
        {
            rnLevel = nLevel;
@@ -411,7 +411,7 @@ bool ScOutlineWindow::ItemHit( const Point& rPos, size_t& rnLevel, size_t& rnEnt

        if ( (nEnd >= nStartIndex) && (nStart <= nEndIndex) )
        {
            long nStartPos, nEndPos, nImagePos;
            tools::Long nStartPos, nEndPos, nImagePos;
            if ( GetEntryPos( nLevel, nEntry, nStartPos, nEndPos, nImagePos ) )
            {
                rnLevel = nLevel;
@@ -517,13 +517,13 @@ void ScOutlineWindow::SetEntryAreaClipRegion()
}

void ScOutlineWindow::DrawLineRel(
        long nLevelStart, long nEntryStart, long nLevelEnd, long nEntryEnd )
        tools::Long nLevelStart, tools::Long nEntryStart, tools::Long nLevelEnd, tools::Long nEntryEnd )
{
    DrawLine( GetPoint( nLevelStart, nEntryStart ), GetPoint( nLevelEnd, nEntryEnd ) );
}

void ScOutlineWindow::DrawRectRel(
        long nLevelStart, long nEntryStart, long nLevelEnd, long nEntryEnd )
        tools::Long nLevelStart, tools::Long nEntryStart, tools::Long nLevelEnd, tools::Long nEntryEnd )
{
    DrawRect( GetRectangle( nLevelStart, nEntryStart, nLevelEnd, nEntryEnd ) );
}
@@ -536,7 +536,7 @@ namespace
    }
}

void ScOutlineWindow::DrawImageRel(long nLevelPos, long nEntryPos, const OUString& rId)
void ScOutlineWindow::DrawImageRel(tools::Long nLevelPos, tools::Long nEntryPos, const OUString& rId)
{
    const Image& rImage = GetImage(rId);
    SetLineColor();
@@ -615,15 +615,15 @@ const std::u16string_view aLevelBmps[]=

void ScOutlineWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle& /* rRect */ )
{
    long nEntriesSign = mbMirrorEntries ? -1 : 1;
    long nLevelsSign  = mbMirrorLevels  ? -1 : 1;
    tools::Long nEntriesSign = mbMirrorEntries ? -1 : 1;
    tools::Long nLevelsSign  = mbMirrorLevels  ? -1 : 1;

    Size aSize = GetOutputSizePixel();
    long nLevelEnd = (mbHoriz ? aSize.Height() : aSize.Width()) - 1;
    long nEntryEnd = (mbHoriz ? aSize.Width() : aSize.Height()) - 1;
    tools::Long nLevelEnd = (mbHoriz ? aSize.Height() : aSize.Width()) - 1;
    tools::Long nEntryEnd = (mbHoriz ? aSize.Width() : aSize.Height()) - 1;

    SetLineColor( maLineColor );
    long nBorderPos = mbMirrorLevels ? 0 : nLevelEnd;
    tools::Long nBorderPos = mbMirrorLevels ? 0 : nLevelEnd;
    DrawLineRel( nBorderPos, 0, nBorderPos, nEntryEnd );

    const ScOutlineArray* pArray = GetOutlineArray();
@@ -635,12 +635,12 @@ void ScOutlineWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const tools

    if ( mnHeaderSize > 0 )
    {
        long nEntryPos = GetHeaderEntryPos();
        tools::Long nEntryPos = GetHeaderEntryPos();
        for ( size_t nLevel = 0; nLevel < nLevelCount; ++nLevel )
            DrawImageRel(GetLevelPos(nLevel), nEntryPos, aLevelBmps[nLevel]);

        SetLineColor( maLineColor );
        long nLinePos = mnHeaderPos + (mbMirrorEntries ? 0 : (mnHeaderSize - 1));
        tools::Long nLinePos = mnHeaderPos + (mbMirrorEntries ? 0 : (mnHeaderSize - 1));
        DrawLineRel( 0, nLinePos, nLevelEnd, nLinePos );
    }

@@ -653,8 +653,8 @@ void ScOutlineWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const tools

    for ( size_t nLevel = 0; nLevel + 1 < nLevelCount; ++nLevel )
    {
        long nLevelPos = GetLevelPos( nLevel );
        long nEntryPos1 = 0, nEntryPos2 = 0, nImagePos = 0;
        tools::Long nLevelPos = GetLevelPos( nLevel );
        tools::Long nEntryPos1 = 0, nEntryPos2 = 0, nImagePos = 0;

        size_t nEntryCount = pArray->GetCount( sal::static_int_cast<sal_uInt16>(nLevel) );
        size_t nEntry;
@@ -680,7 +680,7 @@ void ScOutlineWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const tools
                if ( nStart >= nStartIndex )
                    nEntryPos1 += nEntriesSign;
                nEntryPos2 -= 2 * nEntriesSign;
                long nLinePos = nLevelPos;
                tools::Long nLinePos = nLevelPos;
                if ( mbMirrorLevels )
                    nLinePos += SC_OL_BITMAPSIZE - 1;   // align with right edge of bitmap
                DrawRectRel( nLinePos, nEntryPos1, nLinePos + nLevelsSign, nEntryPos2 );
diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx
index 584125b..65e8974 100644
--- a/sc/source/ui/view/output.cxx
+++ b/sc/source/ui/view/output.cxx
@@ -133,7 +133,7 @@ void ScActionColorChanger::Update( const ScChangeAction& rAction )

ScOutputData::ScOutputData( OutputDevice* pNewDev, ScOutputType eNewType,
                            ScTableInfo& rTabInfo, ScDocument* pNewDoc,
                            SCTAB nNewTab, long nNewScrX, long nNewScrY,
                            SCTAB nNewTab, tools::Long nNewScrX, tools::Long nNewScrY,
                            SCCOL nNewX1, SCROW nNewY1, SCCOL nNewX2, SCROW nNewY2,
                            double nPixelPerTwipsX, double nPixelPerTwipsY,
                            const Fraction* pZoomX, const Fraction* pZoomY ) :
@@ -227,7 +227,7 @@ void ScOutputData::SetContentDevice( OutputDevice* pContentDev )
    mpDev = pContentDev;
}

void ScOutputData::SetMirrorWidth( long nNew )
void ScOutputData::SetMirrorWidth( tools::Long nNew )
{
    nMirrorW = nNew;
}
@@ -290,8 +290,8 @@ void ScOutputData::DrawGrid(vcl::RenderContext& rRenderContext, bool bGrid, bool
{
    SCCOL nX;
    SCROW nY;
    long nPosX;
    long nPosY;
    tools::Long nPosX;
    tools::Long nPosY;
    SCSIZE nArrY;
    ScBreakType nBreak    = ScBreakType::NONE;
    ScBreakType nBreakOld = ScBreakType::NONE;
@@ -337,8 +337,8 @@ void ScOutputData::DrawGrid(vcl::RenderContext& rRenderContext, bool bGrid, bool
        aManualColor = aGridColor;
    }

    long nOneX = 1;
    long nOneY = 1;
    tools::Long nOneX = 1;
    tools::Long nOneY = 1;
    if (!bWorksInPixels)
    {
        Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
@@ -346,8 +346,8 @@ void ScOutputData::DrawGrid(vcl::RenderContext& rRenderContext, bool bGrid, bool
        nOneY = aOnePixel.Height();
    }

    long nLayoutSign = bLayoutRTL ? -1 : 1;
    long nSignedOneX = nOneX * nLayoutSign;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nSignedOneX = nOneX * nLayoutSign;

    rRenderContext.SetLineColor(aGridColor);
    ScGridMerger aGrid(&rRenderContext, nOneX, nOneY);
@@ -429,7 +429,7 @@ void ScOutputData::DrawGrid(vcl::RenderContext& rRenderContext, bool bGrid, bool
                    for (nArrY=1; nArrY+1<nArrCount; nArrY++)
                    {
                        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
                        const long nNextY = nPosY + pThisRowInfo->nHeight;
                        const tools::Long nNextY = nPosY + pThisRowInfo->nHeight;

                        bool bHOver = pThisRowInfo->pCellInfo[nXplus1].bHideGrid;
                        if (!bHOver)
@@ -540,7 +540,7 @@ void ScOutputData::DrawGrid(vcl::RenderContext& rRenderContext, bool bGrid, bool

                    for (SCCOL i=nX1; i<=nX2; i++)
                    {
                        const long nNextX = nPosX + pRowInfo[0].pCellInfo[i+1].nWidth * nLayoutSign;
                        const tools::Long nNextX = nPosX + pRowInfo[0].pCellInfo[i+1].nWidth * nLayoutSign;
                        if (nNextX != nPosX)                                // visible
                        {
                            bool bVOver;
@@ -651,7 +651,7 @@ void ScOutputData::SetCellRotations()
                        if(nTargetX >= 0 && nTargetY >= 0)
                        {
                            // add rotation info to Array information
                            const long nAttrRotate(pPattern->GetRotateVal(pCondSet));
                            const tools::Long nAttrRotate(pPattern->GetRotateVal(pCondSet));
                            const SvxRotateMode eRotMode(pPattern->GetItem(ATTR_ROTATE_MODE, pCondSet).GetValue());
                            const double fOrient((bLayoutRTL ? -1.0 : 1.0) * nAttrRotate * F_PI18000); // 1/100th degrees -> [0..2PI]
                            svx::frame::Array& rArray = mrTabInfo.maArray;
@@ -672,7 +672,7 @@ static ScRotateDir lcl_GetRotateDir( const ScDocument* pDoc, SCCOL nCol, SCROW n

    ScRotateDir nRet = ScRotateDir::NONE;

    long nAttrRotate = pPattern->GetRotateVal( pCondSet );
    tools::Long nAttrRotate = pPattern->GetRotateVal( pCondSet );
    if ( nAttrRotate )
    {
        SvxRotateMode eRotMode =
@@ -684,7 +684,7 @@ static ScRotateDir lcl_GetRotateDir( const ScDocument* pDoc, SCCOL nCol, SCROW n
            nRet = ScRotateDir::Center;
        else if ( eRotMode == SVX_ROTATE_MODE_TOP || eRotMode == SVX_ROTATE_MODE_BOTTOM )
        {
            long nRot180 = nAttrRotate % 18000;     // 1/100 degree
            tools::Long nRot180 = nAttrRotate % 18000;     // 1/100 degree
            if ( nRot180 == 9000 )
                nRet = ScRotateDir::Center;
            else if ( ( eRotMode == SVX_ROTATE_MODE_TOP && nRot180 < 9000 ) ||
@@ -821,9 +821,9 @@ namespace {

const double lclCornerRectTransparency = 40.0;

void drawDataBars(vcl::RenderContext& rRenderContext, const ScDataBarInfo* pOldDataBarInfo, const tools::Rectangle& rRect, long nOneX, long nOneY)
void drawDataBars(vcl::RenderContext& rRenderContext, const ScDataBarInfo* pOldDataBarInfo, const tools::Rectangle& rRect, tools::Long nOneX, tools::Long nOneY)
{
    long nPosZero = 0;
    tools::Long nPosZero = 0;
    tools::Rectangle aPaintRect = rRect;
    aPaintRect.AdjustTop(2 * nOneY );
    aPaintRect.AdjustBottom( -(2 * nOneY) );
@@ -832,8 +832,8 @@ void drawDataBars(vcl::RenderContext& rRenderContext, const ScDataBarInfo* pOldD
    if(pOldDataBarInfo->mnZero)
    {
        // need to calculate null point in cell
        long nLength = aPaintRect.Right() - aPaintRect.Left();
        nPosZero = static_cast<long>(aPaintRect.Left() + nLength*pOldDataBarInfo->mnZero/100.0);
        tools::Long nLength = aPaintRect.Right() - aPaintRect.Left();
        nPosZero = static_cast<tools::Long>(aPaintRect.Left() + nLength*pOldDataBarInfo->mnZero/100.0);
    }
    else
    {
@@ -843,14 +843,14 @@ void drawDataBars(vcl::RenderContext& rRenderContext, const ScDataBarInfo* pOldD
    if(pOldDataBarInfo->mnLength < 0)
    {
        aPaintRect.SetRight( nPosZero );
        long nLength = nPosZero - aPaintRect.Left();
        aPaintRect.SetLeft( nPosZero + static_cast<long>(nLength * pOldDataBarInfo->mnLength/100.0) );
        tools::Long nLength = nPosZero - aPaintRect.Left();
        aPaintRect.SetLeft( nPosZero + static_cast<tools::Long>(nLength * pOldDataBarInfo->mnLength/100.0) );
    }
    else if(pOldDataBarInfo->mnLength > 0)
    {
        aPaintRect.SetLeft( nPosZero );
        long nLength = aPaintRect.Right() - nPosZero;
        aPaintRect.SetRight( nPosZero + static_cast<long>(nLength * pOldDataBarInfo->mnLength/100.0) );
        tools::Long nLength = aPaintRect.Right() - nPosZero;
        aPaintRect.SetRight( nPosZero + static_cast<tools::Long>(nLength * pOldDataBarInfo->mnLength/100.0) );
    }
    else
        return;
@@ -898,23 +898,23 @@ const BitmapEx& getIcon(sc::IconSetBitmapMap & rIconSetBitmapMap, ScIconSetType 
    return ScIconSetFormat::getBitmap(rIconSetBitmapMap, eType, nIndex);
}

void drawIconSets(vcl::RenderContext& rRenderContext, const ScIconSetInfo* pOldIconSetInfo, const tools::Rectangle& rRect, long nOneX, long nOneY,
void drawIconSets(vcl::RenderContext& rRenderContext, const ScIconSetInfo* pOldIconSetInfo, const tools::Rectangle& rRect, tools::Long nOneX, tools::Long nOneY,
        sc::IconSetBitmapMap & rIconSetBitmapMap)
{
    //long nSize = 16;
    ScIconSetType eType = pOldIconSetInfo->eIconSetType;
    sal_Int32 nIndex = pOldIconSetInfo->nIconIndex;
    const BitmapEx& rIcon = getIcon(rIconSetBitmapMap, eType, nIndex);
    long aOrigSize = std::max<long>(0,std::min(rRect.GetSize().getWidth() - 4 * nOneX, rRect.GetSize().getHeight() -4 * nOneY));
    tools::Long aOrigSize = std::max<long>(0,std::min(rRect.GetSize().getWidth() - 4 * nOneX, rRect.GetSize().getHeight() -4 * nOneY));
    rRenderContext.DrawBitmapEx( Point( rRect.Left() + 2 * nOneX, rRect.Top() + 2 * nOneY), Size(aOrigSize, aOrigSize), rIcon );
}

void drawCells(vcl::RenderContext& rRenderContext, std::optional<Color> const & pColor, const SvxBrushItem* pBackground, std::optional<Color>& pOldColor, const SvxBrushItem*& pOldBackground,
        tools::Rectangle& rRect, long nPosX, long nLayoutSign, long nOneX, long nOneY, const ScDataBarInfo* pDataBarInfo, const ScDataBarInfo*& pOldDataBarInfo,
        tools::Rectangle& rRect, tools::Long nPosX, tools::Long nLayoutSign, tools::Long nOneX, tools::Long nOneY, const ScDataBarInfo* pDataBarInfo, const ScDataBarInfo*& pOldDataBarInfo,
        const ScIconSetInfo* pIconSetInfo, const ScIconSetInfo*& pOldIconSetInfo,
        sc::IconSetBitmapMap & rIconSetBitmapMap)
{
    long nSignedOneX = nOneX * nLayoutSign;
    tools::Long nSignedOneX = nOneX * nLayoutSign;
    // need to paint if old color scale has been used and now
    // we have a different color or a style based background
    // we can here fall back to pointer comparison
@@ -990,16 +990,16 @@ void drawCells(vcl::RenderContext& rRenderContext, std::optional<Color> const & 
void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
{
    Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
    long nOneXLogic = aOnePixel.Width();
    long nOneYLogic = aOnePixel.Height();
    tools::Long nOneXLogic = aOnePixel.Width();
    tools::Long nOneYLogic = aOnePixel.Height();

    // See more about bWorksInPixels in ScOutputData::DrawGrid
    bool bWorksInPixels = false;
    if (eType == OUTTYPE_WINDOW)
        bWorksInPixels = true;

    long nOneX = 1;
    long nOneY = 1;
    tools::Long nOneX = 1;
    tools::Long nOneY = 1;
    if (!bWorksInPixels)
    {
        nOneX = nOneXLogic;
@@ -1008,7 +1008,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)

    tools::Rectangle aRect;

    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    rRenderContext.SetLineColor();

@@ -1018,7 +1018,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
    bool bCellContrast = mbUseStyleColor &&
            Application::GetSettings().GetStyleSettings().GetHighContrastMode();

    long nPosY = nScrY;
    tools::Long nPosY = nScrY;

    const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig();
    Color aProtectedColor( rColorCfg.GetColorValue( svtools::CALCPROTECTEDBACKGROUND ).nColor );
@@ -1028,7 +1028,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
    for (SCSIZE nArrY=1; nArrY+1<nArrCount; nArrY++)
    {
        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
        long nRowHeight = pThisRowInfo->nHeight;
        tools::Long nRowHeight = pThisRowInfo->nHeight;

        if ( pThisRowInfo->bChanged )
        {
@@ -1048,7 +1048,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                    nRowHeight += pRowInfo[nArrY+nSkip].nHeight;    // after incrementing
                }

                long nPosX = nScrX;
                tools::Long nPosX = nScrX;

                if ( bLayoutRTL )
                    nPosX += nMirrorW - nOneX;
@@ -1108,7 +1108,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                    const ScDataBarInfo* pDataBarInfo = pInfo->pDataBar.get();
                    const ScIconSetInfo* pIconSetInfo = pInfo->pIconSet.get();

                    long nPosXLogic = nPosX;
                    tools::Long nPosXLogic = nPosX;
                    if (bWorksInPixels)
                        nPosXLogic = rRenderContext.PixelToLogic(Point(nPosX, 0)).X();

@@ -1132,7 +1132,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext)
                    }
                }

                long nPosXLogic = nPosX;
                tools::Long nPosXLogic = nPosX;
                if (bWorksInPixels)
                    nPosXLogic = rRenderContext.PixelToLogic(Point(nPosX, 0)).X();

@@ -1160,27 +1160,27 @@ void ScOutputData::DrawExtraShadow(bool bLeft, bool bTop, bool bRight, bool bBot
    if ( bCellContrast )
        aAutoTextColor = SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor;

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
    {
        Size aOnePixel = mpDev->PixelToLogic(Size(1,1));
        long nOneX = aOnePixel.Width();
        tools::Long nOneX = aOnePixel.Width();
        nInitPosX += nMirrorW - nOneX;
    }
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    long nPosY = nScrY - pRowInfo[0].nHeight;
    tools::Long nPosY = nScrY - pRowInfo[0].nHeight;
    for (SCSIZE nArrY=0; nArrY<nArrCount; nArrY++)
    {
        bool bCornerY = ( nArrY == 0 ) || ( nArrY+1 == nArrCount );
        bool bSkipY = ( nArrY==0 && !bTop ) || ( nArrY+1 == nArrCount && !bBottom );

        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
        long nRowHeight = pThisRowInfo->nHeight;
        tools::Long nRowHeight = pThisRowInfo->nHeight;

        if ( pThisRowInfo->bChanged && !bSkipY )
        {
            long nPosX = nInitPosX - pRowInfo[0].pCellInfo[nX1].nWidth * nLayoutSign;
            tools::Long nPosX = nInitPosX - pRowInfo[0].pCellInfo[nX1].nWidth * nLayoutSign;
            for (SCCOL nArrX=nX1; nArrX<=nX2+2; nArrX++)
            {
                bool bCornerX = ( nArrX==nX1 || nArrX==nX2+2 );
@@ -1204,8 +1204,8 @@ void ScOutputData::DrawExtraShadow(bool bLeft, bool bTop, bool bRight, bool bBot

                        if (bDo)
                        {
                            long nThisWidth = pRowInfo[0].pCellInfo[nArrX].nWidth;
                            long nMaxWidth = nThisWidth;
                            tools::Long nThisWidth = pRowInfo[0].pCellInfo[nArrX].nWidth;
                            tools::Long nMaxWidth = nThisWidth;
                            if (!nMaxWidth)
                            {
                                //! direction must depend on shadow location
@@ -1220,10 +1220,10 @@ void ScOutputData::DrawExtraShadow(bool bLeft, bool bTop, bool bRight, bool bBot
                                             nPosX + ( nThisWidth - 1 ) * nLayoutSign,
                                             nPosY + pRowInfo[nArrY].nHeight - 1 );

                            long nSize = pAttr->GetWidth();
                            long nSizeX = static_cast<long>(nSize*mnPPTX);
                            tools::Long nSize = pAttr->GetWidth();
                            tools::Long nSizeX = static_cast<tools::Long>(nSize*mnPPTX);
                            if (nSizeX >= nMaxWidth) nSizeX = nMaxWidth-1;
                            long nSizeY = static_cast<long>(nSize*mnPPTY);
                            tools::Long nSizeY = static_cast<tools::Long>(nSize*mnPPTY);
                            if (nSizeY >= nRowHeight) nSizeY = nRowHeight-1;

                            nSizeX *= nLayoutSign;      // used only to add to rectangle values
@@ -1295,8 +1295,8 @@ void ScOutputData::DrawClear()
{
    tools::Rectangle aRect;
    Size aOnePixel = mpDev->PixelToLogic(Size(1,1));
    long nOneX = aOnePixel.Width();
    long nOneY = aOnePixel.Height();
    tools::Long nOneX = aOnePixel.Width();
    tools::Long nOneY = aOnePixel.Height();

    // (called only for ScGridWindow)
    Color aBgColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor );
@@ -1308,11 +1308,11 @@ void ScOutputData::DrawClear()

    mpDev->SetFillColor( aBgColor );

    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    for (SCSIZE nArrY=1; nArrY+1<nArrCount; nArrY++)
    {
        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
        long nRowHeight = pThisRowInfo->nHeight;
        tools::Long nRowHeight = pThisRowInfo->nHeight;

        if ( pThisRowInfo->bChanged )
        {
@@ -1336,12 +1336,12 @@ void ScOutputData::DrawClear()

// Lines

static long lclGetSnappedX( const OutputDevice& rDev, long nPosX, bool bSnapPixel )
static tools::Long lclGetSnappedX( const OutputDevice& rDev, tools::Long nPosX, bool bSnapPixel )
{
    return (bSnapPixel && nPosX) ? rDev.PixelToLogic( rDev.LogicToPixel( Size( nPosX, 0 ) ) ).Width() : nPosX;
}

static long lclGetSnappedY( const OutputDevice& rDev, long nPosY, bool bSnapPixel )
static tools::Long lclGetSnappedY( const OutputDevice& rDev, tools::Long nPosY, bool bSnapPixel )
{
    return (bSnapPixel && nPosY) ? rDev.PixelToLogic( rDev.LogicToPixel( Size( 0, nPosY ) ) ).Height() : nPosY;
}
@@ -1390,14 +1390,14 @@ void ScOutputData::DrawFrame(vcl::RenderContext& rRenderContext)
        DrawRotatedFrame(rRenderContext);        // removes the lines that must not be painted here
    }

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
    {
        Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
        long nOneX = aOnePixel.Width();
        tools::Long nOneX = aOnePixel.Width();
        nInitPosX += nMirrorW - nOneX;
    }
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    // *** set column and row sizes of the frame border array ***

@@ -1409,13 +1409,13 @@ void ScOutputData::DrawFrame(vcl::RenderContext& rRenderContext)

    // row 0 is not visible (dummy for borders from top) - subtract its height from initial position
    // subtract 1 unit more, because position 0 is first *in* cell, grid line is one unit before
    long nOldPosY = nScrY - 1 - pRowInfo[ 0 ].nHeight;
    long nOldSnapY = lclGetSnappedY( rRenderContext, nOldPosY, bSnapPixel );
    tools::Long nOldPosY = nScrY - 1 - pRowInfo[ 0 ].nHeight;
    tools::Long nOldSnapY = lclGetSnappedY( rRenderContext, nOldPosY, bSnapPixel );
    rArray.SetYOffset( nOldSnapY );
    for( size_t nRow = 0; nRow < nRowCount; ++nRow )
    {
        long nNewPosY = nOldPosY + pRowInfo[ nRow ].nHeight;
        long nNewSnapY = lclGetSnappedY( rRenderContext, nNewPosY, bSnapPixel );
        tools::Long nNewPosY = nOldPosY + pRowInfo[ nRow ].nHeight;
        tools::Long nNewSnapY = lclGetSnappedY( rRenderContext, nNewPosY, bSnapPixel );
        rArray.SetRowHeight( nRow, nNewSnapY - nOldSnapY );
        nOldPosY = nNewPosY;
        nOldSnapY = nNewSnapY;
@@ -1425,16 +1425,16 @@ void ScOutputData::DrawFrame(vcl::RenderContext& rRenderContext)

    // column nX1 is not visible (dummy for borders from left) - subtract its width from initial position
    // subtract 1 unit more, because position 0 is first *in* cell, grid line is one unit above
    long nOldPosX = nInitPosX - nLayoutSign * (1 + pRowInfo[ 0 ].pCellInfo[ nX1 ].nWidth);
    long nOldSnapX = lclGetSnappedX( rRenderContext, nOldPosX, bSnapPixel );
    tools::Long nOldPosX = nInitPosX - nLayoutSign * (1 + pRowInfo[ 0 ].pCellInfo[ nX1 ].nWidth);
    tools::Long nOldSnapX = lclGetSnappedX( rRenderContext, nOldPosX, bSnapPixel );
    // set X offset for left-to-right sheets; for right-to-left sheets this is done after for() loop
    if( !bLayoutRTL )
        rArray.SetXOffset( nOldSnapX );
    for( sal_uInt16 nInfoIdx = nX1; nInfoIdx <= nX2 + 2; ++nInfoIdx )
    {
        size_t nCol = lclGetArrayColFromCellInfoX( nInfoIdx, nX1, nX2, bLayoutRTL );
        long nNewPosX = nOldPosX + pRowInfo[ 0 ].pCellInfo[ nInfoIdx ].nWidth * nLayoutSign;
        long nNewSnapX = lclGetSnappedX( rRenderContext, nNewPosX, bSnapPixel );
        tools::Long nNewPosX = nOldPosX + pRowInfo[ 0 ].pCellInfo[ nInfoIdx ].nWidth * nLayoutSign;
        tools::Long nNewSnapX = lclGetSnappedX( rRenderContext, nNewPosX, bSnapPixel );
        rArray.SetColWidth( nCol, std::abs( nNewSnapX - nOldSnapX ) );
        nOldPosX = nNewPosX;
        nOldSnapX = nNewSnapX;
@@ -1491,14 +1491,14 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext)
    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
    bool bCellContrast = mbUseStyleColor && rStyleSettings.GetHighContrastMode();

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
    {
        Size aOnePixel = rRenderContext.PixelToLogic(Size(1,1));
        long nOneX = aOnePixel.Width();
        tools::Long nOneX = aOnePixel.Width();
        nInitPosX += nMirrorW - nOneX;
    }
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    tools::Rectangle aClipRect( Point(nScrX, nScrY), Size(nScrW, nScrH) );
    if (bMetaFile)
@@ -1510,7 +1510,7 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext)
        rRenderContext.SetClipRegion( vcl::Region( aClipRect ) );

    std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(CreateProcessor2D( ));
    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    for (SCSIZE nArrY=1; nArrY<nArrCount; nArrY++)
    {
        // Rotated is also drawn one line above/below Changed if parts extend into the cell
@@ -1519,13 +1519,13 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext)
        RowInfo& rThisRowInfo = pRowInfo[nArrY];
        RowInfo& rNextRowInfo = pRowInfo[nArrY+1];

        long nRowHeight = rThisRowInfo.nHeight;
        tools::Long nRowHeight = rThisRowInfo.nHeight;
        if ( rThisRowInfo.nRotMaxCol != SC_ROTMAX_NONE &&
             ( rThisRowInfo.bChanged || rPrevRowInfo.bChanged ||
               ( nArrY+1<nArrCount && rNextRowInfo.bChanged ) ) )
        {
            SCROW nY = rThisRowInfo.nRowNo;
            long nPosX = 0;
            tools::Long nPosX = 0;
            SCCOL nX;
            for (nX=0; nX<=nRotMax; nX++)
            {
@@ -1534,7 +1534,7 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext)
                sal_uInt16 nArrX = nX + 1;

                CellInfo* pInfo = &rThisRowInfo.pCellInfo[nArrX];
                long nColWidth = pRowInfo[0].pCellInfo[nArrX].nWidth;
                tools::Long nColWidth = pRowInfo[0].pCellInfo[nArrX].nWidth;
                if ( pInfo->nRotateDir > ScRotateDir::Standard &&
                        !pInfo->bHOverlapped && !pInfo->bVOverlapped )
                {
@@ -1550,7 +1550,7 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext)

                    //! LastPattern etc.

                    long nAttrRotate = pPattern->GetRotateVal( pCondSet );
                    tools::Long nAttrRotate = pPattern->GetRotateVal( pCondSet );
                    SvxRotateMode eRotMode =
                                    pPattern->GetItem(ATTR_ROTATE_MODE, pCondSet).GetValue();

@@ -1563,19 +1563,19 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext)
                            while (nCol > nX)
                            {
                                --nCol;
                                nPosX -= nLayoutSign * static_cast<long>(pRowInfo[0].pCellInfo[nCol + 1].nWidth);
                                nPosX -= nLayoutSign * static_cast<tools::Long>(pRowInfo[0].pCellInfo[nCol + 1].nWidth);
                            }
                        }

                        // start position minus 1 so rotated backgrounds suit the border
                        // (border is on the grid)

                        long nTop = nPosY - 1;
                        long nBottom = nPosY + nRowHeight - 1;
                        long nTopLeft = nPosX - nLayoutSign;
                        long nTopRight = nPosX + (nColWidth - 1) * nLayoutSign;
                        long nBotLeft = nTopLeft;
                        long nBotRight = nTopRight;
                        tools::Long nTop = nPosY - 1;
                        tools::Long nBottom = nPosY + nRowHeight - 1;
                        tools::Long nTopLeft = nPosX - nLayoutSign;
                        tools::Long nTopRight = nPosX + (nColWidth - 1) * nLayoutSign;
                        tools::Long nBotLeft = nTopLeft;
                        tools::Long nBotRight = nTopRight;

                        // inclusion of the sign here hasn't been decided yet
                        // (if not, the extension of the non-rotated background must also be changed)
@@ -1583,7 +1583,7 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext)
                        double nCos = cos(nRealOrient);
                        double nSin = sin(nRealOrient);
                        //! restrict !!!
                        long nSkew = static_cast<long>(nRowHeight * nCos / nSin);
                        tools::Long nSkew = static_cast<tools::Long>(nRowHeight * nCos / nSin);

                        switch (eRotMode)
                        {
@@ -1706,7 +1706,7 @@ vcl::Region ScOutputData::GetChangedAreaRegion()
    vcl::Region aRegion;
    tools::Rectangle aDrawingRect;
    bool bHad(false);
    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    SCSIZE nArrY;

    aDrawingRect.SetLeft( nScrX );
@@ -1752,7 +1752,7 @@ bool ScOutputData::SetChangedClip()
    aDrawingRect.SetRight( nScrX+nScrW-1 );

    bool    bHad    = false;
    long    nPosY   = nScrY;
    tools::Long    nPosY   = nScrY;
    SCSIZE  nArrY;
    for (nArrY=1; nArrY+1<nArrCount; nArrY++)
    {
@@ -1893,24 +1893,24 @@ ReferenceMark ScOutputData::FillReferenceMark( SCCOL nRefStartX, SCROW nRefStart
    if ( nRefStartX <= nVisX2 && nRefEndX >= nVisX1 &&
         nRefStartY <= nVisY2 && nRefEndY >= nVisY1 )
    {
        long nMinX = nScrX;
        long nMinY = nScrY;
        long nMaxX = nScrX + nScrW - 1;
        long nMaxY = nScrY + nScrH - 1;
        tools::Long nMinX = nScrX;
        tools::Long nMinY = nScrY;
        tools::Long nMaxX = nScrX + nScrW - 1;
        tools::Long nMaxY = nScrY + nScrH - 1;
        if ( bLayoutRTL )
        {
            long nTemp = nMinX;
            tools::Long nTemp = nMinX;
            nMinX = nMaxX;
            nMaxX = nTemp;
        }
        long nLayoutSign = bLayoutRTL ? -1 : 1;
        tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

        bool bTop    = false;
        bool bBottom = false;
        bool bLeft   = false;
        bool bRight  = false;

        long nPosY = nScrY;
        tools::Long nPosY = nScrY;
        bool bNoStartY = ( nY1 < nRefStartY );
        bool bNoEndY   = false;
        for (SCSIZE nArrY=1; nArrY<nArrCount; nArrY++)      // loop to end for bNoEndY check
@@ -1937,7 +1937,7 @@ ReferenceMark ScOutputData::FillReferenceMark( SCCOL nRefStartX, SCROW nRefStart
            nPosY += pRowInfo[nArrY].nHeight;
        }

        long nPosX = nScrX;
        tools::Long nPosX = nScrX;
        if ( bLayoutRTL )
            nPosX += nMirrorW - 1;      // always in pixels

@@ -1985,24 +1985,24 @@ void ScOutputData::DrawRefMark( SCCOL nRefStartX, SCROW nRefStartY,
         nRefStartY <= nVisY2 && nRefEndY >= nVisY1) )
        return;

    long nMinX = nScrX;
    long nMinY = nScrY;
    long nMaxX = nScrX + nScrW - 1;
    long nMaxY = nScrY + nScrH - 1;
    tools::Long nMinX = nScrX;
    tools::Long nMinY = nScrY;
    tools::Long nMaxX = nScrX + nScrW - 1;
    tools::Long nMaxY = nScrY + nScrH - 1;
    if ( bLayoutRTL )
    {
        long nTemp = nMinX;
        tools::Long nTemp = nMinX;
        nMinX = nMaxX;
        nMaxX = nTemp;
    }
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    bool bTop    = false;
    bool bBottom = false;
    bool bLeft   = false;
    bool bRight  = false;

    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    bool bNoStartY = ( nY1 < nRefStartY );
    bool bNoEndY   = false;
    for (SCSIZE nArrY=1; nArrY<nArrCount; nArrY++)      // loop to end for bNoEndY check
@@ -2029,7 +2029,7 @@ void ScOutputData::DrawRefMark( SCCOL nRefStartX, SCROW nRefStartY,
        nPosY += pRowInfo[nArrY].nHeight;
    }

    long nPosX = nScrX;
    tools::Long nPosX = nScrX;
    if ( bLayoutRTL )
        nPosX += nMirrorW - 1;      // always in pixels

@@ -2112,24 +2112,24 @@ void ScOutputData::DrawOneChange( SCCOL nRefStartX, SCROW nRefStartY,
         nRefStartY <= nVisY2 + 1 && nRefEndY >= nVisY1) )       // +1 because it touches next cells left/top
        return;

    long nMinX = nScrX;
    long nMinY = nScrY;
    long nMaxX = nScrX+nScrW-1;
    long nMaxY = nScrY+nScrH-1;
    tools::Long nMinX = nScrX;
    tools::Long nMinY = nScrY;
    tools::Long nMaxX = nScrX+nScrW-1;
    tools::Long nMaxY = nScrY+nScrH-1;
    if ( bLayoutRTL )
    {
        long nTemp = nMinX;
        tools::Long nTemp = nMinX;
        nMinX = nMaxX;
        nMaxX = nTemp;
    }
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    bool bTop    = false;
    bool bBottom = false;
    bool bLeft   = false;
    bool bRight  = false;

    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    bool bNoStartY = ( nY1 < nRefStartY );
    bool bNoEndY   = false;
    for (SCSIZE nArrY=1; nArrY<nArrCount; nArrY++)      // loop to end for bNoEndY check
@@ -2156,7 +2156,7 @@ void ScOutputData::DrawOneChange( SCCOL nRefStartX, SCROW nRefStartY,
        nPosY += pRowInfo[nArrY].nHeight;
    }

    long nPosX = nScrX;
    tools::Long nPosX = nScrX;
    if ( bLayoutRTL )
        nPosX += nMirrorW - 1;      // always in pixels

@@ -2286,18 +2286,18 @@ void ScOutputData::DrawNoteMarks(vcl::RenderContext& rRenderContext)

    bool bFirst = true;

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
        nInitPosX += nMirrorW - 1;              // always in pixels
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    for (SCSIZE nArrY=1; nArrY+1<nArrCount; nArrY++)
    {
        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
        if ( pThisRowInfo->bChanged )
        {
            long nPosX = nInitPosX;
            tools::Long nPosX = nInitPosX;
            for (SCCOL nX=nX1; nX<=nX2; nX++)
            {
                CellInfo* pInfo = &pThisRowInfo->pCellInfo[nX+1];
@@ -2330,7 +2330,7 @@ void ScOutputData::DrawNoteMarks(vcl::RenderContext& rRenderContext)
                        bFirst = false;
                    }

                    long nMarkX = nPosX + ( pRowInfo[0].pCellInfo[nX+1].nWidth - 4 ) * nLayoutSign;
                    tools::Long nMarkX = nPosX + ( pRowInfo[0].pCellInfo[nX+1].nWidth - 4 ) * nLayoutSign;
                    if ( bIsMerged || pInfo->bMerged )
                    {
                        //  if merged, add widths of all cells
@@ -2358,22 +2358,22 @@ void ScOutputData::AddPDFNotes()
    if ( !pPDFData || !pPDFData->GetIsExportNotes() )
        return;

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
    {
        Size aOnePixel = mpDev->PixelToLogic(Size(1,1));
        long nOneX = aOnePixel.Width();
        tools::Long nOneX = aOnePixel.Width();
        nInitPosX += nMirrorW - nOneX;
    }
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    for (SCSIZE nArrY=1; nArrY+1<nArrCount; nArrY++)
    {
        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
        if ( pThisRowInfo->bChanged )
        {
            long nPosX = nInitPosX;
            tools::Long nPosX = nInitPosX;
            for (SCCOL nX=nX1; nX<=nX2; nX++)
            {
                CellInfo* pInfo = &pThisRowInfo->pCellInfo[nX+1];
@@ -2393,10 +2393,10 @@ void ScOutputData::AddPDFNotes()
                if ( mpDoc->GetNote(nMergeX, nMergeY, nTab) && ( bIsMerged ||
                        ( !pInfo->bHOverlapped && !pInfo->bVOverlapped ) ) )
                {
                    long nNoteWidth = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTX );
                    long nNoteHeight = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTY );
                    tools::Long nNoteWidth = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTX );
                    tools::Long nNoteHeight = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTY );

                    long nMarkX = nPosX + ( pRowInfo[0].pCellInfo[nX+1].nWidth - nNoteWidth ) * nLayoutSign;
                    tools::Long nMarkX = nPosX + ( pRowInfo[0].pCellInfo[nX+1].nWidth - nNoteWidth ) * nLayoutSign;
                    if ( bIsMerged || pInfo->bMerged )
                    {
                        //  if merged, add widths of all cells
@@ -2451,20 +2451,20 @@ void ScOutputData::DrawClipMarks()
        aArrowFillCol = SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor;
    }

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
        nInitPosX += nMirrorW - 1;              // always in pixels
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    tools::Rectangle aCellRect;
    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    for (SCSIZE nArrY=1; nArrY+1<nArrCount; nArrY++)
    {
        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
        if ( pThisRowInfo->bChanged )
        {
            SCROW nY = pThisRowInfo->nRowNo;
            long nPosX = nInitPosX;
            tools::Long nPosX = nInitPosX;
            for (SCCOL nX=nX1; nX<=nX2; nX++)
            {
                CellInfo* pInfo = &pThisRowInfo->pCellInfo[nX+1];
@@ -2476,32 +2476,32 @@ void ScOutputData::DrawClipMarks()

                        SCCOL nOverX = nX;
                        SCROW nOverY = nY;
                        long nStartPosX = nPosX;
                        long nStartPosY = nPosY;
                        tools::Long nStartPosX = nPosX;
                        tools::Long nStartPosY = nPosY;

                        while ( nOverX > 0 && ( mpDoc->GetAttr(
                                nOverX, nOverY, nTab, ATTR_MERGE_FLAG )->GetValue() & ScMF::Hor ) )
                        {
                            --nOverX;
                            nStartPosX -= nLayoutSign * static_cast<long>( mpDoc->GetColWidth(nOverX,nTab) * mnPPTX );
                            nStartPosX -= nLayoutSign * static_cast<tools::Long>( mpDoc->GetColWidth(nOverX,nTab) * mnPPTX );
                        }

                        while ( nOverY > 0 && ( mpDoc->GetAttr(
                                nOverX, nOverY, nTab, ATTR_MERGE_FLAG )->GetValue() & ScMF::Ver ) )
                        {
                            --nOverY;
                            nStartPosY -= nLayoutSign * static_cast<long>( mpDoc->GetRowHeight(nOverY,nTab) * mnPPTY );
                            nStartPosY -= nLayoutSign * static_cast<tools::Long>( mpDoc->GetRowHeight(nOverY,nTab) * mnPPTY );
                        }

                        long nOutWidth = static_cast<long>( mpDoc->GetColWidth(nOverX,nTab) * mnPPTX );
                        long nOutHeight = static_cast<long>( mpDoc->GetRowHeight(nOverY,nTab) * mnPPTY );
                        tools::Long nOutWidth = static_cast<tools::Long>( mpDoc->GetColWidth(nOverX,nTab) * mnPPTX );
                        tools::Long nOutHeight = static_cast<tools::Long>( mpDoc->GetRowHeight(nOverY,nTab) * mnPPTY );

                        const ScMergeAttr* pMerge = mpDoc->GetAttr( nOverX, nOverY, nTab, ATTR_MERGE );
                        SCCOL nCountX = pMerge->GetColMerge();
                        for (SCCOL i=1; i<nCountX; i++)
                            nOutWidth += static_cast<long>( mpDoc->GetColWidth(nOverX+i,nTab) * mnPPTX );
                            nOutWidth += static_cast<tools::Long>( mpDoc->GetColWidth(nOverX+i,nTab) * mnPPTX );
                        SCROW nCountY = pMerge->GetRowMerge();
                        nOutHeight += static_cast<long>(mpDoc->GetScaledRowHeight( nOverY+1, nOverY+nCountY-1, nTab, mnPPTY));
                        nOutHeight += static_cast<tools::Long>(mpDoc->GetScaledRowHeight( nOverY+1, nOverY+nCountY-1, nTab, mnPPTY));

                        if ( bLayoutRTL )
                            nStartPosX -= nOutWidth - 1;
@@ -2509,8 +2509,8 @@ void ScOutputData::DrawClipMarks()
                    }
                    else
                    {
                        long nOutWidth = pRowInfo[0].pCellInfo[nX+1].nWidth;
                        long nOutHeight = pThisRowInfo->nHeight;
                        tools::Long nOutWidth = pRowInfo[0].pCellInfo[nX+1].nWidth;
                        tools::Long nOutHeight = pThisRowInfo->nHeight;

                        if ( pInfo->bMerged && pInfo->pPatternAttr )
                        {
@@ -2520,12 +2520,12 @@ void ScOutputData::DrawClipMarks()
                                    &pInfo->pPatternAttr->GetItem(ATTR_MERGE);
                            SCCOL nCountX = pMerge->GetColMerge();
                            for (SCCOL i=1; i<nCountX; i++)
                                nOutWidth += static_cast<long>( mpDoc->GetColWidth(nOverX+i,nTab) * mnPPTX );
                                nOutWidth += static_cast<tools::Long>( mpDoc->GetColWidth(nOverX+i,nTab) * mnPPTX );
                            SCROW nCountY = pMerge->GetRowMerge();
                            nOutHeight += static_cast<long>(mpDoc->GetScaledRowHeight( nOverY+1, nOverY+nCountY-1, nTab, mnPPTY));
                            nOutHeight += static_cast<tools::Long>(mpDoc->GetScaledRowHeight( nOverY+1, nOverY+nCountY-1, nTab, mnPPTY));
                        }

                        long nStartPosX = nPosX;
                        tools::Long nStartPosX = nPosX;
                        if ( bLayoutRTL )
                            nStartPosX -= nOutWidth - 1;
                        // #i80447# create aCellRect from two points in case nOutWidth is 0
@@ -2539,7 +2539,7 @@ void ScOutputData::DrawClipMarks()
                    else
                        aCellRect.AdjustRight( -1 );

                    long nMarkPixel = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTX );
                    tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTX );
                    Size aMarkSize( nMarkPixel, (nMarkPixel-1)*2 );

                    if ( pInfo->nClipMark & ( bLayoutRTL ? ScClipMark::Right : ScClipMark::Left ) )
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 39aaf01..c25d8ab 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -96,7 +96,7 @@ class ScDrawStringsVars

    vcl::Font           aFont;                  // created from attributes
    FontMetric          aMetric;
    long                nAscentPixel;           // always pixels
    tools::Long                nAscentPixel;           // always pixels
    SvxCellOrientation  eAttrOrient;
    SvxCellHorJustify   eAttrHorJust;
    SvxCellVerJustify   eAttrVerJust;
@@ -107,11 +107,11 @@ class ScDrawStringsVars

    OUString            aString;                // contents
    Size                aTextSize;
    long                nOriginalWidth;
    long                nMaxDigitWidth;
    long                nSignWidth;
    long                nDotWidth;
    long                nExpWidth;
    tools::Long                nOriginalWidth;
    tools::Long                nMaxDigitWidth;
    tools::Long                nSignWidth;
    tools::Long                nDotWidth;
    tools::Long                nExpWidth;

    ScRefCellValue      maLastCell;
    sal_uLong           nValueFormat;
@@ -141,7 +141,7 @@ public:

    bool SetText( const ScRefCellValue& rCell );   // TRUE -> drop pOldPattern
    void        SetHashText();
    void SetTextToWidthOrHash( ScRefCellValue& rCell, long nWidth );
    void SetTextToWidthOrHash( ScRefCellValue& rCell, tools::Long nWidth );
    void        SetAutoText( const OUString& rAutoText );

    SvxCellOrientation      GetOrient() const        { return eAttrOrient; }
@@ -155,7 +155,7 @@ public:

    const OUString&         GetString() const        { return aString; }
    const Size&             GetTextSize() const      { return aTextSize; }
    long                    GetOriginalWidth() const { return nOriginalWidth; }
    tools::Long                    GetOriginalWidth() const { return nOriginalWidth; }

    // Get the effective number format, including formula result types.
    // This assumes that a formula cell has already been calculated.
@@ -164,12 +164,12 @@ public:
    bool    GetLineBreak() const                    { return bLineBreak; }
    bool    IsRepeat() const                        { return bRepeat; }
    bool    IsShrink() const                        { return bShrink; }
    void        RepeatToFill( long nColWidth );
    void        RepeatToFill( tools::Long nColWidth );

    long    GetAscent() const   { return nAscentPixel; }
    tools::Long    GetAscent() const   { return nAscentPixel; }
    bool    IsRotated() const   { return bRotated; }

    void    SetShrinkScale( long nScale, SvtScriptType nScript );
    void    SetShrinkScale( tools::Long nScale, SvtScriptType nScript );

    bool    HasCondHeight() const   { return pCondSet && SfxItemState::SET ==
                                        pCondSet->GetItemState( ATTR_FONT_HEIGHT ); }
@@ -177,10 +177,10 @@ public:
    bool    HasEditCharacters() const;

private:
    long        GetMaxDigitWidth();     // in logic units
    long        GetSignWidth();
    long        GetDotWidth();
    long        GetExpWidth();
    tools::Long        GetMaxDigitWidth();     // in logic units
    tools::Long        GetSignWidth();
    tools::Long        GetDotWidth();
    tools::Long        GetExpWidth();
    void        TextChanged();
};

@@ -218,7 +218,7 @@ ScDrawStringsVars::ScDrawStringsVars(ScOutputData* pData, bool bPTL) :
    aTextConfigColor = rColorConfig.GetColorValue(svtools::FONTCOLOR).nColor;
}

void ScDrawStringsVars::SetShrinkScale( long nScale, SvtScriptType nScript )
void ScDrawStringsVars::SetShrinkScale( tools::Long nScale, SvtScriptType nScript )
{
    // text remains valid, size is updated

@@ -233,7 +233,7 @@ void ScDrawStringsVars::SetShrinkScale( long nScale, SvtScriptType nScript )
        aFraction *= pOutput->aZoomY;
    vcl::Font aTmpFont;
    pPattern->GetFont( aTmpFont, SC_AUTOCOL_RAW, pFmtDevice, &aFraction, pCondSet, nScript );
    long nNewHeight = aTmpFont.GetFontHeight();
    tools::Long nNewHeight = aTmpFont.GetFontHeight();
    if ( nNewHeight > 0 )
        aFont.SetFontHeight( nNewHeight );

@@ -554,36 +554,36 @@ void ScDrawStringsVars::SetHashText()
    SetAutoText("###");
}

void ScDrawStringsVars::RepeatToFill( long nColWidth )
void ScDrawStringsVars::RepeatToFill( tools::Long nColWidth )
{
    if ( nRepeatPos == -1 || nRepeatPos > aString.getLength() )
        return;

    long nCharWidth = pOutput->pFmtDevice->GetTextWidth(OUString(nRepeatChar));
    tools::Long nCharWidth = pOutput->pFmtDevice->GetTextWidth(OUString(nRepeatChar));

    if ( nCharWidth < 1 || (bPixelToLogic && nCharWidth < pOutput->mpRefDevice->PixelToLogic(Size(1,0)).Width()) )
        return;

    // Are there restrictions on the cell type we should filter out here ?
    long nTextWidth = aTextSize.Width();
    tools::Long nTextWidth = aTextSize.Width();
    if ( bPixelToLogic )
    {
        nColWidth = pOutput->mpRefDevice->PixelToLogic(Size(nColWidth,0)).Width();
        nTextWidth = pOutput->mpRefDevice->PixelToLogic(Size(nTextWidth,0)).Width();
    }

    long nSpaceToFill = nColWidth - nTextWidth;
    tools::Long nSpaceToFill = nColWidth - nTextWidth;
    if ( nSpaceToFill <= nCharWidth )
        return;

    long nCharsToInsert = nSpaceToFill / nCharWidth;
    tools::Long nCharsToInsert = nSpaceToFill / nCharWidth;
    OUStringBuffer aFill;
    comphelper::string::padToLength(aFill, nCharsToInsert, nRepeatChar);
    aString = aString.replaceAt( nRepeatPos, 0, aFill.makeStringAndClear() );
    TextChanged();
}

void ScDrawStringsVars::SetTextToWidthOrHash( ScRefCellValue& rCell, long nWidth )
void ScDrawStringsVars::SetTextToWidthOrHash( ScRefCellValue& rCell, tools::Long nWidth )
{
    // #i113045# do the single-character width calculations in logic units
    if (bPixelToLogic)
@@ -621,7 +621,7 @@ void ScDrawStringsVars::SetTextToWidthOrHash( ScRefCellValue& rCell, long nWidth
    if (!pNumFormat)
        return;

    long nMaxDigit = GetMaxDigitWidth();
    tools::Long nMaxDigit = GetMaxDigitWidth();
    if (!nMaxDigit)
        return;

@@ -676,7 +676,7 @@ void ScDrawStringsVars::SetTextToWidthOrHash( ScRefCellValue& rCell, long nWidth
        aString = sTempOut;
    }

    long nActualTextWidth = pOutput->pFmtDevice->GetTextWidth(aString);
    tools::Long nActualTextWidth = pOutput->pFmtDevice->GetTextWidth(aString);
    if (nActualTextWidth > nWidth)
    {
        // Even after the decimal adjustment the text doesn't fit.  Give up.
@@ -700,13 +700,13 @@ void ScDrawStringsVars::SetAutoText( const OUString& rAutoText )
    if ( !pRefDevice->GetConnectMetaFile() || pRefDevice->GetOutDevType() == OUTDEV_PRINTER )
    {
        double fMul = pOutput->GetStretch();
        aTextSize.setWidth( static_cast<long>(aTextSize.Width() / fMul + 0.5) );
        aTextSize.setWidth( static_cast<tools::Long>(aTextSize.Width() / fMul + 0.5) );
    }

    aTextSize.setHeight( aMetric.GetAscent() + aMetric.GetDescent() );
    if ( GetOrient() != SvxCellOrientation::Standard )
    {
        long nTemp = aTextSize.Height();
        tools::Long nTemp = aTextSize.Height();
        aTextSize.setHeight( aTextSize.Width() );
        aTextSize.setWidth( nTemp );
    }
@@ -718,7 +718,7 @@ void ScDrawStringsVars::SetAutoText( const OUString& rAutoText )
    maLastCell.clear();       // the same text may fit in the next cell
}

long ScDrawStringsVars::GetMaxDigitWidth()
tools::Long ScDrawStringsVars::GetMaxDigitWidth()
{
    if (nMaxDigitWidth > 0)
        return nMaxDigitWidth;
@@ -726,13 +726,13 @@ long ScDrawStringsVars::GetMaxDigitWidth()
    for (char i = 0; i < 10; ++i)
    {
        char cDigit = '0' + i;
        long n = pOutput->pFmtDevice->GetTextWidth(OUString(cDigit));
        tools::Long n = pOutput->pFmtDevice->GetTextWidth(OUString(cDigit));
        nMaxDigitWidth = ::std::max(nMaxDigitWidth, n);
    }
    return nMaxDigitWidth;
}

long ScDrawStringsVars::GetSignWidth()
tools::Long ScDrawStringsVars::GetSignWidth()
{
    if (nSignWidth > 0)
        return nSignWidth;
@@ -741,7 +741,7 @@ long ScDrawStringsVars::GetSignWidth()
    return nSignWidth;
}

long ScDrawStringsVars::GetDotWidth()
tools::Long ScDrawStringsVars::GetDotWidth()
{
    if (nDotWidth > 0)
        return nDotWidth;
@@ -751,7 +751,7 @@ long ScDrawStringsVars::GetDotWidth()
    return nDotWidth;
}

long ScDrawStringsVars::GetExpWidth()
tools::Long ScDrawStringsVars::GetExpWidth()
{
    if (nExpWidth > 0)
        return nExpWidth;
@@ -770,13 +770,13 @@ void ScDrawStringsVars::TextChanged()
    if ( !pRefDevice->GetConnectMetaFile() || pRefDevice->GetOutDevType() == OUTDEV_PRINTER )
    {
        double fMul = pOutput->GetStretch();
        aTextSize.setWidth( static_cast<long>(aTextSize.Width() / fMul + 0.5) );
        aTextSize.setWidth( static_cast<tools::Long>(aTextSize.Width() / fMul + 0.5) );
    }

    aTextSize.setHeight( aMetric.GetAscent() + aMetric.GetDescent() );
    if ( GetOrient() != SvxCellOrientation::Standard )
    {
        long nTemp = aTextSize.Height();
        tools::Long nTemp = aTextSize.Height();
        aTextSize.setHeight( aTextSize.Width() );
        aTextSize.setWidth( nTemp );
    }
@@ -1161,8 +1161,8 @@ bool ScOutputData::IsAvailable( SCCOL nX, SCROW nY )
// bOverwrite:      if set, also extend into non-empty cells (for rotated text)
// rParam           output: various area parameters.

void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY,
                                  SCCOL nCellX, SCROW nCellY, long nNeeded,
void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, tools::Long nPosX, tools::Long nPosY,
                                  SCCOL nCellX, SCROW nCellY, tools::Long nNeeded,
                                  const ScPatternAttr& rPattern,
                                  sal_uInt16 nHorJustify, bool bCellIsValue,
                                  bool bBreak, bool bOverwrite,
@@ -1171,29 +1171,29 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
    //  rThisRowInfo may be for a different row than nCellY, is still used for clip marks
    RowInfo& rThisRowInfo = pRowInfo[nArrY];

    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    long nCellPosX = nPosX;         // find nCellX position, starting at nX/nPosX
    tools::Long nCellPosX = nPosX;         // find nCellX position, starting at nX/nPosX
    SCCOL nCompCol = nX;
    while ( nCellX > nCompCol )
    {
        //! extra member function for width?
        long nColWidth = ( nCompCol <= nX2 ) ?
        tools::Long nColWidth = ( nCompCol <= nX2 ) ?
                pRowInfo[0].pCellInfo[nCompCol+1].nWidth :
                static_cast<long>( mpDoc->GetColWidth( nCompCol, nTab ) * mnPPTX );
                static_cast<tools::Long>( mpDoc->GetColWidth( nCompCol, nTab ) * mnPPTX );
        nCellPosX += nColWidth * nLayoutSign;
        ++nCompCol;
    }
    while ( nCellX < nCompCol )
    {
        --nCompCol;
        long nColWidth = ( nCompCol <= nX2 ) ?
        tools::Long nColWidth = ( nCompCol <= nX2 ) ?
                pRowInfo[0].pCellInfo[nCompCol+1].nWidth :
                static_cast<long>( mpDoc->GetColWidth( nCompCol, nTab ) * mnPPTX );
                static_cast<tools::Long>( mpDoc->GetColWidth( nCompCol, nTab ) * mnPPTX );
        nCellPosX -= nColWidth * nLayoutSign;
    }

    long nCellPosY = nPosY;         // find nCellY position, starting at nArrY/nPosY
    tools::Long nCellPosY = nPosY;         // find nCellY position, starting at nArrY/nPosY
    SCSIZE nCompArr = nArrY;
    SCROW nCompRow = pRowInfo[nCompArr].nRowNo;
    while ( nCellY > nCompRow )
@@ -1208,30 +1208,30 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
        {
            sal_uInt16 nDocHeight = mpDoc->GetRowHeight( nCompRow, nTab );
            if ( nDocHeight )
                nCellPosY += static_cast<long>( nDocHeight * mnPPTY );
                nCellPosY += static_cast<tools::Long>( nDocHeight * mnPPTY );
            ++nCompRow;
        }
    }
    nCellPosY -= static_cast<long>(mpDoc->GetScaledRowHeight( nCellY, nCompRow-1, nTab, mnPPTY ));
    nCellPosY -= static_cast<tools::Long>(mpDoc->GetScaledRowHeight( nCellY, nCompRow-1, nTab, mnPPTY ));

    const ScMergeAttr* pMerge = &rPattern.GetItem( ATTR_MERGE );
    bool bMerged = pMerge->IsMerged();
    long nMergeCols = pMerge->GetColMerge();
    tools::Long nMergeCols = pMerge->GetColMerge();
    if ( nMergeCols == 0 )
        nMergeCols = 1;
    long nMergeRows = pMerge->GetRowMerge();
    tools::Long nMergeRows = pMerge->GetRowMerge();
    if ( nMergeRows == 0 )
        nMergeRows = 1;

    long nMergeSizeX = 0;
    for ( long i=0; i<nMergeCols; i++ )
    tools::Long nMergeSizeX = 0;
    for ( tools::Long i=0; i<nMergeCols; i++ )
    {
        long nColWidth = ( nCellX+i <= nX2 ) ?
        tools::Long nColWidth = ( nCellX+i <= nX2 ) ?
                pRowInfo[0].pCellInfo[nCellX+i+1].nWidth :
                static_cast<long>( mpDoc->GetColWidth( sal::static_int_cast<SCCOL>(nCellX+i), nTab ) * mnPPTX );
                static_cast<tools::Long>( mpDoc->GetColWidth( sal::static_int_cast<SCCOL>(nCellX+i), nTab ) * mnPPTX );
        nMergeSizeX += nColWidth;
    }
    long nMergeSizeY = 0;
    tools::Long nMergeSizeY = 0;
    short nDirect = 0;
    if ( rThisRowInfo.nRowNo == nCellY )
    {
@@ -1240,7 +1240,7 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
        nDirect = 1;        // skip in loop
    }
    // following rows always from document
    nMergeSizeY += static_cast<long>(mpDoc->GetScaledRowHeight( nCellY+nDirect, nCellY+nMergeRows-1, nTab, mnPPTY));
    nMergeSizeY += static_cast<tools::Long>(mpDoc->GetScaledRowHeight( nCellY+nDirect, nCellY+nMergeRows-1, nTab, mnPPTY));

    --nMergeSizeX;      // leave out the grid horizontally, also for alignment (align between grid lines)

@@ -1264,9 +1264,9 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
    {
        SvxCellHorJustify eHorJust = static_cast<SvxCellHorJustify>(nHorJustify);

        long nMissing = nNeeded - nMergeSizeX;
        long nLeftMissing = 0;
        long nRightMissing = 0;
        tools::Long nMissing = nNeeded - nMergeSizeX;
        tools::Long nLeftMissing = 0;
        tools::Long nRightMissing = 0;
        switch ( eHorJust )
        {
            case SvxCellHorJustify::Left:
@@ -1298,7 +1298,7 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
            while ( nRightMissing > 0 && nRightX < mpDoc->MaxCol() && ( bOverwrite || IsAvailable( nRightX+1, nCellY ) ) )
            {
                ++nRightX;
                long nAdd = static_cast<long>( mpDoc->GetColWidth( nRightX, nTab ) * mnPPTX );
                tools::Long nAdd = static_cast<tools::Long>( mpDoc->GetColWidth( nRightX, nTab ) * mnPPTX );
                nRightMissing -= nAdd;
                rParam.maClipRect.AdjustRight(nAdd * nLayoutSign );

@@ -1312,7 +1312,7 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
                    rThisRowInfo.pCellInfo[nLeftX].bHideGrid = true;

                --nLeftX;
                long nAdd = static_cast<long>( mpDoc->GetColWidth( nLeftX, nTab ) * mnPPTX );
                tools::Long nAdd = static_cast<tools::Long>( mpDoc->GetColWidth( nLeftX, nTab ) * mnPPTX );
                nLeftMissing -= nAdd;
                rParam.maClipRect.AdjustLeft( -(nAdd * nLayoutSign) );
            }
@@ -1324,14 +1324,14 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
        {
            rThisRowInfo.pCellInfo[nRightX+1].nClipMark |= ScClipMark::Right;
            bAnyClipped = true;
            long nMarkPixel = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTX );
            tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTX );
            rParam.maClipRect.AdjustRight( -(nMarkPixel * nLayoutSign) );
        }
        if ( nLeftMissing > 0 && bMarkClipped && nLeftX >= nX1 && nLeftX <= nX2 && !bBreak && !bCellIsValue )
        {
            rThisRowInfo.pCellInfo[nLeftX+1].nClipMark |= ScClipMark::Left;
            bAnyClipped = true;
            long nMarkPixel = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTX );
            tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTX );
            rParam.maClipRect.AdjustLeft(nMarkPixel * nLayoutSign );
        }

@@ -1352,7 +1352,7 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
             ( !bBreak || mpRefDevice == pFmtDevice ) )
        {
            // filter drop-down width is now independent from row height
            const long nFilter = DROPDOWN_BITMAP_SIZE;
            const tools::Long nFilter = DROPDOWN_BITMAP_SIZE;
            bool bFit = ( nNeeded + nFilter <= nMergeSizeX );
            if ( bFit )
            {
@@ -1461,10 +1461,10 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co

    bool bProgress = false;

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
        nInitPosX += nMirrorW - 1;              // pixels
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    SCCOL nLastContentCol = mpDoc->MaxCol();
    if ( nX2 < mpDoc->MaxCol() )
@@ -1477,7 +1477,7 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
    // variables for GetOutputArea
    OutputAreaParam aAreaParam;
    bool bCellIsValue = false;
    long nNeededWidth = 0;
    tools::Long nNeededWidth = 0;
    const ScPatternAttr* pPattern = nullptr;
    const SfxItemSet* pCondSet = nullptr;
    const ScPatternAttr* pOldPattern = nullptr;
@@ -1489,14 +1489,14 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
    std::vector<std::unique_ptr<ScPatternAttr> > aAltPatterns;

    std::vector<long> aDX;
    long nPosY = nScrY;
    tools::Long nPosY = nScrY;
    for (SCSIZE nArrY=1; nArrY+1<nArrCount; nArrY++)
    {
        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
        SCROW nY = pThisRowInfo->nRowNo;
        if ((bPaint && pThisRowInfo->bChanged) || (!bPaint && rAddress.Row() == nY))
        {
            long nPosX = nInitPosX;
            tools::Long nPosX = nInitPosX;
            if ( nLoopStartX < nX1 )
                nPosX -= pRowInfo[0].pCellInfo[nLoopStartX+1].nWidth * nLayoutSign;
            for (SCCOL nX=nLoopStartX; nX<=nX2; nX++)
@@ -1696,7 +1696,7 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                        pOldPattern = nullptr;
                    bUseEditEngine = aVars.HasEditCharacters() || (bFormulaCell && aCell.mpFormula->IsMultilineResult());
                }
                long nTotalMargin = 0;
                tools::Long nTotalMargin = 0;
                SvxCellHorJustify eOutHorJust = SvxCellHorJustify::Standard;
                if (bDoCell && !bUseEditEngine)
                {
@@ -1723,8 +1723,8 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                    bool bShrink = aVars.IsShrink() && !bBreak && !bRepeat;

                    nTotalMargin =
                        static_cast<long>(aVars.GetLeftTotal() * mnPPTX) +
                        static_cast<long>(aVars.GetMargin()->GetRightMargin() * mnPPTX);
                        static_cast<tools::Long>(aVars.GetLeftTotal() * mnPPTX) +
                        static_cast<tools::Long>(aVars.GetMargin()->GetRightMargin() * mnPPTX);

                    nNeededWidth = aVars.GetTextSize().Width() + nTotalMargin;

@@ -1745,15 +1745,15 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                        }
                        else if ( aAreaParam.mbLeftClip || aAreaParam.mbRightClip )     // horizontal
                        {
                            long nAvailable = aAreaParam.maAlignRect.GetWidth() - nTotalMargin;
                            long nScaleSize = aVars.GetTextSize().Width();         // without margin
                            tools::Long nAvailable = aAreaParam.maAlignRect.GetWidth() - nTotalMargin;
                            tools::Long nScaleSize = aVars.GetTextSize().Width();         // without margin

                            if ( nAvailable > 0 && nScaleSize > 0 )       // 0 if the text is empty (formulas, number formats)
                            {
                                long nScale = ( nAvailable * 100 ) / nScaleSize;
                                tools::Long nScale = ( nAvailable * 100 ) / nScaleSize;

                                aVars.SetShrinkScale( nScale, nOldScript );
                                long nNewSize = aVars.GetTextSize().Width();
                                tools::Long nNewSize = aVars.GetTextSize().Width();

                                sal_uInt16 nShrinkAgain = 0;
                                while ( nNewSize > nAvailable && nShrinkAgain < SC_SHRINKAGAIN_MAX )
@@ -1782,20 +1782,20 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co

                    if ( bRepeat && !aAreaParam.mbLeftClip && !aAreaParam.mbRightClip )
                    {
                        long nAvailable = aAreaParam.maAlignRect.GetWidth() - nTotalMargin;
                        long nRepeatSize = aVars.GetTextSize().Width();         // without margin
                        tools::Long nAvailable = aAreaParam.maAlignRect.GetWidth() - nTotalMargin;
                        tools::Long nRepeatSize = aVars.GetTextSize().Width();         // without margin
                        // When formatting for the printer, the text sizes don't always add up.
                        // Round down (too few repetitions) rather than exceeding the cell size then:
                        if ( pFmtDevice != mpRefDevice )
                            ++nRepeatSize;
                        if ( nRepeatSize > 0 )
                        {
                            long nRepeatCount = nAvailable / nRepeatSize;
                            tools::Long nRepeatCount = nAvailable / nRepeatSize;
                            if ( nRepeatCount > 1 )
                            {
                                OUString aCellStr = aVars.GetString();
                                OUStringBuffer aRepeated = aCellStr;
                                for ( long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ )
                                for ( tools::Long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ )
                                    aRepeated.append(aCellStr);
                                aVars.SetAutoText( aRepeated.makeStringAndClear() );
                            }
@@ -1809,9 +1809,9 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                            bUseEditEngine = ( aAreaParam.mbLeftClip || aAreaParam.mbRightClip );
                        else
                        {
                            long nHeight = aVars.GetTextSize().Height() +
                                            static_cast<long>(aVars.GetMargin()->GetTopMargin()*mnPPTY) +
                                            static_cast<long>(aVars.GetMargin()->GetBottomMargin()*mnPPTY);
                            tools::Long nHeight = aVars.GetTextSize().Height() +
                                            static_cast<tools::Long>(aVars.GetMargin()->GetTopMargin()*mnPPTY) +
                                            static_cast<tools::Long>(aVars.GetMargin()->GetBottomMargin()*mnPPTY);
                            bUseEditEngine = ( nHeight > aAreaParam.maClipRect.GetHeight() );
                        }
                    }
@@ -1843,8 +1843,8 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                            aVars.SetTextToWidthOrHash(aCell, aAreaParam.mnColWidth - nTotalMargin);

                        nNeededWidth = aVars.GetTextSize().Width() +
                                    static_cast<long>( aVars.GetLeftTotal() * mnPPTX ) +
                                    static_cast<long>( aVars.GetMargin()->GetRightMargin() * mnPPTX );
                                    static_cast<tools::Long>( aVars.GetLeftTotal() * mnPPTX ) +
                                    static_cast<tools::Long>( aVars.GetMargin()->GetRightMargin() * mnPPTX );
                        if ( nNeededWidth <= aAreaParam.maClipRect.GetWidth() )
                        {
                            // Cell value is no longer clipped.  Reset relevant parameters.
@@ -1857,10 +1857,10 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                        //  The rectangles from the first GetOutputArea call remain valid.
                    }

                    long nJustPosX = aAreaParam.maAlignRect.Left();     // "justified" - effect of alignment will be added
                    long nJustPosY = aAreaParam.maAlignRect.Top();
                    long nAvailWidth = aAreaParam.maAlignRect.GetWidth();
                    long nOutHeight = aAreaParam.maAlignRect.GetHeight();
                    tools::Long nJustPosX = aAreaParam.maAlignRect.Left();     // "justified" - effect of alignment will be added
                    tools::Long nJustPosY = aAreaParam.maAlignRect.Top();
                    tools::Long nAvailWidth = aAreaParam.maAlignRect.GetWidth();
                    tools::Long nOutHeight = aAreaParam.maAlignRect.GetHeight();

                    bool bOutside = ( aAreaParam.maClipRect.Right() < nScrX || aAreaParam.maClipRect.Left() >= nScrX + nScrW );
                    // Take adjusted values of aAreaParam.mbLeftClip and aAreaParam.mbRightClip
@@ -1875,17 +1875,17 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                        switch (eOutHorJust)
                        {
                            case SvxCellHorJustify::Left:
                                nJustPosX += static_cast<long>( aVars.GetLeftTotal() * mnPPTX );
                                nJustPosX += static_cast<tools::Long>( aVars.GetLeftTotal() * mnPPTX );
                                break;
                            case SvxCellHorJustify::Right:
                                nJustPosX += nAvailWidth - aVars.GetTextSize().Width() -
                                            static_cast<long>( aVars.GetRightTotal() * mnPPTX );
                                            static_cast<tools::Long>( aVars.GetRightTotal() * mnPPTX );
                                bRightAdjusted = true;
                                break;
                            case SvxCellHorJustify::Center:
                                nJustPosX += ( nAvailWidth - aVars.GetTextSize().Width() +
                                            static_cast<long>( aVars.GetLeftTotal() * mnPPTX ) -
                                            static_cast<long>( aVars.GetMargin()->GetRightMargin() * mnPPTX ) ) / 2;
                                            static_cast<tools::Long>( aVars.GetLeftTotal() * mnPPTX ) -
                                            static_cast<tools::Long>( aVars.GetMargin()->GetRightMargin() * mnPPTX ) ) / 2;
                                break;
                            default:
                            {
@@ -1893,28 +1893,28 @@ tools::Rectangle ScOutputData::LayoutStrings(bool bPixelToLogic, bool bPaint, co
                            }
                        }

                        long nTestClipHeight = aVars.GetTextSize().Height();
                        tools::Long nTestClipHeight = aVars.GetTextSize().Height();
                        switch (aVars.GetVerJust())
                        {
                            case SvxCellVerJustify::Top:
                            case SvxCellVerJustify::Block:
                                {
                                    long nTop = static_cast<long>( aVars.GetMargin()->GetTopMargin() * mnPPTY );
                                    tools::Long nTop = static_cast<tools::Long>( aVars.GetMargin()->GetTopMargin() * mnPPTY );
                                    nJustPosY += nTop;
                                    nTestClipHeight += nTop;
                                }
                                break;
                            case SvxCellVerJustify::Bottom:
                                {
                                    long nBot = static_cast<long>( aVars.GetMargin()->GetBottomMargin() * mnPPTY );
                                    tools::Long nBot = static_cast<tools::Long>( aVars.GetMargin()->GetBottomMargin() * mnPPTY );
                                    nJustPosY += nOutHeight - aVars.GetTextSize().Height() - nBot;
                                    nTestClipHeight += nBot;
                                }
                                break;
                            case SvxCellVerJustify::Center:
                                {
                                    long nTop = static_cast<long>( aVars.GetMargin()->GetTopMargin() * mnPPTY );
                                    long nBot = static_cast<long>( aVars.GetMargin()->GetBottomMargin() * mnPPTY );
                                    tools::Long nTop = static_cast<tools::Long>( aVars.GetMargin()->GetTopMargin() * mnPPTY );
                                    tools::Long nBot = static_cast<tools::Long>( aVars.GetMargin()->GetBottomMargin() * mnPPTY );
                                    nJustPosY += ( nOutHeight + nTop -
                                                    aVars.GetTextSize().Height() - nBot ) / 2;
                                    nTestClipHeight += std::abs( nTop - nBot );
@@ -2170,7 +2170,7 @@ static bool lcl_SafeIsValue( ScRefCellValue& rCell )
    return false;
}

static void lcl_ScaleFonts( EditEngine& rEngine, long nPercent )
static void lcl_ScaleFonts( EditEngine& rEngine, tools::Long nPercent )
{
    bool bUpdateMode = rEngine.GetUpdateMode();
    if ( bUpdateMode )
@@ -2188,9 +2188,9 @@ static void lcl_ScaleFonts( EditEngine& rEngine, long nPercent )
            ESelection aSel( nPar, nStart, nPar, nEnd );
            SfxItemSet aAttribs = rEngine.GetAttribs( aSel );

            long nWestern = aAttribs.Get(EE_CHAR_FONTHEIGHT).GetHeight();
            long nCJK = aAttribs.Get(EE_CHAR_FONTHEIGHT_CJK).GetHeight();
            long nCTL = aAttribs.Get(EE_CHAR_FONTHEIGHT_CTL).GetHeight();
            tools::Long nWestern = aAttribs.Get(EE_CHAR_FONTHEIGHT).GetHeight();
            tools::Long nCJK = aAttribs.Get(EE_CHAR_FONTHEIGHT_CJK).GetHeight();
            tools::Long nCTL = aAttribs.Get(EE_CHAR_FONTHEIGHT_CTL).GetHeight();

            nWestern = ( nWestern * nPercent ) / 100;
            nCJK     = ( nCJK     * nPercent ) / 100;
@@ -2210,15 +2210,15 @@ static void lcl_ScaleFonts( EditEngine& rEngine, long nPercent )
        rEngine.SetUpdateMode( true );
}

static long lcl_GetEditSize( EditEngine& rEngine, bool bWidth, bool bSwap, long nAttrRotate )
static tools::Long lcl_GetEditSize( EditEngine& rEngine, bool bWidth, bool bSwap, tools::Long nAttrRotate )
{
    if ( bSwap )
        bWidth = !bWidth;

    if ( nAttrRotate )
    {
        long nRealWidth  = static_cast<long>(rEngine.CalcTextWidth());
        long nRealHeight = rEngine.GetTextHeight();
        tools::Long nRealWidth  = static_cast<tools::Long>(rEngine.CalcTextWidth());
        tools::Long nRealHeight = rEngine.GetTextHeight();

        // assuming standard mode, otherwise width isn't used

@@ -2226,26 +2226,26 @@ static long lcl_GetEditSize( EditEngine& rEngine, bool bWidth, bool bSwap, long 
        double nAbsCos = fabs( cos( nRealOrient ) );
        double nAbsSin = fabs( sin( nRealOrient ) );
        if ( bWidth )
            return static_cast<long>( nRealWidth * nAbsCos + nRealHeight * nAbsSin );
            return static_cast<tools::Long>( nRealWidth * nAbsCos + nRealHeight * nAbsSin );
        else
            return static_cast<long>( nRealHeight * nAbsCos + nRealWidth * nAbsSin );
            return static_cast<tools::Long>( nRealHeight * nAbsCos + nRealWidth * nAbsSin );
    }
    else if ( bWidth )
        return static_cast<long>(rEngine.CalcTextWidth());
        return static_cast<tools::Long>(rEngine.CalcTextWidth());
    else
        return rEngine.GetTextHeight();
}

void ScOutputData::ShrinkEditEngine( EditEngine& rEngine, const tools::Rectangle& rAlignRect,
            long nLeftM, long nTopM, long nRightM, long nBottomM,
            bool bWidth, SvxCellOrientation nOrient, long nAttrRotate, bool bPixelToLogic,
            long& rEngineWidth, long& rEngineHeight, long& rNeededPixel, bool& rLeftClip, bool& rRightClip )
            tools::Long nLeftM, tools::Long nTopM, tools::Long nRightM, tools::Long nBottomM,
            bool bWidth, SvxCellOrientation nOrient, tools::Long nAttrRotate, bool bPixelToLogic,
            tools::Long& rEngineWidth, tools::Long& rEngineHeight, tools::Long& rNeededPixel, bool& rLeftClip, bool& rRightClip )
{
    if ( !bWidth )
    {
        // vertical

        long nScaleSize = bPixelToLogic ?
        tools::Long nScaleSize = bPixelToLogic ?
            mpRefDevice->LogicToPixel(Size(0,rEngineHeight)).Height() : rEngineHeight;

        // Don't scale if it fits already.
@@ -2254,12 +2254,12 @@ void ScOutputData::ShrinkEditEngine( EditEngine& rEngine, const tools::Rectangle
            return;

        bool bSwap = ( nOrient == SvxCellOrientation::TopBottom || nOrient == SvxCellOrientation::BottomUp );
        long nAvailable = rAlignRect.GetHeight() - nTopM - nBottomM;
        long nScale = ( nAvailable * 100 ) / nScaleSize;
        tools::Long nAvailable = rAlignRect.GetHeight() - nTopM - nBottomM;
        tools::Long nScale = ( nAvailable * 100 ) / nScaleSize;

        lcl_ScaleFonts( rEngine, nScale );
        rEngineHeight = lcl_GetEditSize( rEngine, false, bSwap, nAttrRotate );
        long nNewSize = bPixelToLogic ?
        tools::Long nNewSize = bPixelToLogic ?
            mpRefDevice->LogicToPixel(Size(0,rEngineHeight)).Height() : rEngineHeight;

        sal_uInt16 nShrinkAgain = 0;
@@ -2275,7 +2275,7 @@ void ScOutputData::ShrinkEditEngine( EditEngine& rEngine, const tools::Rectangle

        // sizes for further processing (alignment etc):
        rEngineWidth = lcl_GetEditSize( rEngine, true, bSwap, nAttrRotate );
        long nPixelWidth = bPixelToLogic ?
        tools::Long nPixelWidth = bPixelToLogic ?
            mpRefDevice->LogicToPixel(Size(rEngineWidth,0)).Width() : rEngineWidth;
        rNeededPixel = nPixelWidth + nLeftM + nRightM;
    }
@@ -2283,17 +2283,17 @@ void ScOutputData::ShrinkEditEngine( EditEngine& rEngine, const tools::Rectangle
    {
        // horizontal

        long nAvailable = rAlignRect.GetWidth() - nLeftM - nRightM;
        long nScaleSize = rNeededPixel - nLeftM - nRightM;      // without margin
        tools::Long nAvailable = rAlignRect.GetWidth() - nLeftM - nRightM;
        tools::Long nScaleSize = rNeededPixel - nLeftM - nRightM;      // without margin

        if ( nScaleSize <= nAvailable )
            return;

        long nScale = ( nAvailable * 100 ) / nScaleSize;
        tools::Long nScale = ( nAvailable * 100 ) / nScaleSize;

        lcl_ScaleFonts( rEngine, nScale );
        rEngineWidth = lcl_GetEditSize( rEngine, true, false, nAttrRotate );
        long nNewSize = bPixelToLogic ?
        tools::Long nNewSize = bPixelToLogic ?
            mpRefDevice->LogicToPixel(Size(rEngineWidth,0)).Width() : rEngineWidth;

        sal_uInt16 nShrinkAgain = 0;
@@ -2450,7 +2450,7 @@ void ScOutputData::DrawEditParam::setPatternToEngine(bool bUseStyleColor)
    mpEngine->SetBackgroundColor( aBackCol );
}

void ScOutputData::DrawEditParam::calcMargins(long& rTopM, long& rLeftM, long& rBottomM, long& rRightM, double nPPTX, double nPPTY) const
void ScOutputData::DrawEditParam::calcMargins(tools::Long& rTopM, tools::Long& rLeftM, tools::Long& rBottomM, tools::Long& rRightM, double nPPTX, double nPPTY) const
{
    const SvxMarginItem& rMargin = mpPattern->GetItem(ATTR_MARGIN, mpCondSet);

@@ -2458,21 +2458,21 @@ void ScOutputData::DrawEditParam::calcMargins(long& rTopM, long& rLeftM, long& r
    if (meHorJustAttr == SvxCellHorJustify::Left || meHorJustAttr == SvxCellHorJustify::Right)
        nIndent = lcl_GetValue<ScIndentItem, sal_uInt16>(*mpPattern, ATTR_INDENT, mpCondSet);

    rLeftM   = static_cast<long>(((rMargin.GetLeftMargin() + nIndent) * nPPTX));
    rTopM    = static_cast<long>((rMargin.GetTopMargin() * nPPTY));
    rRightM  = static_cast<long>((rMargin.GetRightMargin() * nPPTX));
    rBottomM = static_cast<long>((rMargin.GetBottomMargin() * nPPTY));
    rLeftM   = static_cast<tools::Long>(((rMargin.GetLeftMargin() + nIndent) * nPPTX));
    rTopM    = static_cast<tools::Long>((rMargin.GetTopMargin() * nPPTY));
    rRightM  = static_cast<tools::Long>((rMargin.GetRightMargin() * nPPTX));
    rBottomM = static_cast<tools::Long>((rMargin.GetBottomMargin() * nPPTY));
    if(meHorJustAttr == SvxCellHorJustify::Right)
    {
        rLeftM   = static_cast<long>((rMargin.GetLeftMargin()  * nPPTX));
        rRightM  = static_cast<long>(((rMargin.GetRightMargin() + nIndent) * nPPTX));
        rLeftM   = static_cast<tools::Long>((rMargin.GetLeftMargin()  * nPPTX));
        rRightM  = static_cast<tools::Long>(((rMargin.GetRightMargin() + nIndent) * nPPTX));
    }
}

void ScOutputData::DrawEditParam::calcPaperSize(
    Size& rPaperSize, const tools::Rectangle& rAlignRect, double nPPTX, double nPPTY) const
{
    long nTopM, nLeftM, nBottomM, nRightM;
    tools::Long nTopM, nLeftM, nBottomM, nRightM;
    calcMargins(nTopM, nLeftM, nBottomM, nRightM, nPPTX, nPPTY);

    if (isVerticallyOriented())
@@ -2496,17 +2496,17 @@ void ScOutputData::DrawEditParam::calcPaperSize(
    }
}

void ScOutputData::DrawEditParam::getEngineSize(ScFieldEditEngine* pEngine, long& rWidth, long& rHeight) const
void ScOutputData::DrawEditParam::getEngineSize(ScFieldEditEngine* pEngine, tools::Long& rWidth, tools::Long& rHeight) const
{
    long nEngineWidth = 0;
    tools::Long nEngineWidth = 0;
    if (!mbBreak || meOrient == SvxCellOrientation::Stacked || mbAsianVertical)
        nEngineWidth = static_cast<long>(pEngine->CalcTextWidth());
        nEngineWidth = static_cast<tools::Long>(pEngine->CalcTextWidth());

    long nEngineHeight = pEngine->GetTextHeight();
    tools::Long nEngineHeight = pEngine->GetTextHeight();

    if (isVerticallyOriented())
    {
        long nTemp = nEngineWidth;
        tools::Long nTemp = nEngineWidth;
        nEngineWidth = nEngineHeight;
        nEngineHeight = nTemp;
    }
@@ -2537,7 +2537,7 @@ bool ScOutputData::DrawEditParam::isVerticallyOriented() const
}

void ScOutputData::DrawEditParam::calcStartPosForVertical(
    Point& rLogicStart, long nCellWidth, long nEngineWidth, long nTopM, const OutputDevice* pRefDevice)
    Point& rLogicStart, tools::Long nCellWidth, tools::Long nEngineWidth, tools::Long nTopM, const OutputDevice* pRefDevice)
{
    OSL_ENSURE(isVerticallyOriented(), "Use this only for vertically oriented cell!");

@@ -2697,8 +2697,8 @@ void ScOutputData::DrawEditParam::adjustForHyperlinkInPDF(Point aURLStart, const
    if (!bHasURL)
        return;

    long nURLWidth = static_cast<long>(mpEngine->CalcTextWidth());
    long nURLHeight = mpEngine->GetTextHeight();
    tools::Long nURLWidth = static_cast<tools::Long>(mpEngine->CalcTextWidth());
    tools::Long nURLHeight = mpEngine->GetTextHeight();
    if (mbBreak)
    {
        Size aPaper = mpEngine->GetPaperSize();
@@ -2792,11 +2792,11 @@ private:
};

// Returns needed width in current units; sets rNeededPixel to needed width in pixels
long ScOutputData::SetEngineTextAndGetWidth( DrawEditParam& rParam, const OUString& rSetString,
                                             long& rNeededPixel, long nAddWidthPixels )
tools::Long ScOutputData::SetEngineTextAndGetWidth( DrawEditParam& rParam, const OUString& rSetString,
                                             tools::Long& rNeededPixel, tools::Long nAddWidthPixels )
{
    rParam.mpEngine->SetTextCurrentDefaults( rSetString );
    long nEngineWidth = static_cast<long>( rParam.mpEngine->CalcTextWidth() );
    tools::Long nEngineWidth = static_cast<tools::Long>( rParam.mpEngine->CalcTextWidth() );
    if ( rParam.mbPixelToLogic )
        rNeededPixel = mpRefDevice->LogicToPixel( Size( nEngineWidth, 0 ) ).Width();
    else
@@ -2816,7 +2816,7 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam)

    bool bRepeat = (rParam.meHorJustAttr == SvxCellHorJustify::Repeat && !rParam.mbBreak);
    bool bShrink = !rParam.mbBreak && !bRepeat && lcl_GetBoolValue(*rParam.mpPattern, ATTR_SHRINKTOFIT, rParam.mpCondSet);
    long nAttrRotate = lcl_GetValue<ScRotateValueItem, long>(*rParam.mpPattern, ATTR_ROTATE_VALUE, rParam.mpCondSet);
    tools::Long nAttrRotate = lcl_GetValue<ScRotateValueItem, long>(*rParam.mpPattern, ATTR_ROTATE_VALUE, rParam.mpCondSet);

    if ( rParam.meHorJustAttr == SvxCellHorJustify::Repeat )
    {
@@ -2843,7 +2843,7 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam)

    //! mirror margin values for RTL?
    //! move margin down to after final GetOutputArea call
    long nTopM, nLeftM, nBottomM, nRightM;
    tools::Long nTopM, nLeftM, nBottomM, nRightM;
    rParam.calcMargins(nTopM, nLeftM, nBottomM, nRightM, mnPPTX, mnPPTY);

    SCCOL nXForPos = rParam.mnX;
@@ -2919,10 +2919,10 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam)

    //  Get final output area using the calculated width

    long nEngineWidth, nEngineHeight;
    tools::Long nEngineWidth, nEngineHeight;
    rParam.getEngineSize(rParam.mpEngine, nEngineWidth, nEngineHeight);

    long nNeededPixel = nEngineWidth;
    tools::Long nNeededPixel = nEngineWidth;
    if (rParam.mbPixelToLogic)
        nNeededPixel = mpRefDevice->LogicToPixel(Size(nNeededPixel,0)).Width();
    nNeededPixel += nLeftM + nRightM;
@@ -2947,24 +2947,24 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam)
            // First check if twice the space for the formatted text is available
            // (otherwise just keep it unchanged).

            long nFormatted = nNeededPixel - nLeftM - nRightM;      // without margin
            long nAvailable = aAreaParam.maAlignRect.GetWidth() - nLeftM - nRightM;
            tools::Long nFormatted = nNeededPixel - nLeftM - nRightM;      // without margin
            tools::Long nAvailable = aAreaParam.maAlignRect.GetWidth() - nLeftM - nRightM;
            if ( nAvailable >= 2 * nFormatted )
            {
                // "repeat" is handled with unformatted text (for performance reasons)
                OUString aCellStr = rParam.mpEngine->GetText();

                long nRepeatSize = 0;
                tools::Long nRepeatSize = 0;
                SetEngineTextAndGetWidth( rParam, aCellStr, nRepeatSize, 0 );
                if ( pFmtDevice != mpRefDevice )
                    ++nRepeatSize;
                if ( nRepeatSize > 0 )
                {
                    long nRepeatCount = nAvailable / nRepeatSize;
                    tools::Long nRepeatCount = nAvailable / nRepeatSize;
                    if ( nRepeatCount > 1 )
                    {
                        OUStringBuffer aRepeated = aCellStr;
                        for ( long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ )
                        for ( tools::Long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ )
                            aRepeated.append(aCellStr);

                        SetEngineTextAndGetWidth( rParam, aRepeated.makeStringAndClear(),
@@ -2994,11 +2994,11 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam)
        }
    }

    long nStartX = aAreaParam.maAlignRect.Left();
    long nStartY = aAreaParam.maAlignRect.Top();
    long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;
    tools::Long nStartX = aAreaParam.maAlignRect.Left();
    tools::Long nStartY = aAreaParam.maAlignRect.Top();
    tools::Long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    tools::Long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    tools::Long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;

    if (rParam.mbBreak)
    {
@@ -3071,7 +3071,7 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam)
            pClipMarkCell->nClipMark |= ScClipMark::Right;      //! also allow left?
            bAnyClipped = true;

            long nMarkPixel = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTX );
            tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTX );
            if ( aAreaParam.maClipRect.Right() - nMarkPixel > aAreaParam.maClipRect.Left() )
                aAreaParam.maClipRect.AdjustRight( -nMarkPixel );
        }
@@ -3150,7 +3150,7 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam)
    rParam.adjustForHyperlinkInPDF(aURLStart, mpDev);
}

void ScOutputData::ShowClipMarks( DrawEditParam& rParam, long nEngineHeight, const Size& aCellSize,
void ScOutputData::ShowClipMarks( DrawEditParam& rParam, tools::Long nEngineHeight, const Size& aCellSize,
                                  bool bMerged, OutputAreaParam& aAreaParam)
{
    //  Show clip marks if height is at least 5pt too small and
@@ -3177,13 +3177,13 @@ void ScOutputData::ShowClipMarks( DrawEditParam& rParam, long nEngineHeight, con
    pClipMarkCell->nClipMark |= ScClipMark::Right;      //! also allow left?
    bAnyClipped = true;

    const long nMarkPixel = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTX );
    const tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTX );
    if ( aAreaParam.maClipRect.Right() - nMarkPixel > aAreaParam.maClipRect.Left() )
        aAreaParam.maClipRect.AdjustRight( -nMarkPixel );
}

ClearableClipRegionPtr ScOutputData::Clip( DrawEditParam& rParam, const Size& aCellSize,
                                                        OutputAreaParam& aAreaParam, long nEngineHeight,
                                                        OutputAreaParam& aAreaParam, tools::Long nEngineHeight,
                                                        bool bWrapFields)
{
    // Also take fields in a cell with automatic breaks into account: clip to cell width
@@ -3227,7 +3227,7 @@ void ScOutputData::DrawEditBottomTop(DrawEditParam& rParam)

    //! mirror margin values for RTL?
    //! move margin down to after final GetOutputArea call
    long nTopM, nLeftM, nBottomM, nRightM;
    tools::Long nTopM, nLeftM, nBottomM, nRightM;
    rParam.calcMargins(nTopM, nLeftM, nBottomM, nRightM, mnPPTX, mnPPTY);

    SCCOL nXForPos = rParam.mnX;
@@ -3289,10 +3289,10 @@ void ScOutputData::DrawEditBottomTop(DrawEditParam& rParam)

    //  Get final output area using the calculated width

    long nEngineWidth, nEngineHeight;
    tools::Long nEngineWidth, nEngineHeight;
    rParam.getEngineSize(rParam.mpEngine, nEngineWidth, nEngineHeight);

    long nNeededPixel = nEngineWidth;
    tools::Long nNeededPixel = nEngineWidth;
    if (rParam.mbPixelToLogic)
        nNeededPixel = mpRefDevice->LogicToPixel(Size(nNeededPixel,0)).Width();
    nNeededPixel += nLeftM + nRightM;
@@ -3317,24 +3317,24 @@ void ScOutputData::DrawEditBottomTop(DrawEditParam& rParam)
            // First check if twice the space for the formatted text is available
            // (otherwise just keep it unchanged).

            const long nFormatted = nNeededPixel - nLeftM - nRightM;      // without margin
            const long nAvailable = aAreaParam.maAlignRect.GetWidth() - nLeftM - nRightM;
            const tools::Long nFormatted = nNeededPixel - nLeftM - nRightM;      // without margin
            const tools::Long nAvailable = aAreaParam.maAlignRect.GetWidth() - nLeftM - nRightM;
            if ( nAvailable >= 2 * nFormatted )
            {
                // "repeat" is handled with unformatted text (for performance reasons)
                OUString aCellStr = rParam.mpEngine->GetText();

                long nRepeatSize = 0;
                tools::Long nRepeatSize = 0;
                SetEngineTextAndGetWidth( rParam, aCellStr, nRepeatSize, 0 );
                if ( pFmtDevice != mpRefDevice )
                    ++nRepeatSize;
                if ( nRepeatSize > 0 )
                {
                    const long nRepeatCount = nAvailable / nRepeatSize;
                    const tools::Long nRepeatCount = nAvailable / nRepeatSize;
                    if ( nRepeatCount > 1 )
                    {
                        OUStringBuffer aRepeated = aCellStr;
                        for ( long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ )
                        for ( tools::Long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ )
                            aRepeated.append(aCellStr);

                        nEngineWidth = SetEngineTextAndGetWidth( rParam, aRepeated.makeStringAndClear(),
@@ -3353,11 +3353,11 @@ void ScOutputData::DrawEditBottomTop(DrawEditParam& rParam)
        }
    }

    long nStartX = aAreaParam.maAlignRect.Left();
    const long nStartY = aAreaParam.maAlignRect.Top();
    const long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    const long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    const long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;
    tools::Long nStartX = aAreaParam.maAlignRect.Left();
    const tools::Long nStartY = aAreaParam.maAlignRect.Top();
    const tools::Long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    const tools::Long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    const tools::Long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;

    if (rParam.mbBreak)
    {
@@ -3415,8 +3415,8 @@ void ScOutputData::DrawEditBottomTop(DrawEditParam& rParam)
            aPSize.setWidth( rParam.mpEngine->CalcTextWidth() );
            rParam.mpEngine->SetPaperSize(aPSize);

            long nGap = 0;
            long nTopOffset = 0;
            tools::Long nGap = 0;
            tools::Long nTopOffset = 0;
            if (rParam.mbPixelToLogic)
            {
                nGap = mpRefDevice->LogicToPixel(aCellSize).Height() - mpRefDevice->LogicToPixel(aPSize).Width();
@@ -3470,7 +3470,7 @@ void ScOutputData::DrawEditTopBottom(DrawEditParam& rParam)

    //! mirror margin values for RTL?
    //! move margin down to after final GetOutputArea call
    long nTopM, nLeftM, nBottomM, nRightM;
    tools::Long nTopM, nLeftM, nBottomM, nRightM;
    rParam.calcMargins(nTopM, nLeftM, nBottomM, nRightM, mnPPTX, mnPPTY);

    SCCOL nXForPos = rParam.mnX;
@@ -3532,10 +3532,10 @@ void ScOutputData::DrawEditTopBottom(DrawEditParam& rParam)

    //  Get final output area using the calculated width

    long nEngineWidth, nEngineHeight;
    tools::Long nEngineWidth, nEngineHeight;
    rParam.getEngineSize(rParam.mpEngine, nEngineWidth, nEngineHeight);

    long nNeededPixel = nEngineWidth;
    tools::Long nNeededPixel = nEngineWidth;
    if (rParam.mbPixelToLogic)
        nNeededPixel = mpRefDevice->LogicToPixel(Size(nNeededPixel,0)).Width();
    nNeededPixel += nLeftM + nRightM;
@@ -3560,25 +3560,25 @@ void ScOutputData::DrawEditTopBottom(DrawEditParam& rParam)
            // First check if twice the space for the formatted text is available
            // (otherwise just keep it unchanged).

            const long nFormatted = nNeededPixel - nLeftM - nRightM;      // without margin
            const long nAvailable = aAreaParam.maAlignRect.GetWidth() - nLeftM - nRightM;
            const tools::Long nFormatted = nNeededPixel - nLeftM - nRightM;      // without margin
            const tools::Long nAvailable = aAreaParam.maAlignRect.GetWidth() - nLeftM - nRightM;
            if ( nAvailable >= 2 * nFormatted )
            {
                // "repeat" is handled with unformatted text (for performance reasons)
                OUString aCellStr = rParam.mpEngine->GetText();

                long nRepeatSize = 0;
                tools::Long nRepeatSize = 0;
                SetEngineTextAndGetWidth( rParam, aCellStr, nRepeatSize, 0 );

                if ( pFmtDevice != mpRefDevice )
                    ++nRepeatSize;
                if ( nRepeatSize > 0 )
                {
                    const long nRepeatCount = nAvailable / nRepeatSize;
                    const tools::Long nRepeatCount = nAvailable / nRepeatSize;
                    if ( nRepeatCount > 1 )
                    {
                        OUStringBuffer aRepeated = aCellStr;
                        for ( long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ )
                        for ( tools::Long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ )
                            aRepeated.append(aCellStr);

                        nEngineWidth = SetEngineTextAndGetWidth( rParam, aRepeated.makeStringAndClear(),
@@ -3597,11 +3597,11 @@ void ScOutputData::DrawEditTopBottom(DrawEditParam& rParam)
        }
    }

    long nStartX = aAreaParam.maAlignRect.Left();
    const long nStartY = aAreaParam.maAlignRect.Top();
    const long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    const long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    const long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;
    tools::Long nStartX = aAreaParam.maAlignRect.Left();
    const tools::Long nStartY = aAreaParam.maAlignRect.Top();
    const tools::Long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    const tools::Long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    const tools::Long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;

    if (rParam.mbBreak)
    {
@@ -3652,8 +3652,8 @@ void ScOutputData::DrawEditTopBottom(DrawEditParam& rParam)
                aPSize.setWidth( rParam.mpEngine->CalcTextWidth() );
                rParam.mpEngine->SetPaperSize(aPSize);

                long nGap = 0;
                long nTopOffset = 0; // offset by top margin
                tools::Long nGap = 0;
                tools::Long nTopOffset = 0; // offset by top margin
                if (rParam.mbPixelToLogic)
                {
                    nGap = mpRefDevice->LogicToPixel(aPSize).Width() - mpRefDevice->LogicToPixel(aCellSize).Height();
@@ -3719,7 +3719,7 @@ void ScOutputData::DrawEditStacked(DrawEditParam& rParam)

    //! mirror margin values for RTL?
    //! move margin down to after final GetOutputArea call
    long nTopM, nLeftM, nBottomM, nRightM;
    tools::Long nTopM, nLeftM, nBottomM, nRightM;
    rParam.calcMargins(nTopM, nLeftM, nBottomM, nRightM, mnPPTX, mnPPTY);

    SCCOL nXForPos = rParam.mnX;
@@ -3789,10 +3789,10 @@ void ScOutputData::DrawEditStacked(DrawEditParam& rParam)

    //  Get final output area using the calculated width

    long nEngineWidth, nEngineHeight;
    tools::Long nEngineWidth, nEngineHeight;
    rParam.getEngineSize(rParam.mpEngine, nEngineWidth, nEngineHeight);

    long nNeededPixel = nEngineWidth;
    tools::Long nNeededPixel = nEngineWidth;
    if (rParam.mbPixelToLogic)
        nNeededPixel = mpRefDevice->LogicToPixel(Size(nNeededPixel,0)).Width();
    nNeededPixel += nLeftM + nRightM;
@@ -3827,11 +3827,11 @@ void ScOutputData::DrawEditStacked(DrawEditParam& rParam)
        }
    }

    long nStartX = aAreaParam.maAlignRect.Left();
    long nStartY = aAreaParam.maAlignRect.Top();
    long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;
    tools::Long nStartX = aAreaParam.maAlignRect.Left();
    tools::Long nStartY = aAreaParam.maAlignRect.Top();
    tools::Long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    tools::Long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    tools::Long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;

    if (rParam.mbBreak)
    {
@@ -3904,7 +3904,7 @@ void ScOutputData::DrawEditStacked(DrawEditParam& rParam)
            pClipMarkCell->nClipMark |= ScClipMark::Right;      //! also allow left?
            bAnyClipped = true;

            long nMarkPixel = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTX );
            tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTX );
            if ( aAreaParam.maClipRect.Right() - nMarkPixel > aAreaParam.maClipRect.Left() )
                aAreaParam.maClipRect.AdjustRight( -nMarkPixel );
        }
@@ -3991,7 +3991,7 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam)

    bool bHidden = false;
    bool bShrink = !rParam.mbBreak && lcl_GetBoolValue(*rParam.mpPattern, ATTR_SHRINKTOFIT, rParam.mpCondSet);
    long nAttrRotate = lcl_GetValue<ScRotateValueItem, long>(*rParam.mpPattern, ATTR_ROTATE_VALUE, rParam.mpCondSet);
    tools::Long nAttrRotate = lcl_GetValue<ScRotateValueItem, long>(*rParam.mpPattern, ATTR_ROTATE_VALUE, rParam.mpCondSet);

    if (nAttrRotate)
    {
@@ -4014,7 +4014,7 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam)

    //! mirror margin values for RTL?
    //! move margin down to after final GetOutputArea call
    long nTopM, nLeftM, nBottomM, nRightM;
    tools::Long nTopM, nLeftM, nBottomM, nRightM;
    rParam.calcMargins(nTopM, nLeftM, nBottomM, nRightM, mnPPTX, mnPPTY);

    SCCOL nXForPos = rParam.mnX;
@@ -4088,10 +4088,10 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam)

    //  Get final output area using the calculated width

    long nEngineWidth, nEngineHeight;
    tools::Long nEngineWidth, nEngineHeight;
    rParam.getEngineSize(rParam.mpEngine, nEngineWidth, nEngineHeight);

    long nNeededPixel = nEngineWidth;
    tools::Long nNeededPixel = nEngineWidth;
    if (rParam.mbPixelToLogic)
        nNeededPixel = mpRefDevice->LogicToPixel(Size(nNeededPixel,0)).Width();
    nNeededPixel += nLeftM + nRightM;
@@ -4125,11 +4125,11 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam)
            rParam.mpEngine->SetPaperSize(aPaperSize);
    }

    long nStartX = aAreaParam.maAlignRect.Left();
    long nStartY = aAreaParam.maAlignRect.Top();
    long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;
    tools::Long nStartX = aAreaParam.maAlignRect.Left();
    tools::Long nStartY = aAreaParam.maAlignRect.Top();
    tools::Long nCellWidth = aAreaParam.maAlignRect.GetWidth();
    tools::Long nOutWidth = nCellWidth - 1 - nLeftM - nRightM;
    tools::Long nOutHeight = aAreaParam.maAlignRect.GetHeight() - nTopM - nBottomM;

    //  text with automatic breaks is aligned only within the
    //  edit engine's paper size, the output of the whole area
@@ -4191,7 +4191,7 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam)
            pClipMarkCell->nClipMark |= ScClipMark::Right;      //! also allow left?
            bAnyClipped = true;

            long nMarkPixel = static_cast<long>( SC_CLIPMARK_SIZE * mnPPTX );
            tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * mnPPTX );
            if ( aAreaParam.maClipRect.Right() - nMarkPixel > aAreaParam.maClipRect.Left() )
                aAreaParam.maClipRect.AdjustRight( -nMarkPixel );
        }
@@ -4209,7 +4209,7 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam)
        else
            aLogicStart = Point(nStartX, nStartY);

        long nAvailWidth = aCellSize.Width();
        tools::Long nAvailWidth = aCellSize.Width();
        // space for AutoFilter is already handled in GetOutputArea

        //  horizontal alignment
@@ -4252,12 +4252,12 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
    const SfxItemSet*    pOldPreviewFontSet = nullptr;
    ScRefCellValue aCell;

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
    {
        nInitPosX += nMirrorW - 1;
    }
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    //! store nLastContentCol as member!
    SCCOL nLastContentCol = mpDoc->MaxCol();
@@ -4265,7 +4265,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
        nLastContentCol = sal::static_int_cast<SCCOL>(
            nLastContentCol - mpDoc->GetEmptyLinesInBlock( nX2+1, nY1, nTab, mpDoc->MaxCol(), nY2, nTab, DIR_RIGHT ) );

    long nRowPosY = nScrY;
    tools::Long nRowPosY = nScrY;
    for (SCSIZE nArrY=0; nArrY+1<nArrCount; nArrY++)            // 0 of the rest of the merged
    {
        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
@@ -4274,7 +4274,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)

        if ( pThisRowInfo->bChanged || nArrY==0 )
        {
            long nPosX = 0;
            tools::Long nPosX = 0;
            for (SCCOL nX=0; nX<=nX2; nX++)                     // due to overflow
            {
                std::unique_ptr< ScPatternAttr > pPreviewPattr;
@@ -4289,7 +4289,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
                    SCROW nCellY = nY;
                    bool bDoCell = false;

                    long nPosY = nRowPosY;
                    tools::Long nPosY = nRowPosY;
                    if ( nArrY == 0 )
                    {
                        nPosY = nScrY;
@@ -4456,23 +4456,23 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
    const SfxItemSet*    pOldCondSet = nullptr;
    ScRefCellValue aCell;

    long nInitPosX = nScrX;
    tools::Long nInitPosX = nScrX;
    if ( bLayoutRTL )
    {
        nInitPosX += nMirrorW - 1;
    }
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    long nRowPosY = nScrY;
    tools::Long nRowPosY = nScrY;
    for (SCSIZE nArrY=0; nArrY+1<nArrCount; nArrY++)            // 0 for the rest of the merged
    {
        RowInfo* pThisRowInfo = &pRowInfo[nArrY];
        long nCellHeight = static_cast<long>(pThisRowInfo->nHeight);
        tools::Long nCellHeight = static_cast<tools::Long>(pThisRowInfo->nHeight);
        if (nArrY==1) nRowPosY = nScrY;                         // positions before are calculated individually

        if ( ( pThisRowInfo->bChanged || nArrY==0 ) && pThisRowInfo->nRotMaxCol != SC_ROTMAX_NONE )
        {
            long nPosX = 0;
            tools::Long nPosX = 0;
            for (SCCOL nX=0; nX<=nRotMax; nX++)
            {
                if (nX==nX1) nPosX = nInitPosX;                 // positions before nX1 are calculated individually
@@ -4494,7 +4494,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                        else
                            lcl_ClearEdit( *pEngine );      // also calls SetUpdateMode(sal_False)

                        long nPosY = nRowPosY;
                        tools::Long nPosY = nRowPosY;

                        //! rest from merged cells further up do not work!

@@ -4516,7 +4516,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                        if (aCell.isEmpty() || IsEmptyCellText(pThisRowInfo, nX, nY))
                            bHidden = true;     // nRotateDir is also set without a cell

                        long nCellWidth = static_cast<long>(pRowInfo[0].pCellInfo[nX+1].nWidth);
                        tools::Long nCellWidth = static_cast<tools::Long>(pRowInfo[0].pCellInfo[nX+1].nWidth);

                        SvxCellHorJustify eHorJust =
                                            pPattern->GetItem(ATTR_HOR_JUSTIFY, pCondSet).GetValue();
@@ -4530,8 +4530,8 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                        const ScMergeAttr* pMerge = &pPattern->GetItem(ATTR_MERGE);
                        bool bMerged = pMerge->GetColMerge() > 1 || pMerge->GetRowMerge() > 1;

                        long nStartX = nPosX;
                        long nStartY = nPosY;
                        tools::Long nStartX = nPosX;
                        tools::Long nStartY = nPosY;
                        if (nX<nX1)
                        {
                            if ((bBreak || eOrient!=SvxCellOrientation::Standard) && !bMerged)
@@ -4543,26 +4543,26 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                while (nCol > nX)
                                {
                                    --nCol;
                                    nStartX -= nLayoutSign * static_cast<long>(pRowInfo[0].pCellInfo[nCol+1].nWidth);
                                    nStartX -= nLayoutSign * static_cast<tools::Long>(pRowInfo[0].pCellInfo[nCol+1].nWidth);
                                }
                            }
                        }
                        long nCellStartX = nStartX;
                        tools::Long nCellStartX = nStartX;

                        // omit substitute representation of small text

                        if (!bHidden)
                        {
                            long nOutWidth = nCellWidth - 1;
                            long nOutHeight = nCellHeight;
                            tools::Long nOutWidth = nCellWidth - 1;
                            tools::Long nOutHeight = nCellHeight;

                            if ( bMerged )
                            {
                                SCCOL nCountX = pMerge->GetColMerge();
                                for (SCCOL i=1; i<nCountX; i++)
                                    nOutWidth += static_cast<long>( mpDoc->GetColWidth(nX+i,nTab) * mnPPTX );
                                    nOutWidth += static_cast<tools::Long>( mpDoc->GetColWidth(nX+i,nTab) * mnPPTX );
                                SCROW nCountY = pMerge->GetRowMerge();
                                nOutHeight += static_cast<long>(mpDoc->GetScaledRowHeight( nY+1, nY+nCountY-1, nTab, mnPPTY));
                                nOutHeight += static_cast<tools::Long>(mpDoc->GetScaledRowHeight( nY+1, nY+nCountY-1, nTab, mnPPTY));
                            }

                            SvxCellVerJustify eVerJust =
@@ -4620,21 +4620,21 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                            if ( eHorJust == SvxCellHorJustify::Left )
                                nIndent = pPattern->GetItem(ATTR_INDENT, pCondSet).GetValue();

                            long nTotalHeight = nOutHeight; // without subtracting the margin
                            tools::Long nTotalHeight = nOutHeight; // without subtracting the margin
                            if ( bPixelToLogic )
                                nTotalHeight = mpRefDevice->PixelToLogic(Size(0,nTotalHeight)).Height();

                            long nLeftM = static_cast<long>( (pMargin->GetLeftMargin() + nIndent) * mnPPTX );
                            long nTopM  = static_cast<long>( pMargin->GetTopMargin() * mnPPTY );
                            long nRightM  = static_cast<long>( pMargin->GetRightMargin() * mnPPTX );
                            long nBottomM = static_cast<long>( pMargin->GetBottomMargin() * mnPPTY );
                            tools::Long nLeftM = static_cast<tools::Long>( (pMargin->GetLeftMargin() + nIndent) * mnPPTX );
                            tools::Long nTopM  = static_cast<tools::Long>( pMargin->GetTopMargin() * mnPPTY );
                            tools::Long nRightM  = static_cast<tools::Long>( pMargin->GetRightMargin() * mnPPTX );
                            tools::Long nBottomM = static_cast<tools::Long>( pMargin->GetBottomMargin() * mnPPTY );
                            nStartX += nLeftM;
                            nStartY += nTopM;
                            nOutWidth -= nLeftM + nRightM;
                            nOutHeight -= nTopM + nBottomM;

                            // rotate here already, to adjust paper size for page breaks
                            long nAttrRotate = 0;
                            tools::Long nAttrRotate = 0;
                            double nSin = 0.0;
                            double nCos = 1.0;
                            SvxRotateMode eRotMode = SVX_ROTATE_MODE_STANDARD;
@@ -4669,7 +4669,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                    //! of rows, as long as the rows can not be outputted individually
                                    //! offsetted -> therefore unlimited, so no wrapping.
                                    //! With offset rows the following would be correct:
                                    aPaperSize.setWidth( static_cast<long>(nOutHeight / fabs(nSin)) );
                                    aPaperSize.setWidth( static_cast<tools::Long>(nOutHeight / fabs(nSin)) );
                                }
                                else if (eOrient == SvxCellOrientation::Standard)
                                    aPaperSize.setWidth( nOutWidth );
@@ -4719,8 +4719,8 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)

                            pEngine->SetUpdateMode( true );     // after SetText, before CalcTextWidth/GetTextHeight

                            long nEngineWidth  = static_cast<long>(pEngine->CalcTextWidth());
                            long nEngineHeight = pEngine->GetTextHeight();
                            tools::Long nEngineWidth  = static_cast<tools::Long>(pEngine->CalcTextWidth());
                            tools::Long nEngineHeight = pEngine->GetTextHeight();

                            if (nAttrRotate && bBreak)
                            {
@@ -4732,10 +4732,10 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                while (nSteps > 0)
                                {
                                    // everything is in pixels
                                    long nEnginePixel = mpRefDevice->LogicToPixel(
                                    tools::Long nEnginePixel = mpRefDevice->LogicToPixel(
                                                            Size(0,nEngineHeight)).Height();
                                    long nEffHeight = nOutHeight - static_cast<long>(nEnginePixel * nAbsCos) + 2;
                                    long nNewWidth = static_cast<long>(nEffHeight / nAbsSin) + 2;
                                    tools::Long nEffHeight = nOutHeight - static_cast<tools::Long>(nEnginePixel * nAbsCos) + 2;
                                    tools::Long nNewWidth = static_cast<tools::Long>(nEffHeight / nAbsSin) + 2;
                                    bool bFits = ( nNewWidth >= aPaperSize.Width() );
                                    if ( bFits )
                                        nSteps = 0;
@@ -4745,7 +4745,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                        {
                                            // can't fit -> fall back to using half height
                                            nEffHeight = nOutHeight / 2;
                                            nNewWidth = static_cast<long>(nEffHeight / nAbsSin) + 2;
                                            nNewWidth = static_cast<tools::Long>(nEffHeight / nAbsSin) + 2;
                                            nSteps = 0;
                                        }
                                        else
@@ -4759,14 +4759,14 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                            pEngine->SetPaperSize(aPaperSize);  // Scale is always 1
                                        //pEngine->QuickFormatDoc( sal_True );

                                        nEngineWidth  = static_cast<long>(pEngine->CalcTextWidth());
                                        nEngineWidth  = static_cast<tools::Long>(pEngine->CalcTextWidth());
                                        nEngineHeight = pEngine->GetTextHeight();
                                    }
                                }
                            }

                            long nRealWidth  = nEngineWidth;
                            long nRealHeight = nEngineHeight;
                            tools::Long nRealWidth  = nEngineWidth;
                            tools::Long nRealHeight = nEngineHeight;

                            // when rotated, adjust size
                            if (nAttrRotate)
@@ -4775,13 +4775,13 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                double nAbsSin = fabs( nSin );

                                if ( eRotMode == SVX_ROTATE_MODE_STANDARD )
                                    nEngineWidth = static_cast<long>( nRealWidth * nAbsCos +
                                    nEngineWidth = static_cast<tools::Long>( nRealWidth * nAbsCos +
                                                            nRealHeight * nAbsSin );
                                else
                                    nEngineWidth = static_cast<long>( nRealHeight / nAbsSin );
                                    nEngineWidth = static_cast<tools::Long>( nRealHeight / nAbsSin );
                                //! limit !!!

                                nEngineHeight = static_cast<long>( nRealHeight * nAbsCos +
                                nEngineHeight = static_cast<tools::Long>( nRealHeight * nAbsCos +
                                                         nRealWidth * nAbsSin );
                            }

@@ -4802,12 +4802,12 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                else
                                    aCellSize = Size( nOutWidth, nOutHeight );  // scale is one

                                long nGridWidth = nEngineWidth;
                                tools::Long nGridWidth = nEngineWidth;
                                bool bNegative = false;
                                if ( eRotMode != SVX_ROTATE_MODE_STANDARD )
                                {
                                    nGridWidth = aCellSize.Width() +
                                            std::abs(static_cast<long>( aCellSize.Height() * nCos / nSin ));
                                            std::abs(static_cast<tools::Long>( aCellSize.Height() * nCos / nSin ));
                                    bNegative = ( pInfo->nRotateDir == ScRotateDir::Left );
                                    if ( bLayoutRTL )
                                        bNegative = !bNegative;
@@ -4822,7 +4822,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                SvxCellHorJustify eOutHorJust = eHorJust;
                                if ( eRotMode != SVX_ROTATE_MODE_STANDARD )
                                    eOutHorJust = bNegative ? SvxCellHorJustify::Right : SvxCellHorJustify::Left;
                                long nNeededWidth = nGridWidth;     // in pixel for GetOutputArea
                                tools::Long nNeededWidth = nGridWidth;     // in pixel for GetOutputArea
                                if ( bPixelToLogic )
                                    nNeededWidth =  mpRefDevice->LogicToPixel(Size(nNeededWidth,0)).Width();

@@ -4832,9 +4832,9 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)

                                if ( bShrink )
                                {
                                    long nPixelWidth = bPixelToLogic ?
                                    tools::Long nPixelWidth = bPixelToLogic ?
                                        mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width() : nEngineWidth;
                                    long nNeededPixel = nPixelWidth + nLeftM + nRightM;
                                    tools::Long nNeededPixel = nPixelWidth + nLeftM + nRightM;

                                    aAreaParam.mbLeftClip = aAreaParam.mbRightClip = true;

@@ -4853,30 +4853,30 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)

                                    // nEngineWidth/nEngineHeight is updated in ShrinkEditEngine
                                    // (but width is only valid for standard mode)
                                    nRealWidth  = static_cast<long>(pEngine->CalcTextWidth());
                                    nRealWidth  = static_cast<tools::Long>(pEngine->CalcTextWidth());
                                    nRealHeight = pEngine->GetTextHeight();

                                    if ( eRotMode != SVX_ROTATE_MODE_STANDARD )
                                        nEngineWidth = static_cast<long>( nRealHeight / fabs( nSin ) );
                                        nEngineWidth = static_cast<tools::Long>( nRealHeight / fabs( nSin ) );
                                }

                                long nClipStartX = nStartX;
                                tools::Long nClipStartX = nStartX;
                                if (nX<nX1)
                                {
                                    //! clipping is not needed when on the left side of the window

                                    if (nStartX<nScrX)
                                    {
                                        long nDif = nScrX - nStartX;
                                        tools::Long nDif = nScrX - nStartX;
                                        nClipStartX = nScrX;
                                        aClipSize.AdjustWidth( -nDif );
                                    }
                                }

                                long nClipStartY = nStartY;
                                tools::Long nClipStartY = nStartY;
                                if (nArrY==0 && nClipStartY < nRowPosY )
                                {
                                    long nDif = nRowPosY - nClipStartY;
                                    tools::Long nDif = nRowPosY - nClipStartY;
                                    nClipStartY = nRowPosY;
                                    aClipSize.AdjustHeight( -nDif );
                                }
@@ -4910,7 +4910,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                    aLogicStart = Point(nStartX, nStartY);
                                if ( eOrient!=SvxCellOrientation::Standard || !bBreak )
                                {
                                    long nAvailWidth = aCellSize.Width();
                                    tools::Long nAvailWidth = aCellSize.Width();
                                    if (eType==OUTTYPE_WINDOW &&
                                            eOrient!=SvxCellOrientation::Stacked &&
                                            pInfo->bAutoFilter)
@@ -4920,7 +4920,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                            nAvailWidth -= mpRefDevice->PixelToLogic(Size(0,DROPDOWN_BITMAP_SIZE)).Height();
                                        else
                                            nAvailWidth -= DROPDOWN_BITMAP_SIZE;
                                        long nComp = nEngineWidth;
                                        tools::Long nComp = nEngineWidth;
                                        if (nAvailWidth<nComp) nAvailWidth=nComp;
                                    }

@@ -4999,7 +4999,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                OSL_ENSURE( eOrient == SvxCellOrientation::Standard && nAttrRotate,
                                            "DrawRotated: no rotation" );

                                long nOriVal = 0;
                                tools::Long nOriVal = 0;
                                if ( nAttrRotate )
                                {
                                    // attribute is 1/100, Font 1/10 Grad
@@ -5032,7 +5032,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                             ( eRotMode == SVX_ROTATE_MODE_BOTTOM && nSin < 0.0 ) )
                                            nAddX -= nSkew;

                                        long nUp = 0;
                                        tools::Long nUp = 0;
                                        if ( eVerJust == SvxCellVerJustify::Center )
                                            nUp = ( aCellSize.Height() - nEngineHeight ) / 2;
                                        else if ( eVerJust == SvxCellVerJustify::Top )
@@ -5049,8 +5049,8 @@ void ScOutputData::DrawRotated(bool bPixelToLogic)
                                            nAddX += ( nUp * nCos / fabs(nSin) );
                                    }

                                    aLogicStart.AdjustX(static_cast<long>(nAddX) );
                                    aLogicStart.AdjustY(static_cast<long>(nAddY) );
                                    aLogicStart.AdjustX(static_cast<tools::Long>(nAddX) );
                                    aLogicStart.AdjustY(static_cast<tools::Long>(nAddY) );
                                }

                                //  bSimClip is not used here (because nOriVal is set)
diff --git a/sc/source/ui/view/output3.cxx b/sc/source/ui/view/output3.cxx
index 4601d02..c4e225a 100644
--- a/sc/source/ui/view/output3.cxx
+++ b/sc/source/ui/view/output3.cxx
@@ -31,18 +31,18 @@
#include <svx/fmview.hxx>

// #i72502#
Point ScOutputData::PrePrintDrawingLayer(long nLogStX, long nLogStY )
Point ScOutputData::PrePrintDrawingLayer(tools::Long nLogStX, tools::Long nLogStY )
{
    tools::Rectangle aRect;
    SCCOL nCol;
    Point aOffset;
    long nLayoutSign(bLayoutRTL ? -1 : 1);
    tools::Long nLayoutSign(bLayoutRTL ? -1 : 1);

    for (nCol=0; nCol<nX1; nCol++)
        aOffset.AdjustX( -(mpDoc->GetColWidth( nCol, nTab ) * nLayoutSign) );
    aOffset.AdjustY( -sal_Int32(mpDoc->GetRowHeight( 0, nY1-1, nTab )) );

    long nDataWidth = 0;
    tools::Long nDataWidth = 0;
    for (nCol=nX1; nCol<=nX2; nCol++)
        nDataWidth += mpDoc->GetColWidth( nCol, nTab );

@@ -55,8 +55,8 @@ Point ScOutputData::PrePrintDrawingLayer(long nLogStX, long nLogStY )
    aRect.SetBottom( -aOffset.Y() );

    Point aMMOffset( aOffset );
    aMMOffset.setX( static_cast<long>(aMMOffset.X() * HMM_PER_TWIPS) );
    aMMOffset.setY( static_cast<long>(aMMOffset.Y() * HMM_PER_TWIPS) );
    aMMOffset.setX( static_cast<tools::Long>(aMMOffset.X() * HMM_PER_TWIPS) );
    aMMOffset.setY( static_cast<tools::Long>(aMMOffset.Y() * HMM_PER_TWIPS) );

    if (!bMetaFile)
        aMMOffset += Point( nLogStX, nLogStY );
@@ -65,10 +65,10 @@ Point ScOutputData::PrePrintDrawingLayer(long nLogStX, long nLogStY )
        aRect.AdjustRight(mpDoc->GetColWidth( nCol, nTab ) );
    aRect.AdjustBottom(mpDoc->GetRowHeight( nY1, nY2, nTab ) );

    aRect.SetLeft( static_cast<long>(aRect.Left()   * HMM_PER_TWIPS) );
    aRect.SetTop( static_cast<long>(aRect.Top()    * HMM_PER_TWIPS) );
    aRect.SetRight( static_cast<long>(aRect.Right()  * HMM_PER_TWIPS) );
    aRect.SetBottom( static_cast<long>(aRect.Bottom() * HMM_PER_TWIPS) );
    aRect.SetLeft( static_cast<tools::Long>(aRect.Left()   * HMM_PER_TWIPS) );
    aRect.SetTop( static_cast<tools::Long>(aRect.Top()    * HMM_PER_TWIPS) );
    aRect.SetRight( static_cast<tools::Long>(aRect.Right()  * HMM_PER_TWIPS) );
    aRect.SetBottom( static_cast<tools::Long>(aRect.Bottom() * HMM_PER_TWIPS) );

    if(pViewShell || pDrawView)
    {
diff --git a/sc/source/ui/view/pfuncache.cxx b/sc/source/ui/view/pfuncache.cxx
index 1d56bf3..3c1ff3a 100644
--- a/sc/source/ui/view/pfuncache.cxx
+++ b/sc/source/ui/view/pfuncache.cxx
@@ -58,9 +58,9 @@ ScPrintFuncCache::ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
    SCTAB nTab;
    for ( nTab=0; nTab<nTabCount; nTab++ )
    {
        long nAttrPage = nTab > 0 ? nFirstAttr[nTab-1] : 1;
        tools::Long nAttrPage = nTab > 0 ? nFirstAttr[nTab-1] : 1;

        long nThisTab = 0;
        tools::Long nThisTab = 0;
        if ( rMark.GetTableSelect( nTab ) )
        {
            ScPrintFunc aFunc( pDocSh, pPrinter, nTab, nAttrPage, 0, pSelRange, &aSelection.GetOptions() );
@@ -92,8 +92,8 @@ void ScPrintFuncCache::InitLocations( const ScMarkData& rMark, OutputDevice* pDe
        pSelRange = &aRange;
    }

    long nRenderer = 0;     // 0-based physical page number across sheets
    long nTabStart = 0;
    tools::Long nRenderer = 0;     // 0-based physical page number across sheets
    tools::Long nTabStart = 0;

    ScDocument& rDoc = pDocSh->GetDocument();
    SCTAB nTabCount = rDoc.GetTableCount();
@@ -104,9 +104,9 @@ void ScPrintFuncCache::InitLocations( const ScMarkData& rMark, OutputDevice* pDe
        ScPrintFunc aFunc( pDev, pDocSh, nTab, nFirstAttr[nTab], nTotalPages, pSelRange, &aSelection.GetOptions() );
        aFunc.SetRenderFlag( true );

        long nDisplayStart = GetDisplayStart( nTab );
        tools::Long nDisplayStart = GetDisplayStart( nTab );

        for ( long nPage=0; nPage<nPages[nTab]; nPage++ )
        for ( tools::Long nPage=0; nPage<nPages[nTab]; nPage++ )
        {
            Range aPageRange( nRenderer+1, nRenderer+1 );
            MultiSelection aPage( aPageRange );
@@ -147,7 +147,7 @@ bool ScPrintFuncCache::IsSameSelection( const ScPrintSelectionStatus& rStatus ) 
    return aSelection == rStatus;
}

SCTAB ScPrintFuncCache::GetTabForPage( long nPage ) const
SCTAB ScPrintFuncCache::GetTabForPage( tools::Long nPage ) const
{
    ScDocument& rDoc = pDocSh->GetDocument();
    SCTAB nTabCount = rDoc.GetTableCount();
@@ -159,20 +159,20 @@ SCTAB ScPrintFuncCache::GetTabForPage( long nPage ) const
    return nTab;
}

long ScPrintFuncCache::GetTabStart( SCTAB nTab ) const
tools::Long ScPrintFuncCache::GetTabStart( SCTAB nTab ) const
{
    long nRet = 0;
    tools::Long nRet = 0;
    const SCTAB maxIndex = std::min(nTab, static_cast<SCTAB>(nPages.size()));
    for ( SCTAB i=0; i<maxIndex; i++ )
        nRet += nPages[i];
    return nRet;
}

long ScPrintFuncCache::GetDisplayStart( SCTAB nTab ) const
tools::Long ScPrintFuncCache::GetDisplayStart( SCTAB nTab ) const
{
    //! merge with lcl_GetDisplayStart in preview?

    long nDisplayStart = 0;
    tools::Long nDisplayStart = 0;
    ScDocument& rDoc = pDocSh->GetDocument();
    for (SCTAB i=0; i<nTab; i++)
    {
diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx
index 207d098..d2d19f3 100644
--- a/sc/source/ui/view/preview.cxx
+++ b/sc/source/ui/view/preview.cxx
@@ -67,9 +67,9 @@

#define SC_PREVIEW_SHADOWSIZE   2

static long lcl_GetDisplayStart( SCTAB nTab, const ScDocument* pDoc, std::vector<long>& nPages )
static tools::Long lcl_GetDisplayStart( SCTAB nTab, const ScDocument* pDoc, std::vector<long>& nPages )
{
    long nDisplayStart = 0;
    tools::Long nDisplayStart = 0;
    for (SCTAB i=0; i<nTab; i++)
    {
        if ( pDoc->NeedPageResetAfterTab(i) )
@@ -255,11 +255,11 @@ void ScPreview::CalcPages()
            continue;
        }

        long nAttrPage = i > 0 ? nFirstAttr[i-1] : 1;
        tools::Long nAttrPage = i > 0 ? nFirstAttr[i-1] : 1;

        long nThisStart = nTotalPages;
        tools::Long nThisStart = nTotalPages;
        ScPrintFunc aPrintFunc( this, pDocShell, i, nAttrPage, 0, nullptr, &aOptions );
        long nThisTab = aPrintFunc.GetTotalPages();
        tools::Long nThisTab = aPrintFunc.GetTotalPages();
        if (!aPrintFunc.HasPrintRange())
            mbHasEmptyRangeTable = true;

@@ -307,10 +307,10 @@ void ScPreview::RecalcPages()           // only nPageNo is changed

    if (!bDone)
    {
        long nPartPages = 0;
        tools::Long nPartPages = 0;
        for (SCTAB i=0; i<nTabsTested && nTab < static_cast<SCTAB>(nPages.size()); i++)
        {
            long nThisStart = nPartPages;
            tools::Long nThisStart = nPartPages;
            nPartPages += nPages[i];

            if (nPageNo>=nThisStart && nPageNo<nPartPages)
@@ -343,7 +343,7 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
    }

    Fraction aPreviewZoom( nZoom, 100 );
    Fraction aHorPrevZoom( static_cast<long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    Fraction aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );

    bool bDoPrint = ( pFillLocation == nullptr );
@@ -366,10 +366,10 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
            DrawRect(tools::Rectangle( 0, 0, aWinSize.Width(), -aOffset.Y() ));
    }

    long   nLeftMargin = 0;
    long   nRightMargin = 0;
    long   nTopMargin = 0;
    long   nBottomMargin = 0;
    tools::Long   nLeftMargin = 0;
    tools::Long   nRightMargin = 0;
    tools::Long   nTopMargin = 0;
    tools::Long   nBottomMargin = 0;
    bool   bHeaderOn = false;
    bool   bFooterOn = false;

@@ -401,7 +401,7 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
        aPage.SetTotalRange( Range(0,RANGE_MAX) );
        aPage.Select( aPageRange );

        long nPrinted = pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart, bDoPrint, pFillLocation );
        tools::Long nPrinted = pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart, bDoPrint, pFillLocation );
        OSL_ENSURE(nPrinted<=1, "What is happening?");

        SetMapMode(aMMMode);
@@ -452,15 +452,15 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
        if (nPrinted)   // if not, draw everything grey
        {
            aLocalPageSize = pPrintFunc->GetPageSize();
            aLocalPageSize.setWidth( static_cast<long>(aLocalPageSize.Width()  * HMM_PER_TWIPS ) );
            aLocalPageSize.setHeight( static_cast<long>(aLocalPageSize.Height() * HMM_PER_TWIPS ) );
            aLocalPageSize.setWidth( static_cast<tools::Long>(aLocalPageSize.Width()  * HMM_PER_TWIPS ) );
            aLocalPageSize.setHeight( static_cast<tools::Long>(aLocalPageSize.Height() * HMM_PER_TWIPS ) );

            nLeftMargin = static_cast<long>( nLeftMargin * HMM_PER_TWIPS );
            nRightMargin = static_cast<long>( nRightMargin * HMM_PER_TWIPS );
            nTopMargin = static_cast<long>( nTopMargin * HMM_PER_TWIPS );
            nBottomMargin = static_cast<long>( nBottomMargin * HMM_PER_TWIPS );
            nHeaderHeight = static_cast<long>( nHeaderHeight * HMM_PER_TWIPS * mnScale / 100 + nTopMargin );
            nFooterHeight = static_cast<long>( nFooterHeight * HMM_PER_TWIPS * mnScale / 100 + nBottomMargin );
            nLeftMargin = static_cast<tools::Long>( nLeftMargin * HMM_PER_TWIPS );
            nRightMargin = static_cast<tools::Long>( nRightMargin * HMM_PER_TWIPS );
            nTopMargin = static_cast<tools::Long>( nTopMargin * HMM_PER_TWIPS );
            nBottomMargin = static_cast<tools::Long>( nBottomMargin * HMM_PER_TWIPS );
            nHeaderHeight = static_cast<tools::Long>( nHeaderHeight * HMM_PER_TWIPS * mnScale / 100 + nTopMargin );
            nFooterHeight = static_cast<tools::Long>( nFooterHeight * HMM_PER_TWIPS * mnScale / 100 + nBottomMargin );
        }

        if (!bStateValid)
@@ -474,8 +474,8 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
    if ( !bDoPrint )
        return;

    long nPageEndX = aLocalPageSize.Width()  - aOffset.X();
    long nPageEndY = aLocalPageSize.Height() - aOffset.Y();
    tools::Long nPageEndX = aLocalPageSize.Width()  - aOffset.X();
    tools::Long nPageEndY = aLocalPageSize.Height() - aOffset.Y();
    if ( !bValidPage )
        nPageEndX = nPageEndY = 0;

@@ -514,7 +514,7 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
        else
            aEmptyMsg = ScResId(STR_PRINT_PREVIEW_NODATA);

        long nHeight = 3000;
        tools::Long nHeight = 3000;
        pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT));
        pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT_CJK));
        pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT_CTL));
@@ -534,10 +534,10 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
    {
        SetMapMode(aMMMode);
        SetLineColor( COL_BLACK );
        DrawInvert( static_cast<long>( nTopMargin - aOffset.Y() ), PointerStyle::VSizeBar );
        DrawInvert( static_cast<long>(nPageEndY - nBottomMargin ), PointerStyle::VSizeBar );
        DrawInvert( static_cast<long>( nLeftMargin - aOffset.X() ), PointerStyle::HSizeBar );
        DrawInvert( static_cast<long>( nPageEndX - nRightMargin ) , PointerStyle::HSizeBar );
        DrawInvert( static_cast<tools::Long>( nTopMargin - aOffset.Y() ), PointerStyle::VSizeBar );
        DrawInvert( static_cast<tools::Long>(nPageEndY - nBottomMargin ), PointerStyle::VSizeBar );
        DrawInvert( static_cast<tools::Long>( nLeftMargin - aOffset.X() ), PointerStyle::HSizeBar );
        DrawInvert( static_cast<tools::Long>( nPageEndX - nRightMargin ) , PointerStyle::HSizeBar );
        if( bHeaderOn )
        {
            DrawInvert( nHeaderHeight - aOffset.Y(), PointerStyle::VSizeBar );
@@ -726,7 +726,7 @@ void ScPreview::SetZoom(sal_uInt16 nNewZoom)
    //  apply new MapMode and call UpdateScrollBars to update aOffset

    Fraction aPreviewZoom( nZoom, 100 );
    Fraction aHorPrevZoom( static_cast<long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    Fraction aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
    SetMapMode( aMMMode );

@@ -740,7 +740,7 @@ void ScPreview::SetZoom(sal_uInt16 nNewZoom)
    Invalidate();
}

void ScPreview::SetPageNo( long nPage )
void ScPreview::SetPageNo( tools::Long nPage )
{
    nPageNo = nPage;
    RecalcPages();
@@ -749,13 +749,13 @@ void ScPreview::SetPageNo( long nPage )
    Invalidate();
}

long ScPreview::GetFirstPage(SCTAB nTabP)
tools::Long ScPreview::GetFirstPage(SCTAB nTabP)
{
    SCTAB nDocTabCount = pDocShell->GetDocument().GetTableCount();
    if (nTabP >= nDocTabCount)
        nTabP = nDocTabCount-1;

    long nPage = 0;
    tools::Long nPage = 0;
    if (nTabP>0)
    {
        CalcPages();
@@ -808,10 +808,10 @@ sal_uInt16 ScPreview::GetOptimalZoom(bool bWidthOnly)
    Size aLocalPageSize = lcl_GetDocPageSize( &pDocShell->GetDocument(), nTab );
    if ( aLocalPageSize.Width() && aLocalPageSize.Height() )
    {
        long nZoomX = static_cast<long>( aWinSize.Width() * 100  / ( aLocalPageSize.Width() * nWinScaleX ));
        long nZoomY = static_cast<long>( aWinSize.Height() * 100 / ( aLocalPageSize.Height() * nWinScaleY ));
        tools::Long nZoomX = static_cast<tools::Long>( aWinSize.Width() * 100  / ( aLocalPageSize.Width() * nWinScaleX ));
        tools::Long nZoomY = static_cast<tools::Long>( aWinSize.Height() * 100 / ( aLocalPageSize.Height() * nWinScaleY ));

        long nOptimal = nZoomX;
        tools::Long nOptimal = nZoomX;
        if (!bWidthOnly && nZoomY<nOptimal)
            nOptimal = nZoomY;

@@ -826,14 +826,14 @@ sal_uInt16 ScPreview::GetOptimalZoom(bool bWidthOnly)
        return nZoom;
}

void ScPreview::SetXOffset( long nX )
void ScPreview::SetXOffset( tools::Long nX )
{
    if ( aOffset.X() == nX )
        return;

    if (bValid)
    {
        long nDif = LogicToPixel(aOffset).X() - LogicToPixel(Point(nX,0)).X();
        tools::Long nDif = LogicToPixel(aOffset).X() - LogicToPixel(Point(nX,0)).X();
        aOffset.setX( nX );
        if (nDif && !bInSetZoom)
        {
@@ -853,14 +853,14 @@ void ScPreview::SetXOffset( long nX )
    Invalidate();
}

void ScPreview::SetYOffset( long nY )
void ScPreview::SetYOffset( tools::Long nY )
{
    if ( aOffset.Y() == nY )
        return;

    if (bValid)
    {
        long nDif = LogicToPixel(aOffset).Y() - LogicToPixel(Point(0,nY)).Y();
        tools::Long nDif = LogicToPixel(aOffset).Y() - LogicToPixel(Point(0,nY)).Y();
        aOffset.setY( nY );
        if (nDif && !bInSetZoom)
        {
@@ -953,7 +953,7 @@ void ScPreview::DataChanged( const DataChangedEvent& rDCEvt )
void ScPreview::MouseButtonDown( const MouseEvent& rMEvt )
{
    Fraction  aPreviewZoom( nZoom, 100 );
    Fraction  aHorPrevZoom( static_cast<long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    Fraction  aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    MapMode   aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );

    aButtonDownChangePoint = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
@@ -1036,13 +1036,13 @@ void ScPreview::MouseButtonDown( const MouseEvent& rMEvt )
void ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
{
        Fraction  aPreviewZoom( nZoom, 100 );
        Fraction  aHorPrevZoom( static_cast<long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
        Fraction  aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
        MapMode   aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );

        aButtonUpPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );

        long  nWidth = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Width();
        long  nHeight = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Height();
        tools::Long  nWidth = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Width();
        tools::Long  nHeight = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Height();

        if( rMEvt.IsLeft() && GetPointer() == PointerStyle::HSizeBar )
        {
@@ -1090,13 +1090,13 @@ void ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
                    ScDocShellModificator aModificator( *pDocShell );
                    if( bLeftRulerChange && bLeftRulerMove )
                    {
                       aLRItem.SetLeft( static_cast<long>( aButtonUpPt.X() / HMM_PER_TWIPS + aOffset.X() / HMM_PER_TWIPS ));
                       aLRItem.SetLeft( static_cast<tools::Long>( aButtonUpPt.X() / HMM_PER_TWIPS + aOffset.X() / HMM_PER_TWIPS ));
                       rStyleSet.Put( aLRItem );
                       pDocShell->SetModified();
                    }
                    else if( bRightRulerChange && bRightRulerMove )
                    {
                        aLRItem.SetRight( static_cast<long>( nWidth - aButtonUpPt.X() / HMM_PER_TWIPS - aOffset.X() / HMM_PER_TWIPS ));
                        aLRItem.SetRight( static_cast<tools::Long>( nWidth - aButtonUpPt.X() / HMM_PER_TWIPS - aOffset.X() / HMM_PER_TWIPS ));
                        rStyleSet.Put( aLRItem );
                        pDocShell->SetModified();
                    }
@@ -1179,7 +1179,7 @@ void ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
                        {
                            const SfxItemSet& rHeaderSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
                            Size  aHeaderSize = rHeaderSet.Get(ATTR_PAGE_SIZE).GetSize();
                            aHeaderSize.setHeight( static_cast<long>( aButtonUpPt.Y() / HMM_PER_TWIPS + aOffset.Y() / HMM_PER_TWIPS - aULItem.GetUpper()) );
                            aHeaderSize.setHeight( static_cast<tools::Long>( aButtonUpPt.Y() / HMM_PER_TWIPS + aOffset.Y() / HMM_PER_TWIPS - aULItem.GetUpper()) );
                            aHeaderSize.setHeight( aHeaderSize.Height() * 100 / mnScale );
                            SvxSetItem  aNewHeader( rStyleSet.Get(ATTR_PAGE_HEADERSET) );
                            aNewHeader.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aHeaderSize ) );
@@ -1194,7 +1194,7 @@ void ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
                        {
                            const SfxItemSet& rFooterSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
                            Size aFooterSize = rFooterSet.Get(ATTR_PAGE_SIZE).GetSize();
                            aFooterSize.setHeight( static_cast<long>( nHeight - aButtonUpPt.Y() / HMM_PER_TWIPS - aOffset.Y() / HMM_PER_TWIPS - aULItem.GetLower() ) );
                            aFooterSize.setHeight( static_cast<tools::Long>( nHeight - aButtonUpPt.Y() / HMM_PER_TWIPS - aOffset.Y() / HMM_PER_TWIPS - aULItem.GetLower() ) );
                            aFooterSize.setHeight( aFooterSize.Height() * 100 / mnScale );
                            SvxSetItem  aNewFooter( rStyleSet.Get(ATTR_PAGE_FOOTERSET) );
                            aNewFooter.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aFooterSize ) );
@@ -1249,18 +1249,18 @@ void ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
            }
            if( bMoveRulerAction )
            {
                long  nNewColWidth = 0;
                tools::Long  nNewColWidth = 0;
                std::vector<sc::ColRowSpan> aCols(1, sc::ColRowSpan(nColNumberButtonDown,nColNumberButtonDown));

                if( !bLayoutRTL )
                {
                    nNewColWidth = static_cast<long>( PixelToLogic( Point( rMEvt.GetPosPixel().X() - mvRight[ nColNumberButtonDown ], 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
                    nNewColWidth = static_cast<tools::Long>( PixelToLogic( Point( rMEvt.GetPosPixel().X() - mvRight[ nColNumberButtonDown ], 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
                    nNewColWidth += pDocShell->GetDocument().GetColWidth( nColNumberButtonDown, nTab );
                }
                else
                {

                    nNewColWidth = static_cast<long>( PixelToLogic( Point( mvRight[ nColNumberButtonDown ] - rMEvt.GetPosPixel().X(), 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
                    nNewColWidth = static_cast<tools::Long>( PixelToLogic( Point( mvRight[ nColNumberButtonDown ] - rMEvt.GetPosPixel().X(), 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
                    nNewColWidth += pDocShell->GetDocument().GetColWidth( nColNumberButtonDown, nTab );
                }

@@ -1286,17 +1286,17 @@ void ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
void ScPreview::MouseMove( const MouseEvent& rMEvt )
{
    Fraction aPreviewZoom( nZoom, 100 );
    Fraction aHorPrevZoom( static_cast<long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    Fraction aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    MapMode  aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
    Point    aMouseMovePoint = PixelToLogic( rMEvt.GetPosPixel(), aMMMode );

    long    nLeftMargin = 0;
    long    nRightMargin = 0;
    long    nTopMargin = 0;
    long    nBottomMargin = 0;
    tools::Long    nLeftMargin = 0;
    tools::Long    nRightMargin = 0;
    tools::Long    nTopMargin = 0;
    tools::Long    nBottomMargin = 0;

    long    nWidth = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Width();
    long    nHeight = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Height();
    tools::Long    nWidth = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Width();
    tools::Long    nHeight = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Height();

    if ( nPageNo < nTotalPages )
    {
@@ -1308,30 +1308,30 @@ void ScPreview::MouseMove( const MouseEvent& rMEvt )
        else
            pPrintFunc.reset(new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, nullptr, &aOptions ));

        nLeftMargin = static_cast<long>( pPrintFunc->GetLeftMargin() * HMM_PER_TWIPS - aOffset.X() );
        nRightMargin = static_cast<long>( pPrintFunc->GetRightMargin() * HMM_PER_TWIPS );
        nRightMargin = static_cast<long>( nWidth * HMM_PER_TWIPS - nRightMargin - aOffset.X() );
        nTopMargin = static_cast<long>( pPrintFunc->GetTopMargin() * HMM_PER_TWIPS - aOffset.Y() );
        nBottomMargin = static_cast<long>( pPrintFunc->GetBottomMargin() * HMM_PER_TWIPS );
        nBottomMargin = static_cast<long>( nHeight * HMM_PER_TWIPS - nBottomMargin - aOffset.Y() );
        nLeftMargin = static_cast<tools::Long>( pPrintFunc->GetLeftMargin() * HMM_PER_TWIPS - aOffset.X() );
        nRightMargin = static_cast<tools::Long>( pPrintFunc->GetRightMargin() * HMM_PER_TWIPS );
        nRightMargin = static_cast<tools::Long>( nWidth * HMM_PER_TWIPS - nRightMargin - aOffset.X() );
        nTopMargin = static_cast<tools::Long>( pPrintFunc->GetTopMargin() * HMM_PER_TWIPS - aOffset.Y() );
        nBottomMargin = static_cast<tools::Long>( pPrintFunc->GetBottomMargin() * HMM_PER_TWIPS );
        nBottomMargin = static_cast<tools::Long>( nHeight * HMM_PER_TWIPS - nBottomMargin - aOffset.Y() );
        if( mnScale > 0 )
        {
            nHeaderHeight = static_cast<long>( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS * mnScale / 100 );
            nFooterHeight = static_cast<long>( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS * mnScale / 100 );
            nHeaderHeight = static_cast<tools::Long>( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS * mnScale / 100 );
            nFooterHeight = static_cast<tools::Long>( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS * mnScale / 100 );
        }
        else
        {
            nHeaderHeight = static_cast<long>( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS );
            nFooterHeight = static_cast<long>( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS );
            nHeaderHeight = static_cast<tools::Long>( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS );
            nFooterHeight = static_cast<tools::Long>( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS );
        }
    }

    Point   aPixPt( rMEvt.GetPosPixel() );
    Point   aLeftTop = LogicToPixel( Point( nLeftMargin, -aOffset.Y() ) , aMMMode );
    Point   aLeftBottom = LogicToPixel( Point( nLeftMargin ,static_cast<long>(nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
    Point   aLeftBottom = LogicToPixel( Point( nLeftMargin ,static_cast<tools::Long>(nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
    Point   aRightTop = LogicToPixel( Point( nRightMargin, -aOffset.Y() ), aMMMode );
    Point   aTopLeft = LogicToPixel( Point( -aOffset.X(), nTopMargin ), aMMMode );
    Point   aTopRight = LogicToPixel( Point( static_cast<long>(nWidth * HMM_PER_TWIPS - aOffset.X()), nTopMargin ), aMMMode );
    Point   aTopRight = LogicToPixel( Point( static_cast<tools::Long>(nWidth * HMM_PER_TWIPS - aOffset.X()), nTopMargin ), aMMMode );
    Point   aBottomLeft = LogicToPixel( Point( -aOffset.X(), nBottomMargin ), aMMMode );
    Point   aHeaderLeft = LogicToPixel( Point(  -aOffset.X(), nHeaderHeight ), aMMMode );
    Point   aFooderLeft = LogicToPixel( Point( -aOffset.X(), nFooterHeight ), aMMMode );
@@ -1341,8 +1341,8 @@ void ScPreview::MouseMove( const MouseEvent& rMEvt )
    for( SCCOL i=aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
    {
        Point   aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
        Point   aColumnBottom = LogicToPixel( Point( 0, static_cast<long>( nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
        long nRight = i < static_cast<SCCOL>(mvRight.size()) ? mvRight[i] : 0;
        Point   aColumnBottom = LogicToPixel( Point( 0, static_cast<tools::Long>( nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
        tools::Long nRight = i < static_cast<SCCOL>(mvRight.size()) ? mvRight[i] : 0;
        if( aPixPt.X() < ( nRight + 2 ) && ( aPixPt.X() > ( nRight - 2 ) ) && ( aPixPt.X() < aRightTop.X() ) && ( aPixPt.X() > aLeftTop.X() )
            && ( aPixPt.Y() > aColumnTop.Y() ) && ( aPixPt.Y() < aColumnBottom.Y() ) && !bLeftRulerMove && !bRightRulerMove
            && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
@@ -1519,13 +1519,13 @@ css::uno::Reference<css::accessibility::XAccessible> ScPreview::CreateAccessible
    return xAcc;
}

void ScPreview::DragMove( long nDragMovePos, PointerStyle nFlags )
void ScPreview::DragMove( tools::Long nDragMovePos, PointerStyle nFlags )
{
    Fraction aPreviewZoom( nZoom, 100 );
    Fraction aHorPrevZoom( static_cast<long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    Fraction aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
    MapMode  aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
    SetMapMode( aMMMode );
    long  nPos = nDragMovePos;
    tools::Long  nPos = nDragMovePos;
    if( nFlags == PointerStyle::HSizeBar || nFlags == PointerStyle::HSplit )
    {
        if( nDragMovePos != aButtonDownChangePoint.X() )
@@ -1546,18 +1546,18 @@ void ScPreview::DragMove( long nDragMovePos, PointerStyle nFlags )
    }
}

void ScPreview::DrawInvert( long nDragPos, PointerStyle nFlags )
void ScPreview::DrawInvert( tools::Long nDragPos, PointerStyle nFlags )
{
    long  nHeight = lcl_GetDocPageSize( &pDocShell->GetDocument(), nTab ).Height();
    long  nWidth = lcl_GetDocPageSize( &pDocShell->GetDocument(), nTab ).Width();
    tools::Long  nHeight = lcl_GetDocPageSize( &pDocShell->GetDocument(), nTab ).Height();
    tools::Long  nWidth = lcl_GetDocPageSize( &pDocShell->GetDocument(), nTab ).Width();
    if( nFlags == PointerStyle::HSizeBar || nFlags == PointerStyle::HSplit )
    {
        tools::Rectangle aRect( nDragPos, -aOffset.Y(), nDragPos + 1,static_cast<long>( ( nHeight * HMM_PER_TWIPS ) - aOffset.Y()));
        tools::Rectangle aRect( nDragPos, -aOffset.Y(), nDragPos + 1,static_cast<tools::Long>( ( nHeight * HMM_PER_TWIPS ) - aOffset.Y()));
        Invert( aRect, InvertFlags::N50 );
    }
    else if( nFlags == PointerStyle::VSizeBar )
    {
        tools::Rectangle aRect( -aOffset.X(), nDragPos,static_cast<long>( ( nWidth * HMM_PER_TWIPS ) - aOffset.X() ), nDragPos + 1 );
        tools::Rectangle aRect( -aOffset.X(), nDragPos,static_cast<tools::Long>( ( nWidth * HMM_PER_TWIPS ) - aOffset.X() ), nDragPos + 1 );
        Invert( aRect, InvertFlags::N50 );
    }
}
diff --git a/sc/source/ui/view/prevloc.cxx b/sc/source/ui/view/prevloc.cxx
index 668903e..281cc46 100644
--- a/sc/source/ui/view/prevloc.cxx
+++ b/sc/source/ui/view/prevloc.cxx
@@ -282,20 +282,20 @@ tools::Rectangle ScPreviewLocationData::GetOffsetPixel( const ScAddress& rCellPo
    const double nScaleY = HMM_PER_TWIPS;
    SCTAB nTab = rRange.aStart.Tab();

    long nPosX = 0;
    tools::Long nPosX = 0;
    SCCOL nEndCol = rCellPos.Col();
    for (SCCOL nCol = rRange.aStart.Col(); nCol < nEndCol; nCol++)
    {
        sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
        if (nDocW)
            nPosX += static_cast<long>(nDocW * nScaleX);
            nPosX += static_cast<tools::Long>(nDocW * nScaleX);
    }
    long nSizeX = static_cast<long>( pDoc->GetColWidth( nEndCol, nTab ) * nScaleX );
    tools::Long nSizeX = static_cast<tools::Long>( pDoc->GetColWidth( nEndCol, nTab ) * nScaleX );

    SCROW nEndRow = rCellPos.Row();
    long nPosY = static_cast<long>(pDoc->GetScaledRowHeight( rRange.aStart.Row(),
    tools::Long nPosY = static_cast<tools::Long>(pDoc->GetScaledRowHeight( rRange.aStart.Row(),
            nEndRow, nTab, nScaleY));
    long nSizeY = static_cast<long>( pDoc->GetRowHeight( nEndRow, nTab ) * nScaleY );
    tools::Long nSizeY = static_cast<tools::Long>( pDoc->GetRowHeight( nEndRow, nTab ) * nScaleY );

    Size aOffsetLogic( nPosX, nPosY );
    Size aSizeLogic( nSizeX, nSizeY );
@@ -386,7 +386,7 @@ bool ScPreviewLocationData::IsFooterLeft() const
    return false;
}

long ScPreviewLocationData::GetNoteCountInRange( const tools::Rectangle& rVisiblePixel, bool bNoteMarks ) const
tools::Long ScPreviewLocationData::GetNoteCountInRange( const tools::Rectangle& rVisiblePixel, bool bNoteMarks ) const
{
    ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;

@@ -400,7 +400,7 @@ long ScPreviewLocationData::GetNoteCountInRange( const tools::Rectangle& rVisibl
    return nRet;
}

bool ScPreviewLocationData::GetNoteInRange( const tools::Rectangle& rVisiblePixel, long nIndex, bool bNoteMarks,
bool ScPreviewLocationData::GetNoteInRange( const tools::Rectangle& rVisiblePixel, tools::Long nIndex, bool bNoteMarks,
                                            ScAddress& rCellPos, tools::Rectangle& rNoteRect ) const
{
    ScPreviewLocationType eType = bNoteMarks ? SC_PLOC_NOTEMARK : SC_PLOC_NOTETEXT;
@@ -548,15 +548,15 @@ void ScPreviewLocationData::GetTableInfo( const tools::Rectangle& rVisiblePixel,
        }
        if ( bHasRepCols )
        {
            long nPosX = 0;
            tools::Long nPosX = 0;
            for ( nCol=nRepeatColStart; nCol<=nRepeatColEnd; nCol++ )
                if (!pDoc->ColHidden(nCol, nTab))
                {
                    sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
                    long nNextX = nPosX + static_cast<long>(nDocW * nScaleX);
                    tools::Long nNextX = nPosX + static_cast<tools::Long>(nDocW * nScaleX);

                    long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
                    long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
                    tools::Long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
                    tools::Long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
                    pColInfo[nColPos].Set( false, nCol,
                                                aRepeatRect.Left() + nPixelStart,
                                                aRepeatRect.Left() + nPixelEnd );
@@ -567,15 +567,15 @@ void ScPreviewLocationData::GetTableInfo( const tools::Rectangle& rVisiblePixel,
        }
        if ( bHasMainCols )
        {
            long nPosX = 0;
            tools::Long nPosX = 0;
            for ( nCol=nMainColStart; nCol<=nMainColEnd; nCol++ )
                if (!pDoc->ColHidden(nCol, nTab))
                {
                    sal_uInt16 nDocW = pDoc->GetColWidth( nCol, nTab );
                    long nNextX = nPosX + static_cast<long>(nDocW * nScaleX);
                    tools::Long nNextX = nPosX + static_cast<tools::Long>(nDocW * nScaleX);

                    long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
                    long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
                    tools::Long nPixelStart = pWindow->LogicToPixel( Size( nPosX, 0 ), aCellMapMode ).Width();
                    tools::Long nPixelEnd = pWindow->LogicToPixel( Size( nNextX, 0 ), aCellMapMode ).Width() - 1;
                    pColInfo[nColPos].Set( false, nCol,
                                                aMainRect.Left() + nPixelStart,
                                                aMainRect.Left() + nPixelEnd );
@@ -611,17 +611,17 @@ void ScPreviewLocationData::GetTableInfo( const tools::Rectangle& rVisiblePixel,
        }
        if ( bHasRepRows )
        {
            long nPosY = 0;
            tools::Long nPosY = 0;
            for (SCROW nRow = nRepeatRowStart; nRow <= nRepeatRowEnd; ++nRow)
            {
                if (pDoc->RowHidden(nRow, nTab))
                    continue;

                sal_uInt16 nDocH = pDoc->GetOriginalHeight( nRow, nTab );
                long nNextY = nPosY + static_cast<long>(nDocH * nScaleY);
                tools::Long nNextY = nPosY + static_cast<tools::Long>(nDocH * nScaleY);

                long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
                long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
                tools::Long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
                tools::Long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
                pRowInfo[nRowPos].Set( false, nRow,
                        aRepeatRect.Top() + nPixelStart,
                        aRepeatRect.Top() + nPixelEnd );
@@ -632,17 +632,17 @@ void ScPreviewLocationData::GetTableInfo( const tools::Rectangle& rVisiblePixel,
        }
        if ( bHasMainRows )
        {
            long nPosY = 0;
            tools::Long nPosY = 0;
            for (SCROW nRow = nMainRowStart; nRow <= nMainRowEnd; ++nRow)
            {
                if (pDoc->RowHidden(nRow, nTab))
                    continue;

                sal_uInt16 nDocH = pDoc->GetOriginalHeight( nRow, nTab );
                long nNextY = nPosY + static_cast<long>(nDocH * nScaleY);
                tools::Long nNextY = nPosY + static_cast<tools::Long>(nDocH * nScaleY);

                long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
                long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
                tools::Long nPixelStart = pWindow->LogicToPixel( Size( 0, nPosY ), aCellMapMode ).Height();
                tools::Long nPixelEnd = pWindow->LogicToPixel( Size( 0, nNextY ), aCellMapMode ).Height() - 1;
                pRowInfo[nRowPos].Set( false, nRow,
                        aMainRect.Top() + nPixelStart,
                        aMainRect.Top() + nPixelEnd );
diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx
index 1ebc28b..c16159c7 100644
--- a/sc/source/ui/view/prevwsh.cxx
+++ b/sc/source/ui/view/prevwsh.cxx
@@ -264,8 +264,8 @@ bool ScPreviewShell::GetPageSize( Size& aPageSize )
    const SfxItemSet* pParamSet = &pStyleSheet->GetItemSet();

    aPageSize = pParamSet->Get(ATTR_PAGE_SIZE).GetSize();
    aPageSize.setWidth( static_cast<long>(aPageSize.Width()  * HMM_PER_TWIPS ) );
    aPageSize.setHeight( static_cast<long>(aPageSize.Height() * HMM_PER_TWIPS ) );
    aPageSize.setWidth( static_cast<tools::Long>(aPageSize.Width()  * HMM_PER_TWIPS ) );
    aPageSize.setHeight( static_cast<tools::Long>(aPageSize.Height() * HMM_PER_TWIPS ) );
    return true;
}

@@ -274,11 +274,11 @@ void ScPreviewShell::UpdateNeededScrollBars( bool bFromZoom )
    Size aPageSize;
    OutputDevice* pDevice = Application::GetDefaultDevice();

    long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
    long nBarH = nBarW;
    tools::Long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize();
    tools::Long nBarH = nBarW;

    long aHeightOffSet = pDevice ? pDevice->PixelToLogic( Size( nBarW, nBarH ), pPreview->GetMapMode() ).Height() : 0;
    long aWidthOffSet = aHeightOffSet;
    tools::Long aHeightOffSet = pDevice ? pDevice->PixelToLogic( Size( nBarW, nBarH ), pPreview->GetMapMode() ).Height() : 0;
    tools::Long aWidthOffSet = aHeightOffSet;

    if (!GetPageSize( aPageSize ))
        return;
@@ -307,9 +307,9 @@ void ScPreviewShell::UpdateNeededScrollBars( bool bFromZoom )
    }

    // recalculate any needed scrollbars
    long nMaxWidthPos = aPageSize.Width() - aWindowSize.Width();
    tools::Long nMaxWidthPos = aPageSize.Width() - aWindowSize.Width();
    bHori = nMaxWidthPos >= 0;
    long nMaxHeightPos = aPageSize.Height() - aWindowSize.Height();
    tools::Long nMaxHeightPos = aPageSize.Height() - aWindowSize.Height();
    bVert = nMaxHeightPos >= 0;

    // see if having a scroll bar requires the other
@@ -358,7 +358,7 @@ void ScPreviewShell::UpdateScrollBars()
        pHorScroll->SetLineSize( aWindowSize.Width() / 16 );
        pHorScroll->SetPageSize( aWindowSize.Width() );
        pHorScroll->SetVisibleSize( aWindowSize.Width() );
        long nMaxPos = aPageSize.Width() - aWindowSize.Width();
        tools::Long nMaxPos = aPageSize.Width() - aWindowSize.Width();
        if ( nMaxPos<0 )
        {
            //  page smaller than window -> center (but put scrollbar to 0)
@@ -383,8 +383,8 @@ void ScPreviewShell::UpdateScrollBars()
    if( !pVerScroll )
        return;

    long nPageNo     = pPreview->GetPageNo();
    long nTotalPages = pPreview->GetTotalPages();
    tools::Long nPageNo     = pPreview->GetPageNo();
    tools::Long nTotalPages = pPreview->GetTotalPages();

    nMaxVertPos = aPageSize.Height() - aWindowSize.Height();
    pVerScroll->SetLineSize( aWindowSize.Height() / 16  );
@@ -418,12 +418,12 @@ void ScPreviewShell::UpdateScrollBars()

IMPL_LINK( ScPreviewShell, ScrollHandler, ScrollBar*, pScroll, void )
{
    long nPos           = pScroll->GetThumbPos();
    long nDelta         = pScroll->GetDelta();
    long nMaxRange      = pScroll->GetRangeMax();
    long nTotalPages    = pPreview->GetTotalPages();
    long nPageNo        = 0;
    long nPerPageLength = 0;
    tools::Long nPos           = pScroll->GetThumbPos();
    tools::Long nDelta         = pScroll->GetDelta();
    tools::Long nMaxRange      = pScroll->GetRangeMax();
    tools::Long nTotalPages    = pPreview->GetTotalPages();
    tools::Long nPageNo        = 0;
    tools::Long nPerPageLength = 0;
    bool bIsDivide      = true;

    if( nTotalPages )
@@ -498,12 +498,12 @@ bool ScPreviewShell::ScrollCommand( const CommandEvent& rCEvt )
    const CommandWheelData* pData = rCEvt.GetWheelData();
    if ( pData && pData->GetMode() == CommandWheelMode::ZOOM )
    {
        long nOld = pPreview->GetZoom();
        long nNew;
        tools::Long nOld = pPreview->GetZoom();
        tools::Long nNew;
        if ( pData->GetDelta() < 0 )
            nNew = std::max( long(MINZOOM), basegfx::zoomtools::zoomOut( nOld ));
            nNew = std::max( tools::Long(MINZOOM), basegfx::zoomtools::zoomOut( nOld ));
        else
            nNew = std::min( long(MAXZOOM), basegfx::zoomtools::zoomIn( nOld ));
            nNew = std::min( tools::Long(MAXZOOM), basegfx::zoomtools::zoomIn( nOld ));

        if ( nNew != nOld )
        {
@@ -579,8 +579,8 @@ void ScPreviewShell::Execute( SfxRequest& rReq )
        case SID_PREV_TABLE: // Accelerator
        case SID_PREVIEW_PREVIOUS:
            {
                long nPage = pPreview->GetPageNo();
                long nTotal = pPreview->GetTotalPages();
                tools::Long nPage = pPreview->GetPageNo();
                tools::Long nTotal = pPreview->GetTotalPages();
                if (nTotal && nPage > 0)
                    pPreview->SetPageNo( nPage-1 );
            }
@@ -589,8 +589,8 @@ void ScPreviewShell::Execute( SfxRequest& rReq )
        case SID_PREVIEW_NEXT:
            {
                bool bAllTested = pPreview->AllTested();
                long nPage = pPreview->GetPageNo();
                long nTotal = pPreview->GetTotalPages();
                tools::Long nPage = pPreview->GetPageNo();
                tools::Long nTotal = pPreview->GetTotalPages();
                if (nTotal && (nPage+1 < nTotal || !bAllTested))
                    pPreview->SetPageNo( nPage+1 );
            }
@@ -598,8 +598,8 @@ void ScPreviewShell::Execute( SfxRequest& rReq )
        case SID_CURSORTOPOFFILE: // Accelerator
        case SID_PREVIEW_FIRST:
            {
                long nPage = pPreview->GetPageNo();
                long nTotal = pPreview->GetTotalPages();
                tools::Long nPage = pPreview->GetPageNo();
                tools::Long nTotal = pPreview->GetTotalPages();
                if (nTotal && nPage != 0)
                    pPreview->SetPageNo( 0 );
            }
@@ -610,8 +610,8 @@ void ScPreviewShell::Execute( SfxRequest& rReq )
                if (!pPreview->AllTested())
                    pPreview->CalcAll();

                long nPage = pPreview->GetPageNo();
                long nTotal = pPreview->GetTotalPages();
                tools::Long nPage = pPreview->GetPageNo();
                tools::Long nTotal = pPreview->GetTotalPages();
                if (nTotal && nPage+1 != nTotal)
                    pPreview->SetPageNo( nTotal-1 );
            }
@@ -771,8 +771,8 @@ void ScPreviewShell::GetState( SfxItemSet& rSet )
    pPreview->SetInGetState(true);

    SCTAB nTab      = pPreview->GetTab();
    long nPage      = pPreview->GetPageNo();
    long nTotal     = pPreview->GetTotalPages();
    tools::Long nPage      = pPreview->GetPageNo();
    tools::Long nTotal     = pPreview->GetTotalPages();
    sal_uInt16 nZoom    = pPreview->GetZoom();
    bool bAllTested = pPreview->AllTested();

@@ -973,26 +973,26 @@ void ScPreviewShell::DoScroll( sal_uInt16 nMode )
{
    Point   aCurPos, aPrevPos;

    long nHRange    = pHorScroll->GetRange().Max();
    long nHLine     = pHorScroll->GetLineSize();
    long nHPage     = pHorScroll->GetPageSize();
    long nVRange    = pVerScroll->GetRange().Max();
    long nVLine     = pVerScroll->GetLineSize();
    long nVPage     = pVerScroll->GetPageSize();
    tools::Long nHRange    = pHorScroll->GetRange().Max();
    tools::Long nHLine     = pHorScroll->GetLineSize();
    tools::Long nHPage     = pHorScroll->GetPageSize();
    tools::Long nVRange    = pVerScroll->GetRange().Max();
    tools::Long nVLine     = pVerScroll->GetLineSize();
    tools::Long nVPage     = pVerScroll->GetPageSize();

    aCurPos.setX( pHorScroll->GetThumbPos() );
    aCurPos.setY( pVerScroll->GetThumbPos() );
    aPrevPos = aCurPos;

    long nThumbPos  = pVerScroll->GetThumbPos();
    long nRangeMax  = pVerScroll->GetRangeMax();
    tools::Long nThumbPos  = pVerScroll->GetThumbPos();
    tools::Long nRangeMax  = pVerScroll->GetRangeMax();

    switch( nMode )
    {
        case SID_CURSORUP:
            if( nMaxVertPos<0 )
            {
                long nPage = pPreview->GetPageNo();
                tools::Long nPage = pPreview->GetPageNo();

                if( nPage>0 )
                {
@@ -1007,8 +1007,8 @@ void ScPreviewShell::DoScroll( sal_uInt16 nMode )
        case SID_CURSORDOWN:
            if( nMaxVertPos<0 )
            {
                long nPage = pPreview->GetPageNo();
                long nTotal = pPreview->GetTotalPages();
                tools::Long nPage = pPreview->GetPageNo();
                tools::Long nTotal = pPreview->GetTotalPages();

                // before testing for last page, make sure all page counts are calculated
                if ( nPage+1 == nTotal && !pPreview->AllTested() )
@@ -1036,7 +1036,7 @@ void ScPreviewShell::DoScroll( sal_uInt16 nMode )
        case SID_CURSORPAGEUP:
            if( nThumbPos==0 || nMaxVertPos<0 )
            {
                long nPage = pPreview->GetPageNo();
                tools::Long nPage = pPreview->GetPageNo();

                if( nPage>0 )
                {
@@ -1052,8 +1052,8 @@ void ScPreviewShell::DoScroll( sal_uInt16 nMode )
        case SID_CURSORPAGEDOWN:
            if( (std::abs(nVPage+nThumbPos-nRangeMax)<10) || nMaxVertPos<0 )
            {
                long nPage = pPreview->GetPageNo();
                long nTotal = pPreview->GetTotalPages();
                tools::Long nPage = pPreview->GetPageNo();
                tools::Long nTotal = pPreview->GetTotalPages();

                // before testing for last page, make sure all page counts are calculated
                if ( nPage+1 == nTotal && !pPreview->AllTested() )
@@ -1075,8 +1075,8 @@ void ScPreviewShell::DoScroll( sal_uInt16 nMode )
        case SID_CURSORHOME:
            if( nMaxVertPos<0 )
            {
                long nPage  = pPreview->GetPageNo();
                long nTotal = pPreview->GetTotalPages();
                tools::Long nPage  = pPreview->GetPageNo();
                tools::Long nTotal = pPreview->GetTotalPages();
                if( nTotal && nPage != 0 )
                {
                    SfxViewFrame* pSfxViewFrame = GetViewFrame();
@@ -1095,8 +1095,8 @@ void ScPreviewShell::DoScroll( sal_uInt16 nMode )
            {
                if( !pPreview->AllTested() )
                    pPreview->CalcAll();
                long nPage  = pPreview->GetPageNo();
                long nTotal = pPreview->GetTotalPages();
                tools::Long nPage  = pPreview->GetPageNo();
                tools::Long nTotal = pPreview->GetTotalPages();
                if( nTotal && nPage+1 != nTotal )
                {
                    SfxViewFrame* pSfxViewFrame = GetViewFrame();
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index ec875de..467ec9f 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -146,7 +146,7 @@ size_t ScPageRowEntry::CountVisible() const
        return nPagesX;
}

static long lcl_LineTotal(const ::editeng::SvxBorderLine* pLine)
static tools::Long lcl_LineTotal(const ::editeng::SvxBorderLine* pLine)
{
    return pLine ? ( pLine->GetScaledWidth() ) : 0;
}
@@ -195,7 +195,7 @@ void ScPrintFunc::Construct( const ScPrintOptions* pOptions )
}

ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab,
                            long nPage, long nDocP, const ScRange* pArea,
                            tools::Long nPage, tools::Long nDocP, const ScRange* pArea,
                            const ScPrintOptions* pOptions,
                            ScPageBreakData* pData )
    :   pDocShell           ( pShell ),
@@ -265,7 +265,7 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter,
}

ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
                            long nPage, long nDocP, const ScRange* pArea,
                            tools::Long nPage, tools::Long nDocP, const ScRange* pArea,
                            const ScPrintOptions* pOptions )
    :   pDocShell           ( pShell ),
        rDoc(pDocShell->GetDocument()),
@@ -507,13 +507,13 @@ void ScPrintFunc::DrawToDev(ScDocument& rDoc, OutputDevice* pDev, double /* nPri
    if (nY1 > rDoc.MaxRow()) nY1 = rDoc.MaxRow();
    if (nY2 > rDoc.MaxRow()) nY2 = rDoc.MaxRow();

    long nDevSizeX = aRect.Right()-aRect.Left()+1;
    long nDevSizeY = aRect.Bottom()-aRect.Top()+1;
    tools::Long nDevSizeX = aRect.Right()-aRect.Left()+1;
    tools::Long nDevSizeY = aRect.Bottom()-aRect.Top()+1;

    long nTwipsSizeX = 0;
    tools::Long nTwipsSizeX = 0;
    for (SCCOL i=nX1; i<=nX2; i++)
        nTwipsSizeX += rDoc.GetColWidth( i, nTab );
    long nTwipsSizeY = static_cast<long>(rDoc.GetRowHeight( nY1, nY2, nTab ));
    tools::Long nTwipsSizeY = static_cast<tools::Long>(rDoc.GetRowHeight( nY1, nY2, nTab ));

    //  if no lines, still space for the outline frame (20 Twips = 1pt)
    //  (HasLines initializes aLines to 0,0,0,0)
@@ -542,8 +542,8 @@ void ScPrintFunc::DrawToDev(ScDocument& rDoc, OutputDevice* pDev, double /* nPri
    if (bEmbed)
        rDoc.SetEmbedded(aERange);

    long nScrX = aRect.Left();
    long nScrY = aRect.Top();
    tools::Long nScrX = aRect.Left();
    tools::Long nScrY = aRect.Top();

    //  If no lines, still leave space for grid lines
    //  (would be elseways cut away)
@@ -576,8 +576,8 @@ void ScPrintFunc::DrawToDev(ScDocument& rDoc, OutputDevice* pDev, double /* nPri
        aOutputData.SetSnapPixel();

    Point aLogStart = pDev->PixelToLogic(Point(nScrX, nScrY), MapMode(MapUnit::Map100thMM));
    long nLogStX = aLogStart.X();
    long nLogStY = aLogStart.Y();
    tools::Long nLogStX = aLogStart.X();
    tools::Long nLogStY = aLogStart.Y();

    //!     nZoom for GetFont in OutputData ???

@@ -614,8 +614,8 @@ void ScPrintFunc::DrawToDev(ScDocument& rDoc, OutputDevice* pDev, double /* nPri
        Size aOne = pDev->PixelToLogic( Size(1,1) );
        if (bMetaFile)
            aOne = Size(1,1);   // compatible with DrawGrid
        long nRight = nScrX + aOutputData.GetScrW() - aOne.Width();
        long nBottom = nScrY + aOutputData.GetScrH() - aOne.Height();
        tools::Long nRight = nScrX + aOutputData.GetScrW() - aOne.Width();
        tools::Long nBottom = nScrY + aOutputData.GetScrH() - aOne.Height();

        bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );

@@ -654,7 +654,7 @@ static void lcl_FillHFParam( ScPrintHFParam& rParam, const SfxItemSet* pHFSet )
        rParam.bShared  = pHFSet->Get(ATTR_PAGE_SHARED).GetValue();
        rParam.nHeight  = pHFSet->Get(ATTR_PAGE_SIZE).GetSize().Height();
        const SvxLRSpaceItem* pHFLR = &pHFSet->Get(ATTR_LRSPACE);
        long nTmp;
        tools::Long nTmp;
        nTmp = pHFLR->GetLeft();
        rParam.nLeft = nTmp < 0 ? 0 : sal_uInt16(nTmp);
        nTmp = pHFLR->GetRight();
@@ -763,14 +763,14 @@ bool ScPrintFunc::AdjustPrintArea( bool bNew )
    return true;
}

long ScPrintFunc::TextHeight( const EditTextObject* pObject )
tools::Long ScPrintFunc::TextHeight( const EditTextObject* pObject )
{
    if (!pObject)
        return 0;

    pEditEngine->SetTextNewDefaults( *pObject, *pEditDefaults, false );

    return static_cast<long>(pEditEngine->GetTextHeight());
    return static_cast<tools::Long>(pEditEngine->GetTextHeight());
}

//  nZoom must be set !!!
@@ -786,7 +786,7 @@ void ScPrintFunc::UpdateHFHeight( ScPrintHFParam& rParam )
    //  calculate nHeight from content

    MakeEditEngine();
    long nPaperWidth = ( aPageSize.Width() - nLeftMargin - nRightMargin -
    tools::Long nPaperWidth = ( aPageSize.Width() - nLeftMargin - nRightMargin -
                            rParam.nLeft - rParam.nRight ) * 100 / nZoom;
    if (rParam.pBorder)
        nPaperWidth -= ( rParam.pBorder->GetDistance(SvxBoxItemLine::LEFT) +
@@ -800,7 +800,7 @@ void ScPrintFunc::UpdateHFHeight( ScPrintHFParam& rParam )

    pEditEngine->SetPaperSize( Size( nPaperWidth, 10000 ) );

    long nMaxHeight = 0;
    tools::Long nMaxHeight = 0;
    if ( rParam.pLeft )
    {
        nMaxHeight = std::max( nMaxHeight, TextHeight( rParam.pLeft->GetLeftArea() ) );
@@ -835,7 +835,7 @@ void ScPrintFunc::InitParam( const ScPrintOptions* pOptions )

                                // TabPage "Page"
    const SvxLRSpaceItem* pLRItem = &pParamSet->Get( ATTR_LRSPACE );
    long nTmp;
    tools::Long nTmp;
    nTmp = pLRItem->GetLeft();
    nLeftMargin = nTmp < 0 ? 0 : sal_uInt16(nTmp);
    nTmp = pLRItem->GetRight();
@@ -1098,7 +1098,7 @@ Size ScPrintFunc::GetDataSize() const
    return aSize;
}

void ScPrintFunc::GetScaleData( Size& rPhysSize, long& rDocHdr, long& rDocFtr )
void ScPrintFunc::GetScaleData( Size& rPhysSize, tools::Long& rDocHdr, tools::Long& rDocFtr )
{
    rPhysSize = aPageSize;
    rPhysSize.AdjustWidth( -(nLeftMargin + nRightMargin) );
@@ -1253,7 +1253,7 @@ static void lcl_DrawGraphic( const SvxBrushItem &rBrush, vcl::RenderContext *pOu

// The frame is drawn inwards

void ScPrintFunc::DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH,
void ScPrintFunc::DrawBorder( tools::Long nScrX, tools::Long nScrY, tools::Long nScrW, tools::Long nScrH,
                                const SvxBoxItem* pBorderData, const SvxBrushItem* pBackground,
                                const SvxShadowItem* pShadow )
{
@@ -1267,18 +1267,18 @@ void ScPrintFunc::DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH,
    if (!pBorderData && !pBackground && !pShadow)
        return;                                     // nothing to do

    long nLeft   = 0;
    long nRight  = 0;
    long nTop    = 0;
    long nBottom = 0;
    tools::Long nLeft   = 0;
    tools::Long nRight  = 0;
    tools::Long nTop    = 0;
    tools::Long nBottom = 0;

    //  aFrameRect - outside around frame, without shadow
    if ( pShadow && pShadow->GetLocation() != SvxShadowLocation::NONE )
    {
        nLeft   += static_cast<long>( pShadow->CalcShadowSpace(SvxShadowItemSide::LEFT)   * nScaleX );
        nRight  += static_cast<long>( pShadow->CalcShadowSpace(SvxShadowItemSide::RIGHT)  * nScaleX );
        nTop    += static_cast<long>( pShadow->CalcShadowSpace(SvxShadowItemSide::TOP)    * nScaleY );
        nBottom += static_cast<long>( pShadow->CalcShadowSpace(SvxShadowItemSide::BOTTOM) * nScaleY );
        nLeft   += static_cast<tools::Long>( pShadow->CalcShadowSpace(SvxShadowItemSide::LEFT)   * nScaleX );
        nRight  += static_cast<tools::Long>( pShadow->CalcShadowSpace(SvxShadowItemSide::RIGHT)  * nScaleX );
        nTop    += static_cast<tools::Long>( pShadow->CalcShadowSpace(SvxShadowItemSide::TOP)    * nScaleY );
        nBottom += static_cast<tools::Long>( pShadow->CalcShadowSpace(SvxShadowItemSide::BOTTOM) * nScaleY );
    }
    tools::Rectangle aFrameRect( Point(nScrX+nLeft, nScrY+nTop),
                          Size(nScrW-nLeft-nRight, nScrH-nTop-nBottom) );
@@ -1286,13 +1286,13 @@ void ScPrintFunc::DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH,
    //  center of frame, to paint lines through OutputData
    if (pBorderData)
    {
        nLeft   += static_cast<long>( lcl_LineTotal(pBorderData->GetLeft())   * nScaleX / 2 );
        nRight  += static_cast<long>( lcl_LineTotal(pBorderData->GetRight())  * nScaleX / 2 );
        nTop    += static_cast<long>( lcl_LineTotal(pBorderData->GetTop())    * nScaleY / 2 );
        nBottom += static_cast<long>( lcl_LineTotal(pBorderData->GetBottom()) * nScaleY / 2 );
        nLeft   += static_cast<tools::Long>( lcl_LineTotal(pBorderData->GetLeft())   * nScaleX / 2 );
        nRight  += static_cast<tools::Long>( lcl_LineTotal(pBorderData->GetRight())  * nScaleX / 2 );
        nTop    += static_cast<tools::Long>( lcl_LineTotal(pBorderData->GetTop())    * nScaleY / 2 );
        nBottom += static_cast<tools::Long>( lcl_LineTotal(pBorderData->GetBottom()) * nScaleY / 2 );
    }
    long nEffHeight = nScrH - nTop - nBottom;
    long nEffWidth = nScrW - nLeft - nRight;
    tools::Long nEffHeight = nScrH - nTop - nBottom;
    tools::Long nEffWidth = nScrW - nLeft - nRight;
    if (nEffHeight<=0 || nEffWidth<=0)
        return;                                         // empty

@@ -1323,8 +1323,8 @@ void ScPrintFunc::DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH,
    {
        pDev->SetFillColor(pShadow->GetColor());
        pDev->SetLineColor();
        long nShadowX = static_cast<long>( pShadow->GetWidth() * nScaleX );
        long nShadowY = static_cast<long>( pShadow->GetWidth() * nScaleY );
        tools::Long nShadowX = static_cast<tools::Long>( pShadow->GetWidth() * nScaleX );
        tools::Long nShadowY = static_cast<tools::Long>( pShadow->GetWidth() * nScaleY );
        switch (pShadow->GetLocation())
        {
            case SvxShadowLocation::TopLeft:
@@ -1389,28 +1389,28 @@ void ScPrintFunc::DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH,
    aOutputData.DrawFrame(*pDev);
}

void ScPrintFunc::PrintColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY )
void ScPrintFunc::PrintColHdr( SCCOL nX1, SCCOL nX2, tools::Long nScrX, tools::Long nScrY )
{
    bool bLayoutRTL = rDoc.IsLayoutRTL( nPrintTab );
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    Size aOnePixel = pDev->PixelToLogic(Size(1,1));
    long nOneX = aOnePixel.Width();
    long nOneY = aOnePixel.Height();
    tools::Long nOneX = aOnePixel.Width();
    tools::Long nOneY = aOnePixel.Height();
    SCCOL nCol;

    long nHeight = static_cast<long>(PRINT_HEADER_HEIGHT * nScaleY);
    long nEndY = nScrY + nHeight - nOneY;
    tools::Long nHeight = static_cast<tools::Long>(PRINT_HEADER_HEIGHT * nScaleY);
    tools::Long nEndY = nScrY + nHeight - nOneY;

    long nPosX = nScrX;
    tools::Long nPosX = nScrX;
    if ( bLayoutRTL )
    {
        for (nCol=nX1; nCol<=nX2; nCol++)
            nPosX += static_cast<long>( rDoc.GetColWidth( nCol, nPrintTab ) * nScaleX );
            nPosX += static_cast<tools::Long>( rDoc.GetColWidth( nCol, nPrintTab ) * nScaleX );
    }
    else
        nPosX -= nOneX;
    long nPosY = nScrY - nOneY;
    tools::Long nPosY = nScrY - nOneY;
    OUString aText;

    for (nCol=nX1; nCol<=nX2; nCol++)
@@ -1418,17 +1418,17 @@ void ScPrintFunc::PrintColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY )
        sal_uInt16 nDocW = rDoc.GetColWidth( nCol, nPrintTab );
        if (nDocW)
        {
            long nWidth = static_cast<long>(nDocW * nScaleX);
            long nEndX = nPosX + nWidth * nLayoutSign;
            tools::Long nWidth = static_cast<tools::Long>(nDocW * nScaleX);
            tools::Long nEndX = nPosX + nWidth * nLayoutSign;

            pDev->DrawRect( tools::Rectangle( nPosX,nPosY,nEndX,nEndY ) );

            aText = ::ScColToAlpha( nCol);
            long nTextWidth = pDev->GetTextWidth(aText);
            long nTextHeight = pDev->GetTextHeight();
            long nAddX = ( nWidth  - nTextWidth  ) / 2;
            long nAddY = ( nHeight - nTextHeight ) / 2;
            long nTextPosX = nPosX+nAddX;
            tools::Long nTextWidth = pDev->GetTextWidth(aText);
            tools::Long nTextHeight = pDev->GetTextHeight();
            tools::Long nAddX = ( nWidth  - nTextWidth  ) / 2;
            tools::Long nAddY = ( nHeight - nTextHeight ) / 2;
            tools::Long nTextPosX = nPosX+nAddX;
            if ( bLayoutRTL )
                nTextPosX -= nWidth;
            pDev->DrawText( Point( nTextPosX,nPosY+nAddY ), aText );
@@ -1438,23 +1438,23 @@ void ScPrintFunc::PrintColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY )
    }
}

void ScPrintFunc::PrintRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY )
void ScPrintFunc::PrintRowHdr( SCROW nY1, SCROW nY2, tools::Long nScrX, tools::Long nScrY )
{
    Size aOnePixel = pDev->PixelToLogic(Size(1,1));
    long nOneX = aOnePixel.Width();
    long nOneY = aOnePixel.Height();
    tools::Long nOneX = aOnePixel.Width();
    tools::Long nOneY = aOnePixel.Height();

    bool bLayoutRTL = rDoc.IsLayoutRTL( nPrintTab );

    long nWidth = static_cast<long>(PRINT_HEADER_WIDTH * nScaleX);
    long nEndX = nScrX + nWidth;
    long nPosX = nScrX;
    tools::Long nWidth = static_cast<tools::Long>(PRINT_HEADER_WIDTH * nScaleX);
    tools::Long nEndX = nScrX + nWidth;
    tools::Long nPosX = nScrX;
    if ( !bLayoutRTL )
    {
        nEndX -= nOneX;
        nPosX -= nOneX;
    }
    long nPosY = nScrY - nOneY;
    tools::Long nPosY = nScrY - nOneY;
    OUString aText;

    for (SCROW nRow=nY1; nRow<=nY2; nRow++)
@@ -1462,16 +1462,16 @@ void ScPrintFunc::PrintRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY )
        sal_uInt16 nDocH = rDoc.GetRowHeight( nRow, nPrintTab );
        if (nDocH)
        {
            long nHeight = static_cast<long>(nDocH * nScaleY);
            long nEndY = nPosY + nHeight;
            tools::Long nHeight = static_cast<tools::Long>(nDocH * nScaleY);
            tools::Long nEndY = nPosY + nHeight;

            pDev->DrawRect( tools::Rectangle( nPosX,nPosY,nEndX,nEndY ) );

            aText = OUString::number( nRow+1 );
            long nTextWidth = pDev->GetTextWidth(aText);
            long nTextHeight = pDev->GetTextHeight();
            long nAddX = ( nWidth  - nTextWidth  ) / 2;
            long nAddY = ( nHeight - nTextHeight ) / 2;
            tools::Long nTextWidth = pDev->GetTextWidth(aText);
            tools::Long nTextHeight = pDev->GetTextHeight();
            tools::Long nAddX = ( nWidth  - nTextWidth  ) / 2;
            tools::Long nAddY = ( nHeight - nTextHeight ) / 2;
            pDev->DrawText( Point( nPosX+nAddX,nPosY+nAddY ), aText );

            nPosY = nEndY;
@@ -1479,56 +1479,56 @@ void ScPrintFunc::PrintRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY )
    }
}

void ScPrintFunc::LocateColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY,
void ScPrintFunc::LocateColHdr( SCCOL nX1, SCCOL nX2, tools::Long nScrX, tools::Long nScrY,
                                bool bRepCol, ScPreviewLocationData& rLocationData )
{
    Size aOnePixel = pDev->PixelToLogic(Size(1,1));
    long nOneX = aOnePixel.Width();
    long nOneY = aOnePixel.Height();
    tools::Long nOneX = aOnePixel.Width();
    tools::Long nOneY = aOnePixel.Height();

    long nHeight = static_cast<long>(PRINT_HEADER_HEIGHT * nScaleY);
    long nEndY = nScrY + nHeight - nOneY;
    tools::Long nHeight = static_cast<tools::Long>(PRINT_HEADER_HEIGHT * nScaleY);
    tools::Long nEndY = nScrY + nHeight - nOneY;

    long nPosX = nScrX - nOneX;
    tools::Long nPosX = nScrX - nOneX;
    for (SCCOL nCol=nX1; nCol<=nX2; nCol++)
    {
        sal_uInt16 nDocW = rDoc.GetColWidth( nCol, nPrintTab );
        if (nDocW)
            nPosX += static_cast<long>(nDocW * nScaleX);
            nPosX += static_cast<tools::Long>(nDocW * nScaleX);
    }
    tools::Rectangle aCellRect( nScrX, nScrY, nPosX, nEndY );
    rLocationData.AddColHeaders( aCellRect, nX1, nX2, bRepCol );
}

void ScPrintFunc::LocateRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY,
void ScPrintFunc::LocateRowHdr( SCROW nY1, SCROW nY2, tools::Long nScrX, tools::Long nScrY,
                                bool bRepRow, ScPreviewLocationData& rLocationData )
{
    Size aOnePixel = pDev->PixelToLogic(Size(1,1));
    long nOneX = aOnePixel.Width();
    long nOneY = aOnePixel.Height();
    tools::Long nOneX = aOnePixel.Width();
    tools::Long nOneY = aOnePixel.Height();

    bool bLayoutRTL = rDoc.IsLayoutRTL( nPrintTab );

    long nWidth = static_cast<long>(PRINT_HEADER_WIDTH * nScaleX);
    long nEndX = nScrX + nWidth;
    tools::Long nWidth = static_cast<tools::Long>(PRINT_HEADER_WIDTH * nScaleX);
    tools::Long nEndX = nScrX + nWidth;
    if ( !bLayoutRTL )
        nEndX -= nOneX;

    long nPosY = nScrY - nOneY;
    tools::Long nPosY = nScrY - nOneY;
    nPosY += rDoc.GetScaledRowHeight( nY1, nY2, nPrintTab, nScaleY);
    tools::Rectangle aCellRect( nScrX, nScrY, nEndX, nPosY );
    rLocationData.AddRowHeaders( aCellRect, nY1, nY2, bRepRow );
}

void ScPrintFunc::LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
                                long nScrX, long nScrY, bool bRepCol, bool bRepRow,
                                tools::Long nScrX, tools::Long nScrY, bool bRepCol, bool bRepRow,
                                ScPreviewLocationData& rLocationData )
{
    //  get MapMode for drawing objects (same MapMode as in ScOutputData::PrintDrawingLayer)

    Point aLogPos = OutputDevice::LogicToLogic(Point(nScrX,nScrY), aOffsetMode, aLogicMode);
    long nLogStX = aLogPos.X();
    long nLogStY = aLogPos.Y();
    tools::Long nLogStX = aLogPos.X();
    tools::Long nLogStY = aLogPos.Y();

    SCCOL nCol;
    Point aTwipOffset;
@@ -1537,26 +1537,26 @@ void ScPrintFunc::LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
    aTwipOffset.AdjustY( -sal_Int32(rDoc.GetRowHeight( 0, nY1-1, nPrintTab )) );

    Point aMMOffset( aTwipOffset );
    aMMOffset.setX( static_cast<long>(aMMOffset.X() * HMM_PER_TWIPS) );
    aMMOffset.setY( static_cast<long>(aMMOffset.Y() * HMM_PER_TWIPS) );
    aMMOffset.setX( static_cast<tools::Long>(aMMOffset.X() * HMM_PER_TWIPS) );
    aMMOffset.setY( static_cast<tools::Long>(aMMOffset.Y() * HMM_PER_TWIPS) );
    aMMOffset += Point( nLogStX, nLogStY );
    MapMode aDrawMapMode( MapUnit::Map100thMM, aMMOffset, aLogicMode.GetScaleX(), aLogicMode.GetScaleY() );

    //  get pixel rectangle

    Size aOnePixel = pDev->PixelToLogic(Size(1,1));
    long nOneX = aOnePixel.Width();
    long nOneY = aOnePixel.Height();
    tools::Long nOneX = aOnePixel.Width();
    tools::Long nOneY = aOnePixel.Height();

    long nPosX = nScrX - nOneX;
    tools::Long nPosX = nScrX - nOneX;
    for (nCol=nX1; nCol<=nX2; nCol++)
    {
        sal_uInt16 nDocW = rDoc.GetColWidth( nCol, nPrintTab );
        if (nDocW)
            nPosX += static_cast<long>(nDocW * nScaleX);
            nPosX += static_cast<tools::Long>(nDocW * nScaleX);
    }

    long nPosY = nScrY - nOneY;
    tools::Long nPosY = nScrY - nOneY;
    nPosY += rDoc.GetScaledRowHeight( nY1, nY2, nPrintTab, nScaleY);
    tools::Rectangle aCellRect( nScrX, nScrY, nPosX, nPosY );
    rLocationData.AddCellRange( aCellRect, ScRange( nX1,nY1,nPrintTab, nX2,nY2,nPrintTab ),
@@ -1564,7 +1564,7 @@ void ScPrintFunc::LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
}

void ScPrintFunc::PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
                                long nScrX, long nScrY,
                                tools::Long nScrX, tools::Long nScrY,
                                bool bShLeft, bool bShTop, bool bShRight, bool bShBottom )
{
    // #i47547# nothing to do if the end of the print area is before the end of
@@ -1582,8 +1582,8 @@ void ScPrintFunc::PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
    }

    Point aPos = OutputDevice::LogicToLogic(Point(nScrX,nScrY), aOffsetMode, aLogicMode);
    long nLogStX = aPos.X();
    long nLogStY = aPos.Y();
    tools::Long nLogStX = aPos.X();
    tools::Long nLogStY = aPos.Y();

                    //  Assemble data

@@ -1670,12 +1670,12 @@ void ScPrintFunc::PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
    aOutputData.PostPrintDrawingLayer(aMMOffset); // #i74768#
}

bool ScPrintFunc::IsMirror( long nPageNo )          // Mirror margins?
bool ScPrintFunc::IsMirror( tools::Long nPageNo )          // Mirror margins?
{
    return nPageUsage == SvxPageUsage::Mirror && (nPageNo & 1);
}

bool ScPrintFunc::IsLeft( long nPageNo )            // left foot notes?
bool ScPrintFunc::IsLeft( tools::Long nPageNo )            // left foot notes?
{
    bool bLeft;
    if (nPageUsage == SvxPageUsage::Left)
@@ -1734,7 +1734,7 @@ void ScPrintFunc::MakeEditEngine()
}

//  nStartY = logic
void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,
void ScPrintFunc::PrintHF( tools::Long nPageNo, bool bHeader, tools::Long nStartY,
                            bool bDoPrint, ScPreviewLocationData* pLocationData )
{
    const ScPrintHFParam& rParam = bHeader ? aHdr : aFtr;
@@ -1744,9 +1744,9 @@ void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,
    bool bLeft = IsLeft(nPageNo) && !rParam.bShared;
    const ScPageHFItem* pHFItem = bLeft ? rParam.pLeft : rParam.pRight;

    long nLineStartX = aPageRect.Left()  + rParam.nLeft;
    long nLineEndX   = aPageRect.Right() - rParam.nRight;
    long nLineWidth  = nLineEndX - nLineStartX + 1;
    tools::Long nLineStartX = aPageRect.Left()  + rParam.nLeft;
    tools::Long nLineEndX   = aPageRect.Right() - rParam.nRight;
    tools::Long nLineWidth  = nLineEndX - nLineStartX + 1;

    //  Edit-Engine

@@ -1754,8 +1754,8 @@ void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,
    Size aPaperSize( nLineWidth, rParam.nHeight-rParam.nDistance );
    if ( rParam.pBorder )
    {
        long nLeft = lcl_LineTotal( rParam.pBorder->GetLeft() ) + rParam.pBorder->GetDistance(SvxBoxItemLine::LEFT);
        long nTop = lcl_LineTotal( rParam.pBorder->GetTop() ) + rParam.pBorder->GetDistance(SvxBoxItemLine::TOP);
        tools::Long nLeft = lcl_LineTotal( rParam.pBorder->GetLeft() ) + rParam.pBorder->GetDistance(SvxBoxItemLine::LEFT);
        tools::Long nTop = lcl_LineTotal( rParam.pBorder->GetTop() ) + rParam.pBorder->GetDistance(SvxBoxItemLine::TOP);
        aStart.AdjustX(nLeft );
        aStart.AdjustY(nTop );
        aPaperSize.AdjustWidth( -(nLeft + lcl_LineTotal( rParam.pBorder->GetRight() ) + rParam.pBorder->GetDistance(SvxBoxItemLine::RIGHT)) );
@@ -1764,8 +1764,8 @@ void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,

    if ( rParam.pShadow && rParam.pShadow->GetLocation() != SvxShadowLocation::NONE )
    {
        long nLeft  = rParam.pShadow->CalcShadowSpace(SvxShadowItemSide::LEFT);
        long nTop   = rParam.pShadow->CalcShadowSpace(SvxShadowItemSide::TOP);
        tools::Long nLeft  = rParam.pShadow->CalcShadowSpace(SvxShadowItemSide::LEFT);
        tools::Long nTop   = rParam.pShadow->CalcShadowSpace(SvxShadowItemSide::TOP);
        aStart.AdjustX(nLeft );
        aStart.AdjustY(nTop );
        aPaperSize.AdjustWidth( -(nLeft + rParam.pShadow->CalcShadowSpace(SvxShadowItemSide::RIGHT)) );
@@ -1786,7 +1786,7 @@ void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,
        //  adjust here again, for even/odd head-/footlines
        //  and probably other breaks by variable (page number etc.)

        long nMaxHeight = 0;
        tools::Long nMaxHeight = 0;
        nMaxHeight = std::max( nMaxHeight, TextHeight( pHFItem->GetLeftArea() ) );
        nMaxHeight = std::max( nMaxHeight, TextHeight( pHFItem->GetCenterArea() ) );
        nMaxHeight = std::max( nMaxHeight, TextHeight( pHFItem->GetRightArea() ) );
@@ -1827,7 +1827,7 @@ void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,
            pEditDefaults->Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) );
            pEditEngine->SetTextNewDefaults( *pObject, *pEditDefaults, false );
            Point aDraw = aStart;
            long nDif = aPaperSize.Height() - static_cast<long>(pEditEngine->GetTextHeight());
            tools::Long nDif = aPaperSize.Height() - static_cast<tools::Long>(pEditEngine->GetTextHeight());
            if (nDif > 0)
                aDraw.AdjustY(nDif / 2 );
            pEditEngine->Draw( pDev, aDraw );
@@ -1841,7 +1841,7 @@ void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,
            pEditDefaults->Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
            pEditEngine->SetTextNewDefaults( *pObject, *pEditDefaults, false );
            Point aDraw = aStart;
            long nDif = aPaperSize.Height() - static_cast<long>(pEditEngine->GetTextHeight());
            tools::Long nDif = aPaperSize.Height() - static_cast<tools::Long>(pEditEngine->GetTextHeight());
            if (nDif > 0)
                aDraw.AdjustY(nDif / 2 );
            pEditEngine->Draw( pDev, aDraw );
@@ -1855,7 +1855,7 @@ void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,
            pEditDefaults->Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
            pEditEngine->SetTextNewDefaults( *pObject, *pEditDefaults, false );
            Point aDraw = aStart;
            long nDif = aPaperSize.Height() - static_cast<long>(pEditEngine->GetTextHeight());
            tools::Long nDif = aPaperSize.Height() - static_cast<tools::Long>(pEditEngine->GetTextHeight());
            if (nDif > 0)
                aDraw.AdjustY(nDif / 2 );
            pEditEngine->Draw( pDev, aDraw );
@@ -1871,7 +1871,7 @@ void ScPrintFunc::PrintHF( long nPageNo, bool bHeader, long nStartY,
    }
}

long ScPrintFunc::DoNotes( long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData )
tools::Long ScPrintFunc::DoNotes( tools::Long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData )
{
    if (bDoPrint)
        pDev->SetMapMode(aTwipMode);
@@ -1884,7 +1884,7 @@ long ScPrintFunc::DoNotes( long nNoteStart, bool bDoPrint, ScPreviewLocationData
    ScAutoFontColorMode eColorMode = bUseStyleColor ? SC_AUTOCOL_DISPLAY : SC_AUTOCOL_PRINT;
    rDoc.GetPool()->GetDefaultItem(ATTR_PATTERN).GetFont( aMarkFont, eColorMode );
    pDev->SetFont( aMarkFont );
    long nMarkLen = pDev->GetTextWidth("GW99999:");
    tools::Long nMarkLen = pDev->GetTextWidth("GW99999:");
    // without Space-Char, because it rarely arrives there

    Size aDataSize = aPageRect.GetSize();
@@ -1893,11 +1893,11 @@ long ScPrintFunc::DoNotes( long nNoteStart, bool bDoPrint, ScPreviewLocationData
    aDataSize.AdjustWidth( -nMarkLen );

    pEditEngine->SetPaperSize( aDataSize );
    long nPosX = aPageRect.Left() + nMarkLen;
    long nPosY = aPageRect.Top();
    tools::Long nPosX = aPageRect.Left() + nMarkLen;
    tools::Long nPosY = aPageRect.Top();

    long nCount = 0;
    long nSize = aNotePosList.size();
    tools::Long nCount = 0;
    tools::Long nSize = aNotePosList.size();
    bool bOk;
    do
    {
@@ -1910,7 +1910,7 @@ long ScPrintFunc::DoNotes( long nNoteStart, bool bDoPrint, ScPreviewLocationData
            {
                if(const EditTextObject *pEditText = pNote->GetEditTextObject())
                    pEditEngine->SetTextCurrentDefaults(*pEditText);
                long nTextHeight = pEditEngine->GetTextHeight();
                tools::Long nTextHeight = pEditEngine->GetTextHeight();
                if ( nPosY + nTextHeight < aPageRect.Bottom() )
                {
                    if (bDoPrint)
@@ -1945,9 +1945,9 @@ long ScPrintFunc::DoNotes( long nNoteStart, bool bDoPrint, ScPreviewLocationData
    return nCount;
}

long ScPrintFunc::PrintNotes( long nPageNo, long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData )
tools::Long ScPrintFunc::PrintNotes( tools::Long nPageNo, tools::Long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData )
{
    if ( nNoteStart >= static_cast<long>(aNotePosList.size()) || !aTableParam.bNotes )
    if ( nNoteStart >= static_cast<tools::Long>(aNotePosList.size()) || !aTableParam.bNotes )
        return 0;

    if ( bDoPrint && bClearWin )
@@ -1962,8 +1962,8 @@ long ScPrintFunc::PrintNotes( long nPageNo, long nNoteStart, bool bDoPrint, ScPr
        pDev->SetLineColor();
        pDev->SetFillColor(aBackgroundColor);
        pDev->DrawRect(tools::Rectangle(Point(),
                Size(static_cast<long>(aPageSize.Width() * nScaleX * 100 / nZoom),
                     static_cast<long>(aPageSize.Height() * nScaleY * 100 / nZoom))));
                Size(static_cast<tools::Long>(aPageSize.Width() * nScaleX * 100 / nZoom),
                     static_cast<tools::Long>(aPageSize.Height() * nScaleY * 100 / nZoom))));
    }

    //      adjust aPageRect for left/right page
@@ -1991,17 +1991,17 @@ long ScPrintFunc::PrintNotes( long nPageNo, long nNoteStart, bool bDoPrint, ScPr

        if (aHdr.bEnable)
        {
            long nHeaderY = aPageRect.Top()-aHdr.nHeight;
            tools::Long nHeaderY = aPageRect.Top()-aHdr.nHeight;
            PrintHF( nPageNo, true, nHeaderY, bDoPrint, pLocationData );
        }
        if (aFtr.bEnable)
        {
            long nFooterY = aPageRect.Bottom()+aFtr.nDistance;
            tools::Long nFooterY = aPageRect.Bottom()+aFtr.nDistance;
            PrintHF( nPageNo, false, nFooterY, bDoPrint, pLocationData );
        }
    }

    long nCount = DoNotes( nNoteStart, bDoPrint, pLocationData );
    tools::Long nCount = DoNotes( nNoteStart, bDoPrint, pLocationData );

    if ( pPrinter && bDoPrint )
    {
@@ -2011,11 +2011,11 @@ long ScPrintFunc::PrintNotes( long nPageNo, long nNoteStart, bool bDoPrint, ScPr
    return nCount;
}

void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
void ScPrintFunc::PrintPage( tools::Long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
                                bool bDoPrint, ScPreviewLocationData* pLocationData )
{
    bool bLayoutRTL = rDoc.IsLayoutRTL( nPrintTab );
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    //  nPageNo is the page number within all sheets of one "start page" setting

@@ -2031,8 +2031,8 @@ void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCRO
        pDev->SetLineColor();
        pDev->SetFillColor(aBackgroundColor);
        pDev->DrawRect(tools::Rectangle(Point(),
                Size(static_cast<long>(aPageSize.Width() * nScaleX * 100 / nZoom),
                     static_cast<long>(aPageSize.Height() * nScaleY * 100 / nZoom))));
                Size(static_cast<tools::Long>(aPageSize.Width() * nScaleX * 100 / nZoom),
                     static_cast<tools::Long>(aPageSize.Height() * nScaleY * 100 / nZoom))));
    }

    //      adjust aPageRect for left/right page
@@ -2076,22 +2076,22 @@ void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCRO

    if (aHdr.bEnable)
    {
        long nHeaderY = aPageRect.Top()-aHdr.nHeight;
        tools::Long nHeaderY = aPageRect.Top()-aHdr.nHeight;
        PrintHF( nPageNo, true, nHeaderY, bDoPrint, pLocationData );
    }
    if (aFtr.bEnable)
    {
        long nFooterY = aPageRect.Bottom()+aFtr.nDistance;
        tools::Long nFooterY = aPageRect.Bottom()+aFtr.nDistance;
        PrintHF( nPageNo, false, nFooterY, bDoPrint, pLocationData );
    }

    //  Position ( margins / centering )

    long nLeftSpace = aPageRect.Left();     // Document-Twips
    long nTopSpace  = aPageRect.Top();
    tools::Long nLeftSpace = aPageRect.Left();     // Document-Twips
    tools::Long nTopSpace  = aPageRect.Top();
    if ( bCenterHor || bLayoutRTL )
    {
        long nDataWidth = 0;
        tools::Long nDataWidth = 0;
        SCCOL i;
        for (i=nX1; i<=nX2; i++)
            nDataWidth += rDoc.GetColWidth( i,nPrintTab );
@@ -2099,7 +2099,7 @@ void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCRO
            for (i=nRepeatStartCol; i<=nRepeatEndCol; i++)
                nDataWidth += rDoc.GetColWidth( i,nPrintTab );
        if (aTableParam.bHeaders)
            nDataWidth += long(PRINT_HEADER_WIDTH);
            nDataWidth += tools::Long(PRINT_HEADER_WIDTH);
        if (pBorderItem)
            nDataWidth += pBorderItem->GetDistance(SvxBoxItemLine::LEFT) +
                           pBorderItem->GetDistance(SvxBoxItemLine::RIGHT);        //! Line width?
@@ -2117,12 +2117,12 @@ void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCRO
    }
    if ( bCenterVer )
    {
        long nDataHeight = rDoc.GetRowHeight( nY1, nY2, nPrintTab);
        tools::Long nDataHeight = rDoc.GetRowHeight( nY1, nY2, nPrintTab);
        if (bDoRepRow)
            nDataHeight += rDoc.GetRowHeight( nRepeatStartRow,
                    nRepeatEndRow, nPrintTab);
        if (aTableParam.bHeaders)
            nDataHeight += long(PRINT_HEADER_HEIGHT);
            nDataHeight += tools::Long(PRINT_HEADER_HEIGHT);
        if (pBorderItem)
            nDataHeight += pBorderItem->GetDistance(SvxBoxItemLine::TOP) +
                           pBorderItem->GetDistance(SvxBoxItemLine::BOTTOM);       //! Line width?
@@ -2137,45 +2137,45 @@ void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCRO
    //  calculate sizes of the elements for partitioning
    //  (header, repeat, data)

    long nHeaderWidth   = 0;
    long nHeaderHeight  = 0;
    long nRepeatWidth   = 0;
    long nRepeatHeight  = 0;
    long nContentWidth  = 0;        // scaled - not the same as nDataWidth above
    long nContentHeight = 0;
    tools::Long nHeaderWidth   = 0;
    tools::Long nHeaderHeight  = 0;
    tools::Long nRepeatWidth   = 0;
    tools::Long nRepeatHeight  = 0;
    tools::Long nContentWidth  = 0;        // scaled - not the same as nDataWidth above
    tools::Long nContentHeight = 0;
    if (aTableParam.bHeaders)
    {
        nHeaderWidth  = static_cast<long>(PRINT_HEADER_WIDTH * nScaleX);
        nHeaderHeight = static_cast<long>(PRINT_HEADER_HEIGHT * nScaleY);
        nHeaderWidth  = static_cast<tools::Long>(PRINT_HEADER_WIDTH * nScaleX);
        nHeaderHeight = static_cast<tools::Long>(PRINT_HEADER_HEIGHT * nScaleY);
    }
    if (bDoRepCol)
        for (SCCOL i=nRepeatStartCol; i<=nRepeatEndCol; i++)
            nRepeatWidth += static_cast<long>(rDoc.GetColWidth(i,nPrintTab) * nScaleX);
            nRepeatWidth += static_cast<tools::Long>(rDoc.GetColWidth(i,nPrintTab) * nScaleX);
    if (bDoRepRow)
        nRepeatHeight += rDoc.GetScaledRowHeight( nRepeatStartRow,
                nRepeatEndRow, nPrintTab, nScaleY);
    for (SCCOL i=nX1; i<=nX2; i++)
        nContentWidth += static_cast<long>(rDoc.GetColWidth(i,nPrintTab) * nScaleX);
        nContentWidth += static_cast<tools::Long>(rDoc.GetColWidth(i,nPrintTab) * nScaleX);
    nContentHeight += rDoc.GetScaledRowHeight( nY1, nY2, nPrintTab,
            nScaleY);

    //  partition the page

    long nStartX = static_cast<long>( nLeftSpace * nScaleX );
    long nStartY = static_cast<long>( nTopSpace  * nScaleY );
    long nInnerStartX = nStartX;
    long nInnerStartY = nStartY;
    tools::Long nStartX = static_cast<tools::Long>( nLeftSpace * nScaleX );
    tools::Long nStartY = static_cast<tools::Long>( nTopSpace  * nScaleY );
    tools::Long nInnerStartX = nStartX;
    tools::Long nInnerStartY = nStartY;
    if (pBorderItem)
    {
        nInnerStartX += static_cast<long>( ( lcl_LineTotal(pBorderItem->GetLeft()) +
        nInnerStartX += static_cast<tools::Long>( ( lcl_LineTotal(pBorderItem->GetLeft()) +
                                    pBorderItem->GetDistance(SvxBoxItemLine::LEFT) ) * nScaleX );
        nInnerStartY += static_cast<long>( ( lcl_LineTotal(pBorderItem->GetTop()) +
        nInnerStartY += static_cast<tools::Long>( ( lcl_LineTotal(pBorderItem->GetTop()) +
                                    pBorderItem->GetDistance(SvxBoxItemLine::TOP) ) * nScaleY );
    }
    if (pShadowItem && pShadowItem->GetLocation() != SvxShadowLocation::NONE)
    {
        nInnerStartX += static_cast<long>( pShadowItem->CalcShadowSpace(SvxShadowItemSide::LEFT) * nScaleX );
        nInnerStartY += static_cast<long>( pShadowItem->CalcShadowSpace(SvxShadowItemSide::TOP) * nScaleY );
        nInnerStartX += static_cast<tools::Long>( pShadowItem->CalcShadowSpace(SvxShadowItemSide::LEFT) * nScaleX );
        nInnerStartY += static_cast<tools::Long>( pShadowItem->CalcShadowSpace(SvxShadowItemSide::TOP) * nScaleY );
    }

    if ( bLayoutRTL )
@@ -2185,21 +2185,21 @@ void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCRO

        //  make rounding easier so the elements are really next to each other in preview
        Size aOffsetOnePixel = pDev->PixelToLogic( Size(1,1), aOffsetMode );
        long nOffsetOneX = aOffsetOnePixel.Width();
        tools::Long nOffsetOneX = aOffsetOnePixel.Width();
        nInnerStartX += nOffsetOneX / 2;
    }

    long nFrameStartX = nInnerStartX;
    long nFrameStartY = nInnerStartY;
    tools::Long nFrameStartX = nInnerStartX;
    tools::Long nFrameStartY = nInnerStartY;

    long nRepStartX = nInnerStartX + nHeaderWidth * nLayoutSign;    // widths/heights are 0 if not used
    long nRepStartY = nInnerStartY + nHeaderHeight;
    long nDataX = nRepStartX + nRepeatWidth * nLayoutSign;
    long nDataY = nRepStartY + nRepeatHeight;
    long nEndX = nDataX + nContentWidth * nLayoutSign;
    long nEndY = nDataY + nContentHeight;
    long nFrameEndX = nEndX;
    long nFrameEndY = nEndY;
    tools::Long nRepStartX = nInnerStartX + nHeaderWidth * nLayoutSign;    // widths/heights are 0 if not used
    tools::Long nRepStartY = nInnerStartY + nHeaderHeight;
    tools::Long nDataX = nRepStartX + nRepeatWidth * nLayoutSign;
    tools::Long nDataY = nRepStartY + nRepeatHeight;
    tools::Long nEndX = nDataX + nContentWidth * nLayoutSign;
    tools::Long nEndY = nDataY + nContentHeight;
    tools::Long nFrameEndX = nEndX;
    tools::Long nFrameEndY = nEndY;

    if ( bLayoutRTL )
    {
@@ -2217,19 +2217,19 @@ void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCRO

    //! adjust nEndX/Y

    long nBorderEndX = nEndX;
    long nBorderEndY = nEndY;
    tools::Long nBorderEndX = nEndX;
    tools::Long nBorderEndY = nEndY;
    if (pBorderItem)
    {
        nBorderEndX += static_cast<long>( ( lcl_LineTotal(pBorderItem->GetRight()) +
        nBorderEndX += static_cast<tools::Long>( ( lcl_LineTotal(pBorderItem->GetRight()) +
                                    pBorderItem->GetDistance(SvxBoxItemLine::RIGHT) ) * nScaleX );
        nBorderEndY += static_cast<long>( ( lcl_LineTotal(pBorderItem->GetBottom()) +
        nBorderEndY += static_cast<tools::Long>( ( lcl_LineTotal(pBorderItem->GetBottom()) +
                                    pBorderItem->GetDistance(SvxBoxItemLine::BOTTOM) ) * nScaleY );
    }
    if (pShadowItem && pShadowItem->GetLocation() != SvxShadowLocation::NONE)
    {
        nBorderEndX += static_cast<long>( pShadowItem->CalcShadowSpace(SvxShadowItemSide::RIGHT) * nScaleX );
        nBorderEndY += static_cast<long>( pShadowItem->CalcShadowSpace(SvxShadowItemSide::BOTTOM) * nScaleY );
        nBorderEndX += static_cast<tools::Long>( pShadowItem->CalcShadowSpace(SvxShadowItemSide::RIGHT) * nScaleX );
        nBorderEndY += static_cast<tools::Long>( pShadowItem->CalcShadowSpace(SvxShadowItemSide::BOTTOM) * nScaleY );
    }

    if ( bDoPrint )
@@ -2329,13 +2329,13 @@ void ScPrintFunc::PrintPage( long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX2, SCRO
    if ( bDoPrint && ( aTableParam.bGrid || aTableParam.bHeaders ) )
    {
        Size aOnePixel = pDev->PixelToLogic(Size(1,1));
        long nOneX = aOnePixel.Width();
        long nOneY = aOnePixel.Height();
        tools::Long nOneX = aOnePixel.Width();
        tools::Long nOneY = aOnePixel.Height();

        long nLeftX   = nFrameStartX;
        long nTopY    = nFrameStartY - nOneY;
        long nRightX  = nFrameEndX;
        long nBottomY = nFrameEndY - nOneY;
        tools::Long nLeftX   = nFrameStartX;
        tools::Long nTopY    = nFrameStartY - nOneY;
        tools::Long nRightX  = nFrameEndX;
        tools::Long nBottomY = nFrameEndY - nOneY;
        if ( !bLayoutRTL )
        {
            nLeftX   -= nOneX;
@@ -2430,7 +2430,7 @@ bool ScPrintFunc::UpdatePages()
    return true;
}

long ScPrintFunc::CountPages()                          // sets also nPagesX, nPagesY
tools::Long ScPrintFunc::CountPages()                          // sets also nPagesX, nPagesY
{
    bool bAreaOk = false;

@@ -2461,7 +2461,7 @@ long ScPrintFunc::CountPages()                          // sets also nPagesX, nP

    if (bAreaOk)
    {
        long nPages = 0;
        tools::Long nPages = 0;
        size_t nY;
        if (bMultiArea)
        {
@@ -2476,7 +2476,7 @@ long ScPrintFunc::CountPages()                          // sets also nPagesX, nP
                        nPages += m_aRanges.m_aPageRows[nY].CountVisible();
                    }
                else
                    nPages += static_cast<long>(m_aRanges.m_nPagesX) * m_aRanges.m_nPagesY;
                    nPages += static_cast<tools::Long>(m_aRanges.m_nPagesX) * m_aRanges.m_nPagesY;
                if ( pPageData )
                    FillPageData();
            }
@@ -2491,7 +2491,7 @@ long ScPrintFunc::CountPages()                          // sets also nPagesX, nP
                    nPages += m_aRanges.m_aPageRows[nY].CountVisible();
                }
            else
                nPages += static_cast<long>(m_aRanges.m_nPagesX) * m_aRanges.m_nPagesY;
                nPages += static_cast<tools::Long>(m_aRanges.m_nPagesX) * m_aRanges.m_nPagesY;
            if ( pPageData )
                FillPageData();
        }
@@ -2504,7 +2504,7 @@ long ScPrintFunc::CountPages()                          // sets also nPagesX, nP
    }
}

long ScPrintFunc::CountNotePages()
tools::Long ScPrintFunc::CountNotePages()
{
    if ( !aTableParam.bNotes || !bPrintCurrentTable )
        return 0;
@@ -2552,9 +2552,9 @@ long ScPrintFunc::CountNotePages()
        }
    }

    long nPages = 0;
    long nNoteNr = 0;
    long nNoteAdd;
    tools::Long nPages = 0;
    tools::Long nNoteNr = 0;
    tools::Long nNoteAdd;
    do
    {
        nNoteAdd = PrintNotes( nPages, nNoteNr, false, nullptr );
@@ -2573,7 +2573,7 @@ void ScPrintFunc::InitModes()               // set MapModes from  nZoom etc.
{
    aOffset = Point( aSrcOffset.X()*100/nZoom, aSrcOffset.Y()*100/nZoom );

    long nEffZoom = nZoom * static_cast<long>(nManualZoom);
    tools::Long nEffZoom = nZoom * static_cast<tools::Long>(nManualZoom);
    nScaleX = nScaleY = HMM_PER_TWIPS;  // output in 1/100 mm

    Fraction aZoomFract( nEffZoom,10000 );
@@ -2582,7 +2582,7 @@ void ScPrintFunc::InitModes()               // set MapModes from  nZoom etc.
    if ( !pPrinter && !bIsRender )                          // adjust scale for preview
    {
        double nFact = pDocShell->GetOutputFactor();
        aHorFract = Fraction( static_cast<long>( nEffZoom / nFact ), 10000 );
        aHorFract = Fraction( static_cast<tools::Long>( nEffZoom / nFact ), 10000 );
    }

    aLogicMode = MapMode( MapUnit::Map100thMM, Point(), aHorFract, aZoomFract );
@@ -2590,7 +2590,7 @@ void ScPrintFunc::InitModes()               // set MapModes from  nZoom etc.
    Point aLogicOfs( -aOffset.X(), -aOffset.Y() );
    aOffsetMode = MapMode( MapUnit::Map100thMM, aLogicOfs, aHorFract, aZoomFract );

    Point aTwipsOfs( static_cast<long>( -aOffset.X() / nScaleX + 0.5 ), static_cast<long>( -aOffset.Y() / nScaleY + 0.5 ) );
    Point aTwipsOfs( static_cast<tools::Long>( -aOffset.X() / nScaleX + 0.5 ), static_cast<tools::Long>( -aOffset.Y() / nScaleY + 0.5 ) );
    aTwipMode = MapMode( MapUnit::MapTwip, aTwipsOfs, aHorFract, aZoomFract );
}

@@ -2609,7 +2609,7 @@ void ScPrintFunc::ApplyPrintSettings()
            // landscape is always interpreted as a rotation by 90 degrees !
            // this leads to non WYSIWIG but at least it prints!
            // #i21775#
            long nTemp = aEnumSize.Width();
            tools::Long nTemp = aEnumSize.Width();
            aEnumSize.setWidth( aEnumSize.Height() );
            aEnumSize.setHeight( nTemp );
    }
@@ -2633,8 +2633,8 @@ void ScPrintFunc::ApplyPrintSettings()
//  nStartPage    = rPageRanges starts at nStartPage
//  nDisplayStart = continuous number for displaying the page number

long ScPrintFunc::DoPrint( const MultiSelection& rPageRanges,
                                long nStartPage, long nDisplayStart, bool bDoPrint,
tools::Long ScPrintFunc::DoPrint( const MultiSelection& rPageRanges,
                                tools::Long nStartPage, tools::Long nDisplayStart, bool bDoPrint,
                                ScPreviewLocationData* pLocationData )
{
    OSL_ENSURE(pDev,"Device == NULL");
@@ -2653,9 +2653,9 @@ long ScPrintFunc::DoPrint( const MultiSelection& rPageRanges,

    MakeTableString();

    long nPageNo = 0;
    long nPrinted = 0;
    long nEndPage = rPageRanges.GetTotalRange().Max();
    tools::Long nPageNo = 0;
    tools::Long nPrinted = 0;
    tools::Long nEndPage = rPageRanges.GetTotalRange().Max();

    sal_uInt16 nRepeats = 1;
    if (bMultiArea)
@@ -2731,8 +2731,8 @@ long ScPrintFunc::DoPrint( const MultiSelection& rPageRanges,

    aFieldData.aTabName = ScResId( STR_NOTES );

    long nNoteNr = 0;
    long nNoteAdd;
    tools::Long nNoteNr = 0;
    tools::Long nNoteAdd;
    do
    {
        if ( nPageNo+nStartPage <= nEndPage )
@@ -2954,8 +2954,8 @@ Size ScPrintFunc::GetDocPageSize()
    Size aDocPageSize = aPageRect.GetSize();
    if (aTableParam.bHeaders)
    {
        aDocPageSize.AdjustWidth( -(long(PRINT_HEADER_WIDTH)) );
        aDocPageSize.AdjustHeight( -(long(PRINT_HEADER_HEIGHT)) );
        aDocPageSize.AdjustWidth( -(tools::Long(PRINT_HEADER_WIDTH)) );
        aDocPageSize.AdjustHeight( -(tools::Long(PRINT_HEADER_HEIGHT)) );
    }
    if (pBorderItem)
    {
diff --git a/sc/source/ui/view/reffact.cxx b/sc/source/ui/view/reffact.cxx
index 61db86e..0133a90 100644
--- a/sc/source/ui/view/reffact.cxx
+++ b/sc/source/ui/view/reffact.cxx
@@ -118,10 +118,10 @@ IMPL_CONTROLLER_CHILD_CTOR( ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
// ScSimpleRefDlgWrapper

static bool         bScSimpleRefFlag;
static long         nScSimpleRefHeight;
static long         nScSimpleRefWidth;
static long         nScSimpleRefX;
static long         nScSimpleRefY;
static tools::Long         nScSimpleRefHeight;
static tools::Long         nScSimpleRefWidth;
static tools::Long         nScSimpleRefX;
static tools::Long         nScSimpleRefY;
static bool         bAutoReOpen = true;

ScSimpleRefDlgWrapper::ScSimpleRefDlgWrapper( vcl::Window* pParentP,
diff --git a/sc/source/ui/view/select.cxx b/sc/source/ui/view/select.cxx
index 464c550..0ef0e20 100644
--- a/sc/source/ui/view/select.cxx
+++ b/sc/source/ui/view/select.cxx
@@ -502,10 +502,10 @@ bool ScViewFunctionSet::SetCursorAtCell( SCCOL nPosX, SCROW nPosY, bool bScroll 
        {
            // direction (left or top)

            long nSizeX = 0;
            tools::Long nSizeX = 0;
            for (SCCOL i=nPosX+1; i<=nEndX; i++)
                nSizeX += rDoc.GetColWidth( i, nTab );
            long nSizeY = static_cast<long>(rDoc.GetRowHeight( nPosY+1, nEndY, nTab ));
            tools::Long nSizeY = static_cast<tools::Long>(rDoc.GetRowHeight( nPosY+1, nEndY, nTab ));

            SCCOL nDelStartX = nStartX;
            SCROW nDelStartY = nStartY;
@@ -550,7 +550,7 @@ bool ScViewFunctionSet::SetCursorAtCell( SCCOL nPosX, SCROW nPosY, bool bScroll 
            bool bNegX = ( nPosX < nStartX );
            bool bNegY = ( nPosY < nStartY );

            long nSizeX = 0;
            tools::Long nSizeX = 0;
            if ( bNegX )
            {
                //  in SetCursorAtPoint hidden columns are skipped.
@@ -563,7 +563,7 @@ bool ScViewFunctionSet::SetCursorAtCell( SCCOL nPosX, SCROW nPosY, bool bScroll 
                for (SCCOL i=nEndX+1; i<=nPosX; i++)
                    nSizeX += rDoc.GetColWidth( i, nTab );

            long nSizeY = 0;
            tools::Long nSizeY = 0;
            if ( bNegY )
            {
                //  in SetCursorAtPoint hidden rows are skipped.
diff --git a/sc/source/ui/view/tabsplit.cxx b/sc/source/ui/view/tabsplit.cxx
index 797c2e0..8f0bd7a 100644
--- a/sc/source/ui/view/tabsplit.cxx
+++ b/sc/source/ui/view/tabsplit.cxx
@@ -71,8 +71,8 @@ void ScTabSplitter::Paint( vcl::RenderContext& rRenderContext, const tools::Rect
                // Draw handle
                rRenderContext.SetLineColor(COL_BLACK);
                rRenderContext.SetFillColor(COL_BLACK);
                const long xc = rRect.Right() + rRect.Left();
                const long h4 = rRect.GetHeight() / 4;
                const tools::Long xc = rRect.Right() + rRect.Left();
                const tools::Long h4 = rRect.GetHeight() / 4;
                // First xc fraction is truncated, second one is rounded. This will draw a centered line
                // in handlers with odd width and a centered rectangle in those with even width.
                rRenderContext.DrawRect(tools::Rectangle(Point(xc / 2, rRect.Top() + h4),
@@ -102,8 +102,8 @@ void ScTabSplitter::Paint( vcl::RenderContext& rRenderContext, const tools::Rect
                 // Draw handle
                rRenderContext.SetLineColor(COL_BLACK);
                rRenderContext.SetFillColor(COL_BLACK);
                const long yc = rRect.Top() + rRect.Bottom();
                const long w4 = rRect.GetWidth() / 4;
                const tools::Long yc = rRect.Top() + rRect.Bottom();
                const tools::Long w4 = rRect.GetWidth() / 4;
                // First yc fraction is truncated, second one is rounded. This will draw a centered line
                // in handlers with odd height and a centered rectangle in those with even height.
                DrawRect(tools::Rectangle(Point(rRect.Left() + w4, yc / 2),
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 40a42ea..b0856d3 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -89,13 +89,13 @@ void ScCornerButton::Paint(vcl::RenderContext& rRenderContext, const tools::Rect
    SetBackground(rStyleSettings.GetFaceColor());

    Size aSize(GetOutputSizePixel());
    long nPosX = aSize.Width() - 1;
    long nPosY = aSize.Height() - 1;
    tools::Long nPosX = aSize.Width() - 1;
    tools::Long nPosY = aSize.Height() - 1;

    Window::Paint(rRenderContext, rRect);

    bool bLayoutRTL = pViewData->GetDocument().IsLayoutRTL( pViewData->GetTabNo() );
    long nDarkX = bLayoutRTL ? 0 : nPosX;
    tools::Long nDarkX = bLayoutRTL ? 0 : nPosX;

    //  both buttons have the same look now - only dark right/bottom lines
    rRenderContext.SetLineColor(rStyleSettings.GetDarkShadowColor());
@@ -219,7 +219,7 @@ ScTabView::ScTabView( vcl::Window* pParent, ScDocShell& rDocSh, ScTabViewShell* 
    Init();
}

void ScTabView::InitScrollBar( ScrollBar& rScrollBar, long nMaxVal )
void ScTabView::InitScrollBar( ScrollBar& rScrollBar, tools::Long nMaxVal )
{
    rScrollBar.SetRange( Range( 0, nMaxVal ) );
    rScrollBar.SetLineSize( 1 );
@@ -256,7 +256,7 @@ IMPL_LINK_NOARG(ScTabView, TimerHdl, Timer *, void)
// --- Resize ---------------------------------------------------------------------

static void lcl_SetPosSize( vcl::Window& rWindow, const Point& rPos, const Size& rSize,
                            long nTotalWidth, bool bLayoutRTL )
                            tools::Long nTotalWidth, bool bLayoutRTL )
{
    Point aNewPos = rPos;
    if ( bLayoutRTL )
@@ -281,7 +281,7 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )
        RemoveHintWindow();

    bool bLayoutRTL = aViewData.GetDocument().IsLayoutRTL( aViewData.GetTabNo() );
    long nTotalWidth = rSize.Width();
    tools::Long nTotalWidth = rSize.Width();
    if ( bLayoutRTL )
        nTotalWidth += 2*rOffset.X();

@@ -296,17 +296,17 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )
    if ( aViewData.GetDocShell()->IsPreview() )
        bHScroll = bVScroll = bTabControl = bHeaders = bHOutline = bVOutline = false;

    long nBarX = 0;
    long nBarY = 0;
    long nOutlineX = 0;
    long nOutlineY = 0;
    long nOutPosX;
    long nOutPosY;
    tools::Long nBarX = 0;
    tools::Long nBarY = 0;
    tools::Long nOutlineX = 0;
    tools::Long nOutlineY = 0;
    tools::Long nOutPosX;
    tools::Long nOutPosY;

    long nPosX = rOffset.X();
    long nPosY = rOffset.Y();
    long nSizeX = rSize.Width();
    long nSizeY = rSize.Height();
    tools::Long nPosX = rOffset.X();
    tools::Long nPosY = rOffset.Y();
    tools::Long nSizeX = rSize.Width();
    tools::Long nSizeY = rSize.Height();

    bMinimized = ( nSizeX<=SC_ICONSIZE || nSizeY<=SC_ICONSIZE );
    if ( bMinimized )
@@ -314,10 +314,10 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )

    float fScaleFactor = pFrameWin->GetDPIScaleFactor();

    long nSplitSizeX = SPLIT_HANDLE_SIZE * fScaleFactor;
    tools::Long nSplitSizeX = SPLIT_HANDLE_SIZE * fScaleFactor;
    if ( aViewData.GetHSplitMode() == SC_SPLIT_FIX )
        nSplitSizeX = 1;
    long nSplitSizeY = SPLIT_HANDLE_SIZE * fScaleFactor;
    tools::Long nSplitSizeY = SPLIT_HANDLE_SIZE * fScaleFactor;
    if ( aViewData.GetVSplitMode() == SC_SPLIT_FIX )
        nSplitSizeY = 1;

@@ -357,7 +357,7 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )

    if (bHScroll || bVScroll)       // Scrollbars horizontal or vertical
    {
        long nScrollBarSize = rStyleSettings.GetScrollBarSize();
        tools::Long nScrollBarSize = rStyleSettings.GetScrollBarSize();
        if (bVScroll)
        {
            nBarX = nScrollBarSize;
@@ -379,9 +379,9 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )

        if (bHScroll) // Scrollbars horizontal
        {
            long nSizeLt = 0;       // left scroll bar
            long nSizeRt = 0;       // right scroll bar
            long nSizeSp = 0;       // splitter
            tools::Long nSizeLt = 0;       // left scroll bar
            tools::Long nSizeRt = 0;       // right scroll bar
            tools::Long nSizeSp = 0;       // splitter

            switch (aViewData.GetHSplitMode())
            {
@@ -400,7 +400,7 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )
            }
            nSizeRt = nSizeX - nSizeLt - nSizeSp;

            long nTabSize = 0;
            tools::Long nTabSize = 0;

            if (bTabControl)
            {
@@ -477,9 +477,9 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )

        if (bVScroll)
        {
            long nSizeUp = 0;       // upper scroll bar
            long nSizeSp = 0;       // splitter
            long nSizeDn;           // lower scroll bar
            tools::Long nSizeUp = 0;       // upper scroll bar
            tools::Long nSizeSp = 0;       // splitter
            tools::Long nSizeDn;           // lower scroll bar

            switch (aViewData.GetVSplitMode())
            {
@@ -523,9 +523,9 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )
        nBarY = aHScrollLeft->GetSizePixel().Height();
        nBarX = aVScrollBottom->GetSizePixel().Width();

        long nSize1 = nSizeX;
        tools::Long nSize1 = nSizeX;

        long nTabSize = nSize1;
        tools::Long nTabSize = nSize1;
        if (nTabSize < 0) nTabSize = 0;

        lcl_SetPosSize( *pTabControl, Point(nPosX, nPosY+nSizeY-nBarY),
@@ -573,16 +573,16 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )

        // evaluate splitter

    long nLeftSize   = nSizeX;
    long nRightSize  = 0;
    long nTopSize    = 0;
    long nBottomSize = nSizeY;
    long nSplitPosX  = nPosX;
    long nSplitPosY  = nPosY;
    tools::Long nLeftSize   = nSizeX;
    tools::Long nRightSize  = 0;
    tools::Long nTopSize    = 0;
    tools::Long nBottomSize = nSizeY;
    tools::Long nSplitPosX  = nPosX;
    tools::Long nSplitPosY  = nPosY;

    if ( aViewData.GetHSplitMode() != SC_SPLIT_NONE )
    {
        long nSplitHeight = rSize.Height();
        tools::Long nSplitHeight = rSize.Height();
        if ( aViewData.GetHSplitMode() == SC_SPLIT_FIX )
        {
            // Do not allow freeze splitter to overlap scroll bar/tab bar
@@ -601,7 +601,7 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )
    }
    if ( aViewData.GetVSplitMode() != SC_SPLIT_NONE )
    {
        long nSplitWidth = rSize.Width();
        tools::Long nSplitWidth = rSize.Width();
        if ( aViewData.GetVSplitMode() == SC_SPLIT_FIX && bVScroll )
            nSplitWidth -= aVScrollBottom->GetSizePixel().Width();
        nSplitPosY = aViewData.GetVSplitPos();
@@ -688,7 +688,7 @@ void ScTabView::DoResize( const Point& rOffset, const Size& rSize, bool bInner )

    if (bInner)
    {
        long nInnerPosX = bLayoutRTL ? ( nTotalWidth - nPosX - nLeftSize ) : nPosX;
        tools::Long nInnerPosX = bLayoutRTL ? ( nTotalWidth - nPosX - nLeftSize ) : nPosX;
        pGridWin[SC_SPLIT_BOTTOMLEFT]->SetPosPixel( Point(nInnerPosX,nSplitPosY) );
    }
    else
@@ -736,7 +736,7 @@ void ScTabView::UpdateVarZoom()
    bInZoomUpdate = true;
    const Fraction& rOldX = GetViewData().GetZoomX();
    const Fraction& rOldY = GetViewData().GetZoomY();
    long nOldPercent = long(rOldY * 100);
    tools::Long nOldPercent = tools::Long(rOldY * 100);
    sal_uInt16 nNewZoom = CalcZoom( eZoomType, static_cast<sal_uInt16>(nOldPercent) );
    Fraction aNew( nNewZoom, 100 );

@@ -827,11 +827,11 @@ IMPL_LINK_NOARG(ScTabView, TabBarResize, TabBar*, void)
    if (!aViewData.IsHScrollMode())
        return;

    long nSize = pTabControl->GetSplitSize();
    tools::Long nSize = pTabControl->GetSplitSize();

    if (aViewData.GetHSplitMode() != SC_SPLIT_FIX)
    {
        long nMax = pHSplitter->GetPosPixel().X();
        tools::Long nMax = pHSplitter->GetPosPixel().X();
        if( pTabControl->IsEffectiveRTL() )
            nMax = pFrameWin->GetSizePixel().Width() - nMax;
        --nMax;
@@ -846,7 +846,7 @@ IMPL_LINK_NOARG(ScTabView, TabBarResize, TabBar*, void)
    }
}

void ScTabView::SetTabBarWidth( long nNewWidth )
void ScTabView::SetTabBarWidth( tools::Long nNewWidth )
{
    Size aSize = pTabControl->GetSizePixel();

@@ -860,8 +860,8 @@ void ScTabView::SetTabBarWidth( long nNewWidth )
void ScTabView::SetRelTabBarWidth( double fRelTabBarWidth )
{
    if( (0.0 <= fRelTabBarWidth) && (fRelTabBarWidth <= 1.0) )
        if( long nFrameWidth = pFrameWin->GetSizePixel().Width() )
            SetTabBarWidth( static_cast< long >( fRelTabBarWidth * nFrameWidth + 0.5 ) );
        if( tools::Long nFrameWidth = pFrameWin->GetSizePixel().Width() )
            SetTabBarWidth( static_cast< tools::Long >( fRelTabBarWidth * nFrameWidth + 0.5 ) );
}

void ScTabView::SetPendingRelTabBarWidth( double fRelTabBarWidth )
@@ -870,7 +870,7 @@ void ScTabView::SetPendingRelTabBarWidth( double fRelTabBarWidth )
    SetRelTabBarWidth( fRelTabBarWidth );
}

long ScTabView::GetTabBarWidth() const
tools::Long ScTabView::GetTabBarWidth() const
{
    return pTabControl->GetSizePixel().Width();
}
@@ -955,12 +955,12 @@ bool ScTabView::ScrollCommand( const CommandEvent& rCEvt, ScSplitPos ePos )
            //  and can't be changed directly

            const Fraction& rOldY = aViewData.GetZoomY();
            long nOld = static_cast<long>( rOldY * 100 );
            long nNew;
            tools::Long nOld = static_cast<tools::Long>( rOldY * 100 );
            tools::Long nNew;
            if ( pData->GetDelta() < 0 )
                nNew = std::max( long(MINZOOM), basegfx::zoomtools::zoomOut( nOld ));
                nNew = std::max( tools::Long(MINZOOM), basegfx::zoomtools::zoomOut( nOld ));
            else
                nNew = std::min( long(MAXZOOM), basegfx::zoomtools::zoomIn( nOld ));
                nNew = std::min( tools::Long(MAXZOOM), basegfx::zoomtools::zoomIn( nOld ));
            if ( nNew != nOld )
            {
                // scroll wheel doesn't set the AppOptions default
@@ -1003,7 +1003,7 @@ IMPL_LINK_NOARG(ScTabView, EndScrollHdl, ScrollBar*, void)
IMPL_LINK( ScTabView, ScrollHdl, ScrollBar*, pScroll, void )
{
    bool bHoriz = ( pScroll == aHScrollLeft.get() || pScroll == aHScrollRight.get() );
    long nViewPos;
    tools::Long nViewPos;
    if ( bHoriz )
        nViewPos = aViewData.GetPosX( (pScroll == aHScrollLeft.get()) ?
                                        SC_SPLIT_LEFT : SC_SPLIT_RIGHT );
@@ -1044,12 +1044,12 @@ IMPL_LINK( ScTabView, ScrollHdl, ScrollBar*, pScroll, void )
            Point aPos = pScroll->OutputToNormalizedScreenPixel( Point() );

            // get scrollbar scroll position for help text (row number/column name)
            long nScrollMin = 0;        // simulate RangeMin
            tools::Long nScrollMin = 0;        // simulate RangeMin
            if ( aViewData.GetHSplitMode()==SC_SPLIT_FIX && pScroll == aHScrollRight.get() )
                nScrollMin = aViewData.GetFixPosX();
            if ( aViewData.GetVSplitMode()==SC_SPLIT_FIX && pScroll == aVScrollBottom.get() )
                nScrollMin = aViewData.GetFixPosY();
            long nScrollPos = GetScrollBarPos( *pScroll ) + nScrollMin;
            tools::Long nScrollPos = GetScrollBarPos( *pScroll ) + nScrollMin;

            OUString aHelpStr;
            tools::Rectangle aRect;
@@ -1080,7 +1080,7 @@ IMPL_LINK( ScTabView, ScrollHdl, ScrollBar*, pScroll, void )
        }
    }

    long nDelta = pScroll->GetDelta();
    tools::Long nDelta = pScroll->GetDelta();
    switch ( eType )
    {
        case ScrollType::LineUp:
@@ -1090,10 +1090,10 @@ IMPL_LINK( ScTabView, ScrollHdl, ScrollBar*, pScroll, void )
            nDelta = 1;
            break;
        case ScrollType::PageUp:
            if ( pScroll == aHScrollLeft.get() ) nDelta = -static_cast<long>(aViewData.PrevCellsX( SC_SPLIT_LEFT ));
            if ( pScroll == aHScrollRight.get() ) nDelta = -static_cast<long>(aViewData.PrevCellsX( SC_SPLIT_RIGHT ));
            if ( pScroll == aVScrollTop.get() ) nDelta = -static_cast<long>(aViewData.PrevCellsY( SC_SPLIT_TOP ));
            if ( pScroll == aVScrollBottom.get() ) nDelta = -static_cast<long>(aViewData.PrevCellsY( SC_SPLIT_BOTTOM ));
            if ( pScroll == aHScrollLeft.get() ) nDelta = -static_cast<tools::Long>(aViewData.PrevCellsX( SC_SPLIT_LEFT ));
            if ( pScroll == aHScrollRight.get() ) nDelta = -static_cast<tools::Long>(aViewData.PrevCellsX( SC_SPLIT_RIGHT ));
            if ( pScroll == aVScrollTop.get() ) nDelta = -static_cast<tools::Long>(aViewData.PrevCellsY( SC_SPLIT_TOP ));
            if ( pScroll == aVScrollBottom.get() ) nDelta = -static_cast<tools::Long>(aViewData.PrevCellsY( SC_SPLIT_BOTTOM ));
            if (nDelta==0) nDelta=-1;
            break;
        case ScrollType::PageDown:
@@ -1106,13 +1106,13 @@ IMPL_LINK( ScTabView, ScrollHdl, ScrollBar*, pScroll, void )
        case ScrollType::Drag:
            {
                // only scroll in the correct direction, do not jitter around hidden ranges
                long nScrollMin = 0;        // simulate RangeMin
                tools::Long nScrollMin = 0;        // simulate RangeMin
                if ( aViewData.GetHSplitMode()==SC_SPLIT_FIX && pScroll == aHScrollRight.get() )
                    nScrollMin = aViewData.GetFixPosX();
                if ( aViewData.GetVSplitMode()==SC_SPLIT_FIX && pScroll == aVScrollBottom.get() )
                    nScrollMin = aViewData.GetFixPosY();

                long nScrollPos = GetScrollBarPos( *pScroll ) + nScrollMin;
                tools::Long nScrollPos = GetScrollBarPos( *pScroll ) + nScrollMin;
                nDelta = nScrollPos - nViewPos;
                if ( nScrollPos > nPrevDragPos )
                {
@@ -1143,7 +1143,7 @@ IMPL_LINK( ScTabView, ScrollHdl, ScrollBar*, pScroll, void )
    }
}

void ScTabView::ScrollX( long nDeltaX, ScHSplitPos eWhich, bool bUpdBars )
void ScTabView::ScrollX( tools::Long nDeltaX, ScHSplitPos eWhich, bool bUpdBars )
{
    ScDocument& rDoc = aViewData.GetDocument();
    SCCOL nOldX = aViewData.GetPosX(eWhich);
@@ -1194,9 +1194,9 @@ void ScTabView::ScrollX( long nDeltaX, ScHSplitPos eWhich, bool bUpdBars )
        if (pColBar[eWhich])
            pColBar[eWhich]->PaintImmediately();

        long nOldPos = aViewData.GetScrPos( nTrackX, 0, eWhich ).X();
        tools::Long nOldPos = aViewData.GetScrPos( nTrackX, 0, eWhich ).X();
        aViewData.SetPosX( eWhich, nNewX );
        long nDiff = aViewData.GetScrPos( nTrackX, 0, eWhich ).X() - nOldPos;
        tools::Long nDiff = aViewData.GetScrPos( nTrackX, 0, eWhich ).X() - nOldPos;

        if ( eWhich==SC_SPLIT_LEFT )
        {
@@ -1226,7 +1226,7 @@ void ScTabView::ScrollX( long nDeltaX, ScHSplitPos eWhich, bool bUpdBars )
    TestHintWindow();
}

void ScTabView::ScrollY( long nDeltaY, ScVSplitPos eWhich, bool bUpdBars )
void ScTabView::ScrollY( tools::Long nDeltaY, ScVSplitPos eWhich, bool bUpdBars )
{
    ScDocument& rDoc = aViewData.GetDocument();
    SCROW nOldY = aViewData.GetPosY(eWhich);
@@ -1278,9 +1278,9 @@ void ScTabView::ScrollY( long nDeltaY, ScVSplitPos eWhich, bool bUpdBars )
        if (pRowBar[eWhich])
            pRowBar[eWhich]->PaintImmediately();

        long nOldPos = aViewData.GetScrPos( 0, nTrackY, eWhich ).Y();
        tools::Long nOldPos = aViewData.GetScrPos( 0, nTrackY, eWhich ).Y();
        aViewData.SetPosY( eWhich, nNewY );
        long nDiff = aViewData.GetScrPos( 0, nTrackY, eWhich ).Y() - nOldPos;
        tools::Long nDiff = aViewData.GetScrPos( 0, nTrackY, eWhich ).Y() - nOldPos;

        if ( eWhich==SC_SPLIT_TOP )
        {
@@ -1310,7 +1310,7 @@ void ScTabView::ScrollY( long nDeltaY, ScVSplitPos eWhich, bool bUpdBars )
    TestHintWindow();
}

void ScTabView::ScrollLines( long nDeltaX, long nDeltaY )
void ScTabView::ScrollLines( tools::Long nDeltaX, tools::Long nDeltaY )
{
    ScSplitPos eWhich = aViewData.GetActivePart();
    if (nDeltaX)
@@ -1373,15 +1373,15 @@ void ScTabView::UpdateHeaderWidth( const ScVSplitPos* pWhich, const SCROW* pPosY
        }
    }

    long nSmall = pRowBar[SC_SPLIT_BOTTOM]->GetSmallWidth();
    long nBig   = pRowBar[SC_SPLIT_BOTTOM]->GetBigWidth();
    long nDiff  = nBig - nSmall;
    tools::Long nSmall = pRowBar[SC_SPLIT_BOTTOM]->GetSmallWidth();
    tools::Long nBig   = pRowBar[SC_SPLIT_BOTTOM]->GetBigWidth();
    tools::Long nDiff  = nBig - nSmall;

    if (nEndPos>10000)
        nEndPos = 10000;
    else if (nEndPos<1)     // avoid extra step at 0 (when only one row is visible)
        nEndPos = 1;
    long nWidth = nBig - ( 10000 - nEndPos ) * nDiff / 10000;
    tools::Long nWidth = nBig - ( 10000 - nEndPos ) * nDiff / 10000;

    if (nWidth == pRowBar[SC_SPLIT_BOTTOM]->GetWidth() || bInUpdateHeader)
        return;
@@ -1518,7 +1518,7 @@ IMPL_LINK( ScTabView, SplitHdl, Splitter*, pSplitter, void )
    DoResize( aBorderPos, aFrameSize );
}

void ScTabView::DoHSplit(long nSplitPos)
void ScTabView::DoHSplit(tools::Long nSplitPos)
{
    //  nSplitPos is the real pixel position on the frame window,
    //  mirroring for RTL has to be done here.
@@ -1527,8 +1527,8 @@ void ScTabView::DoHSplit(long nSplitPos)
    if ( bLayoutRTL )
        nSplitPos = pFrameWin->GetOutputSizePixel().Width() - nSplitPos - 1;

    long nMinPos;
    long nMaxPos;
    tools::Long nMinPos;
    tools::Long nMaxPos;

    nMinPos = SPLIT_MARGIN;
    if ( pRowBar[SC_SPLIT_BOTTOM] && pRowBar[SC_SPLIT_BOTTOM]->GetSizePixel().Width() >= nMinPos )
@@ -1559,7 +1559,7 @@ void ScTabView::DoHSplit(long nSplitPos)
    else
    {
        SCCOL nOldDelta = aViewData.GetPosX( SC_SPLIT_LEFT );
        long nLeftWidth = nSplitPos - pRowBar[SC_SPLIT_BOTTOM]->GetSizePixel().Width();
        tools::Long nLeftWidth = nSplitPos - pRowBar[SC_SPLIT_BOTTOM]->GetSizePixel().Width();
        if ( nLeftWidth < 0 ) nLeftWidth = 0;
        SCCOL nNewDelta = nOldDelta + aViewData.CellsAtX( nOldDelta, 1, SC_SPLIT_LEFT,
                        static_cast<sal_uInt16>(nLeftWidth) );
@@ -1588,10 +1588,10 @@ void ScTabView::DoHSplit(long nSplitPos)
    InvalidateSplit();
}

void ScTabView::DoVSplit(long nSplitPos)
void ScTabView::DoVSplit(tools::Long nSplitPos)
{
    long nMinPos;
    long nMaxPos;
    tools::Long nMinPos;
    tools::Long nMaxPos;
    SCROW nOldDelta;

    nMinPos = SPLIT_MARGIN;
@@ -1631,7 +1631,7 @@ void ScTabView::DoVSplit(long nSplitPos)
            nOldDelta = aViewData.GetPosY( SC_SPLIT_TOP );

        aViewData.SetPosY( SC_SPLIT_TOP, nOldDelta );
        long nTopHeight = nSplitPos - pColBar[SC_SPLIT_LEFT]->GetSizePixel().Height();
        tools::Long nTopHeight = nSplitPos - pColBar[SC_SPLIT_LEFT]->GetSizePixel().Height();
        if ( nTopHeight < 0 ) nTopHeight = 0;
        SCROW nNewDelta = nOldDelta + aViewData.CellsAtY( nOldDelta, 1, SC_SPLIT_TOP,
                        static_cast<sal_uInt16>(nTopHeight) );
@@ -1666,23 +1666,23 @@ Point ScTabView::GetInsertPos() const
    SCCOL nCol = aViewData.GetCurX();
    SCROW nRow = aViewData.GetCurY();
    SCTAB nTab = aViewData.GetTabNo();
    long nPosX = 0;
    tools::Long nPosX = 0;
    for (SCCOL i=0; i<nCol; i++)
        nPosX += rDoc.GetColWidth(i,nTab);
    nPosX = static_cast<long>(nPosX * HMM_PER_TWIPS);
    nPosX = static_cast<tools::Long>(nPosX * HMM_PER_TWIPS);
    if ( rDoc.IsNegativePage( nTab ) )
        nPosX = -nPosX;
    long nPosY = static_cast<long>(rDoc.GetRowHeight( 0, nRow-1, nTab));
    nPosY = static_cast<long>(nPosY * HMM_PER_TWIPS);
    tools::Long nPosY = static_cast<tools::Long>(rDoc.GetRowHeight( 0, nRow-1, nTab));
    nPosY = static_cast<tools::Long>(nPosY * HMM_PER_TWIPS);
    return Point(nPosX,nPosY);
}

Point ScTabView::GetChartInsertPos( const Size& rSize, const ScRange& rCellRange )
{
    Point aInsertPos;
    const long nBorder = 100;   // leave 1mm for border
    long nNeededWidth = rSize.Width() + 2 * nBorder;
    long nNeededHeight = rSize.Height() + 2 * nBorder;
    const tools::Long nBorder = 100;   // leave 1mm for border
    tools::Long nNeededWidth = rSize.Width() + 2 * nBorder;
    tools::Long nNeededHeight = rSize.Height() + 2 * nBorder;

    // use the active window, or lower/right if frozen (as in CalcZoom)
    ScSplitPos eUsedPart = aViewData.GetActivePart();
@@ -1705,10 +1705,10 @@ Point ScTabView::GetChartInsertPos( const Size& rSize, const ScRange& rCellRange
        ScDocument& rDoc = aViewData.GetDocument();
        SCTAB nTab = aViewData.GetTabNo();
        bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
        long nLayoutSign = bLayoutRTL ? -1 : 1;
        tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

        long nDocX = static_cast<long>( static_cast<double>(rDoc.GetColOffset( rDoc.MaxCol() + 1, nTab )) * HMM_PER_TWIPS ) * nLayoutSign;
        long nDocY = static_cast<long>( static_cast<double>(rDoc.GetRowOffset( rDoc.MaxRow() + 1, nTab )) * HMM_PER_TWIPS );
        tools::Long nDocX = static_cast<tools::Long>( static_cast<double>(rDoc.GetColOffset( rDoc.MaxCol() + 1, nTab )) * HMM_PER_TWIPS ) * nLayoutSign;
        tools::Long nDocY = static_cast<tools::Long>( static_cast<double>(rDoc.GetRowOffset( rDoc.MaxRow() + 1, nTab )) * HMM_PER_TWIPS );

        if ( aVisible.Left() * nLayoutSign > nDocX * nLayoutSign )
            aVisible.SetLeft( nDocX );
@@ -1724,10 +1724,10 @@ Point ScTabView::GetChartInsertPos( const Size& rSize, const ScRange& rCellRange
        tools::Rectangle aSelection = rDoc.GetMMRect( rCellRange.aStart.Col(), rCellRange.aStart.Row(),
                                                rCellRange.aEnd.Col(), rCellRange.aEnd.Row(), nTab );

        long nLeftSpace = aSelection.Left() - aVisible.Left();
        long nRightSpace = aVisible.Right() - aSelection.Right();
        long nTopSpace = aSelection.Top() - aVisible.Top();
        long nBottomSpace = aVisible.Bottom() - aSelection.Bottom();
        tools::Long nLeftSpace = aSelection.Left() - aVisible.Left();
        tools::Long nRightSpace = aVisible.Right() - aSelection.Right();
        tools::Long nTopSpace = aSelection.Top() - aVisible.Top();
        tools::Long nBottomSpace = aVisible.Bottom() - aSelection.Bottom();

        bool bFitLeft = ( nLeftSpace >= nNeededWidth );
        bool bFitRight = ( nRightSpace >= nNeededWidth );
@@ -1933,7 +1933,7 @@ void ScTabView::FreezeSplitters( bool bFreeze, SplitMethod eSplitMethod, SCCOLRO

            if ( eOldH != SC_SPLIT_NONE && (eSplitMethod == SC_SPLIT_METHOD_COL || eSplitMethod == SC_SPLIT_METHOD_CURSOR))
            {
                long nSplitPos = aViewData.GetHSplitPos();
                tools::Long nSplitPos = aViewData.GetHSplitPos();
                if ( bLayoutRTL )
                    nSplitPos = pFrameWin->GetOutputSizePixel().Width() - nSplitPos - 1;
                aSplit.setX( nSplitPos - aWinStart.X() );
@@ -2014,7 +2014,7 @@ void ScTabView::FreezeSplitters( bool bFreeze, SplitMethod eSplitMethod, SCCOLRO
            aSplit = aViewData.GetScrPos( nPosX, nPosY, ePos, true );
            if (nPosX > aViewData.GetPosX(SC_SPLIT_LEFT))       // (aSplit.X() > 0) doesn't work for RTL
            {
                long nSplitPos = aSplit.X() + aWinStart.X();
                tools::Long nSplitPos = aSplit.X() + aWinStart.X();
                if ( bLayoutRTL )
                    nSplitPos = pFrameWin->GetOutputSizePixel().Width() - nSplitPos - 1;

@@ -2283,13 +2283,13 @@ void ScTabView::SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const std::vector<ed
namespace
{

long lcl_GetRowHeightPx(const ScViewData &rViewData, SCROW nRow, SCTAB nTab)
tools::Long lcl_GetRowHeightPx(const ScViewData &rViewData, SCROW nRow, SCTAB nTab)
{
    const sal_uInt16 nSize = rViewData.GetDocument().GetRowHeight(nRow, nTab);
    return ScViewData::ToPixel(nSize, rViewData.GetPPTY());
}

long lcl_GetColWidthPx(const ScViewData &rViewData, SCCOL nCol, SCTAB nTab)
tools::Long lcl_GetColWidthPx(const ScViewData &rViewData, SCCOL nCol, SCTAB nTab)
{
    const sal_uInt16 nSize = rViewData.GetDocument().GetColWidth(nCol, nTab);
    return ScViewData::ToPixel(nSize, rViewData.GetPPTX());
@@ -2359,7 +2359,7 @@ void lcl_getGroupIndexes(const ScOutlineArray& rArray, SCCOLROW nStart, SCCOLROW
}

void lcl_createGroupsData(
        SCCOLROW nHeaderIndex, SCCOLROW nEnd, long nSizePx, long nTotalPx,
        SCCOLROW nHeaderIndex, SCCOLROW nEnd, tools::Long nSizePx, tools::Long nTotalPx,
        const ScOutlineArray& rArray, std::vector<size_t>& rGroupIndexes,
        std::vector<long>& rGroupStartPositions, OStringBuffer& rGroupsBuffer)
{
@@ -2452,13 +2452,13 @@ public:
        return maRange;
    }

    void getColPositions(long& rStartColPos, long& rEndColPos) const
    void getColPositions(tools::Long& rStartColPos, tools::Long& rEndColPos) const
    {
        rStartColPos = maBoundPositions.Left();
        rEndColPos = maBoundPositions.Right();
    }

    void getRowPositions(long& rStartRowPos, long& rEndRowPos) const
    void getRowPositions(tools::Long& rStartRowPos, tools::Long& rEndRowPos) const
    {
        rStartRowPos = maBoundPositions.Top();
        rEndRowPos = maBoundPositions.Bottom();
@@ -2467,12 +2467,12 @@ public:
private:
    void calculateBounds(const tools::Rectangle& rAreaPx)
    {
        long nLeftPx = 0, nRightPx = 0;
        tools::Long nLeftPx = 0, nRightPx = 0;
        SCCOLROW nStartCol = -1, nEndCol = -1;
        calculateDimensionBounds(rAreaPx.Left(), rAreaPx.Right(), true,
                                 nStartCol, nEndCol, nLeftPx, nRightPx,
                                 mnEnlargeX, mrViewData);
        long nTopPx = 0, nBottomPx = 0;
        tools::Long nTopPx = 0, nBottomPx = 0;
        SCCOLROW nStartRow = -1, nEndRow = -1;
        calculateDimensionBounds(rAreaPx.Top(), rAreaPx.Bottom(), false,
                                 nStartRow, nEndRow, nTopPx, nBottomPx,
@@ -2488,10 +2488,10 @@ private:
    }

    // All positions are in pixels.
    static void calculateDimensionBounds(const long nStartPos, const long nEndPos,
    static void calculateDimensionBounds(const tools::Long nStartPos, const tools::Long nEndPos,
                                         bool bColumns, SCCOLROW& rStartIndex,
                                         SCCOLROW& rEndIndex, long& rBoundStart,
                                         long& rBoundEnd, SCCOLROW nEnlarge,
                                         SCCOLROW& rEndIndex, tools::Long& rBoundStart,
                                         tools::Long& rBoundEnd, SCCOLROW nEnlarge,
                                         ScViewData& rViewData)
    {
        ScPositionHelper& rPosHelper = bColumns ? rViewData.GetLOKWidthHelper() :
@@ -2606,10 +2606,10 @@ void ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle, tools::J
    SCTAB nTab = aViewData.GetTabNo();
    SCROW nStartRow = -1;
    SCROW nEndRow = -1;
    long nStartHeightPx = 0;
    tools::Long nStartHeightPx = 0;
    SCCOL nStartCol = -1;
    SCCOL nEndCol = -1;
    long nStartWidthPx = 0;
    tools::Long nStartWidthPx = 0;

    tools::Rectangle aOldVisArea(
            mnLOKStartHeaderCol + 1, mnLOKStartHeaderRow + 1,
@@ -2625,7 +2625,7 @@ void ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle, tools::J
    if (rRectangle.Top() < rRectangle.Bottom())
    {
        SAL_INFO("sc.lok.header", "Row Header: compute start/end rows.");
        long nEndHeightPx = 0;
        tools::Long nEndHeightPx = 0;
        nStartRow = rCellRange.aStart.Row();
        nEndRow = rCellRange.aEnd.Row();
        aRangeProvider.getRowPositions(nStartHeightPx, nEndHeightPx);
@@ -2639,7 +2639,7 @@ void ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle, tools::J
        mnLOKEndHeaderRow = nEndRow;
    }

    long nVisibleRows = nEndRow - nStartRow;
    tools::Long nVisibleRows = nEndRow - nStartRow;
    if (nVisibleRows < 25)
        nVisibleRows = 25;

@@ -2666,8 +2666,8 @@ void ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle, tools::J

    /// 3) create string data for rows

    long nTotalPixels = nStartHeightPx;
    long nPrevSizePx = -1;
    tools::Long nTotalPixels = nStartHeightPx;
    tools::Long nPrevSizePx = -1;
    OStringBuffer aRowGroupsBuffer = "\"rowGroups\": [\n";
    {
        auto rowsNode = rJsonWriter.startArray("rows");
@@ -2687,7 +2687,7 @@ void ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle, tools::J
        for (SCROW nRow = nStartRow + 1; nRow <= nEndRow; ++nRow)
        {
            // nSize will be 0 for hidden rows.
            const long nSizePx = lcl_GetRowHeightPx(aViewData, nRow, nTab);
            const tools::Long nSizePx = lcl_GetRowHeightPx(aViewData, nRow, nTab);
            nTotalPixels += nSizePx;

            if (bRangeHeaderSupport && nRowGroupDepth > 0)
@@ -2723,7 +2723,7 @@ void ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle, tools::J
    if (rRectangle.Left() < rRectangle.Right())
    {
        SAL_INFO("sc.lok.header", "Column Header: compute start/end columns.");
        long nEndWidthPx = 0;
        tools::Long nEndWidthPx = 0;
        nStartCol = rCellRange.aStart.Col();
        nEndCol = rCellRange.aEnd.Col();
        aRangeProvider.getColPositions(nStartWidthPx, nEndWidthPx);
@@ -2737,7 +2737,7 @@ void ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle, tools::J
        mnLOKEndHeaderCol = nEndCol;
    }

    long nVisibleCols = nEndCol - nStartCol;
    tools::Long nVisibleCols = nEndCol - nStartCol;
    if (nVisibleCols < 10)
        nVisibleCols = 10;

@@ -2781,7 +2781,7 @@ void ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle, tools::J
        for (SCCOL nCol = nStartCol + 1; nCol <= nEndCol; ++nCol)
        {
            // nSize will be 0 for hidden columns.
            const long nSizePx = lcl_GetColWidthPx(aViewData, nCol, nTab);
            const tools::Long nSizePx = lcl_GetColWidthPx(aViewData, nCol, nTab);
            nTotalPixels += nSizePx;

            if (bRangeHeaderSupport && nColGroupDepth > 0)
@@ -2923,7 +2923,7 @@ void ScTabView::extendTiledAreaIfNeeded()
    const SCROW nEndRow = rCellRange.aEnd.Row();

    // Column/Row positions.
    long nStartColPos, nEndColPos, nStartRowPos, nEndRowPos;
    tools::Long nStartColPos, nEndColPos, nStartRowPos, nEndRowPos;
    aRangeProvider.getColPositions(nStartColPos, nEndColPos);
    aRangeProvider.getRowPositions(nStartRowPos, nEndRowPos);

diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx
index 54b42b81..ee7be2a 100644
--- a/sc/source/ui/view/tabview2.cxx
+++ b/sc/source/ui/view/tabview2.cxx
@@ -1116,7 +1116,7 @@ void ScTabView::DeselectAllTables()
}

static bool lcl_FitsInWindow( double fScaleX, double fScaleY, sal_uInt16 nZoom,
                        long nWindowX, long nWindowY, const ScDocument* pDoc, SCTAB nTab,
                        tools::Long nWindowX, tools::Long nWindowY, const ScDocument* pDoc, SCTAB nTab,
                        SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
                        SCCOL nFixPosX, SCROW nFixPosY )
{
@@ -1124,7 +1124,7 @@ static bool lcl_FitsInWindow( double fScaleX, double fScaleY, sal_uInt16 nZoom,
    fScaleX *= fZoomFactor;
    fScaleY *= fZoomFactor;

    long nBlockX = 0;
    tools::Long nBlockX = 0;
    SCCOL nCol;
    for (nCol=0; nCol<nFixPosX; nCol++)
    {
@@ -1132,7 +1132,7 @@ static bool lcl_FitsInWindow( double fScaleX, double fScaleY, sal_uInt16 nZoom,
        sal_uInt16 nColTwips = pDoc->GetColWidth( nCol, nTab );
        if (nColTwips)
        {
            nBlockX += static_cast<long>(nColTwips * fScaleX);
            nBlockX += static_cast<tools::Long>(nColTwips * fScaleX);
            if (nBlockX > nWindowX)
                return false;
        }
@@ -1142,13 +1142,13 @@ static bool lcl_FitsInWindow( double fScaleX, double fScaleY, sal_uInt16 nZoom,
        sal_uInt16 nColTwips = pDoc->GetColWidth( nCol, nTab );
        if (nColTwips)
        {
            nBlockX += static_cast<long>(nColTwips * fScaleX);
            nBlockX += static_cast<tools::Long>(nColTwips * fScaleX);
            if (nBlockX > nWindowX)
                return false;
        }
    }

    long nBlockY = 0;
    tools::Long nBlockY = 0;
    for (SCROW nRow = 0; nRow <= nFixPosY-1; ++nRow)
    {
        if (pDoc->RowHidden(nRow, nTab))
@@ -1158,7 +1158,7 @@ static bool lcl_FitsInWindow( double fScaleX, double fScaleY, sal_uInt16 nZoom,
        sal_uInt16 nRowTwips = pDoc->GetRowHeight(nRow, nTab);
        if (nRowTwips)
        {
            nBlockY += static_cast<long>(nRowTwips * fScaleY);
            nBlockY += static_cast<tools::Long>(nRowTwips * fScaleY);
            if (nBlockY > nWindowY)
                return false;
        }
@@ -1168,7 +1168,7 @@ static bool lcl_FitsInWindow( double fScaleX, double fScaleY, sal_uInt16 nZoom,
        sal_uInt16 nRowTwips = pDoc->GetRowHeight(nRow, nTab);
        if (nRowTwips)
        {
            nBlockY += static_cast<long>(nRowTwips * fScaleY);
            nBlockY += static_cast<tools::Long>(nRowTwips * fScaleY);
            if (nBlockY > nWindowY)
                return false;
        }
@@ -1314,7 +1314,7 @@ sal_uInt16 ScTabView::CalcZoom( SvxZoomType eType, sal_uInt16 nOldZoom )
                        ScSplitMode eHMode = aViewData.GetHSplitMode();
                        if ( eHMode != SC_SPLIT_NONE && pGridWin[SC_SPLIT_BOTTOMRIGHT] )
                        {
                            long nOtherWidth = pGridWin[SC_SPLIT_BOTTOMRIGHT]->
                            tools::Long nOtherWidth = pGridWin[SC_SPLIT_BOTTOMRIGHT]->
                                                        GetOutputSizePixel().Width();
                            if ( eHMode == SC_SPLIT_FIX )
                            {
@@ -1329,7 +1329,7 @@ sal_uInt16 ScTabView::CalcZoom( SvxZoomType eType, sal_uInt16 nOldZoom )
                        ScSplitMode eVMode = aViewData.GetVSplitMode();
                        if ( eVMode != SC_SPLIT_NONE && pGridWin[SC_SPLIT_TOPLEFT] )
                        {
                            long nOtherHeight = pGridWin[SC_SPLIT_TOPLEFT]->
                            tools::Long nOtherHeight = pGridWin[SC_SPLIT_TOPLEFT]->
                                                        GetOutputSizePixel().Height();
                            if ( eVMode == SC_SPLIT_FIX )
                            {
@@ -1345,9 +1345,9 @@ sal_uInt16 ScTabView::CalcZoom( SvxZoomType eType, sal_uInt16 nOldZoom )
                        double nPPTX = ScGlobal::nScreenPPTX / aViewData.GetDocShell()->GetOutputFactor();
                        double nPPTY = ScGlobal::nScreenPPTY;

                        long nZoomX = static_cast<long>( aWinSize.Width() * 100 /
                        tools::Long nZoomX = static_cast<tools::Long>( aWinSize.Width() * 100 /
                                               ( aPageSize.Width() * nPPTX ) );
                        long nZoomY = static_cast<long>( aWinSize.Height() * 100 /
                        tools::Long nZoomY = static_cast<tools::Long>( aWinSize.Height() * 100 /
                                               ( aPageSize.Height() * nPPTY ) );

                        if (nZoomX > 0)
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index ace3068..ccc47fb 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -647,12 +647,12 @@ namespace {
Point calcHintWindowPosition(
    const Point& rCellPos, const Size& rCellSize, const Size& rFrameWndSize, const Size& rHintWndSize)
{
    const long nMargin = 20;
    const tools::Long nMargin = 20;

    long nMLeft = rCellPos.X();
    long nMRight = rFrameWndSize.Width() - rCellPos.X() - rCellSize.Width();
    long nMTop = rCellPos.Y();
    long nMBottom = rFrameWndSize.Height() - rCellPos.Y() - rCellSize.Height();
    tools::Long nMLeft = rCellPos.X();
    tools::Long nMRight = rFrameWndSize.Width() - rCellPos.X() - rCellSize.Width();
    tools::Long nMTop = rCellPos.Y();
    tools::Long nMBottom = rFrameWndSize.Height() - rCellPos.Y() - rCellSize.Height();

    // First, see if we can fit the entire hint window in the visible region.

@@ -813,8 +813,8 @@ void ScTabView::TestHintWindow()
                mxInputHintOO->append(std::unique_ptr<sdr::overlay::OverlayObject>(pOverlay));

                Size aHintWndSize = pOverlay->GetSizePixel();
                long nCellSizeX = 0;
                long nCellSizeY = 0;
                tools::Long nCellSizeX = 0;
                tools::Long nCellSizeY = 0;
                aViewData.GetMergeSizePixel(nCol, nRow, nCellSizeX, nCellSizeY);

                Point aHintPos = calcHintWindowPosition(
@@ -946,15 +946,15 @@ void ScTabView::AlignToCursor( SCCOL nCurX, SCROW nCurY, ScFollowMode eMode,
        SCCOL nSizeX = aViewData.VisibleCellsX(eAlignX);
        SCROW nSizeY = aViewData.VisibleCellsY(eAlignY);

        long nCellSizeX;
        long nCellSizeY;
        tools::Long nCellSizeX;
        tools::Long nCellSizeY;
        if ( nCurX >= 0 && nCurY >= 0 )
            aViewData.GetMergeSizePixel( nCurX, nCurY, nCellSizeX, nCellSizeY );
        else
            nCellSizeX = nCellSizeY = 0;
        Size aScrSize = aViewData.GetScrSize();
        long nSpaceX = ( aScrSize.Width()  - nCellSizeX ) / 2;
        long nSpaceY = ( aScrSize.Height() - nCellSizeY ) / 2;
        tools::Long nSpaceX = ( aScrSize.Width()  - nCellSizeX ) / 2;
        tools::Long nSpaceY = ( aScrSize.Height() - nCellSizeY ) / 2;
        //  nSpaceY: desired start position of cell for FOLLOW_JUMP, modified if dialog interferes

        bool bForceNew = false;     // force new calculation of JUMP position (vertical only)
@@ -990,7 +990,7 @@ void ScTabView::AlignToCursor( SCCOL nCurX, SCROW nCurY, ScFollowMode eMode,
                        {
                            // cursor is on the screen
                            Point aStart = aViewData.GetScrPos( nCurX, nCurY, eAlign );
                            long nCSX, nCSY;
                            tools::Long nCSX, nCSY;
                            aViewData.GetMergeSizePixel( nCurX, nCurY, nCSX, nCSY );
                            tools::Rectangle aCursor( aStart, Size( nCSX, nCSY ) );
                            if ( aCursor.IsOver( aDlgPixel ) )
@@ -1002,11 +1002,11 @@ void ScTabView::AlignToCursor( SCCOL nCurX, SCROW nCurY, ScFollowMode eMode,
                if (bLimit)
                {
                    bool bBottom = false;
                    long nTopSpace = aDlgPixel.Top();
                    long nBotSpace = aWinSize.Height() - aDlgPixel.Bottom();
                    tools::Long nTopSpace = aDlgPixel.Top();
                    tools::Long nBotSpace = aWinSize.Height() - aDlgPixel.Bottom();
                    if ( nBotSpace > 0 && nBotSpace > nTopSpace )
                    {
                        long nDlgBot = aDlgPixel.Bottom();
                        tools::Long nDlgBot = aDlgPixel.Bottom();
                        SCCOL nWPosX;
                        SCROW nWPosY;
                        aViewData.GetPosFromPixel( 0,nDlgBot, eAlign, nWPosX, nWPosY );
@@ -2148,9 +2148,9 @@ void ScTabView::UpdateEditView()
        {
            EditView* pEditView = aViewData.GetEditView(eCurrent);

            long nRefTabNo = GetViewData().GetRefTabNo();
            long nX = GetViewData().GetCurXForTab(nRefTabNo);
            long nY = GetViewData().GetCurYForTab(nRefTabNo);
            tools::Long nRefTabNo = GetViewData().GetRefTabNo();
            tools::Long nX = GetViewData().GetCurXForTab(nRefTabNo);
            tools::Long nY = GetViewData().GetCurYForTab(nRefTabNo);

            aViewData.SetEditEngine(eCurrent,
                static_cast<ScEditEngineDefaulter*>(pEditView->GetEditEngine()),
@@ -2368,7 +2368,7 @@ void ScTabView::PaintArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCRO
            continue;

        bool bLayoutRTL = aViewData.GetDocument().IsLayoutRTL( aViewData.GetTabNo() );
        long nLayoutSign = bLayoutRTL ? -1 : 1;
        tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

        Point aStart = aViewData.GetScrPos( nCol1, nRow1, static_cast<ScSplitPos>(i) );
        Point aEnd   = aViewData.GetScrPos( nCol2+1, nRow2+1, static_cast<ScSplitPos>(i) );
@@ -2408,7 +2408,7 @@ void ScTabView::PaintArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCRO
            //!if ( nCol1 > 0 && !aViewData.GetDocument()->IsBlockEmpty(
            //!                     aViewData.GetTabNo(),
            //!                     0, nRow1, nCol1-1, nRow2 ) )
            long nMarkPixel = static_cast<long>( SC_CLIPMARK_SIZE * aViewData.GetPPTX() );
            tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * aViewData.GetPPTX() );
            aStart.AdjustX( -(nMarkPixel * nLayoutSign) );
        }

@@ -2485,7 +2485,7 @@ void ScTabView::PaintRangeFinderEntry (const ScRangeFindData* pData, const SCTAB
        PaintArea( nCol1, nRow1, nCol2, nRow2, ScUpdateMode::Marks );
}

void ScTabView::PaintRangeFinder( long nNumber )
void ScTabView::PaintRangeFinder( tools::Long nNumber )
{
    ScInputHandler* pHdl = SC_MOD()->GetInputHdl( aViewData.GetViewShell() );
    if (!pHdl)
@@ -2577,11 +2577,11 @@ void ScTabView::DoChartSelection(
                {
                    aTargetRange.PutInOrder();

                    long nX1 = aTargetRange.aStart.Col();
                    long nX2 = aTargetRange.aEnd.Col();
                    long nY1 = aTargetRange.aStart.Row();
                    long nY2 = aTargetRange.aEnd.Row();
                    long nTab = aTargetRange.aStart.Tab();
                    tools::Long nX1 = aTargetRange.aStart.Col();
                    tools::Long nX2 = aTargetRange.aEnd.Col();
                    tools::Long nY1 = aTargetRange.aStart.Row();
                    tools::Long nY2 = aTargetRange.aEnd.Row();
                    tools::Long nTab = aTargetRange.aStart.Tab();

                    aReferenceMarks[nIndex++] = ScInputHandler::GetReferenceMark( aViewData, aViewData.GetDocShell(),
                                                                            nX1, nX2, nY1, nY2,
@@ -2670,7 +2670,7 @@ void ScTabView::PaintTopArea( SCCOL nStartCol, SCCOL nEndCol )

    ScDocument& rDoc = aViewData.GetDocument();
    bool bLayoutRTL = rDoc.IsLayoutRTL( aViewData.GetTabNo() );
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    for (sal_uInt16 i = 0; i < 2; i++)
    {
@@ -2678,8 +2678,8 @@ void ScTabView::PaintTopArea( SCCOL nStartCol, SCCOL nEndCol )
        if (pColBar[eWhich])
        {
            Size aWinSize = pColBar[eWhich]->GetSizePixel();
            long nStartX = aViewData.GetScrPos( nStartCol, 0, eWhich ).X();
            long nEndX;
            tools::Long nStartX = aViewData.GetScrPos( nStartCol, 0, eWhich ).X();
            tools::Long nEndX;
            if (nEndCol >= rDoc.MaxCol())
                nEndX = nStartX + (bLayoutRTL ? 0 : ( aWinSize.Width()-1 ));
            else
@@ -2731,8 +2731,8 @@ void ScTabView::PaintLeftArea( SCROW nStartRow, SCROW nEndRow )
        if (pRowBar[eWhich])
        {
            Size aWinSize = pRowBar[eWhich]->GetSizePixel();
            long nStartY = aViewData.GetScrPos( 0, nStartRow, eWhich ).Y();
            long nEndY;
            tools::Long nStartY = aViewData.GetScrPos( 0, nStartRow, eWhich ).Y();
            tools::Long nEndY;
            if (nEndRow >= rDoc.MaxRow())
                nEndY = nStartY + aWinSize.Height() - 1;
            else
@@ -2918,7 +2918,7 @@ void ScTabView::ActivatePart( ScSplitPos eWhich )
        pColBar[eOldH]->SetIgnoreMove(true);
        pColBar[eNewH]->SetIgnoreMove(false);
        pHdrSelEng->SetWindow( pColBar[eNewH] );
        long nWidth = pColBar[eNewH]->GetOutputSizePixel().Width();
        tools::Long nWidth = pColBar[eNewH]->GetOutputSizePixel().Width();
        pHdrSelEng->SetVisibleArea( tools::Rectangle( 0, LONG_MIN, nWidth-1, LONG_MAX ) );
        pColBar[eNewH]->CaptureMouse();
    }
@@ -2927,7 +2927,7 @@ void ScTabView::ActivatePart( ScSplitPos eWhich )
        pRowBar[eOldV]->SetIgnoreMove(true);
        pRowBar[eNewV]->SetIgnoreMove(false);
        pHdrSelEng->SetWindow( pRowBar[eNewV] );
        long nHeight = pRowBar[eNewV]->GetOutputSizePixel().Height();
        tools::Long nHeight = pRowBar[eNewV]->GetOutputSizePixel().Height();
        pHdrSelEng->SetVisibleArea( tools::Rectangle( LONG_MIN, 0, LONG_MAX, nHeight-1 ) );
        pRowBar[eNewV]->CaptureMouse();
    }
@@ -2975,7 +2975,7 @@ void ScTabView::UpdateInputContext()

// GetGridWidth - width of an output range (for ViewData)

long ScTabView::GetGridWidth( ScHSplitPos eWhich )
tools::Long ScTabView::GetGridWidth( ScHSplitPos eWhich )
{
    ScSplitPos eGridWhich = ( eWhich == SC_SPLIT_LEFT ) ? SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT;
    if (pGridWin[eGridWhich])
@@ -2986,7 +2986,7 @@ long ScTabView::GetGridWidth( ScHSplitPos eWhich )

// GetGridHeight - height of an output range (for ViewData)

long ScTabView::GetGridHeight( ScVSplitPos eWhich )
tools::Long ScTabView::GetGridHeight( ScVSplitPos eWhich )
{
    ScSplitPos eGridWhich = ( eWhich == SC_SPLIT_TOP ) ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT;
    if (pGridWin[eGridWhich])
diff --git a/sc/source/ui/view/tabview4.cxx b/sc/source/ui/view/tabview4.cxx
index b8703e2..aa34633 100644
--- a/sc/source/ui/view/tabview4.cxx
+++ b/sc/source/ui/view/tabview4.cxx
@@ -342,7 +342,7 @@ void ScTabView::InitRefMode( SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, ScRefType eT
    }
}

void ScTabView::SetScrollBar( ScrollBar& rScroll, long nRangeMax, long nVisible, long nPos, bool bLayoutRTL )
void ScTabView::SetScrollBar( ScrollBar& rScroll, tools::Long nRangeMax, tools::Long nVisible, tools::Long nPos, bool bLayoutRTL )
{
    if ( nVisible == 0 )
        nVisible = 1;       // #i59893# don't use visible size 0
@@ -354,20 +354,20 @@ void ScTabView::SetScrollBar( ScrollBar& rScroll, long nRangeMax, long nVisible,
    rScroll.EnableRTL( bLayoutRTL );
}

long ScTabView::GetScrollBarPos( const ScrollBar& rScroll )
tools::Long ScTabView::GetScrollBarPos( const ScrollBar& rScroll )
{
    return rScroll.GetThumbPos();
}

//  UpdateScrollBars - set visible area and scroll width of scroll bars

static long lcl_UpdateBar( ScrollBar& rScroll, SCCOLROW nSize )        // Size = (complete) cells
static tools::Long lcl_UpdateBar( ScrollBar& rScroll, SCCOLROW nSize )        // Size = (complete) cells
{
    long nOldPos;
    long nNewPos;
    tools::Long nOldPos;
    tools::Long nNewPos;

    nOldPos = rScroll.GetThumbPos();
    rScroll.SetPageSize( static_cast<long>(nSize) );
    rScroll.SetPageSize( static_cast<tools::Long>(nSize) );
    nNewPos = rScroll.GetThumbPos();
#ifndef UNX
    rScroll.SetPageSize( 1 );               // always possible !
@@ -376,7 +376,7 @@ static long lcl_UpdateBar( ScrollBar& rScroll, SCCOLROW nSize )        // Size =
    return nNewPos - nOldPos;
}

static long lcl_GetScrollRange( SCCOLROW nDocEnd, SCCOLROW nPos, SCCOLROW nVis, SCCOLROW nMax, SCCOLROW nStart )
static tools::Long lcl_GetScrollRange( SCCOLROW nDocEnd, SCCOLROW nPos, SCCOLROW nVis, SCCOLROW nMax, SCCOLROW nStart )
{
    // get the end (positive) of a scroll bar range that always starts at 0

@@ -393,7 +393,7 @@ void ScTabView::UpdateScrollBars( HeaderType eHeaderType )
{
    ScTabViewShell::notifyAllViewsHeaderInvalidation(GetViewData().GetViewShell(), eHeaderType, GetViewData().GetTabNo());

    long        nDiff;
    tools::Long        nDiff;
    bool        bTop =   ( aViewData.GetVSplitMode() != SC_SPLIT_NONE );
    bool        bRight = ( aViewData.GetHSplitMode() != SC_SPLIT_NONE );
    ScDocument& rDoc = aViewData.GetDocument();
@@ -416,24 +416,24 @@ void ScTabView::UpdateScrollBars( HeaderType eHeaderType )
        nStartY = aViewData.GetFixPosY();

    nVisXL = aViewData.VisibleCellsX( SC_SPLIT_LEFT );
    long nMaxXL = lcl_GetScrollRange( nUsedX, aViewData.GetPosX(SC_SPLIT_LEFT), nVisXL, rDoc.MaxCol(), 0 );
    tools::Long nMaxXL = lcl_GetScrollRange( nUsedX, aViewData.GetPosX(SC_SPLIT_LEFT), nVisXL, rDoc.MaxCol(), 0 );
    SetScrollBar( *aHScrollLeft, nMaxXL, nVisXL, aViewData.GetPosX( SC_SPLIT_LEFT ), bLayoutRTL );

    nVisYB = aViewData.VisibleCellsY( SC_SPLIT_BOTTOM );
    long nMaxYB = lcl_GetScrollRange( nUsedY, aViewData.GetPosY(SC_SPLIT_BOTTOM), nVisYB, rDoc.MaxRow(), nStartY );
    tools::Long nMaxYB = lcl_GetScrollRange( nUsedY, aViewData.GetPosY(SC_SPLIT_BOTTOM), nVisYB, rDoc.MaxRow(), nStartY );
    SetScrollBar( *aVScrollBottom, nMaxYB, nVisYB, aViewData.GetPosY( SC_SPLIT_BOTTOM ) - nStartY, bLayoutRTL );

    if (bRight)
    {
        nVisXR = aViewData.VisibleCellsX( SC_SPLIT_RIGHT );
        long nMaxXR = lcl_GetScrollRange( nUsedX, aViewData.GetPosX(SC_SPLIT_RIGHT), nVisXR, rDoc.MaxCol(), nStartX );
        tools::Long nMaxXR = lcl_GetScrollRange( nUsedX, aViewData.GetPosX(SC_SPLIT_RIGHT), nVisXR, rDoc.MaxCol(), nStartX );
        SetScrollBar( *aHScrollRight, nMaxXR, nVisXR, aViewData.GetPosX( SC_SPLIT_RIGHT ) - nStartX, bLayoutRTL );
    }

    if (bTop)
    {
        nVisYT = aViewData.VisibleCellsY( SC_SPLIT_TOP );
        long nMaxYT = lcl_GetScrollRange( nUsedY, aViewData.GetPosY(SC_SPLIT_TOP), nVisYT, rDoc.MaxRow(), 0 );
        tools::Long nMaxYT = lcl_GetScrollRange( nUsedY, aViewData.GetPosY(SC_SPLIT_TOP), nVisYT, rDoc.MaxRow(), 0 );
        SetScrollBar( *aVScrollTop, nMaxYT, nVisYT, aViewData.GetPosY( SC_SPLIT_TOP ), bLayoutRTL );
    }

@@ -468,7 +468,7 @@ void ScTabView::UpdateScrollBars( HeaderType eHeaderType )
#define HDR_SLIDERSIZE      2
#endif

void ScTabView::InvertHorizontal( ScVSplitPos eWhich, long nDragPos )
void ScTabView::InvertHorizontal( ScVSplitPos eWhich, tools::Long nDragPos )
{
    for (sal_uInt16 i=0; i<4; i++)
        if (WhichV(static_cast<ScSplitPos>(i))==eWhich)
@@ -483,7 +483,7 @@ void ScTabView::InvertHorizontal( ScVSplitPos eWhich, long nDragPos )
        }
}

void ScTabView::InvertVertical( ScHSplitPos eWhich, long nDragPos )
void ScTabView::InvertVertical( ScHSplitPos eWhich, tools::Long nDragPos )
{
    for (sal_uInt16 i=0; i<4; i++)
        if (WhichH(static_cast<ScSplitPos>(i))==eWhich)
diff --git a/sc/source/ui/view/tabview5.cxx b/sc/source/ui/view/tabview5.cxx
index b5ed825..73727a0 100644
--- a/sc/source/ui/view/tabview5.cxx
+++ b/sc/source/ui/view/tabview5.cxx
@@ -549,7 +549,7 @@ void ScTabView::MakeVisible( const tools::Rectangle& rHMMRect )

    tools::Rectangle aRect = pWin->LogicToPixel( rHMMRect );

    long nScrollX=0, nScrollY=0;        // pixel
    tools::Long nScrollX=0, nScrollY=0;        // pixel

    if ( aRect.Right() >= aWinSize.Width() )                // right out
    {
@@ -582,12 +582,12 @@ void ScTabView::MakeVisible( const tools::Rectangle& rHMMRect )
    SCCOL nPosX = aViewData.GetPosX(WhichH(eWhich));
    SCROW nPosY = aViewData.GetPosY(WhichV(eWhich));

    long nLinesX=0, nLinesY=0;      // columns/rows - scroll at least nScrollX/Y
    tools::Long nLinesX=0, nLinesY=0;      // columns/rows - scroll at least nScrollX/Y

    if (nScrollX > 0)
        while (nScrollX > 0 && nPosX < rDoc.MaxCol())
        {
            nScrollX -= static_cast<long>( rDoc.GetColWidth(nPosX, nTab) * nPPTX );
            nScrollX -= static_cast<tools::Long>( rDoc.GetColWidth(nPosX, nTab) * nPPTX );
            ++nPosX;
            ++nLinesX;
        }
@@ -595,14 +595,14 @@ void ScTabView::MakeVisible( const tools::Rectangle& rHMMRect )
        while (nScrollX < 0 && nPosX > 0)
        {
            --nPosX;
            nScrollX += static_cast<long>( rDoc.GetColWidth(nPosX, nTab) * nPPTX );
            nScrollX += static_cast<tools::Long>( rDoc.GetColWidth(nPosX, nTab) * nPPTX );
            --nLinesX;
        }

    if (nScrollY > 0)
        while (nScrollY > 0 && nPosY < rDoc.MaxRow())
        {
            nScrollY -= static_cast<long>( rDoc.GetRowHeight(nPosY, nTab) * nPPTY );
            nScrollY -= static_cast<tools::Long>( rDoc.GetRowHeight(nPosY, nTab) * nPPTY );
            ++nPosY;
            ++nLinesY;
        }
@@ -610,7 +610,7 @@ void ScTabView::MakeVisible( const tools::Rectangle& rHMMRect )
        while (nScrollY < 0 && nPosY > 0)
        {
            --nPosY;
            nScrollY += static_cast<long>( rDoc.GetRowHeight(nPosY, nTab) * nPPTY );
            nScrollY += static_cast<tools::Long>( rDoc.GetRowHeight(nPosY, nTab) * nPPTY );
            --nLinesY;
        }

diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx
index cb607ed..5d86c0c 100644
--- a/sc/source/ui/view/tabvwsh3.cxx
+++ b/sc/source/ui/view/tabvwsh3.cxx
@@ -698,7 +698,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
                SvxZoomType eOldZoomType = GetZoomType();
                SvxZoomType eNewZoomType = eOldZoomType;
                const Fraction& rOldY = GetViewData().GetZoomY();  // Y is shown
                sal_uInt16 nOldZoom = static_cast<sal_uInt16>(long( rOldY * 100 ));
                sal_uInt16 nOldZoom = static_cast<sal_uInt16>(tools::Long( rOldY * 100 ));
                sal_uInt16 nZoom = nOldZoom;
                bool bCancel = false;

diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx
index fb8156f..041560a 100644
--- a/sc/source/ui/view/tabvwsha.cxx
+++ b/sc/source/ui/view/tabvwsha.cxx
@@ -298,7 +298,7 @@ void ScTabViewShell::GetState( SfxItemSet& rSet )
                else
                {
                    const Fraction& rOldY = GetViewData().GetZoomY();
                    sal_uInt16 nZoom = static_cast<sal_uInt16>(long( rOldY * 100 ));
                    sal_uInt16 nZoom = static_cast<sal_uInt16>(tools::Long( rOldY * 100 ));
                    rSet.Put( SvxZoomItem( SvxZoomType::PERCENT, nZoom, nWhich ) );
                }
                break;
@@ -310,7 +310,7 @@ void ScTabViewShell::GetState( SfxItemSet& rSet )
                    else
                    {
                        const Fraction& rOldY = GetViewData().GetZoomY();
                        sal_uInt16 nCurrentZoom = static_cast<sal_uInt16>(long( rOldY * 100 ));
                        sal_uInt16 nCurrentZoom = static_cast<sal_uInt16>(tools::Long( rOldY * 100 ));

                        if( nCurrentZoom )
                        {
diff --git a/sc/source/ui/view/tabvwshb.cxx b/sc/source/ui/view/tabvwshb.cxx
index 58d42e3..cfeedaf 100644
--- a/sc/source/ui/view/tabvwshb.cxx
+++ b/sc/source/ui/view/tabvwshb.cxx
@@ -141,7 +141,7 @@ public:

}

void ScTabViewShell::ActivateObject( SdrOle2Obj* pObj, long nVerb )
void ScTabViewShell::ActivateObject( SdrOle2Obj* pObj, tools::Long nVerb )
{
    // Do not leave the hint message box on top of the object
    RemoveHintWindow();
@@ -259,7 +259,7 @@ void ScTabViewShell::ActivateObject( SdrOle2Obj* pObj, long nVerb )
    //xIPObj->SetDocumentName( GetViewData().GetDocShell()->GetTitle() );
}

ErrCode ScTabViewShell::DoVerb(long nVerb)
ErrCode ScTabViewShell::DoVerb(tools::Long nVerb)
{
    SdrView* pView = GetScDrawView();
    if (!pView)
diff --git a/sc/source/ui/view/tabvwshh.cxx b/sc/source/ui/view/tabvwshh.cxx
index 6a4e842..4a448584 100644
--- a/sc/source/ui/view/tabvwshh.cxx
+++ b/sc/source/ui/view/tabvwshh.cxx
@@ -88,7 +88,7 @@ void ScTabViewShell::ExecuteObject( const SfxRequest& rReq )
                const SfxPoolItem* pItem;
                if ( pReqArgs && pReqArgs->GetItemState( nSlotId, true, &pItem ) == SfxItemState::SET )
                {
                    long nNewVal = static_cast<const SfxInt32Item*>(pItem)->GetValue();
                    tools::Long nNewVal = static_cast<const SfxInt32Item*>(pItem)->GetValue();
                    if ( nNewVal < 0 )
                        nNewVal = 0;

@@ -182,7 +182,7 @@ void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
                            SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
                            tools::Rectangle aRect = pObj->GetLogicRect();

                            long nVal;
                            tools::Long nVal;
                            if ( nWhich == SID_OBJECT_LEFT )
                                nVal = aRect.Left();
                            else if ( nWhich == SID_OBJECT_TOP )
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index e3a1e54..2d30a35 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -129,7 +129,7 @@ void ScPositionHelper::setDocument(const ScDocument& rDoc, bool bColumn)
    MAX_INDEX = bColumn ? rDoc.MaxCol() : MAXTILEDROW;
}

void ScPositionHelper::insert(index_type nIndex, long nPos)
void ScPositionHelper::insert(index_type nIndex, tools::Long nPos)
{
    if (nIndex < 0) return;
    SAL_INFO("sc.lok.poshelper", "ScPositionHelper::insert: nIndex: "
@@ -169,7 +169,7 @@ void ScPositionHelper::invalidateByIndex(index_type nIndex)
    }
}

void ScPositionHelper::invalidateByPosition(long nPos)
void ScPositionHelper::invalidateByPosition(tools::Long nPos)
{
    SAL_INFO("sc.lok.poshelper", "ScPositionHelper::invalidate: nPos: " << nPos);
    if (nPos <= 0)
@@ -202,8 +202,8 @@ ScPositionHelper::getNearestByIndex(index_type nIndex) const
        return *posLB;
    }

    long nDiffUB = posUB->first - nIndex;
    long nDiffLB = posLB->first - nIndex;
    tools::Long nDiffUB = posUB->first - nIndex;
    tools::Long nDiffLB = posLB->first - nIndex;
    if (nDiffUB < -nDiffLB)
    {
        return *posUB;
@@ -215,7 +215,7 @@ ScPositionHelper::getNearestByIndex(index_type nIndex) const
}

const ScPositionHelper::value_type&
ScPositionHelper::getNearestByPosition(long nPos) const
ScPositionHelper::getNearestByPosition(tools::Long nPos) const
{
    SAL_INFO("sc.lok.poshelper",
            "ScPositionHelper::getNearest: nPos: " << nPos << ", size: " << mData.size());
@@ -233,8 +233,8 @@ ScPositionHelper::getNearestByPosition(long nPos) const
        return *posLB;
    }

    long nDiffUB = posUB->second - nPos;
    long nDiffLB = posLB->second - nPos;
    tools::Long nDiffUB = posUB->second - nPos;
    tools::Long nDiffLB = posLB->second - nPos;

    if (nDiffUB < -nDiffLB)
    {
@@ -246,14 +246,14 @@ ScPositionHelper::getNearestByPosition(long nPos) const
    }
}

long ScPositionHelper::getPosition(index_type nIndex) const
tools::Long ScPositionHelper::getPosition(index_type nIndex) const
{
    auto it = mData.find(std::make_pair(nIndex, 0));
    if (it == mData.end()) return -1;
    return it->second;
}

long ScPositionHelper::computePosition(index_type nIndex, const std::function<long (index_type)>& getSizePx)
tools::Long ScPositionHelper::computePosition(index_type nIndex, const std::function<long (index_type)>& getSizePx)
{
    assert(MAX_INDEX > 0);
    if (nIndex < 0) nIndex = 0;
@@ -261,7 +261,7 @@ long ScPositionHelper::computePosition(index_type nIndex, const std::function<lo

    const auto& rNearest = getNearestByIndex(nIndex);
    index_type nStartIndex = rNearest.first;
    long nTotalPixels = rNearest.second;
    tools::Long nTotalPixels = rNearest.second;

    if (nStartIndex < nIndex)
    {
@@ -293,43 +293,43 @@ ScBoundsProvider::ScBoundsProvider(const ScViewData &rView, SCTAB nT, bool bColH
    , nSecondPositionPx(-1)
{}

void ScBoundsProvider::GetStartIndexAndPosition(SCCOL& nIndex, long& nPosition) const
void ScBoundsProvider::GetStartIndexAndPosition(SCCOL& nIndex, tools::Long& nPosition) const
{
    assert(bColumnHeader);
    nIndex = nFirstIndex;
    nPosition = nFirstPositionPx;
}

void ScBoundsProvider::GetEndIndexAndPosition(SCCOL& nIndex, long& nPosition) const
void ScBoundsProvider::GetEndIndexAndPosition(SCCOL& nIndex, tools::Long& nPosition) const
{
    assert(bColumnHeader);
    nIndex = nSecondIndex;
    nPosition = nSecondPositionPx;
}

void ScBoundsProvider::GetStartIndexAndPosition(SCROW& nIndex, long& nPosition) const
void ScBoundsProvider::GetStartIndexAndPosition(SCROW& nIndex, tools::Long& nPosition) const
{
    assert(!bColumnHeader);
    nIndex = nFirstIndex;
    nPosition = nFirstPositionPx;
}

void ScBoundsProvider::GetEndIndexAndPosition(SCROW& nIndex, long& nPosition) const
void ScBoundsProvider::GetEndIndexAndPosition(SCROW& nIndex, tools::Long& nPosition) const
{
    assert(!bColumnHeader);
    nIndex = nSecondIndex;
    nPosition = nSecondPositionPx;
}

long ScBoundsProvider::GetSize(index_type nIndex) const
tools::Long ScBoundsProvider::GetSize(index_type nIndex) const
{
    const sal_uInt16 nSize = bColumnHeader ? rDoc.GetColWidth(nIndex, nTab) : rDoc.GetRowHeight(nIndex, nTab);
    return ScViewData::ToPixel(nSize, bColumnHeader ? mfPPTX : mfPPTY);
}

void ScBoundsProvider::GetIndexAndPos(index_type nNearestIndex, long nNearestPosition,
                    long nBound, index_type& nFoundIndex, long& nPosition,
                    bool bTowards, long nDiff)
void ScBoundsProvider::GetIndexAndPos(index_type nNearestIndex, tools::Long nNearestPosition,
                    tools::Long nBound, index_type& nFoundIndex, tools::Long& nPosition,
                    bool bTowards, tools::Long nDiff)
{
    if (nDiff > 0) // nBound < nNearestPosition
        GeIndexBackwards(nNearestIndex, nNearestPosition, nBound,
@@ -341,13 +341,13 @@ void ScBoundsProvider::GetIndexAndPos(index_type nNearestIndex, long nNearestPos

void ScBoundsProvider::Compute(
            value_type aFirstNearest, value_type aSecondNearest,
            long nFirstBound, long nSecondBound)
            tools::Long nFirstBound, tools::Long nSecondBound)
{
    SAL_INFO("sc.lok.header", "BoundsProvider: nFirstBound: " << nFirstBound
            << ", nSecondBound: " << nSecondBound);

    long nFirstDiff = aFirstNearest.second - nFirstBound;
    long nSecondDiff = aSecondNearest.second - nSecondBound;
    tools::Long nFirstDiff = aFirstNearest.second - nFirstBound;
    tools::Long nSecondDiff = aSecondNearest.second - nSecondBound;
    SAL_INFO("sc.lok.header", "BoundsProvider: rTopNearest: index: " << aFirstNearest.first
            << ", pos: " << aFirstNearest.second << ", diff: " << nFirstDiff);
    SAL_INFO("sc.lok.header", "BoundsProvider: rBottomNearest: index: " << aSecondNearest.first
@@ -363,7 +363,7 @@ void ScBoundsProvider::Compute(
    }

    index_type nNearestIndex = aFirstNearest.first;
    long nNearestPosition = aFirstNearest.second;
    tools::Long nNearestPosition = aFirstNearest.second;
    SAL_INFO("sc.lok.header", "BoundsProvider: nearest to first bound:  nNearestIndex: "
            << nNearestIndex << ", nNearestPosition: " << nNearestPosition);

@@ -399,14 +399,14 @@ void ScBoundsProvider::Compute(
    }
}

void ScBoundsProvider::EnlargeStartBy(long nOffset)
void ScBoundsProvider::EnlargeStartBy(tools::Long nOffset)
{
    const index_type nNewFirstIndex =
            std::max(static_cast<index_type>(-1),
                     static_cast<index_type>(nFirstIndex - nOffset));
    for (index_type nIndex = nFirstIndex; nIndex > nNewFirstIndex; --nIndex)
    {
        const long nSizePx = GetSize(nIndex);
        const tools::Long nSizePx = GetSize(nIndex);
        nFirstPositionPx -= nSizePx;
    }
    nFirstIndex = nNewFirstIndex;
@@ -414,12 +414,12 @@ void ScBoundsProvider::EnlargeStartBy(long nOffset)
            << ", nFirstPositionPx: " << nFirstPositionPx);
}

void ScBoundsProvider::EnlargeEndBy(long nOffset)
void ScBoundsProvider::EnlargeEndBy(tools::Long nOffset)
{
    const index_type nNewSecondIndex = std::min(MAX_INDEX, static_cast<index_type>(nSecondIndex + nOffset));
    for (index_type nIndex = nSecondIndex + 1; nIndex <= nNewSecondIndex; ++nIndex)
    {
        const long nSizePx = GetSize(nIndex);
        const tools::Long nSizePx = GetSize(nIndex);
        nSecondPositionPx += nSizePx;
    }
    nSecondIndex = nNewSecondIndex;
@@ -428,8 +428,8 @@ void ScBoundsProvider::EnlargeEndBy(long nOffset)
}

void ScBoundsProvider::GeIndexBackwards(
            index_type nNearestIndex, long nNearestPosition,
            long nBound, index_type& nFoundIndex, long& nPosition, bool bTowards)
            index_type nNearestIndex, tools::Long nNearestPosition,
            tools::Long nBound, index_type& nFoundIndex, tools::Long& nPosition, bool bTowards)
{
    nFoundIndex = -1;
    for (index_type nIndex = nNearestIndex; nIndex >= 0; --nIndex)
@@ -441,7 +441,7 @@ void ScBoundsProvider::GeIndexBackwards(
            break;
        }

        const long nSizePx = GetSize(nIndex);
        const tools::Long nSizePx = GetSize(nIndex);
        nNearestPosition -= nSizePx;
    }
    if (!bTowards && nFoundIndex != -1)
@@ -452,13 +452,13 @@ void ScBoundsProvider::GeIndexBackwards(
}

void ScBoundsProvider::GetIndexTowards(
            index_type nNearestIndex, long nNearestPosition,
            long nBound, index_type& nFoundIndex, long& nPosition, bool bTowards)
            index_type nNearestIndex, tools::Long nNearestPosition,
            tools::Long nBound, index_type& nFoundIndex, tools::Long& nPosition, bool bTowards)
{
    nFoundIndex = -2;
    for (index_type nIndex = nNearestIndex + 1; nIndex <= MAX_INDEX; ++nIndex)
    {
        const long nSizePx = GetSize(nIndex);
        const tools::Long nSizePx = GetSize(nIndex);
        nNearestPosition += nSizePx;

        if (nNearestPosition > nBound)
@@ -529,8 +529,8 @@ void ScViewDataTable::WriteUserDataSequence(uno::Sequence <beans::PropertyValue>
    ScSplitMode eExVSplitMode = eVSplitMode;
    SCCOL nExFixPosX = nFixPosX;
    SCROW nExFixPosY = nFixPosY;
    long nExHSplitPos = nHSplitPos;
    long nExVSplitPos = nVSplitPos;
    tools::Long nExHSplitPos = nHSplitPos;
    tools::Long nExVSplitPos = nVSplitPos;

    if (comphelper::LibreOfficeKit::isActive())
    {
@@ -575,8 +575,8 @@ void ScViewDataTable::WriteUserDataSequence(uno::Sequence <beans::PropertyValue>
    pSettings[SC_POSITION_BOTTOM].Name = SC_POSITIONBOTTOM;
    pSettings[SC_POSITION_BOTTOM].Value <<= sal_Int32(nPosY[SC_SPLIT_BOTTOM]);

    sal_Int32 nZoomValue = long(aZoomY * 100);
    sal_Int32 nPageZoomValue = long(aPageZoomY * 100);
    sal_Int32 nZoomValue = tools::Long(aZoomY * 100);
    sal_Int32 nPageZoomValue = tools::Long(aPageZoomY * 100);
    pSettings[SC_TABLE_ZOOM_TYPE].Name = SC_ZOOMTYPE;
    pSettings[SC_TABLE_ZOOM_TYPE].Value <<= sal_Int16(eZoomType);
    pSettings[SC_TABLE_ZOOM_VALUE].Name = SC_ZOOMVALUE;
@@ -719,12 +719,12 @@ void ScViewDataTable::ReadUserDataSequence(const uno::Sequence <beans::PropertyV
    if (eHSplitMode == SC_SPLIT_FIX)
        nFixPosX = rViewData.GetDocument().SanitizeCol( static_cast<SCCOL>( bHasHSplitInTwips ? nTempPosHTw : nTempPosH ));
    else
        nHSplitPos = bHasHSplitInTwips ? static_cast< long >( nTempPosHTw * rViewData.GetPPTX() ) : nTempPosH;
        nHSplitPos = bHasHSplitInTwips ? static_cast< tools::Long >( nTempPosHTw * rViewData.GetPPTX() ) : nTempPosH;

    if (eVSplitMode == SC_SPLIT_FIX)
        nFixPosY = rViewData.GetDocument().SanitizeRow( static_cast<SCROW>( bHasVSplitInTwips ? nTempPosVTw : nTempPosV ));
    else
        nVSplitPos = bHasVSplitInTwips ? static_cast< long >( nTempPosVTw * rViewData.GetPPTY() ) : nTempPosV;
        nVSplitPos = bHasVSplitInTwips ? static_cast< tools::Long >( nTempPosVTw * rViewData.GetPPTY() ) : nTempPosV;

    eWhichActive = SanitizeWhichActive();
}
@@ -811,8 +811,8 @@ ScViewData::ScViewData(ScDocument* pDoc, ScDocShell* pDocSh, ScTabViewShell* pVi
    assert(bool(pDoc) != bool(pDocSh)); // either one or the other, not both
    maMarkData.SelectOneTable(0); // Sync with nTabNo

    aScrSize = Size( long( STD_COL_WIDTH           * PIXEL_PER_TWIPS * OLE_STD_CELLS_X ),
                     static_cast<long>( ScGlobal::nStdRowHeight * PIXEL_PER_TWIPS * OLE_STD_CELLS_Y ) );
    aScrSize = Size( tools::Long( STD_COL_WIDTH           * PIXEL_PER_TWIPS * OLE_STD_CELLS_X ),
                     static_cast<tools::Long>( ScGlobal::nStdRowHeight * PIXEL_PER_TWIPS * OLE_STD_CELLS_Y ) );
    maTabData.emplace_back( new ScViewDataTable(nullptr) );
    pThisTab = maTabData[nTabNo].get();

@@ -1405,11 +1405,11 @@ void ScViewData::SetMaxTiledCol( SCCOL nNewMaxCol )
    const SCTAB nTab = GetTabNo();
    auto GetColWidthPx = [this, nTab](SCCOL nCol) {
        const sal_uInt16 nSize = this->mrDoc.GetColWidth(nCol, nTab);
        const long nSizePx = ScViewData::ToPixel(nSize, nPPTX);
        const tools::Long nSizePx = ScViewData::ToPixel(nSize, nPPTX);
        return nSizePx;
    };

    long nTotalPixels = GetLOKWidthHelper().computePosition(nNewMaxCol, GetColWidthPx);
    tools::Long nTotalPixels = GetLOKWidthHelper().computePosition(nNewMaxCol, GetColWidthPx);

    SAL_INFO("sc.lok.docsize", "ScViewData::SetMaxTiledCol: nNewMaxCol: "
            << nNewMaxCol << ", nTotalPixels: " << nTotalPixels);
@@ -1430,11 +1430,11 @@ void ScViewData::SetMaxTiledRow( SCROW nNewMaxRow )
    const SCTAB nTab = GetTabNo();
    auto GetRowHeightPx = [this, nTab](SCROW nRow) {
        const sal_uInt16 nSize = this->mrDoc.GetRowHeight(nRow, nTab);
        const long nSizePx = ScViewData::ToPixel(nSize, nPPTY);
        const tools::Long nSizePx = ScViewData::ToPixel(nSize, nPPTY);
        return nSizePx;
    };

    long nTotalPixels = GetLOKHeightHelper().computePosition(nNewMaxRow, GetRowHeightPx);
    tools::Long nTotalPixels = GetLOKHeightHelper().computePosition(nNewMaxRow, GetRowHeightPx);

    SAL_INFO("sc.lok.docsize", "ScViewData::SetMaxTiledRow: nNewMaxRow: "
            << nNewMaxRow << ", nTotalPixels: " << nTotalPixels);
@@ -1592,11 +1592,11 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich,
        if ( bAsianVertical )
            bGrowCentered = bGrowToLeft = false;   // keep old behavior for asian mode

        long nSizeXPix, nSizeXPTwips = 0;
        tools::Long nSizeXPix, nSizeXPTwips = 0;

        const long nGridWidthPx = pView->GetGridWidth(eHWhich);
        const long nGridHeightPx = pView->GetGridHeight(eVWhich);
        long nGridWidthTwips = 0, nGridHeightTwips = 0;
        const tools::Long nGridWidthPx = pView->GetGridWidth(eHWhich);
        const tools::Long nGridHeightPx = pView->GetGridHeight(eVWhich);
        tools::Long nGridWidthTwips = 0, nGridHeightTwips = 0;
        if (bLOKPrintTwips)
        {
            Size aGridSize(nGridWidthPx, nGridHeightPx);
@@ -1622,13 +1622,13 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich,
            {
                //  growing into both directions until one edge is reached
                //! should be limited to whole cells in both directions
                long nLeft = aPixRect.Left();
                long nRight = nGridWidthPx - aPixRect.Right();
                tools::Long nLeft = aPixRect.Left();
                tools::Long nRight = nGridWidthPx - aPixRect.Right();
                nSizeXPix = aPixRect.GetWidth() + 2 * std::min( nLeft, nRight );
                if (bLOKPrintTwips)
                {
                    long nLeftPTwips = aPTwipsRect.Left();
                    long nRightPTwips = nGridWidthTwips - aPTwipsRect.Right();
                    tools::Long nLeftPTwips = aPTwipsRect.Left();
                    tools::Long nRightPTwips = nGridWidthTwips - aPTwipsRect.Right();
                    nSizeXPTwips = aPTwipsRect.GetWidth() + 2 * std::min(nLeftPTwips, nRightPTwips);
                }
            }
@@ -1653,8 +1653,8 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich,
            }
        }
        OSL_ENSURE(pView,"no View for EditView");
        long nSizeYPix = nGridHeightPx - aPixRect.Top();
        long nSizeYPTwips = bLOKPrintTwips ? (nGridHeightTwips - aPTwipsRect.Top()) : 0;
        tools::Long nSizeYPix = nGridHeightPx - aPixRect.Top();
        tools::Long nSizeYPTwips = bLOKPrintTwips ? (nGridHeightTwips - aPTwipsRect.Top()) : 0;

        if ( nSizeYPix <= 0 )
        {
@@ -1690,8 +1690,8 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich,
        if (bLOKPrintTwips)
            aVisPTwips = pEditView[eWhich]->GetLOKSpecialVisArea();

        long nDiff = aVis.Right() - aVis.Left();
        long nDiffPTwips = bLOKPrintTwips ? (aVisPTwips.Right() - aVisPTwips.Left()) : 0;
        tools::Long nDiff = aVis.Right() - aVis.Left();
        tools::Long nDiffPTwips = bLOKPrintTwips ? (aVisPTwips.Right() - aVisPTwips.Left()) : 0;
        if ( GetEditAdjust() == SvxAdjust::Right )
        {
            aVis.SetRight( aPaper.Width() - 1 );
@@ -1820,10 +1820,10 @@ void ScViewData::EditGrowX()
    if (bLOKPrintTwips)
        aAreaPTwips = pCurView->GetLOKSpecialOutputArea();

    long        nOldRight = aArea.Right();
    tools::Long        nOldRight = aArea.Right();

    // Margin is already included in the original width.
    long nTextWidth = pEngine->CalcTextWidth();
    tools::Long nTextWidth = pEngine->CalcTextWidth();

    bool bChanged = false;
    bool bAsianVertical = pEngine->IsVertical();
@@ -1844,24 +1844,24 @@ void ScViewData::EditGrowX()
    {
        while (aArea.GetWidth() + 0 < nTextWidth && ( nEditStartCol > nLeft || nEditEndCol < nRight ) )
        {
            long nLogicLeft = 0;
            long nLogicLeftPTwips = 0;
            tools::Long nLogicLeft = 0;
            tools::Long nLogicLeftPTwips = 0;
            if ( nEditStartCol > nLeft )
            {
                --nEditStartCol;
                long nColWidth = rLocalDoc.GetColWidth( nEditStartCol, nTabNo );
                long nLeftPix = ToPixel( nColWidth, nPPTX );
                tools::Long nColWidth = rLocalDoc.GetColWidth( nEditStartCol, nTabNo );
                tools::Long nLeftPix = ToPixel( nColWidth, nPPTX );
                nLogicLeft = pWin->PixelToLogic(Size(nLeftPix,0)).Width();
                if (bLOKPrintTwips)
                    nLogicLeftPTwips = nColWidth;
            }
            long nLogicRight = 0;
            long nLogicRightPTwips = 0;
            tools::Long nLogicRight = 0;
            tools::Long nLogicRightPTwips = 0;
            if ( nEditEndCol < nRight )
            {
                ++nEditEndCol;
                long nColWidth = rLocalDoc.GetColWidth( nEditEndCol, nTabNo );
                long nRightPix = ToPixel( nColWidth, nPPTX );
                tools::Long nColWidth = rLocalDoc.GetColWidth( nEditEndCol, nTabNo );
                tools::Long nRightPix = ToPixel( nColWidth, nPPTX );
                nLogicRight = pWin->PixelToLogic(Size(nRightPix,0)).Width();
                if (bLOKPrintTwips)
                    nLogicRightPTwips = nColWidth;
@@ -1877,15 +1877,15 @@ void ScViewData::EditGrowX()

            if ( aArea.Right() > aArea.Left() + aSize.Width() - 1 )
            {
                long nCenter = ( aArea.Left() + aArea.Right() ) / 2;
                long nHalf = aSize.Width() / 2;
                tools::Long nCenter = ( aArea.Left() + aArea.Right() ) / 2;
                tools::Long nHalf = aSize.Width() / 2;
                aArea.SetLeft( nCenter - nHalf + 1 );
                aArea.SetRight( nCenter + aSize.Width() - nHalf - 1 );

                if (bLOKPrintTwips)
                {
                    long nCenterPTwips = ( aAreaPTwips.Left() + aAreaPTwips.Right() ) / 2;
                    long nHalfPTwips = aSizePTwips.Width() / 2;
                    tools::Long nCenterPTwips = ( aAreaPTwips.Left() + aAreaPTwips.Right() ) / 2;
                    tools::Long nHalfPTwips = aSizePTwips.Width() / 2;
                    aAreaPTwips.SetLeft( nCenterPTwips - nHalfPTwips + 1 );
                    aAreaPTwips.SetRight( nCenterPTwips + aSizePTwips.Width() - nHalfPTwips - 1 );
                }
@@ -1901,10 +1901,10 @@ void ScViewData::EditGrowX()
        while (aArea.GetWidth() + 0 < nTextWidth && nEditStartCol > nLeft)
        {
            --nEditStartCol;
            long nColWidth = rLocalDoc.GetColWidth( nEditStartCol, nTabNo );
            long nPix = ToPixel( nColWidth, nPPTX );
            long nLogicWidth = pWin->PixelToLogic(Size(nPix,0)).Width();
            long& nLogicWidthPTwips = nColWidth;
            tools::Long nColWidth = rLocalDoc.GetColWidth( nEditStartCol, nTabNo );
            tools::Long nPix = ToPixel( nColWidth, nPPTX );
            tools::Long nLogicWidth = pWin->PixelToLogic(Size(nPix,0)).Width();
            tools::Long& nLogicWidthPTwips = nColWidth;

            if ( !bLayoutRTL )
            {
@@ -1943,10 +1943,10 @@ void ScViewData::EditGrowX()
        while (aArea.GetWidth() + 0 < nTextWidth && nEditEndCol < nRight)
        {
            ++nEditEndCol;
            long nColWidth = rLocalDoc.GetColWidth( nEditEndCol, nTabNo );
            long nPix = ToPixel( nColWidth, nPPTX );
            long nLogicWidth = pWin->PixelToLogic(Size(nPix,0)).Width();
            long& nLogicWidthPTwips = nColWidth;
            tools::Long nColWidth = rLocalDoc.GetColWidth( nEditEndCol, nTabNo );
            tools::Long nPix = ToPixel( nColWidth, nPPTX );
            tools::Long nLogicWidth = pWin->PixelToLogic(Size(nPix,0)).Width();
            tools::Long& nLogicWidthPTwips = nColWidth;
            if ( bLayoutRTL )
            {
                aArea.AdjustLeft( -nLogicWidth );
@@ -1996,15 +1996,15 @@ void ScViewData::EditGrowX()

            pEngine->SetDefaultItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );

            long nCenter = aSize.Width() / 2;
            long nVisSize = aArea.GetWidth();
            tools::Long nCenter = aSize.Width() / 2;
            tools::Long nVisSize = aArea.GetWidth();
            aVis.SetLeft( nCenter - nVisSize / 2 );
            aVis.SetRight( aVis.Left() + nVisSize - 1 );

            if (bLOKPrintTwips)
            {
                long nCenterPTwips = aSizePTwips.Width() / 2;
                long nVisSizePTwips = aAreaPTwips.GetWidth();
                tools::Long nCenterPTwips = aSizePTwips.Width() / 2;
                tools::Long nVisSizePTwips = aAreaPTwips.GetWidth();
                aVisPTwips.SetLeft( nCenterPTwips - nVisSizePTwips / 2 );
                aVisPTwips.SetRight( aVisPTwips.Left() + nVisSizePTwips - 1 );
            }
@@ -2030,13 +2030,13 @@ void ScViewData::EditGrowX()

            pEngine->SetDefaultItem( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) );

            long nMove = aVis.Left();
            tools::Long nMove = aVis.Left();
            aVis.SetLeft( 0 );
            aVis.AdjustRight( -nMove );

            if (bLOKPrintTwips)
            {
                long nMovePTwips = aVisPTwips.Left();
                tools::Long nMovePTwips = aVisPTwips.Left();
                aVisPTwips.SetLeft( 0 );
                aVisPTwips.AdjustRight( -nMovePTwips );
            }
@@ -2115,13 +2115,13 @@ void ScViewData::EditGrowY( bool bInitial )
        aAreaPTwips = pCurView->GetLOKSpecialOutputArea();
    }

    long        nOldBottom = aArea.Bottom();
    long        nTextHeight = pEngine->GetTextHeight();
    tools::Long        nOldBottom = aArea.Bottom();
    tools::Long        nTextHeight = pEngine->GetTextHeight();

    //  When editing a formula in a cell with optimal height, allow a larger portion
    //  to be clipped before extending to following rows, to avoid obscuring cells for
    //  reference input (next row is likely to be useful in formulas).
    long nAllowedExtra = SC_GROWY_SMALL_EXTRA;
    tools::Long nAllowedExtra = SC_GROWY_SMALL_EXTRA;
    if (nEditEndRow == nEditRow && !(mrDoc.GetRowFlags(nEditRow, nTabNo) & CRFlags::ManualSize) &&
            pEngine->GetParagraphCount() <= 1 )
    {
@@ -2141,8 +2141,8 @@ void ScViewData::EditGrowY( bool bInitial )
    {
        ++nEditEndRow;
        ScDocument& rLocalDoc = GetDocument();
        long nRowHeight = rLocalDoc.GetRowHeight( nEditEndRow, nTabNo );
        long nPix = ToPixel( nRowHeight, nPPTY );
        tools::Long nRowHeight = rLocalDoc.GetRowHeight( nEditEndRow, nTabNo );
        tools::Long nPix = ToPixel( nRowHeight, nPPTY );
        aArea.AdjustBottom(pWin->PixelToLogic(Size(0,nPix)).Height() );
        if (bLOKPrintTwips)
            aAreaPTwips.AdjustBottom(nRowHeight);
@@ -2358,7 +2358,7 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,


    SCCOL nPosX = GetPosX(eWhichX, nForTab);
    long nScrPosX = 0;
    tools::Long nScrPosX = 0;

    if (bAllowNeg || nWhereX >= nPosX)
    {
@@ -2382,7 +2382,7 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,
                    nTSize = mrDoc.GetColWidth(nX, nForTab);
                    if (nTSize)
                    {
                        long nSizeXPix = ToPixel( nTSize, nPPTX );
                        tools::Long nSizeXPix = ToPixel( nTSize, nPPTX );
                        nScrPosX += nSizeXPix;
                    }
                }
@@ -2396,7 +2396,7 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,
                nTSize = mrDoc.GetColWidth(nX, nForTab);
                if (nTSize)
                {
                    long nSizeXPix = ToPixel( nTSize, nPPTX );
                    tools::Long nSizeXPix = ToPixel( nTSize, nPPTX );
                    nScrPosX -= nSizeXPix;
                }
            }
@@ -2406,7 +2406,7 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,


    SCROW nPosY = GetPosY(eWhichY, nForTab);
    long nScrPosY = 0;
    tools::Long nScrPosY = 0;

    if (bAllowNeg || nWhereY >= nPosY)
    {
@@ -2446,7 +2446,7 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,
                nTSize = mrDoc.GetRowHeight(nY, nForTab);
                if (nTSize)
                {
                    long nSizeYPix = ToPixel( nTSize, nPPTY );
                    tools::Long nSizeYPix = ToPixel( nTSize, nPPTY );
                    nScrPosY -= nSizeYPix;
                }
            }
@@ -2466,9 +2466,9 @@ Point ScViewData::GetPrintTwipsPos(SCCOL nCol, SCROW nRow) const
{
    // hidden ones are given 0 sizes by these by default.
    // TODO: rewrite this to loop over spans (matters for jumbosheets).
    long nPosX = nCol ? mrDoc.GetColWidth(0, nCol - 1, nTabNo) : 0;
    tools::Long nPosX = nCol ? mrDoc.GetColWidth(0, nCol - 1, nTabNo) : 0;
    // This is now fast as it loops over spans.
    long nPosY = nRow ? mrDoc.GetRowHeight(0, nRow - 1, nTabNo) : 0;
    tools::Long nPosY = nRow ? mrDoc.GetRowHeight(0, nRow - 1, nTabNo) : 0;
    // TODO: adjust for RTL layout case.

    return Point(nPosX, nPosY);
@@ -2476,8 +2476,8 @@ Point ScViewData::GetPrintTwipsPos(SCCOL nCol, SCROW nRow) const

Point ScViewData::GetPrintTwipsPosFromTileTwips(const Point& rTileTwipsPos) const
{
    const long nPixelX = static_cast<long>(rTileTwipsPos.X() * nPPTX);
    const long nPixelY = static_cast<long>(rTileTwipsPos.Y() * nPPTY);
    const tools::Long nPixelX = static_cast<tools::Long>(rTileTwipsPos.X() * nPPTX);
    const tools::Long nPixelY = static_cast<tools::Long>(rTileTwipsPos.Y() * nPPTY);
    SCCOL nCol = 0;
    SCROW nRow = 0;

@@ -2495,8 +2495,8 @@ OString ScViewData::describeCellCursorAt(SCCOL nX, SCROW nY, bool bPixelAligned)
    Point aCellPos = bPosSizeInPixels ? GetScrPos( nX, nY, SC_SPLIT_BOTTOMRIGHT, true ) :
            GetPrintTwipsPos(nX, nY);

    long nSizeX;
    long nSizeY;
    tools::Long nSizeX;
    tools::Long nSizeY;
    if (bPosSizeInPixels)
        GetMergeSizePixel( nX, nY, nSizeX, nSizeY );
    else
@@ -2515,11 +2515,11 @@ OString ScViewData::describeCellCursorAt(SCCOL nX, SCROW nY, bool bPixelAligned)
        if (nSizeY == 0)
            nSizeY = 1;

        long nPosXTw = rtl::math::round(aCellPos.getX() / fPPTX);
        long nPosYTw = rtl::math::round(aCellPos.getY() / fPPTY);
        tools::Long nPosXTw = rtl::math::round(aCellPos.getX() / fPPTX);
        tools::Long nPosYTw = rtl::math::round(aCellPos.getY() / fPPTY);
        // look at Rectangle( const Point& rLT, const Size& rSize ) for the '- 1'
        long nSizeXTw = rtl::math::round(nSizeX / fPPTX) - 1;
        long nSizeYTw = rtl::math::round(nSizeY / fPPTY) - 1;
        tools::Long nSizeXTw = rtl::math::round(nSizeX / fPPTX) - 1;
        tools::Long nSizeYTw = rtl::math::round(nSizeY / fPPTY) - 1;

        ss << nPosXTw << ", " << nPosYTw << ", " << nSizeXTw << ", " << nSizeYTw << ", "
            << nX << ", " << nY;
@@ -2567,7 +2567,7 @@ SCCOL ScViewData::CellsAtX( SCCOL nPosX, SCCOL nDir, ScHSplitPos eWhichX, sal_uI
            sal_uInt16 nTSize = mrDoc.GetColWidth(nColNo, nTabNo);
            if (nTSize)
            {
                long nSizeXPix = ToPixel( nTSize, nPPTX );
                tools::Long nSizeXPix = ToPixel( nTSize, nPPTX );
                nScrPosX = sal::static_int_cast<sal_uInt16>( nScrPosX + static_cast<sal_uInt16>(nSizeXPix) );
            }
        }
@@ -2597,7 +2597,7 @@ SCROW ScViewData::CellsAtY( SCROW nPosY, SCROW nDir, ScVSplitPos eWhichY, sal_uI
    {
        // forward
        nY = nPosY;
        long nScrPosY = 0;
        tools::Long nScrPosY = 0;
        AddPixelsWhile(nScrPosY, nScrSizeY, nY, mrDoc.MaxRow(), nPPTY, &mrDoc, nTabNo);
        // Original loop ended on last evaluated +1 or if that was MaxRow even on MaxRow+2.
        nY += (nY == mrDoc.MaxRow() ? 2 : 1);
@@ -2607,7 +2607,7 @@ SCROW ScViewData::CellsAtY( SCROW nPosY, SCROW nDir, ScVSplitPos eWhichY, sal_uI
    {
        // backward
        nY = nPosY-1;
        long nScrPosY = 0;
        tools::Long nScrPosY = 0;
        AddPixelsWhileBackward(nScrPosY, nScrSizeY, nY, 0, nPPTY, &mrDoc, nTabNo);
        // Original loop ended on last evaluated -1 or if that was 0 even on -2.
        nY -= (nY == 0 ? 2 : 1);
@@ -2638,13 +2638,13 @@ SCROW ScViewData::PrevCellsY( ScVSplitPos eWhichY ) const
    return CellsAtY( GetPosY( eWhichY ), -1, eWhichY );
}

bool ScViewData::GetMergeSizePixel( SCCOL nX, SCROW nY, long& rSizeXPix, long& rSizeYPix ) const
bool ScViewData::GetMergeSizePixel( SCCOL nX, SCROW nY, tools::Long& rSizeXPix, tools::Long& rSizeYPix ) const
{
    const ScMergeAttr* pMerge = mrDoc.GetAttr(nX, nY, nTabNo, ATTR_MERGE);
    if ( pMerge->GetColMerge() > 1 || pMerge->GetRowMerge() > 1 )
    {
        long nOutWidth = 0;
        long nOutHeight = 0;
        tools::Long nOutWidth = 0;
        tools::Long nOutHeight = 0;
        SCCOL nCountX = pMerge->GetColMerge();
        for (SCCOL i=0; i<nCountX; i++)
            nOutWidth += ToPixel(mrDoc.GetColWidth(nX + i, nTabNo), nPPTX);
@@ -2675,7 +2675,7 @@ bool ScViewData::GetMergeSizePixel( SCCOL nX, SCROW nY, long& rSizeXPix, long& r
    }
}

bool ScViewData::GetMergeSizePrintTwips(SCCOL nX, SCROW nY, long& rSizeXTwips, long& rSizeYTwips) const
bool ScViewData::GetMergeSizePrintTwips(SCCOL nX, SCROW nY, tools::Long& rSizeXTwips, tools::Long& rSizeYTwips) const
{
    const ScMergeAttr* pMerge = mrDoc.GetAttr(nX, nY, nTabNo, ATTR_MERGE);
    SCCOL nCountX = pMerge->GetColMerge();
@@ -2691,7 +2691,7 @@ bool ScViewData::GetMergeSizePrintTwips(SCCOL nX, SCROW nY, long& rSizeXTwips, l
    return (nCountX > 1 || nCountY > 1);
}

void ScViewData::GetPosFromPixel( long nClickX, long nClickY, ScSplitPos eWhich,
void ScViewData::GetPosFromPixel( tools::Long nClickX, tools::Long nClickY, ScSplitPos eWhich,
                                        SCCOL& rPosX, SCROW& rPosY,
                                        bool bTestMerge, bool bRepair, SCTAB nForTab )
{
@@ -2722,8 +2722,8 @@ void ScViewData::GetPosFromPixel( long nClickX, long nClickY, ScSplitPos eWhich,
    SCROW nStartPosY = GetPosY(eVWhich, nForTab);
    rPosX = nStartPosX;
    rPosY = nStartPosY;
    long nScrX = 0;
    long nScrY = 0;
    tools::Long nScrX = 0;
    tools::Long nScrY = 0;

    if (nClickX > 0)
    {
@@ -2807,11 +2807,11 @@ void ScViewData::GetMouseQuadrant( const Point& rClickPos, ScSplitPos eWhich,
                                        SCCOL nPosX, SCROW nPosY, bool& rLeft, bool& rTop )
{
    bool bLayoutRTL = mrDoc.IsLayoutRTL(nTabNo);
    long nLayoutSign = bLayoutRTL ? -1 : 1;
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;

    Point aCellStart = GetScrPos( nPosX, nPosY, eWhich, true );
    long nSizeX;
    long nSizeY;
    tools::Long nSizeX;
    tools::Long nSizeY;
    GetMergeSizePixel( nPosX, nPosY, nSizeX, nSizeY );
    rLeft = ( rClickPos.X() - aCellStart.X() ) * nLayoutSign <= nSizeX / 2;
    rTop  = rClickPos.Y() - aCellStart.Y() <= nSizeY / 2;
@@ -2824,27 +2824,27 @@ void ScViewData::SetPosX( ScHSplitPos eWhich, SCCOL nNewPosX )
    if (nNewPosX != 0 && !bIsTiledRendering)
    {
        SCCOL nOldPosX = pThisTab->nPosX[eWhich];
        long nTPosX = pThisTab->nTPosX[eWhich];
        long nPixPosX = pThisTab->nPixPosX[eWhich];
        tools::Long nTPosX = pThisTab->nTPosX[eWhich];
        tools::Long nPixPosX = pThisTab->nPixPosX[eWhich];
        SCCOL i;
        if ( nNewPosX > nOldPosX )
            for ( i=nOldPosX; i<nNewPosX; i++ )
            {
                long nThis = mrDoc.GetColWidth(i, nTabNo);
                tools::Long nThis = mrDoc.GetColWidth(i, nTabNo);
                nTPosX -= nThis;
                nPixPosX -= ToPixel(sal::static_int_cast<sal_uInt16>(nThis), nPPTX);
            }
        else
            for ( i=nNewPosX; i<nOldPosX; i++ )
            {
                long nThis = mrDoc.GetColWidth(i, nTabNo);
                tools::Long nThis = mrDoc.GetColWidth(i, nTabNo);
                nTPosX += nThis;
                nPixPosX += ToPixel(sal::static_int_cast<sal_uInt16>(nThis), nPPTX);
            }

        pThisTab->nPosX[eWhich] = nNewPosX;
        pThisTab->nTPosX[eWhich] = nTPosX;
        pThisTab->nMPosX[eWhich] = static_cast<long>(nTPosX * HMM_PER_TWIPS);
        pThisTab->nMPosX[eWhich] = static_cast<tools::Long>(nTPosX * HMM_PER_TWIPS);
        pThisTab->nPixPosX[eWhich] = nPixPosX;
    }
    else
@@ -2863,13 +2863,13 @@ void ScViewData::SetPosY( ScVSplitPos eWhich, SCROW nNewPosY )
    if (nNewPosY != 0 && !bIsTiledRendering)
    {
        SCROW nOldPosY = pThisTab->nPosY[eWhich];
        long nTPosY = pThisTab->nTPosY[eWhich];
        long nPixPosY = pThisTab->nPixPosY[eWhich];
        tools::Long nTPosY = pThisTab->nTPosY[eWhich];
        tools::Long nPixPosY = pThisTab->nPixPosY[eWhich];
        SCROW i, nHeightEndRow;
        if ( nNewPosY > nOldPosY )
            for ( i=nOldPosY; i<nNewPosY; i++ )
            {
                long nThis = mrDoc.GetRowHeight(i, nTabNo, nullptr, &nHeightEndRow);
                tools::Long nThis = mrDoc.GetRowHeight(i, nTabNo, nullptr, &nHeightEndRow);
                SCROW nRows = std::min( nNewPosY, nHeightEndRow + 1) - i;
                i = nHeightEndRow;
                nTPosY -= nThis * nRows;
@@ -2878,7 +2878,7 @@ void ScViewData::SetPosY( ScVSplitPos eWhich, SCROW nNewPosY )
        else
            for ( i=nNewPosY; i<nOldPosY; i++ )
            {
                long nThis = mrDoc.GetRowHeight(i, nTabNo, nullptr, &nHeightEndRow);
                tools::Long nThis = mrDoc.GetRowHeight(i, nTabNo, nullptr, &nHeightEndRow);
                SCROW nRows = std::min( nOldPosY, nHeightEndRow + 1) - i;
                i = nHeightEndRow;
                nTPosY += nThis * nRows;
@@ -2887,7 +2887,7 @@ void ScViewData::SetPosY( ScVSplitPos eWhich, SCROW nNewPosY )

        pThisTab->nPosY[eWhich] = nNewPosY;
        pThisTab->nTPosY[eWhich] = nTPosY;
        pThisTab->nMPosY[eWhich] = static_cast<long>(nTPosY * HMM_PER_TWIPS);
        pThisTab->nMPosY[eWhich] = static_cast<tools::Long>(nTPosY * HMM_PER_TWIPS);
        pThisTab->nPixPosY[eWhich] = nPixPosY;
    }
    else
@@ -2903,13 +2903,13 @@ void ScViewData::RecalcPixPos()             // after zoom changes
{
    for (sal_uInt16 eWhich=0; eWhich<2; eWhich++)
    {
        long nPixPosX = 0;
        tools::Long nPixPosX = 0;
        SCCOL nPosX = pThisTab->nPosX[eWhich];
        for (SCCOL i=0; i<nPosX; i++)
            nPixPosX -= ToPixel(mrDoc.GetColWidth(i, nTabNo), nPPTX);
        pThisTab->nPixPosX[eWhich] = nPixPosX;

        long nPixPosY = 0;
        tools::Long nPixPosY = 0;
        SCROW nPosY = pThisTab->nPosY[eWhich];
        for (SCROW j=0; j<nPosY; j++)
            nPixPosY -= ToPixel(mrDoc.GetRowHeight(j, nTabNo), nPPTY);
@@ -2935,9 +2935,9 @@ void ScViewData::SetScreen( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
    SCCOL nCol;
    SCROW nRow;
    sal_uInt16 nTSize;
    long nSizePix;
    long nScrPosX = 0;
    long nScrPosY = 0;
    tools::Long nSizePix;
    tools::Long nScrPosX = 0;
    tools::Long nScrPosY = 0;

    SetActivePart( SC_SPLIT_BOTTOMLEFT );
    SetPosX( SC_SPLIT_LEFT, nCol1 );
@@ -2968,20 +2968,20 @@ void ScViewData::SetScreen( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )

void ScViewData::SetScreenPos( const Point& rVisAreaStart )
{
    long nSize;
    long nTwips;
    long nAdd;
    tools::Long nSize;
    tools::Long nTwips;
    tools::Long nAdd;
    bool bEnd;

    nSize = 0;
    nTwips = static_cast<long>(rVisAreaStart.X() / HMM_PER_TWIPS);
    nTwips = static_cast<tools::Long>(rVisAreaStart.X() / HMM_PER_TWIPS);
    if (mrDoc.IsLayoutRTL(nTabNo))
        nTwips = -nTwips;
    SCCOL nX1 = 0;
    bEnd = false;
    while (!bEnd)
    {
        nAdd = static_cast<long>(mrDoc.GetColWidth(nX1, nTabNo));
        nAdd = static_cast<tools::Long>(mrDoc.GetColWidth(nX1, nTabNo));
        if (nSize + nAdd <= nTwips + 1 && nX1 < mrDoc.MaxCol())
        {
            nSize += nAdd;
@@ -2992,12 +2992,12 @@ void ScViewData::SetScreenPos( const Point& rVisAreaStart )
    }

    nSize = 0;
    nTwips = static_cast<long>(rVisAreaStart.Y() / HMM_PER_TWIPS);
    nTwips = static_cast<tools::Long>(rVisAreaStart.Y() / HMM_PER_TWIPS);
    SCROW nY1 = 0;
    bEnd = false;
    while (!bEnd)
    {
        nAdd = static_cast<long>(mrDoc.GetRowHeight(nY1, nTabNo));
        nAdd = static_cast<tools::Long>(mrDoc.GetRowHeight(nY1, nTabNo));
        if (nSize + nAdd <= nTwips + 1 && nY1 < mrDoc.MaxRow())
        {
            nSize += nAdd;
@@ -3022,8 +3022,8 @@ void ScViewData::SetScreen( const tools::Rectangle& rVisArea )
    //  here without GetOutputFactor(), since it's for the output into a Metafile

    aScrSize = rVisArea.GetSize();
    aScrSize.setWidth( static_cast<long>( aScrSize.Width() * ScGlobal::nScreenPPTX / HMM_PER_TWIPS ) );
    aScrSize.setHeight( static_cast<long>( aScrSize.Height() * ScGlobal::nScreenPPTY / HMM_PER_TWIPS ) );
    aScrSize.setWidth( static_cast<tools::Long>( aScrSize.Width() * ScGlobal::nScreenPPTX / HMM_PER_TWIPS ) );
    aScrSize.setHeight( static_cast<tools::Long>( aScrSize.Height() * ScGlobal::nScreenPPTY / HMM_PER_TWIPS ) );
}

ScDocFunc& ScViewData::GetDocFunc() const
@@ -3098,8 +3098,8 @@ void ScViewData::UpdateScreenZoom( const Fraction& rNewX, const Fraction& rNewY 
    aHeight *= Fraction( aScrSize.Height(),1 );
    aHeight /= aOldY;

    aScrSize.setWidth( static_cast<long>(aWidth) );
    aScrSize.setHeight( static_cast<long>(aHeight) );
    aScrSize.setWidth( static_cast<tools::Long>(aWidth) );
    aScrSize.setHeight( static_cast<tools::Long>(aHeight) );
}

void ScViewData::CalcPPT()
@@ -3162,9 +3162,9 @@ void ScViewData::WriteUserData(OUString& rData)
    // PosX[left]/PosX[right]/PosY[top]/PosY[bottom]
    // when rows bigger than 8192, "+" instead of "/"

    sal_uInt16 nZoom = static_cast<sal_uInt16>(long(pThisTab->aZoomY * 100));
    sal_uInt16 nZoom = static_cast<sal_uInt16>(tools::Long(pThisTab->aZoomY * 100));
    rData = OUString::number( nZoom ) + "/";
    nZoom = static_cast<sal_uInt16>(long(pThisTab->aPageZoomY * 100));
    nZoom = static_cast<sal_uInt16>(tools::Long(pThisTab->aPageZoomY * 100));
    rData += OUString::number( nZoom ) + "/";
    if (bPagebreak)
        rData += "1";
@@ -3346,8 +3346,8 @@ void ScViewData::WriteExtOptions( ScExtDocOptions& rDocOpt ) const
            ScSplitMode eExVSplit = pViewTab->eVSplitMode;
            SCCOL nExFixPosX = pViewTab->nFixPosX;
            SCROW nExFixPosY = pViewTab->nFixPosY;
            long nExHSplitPos = pViewTab->nHSplitPos;
            long nExVSplitPos = pViewTab->nVSplitPos;
            tools::Long nExHSplitPos = pViewTab->nHSplitPos;
            tools::Long nExVSplitPos = pViewTab->nVSplitPos;

            if (bLOKActive)
            {
@@ -3372,7 +3372,7 @@ void ScViewData::WriteExtOptions( ScExtDocOptions& rDocOpt ) const
                rSplitPos = Point( bHSplit ? nExHSplitPos : 0, bVSplit ? nExVSplitPos : 0 );
                rSplitPos = Application::GetDefaultDevice()->PixelToLogic( rSplitPos, MapMode( MapUnit::MapTwip ) );
                if( pDocShell )
                    rSplitPos.setX( static_cast<long>(static_cast<double>(rSplitPos.X()) / pDocShell->GetOutputFactor()) );
                    rSplitPos.setX( static_cast<tools::Long>(static_cast<double>(rSplitPos.X()) / pDocShell->GetOutputFactor()) );
            }
            else if( bFrozen )
            {
@@ -3422,8 +3422,8 @@ void ScViewData::WriteExtOptions( ScExtDocOptions& rDocOpt ) const

            // view mode and zoom
            rTabSett.mbPageMode = bPagebreak;
            rTabSett.mnNormalZoom = static_cast< long >( pViewTab->aZoomY * Fraction( 100.0 ) );
            rTabSett.mnPageZoom = static_cast< long >( pViewTab->aPageZoomY * Fraction( 100.0 ) );
            rTabSett.mnNormalZoom = static_cast< tools::Long >( pViewTab->aZoomY * Fraction( 100.0 ) );
            rTabSett.mnPageZoom = static_cast< tools::Long >( pViewTab->aPageZoomY * Fraction( 100.0 ) );
        }
    }
}
@@ -3509,7 +3509,7 @@ void ScViewData::ReadExtOptions( const ScExtDocOptions& rDocOpt )
                if( pDocShell && SC_MOD()->GetInputOptions().GetTextWysiwyg())
                {
                    double nFactor = pDocShell->GetOutputFactor();
                    aPixel.setX( static_cast<long>( aPixel.X() * nFactor + 0.5 ) );
                    aPixel.setX( static_cast<tools::Long>( aPixel.X() * nFactor + 0.5 ) );
                }

                bHSplit = bHSplit && aPixel.X() > 0;
@@ -3640,8 +3640,8 @@ void ScViewData::WriteUserDataSequence(uno::Sequence <beans::PropertyValue>& rSe
    pSettings[SC_ACTIVE_TABLE].Value <<= sName;
    pSettings[SC_HORIZONTAL_SCROLL_BAR_WIDTH].Name = SC_HORIZONTALSCROLLBARWIDTH;
    pSettings[SC_HORIZONTAL_SCROLL_BAR_WIDTH].Value <<= sal_Int32(pView->GetTabBarWidth());
    sal_Int32 nZoomValue = long(pThisTab->aZoomY * 100);
    sal_Int32 nPageZoomValue = long(pThisTab->aPageZoomY * 100);
    sal_Int32 nZoomValue = tools::Long(pThisTab->aZoomY * 100);
    sal_Int32 nPageZoomValue = tools::Long(pThisTab->aPageZoomY * 100);
    pSettings[SC_ZOOM_TYPE].Name = SC_ZOOMTYPE;
    pSettings[SC_ZOOM_TYPE].Value <<= sal_Int16(pThisTab->eZoomType);
    pSettings[SC_ZOOM_VALUE].Name = SC_ZOOMVALUE;
@@ -3916,13 +3916,13 @@ bool ScViewData::UpdateFixX( SCTAB nTab )                   // true = value chan
        return false;

    SCCOL nFix = maTabData[nTab]->nFixPosX;
    long nNewPos = 0;
    tools::Long nNewPos = 0;
    for (SCCOL nX=maTabData[nTab]->nPosX[SC_SPLIT_LEFT]; nX<nFix; nX++)
    {
        sal_uInt16 nTSize = rLocalDoc.GetColWidth( nX, nTab );
        if (nTSize)
        {
            long nPix = ToPixel( nTSize, nPPTX );
            tools::Long nPix = ToPixel( nTSize, nPPTX );
            nNewPos += nPix;
        }
    }
@@ -3951,13 +3951,13 @@ bool ScViewData::UpdateFixY( SCTAB nTab )               // true = value changed
        return false;

    SCROW nFix = maTabData[nTab]->nFixPosY;
    long nNewPos = 0;
    tools::Long nNewPos = 0;
    for (SCROW nY=maTabData[nTab]->nPosY[SC_SPLIT_TOP]; nY<nFix; nY++)
    {
        sal_uInt16 nTSize = rLocalDoc.GetRowHeight( nY, nTab );
        if (nTSize)
        {
            long nPix = ToPixel( nTSize, nPPTY );
            tools::Long nPix = ToPixel( nTSize, nPPTY );
            nNewPos += nPix;
        }
    }
@@ -4019,7 +4019,7 @@ void ScViewData::SetRefEnd( SCCOL nNewX, SCROW nNewY, SCTAB nNewZ )
    nRefEndX = nNewX; nRefEndY = nNewY; nRefEndZ = nNewZ;
}

void ScViewData::AddPixelsWhile( long & rScrY, long nEndPixels, SCROW & rPosY,
void ScViewData::AddPixelsWhile( tools::Long & rScrY, tools::Long nEndPixels, SCROW & rPosY,
        SCROW nEndRow, double nPPTY, const ScDocument * pDoc, SCTAB nTabNo )
{
    SCROW nRow = rPosY;
@@ -4048,7 +4048,7 @@ void ScViewData::AddPixelsWhile( long & rScrY, long nEndPixels, SCROW & rPosY,
                    nAdd += nPixel;
                }
            }
            rScrY += static_cast<long>(nAdd);
            rScrY += static_cast<tools::Long>(nAdd);
            nRow += nRows;
        }
    }
@@ -4057,7 +4057,7 @@ void ScViewData::AddPixelsWhile( long & rScrY, long nEndPixels, SCROW & rPosY,
    rPosY = nRow;
}

void ScViewData::AddPixelsWhileBackward( long & rScrY, long nEndPixels,
void ScViewData::AddPixelsWhileBackward( tools::Long & rScrY, tools::Long nEndPixels,
        SCROW & rPosY, SCROW nStartRow, double nPPTY, const ScDocument * pDoc,
        SCTAB nTabNo )
{
@@ -4087,7 +4087,7 @@ void ScViewData::AddPixelsWhileBackward( long & rScrY, long nEndPixels,
                    nAdd += nPixel;
                }
            }
            rScrY += static_cast<long>(nAdd);
            rScrY += static_cast<tools::Long>(nAdd);
            nRow -= nRows;
        }
    }
@@ -4192,7 +4192,7 @@ void ScViewData::DeriveLOKFreezeIfNeeded(SCTAB nForTab)

void ScViewData::OverrideWithLOKFreeze(ScSplitMode& eExHSplitMode, ScSplitMode& eExVSplitMode,
                                       SCCOL& nExFixPosX, SCROW& nExFixPosY,
                                       long& nExHSplitPos, long& nExVSplitPos, SCTAB nForTab) const
                                       tools::Long& nExHSplitPos, tools::Long& nExVSplitPos, SCTAB nForTab) const
{
    SCCOL nFreezeCol = mrDoc.GetLOKFreezeCol(nForTab);
    SCROW nFreezeRow = mrDoc.GetLOKFreezeRow(nForTab);
diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index 3467147..227f53b 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -93,13 +93,13 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
            //  Window MapMode isn't drawing MapMode if DrawingLayer hasn't been created yet

            SCTAB nTab = GetViewData().GetTabNo();
            long nXT = 0;
            tools::Long nXT = 0;
            for (SCCOL i=0; i<nPosX; i++)
                nXT += rDoc.GetColWidth(i,nTab);
            if (rDoc.IsNegativePage(nTab))
                nXT = -nXT;
            sal_uLong nYT = rDoc.GetRowHeight( 0, nPosY-1, nTab);
            aPos = Point( static_cast<long>(nXT * HMM_PER_TWIPS), static_cast<long>(nYT * HMM_PER_TWIPS) );
            aPos = Point( static_cast<tools::Long>(nXT * HMM_PER_TWIPS), static_cast<tools::Long>(nYT * HMM_PER_TWIPS) );
        }
    }

diff --git a/sc/source/ui/view/viewfun7.cxx b/sc/source/ui/view/viewfun7.cxx
index 659a421..a59fa3a 100644
--- a/sc/source/ui/view/viewfun7.cxx
+++ b/sc/source/ui/view/viewfun7.cxx
@@ -58,8 +58,8 @@ static void lcl_AdjustInsertPos( ScViewData& rData, Point& rPos, const Size& rSi
    Size aPgSize( pPage->GetSize() );
    if (aPgSize.Width() < 0)
        aPgSize.setWidth( -aPgSize.Width() );
    long x = aPgSize.Width() - rPos.X() - rSize.Width();
    long y = aPgSize.Height() - rPos.Y() - rSize.Height();
    tools::Long x = aPgSize.Width() - rPos.X() - rSize.Width();
    tools::Long y = aPgSize.Height() - rPos.Y() - rSize.Height();
    // if necessary: adjustments (80/200) for pixel approx. errors
    if( x < 0 )
        rPos.AdjustX(x + 80 );
@@ -119,8 +119,8 @@ void ScViewFunc::PasteDraw( const Point& rLogicPos, SdrModel* pModel,
            // copy locally - incl. charts

        Point aSourceStart = pDragEditView->GetAllMarkedRect().TopLeft();
        long nDiffX = aPos.X() - aSourceStart.X();
        long nDiffY = aPos.Y() - aSourceStart.Y();
        tools::Long nDiffX = aPos.X() - aSourceStart.X();
        tools::Long nDiffY = aPos.Y() - aSourceStart.Y();

            // move within a page?

diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 6067477..c22effd 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -1461,7 +1461,7 @@ void ScViewFunc::UpdateStyleSheetInUse( const SfxStyleSheetBase* pStyleSheet )
}


void ScViewFunc::OnLOKInsertDeleteColumn(SCCOL nStartCol, long nOffset)
void ScViewFunc::OnLOKInsertDeleteColumn(SCCOL nStartCol, tools::Long nOffset)
{
    if (!comphelper::LibreOfficeKit::isActive() || nOffset == 0)
        return;
@@ -1517,7 +1517,7 @@ void ScViewFunc::OnLOKInsertDeleteColumn(SCCOL nStartCol, long nOffset)
    }
}

void ScViewFunc::OnLOKInsertDeleteRow(SCROW nStartRow, long nOffset)
void ScViewFunc::OnLOKInsertDeleteRow(SCROW nStartRow, tools::Long nOffset)
{
    if (!comphelper::LibreOfficeKit::isActive() || nOffset == 0)
        return;
@@ -2390,7 +2390,7 @@ void ScViewFunc::ModifyCellSize( ScDirection eDir, bool bOptimal )
                ScInputHandler* pHdl = pScMod->GetInputHdl( GetViewData().GetViewShell() );
                if (pHdl)
                {
                    long nEdit = pHdl->GetTextSize().Width();       // in 0.01 mm
                    tools::Long nEdit = pHdl->GetTextSize().Width();       // in 0.01 mm

                    const ScPatternAttr* pPattern = rDoc.GetPattern( nCol, nRow, nTab );
                    const SvxMarginItem& rMItem = pPattern->GetItem(ATTR_MARGIN);
@@ -2418,7 +2418,7 @@ void ScViewFunc::ModifyCellSize( ScDirection eDir, bool bOptimal )
                    aZoomX = aZoomY = Fraction( 1, 1 );
                }

                long nPixel = rDoc.GetNeededSize( nCol, nRow, nTab, aProv.GetDevice(),
                tools::Long nPixel = rDoc.GetNeededSize( nCol, nRow, nTab, aProv.GetDevice(),
                                            nPPTX, nPPTY, aZoomX, aZoomY, true );
                sal_uInt16 nTwips = static_cast<sal_uInt16>( nPixel / nPPTX );
                if (nTwips != 0)