LibreOffice Module sc (master)  1
docfunc.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 #pragma once
21 
22 #include <tools/solar.h>
23 #include <global.hxx>
24 #include <formula/grammar.hxx>
25 #include <tabbgcolor.hxx>
26 #include <unotools/resmgr.hxx>
27 
28 #include <memory>
29 #include <vector>
30 #include <map>
31 
33 class SdrUndoAction;
34 class ScAddress;
35 class ScDocShell;
36 class ScMarkData;
37 class ScPatternAttr;
38 class ScRange;
39 class ScRangeList;
40 class ScFormulaCell;
41 class ScTokenArray;
42 struct ScTabOpParam;
43 class ScTableProtection;
44 class ScDocProtection;
45 struct ScCellMergeOption;
48 class ScUndoRemoveMerge;
49 class ScRangeName;
50 class ScPostIt;
51 
52 enum class TransliterationFlags;
53 enum class CreateNameFlags;
54 namespace sc {
55  struct ColRowSpan;
56 }
57 
58 class ScDocFunc
59 {
60 protected:
62 
63  bool AdjustRowHeight( const ScRange& rRange, bool bPaint, bool bApi );
64  void CreateOneName( ScRangeName& rList,
65  SCCOL nPosX, SCROW nPosY, SCTAB nTab,
66  SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
67  bool& rCancel, bool bApi );
68  void NotifyInputHandler( const ScAddress& rPos );
69 
70  ScDocFunc( ScDocShell& rDocSh ): rDocShell(rDocSh) {}
71 public:
72  virtual ~ScDocFunc() {}
73 
74  void NotifyDrawUndo(std::unique_ptr<SdrUndoAction>);
75 
76  // for grouping multiple operations into one with a new name
77  void EnterListAction(TranslateId pNameResId);
78  void EndListAction();
79 
80  bool DetectiveAddPred(const ScAddress& rPos);
81  bool DetectiveDelPred(const ScAddress& rPos);
82  bool DetectiveAddSucc(const ScAddress& rPos);
83  bool DetectiveDelSucc(const ScAddress& rPos);
84  bool DetectiveAddError(const ScAddress& rPos);
85  bool DetectiveMarkInvalid(SCTAB nTab);
86  bool DetectiveDelAll(SCTAB nTab);
87  bool DetectiveRefresh(bool bAutomatic = false);
88  void DetectiveCollectAllPreds(const ScRangeList& rSrcRanges, ::std::vector<ScTokenRef>& rRefTokens);
89  void DetectiveCollectAllSuccs(const ScRangeList& rSrcRanges, ::std::vector<ScTokenRef>& rRefTokens);
90 
92  const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi );
93 
94  bool DeleteCell(
95  const ScAddress& rPos, const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi );
96 
98  bool bApi );
99 
100  bool SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos, const OUString& rText, bool bApi );
101  bool SetValueCell( const ScAddress& rPos, double fVal, bool bInteraction );
102  void SetValueCells( const ScAddress& rPos, const std::vector<double>& aVals, bool bInteraction );
103  bool SetStringCell( const ScAddress& rPos, const OUString& rStr, bool bInteraction );
104  bool SetEditCell( const ScAddress& rPos, const EditTextObject& rStr, bool bInteraction );
105 
106  bool SetStringOrEditCell( const ScAddress& rPos, const OUString& rStr, bool bInteraction );
107 
112  bool SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell, bool bInteraction );
113  bool SetFormulaCells( const ScAddress& rPos, std::vector<ScFormulaCell*>& rCells, bool bInteraction );
114  void PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngine, bool bApi );
115  bool SetCellText(
116  const ScAddress& rPos, const OUString& rText, bool bInterpret, bool bEnglish, bool bApi,
117  const formula::FormulaGrammar::Grammar eGrammar );
118 
119  SC_DLLPUBLIC bool ShowNote( const ScAddress& rPos, bool bShow );
120 
121  void SetNoteText( const ScAddress& rPos, const OUString& rNoteText, bool bApi );
122  void ReplaceNote( const ScAddress& rPos, const OUString& rNoteText, const OUString* pAuthor, const OUString* pDate, bool bApi );
123  SC_DLLPUBLIC ScPostIt* ImportNote( const ScAddress& rPos, const OUString& rNoteText );
124 
125  bool ApplyAttributes( const ScMarkData& rMark, const ScPatternAttr& rPattern,
126  bool bApi );
127  bool ApplyStyle( const ScMarkData& rMark, const OUString& rStyleName,
128  bool bApi );
129 
130  bool InsertCells( const ScRange& rRange,const ScMarkData* pTabMark,
131  InsCellCmd eCmd, bool bRecord, bool bApi, bool bPartOfPaste = false );
132 
133  bool DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
134  DelCellCmd eCmd, bool bApi );
135 
136  bool MoveBlock( const ScRange& rSource, const ScAddress& rDestPos,
137  bool bCut, bool bRecord, bool bPaint, bool bApi );
138 
139  SC_DLLPUBLIC bool InsertTable( SCTAB nTab, const OUString& rName, bool bRecord, bool bApi );
140  bool RenameTable( SCTAB nTab, const OUString& rName, bool bRecord, bool bApi );
141  bool DeleteTable( SCTAB nTab, bool bRecord );
142 
143  bool SetTabBgColor( SCTAB nTab, const Color& rColor, bool bRecord, bool bApi );
144  bool SetTabBgColor( ScUndoTabColorInfo::List& rUndoTabColorList, bool bApi );
145 
146  void SetTableVisible( SCTAB nTab, bool bVisible, bool bApi );
147 
148  bool SetLayoutRTL( SCTAB nTab, bool bRTL );
149 
151  bool bWidth, const std::vector<sc::ColRowSpan>& rRanges, SCTAB nTab,
152  ScSizeMode eMode, sal_uInt16 nSizeTwips, bool bRecord, bool bApi );
153 
154  bool InsertPageBreak( bool bColumn, const ScAddress& rPos,
155  bool bRecord, bool bSetModified );
156  bool RemovePageBreak( bool bColumn, const ScAddress& rPos,
157  bool bRecord, bool bSetModified );
158 
159  void ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect );
160 
161  bool Protect( SCTAB nTab, const OUString& rPassword );
162  bool Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi );
163 
164  void ClearItems( const ScMarkData& rMark, const sal_uInt16* pWhich, bool bApi );
165  bool ChangeIndent( const ScMarkData& rMark, bool bIncrement, bool bApi );
166  bool AutoFormat( const ScRange& rRange, const ScMarkData* pTabMark,
167  sal_uInt16 nFormatNo, bool bApi );
168 
169  SC_DLLPUBLIC bool
170  EnterMatrix( const ScRange& rRange, const ScMarkData* pTabMark,
171  const ScTokenArray* pTokenArray,
172  const OUString& rString, bool bApi, bool bEnglish,
173  const OUString& rFormulaNmsp,
175 
176  bool TabOp( const ScRange& rRange, const ScMarkData* pTabMark,
177  const ScTabOpParam& rParam, bool bRecord, bool bApi );
178 
179  bool FillSimple( const ScRange& rRange, const ScMarkData* pTabMark,
180  FillDir eDir, bool bApi );
181  bool FillSeries( const ScRange& rRange, const ScMarkData* pTabMark,
182  FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd,
183  double fStart, double fStep, double fMax,
184  bool bApi );
185 
186  // FillAuto: rRange is change from Source-Range to Dest-Range
187  SC_DLLPUBLIC bool
188  FillAuto( ScRange& rRange, const ScMarkData* pTabMark, FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd, sal_uLong nCount, double fStep, double fMax, bool bRecord, bool bApi );
189 
190  bool FillAuto( ScRange& rRange, const ScMarkData* pTabMark,
191  FillDir eDir, sal_uLong nCount, bool bApi );
192 
193  void ResizeMatrix( const ScRange& rOldRange, const ScAddress& rNewEnd );
194 
195  SC_DLLPUBLIC bool
196  MergeCells( const ScCellMergeOption& rOption, bool bContents,
197  bool bRecord, bool bApi, bool bEmptyMergedCells = false );
198  bool UnmergeCells( const ScRange& rRange, bool bRecord, ScUndoRemoveMerge* pUndoRemoveMerge );
199  SC_DLLPUBLIC bool
200  UnmergeCells( const ScCellMergeOption& rOption, bool bRecord, ScUndoRemoveMerge* pUndoRemoveMerge );
201 
202  // takes ownership of pNewRanges, nTab = -1 for local range names
203  void SetNewRangeNames( std::unique_ptr<ScRangeName> pNewRanges, bool bModifyDoc, SCTAB nTab );
204  void ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab = -1 );
211  void ModifyAllRangeNames(const std::map<OUString, std::unique_ptr<ScRangeName>>& rRangeMap);
212 
213  bool CreateNames( const ScRange& rRange, CreateNameFlags nFlags, bool bApi, SCTAB nTab = -1 ); // -1 for global range names
214  bool InsertNameList( const ScAddress& rStartPos, bool bApi );
215 
216  void InsertAreaLink( const OUString& rFile, const OUString& rFilter,
217  const OUString& rOptions, const OUString& rSource,
218  const ScRange& rDestRange, sal_uLong nRefresh,
219  bool bFitBlock, bool bApi );
220 
225  void ReplaceConditionalFormat( sal_uLong nOldIndex, std::unique_ptr<ScConditionalFormat> pFormat, SCTAB nTab, const ScRangeList& rRanges );
226 
234 
235  void ConvertFormulaToValue( const ScRange& rRange, bool bInteraction );
236 
237 private:
238  void ProtectDocument(const ScDocProtection& rProtect);
239 };
240 
241 class ScDocFuncDirect final : public ScDocFunc
242 {
243 public:
244  ScDocFuncDirect( ScDocShell& rDocSh ) : ScDocFunc( rDocSh ) {}
245 };
246 
247 void VBA_DeleteModule( ScDocShell& rDocSh, const OUString& sModuleName );
248 
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ClearItems(const ScMarkData &rMark, const sal_uInt16 *pWhich, bool bApi)
Definition: docfunc.cxx:4084
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
bool Unprotect(SCTAB nTab, const OUString &rPassword, bool bApi)
Definition: docfunc.cxx:4026
bool CreateNames(const ScRange &rRange, CreateNameFlags nFlags, bool bApi, SCTAB nTab=-1)
Definition: docfunc.cxx:5268
SC_DLLPUBLIC bool DeleteContents(const ScMarkData &rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi)
Definition: docfunc.cxx:572
FillDir
Definition: global.hxx:305
SC_DLLPUBLIC bool FillAuto(ScRange &rRange, const ScMarkData *pTabMark, FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd, sal_uLong nCount, double fStep, double fMax, bool bRecord, bool bApi)
Definition: docfunc.cxx:4791
void NotifyDrawUndo(std::unique_ptr< SdrUndoAction >)
Definition: docfunc.cxx:109
bool SetStringCell(const ScAddress &rPos, const OUString &rStr, bool bInteraction)
Definition: docfunc.cxx:929
sheet protection state container
SC_DLLPUBLIC bool MergeCells(const ScCellMergeOption &rOption, bool bContents, bool bRecord, bool bApi, bool bEmptyMergedCells=false)
Definition: docfunc.cxx:4927
bool SetStringOrEditCell(const ScAddress &rPos, const OUString &rStr, bool bInteraction)
Definition: docfunc.cxx:1001
void SetNewRangeNames(std::unique_ptr< ScRangeName > pNewRanges, bool bModifyDoc, SCTAB nTab)
Definition: docfunc.cxx:5136
sal_uIntPtr sal_uLong
virtual ~ScDocFunc()
Definition: docfunc.hxx:72
void VBA_DeleteModule(ScDocShell &rDocSh, const OUString &sModuleName)
Definition: docfunc.cxx:3233
bool DeleteTable(SCTAB nTab, bool bRecord)
Definition: docfunc.cxx:3314
bool FillSimple(const ScRange &rRange, const ScMarkData *pTabMark, FillDir eDir, bool bApi)
Definition: docfunc.cxx:4539
SC_DLLPUBLIC bool ShowNote(const ScAddress &rPos, bool bShow)
Definition: docfunc.cxx:1281
void ProtectSheet(SCTAB nTab, const ScTableProtection &rProtect)
Definition: docfunc.cxx:3941
SC_DLLPUBLIC ScPostIt * ImportNote(const ScAddress &rPos, const OUString &rNoteText)
Definition: docfunc.cxx:1401
CreateNameFlags
Definition: scui_def.hxx:50
bool InsertCells(const ScRange &rRange, const ScMarkData *pTabMark, InsCellCmd eCmd, bool bRecord, bool bApi, bool bPartOfPaste=false)
Definition: docfunc.cxx:1729
bool SetTabBgColor(SCTAB nTab, const Color &rColor, bool bRecord, bool bApi)
Definition: docfunc.cxx:3526
void EnterListAction(TranslateId pNameResId)
Definition: docfunc.cxx:5754
DelCellCmd
Definition: global.hxx:277
void SetValueCells(const ScAddress &rPos, const std::vector< double > &aVals, bool bInteraction)
Definition: docfunc.cxx:895
void NotifyInputHandler(const ScAddress &rPos)
Definition: docfunc.cxx:1121
void CreateOneName(ScRangeName &rList, SCCOL nPosX, SCROW nPosY, SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, bool &rCancel, bool bApi)
Definition: docfunc.cxx:5203
void ProtectDocument(const ScDocProtection &rProtect)
Definition: docfunc.cxx:3973
void DetectiveCollectAllSuccs(const ScRangeList &rSrcRanges,::std::vector< ScTokenRef > &rRefTokens)
Definition: docfunc.cxx:567
void DetectiveCollectAllPreds(const ScRangeList &rSrcRanges,::std::vector< ScTokenRef > &rRefTokens)
Definition: docfunc.cxx:562
Additional class containing cell annotation data.
Definition: postit.hxx:161
bool ChangeIndent(const ScMarkData &rMark, bool bIncrement, bool bApi)
Definition: docfunc.cxx:4129
FillDateCmd
Definition: global.hxx:330
void ConvertFormulaToValue(const ScRange &rRange, bool bInteraction)
Definition: docfunc.cxx:5721
void ReplaceNote(const ScAddress &rPos, const OUString &rNoteText, const OUString *pAuthor, const OUString *pDate, bool bApi)
Definition: docfunc.cxx:1335
bool DetectiveRefresh(bool bAutomatic=false)
Definition: docfunc.cxx:465
bool DeleteCells(const ScRange &rRange, const ScMarkData *pTabMark, DelCellCmd eCmd, bool bApi)
Definition: docfunc.cxx:2264
void EndListAction()
Definition: docfunc.cxx:5763
bool SetEditCell(const ScAddress &rPos, const EditTextObject &rStr, bool bInteraction)
Definition: docfunc.cxx:966
bool SetNormalString(bool &o_rbNumFmtSet, const ScAddress &rPos, const OUString &rText, bool bApi)
Definition: docfunc.cxx:791
TransliterationFlags
bool Protect(SCTAB nTab, const OUString &rPassword)
Definition: docfunc.cxx:4002
bool AutoFormat(const ScRange &rRange, const ScMarkData *pTabMark, sal_uInt16 nFormatNo, bool bApi)
Definition: docfunc.cxx:4199
bool ApplyAttributes(const ScMarkData &rMark, const ScPatternAttr &rPattern, bool bApi)
Definition: docfunc.cxx:1419
bool SetValueCell(const ScAddress &rPos, double fVal, bool bInteraction)
Definition: docfunc.cxx:860
Parameter for data table aka multiple operations.
Definition: paramisc.hxx:45
FillCmd
Definition: global.hxx:313
bool ApplyStyle(const ScMarkData &rMark, const OUString &rStyleName, bool bApi)
Definition: docfunc.cxx:1488
sal_Int16 SCCOL
Definition: types.hxx:21
InsertDeleteFlags
Definition: global.hxx:147
SC_DLLPUBLIC bool InsertTable(SCTAB nTab, const OUString &rName, bool bRecord, bool bApi)
Definition: docfunc.cxx:3262
void PutData(const ScAddress &rPos, ScEditEngineDefaulter &rEngine, bool bApi)
Definition: docfunc.cxx:1153
void ModifyAllRangeNames(const std::map< OUString, std::unique_ptr< ScRangeName >> &rRangeMap)
Modify all range names, global scope names as well as sheet local ones, in one go.
Definition: docfunc.cxx:5182
bool DetectiveAddPred(const ScAddress &rPos)
Definition: docfunc.cxx:198
bool DetectiveAddError(const ScAddress &rPos)
Definition: docfunc.cxx:349
bool InsertPageBreak(bool bColumn, const ScAddress &rPos, bool bRecord, bool bSetModified)
Definition: docfunc.cxx:3815
ScDocShell & rDocShell
Definition: docfunc.hxx:61
void ReplaceConditionalFormat(sal_uLong nOldIndex, std::unique_ptr< ScConditionalFormat > pFormat, SCTAB nTab, const ScRangeList &rRanges)
Definition: docfunc.cxx:5597
bool TabOp(const ScRange &rRange, const ScMarkData *pTabMark, const ScTabOpParam &rParam, bool bRecord, bool bApi)
Definition: docfunc.cxx:4399
ScSizeMode
Definition: global.hxx:347
void ResizeMatrix(const ScRange &rOldRange, const ScAddress &rNewEnd)
Definition: docfunc.cxx:5466
bool RenameTable(SCTAB nTab, const OUString &rName, bool bRecord, bool bApi)
Definition: docfunc.cxx:3492
void SetTableVisible(SCTAB nTab, bool bVisible, bool bApi)
Definition: docfunc.cxx:3411
bool RemovePageBreak(bool bColumn, const ScAddress &rPos, bool bRecord, bool bSetModified)
Definition: docfunc.cxx:3878
void InsertAreaLink(const OUString &rFile, const OUString &rFilter, const OUString &rOptions, const OUString &rSource, const ScRange &rDestRange, sal_uLong nRefresh, bool bFitBlock, bool bApi)
Definition: docfunc.cxx:5508
bool DeleteCell(const ScAddress &rPos, const ScMarkData &rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi)
Definition: docfunc.cxx:665
bool UnmergeCells(const ScRange &rRange, bool bRecord, ScUndoRemoveMerge *pUndoRemoveMerge)
Definition: docfunc.cxx:5044
bool InsertNameList(const ScAddress &rStartPos, bool bApi)
Definition: docfunc.cxx:5357
SC_DLLPUBLIC bool SetWidthOrHeight(bool bWidth, const std::vector< sc::ColRowSpan > &rRanges, SCTAB nTab, ScSizeMode eMode, sal_uInt16 nSizeTwips, bool bRecord, bool bApi)
Definition: docfunc.cxx:3644
sal_Int32 SCROW
Definition: types.hxx:17
bool FillSeries(const ScRange &rRange, const ScMarkData *pTabMark, FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd, double fStart, double fStep, double fMax, bool bApi)
Definition: docfunc.cxx:4653
bool SetFormulaCell(const ScAddress &rPos, ScFormulaCell *pCell, bool bInteraction)
Below two methods take ownership of the formula cell instance(s).
Definition: docfunc.cxx:1016
void SetNoteText(const ScAddress &rPos, const OUString &rNoteText, bool bApi)
Definition: docfunc.cxx:1309
bool SetLayoutRTL(SCTAB nTab, bool bRTL)
Definition: docfunc.cxx:3461
bool DetectiveDelSucc(const ScAddress &rPos)
Definition: docfunc.cxx:310
bool SetFormulaCells(const ScAddress &rPos, std::vector< ScFormulaCell * > &rCells, bool bInteraction)
Definition: docfunc.cxx:1065
InsCellCmd
Definition: global.hxx:286
SC_DLLPUBLIC bool EnterMatrix(const ScRange &rRange, const ScMarkData *pTabMark, const ScTokenArray *pTokenArray, const OUString &rString, bool bApi, bool bEnglish, const OUString &rFormulaNmsp, const formula::FormulaGrammar::Grammar)
Definition: docfunc.cxx:4311
bool TransliterateText(const ScMarkData &rMark, TransliterationFlags nType, bool bApi)
Definition: docfunc.cxx:732
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
bool SetCellText(const ScAddress &rPos, const OUString &rText, bool bInterpret, bool bEnglish, bool bApi, const formula::FormulaGrammar::Grammar eGrammar)
Definition: docfunc.cxx:1233
bool AdjustRowHeight(const ScRange &rRange, bool bPaint, bool bApi)
Definition: docfunc.cxx:140
void SetConditionalFormatList(ScConditionalFormatList *pList, SCTAB nTab)
Sets or replaces the conditional format list of a table.
Definition: docfunc.cxx:5673
bool DetectiveAddSucc(const ScAddress &rPos)
Definition: docfunc.cxx:273
bool DetectiveDelAll(SCTAB nTab)
Definition: docfunc.cxx:425
bool MoveBlock(const ScRange &rSource, const ScAddress &rDestPos, bool bCut, bool bRecord, bool bPaint, bool bApi)
Definition: docfunc.cxx:2845
ScDocFunc(ScDocShell &rDocSh)
Definition: docfunc.hxx:70
bool DetectiveDelPred(const ScAddress &rPos)
Definition: docfunc.cxx:234
bool DetectiveMarkInvalid(SCTAB nTab)
Definition: docfunc.cxx:386
ScDocFuncDirect(ScDocShell &rDocSh)
Definition: docfunc.hxx:244
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
void ModifyRangeNames(const ScRangeName &rNewRanges, SCTAB nTab=-1)
Definition: docfunc.cxx:5131
::std::vector< ScUndoTabColorInfo > List
Definition: tabbgcolor.hxx:36
sal_Int16 SCTAB
Definition: types.hxx:22