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 "address.hxx"
14 #include "formulacell.hxx"
15 #include <svl/broadcast.hxx>
16 #include <svl/sharedstring.hxx>
17 #include <editeng/editobj.hxx>
18 #include "calcmacros.hxx"
20 #include "celltextattr.hxx"
21 #include <osl/mutex.hxx>
23 #if DEBUG_COLUMN_STORAGE
27 #define MDDS_MULTI_TYPE_VECTOR_DEBUG 1
30 #include <mdds/multi_type_vector_macro.hpp>
31 #include <mdds/multi_type_vector.hpp>
32 #include <mdds/multi_type_vector_custom_func1.hpp>
33 #include <mdds/multi_type_vector_custom_func3.hpp>
35 #include <unordered_map>
40 struct ScRefCellValue
;
44 /// Custom element type IDs for multi_type_vector.
46 const mdds::mtv::element_t element_type_broadcaster
= mdds::mtv::element_type_user_start
;
47 const mdds::mtv::element_t element_type_celltextattr
= mdds::mtv::element_type_user_start
+ 1;
49 const mdds::mtv::element_t element_type_string
= mdds::mtv::element_type_user_start
+ 2;
50 const mdds::mtv::element_t element_type_edittext
= mdds::mtv::element_type_user_start
+ 3;
51 const mdds::mtv::element_t element_type_formula
= mdds::mtv::element_type_user_start
+ 4;
53 const mdds::mtv::element_t element_type_cellnote
= mdds::mtv::element_type_user_start
+ 5;
55 /// Mapped standard element types (for convenience).
56 const mdds::mtv::element_t element_type_numeric
= mdds::mtv::element_type_numeric
;
57 const mdds::mtv::element_t element_type_empty
= mdds::mtv::element_type_empty
;
58 const mdds::mtv::element_t element_type_uint16
= mdds::mtv::element_type_ushort
;
60 /// Custom element blocks.
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::numeric_element_block numeric_block
;
71 typedef mdds::mtv::ushort_element_block uint16_block
;
73 /// This needs to be in the same namespace as CellTextAttr.
74 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(CellTextAttr
, element_type_celltextattr
, CellTextAttr(), celltextattr_block
)
77 /// These need to be in global namespace just like their respective types are.
78 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScPostIt
, sc::element_type_cellnote
, nullptr, sc::cellnote_block
)
79 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SvtBroadcaster
, sc::element_type_broadcaster
, nullptr, sc::broadcaster_block
)
80 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScFormulaCell
, sc::element_type_formula
, nullptr, sc::formula_block
)
81 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(EditTextObject
, sc::element_type_edittext
, nullptr, sc::edittext_block
)
85 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(SharedString
, sc::element_type_string
, SharedString(), sc::string_block
)
96 CellStoreEvent(ScColumn
* pCol
);
98 void element_block_acquired(const mdds::mtv::base_element_block
* block
);
99 void element_block_released(const mdds::mtv::base_element_block
* block
);
102 /// Cell note container
103 typedef mdds::mtv::custom_block_func1
<sc::cellnote_block
> CNoteFunc
;
104 typedef mdds::multi_type_vector
<CNoteFunc
> CellNoteStoreType
;
106 /// Broadcaster storage container
107 typedef mdds::mtv::custom_block_func1
<sc::broadcaster_block
> BCBlkFunc
;
108 typedef mdds::multi_type_vector
<BCBlkFunc
> BroadcasterStoreType
;
110 /// Cell text attribute container.
111 typedef mdds::mtv::custom_block_func1
<sc::celltextattr_block
> CTAttrFunc
;
112 typedef mdds::multi_type_vector
<CTAttrFunc
> CellTextAttrStoreType
;
115 typedef mdds::mtv::custom_block_func3
<sc::string_block
, sc::edittext_block
, sc::formula_block
> CellFunc
;
116 typedef mdds::multi_type_vector
<CellFunc
, CellStoreEvent
> CellStoreType
;
119 * Store position data for column array storage.
121 struct ColumnBlockPosition
123 CellNoteStoreType::iterator miCellNotePos
;
124 BroadcasterStoreType::iterator miBroadcasterPos
;
125 CellTextAttrStoreType::iterator miCellTextAttrPos
;
126 CellStoreType::iterator miCellPos
;
128 ColumnBlockPosition(): miCellPos() {}
131 struct ColumnBlockConstPosition
133 CellNoteStoreType::const_iterator miCellNotePos
;
134 BroadcasterStoreType::const_iterator miBroadcasterPos
;
135 CellTextAttrStoreType::const_iterator miCellTextAttrPos
;
136 CellStoreType::const_iterator miCellPos
;
138 ColumnBlockConstPosition(): miCellPos() {}
141 class ColumnBlockPositionSet
143 typedef std::unordered_map
<SCCOL
, ColumnBlockPosition
> ColumnsType
;
144 typedef std::unordered_map
<SCTAB
, ColumnsType
> TablesType
;
148 osl::Mutex maMtxTables
;
151 ColumnBlockPositionSet(ScDocument
& rDoc
);
153 ColumnBlockPosition
* getBlockPosition(SCTAB nTab
, SCCOL nCol
);
159 * Set of column block positions only for one table.
161 class TableColumnBlockPositionSet
164 std::unique_ptr
<Impl
> mpImpl
;
167 TableColumnBlockPositionSet( ScDocument
& rDoc
, SCTAB nTab
);
168 TableColumnBlockPositionSet( TableColumnBlockPositionSet
&& rOther
);
169 ~TableColumnBlockPositionSet();
171 ColumnBlockPosition
* getBlockPosition( SCCOL nCol
);
174 ScRefCellValue
toRefCell( const sc::CellStoreType::const_iterator
& itPos
, size_t nOffset
);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */