/src/libreoffice/sw/inc/cellfml.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include "swdllapi.h" |
23 | | |
24 | | #include <memory> |
25 | | #include <rtl/ustrbuf.hxx> |
26 | | #include <rtl/ustring.hxx> |
27 | | |
28 | | class SwTable; |
29 | | class SwNode; |
30 | | class SwTableSortBoxes; |
31 | | class SwSelBoxes; |
32 | | class SwCalc; |
33 | | class SwTableBox; |
34 | | class SwTableFormulaUpdate; |
35 | | class SwDoc; |
36 | | class SwRootFrame; |
37 | | |
38 | | class SwTableCalcPara |
39 | | { |
40 | | const SwTableBox* m_pLastTableBox; |
41 | | sal_uInt16 m_nStackCount, m_nMaxSize; |
42 | | |
43 | | public: |
44 | | SwRootFrame const*const m_pLayout; ///< layout to access text field results |
45 | | std::unique_ptr<SwTableSortBoxes> m_pBoxStack; ///< stack for recognizing recursion |
46 | | SwCalc& m_rCalc; ///< current Calculator |
47 | | const SwTable* m_pTable; ///< current table |
48 | | |
49 | | SwTableCalcPara(SwCalc& rCalculator, const SwTable& rTable, SwRootFrame const* pLayout); |
50 | | ~SwTableCalcPara(); |
51 | | |
52 | | bool CalcWithStackOverflow(); |
53 | 4 | bool IsStackOverflow() const { return m_nMaxSize == m_nStackCount; } |
54 | 0 | bool IncStackCnt() { return m_nMaxSize == ++m_nStackCount; } |
55 | 0 | void DecStackCnt() { if( m_nStackCount ) --m_nStackCount; } |
56 | 0 | void SetLastTableBox( const SwTableBox* pBox ) { m_pLastTableBox = pBox; } |
57 | | }; |
58 | | |
59 | | typedef struct _xmlTextWriter* xmlTextWriterPtr; |
60 | | class SW_DLLPUBLIC SwTableFormula |
61 | | { |
62 | | typedef void (SwTableFormula::*FnScanFormula)( const SwTable&, OUStringBuffer&, |
63 | | OUString&, OUString*, void* ) const; |
64 | | |
65 | | void BoxNmsToPtr( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
66 | | void* pPara ) const; |
67 | | void PtrToBoxNms( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
68 | | void* pPara ) const; |
69 | | void RelNmsToBoxNms( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
70 | | void* pPara ) const; |
71 | | void RelBoxNmsToPtr( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
72 | | void* pPara ) const; |
73 | | void BoxNmsToRelNm( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
74 | | void* pPara ) const; |
75 | | void MakeFormula_( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
76 | | void* pPara ) const; |
77 | | void GetFormulaBoxes( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
78 | | void* pPara ) const; |
79 | | void HasValidBoxes_( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
80 | | void* pPara ) const; |
81 | | void SplitMergeBoxNm_( const SwTable&, OUStringBuffer&, OUString&, OUString*, |
82 | | void* pPara ) const; |
83 | | |
84 | | static void GetBoxes( const SwTableBox& rStt, const SwTableBox& rEnd, |
85 | | SwSelBoxes& rBoxes ); |
86 | | OUString ScanString( FnScanFormula fnFormula, const SwTable& rTable, |
87 | | void*) const; |
88 | | |
89 | | static const SwTable* FindTable( SwDoc& rDoc, std::u16string_view rNm ); |
90 | | |
91 | | protected: |
92 | | enum class NameType { External, Internal, Relative }; |
93 | | |
94 | | OUString m_sFormula; ///< current formula |
95 | | NameType m_eNmType; ///< current display method |
96 | | bool m_bValidValue; ///< true: recalculate formula |
97 | | |
98 | | // find the node in which the formula is located |
99 | | // TextField -> TextNode, |
100 | | // BoxAttribute -> BoxStartNode |
101 | | // !!! every derived class must override this !!! |
102 | | virtual const SwNode* GetNodeOfFormula() const = 0; |
103 | | |
104 | | SwTableFormula( OUString aFormula ); |
105 | | |
106 | | OUString MakeFormula( SwTableCalcPara& rCalcPara ) const |
107 | 2 | { |
108 | 2 | return ScanString( &SwTableFormula::MakeFormula_, |
109 | 2 | *rCalcPara.m_pTable, &rCalcPara ); |
110 | 2 | } |
111 | | |
112 | | |
113 | | public: |
114 | | |
115 | | virtual ~SwTableFormula(); |
116 | | |
117 | 0 | SwTableFormula(SwTableFormula const &) = default; |
118 | | SwTableFormula(SwTableFormula &&) = default; |
119 | 449 | SwTableFormula & operator =(SwTableFormula const &) = default; |
120 | | SwTableFormula & operator =(SwTableFormula &&) = default; |
121 | | |
122 | | /// create from the internal formula (for CORE) the external formula (for UI) |
123 | | void PtrToBoxNm( const SwTable* pTable ); |
124 | | /// create from the external formula the internal |
125 | | void BoxNmToPtr( const SwTable* pTable ); |
126 | | /// create from the external/internal formula the relative formula |
127 | | void ToRelBoxNm( const SwTable* pTable ); |
128 | | /// gets called before/after merging/splitting of tables |
129 | | void ToSplitMergeBoxNm( SwTableFormulaUpdate& rTableUpd ); |
130 | | |
131 | 0 | bool IsIntrnlName() const { return m_eNmType == NameType::Internal; } |
132 | 0 | NameType GetNameType() const { return m_eNmType; } |
133 | | |
134 | 2 | bool IsValid() const { return m_bValidValue; } |
135 | 4 | void ChgValid( bool bNew ) { m_bValidValue = bNew; } |
136 | | |
137 | 449 | const OUString& GetFormula() const { return m_sFormula; } |
138 | | void SetFormula( const OUString& rNew ) |
139 | 0 | { |
140 | 0 | m_sFormula = rNew; |
141 | 0 | m_eNmType = NameType::External; |
142 | 0 | m_bValidValue = false; |
143 | 0 | } |
144 | | |
145 | | void GetBoxesOfFormula(const SwTable& rTable, SwSelBoxes& rBoxes); |
146 | | // are all boxes valid which this formula relies on? |
147 | | bool HasValidBoxes() const; |
148 | | static sal_uInt16 GetLnPosInTable( const SwTable& rTable, const SwTableBox* pBox ); |
149 | | virtual void dumpAsXml(xmlTextWriterPtr pWriter) const; |
150 | | }; |
151 | | |
152 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |