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/.
12 #include "formulacell.hxx"
13 #include <svl/broadcast.hxx>
14 #include <svl/sharedstring.hxx>
15 #include <editeng/editobj.hxx>
16 #include "calcmacros.hxx"
18 #include "SparklineCell.hxx"
19 #include "celltextattr.hxx"
21 #if DEBUG_COLUMN_STORAGE
25 #define MDDS_MULTI_TYPE_VECTOR_DEBUG 1
28 #include <mdds/multi_type_vector/macro.hpp>
29 #include <mdds/multi_type_vector/soa/main.hpp>
30 #include <mdds/multi_type_vector/block_funcs.hpp>
32 #include <unordered_map>
38 struct ScRefCellValue
;
42 /// Custom element type IDs for multi_type_vector.
44 const mdds::mtv::element_t element_type_broadcaster
= mdds::mtv::element_type_user_start
;
45 const mdds::mtv::element_t element_type_celltextattr
= mdds::mtv::element_type_user_start
+ 1;
47 const mdds::mtv::element_t element_type_string
= mdds::mtv::element_type_user_start
+ 2;
48 const mdds::mtv::element_t element_type_edittext
= mdds::mtv::element_type_user_start
+ 3;
49 const mdds::mtv::element_t element_type_formula
= mdds::mtv::element_type_user_start
+ 4;
51 const mdds::mtv::element_t element_type_cellnote
= mdds::mtv::element_type_user_start
+ 5;
52 const mdds::mtv::element_t element_type_sparkline
= mdds::mtv::element_type_user_start
+ 6;
54 /// Mapped standard element types (for convenience).
55 const mdds::mtv::element_t element_type_numeric
= mdds::mtv::element_type_double
;
56 const mdds::mtv::element_t element_type_empty
= mdds::mtv::element_type_empty
;
57 const mdds::mtv::element_t element_type_uint16
= mdds::mtv::element_type_uint16
;
59 /// Custom element blocks.
61 typedef mdds::mtv::noncopyable_managed_element_block
<element_type_sparkline
, sc::SparklineCell
> sparkline_block
;
62 typedef mdds::mtv::noncopyable_managed_element_block
<element_type_cellnote
, ScPostIt
> cellnote_block
;
63 typedef mdds::mtv::noncopyable_managed_element_block
<element_type_broadcaster
, SvtBroadcaster
> broadcaster_block
;
64 typedef mdds::mtv::default_element_block
<element_type_celltextattr
, CellTextAttr
> celltextattr_block
;
65 typedef mdds::mtv::default_element_block
<element_type_string
, svl::SharedString
> string_block
;
66 typedef mdds::mtv::noncopyable_managed_element_block
<element_type_edittext
, EditTextObject
> edittext_block
;
67 typedef mdds::mtv::noncopyable_managed_element_block
<element_type_formula
, ScFormulaCell
> formula_block
;
69 /// Mapped standard element blocks (for convenience).
70 typedef mdds::mtv::double_element_block numeric_block
;
71 typedef mdds::mtv::uint16_element_block uint16_block
;
75 /// CAUTION! The following defines must be in the same namespace as the respective type.
76 /// For example sc types like sc::CellTextAttr, ScFormulaCell in global namespace.
78 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(CellTextAttr
, element_type_celltextattr
, CellTextAttr(), celltextattr_block
)
79 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SparklineCell
, sc::element_type_sparkline
, nullptr, sc::sparkline_block
)
82 /// These need to be in global namespace just like their respective types are.
83 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScPostIt
, sc::element_type_cellnote
, nullptr, sc::cellnote_block
)
84 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SvtBroadcaster
, sc::element_type_broadcaster
, nullptr, sc::broadcaster_block
)
85 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScFormulaCell
, sc::element_type_formula
, nullptr, sc::formula_block
)
86 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(EditTextObject
, sc::element_type_edittext
, nullptr, sc::edittext_block
)
89 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(SharedString
, sc::element_type_string
, SharedString(), sc::string_block
)
99 CellStoreEvent(ScColumn
* pCol
);
101 void element_block_acquired(const mdds::mtv::base_element_block
* block
);
102 void element_block_released(const mdds::mtv::base_element_block
* block
);
104 /** Stop processing events. */
107 void swap(CellStoreEvent
& other
);
109 const ScColumn
* getColumn() const;
112 struct SparklineTraits
: public mdds::mtv::default_traits
114 using block_funcs
= mdds::mtv::element_block_funcs
<sc::sparkline_block
>;
117 struct CellNodeTraits
: public mdds::mtv::default_traits
119 using block_funcs
= mdds::mtv::element_block_funcs
<sc::cellnote_block
>;
122 struct BroadcasterTraits
: public mdds::mtv::default_traits
124 using block_funcs
= mdds::mtv::element_block_funcs
<sc::broadcaster_block
>;
127 struct CellTextAttrTraits
: public mdds::mtv::default_traits
129 using block_funcs
= mdds::mtv::element_block_funcs
<sc::celltextattr_block
>;
132 struct CellStoreTraits
: public mdds::mtv::default_traits
134 using event_func
= CellStoreEvent
;
135 using block_funcs
= mdds::mtv::element_block_funcs
<
136 numeric_block
, sc::string_block
, sc::edittext_block
, sc::formula_block
>;
139 /// Sparkline container
140 typedef mdds::mtv::soa::multi_type_vector
<SparklineTraits
> SparklineStoreType
;
142 /// Cell note container
143 typedef mdds::mtv::soa::multi_type_vector
<CellNodeTraits
> CellNoteStoreType
;
145 /// Broadcaster storage container
146 typedef mdds::mtv::soa::multi_type_vector
<BroadcasterTraits
> BroadcasterStoreType
;
148 /// Cell text attribute container.
149 typedef mdds::mtv::soa::multi_type_vector
<CellTextAttrTraits
> CellTextAttrStoreType
;
152 typedef mdds::mtv::soa::multi_type_vector
<CellStoreTraits
> CellStoreType
;
155 * Store position data for column array storage.
157 struct ColumnBlockPosition
159 CellNoteStoreType::iterator miCellNotePos
;
160 SparklineStoreType::iterator miSparklinePos
;
161 BroadcasterStoreType::iterator miBroadcasterPos
;
162 CellTextAttrStoreType::iterator miCellTextAttrPos
;
163 CellStoreType::iterator miCellPos
;
165 ColumnBlockPosition(): miCellPos() {}
168 struct ColumnBlockConstPosition
170 CellNoteStoreType::const_iterator miCellNotePos
;
171 SparklineStoreType::const_iterator miSparklinePos
;
172 CellTextAttrStoreType::const_iterator miCellTextAttrPos
;
173 CellStoreType::const_iterator miCellPos
;
175 ColumnBlockConstPosition(): miCellPos() {}
178 class ColumnBlockPositionSet
180 typedef std::unordered_map
<SCCOL
, ColumnBlockPosition
> ColumnsType
;
181 typedef std::unordered_map
<SCTAB
, ColumnsType
> TablesType
;
185 std::mutex maMtxTables
;
188 ColumnBlockPositionSet(ScDocument
& rDoc
);
190 ColumnBlockPosition
* getBlockPosition(SCTAB nTab
, SCCOL nCol
);
196 * Set of column block positions only for one table.
198 class TableColumnBlockPositionSet
201 std::unique_ptr
<Impl
> mpImpl
;
204 TableColumnBlockPositionSet( ScDocument
& rDoc
, SCTAB nTab
);
205 TableColumnBlockPositionSet(TableColumnBlockPositionSet
&& rOther
) noexcept
;
206 ~TableColumnBlockPositionSet();
208 ColumnBlockPosition
* getBlockPosition( SCCOL nCol
);
209 void invalidate(); // discards cached positions
212 ScRefCellValue
toRefCell( const sc::CellStoreType::const_iterator
& itPos
, size_t nOffset
);
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */