Line data Source code
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 SC_COLUMN_HXX
21 : #define SC_COLUMN_HXX
22 :
23 : #include "markarr.hxx"
24 : #include "global.hxx"
25 : #include "address.hxx"
26 : #include "rangenam.hxx"
27 :
28 : #include <set>
29 : #include <vector>
30 :
31 : namespace editeng { class SvxBorderLine; }
32 :
33 : class Fraction;
34 : class OutputDevice;
35 : class SfxItemPoolCache;
36 : class SvtListener;
37 : class SfxPoolItem;
38 : class SfxStyleSheetBase;
39 : class SvxBoxInfoItem;
40 : class SvxBoxItem;
41 :
42 : class ScAttrIterator;
43 : class ScAttrArray;
44 : struct ScAttrEntry;
45 : class ScBaseCell;
46 : class ScDocument;
47 : class ScEditDataArray;
48 : class ScFormulaCell;
49 : class ScMarkData;
50 : class ScPatternAttr;
51 : class ScStyleSheet;
52 : class SvtBroadcaster;
53 : class ScTypedStrData;
54 : class ScProgress;
55 : struct ScFunctionData;
56 : struct ScLineFlags;
57 : struct ScMergePatternState;
58 : class ScFlatBoolRowSegments;
59 : struct ScSetStringParam;
60 : struct ScColWidthParam;
61 :
62 : struct ScNeededSizeOptions
63 : {
64 : const ScPatternAttr* pPattern;
65 : bool bFormula;
66 : bool bSkipMerged;
67 : bool bGetFont;
68 : bool bTotalSize;
69 :
70 97 : ScNeededSizeOptions()
71 : {
72 97 : pPattern = NULL;
73 97 : bFormula = false;
74 97 : bSkipMerged = true;
75 97 : bGetFont = true;
76 97 : bTotalSize = false;
77 97 : }
78 : };
79 :
80 : struct ColEntry
81 : {
82 : SCROW nRow;
83 : ScBaseCell* pCell;
84 : };
85 :
86 :
87 : class ScColumn
88 : {
89 : private:
90 : SCCOL nCol;
91 : SCTAB nTab;
92 :
93 : std::vector<ColEntry> maItems;
94 :
95 : ScAttrArray* pAttrArray;
96 : ScDocument* pDocument;
97 :
98 : friend class ScDocument; // for FillInfo
99 : friend class ScDocumentIterator;
100 : friend class ScValueIterator;
101 : friend class ScHorizontalValueIterator;
102 : friend class ScDBQueryDataIterator;
103 : friend class ScColumnIterator;
104 : friend class ScQueryCellIterator;
105 : friend class ScMarkedDataIter;
106 : friend class ScCellIterator;
107 : friend class ScHorizontalCellIterator;
108 : friend class ScHorizontalAttrIterator;
109 :
110 : public:
111 : ScColumn();
112 : ~ScColumn();
113 :
114 : void Init(SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc);
115 :
116 : bool Search( SCROW nRow, SCSIZE& nIndex ) const;
117 : ScBaseCell* GetCell( SCROW nRow ) const;
118 : void Insert( SCROW nRow, ScBaseCell* pCell );
119 : void Insert( SCROW nRow, sal_uInt32 nFormatIndex, ScBaseCell* pCell );
120 : void Append( SCROW nRow, ScBaseCell* pCell );
121 : void Delete( SCROW nRow );
122 : void DeleteAtIndex( SCSIZE nIndex );
123 : void FreeAll();
124 : void Resize( SCSIZE nSize );
125 : void SwapRow( SCROW nRow1, SCROW nRow2 );
126 : void SwapCell( SCROW nRow, ScColumn& rCol);
127 :
128 : bool HasAttrib( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const;
129 : bool HasAttribSelection( const ScMarkData& rMark, sal_uInt16 nMask ) const;
130 : bool ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow,
131 : SCCOL& rPaintCol, SCROW& rPaintRow,
132 : bool bRefresh );
133 :
134 : bool IsEmptyVisData() const; // without Broadcaster
135 : bool IsEmptyData() const;
136 : bool IsEmptyAttr() const;
137 : bool IsEmpty() const;
138 :
139 : // data only:
140 : bool IsEmptyBlock(SCROW nStartRow, SCROW nEndRow) const;
141 : SCSIZE GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirection eDir ) const;
142 : bool HasDataAt(SCROW nRow) const;
143 : bool HasVisibleDataAt(SCROW nRow) const;
144 : SCROW GetFirstDataPos() const;
145 : SCROW GetLastDataPos() const;
146 : SCROW GetLastVisDataPos() const; // without Broadcaster
147 : SCROW GetFirstVisDataPos() const;
148 : bool GetPrevDataPos(SCROW& rRow) const;
149 : bool GetNextDataPos(SCROW& rRow) const;
150 : void FindDataAreaPos(SCROW& rRow, bool bDown) const; // (without Broadcaster)
151 : void FindUsed( SCROW nStartRow, SCROW nEndRow, bool* pUsed ) const;
152 :
153 : SCSIZE VisibleCount( SCROW nStartRow, SCROW nEndRow ) const;
154 : sal_uInt16 GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const;
155 : bool HasSelectionMatrixFragment(const ScMarkData& rMark) const;
156 :
157 : bool GetFirstVisibleAttr( SCROW& rFirstRow ) const;
158 : bool GetLastVisibleAttr( SCROW& rLastRow, bool bFullFormattedArea = false ) const;
159 : bool HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const;
160 : bool IsVisibleAttrEqual( const ScColumn& rCol, SCROW nStartRow = 0,
161 : SCROW nEndRow = MAXROW ) const;
162 : bool IsAllAttrEqual( const ScColumn& rCol, SCROW nStartRow, SCROW nEndRow ) const;
163 :
164 : bool TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
165 : bool TestInsertRow( SCSIZE nSize ) const;
166 : void InsertRow( SCROW nStartRow, SCSIZE nSize );
167 : void DeleteRow( SCROW nStartRow, SCSIZE nSize );
168 : void DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag );
169 : void DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag );
170 : void CopyToClip(SCROW nRow1, SCROW nRow2, ScColumn& rColumn, bool bKeepScenarioFlags) const;
171 : void CopyFromClip(SCROW nRow1, SCROW nRow2, long nDy,
172 : sal_uInt16 nInsFlag, bool bAsLink, bool bSkipAttrForEmpty, ScColumn& rColumn);
173 : void StartListeningInArea( SCROW nRow1, SCROW nRow2 );
174 : void BroadcastInArea( SCROW nRow1, SCROW nRow2 );
175 :
176 : void RemoveEditAttribs( SCROW nStartRow, SCROW nEndRow );
177 :
178 : // Selection (?) of this document
179 : void MixMarked( const ScMarkData& rMark, sal_uInt16 nFunction,
180 : bool bSkipEmpty, ScColumn& rSrcCol );
181 : void MixData( SCROW nRow1, SCROW nRow2, sal_uInt16 nFunction, bool bSkipEmpty,
182 : ScColumn& rSrcCol );
183 :
184 : ScFormulaCell* CreateRefCell( ScDocument* pDestDoc, const ScAddress& rDestPos,
185 : SCSIZE nIndex, sal_uInt16 nFlags ) const;
186 :
187 : ScAttrIterator* CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const;
188 :
189 :
190 67 : SCCOL GetCol() const { return nCol; }
191 :
192 : // UpdateSelectionFunction: multi-select
193 : void UpdateSelectionFunction(
194 : const ScMarkData& rMark, ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows,
195 : bool bDoExclude, SCROW nExStartRow, SCROW nExEndRow ) const;
196 :
197 : void UpdateAreaFunction(
198 : ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows, SCROW nStartRow, SCROW nEndRow) const;
199 :
200 : void CopyToColumn(
201 : SCROW nRow1, SCROW nRow2, sal_uInt16 nFlags, bool bMarked,
202 : ScColumn& rColumn, const ScMarkData* pMarkData = NULL, bool bAsLink = false) const;
203 :
204 : void UndoToColumn(
205 : SCROW nRow1, SCROW nRow2, sal_uInt16 nFlags, bool bMarked,
206 : ScColumn& rColumn, const ScMarkData* pMarkData = NULL) const;
207 :
208 : void CopyScenarioFrom( const ScColumn& rSrcCol );
209 : void CopyScenarioTo( ScColumn& rDestCol ) const;
210 : bool TestCopyScenarioTo( const ScColumn& rDestCol ) const;
211 : void MarkScenarioIn( ScMarkData& rDestMark ) const;
212 :
213 : void CopyUpdated( const ScColumn& rPosCol, ScColumn& rDestCol ) const;
214 :
215 : void SwapCol(ScColumn& rCol);
216 : void MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol);
217 :
218 :
219 : bool HasEditCells(SCROW nStartRow, SCROW nEndRow, SCROW& rFirst) const;
220 :
221 : // TRUE = format for numbers is set
222 : bool SetString(
223 : SCROW nRow, SCTAB nTab, const String& rString, formula::FormulaGrammar::AddressConvention eConv,
224 : ScSetStringParam* pParam = NULL );
225 : void SetValue( SCROW nRow, const double& rVal);
226 : void SetError( SCROW nRow, const sal_uInt16 nError);
227 :
228 : void GetString( SCROW nRow, rtl::OUString& rString ) const;
229 : void GetInputString( SCROW nRow, rtl::OUString& rString ) const;
230 : double GetValue( SCROW nRow ) const;
231 : void GetFormula( SCROW nRow, rtl::OUString& rFormula ) const;
232 : CellType GetCellType( SCROW nRow ) const;
233 : SCSIZE GetCellCount() const;
234 : sal_uInt32 GetWeightedCount() const;
235 : sal_uInt32 GetCodeCount() const; // RPN-Code in formulas
236 : sal_uInt16 GetErrCode( SCROW nRow ) const;
237 :
238 : bool HasStringData( SCROW nRow ) const;
239 : bool HasValueData( SCROW nRow ) const;
240 : bool HasStringCells( SCROW nStartRow, SCROW nEndRow ) const;
241 :
242 : void SetDirty();
243 : void SetDirty( const ScRange& );
244 : void SetDirtyVar();
245 : void SetDirtyAfterLoad();
246 : void SetTableOpDirty( const ScRange& );
247 : void CalcAll();
248 : void CalcAfterLoad();
249 : void CompileAll();
250 : void CompileXML( ScProgress& rProgress );
251 :
252 : void ResetChanged( SCROW nStartRow, SCROW nEndRow );
253 :
254 : bool UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
255 : SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
256 : SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
257 : ScDocument* pUndoDoc = NULL );
258 : void UpdateInsertTab(SCTAB nInsPos, SCTAB nNewSheets = 1);
259 : void UpdateInsertTabOnlyCells(SCTAB nInsPos, SCTAB nNewSheets = 1);
260 : void UpdateDeleteTab(SCTAB nDelPos, bool bIsMove, ScColumn* pRefUndo = NULL, SCTAB nSheets = 1);
261 : void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
262 : void UpdateCompile( bool bForceIfNameInUse = false );
263 : void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
264 : ScDocument* pUndoDoc );
265 : void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
266 :
267 : void SetTabNo(SCTAB nNewTab);
268 : void FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, std::set<sal_uInt16>& rIndexes) const;
269 :
270 : const SfxPoolItem* GetAttr( SCROW nRow, sal_uInt16 nWhich ) const;
271 : const ScPatternAttr* GetPattern( SCROW nRow ) const;
272 : const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const;
273 :
274 : sal_uInt32 GetNumberFormat( SCROW nRow ) const;
275 : sal_uInt32 GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const;
276 :
277 : void MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, bool bDeep ) const;
278 : void MergePatternArea( ScMergePatternState& rState, SCROW nRow1, SCROW nRow2, bool bDeep ) const;
279 : void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner,
280 : ScLineFlags& rFlags,
281 : SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight ) const;
282 : void ApplyBlockFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner,
283 : SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight );
284 :
285 : void ApplyAttr( SCROW nRow, const SfxPoolItem& rAttr );
286 : void ApplyPattern( SCROW nRow, const ScPatternAttr& rPatAttr );
287 : void ApplyPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& rPatAttr,
288 : ScEditDataArray* pDataArray = NULL );
289 : bool SetAttrEntries(ScAttrEntry* pData, SCSIZE nSize);
290 : void SetPattern( SCROW nRow, const ScPatternAttr& rPatAttr, bool bPutToPool = false );
291 : void SetPatternArea( SCROW nStartRow, SCROW nEndRow,
292 : const ScPatternAttr& rPatAttr, bool bPutToPool = false );
293 : void ApplyPatternIfNumberformatIncompatible( const ScRange& rRange,
294 : const ScPatternAttr& rPattern, short nNewType );
295 :
296 : void ApplyStyle( SCROW nRow, const ScStyleSheet& rStyle );
297 : void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle );
298 : void ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark);
299 : void ApplySelectionLineStyle( const ScMarkData& rMark,
300 : const ::editeng::SvxBorderLine* pLine, bool bColorOnly );
301 : void AddCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
302 : void RemoveCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
303 :
304 : const ScStyleSheet* GetStyle( SCROW nRow ) const;
305 : const ScStyleSheet* GetSelectionStyle( const ScMarkData& rMark, bool& rFound ) const;
306 : const ScStyleSheet* GetAreaStyle( bool& rFound, SCROW nRow1, SCROW nRow2 ) const;
307 :
308 : void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset );
309 : bool IsStyleSheetUsed( const ScStyleSheet& rStyle, bool bGatherAllStyles ) const;
310 :
311 : /// May return -1 if not found
312 : SCsROW SearchStyle(
313 : SCsROW nRow, const ScStyleSheet* pSearchStyle, bool bUp, bool bInSelection,
314 : const ScMarkData& rMark) const;
315 :
316 : bool SearchStyleRange(
317 : SCsROW& rRow, SCsROW& rEndRow, const ScStyleSheet* pSearchStyle, bool bUp,
318 : bool bInSelection, const ScMarkData& rMark) const;
319 :
320 : bool ApplyFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags );
321 : bool RemoveFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags );
322 : void ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich );
323 :
324 : void RemoveProtected( SCROW nStartRow, SCROW nEndRow );
325 :
326 : SCsROW ApplySelectionCache( SfxItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray = NULL );
327 : void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark );
328 :
329 : void ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark );
330 : void ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark );
331 :
332 : long GetNeededSize(
333 : SCROW nRow, OutputDevice* pDev, double nPPTX, double nPPTY,
334 : const Fraction& rZoomX, const Fraction& rZoomY,
335 : bool bWidth, const ScNeededSizeOptions& rOptions) const;
336 :
337 : sal_uInt16 GetOptimalColWidth(
338 : OutputDevice* pDev, double nPPTX, double nPPTY,
339 : const Fraction& rZoomX, const Fraction& rZoomY,
340 : bool bFormula, sal_uInt16 nOldWidth, const ScMarkData* pMarkData, const ScColWidthParam* pParam) const;
341 :
342 : void GetOptimalHeight(
343 : SCROW nStartRow, SCROW nEndRow, sal_uInt16* pHeight, OutputDevice* pDev,
344 : double nPPTX, double nPPTY, const Fraction& rZoomX, const Fraction& rZoomY,
345 : bool bShrink, sal_uInt16 nMinHeight, SCROW nMinStart) const;
346 : public:
347 :
348 : /// Including current, may return -1
349 : SCsROW GetNextUnprotected( SCROW nRow, bool bUp ) const;
350 :
351 : void GetFilterEntries(SCROW nStartRow, SCROW nEndRow, std::vector<ScTypedStrData>& rStrings, bool& rHasDates);
352 : bool GetDataEntries(SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit);
353 :
354 : void UpdateInsertTabAbs(SCTAB nNewPos);
355 : bool TestTabRefAbs(SCTAB nTable) const;
356 : bool GetNextSpellingCell(SCROW& nRow, bool bInSel, const ScMarkData& rData) const;
357 :
358 : void RemoveAutoSpellObj();
359 :
360 : void StartListening( SvtListener& rLst, SCROW nRow );
361 : void EndListening( SvtListener& rLst, SCROW nRow );
362 : void MoveListeners( SvtBroadcaster& rSource, SCROW nDestRow );
363 : void StartAllListeners();
364 : void StartNeededListeners(); // only for cells where NeedsListening()==true
365 : void SetRelNameDirty();
366 :
367 : void CompileDBFormula();
368 : void CompileDBFormula( bool bCreateFormulaString );
369 : void CompileNameFormula( bool bCreateFormulaString );
370 : void CompileColRowNameFormula();
371 :
372 : sal_Int32 GetMaxStringLen( SCROW nRowStart, SCROW nRowEnd, CharSet eCharSet ) const;
373 : xub_StrLen GetMaxNumberStringLen( sal_uInt16& nPrecision,
374 : SCROW nRowStart, SCROW nRowEnd ) const;
375 :
376 : private:
377 : ScBaseCell* CloneCell(SCSIZE nIndex, sal_uInt16 nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos) const;
378 :
379 : SCROW FindNextVisibleRowWithContent(SCROW nRow, bool bForward) const;
380 : SCROW FindNextVisibleRow(SCROW nRow, bool bForward) const;
381 : };
382 :
383 :
384 : class ScColumnIterator // walk through all data of a area/range
385 : {
386 : const ScColumn* pColumn;
387 : SCSIZE nPos;
388 : SCROW nTop;
389 : SCROW nBottom;
390 : public:
391 : ScColumnIterator( const ScColumn* pCol, SCROW nStart=0, SCROW nEnd=MAXROW );
392 : ~ScColumnIterator();
393 :
394 : bool Next( SCROW& rRow, ScBaseCell*& rpCell );
395 : SCSIZE GetIndex() const;
396 : };
397 :
398 :
399 : class ScMarkedDataIter // walk through data in a selected area/range
400 : {
401 : const ScColumn* pColumn;
402 : SCSIZE nPos;
403 : ScMarkArrayIter* pMarkIter;
404 : SCROW nTop;
405 : SCROW nBottom;
406 : bool bNext;
407 : bool bAll;
408 :
409 : public:
410 : ScMarkedDataIter( const ScColumn* pCol, const ScMarkData* pMarkData,
411 : bool bAllIfNone = false );
412 : ~ScMarkedDataIter();
413 :
414 : bool Next( SCSIZE& rIndex );
415 : };
416 :
417 :
418 : #endif
419 :
420 :
421 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|