sync master with lastest vba changes
[ooovba.git] / sc / inc / column.hxx
blob61286b605c4b9b6dd93d000f87b2237ef5832ef1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: column.hxx,v $
10 * $Revision: 1.21.128.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_COLUMN_HXX
32 #define SC_COLUMN_HXX
34 #include "markarr.hxx"
35 #include "global.hxx"
36 #include "compressedarray.hxx"
37 #include "address.hxx"
38 #include "rangenam.hxx"
39 #include <tools/solar.h>
41 #include <set>
43 class Fraction;
44 class OutputDevice;
45 class Rectangle;
46 class SfxBroadcaster;
47 class SfxItemPoolCache;
48 class SfxItemSet;
49 class SvtListener;
50 class SfxPoolItem;
51 class SfxStyleSheetBase;
52 class SvxBorderLine;
53 class SvxBoxInfoItem;
54 class SvxBoxItem;
56 class ScAttrIterator;
57 class ScAttrArray;
58 class ScBaseCell;
59 class ScDocument;
60 class ScEditDataArray;
61 class ScFormulaCell;
62 class ScMarkData;
63 class ScMultipleReadHeader;
64 class ScMultipleWriteHeader;
65 class ScPatternAttr;
66 class ScStyleSheet;
67 class SvtBroadcaster;
68 class TypedScStrCollection;
69 class ScProgress;
70 class ScPostIt;
71 struct ScFunctionData;
72 struct ScLineFlags;
73 struct ScMergePatternState;
74 class ScFlatBoolRowSegments;
76 #define COLUMN_DELTA 4
79 struct ScNeededSizeOptions
81 const ScPatternAttr* pPattern;
82 BOOL bFormula;
83 BOOL bSkipMerged;
84 BOOL bGetFont;
85 BOOL bTotalSize;
87 ScNeededSizeOptions()
89 pPattern = NULL;
90 bFormula = FALSE;
91 bSkipMerged = TRUE;
92 bGetFont = TRUE;
93 bTotalSize = FALSE;
97 struct ColEntry
99 SCROW nRow;
100 ScBaseCell* pCell;
104 class ScIndexMap;
106 class ScColumn
108 private:
109 SCCOL nCol;
110 SCTAB nTab;
112 SCSIZE nCount;
113 SCSIZE nLimit;
114 ColEntry* pItems;
116 ScAttrArray* pAttrArray;
117 ScDocument* pDocument;
119 friend class ScDocument; // fuer FillInfo
120 friend class ScDocumentIterator;
121 friend class ScValueIterator;
122 friend class ScQueryValueIterator;
123 friend class ScColumnIterator;
124 friend class ScQueryCellIterator;
125 friend class ScMarkedDataIter;
126 friend class ScCellIterator;
127 friend class ScHorizontalCellIterator;
128 friend class ScHorizontalAttrIterator;
130 public:
131 static BOOL bDoubleAlloc; // fuer Import: Groesse beim Allozieren verdoppeln
133 public:
134 ScColumn();
135 ~ScColumn();
137 void Init(SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc);
139 BOOL Search( SCROW nRow, SCSIZE& nIndex ) const;
140 ScBaseCell* GetCell( SCROW nRow ) const;
141 void Insert( SCROW nRow, ScBaseCell* pCell );
142 void Insert( SCROW nRow, ULONG nFormatIndex, ScBaseCell* pCell );
143 void Append( SCROW nRow, ScBaseCell* pCell );
144 void Delete( SCROW nRow );
145 void DeleteAtIndex( SCSIZE nIndex );
146 void FreeAll();
147 void Resize( SCSIZE nSize );
148 void SwapRow( SCROW nRow1, SCROW nRow2 );
149 void SwapCell( SCROW nRow, ScColumn& rCol);
151 BOOL HasLines( SCROW nRow1, SCROW nRow2, Rectangle& rSizes,
152 BOOL bLeft, BOOL bRight ) const;
153 BOOL HasAttrib( SCROW nRow1, SCROW nRow2, USHORT nMask ) const;
154 BOOL HasAttribSelection( const ScMarkData& rMark, USHORT nMask ) const;
155 BOOL ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow,
156 SCCOL& rPaintCol, SCROW& rPaintRow,
157 BOOL bRefresh, BOOL bAttrs );
159 BOOL IsEmptyVisData(BOOL bNotes) const; // ohne Broadcaster
160 BOOL IsEmptyData() const;
161 BOOL IsEmptyAttr() const;
162 BOOL IsEmpty() const;
164 // nur Daten:
165 BOOL IsEmptyBlock(SCROW nStartRow, SCROW nEndRow, bool bIgnoreNotes = false) const;
166 SCSIZE GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirection eDir ) const;
167 BOOL HasDataAt(SCROW nRow) const;
168 BOOL HasVisibleDataAt(SCROW nRow) const;
169 SCROW GetFirstDataPos() const;
170 SCROW GetLastDataPos() const;
171 SCROW GetLastVisDataPos(BOOL bNotes) const; // ohne Broadcaster
172 SCROW GetFirstVisDataPos(BOOL bNotes) const;
173 BOOL GetPrevDataPos(SCROW& rRow) const;
174 BOOL GetNextDataPos(SCROW& rRow) const;
175 void FindDataAreaPos(SCROW& rRow, long nMovY) const; // (ohne Broadcaster)
176 void FindUsed( SCROW nStartRow, SCROW nEndRow, BOOL* pUsed ) const;
178 SCSIZE VisibleCount( SCROW nStartRow, SCROW nEndRow ) const;
180 USHORT GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, USHORT nMask ) const;
181 BOOL HasSelectionMatrixFragment(const ScMarkData& rMark) const;
183 BOOL GetFirstVisibleAttr( SCROW& rFirstRow ) const;
184 BOOL GetLastVisibleAttr( SCROW& rLastRow ) const;
185 BOOL HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const;
186 BOOL IsVisibleAttrEqual( const ScColumn& rCol, SCROW nStartRow = 0,
187 SCROW nEndRow = MAXROW ) const;
188 BOOL IsAllAttrEqual( const ScColumn& rCol, SCROW nStartRow, SCROW nEndRow ) const;
190 BOOL TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
191 BOOL TestInsertRow( SCSIZE nSize ) const;
192 void InsertRow( SCROW nStartRow, SCSIZE nSize );
193 void DeleteRow( SCROW nStartRow, SCSIZE nSize );
194 void DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, USHORT nDelFlag );
195 void DeleteArea(SCROW nStartRow, SCROW nEndRow, USHORT nDelFlag );
196 void CopyToClip(SCROW nRow1, SCROW nRow2, ScColumn& rColumn, BOOL bKeepScenarioFlags, BOOL bCloneNoteCaptions);
197 void CopyFromClip(SCROW nRow1, SCROW nRow2, long nDy,
198 USHORT nInsFlag, BOOL bAsLink, BOOL bSkipAttrForEmpty, ScColumn& rColumn);
199 void StartListeningInArea( SCROW nRow1, SCROW nRow2 );
200 void BroadcastInArea( SCROW nRow1, SCROW nRow2 );
202 void RemoveEditAttribs( SCROW nStartRow, SCROW nEndRow );
204 // Markierung von diesem Dokument
205 void MixMarked( const ScMarkData& rMark, USHORT nFunction,
206 BOOL bSkipEmpty, ScColumn& rSrcCol );
207 void MixData( SCROW nRow1, SCROW nRow2, USHORT nFunction, BOOL bSkipEmpty,
208 ScColumn& rSrcCol );
210 ScFormulaCell* CreateRefCell( ScDocument* pDestDoc, const ScAddress& rDestPos,
211 SCSIZE nIndex, USHORT nFlags ) const;
213 ScAttrIterator* CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const;
215 SCCOL GetCol() const { return nCol; }
217 // UpdateSelectionFunction: Mehrfachselektion
218 void UpdateSelectionFunction( const ScMarkData& rMark,
219 ScFunctionData& rData,
220 const ScBitMaskCompressedArray< SCROW, BYTE>* pRowFlags,
221 BOOL bDoExclude, SCROW nExStartRow, SCROW nExEndRow );
222 void UpdateAreaFunction( ScFunctionData& rData,
223 const ScBitMaskCompressedArray< SCROW, BYTE>* pRowFlags,
224 SCROW nStartRow, SCROW nEndRow );
226 void CopyToColumn(SCROW nRow1, SCROW nRow2, USHORT nFlags, BOOL bMarked,
227 ScColumn& rColumn, const ScMarkData* pMarkData = NULL,
228 BOOL bAsLink = FALSE );
229 void UndoToColumn(SCROW nRow1, SCROW nRow2, USHORT nFlags, BOOL bMarked,
230 ScColumn& rColumn, const ScMarkData* pMarkData = NULL );
232 void CopyScenarioFrom( const ScColumn& rSrcCol );
233 void CopyScenarioTo( ScColumn& rDestCol ) const;
234 BOOL TestCopyScenarioTo( const ScColumn& rDestCol ) const;
235 void MarkScenarioIn( ScMarkData& rDestMark ) const;
237 void CopyUpdated( const ScColumn& rPosCol, ScColumn& rDestCol ) const;
239 void SwapCol(ScColumn& rCol);
240 void MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol);
242 BOOL HasEditCells(SCROW nStartRow, SCROW nEndRow, SCROW& rFirst) const;
244 // TRUE = Zahlformat gesetzt
245 BOOL SetString( SCROW nRow, SCTAB nTab, const String& rString,
246 formula::FormulaGrammar::AddressConvention conv = formula::FormulaGrammar::CONV_OOO,
247 SvNumberFormatter* pFormatter = NULL );
248 void SetValue( SCROW nRow, const double& rVal);
249 void SetError( SCROW nRow, const USHORT nError);
251 void GetString( SCROW nRow, String& rString ) const;
252 void GetInputString( SCROW nRow, String& rString ) const;
253 double GetValue( SCROW nRow ) const;
254 void GetFormula( SCROW nRow, String& rFormula,
255 BOOL bAsciiExport = FALSE ) const;
256 CellType GetCellType( SCROW nRow ) const;
257 SCSIZE GetCellCount() const { return nCount; }
258 ULONG GetWeightedCount() const;
259 ULONG GetCodeCount() const; // RPN-Code in Formeln
260 USHORT GetErrCode( SCROW nRow ) const;
262 BOOL HasStringData( SCROW nRow ) const;
263 BOOL HasValueData( SCROW nRow ) const;
264 USHORT GetErrorData( SCROW nRow) const;
265 BOOL HasStringCells( SCROW nStartRow, SCROW nEndRow ) const;
267 /** Returns the pointer to a cell note object at the passed row. */
268 ScPostIt* GetNote( SCROW nRow );
269 /** Sets the passed cell note object at the passed row. Takes ownership! */
270 void TakeNote( SCROW nRow, ScPostIt* pNote );
271 /** Returns and forgets a cell note object at the passed row. */
272 ScPostIt* ReleaseNote( SCROW nRow );
273 /** Deletes the note at the passed row. */
274 void DeleteNote( SCROW nRow );
276 void SetDirty();
277 void SetDirty( const ScRange& );
278 void SetDirtyVar();
279 void SetDirtyAfterLoad();
280 void SetTableOpDirty( const ScRange& );
281 void CalcAll();
282 void CalcAfterLoad();
283 void CompileAll();
284 void CompileXML( ScProgress& rProgress );
285 bool MarkUsedExternalReferences();
287 void ResetChanged( SCROW nStartRow, SCROW nEndRow );
289 void UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
290 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
291 SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
292 ScDocument* pUndoDoc = NULL );
293 void UpdateInsertTab( SCTAB nTable);
294 void UpdateInsertTabOnlyCells( SCTAB nTable);
295 void UpdateDeleteTab( SCTAB nTable, BOOL bIsMove, ScColumn* pRefUndo = NULL );
296 void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
297 void UpdateCompile( BOOL bForceIfNameInUse = FALSE );
298 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
299 ScDocument* pUndoDoc );
300 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
302 void SetTabNo(SCTAB nNewTab);
303 BOOL IsRangeNameInUse(SCROW nRow1, SCROW nRow2, USHORT nIndex) const;
304 void FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, std::set<USHORT>& rIndexes) const;
305 void ReplaceRangeNamesInUse( SCROW nRow1, SCROW nRow2, const ScIndexMap& rMap );
306 void ReplaceRangeNamesInUse( SCROW nRow1, SCROW nRow2, const ScRangeData::IndexMap& rMap );
308 const SfxPoolItem* GetAttr( SCROW nRow, USHORT nWhich ) const;
309 const ScPatternAttr* GetPattern( SCROW nRow ) const;
310 const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const;
312 ULONG GetNumberFormat( SCROW nRow ) const;
313 sal_uInt32 GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const;
315 void MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, BOOL bDeep ) const;
316 void MergePatternArea( ScMergePatternState& rState, SCROW nRow1, SCROW nRow2, BOOL bDeep ) const;
317 void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner,
318 ScLineFlags& rFlags,
319 SCROW nStartRow, SCROW nEndRow, BOOL bLeft, SCCOL nDistRight ) const;
320 void ApplyBlockFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner,
321 SCROW nStartRow, SCROW nEndRow, BOOL bLeft, SCCOL nDistRight );
323 void ApplyAttr( SCROW nRow, const SfxPoolItem& rAttr );
324 void ApplyPattern( SCROW nRow, const ScPatternAttr& rPatAttr );
325 void ApplyPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& rPatAttr,
326 ScEditDataArray* pDataArray = NULL );
327 void SetPattern( SCROW nRow, const ScPatternAttr& rPatAttr, BOOL bPutToPool = FALSE );
328 void SetPatternArea( SCROW nStartRow, SCROW nEndRow,
329 const ScPatternAttr& rPatAttr, BOOL bPutToPool = FALSE );
330 void ApplyPatternIfNumberformatIncompatible( const ScRange& rRange,
331 const ScPatternAttr& rPattern, short nNewType );
333 void ApplyStyle( SCROW nRow, const ScStyleSheet& rStyle );
334 void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle );
335 void ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark);
336 void ApplySelectionLineStyle( const ScMarkData& rMark,
337 const SvxBorderLine* pLine, BOOL bColorOnly );
339 const ScStyleSheet* GetStyle( SCROW nRow ) const;
340 const ScStyleSheet* GetSelectionStyle( const ScMarkData& rMark, BOOL& rFound ) const;
341 const ScStyleSheet* GetAreaStyle( BOOL& rFound, SCROW nRow1, SCROW nRow2 ) const;
343 void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset );
344 BOOL IsStyleSheetUsed( const ScStyleSheet& rStyle, BOOL bGatherAllStyles ) const;
346 /// May return -1 if not found
347 SCsROW SearchStyle( SCsROW nRow, const ScStyleSheet* pSearchStyle,
348 BOOL bUp, BOOL bInSelection, const ScMarkData& rMark );
349 BOOL SearchStyleRange( SCsROW& rRow, SCsROW& rEndRow, const ScStyleSheet* pSearchStyle,
350 BOOL bUp, BOOL bInSelection, const ScMarkData& rMark );
352 BOOL ApplyFlags( SCROW nStartRow, SCROW nEndRow, INT16 nFlags );
353 BOOL RemoveFlags( SCROW nStartRow, SCROW nEndRow, INT16 nFlags );
354 void ClearItems( SCROW nStartRow, SCROW nEndRow, const USHORT* pWhich );
356 void RemoveProtected( SCROW nStartRow, SCROW nEndRow );
358 SCsROW ApplySelectionCache( SfxItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray = NULL );
359 void DeleteSelection( USHORT nDelFlag, const ScMarkData& rMark );
361 void ClearSelectionItems( const USHORT* pWhich, const ScMarkData& rMark );
362 void ChangeSelectionIndent( BOOL bIncrement, const ScMarkData& rMark );
364 long GetNeededSize( SCROW nRow, OutputDevice* pDev,
365 double nPPTX, double nPPTY,
366 const Fraction& rZoomX, const Fraction& rZoomY,
367 BOOL bWidth, const ScNeededSizeOptions& rOptions );
368 USHORT GetOptimalColWidth( OutputDevice* pDev, double nPPTX, double nPPTY,
369 const Fraction& rZoomX, const Fraction& rZoomY,
370 BOOL bFormula, USHORT nOldWidth,
371 const ScMarkData* pMarkData,
372 BOOL bSimpleTextImport );
373 void GetOptimalHeight( SCROW nStartRow, SCROW nEndRow, USHORT* pHeight,
374 OutputDevice* pDev,
375 double nPPTX, double nPPTY,
376 const Fraction& rZoomX, const Fraction& rZoomY,
377 BOOL bShrink, USHORT nMinHeight, SCROW nMinStart );
378 private:
379 long GetSimpleTextNeededSize( SCSIZE nIndex, OutputDevice* pDev,
380 BOOL bWidth );
381 public:
383 /// Including current, may return -1
384 SCsROW GetNextUnprotected( SCROW nRow, BOOL bUp ) const;
386 void GetFilterEntries(SCROW nStartRow, SCROW nEndRow, TypedScStrCollection& rStrings);
387 BOOL GetDataEntries(SCROW nRow, TypedScStrCollection& rStrings, BOOL bLimit);
389 //UNUSED2008-05 SCROW NoteCount( SCROW nMaxRow = MAXROW ) const;
391 void UpdateInsertTabAbs(SCTAB nNewPos);
392 BOOL TestTabRefAbs(SCTAB nTable);
393 BOOL GetNextSpellingCell(SCROW& nRow, BOOL bInSel, const ScMarkData& rData) const;
395 void RemoveAutoSpellObj();
397 void StartListening( SvtListener& rLst, SCROW nRow );
398 void EndListening( SvtListener& rLst, SCROW nRow );
399 void MoveListeners( SvtBroadcaster& rSource, SCROW nDestRow );
400 void StartAllListeners();
401 void StartNeededListeners(); // only for cells where NeedsListening()==TRUE
402 void SetRelNameDirty();
404 void CompileDBFormula();
405 void CompileDBFormula( BOOL bCreateFormulaString );
406 void CompileNameFormula( BOOL bCreateFormulaString );
407 void CompileColRowNameFormula();
409 sal_Int32 GetMaxStringLen( SCROW nRowStart, SCROW nRowEnd, CharSet eCharSet ) const;
410 xub_StrLen GetMaxNumberStringLen( USHORT& nPrecision,
411 SCROW nRowStart, SCROW nRowEnd ) const;
413 private:
414 ScBaseCell* CloneCell(SCSIZE nIndex, USHORT nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos);
415 //UNUSED2008-05 void CorrectSymbolCells( CharSet eStreamCharSet );
419 class ScColumnIterator // alle Daten eines Bereichs durchgehen
421 const ScColumn* pColumn;
422 SCSIZE nPos;
423 SCROW nTop;
424 SCROW nBottom;
425 public:
426 ScColumnIterator( const ScColumn* pCol, SCROW nStart=0, SCROW nEnd=MAXROW );
427 ~ScColumnIterator();
429 BOOL Next( SCROW& rRow, ScBaseCell*& rpCell );
430 SCSIZE GetIndex() const;
434 class ScMarkedDataIter // Daten in selektierten Bereichen durchgehen
436 const ScColumn* pColumn;
437 SCSIZE nPos;
438 ScMarkArrayIter* pMarkIter;
439 SCROW nTop;
440 SCROW nBottom;
441 BOOL bNext;
442 BOOL bAll;
444 public:
445 ScMarkedDataIter( const ScColumn* pCol, const ScMarkData* pMarkData,
446 BOOL bAllIfNone = FALSE );
447 ~ScMarkedDataIter();
449 BOOL Next( SCSIZE& rIndex );
453 #endif