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/.
10 #ifndef INCLUDED_SC_INC_MTVELEMENTS_HXX
11 #define INCLUDED_SC_INC_MTVELEMENTS_HXX
13 #include "formulacell.hxx"
14 #include <svl/broadcast.hxx>
15 #include <svl/sharedstring.hxx>
16 #include <editeng/editobj.hxx>
17 #include "calcmacros.hxx"
19 #include "celltextattr.hxx"
20 #include <osl/mutex.hxx>
22 #if DEBUG_COLUMN_STORAGE
26 #define MDDS_MULTI_TYPE_VECTOR_DEBUG 1
29 #include <mdds/multi_type_vector_macro.hpp>
30 #include <mdds/multi_type_vector.hpp>
31 #include <mdds/multi_type_vector_custom_func1.hpp>
32 #include <mdds/multi_type_vector_custom_func3.hpp>
34 #include <unordered_map>
39 struct ScRefCellValue
;
43 /// Custom element type IDs for multi_type_vector.
45 const mdds::mtv::element_t element_type_broadcaster
= mdds::mtv::element_type_user_start
;
46 const mdds::mtv::element_t element_type_celltextattr
= mdds::mtv::element_type_user_start
+ 1;
48 const mdds::mtv::element_t element_type_string
= mdds::mtv::element_type_user_start
+ 2;
49 const mdds::mtv::element_t element_type_edittext
= mdds::mtv::element_type_user_start
+ 3;
50 const mdds::mtv::element_t element_type_formula
= mdds::mtv::element_type_user_start
+ 4;
52 const mdds::mtv::element_t element_type_cellnote
= mdds::mtv::element_type_user_start
+ 5;
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_cellnote
, ScPostIt
> cellnote_block
;
62 typedef mdds::mtv::noncopyable_managed_element_block
<element_type_broadcaster
, SvtBroadcaster
> broadcaster_block
;
63 typedef mdds::mtv::default_element_block
<element_type_celltextattr
, CellTextAttr
> celltextattr_block
;
64 typedef mdds::mtv::default_element_block
<element_type_string
, svl::SharedString
> string_block
;
65 typedef mdds::mtv::noncopyable_managed_element_block
<element_type_edittext
, EditTextObject
> edittext_block
;
66 typedef mdds::mtv::noncopyable_managed_element_block
<element_type_formula
, ScFormulaCell
> formula_block
;
68 /// Mapped standard element blocks (for convenience).
69 typedef mdds::mtv::double_element_block numeric_block
;
70 typedef mdds::mtv::uint16_element_block uint16_block
;
72 /// This needs to be in the same namespace as CellTextAttr.
73 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(CellTextAttr
, element_type_celltextattr
, CellTextAttr(), celltextattr_block
)
76 /// These need to be in global namespace just like their respective types are.
77 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScPostIt
, sc::element_type_cellnote
, nullptr, sc::cellnote_block
)
78 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SvtBroadcaster
, sc::element_type_broadcaster
, nullptr, sc::broadcaster_block
)
79 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScFormulaCell
, sc::element_type_formula
, nullptr, sc::formula_block
)
80 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(EditTextObject
, sc::element_type_edittext
, nullptr, sc::edittext_block
)
84 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(SharedString
, sc::element_type_string
, SharedString(), sc::string_block
)
95 CellStoreEvent(ScColumn
* pCol
);
97 void element_block_acquired(const mdds::mtv::base_element_block
* block
);
98 void element_block_released(const mdds::mtv::base_element_block
* block
);
101 /// Cell note container
102 typedef mdds::mtv::custom_block_func1
<sc::cellnote_block
> CNoteFunc
;
103 typedef mdds::multi_type_vector
<CNoteFunc
> CellNoteStoreType
;
105 /// Broadcaster storage container
106 typedef mdds::mtv::custom_block_func1
<sc::broadcaster_block
> BCBlkFunc
;
107 typedef mdds::multi_type_vector
<BCBlkFunc
> BroadcasterStoreType
;
109 /// Cell text attribute container.
110 typedef mdds::mtv::custom_block_func1
<sc::celltextattr_block
> CTAttrFunc
;
111 typedef mdds::multi_type_vector
<CTAttrFunc
> CellTextAttrStoreType
;
114 typedef mdds::mtv::custom_block_func3
<sc::string_block
, sc::edittext_block
, sc::formula_block
> CellFunc
;
115 typedef mdds::multi_type_vector
<CellFunc
, CellStoreEvent
> CellStoreType
;
118 * Store position data for column array storage.
120 struct ColumnBlockPosition
122 CellNoteStoreType::iterator miCellNotePos
;
123 BroadcasterStoreType::iterator miBroadcasterPos
;
124 CellTextAttrStoreType::iterator miCellTextAttrPos
;
125 CellStoreType::iterator miCellPos
;
127 ColumnBlockPosition(): miCellPos() {}
130 struct ColumnBlockConstPosition
132 CellNoteStoreType::const_iterator miCellNotePos
;
133 CellTextAttrStoreType::const_iterator miCellTextAttrPos
;
134 CellStoreType::const_iterator miCellPos
;
136 ColumnBlockConstPosition(): miCellPos() {}
139 class ColumnBlockPositionSet
141 typedef std::unordered_map
<SCCOL
, ColumnBlockPosition
> ColumnsType
;
142 typedef std::unordered_map
<SCTAB
, ColumnsType
> TablesType
;
146 osl::Mutex maMtxTables
;
149 ColumnBlockPositionSet(ScDocument
& rDoc
);
151 ColumnBlockPosition
* getBlockPosition(SCTAB nTab
, SCCOL nCol
);
157 * Set of column block positions only for one table.
159 class TableColumnBlockPositionSet
162 std::unique_ptr
<Impl
> mpImpl
;
165 TableColumnBlockPositionSet( ScDocument
& rDoc
, SCTAB nTab
);
166 TableColumnBlockPositionSet(TableColumnBlockPositionSet
&& rOther
) noexcept
;
167 ~TableColumnBlockPositionSet();
169 ColumnBlockPosition
* getBlockPosition( SCCOL nCol
);
170 void invalidate(); // discards cached positions
173 ScRefCellValue
toRefCell( const sc::CellStoreType::const_iterator
& itPos
, size_t nOffset
);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */