Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / chartpos.hxx
blobcde8b9ff52857f53e160d5a7143df827bacb17ba
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SC_INC_CHARTPOS_HXX
21 #define INCLUDED_SC_INC_CHARTPOS_HXX
23 #include "rangelst.hxx"
24 #include <memory>
25 #include <map>
27 // map of row number to ScAddress*
28 typedef std::map<sal_uLong, ScAddress*> RowMap;
29 // map of column number to RowMap*
30 typedef std::map<sal_uLong, RowMap*> ColumnMap;
32 class ScChartPositionMap
34 friend class ScChartPositioner;
36 std::unique_ptr<ScAddress*[]> ppData;
37 std::unique_ptr<ScAddress*[]> ppColHeader;
38 std::unique_ptr<ScAddress*[]> ppRowHeader;
39 sal_uLong nCount;
40 SCCOL nColCount;
41 SCROW nRowCount;
43 ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
44 SCCOL nColAdd, // header columns
45 SCROW nRowAdd, // header rows
46 ColumnMap& rCols // table with col tables with address*
49 ScChartPositionMap( const ScChartPositionMap& ) = delete;
50 ScChartPositionMap& operator=( const ScChartPositionMap& ) = delete;
52 public:
53 ~ScChartPositionMap(); //! deletes all ScAddress*
55 SCCOL GetColCount() const { return nColCount; }
56 SCROW GetRowCount() const { return nRowCount; }
58 bool IsValid( SCCOL nCol, SCROW nRow ) const
59 { return nCol < nColCount && nRow < nRowCount; }
60 // data column by column
61 sal_uLong GetIndex( SCCOL nCol, SCROW nRow ) const
62 { return static_cast<sal_uLong>(nCol) * nRowCount + nRow; }
64 const ScAddress* GetPosition( sal_uLong nIndex ) const
66 if ( nIndex < nCount )
67 return ppData[ nIndex ];
68 return nullptr;
71 //! might be NULL indicating "no value"
72 const ScAddress* GetPosition( SCCOL nChartCol, SCROW nChartRow ) const
74 if ( IsValid( nChartCol, nChartRow ) )
75 return ppData[ GetIndex( nChartCol, nChartRow ) ];
76 return nullptr;
78 const ScAddress* GetColHeaderPosition( SCCOL nChartCol ) const
80 if ( nChartCol < nColCount )
81 return ppColHeader[ nChartCol ];
82 return nullptr;
84 const ScAddress* GetRowHeaderPosition( SCROW nChartRow ) const
86 if ( nChartRow < nRowCount )
87 return ppRowHeader[ nChartRow ];
88 return nullptr;
92 enum class ScChartGlue {
93 NA,
94 NONE, // old mimic
95 Cols, // old mimic
96 Rows,
97 Both
100 class ScDocument;
102 class ScChartPositioner final // only parameter struct
104 ScRangeListRef aRangeListRef;
105 ScDocument* pDocument;
106 std::unique_ptr<ScChartPositionMap> pPositionMap;
107 ScChartGlue eGlue;
108 SCCOL nStartCol;
109 SCROW nStartRow;
110 bool bColHeaders;
111 bool bRowHeaders;
112 bool bDummyUpperLeft;
114 void CheckColRowHeaders();
116 void GlueState(); // summarised areas
117 void CreatePositionMap();
119 public:
120 ScChartPositioner( ScDocument* pDoc, SCTAB nTab,
121 SCCOL nStartColP, SCROW nStartRowP,
122 SCCOL nEndColP, SCROW nEndRowP );
123 ScChartPositioner( ScDocument* pDoc, const ScRangeListRef& rRangeList );
124 ScChartPositioner( const ScChartPositioner& rPositioner );
126 ~ScChartPositioner();
128 const ScRangeListRef& GetRangeList() const { return aRangeListRef; }
129 void SetRangeList( const ScRange& rNew );
131 void SetHeaders(bool bCol, bool bRow) { bColHeaders=bCol; bRowHeaders=bRow; }
132 bool HasColHeaders() const { return bColHeaders; }
133 bool HasRowHeaders() const { return bRowHeaders; }
135 void InvalidateGlue();
136 const ScChartPositionMap* GetPositionMap();
139 #endif
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */