1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/solar.h>
28 // map of row number to ScAddress*
29 typedef std::map
<sal_uLong
, std::unique_ptr
<ScAddress
>> RowMap
;
30 // map of column number to RowMap
31 typedef std::map
<sal_uLong
, RowMap
> ColumnMap
;
33 class ScChartPositionMap
35 friend class ScChartPositioner
;
37 std::unique_ptr
<std::unique_ptr
<ScAddress
>[]> ppData
;
38 std::unique_ptr
<std::unique_ptr
<ScAddress
>[]> ppColHeader
;
39 std::unique_ptr
<std::unique_ptr
<ScAddress
>[]> ppRowHeader
;
40 sal_uLong
const nCount
;
41 SCCOL
const nColCount
;
42 SCROW
const nRowCount
;
44 ScChartPositionMap( SCCOL nChartCols
, SCROW nChartRows
,
45 SCCOL nColAdd
, // header columns
46 SCROW nRowAdd
, // header rows
47 ColumnMap
& rCols
// table with col tables with address*
50 ScChartPositionMap( const ScChartPositionMap
& ) = delete;
51 ScChartPositionMap
& operator=( const ScChartPositionMap
& ) = delete;
54 ~ScChartPositionMap(); //! deletes all ScAddress*
56 SCCOL
GetColCount() const { return nColCount
; }
57 SCROW
GetRowCount() const { return nRowCount
; }
59 bool IsValid( SCCOL nCol
, SCROW nRow
) const
60 { return nCol
< nColCount
&& nRow
< nRowCount
; }
61 // data column by column
62 sal_uLong
GetIndex( SCCOL nCol
, SCROW nRow
) const
63 { return static_cast<sal_uLong
>(nCol
) * nRowCount
+ nRow
; }
65 const ScAddress
* GetPosition( sal_uLong nIndex
) const
67 if ( nIndex
< nCount
)
68 return ppData
[ nIndex
].get();
72 //! might be NULL indicating "no value"
73 const ScAddress
* GetPosition( SCCOL nChartCol
, SCROW nChartRow
) const
75 if ( IsValid( nChartCol
, nChartRow
) )
76 return ppData
[ GetIndex( nChartCol
, nChartRow
) ].get();
79 const ScAddress
* GetColHeaderPosition( SCCOL nChartCol
) const
81 if ( nChartCol
< nColCount
)
82 return ppColHeader
[ nChartCol
].get();
85 const ScAddress
* GetRowHeaderPosition( SCROW nChartRow
) const
87 if ( nChartRow
< nRowCount
)
88 return ppRowHeader
[ nChartRow
].get();
93 enum class ScChartGlue
{
103 class ScChartPositioner final
// only parameter struct
105 ScRangeListRef aRangeListRef
;
106 ScDocument
* const pDocument
;
107 std::unique_ptr
<ScChartPositionMap
> pPositionMap
;
113 bool bDummyUpperLeft
;
115 void CheckColRowHeaders();
117 void GlueState(); // summarised areas
118 void CreatePositionMap();
121 ScChartPositioner( ScDocument
* pDoc
, SCTAB nTab
,
122 SCCOL nStartColP
, SCROW nStartRowP
,
123 SCCOL nEndColP
, SCROW nEndRowP
);
124 ScChartPositioner( ScDocument
* pDoc
, const ScRangeListRef
& rRangeList
);
125 ScChartPositioner( const ScChartPositioner
& rPositioner
);
127 ~ScChartPositioner();
129 const ScRangeListRef
& GetRangeList() const { return aRangeListRef
; }
130 void SetRangeList( const ScRange
& rNew
);
132 void SetHeaders(bool bCol
, bool bRow
) { bColHeaders
=bCol
; bRowHeaders
=bRow
; }
133 bool HasColHeaders() const { return bColHeaders
; }
134 bool HasRowHeaders() const { return bRowHeaders
; }
136 void InvalidateGlue();
137 const ScChartPositionMap
* GetPositionMap();
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */