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