LibreOffice Module sw (master)  1
cellfml.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_SW_INC_CELLFML_HXX
21 #define INCLUDED_SW_INC_CELLFML_HXX
22 
23 #include <memory>
24 #include <rtl/ustrbuf.hxx>
25 #include <rtl/ustring.hxx>
26 
27 class SwTable;
28 class SwNode;
29 class SwTableSortBoxes;
30 class SwSelBoxes;
31 class SwCalc;
32 class SwTableBox;
34 class SwDoc;
35 class SwRootFrame;
36 
38 {
41 
42 public:
43  SwRootFrame const*const m_pLayout;
44  std::unique_ptr<SwTableSortBoxes> m_pBoxStack;
46  const SwTable* m_pTable;
47 
48  SwTableCalcPara(SwCalc& rCalculator, const SwTable& rTable, SwRootFrame const* pLayout);
50 
51  bool CalcWithStackOverflow();
52  bool IsStackOverflow() const { return m_nMaxSize == m_nStackCount; }
53  bool IncStackCnt() { return m_nMaxSize == ++m_nStackCount; }
54  void DecStackCnt() { if( m_nStackCount ) --m_nStackCount; }
55  void SetLastTableBox( const SwTableBox* pBox ) { m_pLastTableBox = pBox; }
56 };
57 
59 {
60 typedef void (SwTableFormula:: *FnScanFormula)( const SwTable&, OUStringBuffer&,
61  OUString&, OUString*, void* ) const;
62 
63  void BoxNmsToPtr( const SwTable&, OUStringBuffer&, OUString&, OUString*,
64  void* pPara ) const;
65  void PtrToBoxNms( const SwTable&, OUStringBuffer&, OUString&, OUString*,
66  void* pPara ) const;
67  void RelNmsToBoxNms( const SwTable&, OUStringBuffer&, OUString&, OUString*,
68  void* pPara ) const;
69  void RelBoxNmsToPtr( const SwTable&, OUStringBuffer&, OUString&, OUString*,
70  void* pPara ) const;
71  void BoxNmsToRelNm( const SwTable&, OUStringBuffer&, OUString&, OUString*,
72  void* pPara ) const;
73  void MakeFormula_( const SwTable&, OUStringBuffer&, OUString&, OUString*,
74  void* pPara ) const;
75  void GetFormulaBoxes( const SwTable&, OUStringBuffer&, OUString&, OUString*,
76  void* pPara ) const;
77  void HasValidBoxes_( const SwTable&, OUStringBuffer&, OUString&, OUString*,
78  void* pPara ) const;
79  void SplitMergeBoxNm_( const SwTable&, OUStringBuffer&, OUString&, OUString*,
80  void* pPara ) const;
81 
82  static void GetBoxes( const SwTableBox& rStt, const SwTableBox& rEnd,
83  SwSelBoxes& rBoxes );
84  OUString ScanString( FnScanFormula fnFormula, const SwTable& rTable,
85  void*) const;
86 
87  static const SwTable* FindTable( SwDoc& rDoc, const OUString& rNm );
88 
89 protected:
91 
92  OUString m_sFormula;
95 
96  // find the node in which the formula is located
97  // TextField -> TextNode,
98  // BoxAttribut -> BoxStartNode
99  // !!! every derived class must override this !!!
100  virtual const SwNode* GetNodeOfFormula() const = 0;
101 
102  SwTableFormula( const OUString& rFormula );
103 
104  OUString MakeFormula( SwTableCalcPara& rCalcPara ) const
105  {
107  *rCalcPara.m_pTable, &rCalcPara );
108  }
109 
110  static sal_uInt16 GetLnPosInTable( const SwTable& rTable, const SwTableBox* pBox );
111 
112 public:
113 
114  virtual ~SwTableFormula();
115 
116  SwTableFormula(SwTableFormula const &) = default;
117  SwTableFormula(SwTableFormula &&) = default;
118  SwTableFormula & operator =(SwTableFormula const &) = default;
119  SwTableFormula & operator =(SwTableFormula &&) = default;
120 
122  void PtrToBoxNm( const SwTable* pTable );
124  void BoxNmToPtr( const SwTable* pTable );
126  void ToRelBoxNm( const SwTable* pTable );
128  void ToSplitMergeBoxNm( SwTableFormulaUpdate& rTableUpd );
129 
130  bool IsIntrnlName() const { return m_eNmType == INTRNL_NAME; }
131  NameType GetNameType() const { return m_eNmType; }
132 
133  bool IsValid() const { return m_bValidValue; }
134  void ChgValid( bool bNew ) { m_bValidValue = bNew; }
135 
136  const OUString& GetFormula() const { return m_sFormula; }
137  void SetFormula( const OUString& rNew )
138  {
139  m_sFormula = rNew;
140  m_eNmType = EXTRNL_NAME;
141  m_bValidValue = false;
142  }
143 
144  void GetBoxesOfFormula(const SwTable& rTable, SwSelBoxes& rBoxes);
145  // are all boxes valid which this formula relies on?
146  bool HasValidBoxes() const;
147 };
148 
149 #endif
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool CalcWithStackOverflow()
Definition: cellfml.cxx:274
Definition: calc.hxx:184
SwTableCalcPara(SwCalc &rCalculator, const SwTable &rTable, SwRootFrame const *pLayout)
Definition: cellfml.cxx:258
void SetLastTableBox(const SwTableBox *pBox)
Definition: cellfml.hxx:55
void RelNmsToBoxNms(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:389
const SwTable * m_pTable
current table
Definition: cellfml.hxx:46
const SwTableBox * m_pLastTableBox
Definition: cellfml.hxx:39
Definition: doc.hxx:185
OUString MakeFormula(SwTableCalcPara &rCalcPara) const
Definition: cellfml.hxx:104
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
void(SwTableFormula::* FnScanFormula)(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *) const
Definition: cellfml.hxx:60
OUString m_sFormula
current formula
Definition: cellfml.hxx:92
bool HasValidBoxes() const
Definition: cellfml.cxx:1034
void BoxNmToPtr(const SwTable *pTable)
create from the external formula the internal
Definition: cellfml.cxx:567
NameType GetNameType() const
Definition: cellfml.hxx:131
sal_uInt16 m_nMaxSize
Definition: cellfml.hxx:40
sal_uInt16 m_nStackCount
Definition: cellfml.hxx:40
SwTableFormula(const OUString &rFormula)
Definition: cellfml.cxx:311
OUString ScanString(FnScanFormula fnFormula, const SwTable &rTable, void *) const
Definition: cellfml.cxx:613
static sal_uInt16 GetLnPosInTable(const SwTable &rTable, const SwTableBox *pBox)
Definition: cellfml.cxx:1044
void PtrToBoxNms(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:488
void SetFormula(const OUString &rNew)
Definition: cellfml.hxx:137
void PtrToBoxNm(const SwTable *pTable)
create from the internal formula (for CORE) the external formula (for UI)
Definition: cellfml.cxx:542
void DecStackCnt()
Definition: cellfml.hxx:54
NameType m_eNmType
current display method
Definition: cellfml.hxx:93
bool IncStackCnt()
Definition: cellfml.hxx:53
bool IsValid() const
Definition: cellfml.hxx:133
SwRootFrame const *const m_pLayout
layout to access text field results
Definition: cellfml.hxx:43
bool IsIntrnlName() const
Definition: cellfml.hxx:130
virtual ~SwTableFormula()
Definition: cellfml.cxx:318
static const SwTable * FindTable(SwDoc &rDoc, const OUString &rNm)
Definition: cellfml.cxx:711
static void GetBoxes(const SwTableBox &rStt, const SwTableBox &rEnd, SwSelBoxes &rBoxes)
Definition: cellfml.cxx:929
bool IsStackOverflow() const
Definition: cellfml.hxx:52
void ToSplitMergeBoxNm(SwTableFormulaUpdate &rTableUpd)
gets called before/after merging/splitting of tables
Definition: cellfml.cxx:1203
void GetBoxesOfFormula(const SwTable &rTable, SwSelBoxes &rBoxes)
Definition: cellfml.cxx:886
void MakeFormula_(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:322
void GetFormulaBoxes(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:895
void BoxNmsToRelNm(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:454
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
std::unique_ptr< SwTableSortBoxes > m_pBoxStack
stack for recognizing recursion
Definition: cellfml.hxx:44
void RelBoxNmsToPtr(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:422
void ChgValid(bool bNew)
Definition: cellfml.hxx:134
const OUString & GetFormula() const
Definition: cellfml.hxx:136
bool m_bValidValue
true: recalculate formula
Definition: cellfml.hxx:94
void HasValidBoxes_(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Are all boxes valid that are referenced by the formula?
Definition: cellfml.cxx:986
void BoxNmsToPtr(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:520
void ToRelBoxNm(const SwTable *pTable)
create from the external/internal formula the relative formula
Definition: cellfml.cxx:592
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
void SplitMergeBoxNm_(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:1057
SwTableFormula & operator=(SwTableFormula const &)=default
virtual const SwNode * GetNodeOfFormula() const =0
SwCalc & m_rCalc
current Calculator
Definition: cellfml.hxx:45
Base class of the Writer document model elements.
Definition: node.hxx:79
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo