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/ustring.hxx>
25 
26 class SwTable;
27 class SwNode;
28 class SwTableSortBoxes;
29 class SwSelBoxes;
30 class SwCalc;
31 class SwTableBox;
33 class SwDoc;
34 class SwRootFrame;
35 
37 {
40 
41 public:
42  SwRootFrame const*const m_pLayout;
43  std::unique_ptr<SwTableSortBoxes> m_pBoxStack;
45  const SwTable* m_pTable;
46 
47  SwTableCalcPara(SwCalc& rCalculator, const SwTable& rTable, SwRootFrame const* pLayout);
49 
50  bool CalcWithStackOverflow();
51  bool IsStackOverflow() const { return m_nMaxSize == m_nStackCount; }
52  bool IncStackCnt() { return m_nMaxSize == ++m_nStackCount; }
53  void DecStackCnt() { if( m_nStackCount ) --m_nStackCount; }
54  void SetLastTableBox( const SwTableBox* pBox ) { m_pLastTableBox = pBox; }
55 };
56 
58 {
59 typedef void (SwTableFormula:: *FnScanFormula)( const SwTable&, OUStringBuffer&,
60  OUString&, OUString*, void* ) const;
61 
62  void BoxNmsToPtr( const SwTable&, OUStringBuffer&, OUString&, OUString*,
63  void* pPara ) const;
64  void PtrToBoxNms( const SwTable&, OUStringBuffer&, OUString&, OUString*,
65  void* pPara ) const;
66  void RelNmsToBoxNms( const SwTable&, OUStringBuffer&, OUString&, OUString*,
67  void* pPara ) const;
68  void RelBoxNmsToPtr( const SwTable&, OUStringBuffer&, OUString&, OUString*,
69  void* pPara ) const;
70  void BoxNmsToRelNm( const SwTable&, OUStringBuffer&, OUString&, OUString*,
71  void* pPara ) const;
72  void MakeFormula_( const SwTable&, OUStringBuffer&, OUString&, OUString*,
73  void* pPara ) const;
74  void GetFormulaBoxes( const SwTable&, OUStringBuffer&, OUString&, OUString*,
75  void* pPara ) const;
76  void HasValidBoxes_( const SwTable&, OUStringBuffer&, OUString&, OUString*,
77  void* pPara ) const;
78  void SplitMergeBoxNm_( const SwTable&, OUStringBuffer&, OUString&, OUString*,
79  void* pPara ) const;
80 
81  static void GetBoxes( const SwTableBox& rStt, const SwTableBox& rEnd,
82  SwSelBoxes& rBoxes );
83  OUString ScanString( FnScanFormula fnFormula, const SwTable& rTable,
84  void*) const;
85 
86  static const SwTable* FindTable( SwDoc& rDoc, const OUString& rNm );
87 
88 protected:
90 
91  OUString m_sFormula;
94 
95  // find the node in which the formula is located
96  // TextField -> TextNode,
97  // BoxAttribut -> BoxStartNode
98  // !!! every derived class must override this !!!
99  virtual const SwNode* GetNodeOfFormula() const = 0;
100 
101  SwTableFormula( const OUString& rFormula );
102 
103  OUString MakeFormula( SwTableCalcPara& rCalcPara ) const
104  {
106  *rCalcPara.m_pTable, &rCalcPara );
107  }
108 
109  static sal_uInt16 GetLnPosInTable( const SwTable& rTable, const SwTableBox* pBox );
110 
111 public:
112 
113  virtual ~SwTableFormula();
114 
115  SwTableFormula(SwTableFormula const &) = default;
116  SwTableFormula(SwTableFormula &&) = default;
117  SwTableFormula & operator =(SwTableFormula const &) = default;
118  SwTableFormula & operator =(SwTableFormula &&) = default;
119 
121  void PtrToBoxNm( const SwTable* pTable );
123  void BoxNmToPtr( const SwTable* pTable );
125  void ToRelBoxNm( const SwTable* pTable );
127  void ToSplitMergeBoxNm( SwTableFormulaUpdate& rTableUpd );
128 
129  bool IsIntrnlName() const { return m_eNmType == INTRNL_NAME; }
130  NameType GetNameType() const { return m_eNmType; }
131 
132  bool IsValid() const { return m_bValidValue; }
133  void ChgValid( bool bNew ) { m_bValidValue = bNew; }
134 
135  const OUString& GetFormula() const { return m_sFormula; }
136  void SetFormula( const OUString& rNew )
137  {
138  m_sFormula = rNew;
139  m_eNmType = EXTRNL_NAME;
140  m_bValidValue = false;
141  }
142 
143  void GetBoxesOfFormula(const SwTable& rTable, SwSelBoxes& rBoxes);
144  // are all boxes valid which this formula relies on?
145  bool HasValidBoxes() const;
146 };
147 
148 #endif
149 
150 /* 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:54
void RelNmsToBoxNms(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:389
const SwTable * m_pTable
current table
Definition: cellfml.hxx:45
const SwTableBox * m_pLastTableBox
Definition: cellfml.hxx:38
Definition: doc.hxx:185
OUString MakeFormula(SwTableCalcPara &rCalcPara) const
Definition: cellfml.hxx:103
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:59
OUString m_sFormula
current formula
Definition: cellfml.hxx:91
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:130
sal_uInt16 m_nMaxSize
Definition: cellfml.hxx:39
sal_uInt16 m_nStackCount
Definition: cellfml.hxx:39
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:136
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:53
NameType m_eNmType
current display method
Definition: cellfml.hxx:92
bool IncStackCnt()
Definition: cellfml.hxx:52
bool IsValid() const
Definition: cellfml.hxx:132
SwRootFrame const *const m_pLayout
layout to access text field results
Definition: cellfml.hxx:42
bool IsIntrnlName() const
Definition: cellfml.hxx:129
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:51
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:43
void RelBoxNmsToPtr(const SwTable &, OUStringBuffer &, OUString &, OUString *, void *pPara) const
Definition: cellfml.cxx:422
void ChgValid(bool bNew)
Definition: cellfml.hxx:133
const OUString & GetFormula() const
Definition: cellfml.hxx:135
bool m_bValidValue
true: recalculate formula
Definition: cellfml.hxx:93
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:44
Base class of the Writer document model elements.
Definition: node.hxx:79
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo