Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sc / inc / column.hxx
blob930cabab81a1bdb7a9940660c1e47e29db462417
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_COLUMN_HXX
21 #define SC_COLUMN_HXX
23 #include "markarr.hxx"
24 #include "global.hxx"
25 #include "address.hxx"
26 #include "rangenam.hxx"
28 #include <set>
29 #include <vector>
31 namespace editeng { class SvxBorderLine; }
33 class Fraction;
34 class OutputDevice;
35 class SfxItemPoolCache;
36 class SvtListener;
37 class SfxPoolItem;
38 class SfxStyleSheetBase;
39 class SvxBoxInfoItem;
40 class SvxBoxItem;
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;
62 struct ScNeededSizeOptions
64 const ScPatternAttr* pPattern;
65 bool bFormula;
66 bool bSkipMerged;
67 bool bGetFont;
68 bool bTotalSize;
70 ScNeededSizeOptions()
72 pPattern = NULL;
73 bFormula = false;
74 bSkipMerged = true;
75 bGetFont = true;
76 bTotalSize = false;
80 struct ColEntry
82 SCROW nRow;
83 ScBaseCell* pCell;
87 class ScColumn
89 private:
90 SCCOL nCol;
91 SCTAB nTab;
93 std::vector<ColEntry> maItems;
95 ScAttrArray* pAttrArray;
96 ScDocument* pDocument;
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;
110 public:
111 ScColumn();
112 ~ScColumn();
114 void Init(SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc);
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);
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 );
134 bool IsEmptyVisData() const; // without Broadcaster
135 bool IsEmptyData() const;
136 bool IsEmptyAttr() const;
137 bool IsEmpty() const;
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;
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;
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;
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 CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol);
172 void CopyFromClip(SCROW nRow1, SCROW nRow2, long nDy,
173 sal_uInt16 nInsFlag, bool bAsLink, bool bSkipAttrForEmpty, ScColumn& rColumn);
174 void StartListeningInArea( SCROW nRow1, SCROW nRow2 );
175 void BroadcastInArea( SCROW nRow1, SCROW nRow2 );
177 void RemoveEditAttribs( SCROW nStartRow, SCROW nEndRow );
179 // Selection (?) of this document
180 void MixMarked( const ScMarkData& rMark, sal_uInt16 nFunction,
181 bool bSkipEmpty, ScColumn& rSrcCol );
182 void MixData( SCROW nRow1, SCROW nRow2, sal_uInt16 nFunction, bool bSkipEmpty,
183 ScColumn& rSrcCol );
185 ScFormulaCell* CreateRefCell( ScDocument* pDestDoc, const ScAddress& rDestPos,
186 SCSIZE nIndex, sal_uInt16 nFlags ) const;
188 ScAttrIterator* CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const;
191 SCCOL GetCol() const { return nCol; }
193 // UpdateSelectionFunction: multi-select
194 void UpdateSelectionFunction(
195 const ScMarkData& rMark, ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows,
196 bool bDoExclude, SCROW nExStartRow, SCROW nExEndRow ) const;
198 void UpdateAreaFunction(
199 ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows, SCROW nStartRow, SCROW nEndRow) const;
201 void CopyToColumn(
202 SCROW nRow1, SCROW nRow2, sal_uInt16 nFlags, bool bMarked,
203 ScColumn& rColumn, const ScMarkData* pMarkData = NULL, bool bAsLink = false) const;
205 void UndoToColumn(
206 SCROW nRow1, SCROW nRow2, sal_uInt16 nFlags, bool bMarked,
207 ScColumn& rColumn, const ScMarkData* pMarkData = NULL) const;
209 void CopyScenarioFrom( const ScColumn& rSrcCol );
210 void CopyScenarioTo( ScColumn& rDestCol ) const;
211 bool TestCopyScenarioTo( const ScColumn& rDestCol ) const;
212 void MarkScenarioIn( ScMarkData& rDestMark ) const;
214 void CopyUpdated( const ScColumn& rPosCol, ScColumn& rDestCol ) const;
216 void SwapCol(ScColumn& rCol);
217 void MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol);
220 bool HasEditCells(SCROW nStartRow, SCROW nEndRow, SCROW& rFirst) const;
222 // TRUE = format for numbers is set
223 bool SetString(
224 SCROW nRow, SCTAB nTab, const String& rString, formula::FormulaGrammar::AddressConvention eConv,
225 ScSetStringParam* pParam = NULL );
226 void SetValue( SCROW nRow, const double& rVal);
227 void SetError( SCROW nRow, const sal_uInt16 nError);
229 void GetString( SCROW nRow, rtl::OUString& rString ) const;
230 void GetInputString( SCROW nRow, rtl::OUString& rString ) const;
231 double GetValue( SCROW nRow ) const;
232 void GetFormula( SCROW nRow, rtl::OUString& rFormula ) const;
233 CellType GetCellType( SCROW nRow ) const;
234 SCSIZE GetCellCount() const;
235 sal_uInt32 GetWeightedCount() const;
236 sal_uInt32 GetCodeCount() const; // RPN-Code in formulas
237 sal_uInt16 GetErrCode( SCROW nRow ) const;
239 bool HasStringData( SCROW nRow ) const;
240 bool HasValueData( SCROW nRow ) const;
241 bool HasStringCells( SCROW nStartRow, SCROW nEndRow ) const;
243 void SetDirty();
244 void SetDirty( const ScRange& );
245 void SetDirtyVar();
246 void SetDirtyAfterLoad();
247 void SetTableOpDirty( const ScRange& );
248 void CalcAll();
249 void CalcAfterLoad();
250 void CompileAll();
251 void CompileXML( ScProgress& rProgress );
253 bool CompileErrorCells(sal_uInt16 nErrCode);
255 void ResetChanged( SCROW nStartRow, SCROW nEndRow );
257 bool UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
258 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
259 SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
260 ScDocument* pUndoDoc = NULL );
261 void UpdateInsertTab(SCTAB nInsPos, SCTAB nNewSheets = 1);
262 void UpdateInsertTabOnlyCells(SCTAB nInsPos, SCTAB nNewSheets = 1);
263 void UpdateDeleteTab(SCTAB nDelPos, bool bIsMove, ScColumn* pRefUndo = NULL, SCTAB nSheets = 1);
264 void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
265 void UpdateCompile( bool bForceIfNameInUse = false );
266 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
267 ScDocument* pUndoDoc );
268 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
270 void SetTabNo(SCTAB nNewTab);
271 void FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, std::set<sal_uInt16>& rIndexes) const;
273 const SfxPoolItem* GetAttr( SCROW nRow, sal_uInt16 nWhich ) const;
274 const ScPatternAttr* GetPattern( SCROW nRow ) const;
275 const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const;
277 sal_uInt32 GetNumberFormat( SCROW nRow ) const;
278 sal_uInt32 GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const;
280 void MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, bool bDeep ) const;
281 void MergePatternArea( ScMergePatternState& rState, SCROW nRow1, SCROW nRow2, bool bDeep ) const;
282 void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner,
283 ScLineFlags& rFlags,
284 SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight ) const;
285 void ApplyBlockFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner,
286 SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight );
288 void ApplyAttr( SCROW nRow, const SfxPoolItem& rAttr );
289 void ApplyPattern( SCROW nRow, const ScPatternAttr& rPatAttr );
290 void ApplyPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& rPatAttr,
291 ScEditDataArray* pDataArray = NULL );
292 bool SetAttrEntries(ScAttrEntry* pData, SCSIZE nSize);
293 void SetPattern( SCROW nRow, const ScPatternAttr& rPatAttr, bool bPutToPool = false );
294 void SetPatternArea( SCROW nStartRow, SCROW nEndRow,
295 const ScPatternAttr& rPatAttr, bool bPutToPool = false );
296 void ApplyPatternIfNumberformatIncompatible( const ScRange& rRange,
297 const ScPatternAttr& rPattern, short nNewType );
299 void ApplyStyle( SCROW nRow, const ScStyleSheet& rStyle );
300 void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle );
301 void ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark);
302 void ApplySelectionLineStyle( const ScMarkData& rMark,
303 const ::editeng::SvxBorderLine* pLine, bool bColorOnly );
304 void AddCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
305 void RemoveCondFormat(SCROW nStartRow, SCROW nEndRow, sal_uInt32 nIndex );
307 const ScStyleSheet* GetStyle( SCROW nRow ) const;
308 const ScStyleSheet* GetSelectionStyle( const ScMarkData& rMark, bool& rFound ) const;
309 const ScStyleSheet* GetAreaStyle( bool& rFound, SCROW nRow1, SCROW nRow2 ) const;
311 void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset );
312 bool IsStyleSheetUsed( const ScStyleSheet& rStyle, bool bGatherAllStyles ) const;
314 /// May return -1 if not found
315 SCsROW SearchStyle(
316 SCsROW nRow, const ScStyleSheet* pSearchStyle, bool bUp, bool bInSelection,
317 const ScMarkData& rMark) const;
319 bool SearchStyleRange(
320 SCsROW& rRow, SCsROW& rEndRow, const ScStyleSheet* pSearchStyle, bool bUp,
321 bool bInSelection, const ScMarkData& rMark) const;
323 bool ApplyFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags );
324 bool RemoveFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags );
325 void ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich );
327 void RemoveProtected( SCROW nStartRow, SCROW nEndRow );
329 SCsROW ApplySelectionCache( SfxItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray = NULL );
330 void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark );
332 void ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark );
333 void ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark );
335 long GetNeededSize(
336 SCROW nRow, OutputDevice* pDev, double nPPTX, double nPPTY,
337 const Fraction& rZoomX, const Fraction& rZoomY,
338 bool bWidth, const ScNeededSizeOptions& rOptions) const;
340 sal_uInt16 GetOptimalColWidth(
341 OutputDevice* pDev, double nPPTX, double nPPTY,
342 const Fraction& rZoomX, const Fraction& rZoomY,
343 bool bFormula, sal_uInt16 nOldWidth, const ScMarkData* pMarkData, const ScColWidthParam* pParam) const;
345 void GetOptimalHeight(
346 SCROW nStartRow, SCROW nEndRow, sal_uInt16* pHeight, OutputDevice* pDev,
347 double nPPTX, double nPPTY, const Fraction& rZoomX, const Fraction& rZoomY,
348 bool bShrink, sal_uInt16 nMinHeight, SCROW nMinStart) const;
349 public:
351 /// Including current, may return -1
352 SCsROW GetNextUnprotected( SCROW nRow, bool bUp ) const;
354 void GetFilterEntries(SCROW nStartRow, SCROW nEndRow, std::vector<ScTypedStrData>& rStrings, bool& rHasDates);
355 bool GetDataEntries(SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit);
357 void UpdateInsertTabAbs(SCTAB nNewPos);
358 bool TestTabRefAbs(SCTAB nTable) const;
359 bool GetNextSpellingCell(SCROW& nRow, bool bInSel, const ScMarkData& rData) const;
361 void RemoveAutoSpellObj();
363 void StartListening( SvtListener& rLst, SCROW nRow );
364 void EndListening( SvtListener& rLst, SCROW nRow );
365 void MoveListeners( SvtBroadcaster& rSource, SCROW nDestRow );
366 void StartAllListeners();
367 void StartNeededListeners(); // only for cells where NeedsListening()==true
368 void SetRelNameDirty();
370 void CompileDBFormula();
371 void CompileDBFormula( bool bCreateFormulaString );
372 void CompileNameFormula( bool bCreateFormulaString );
373 void CompileColRowNameFormula();
375 sal_Int32 GetMaxStringLen( SCROW nRowStart, SCROW nRowEnd, CharSet eCharSet ) const;
376 xub_StrLen GetMaxNumberStringLen( sal_uInt16& nPrecision,
377 SCROW nRowStart, SCROW nRowEnd ) const;
379 private:
380 ScBaseCell* CloneCell(SCSIZE nIndex, sal_uInt16 nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos) const;
382 SCROW FindNextVisibleRowWithContent(SCROW nRow, bool bForward) const;
383 SCROW FindNextVisibleRow(SCROW nRow, bool bForward) const;
387 class ScColumnIterator // walk through all data of a area/range
389 const ScColumn* pColumn;
390 SCSIZE nPos;
391 SCROW nTop;
392 SCROW nBottom;
393 public:
394 ScColumnIterator( const ScColumn* pCol, SCROW nStart=0, SCROW nEnd=MAXROW );
395 ~ScColumnIterator();
397 bool Next( SCROW& rRow, ScBaseCell*& rpCell );
398 SCSIZE GetIndex() const;
402 class ScMarkedDataIter // walk through data in a selected area/range
404 const ScColumn* pColumn;
405 SCSIZE nPos;
406 ScMarkArrayIter* pMarkIter;
407 SCROW nTop;
408 SCROW nBottom;
409 bool bNext;
410 bool bAll;
412 public:
413 ScMarkedDataIter( const ScColumn* pCol, const ScMarkData* pMarkData,
414 bool bAllIfNone = false );
415 ~ScMarkedDataIter();
417 bool Next( SCSIZE& rIndex );
421 #endif
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */