update dev300-m57
[ooovba.git] / sc / inc / column.hxx
blobe215ad71e6dd50886440e935ddd589615dcff449
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 ScPatternAttr;
64 class ScStyleSheet;
65 class SvtBroadcaster;
66 class TypedScStrCollection;
67 class ScProgress;
68 class ScPostIt;
69 struct ScFunctionData;
70 struct ScLineFlags;
71 struct ScMergePatternState;
72 class ScFlatBoolRowSegments;
74 #define COLUMN_DELTA 4
77 struct ScNeededSizeOptions
79 const ScPatternAttr* pPattern;
80 BOOL bFormula;
81 BOOL bSkipMerged;
82 BOOL bGetFont;
83 BOOL bTotalSize;
85 ScNeededSizeOptions()
87 pPattern = NULL;
88 bFormula = FALSE;
89 bSkipMerged = TRUE;
90 bGetFont = TRUE;
91 bTotalSize = FALSE;
95 struct ColEntry
97 SCROW nRow;
98 ScBaseCell* pCell;
102 class ScIndexMap;
104 class ScColumn
106 private:
107 SCCOL nCol;
108 SCTAB nTab;
110 SCSIZE nCount;
111 SCSIZE nLimit;
112 ColEntry* pItems;
114 ScAttrArray* pAttrArray;
115 ScDocument* pDocument;
117 friend class ScDocument; // fuer FillInfo
118 friend class ScDocumentIterator;
119 friend class ScValueIterator;
120 friend class ScQueryValueIterator;
121 friend class ScColumnIterator;
122 friend class ScQueryCellIterator;
123 friend class ScMarkedDataIter;
124 friend class ScCellIterator;
125 friend class ScHorizontalCellIterator;
126 friend class ScHorizontalAttrIterator;
128 public:
129 static BOOL bDoubleAlloc; // fuer Import: Groesse beim Allozieren verdoppeln
131 public:
132 ScColumn();
133 ~ScColumn();
135 void Init(SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc);
137 BOOL Search( SCROW nRow, SCSIZE& nIndex ) const;
138 ScBaseCell* GetCell( SCROW nRow ) const;
139 void Insert( SCROW nRow, ScBaseCell* pCell );
140 void Insert( SCROW nRow, ULONG nFormatIndex, ScBaseCell* pCell );
141 void Append( SCROW nRow, ScBaseCell* pCell );
142 void Delete( SCROW nRow );
143 void DeleteAtIndex( SCSIZE nIndex );
144 void FreeAll();
145 void Resize( SCSIZE nSize );
146 void SwapRow( SCROW nRow1, SCROW nRow2 );
147 void SwapCell( SCROW nRow, ScColumn& rCol);
149 //UNUSED2009-05 BOOL HasLines( SCROW nRow1, SCROW nRow2, Rectangle& rSizes,
150 //UNUSED2009-05 BOOL bLeft, BOOL bRight ) const;
151 BOOL HasAttrib( SCROW nRow1, SCROW nRow2, USHORT nMask ) const;
152 BOOL HasAttribSelection( const ScMarkData& rMark, USHORT nMask ) const;
153 BOOL ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow,
154 SCCOL& rPaintCol, SCROW& rPaintRow,
155 BOOL bRefresh, BOOL bAttrs );
157 BOOL IsEmptyVisData(BOOL bNotes) const; // ohne Broadcaster
158 BOOL IsEmptyData() const;
159 BOOL IsEmptyAttr() const;
160 BOOL IsEmpty() const;
162 // nur Daten:
163 BOOL IsEmptyBlock(SCROW nStartRow, SCROW nEndRow, bool bIgnoreNotes = false) const;
164 SCSIZE GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirection eDir ) const;
165 BOOL HasDataAt(SCROW nRow) const;
166 BOOL HasVisibleDataAt(SCROW nRow) const;
167 SCROW GetFirstDataPos() const;
168 SCROW GetLastDataPos() const;
169 SCROW GetLastVisDataPos(BOOL bNotes) const; // ohne Broadcaster
170 SCROW GetFirstVisDataPos(BOOL bNotes) const;
171 BOOL GetPrevDataPos(SCROW& rRow) const;
172 BOOL GetNextDataPos(SCROW& rRow) const;
173 void FindDataAreaPos(SCROW& rRow, long nMovY) const; // (ohne Broadcaster)
174 void FindUsed( SCROW nStartRow, SCROW nEndRow, BOOL* pUsed ) const;
176 SCSIZE VisibleCount( SCROW nStartRow, SCROW nEndRow ) const;
178 USHORT GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, USHORT nMask ) const;
179 BOOL HasSelectionMatrixFragment(const ScMarkData& rMark) const;
181 BOOL GetFirstVisibleAttr( SCROW& rFirstRow ) const;
182 BOOL GetLastVisibleAttr( SCROW& rLastRow ) const;
183 BOOL HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const;
184 BOOL IsVisibleAttrEqual( const ScColumn& rCol, SCROW nStartRow = 0,
185 SCROW nEndRow = MAXROW ) const;
186 BOOL IsAllAttrEqual( const ScColumn& rCol, SCROW nStartRow, SCROW nEndRow ) const;
188 BOOL TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
189 BOOL TestInsertRow( SCSIZE nSize ) const;
190 void InsertRow( SCROW nStartRow, SCSIZE nSize );
191 void DeleteRow( SCROW nStartRow, SCSIZE nSize );
192 void DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, USHORT nDelFlag );
193 void DeleteArea(SCROW nStartRow, SCROW nEndRow, USHORT nDelFlag );
194 void CopyToClip(SCROW nRow1, SCROW nRow2, ScColumn& rColumn, BOOL bKeepScenarioFlags, BOOL bCloneNoteCaptions);
195 void CopyFromClip(SCROW nRow1, SCROW nRow2, long nDy,
196 USHORT nInsFlag, BOOL bAsLink, BOOL bSkipAttrForEmpty, ScColumn& rColumn);
197 void StartListeningInArea( SCROW nRow1, SCROW nRow2 );
198 void BroadcastInArea( SCROW nRow1, SCROW nRow2 );
200 void RemoveEditAttribs( SCROW nStartRow, SCROW nEndRow );
202 // Markierung von diesem Dokument
203 void MixMarked( const ScMarkData& rMark, USHORT nFunction,
204 BOOL bSkipEmpty, ScColumn& rSrcCol );
205 void MixData( SCROW nRow1, SCROW nRow2, USHORT nFunction, BOOL bSkipEmpty,
206 ScColumn& rSrcCol );
208 ScFormulaCell* CreateRefCell( ScDocument* pDestDoc, const ScAddress& rDestPos,
209 SCSIZE nIndex, USHORT nFlags ) const;
211 ScAttrIterator* CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const;
213 SCCOL GetCol() const { return nCol; }
215 // UpdateSelectionFunction: Mehrfachselektion
216 void UpdateSelectionFunction( const ScMarkData& rMark,
217 ScFunctionData& rData,
218 const ScBitMaskCompressedArray< SCROW, BYTE>* pRowFlags,
219 BOOL bDoExclude, SCROW nExStartRow, SCROW nExEndRow );
220 void UpdateAreaFunction( ScFunctionData& rData,
221 const ScBitMaskCompressedArray< SCROW, BYTE>* pRowFlags,
222 SCROW nStartRow, SCROW nEndRow );
224 void CopyToColumn(SCROW nRow1, SCROW nRow2, USHORT nFlags, BOOL bMarked,
225 ScColumn& rColumn, const ScMarkData* pMarkData = NULL,
226 BOOL bAsLink = FALSE );
227 void UndoToColumn(SCROW nRow1, SCROW nRow2, USHORT nFlags, BOOL bMarked,
228 ScColumn& rColumn, const ScMarkData* pMarkData = NULL );
230 void CopyScenarioFrom( const ScColumn& rSrcCol );
231 void CopyScenarioTo( ScColumn& rDestCol ) const;
232 BOOL TestCopyScenarioTo( const ScColumn& rDestCol ) const;
233 void MarkScenarioIn( ScMarkData& rDestMark ) const;
235 void CopyUpdated( const ScColumn& rPosCol, ScColumn& rDestCol ) const;
237 void SwapCol(ScColumn& rCol);
238 void MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol);
240 BOOL HasEditCells(SCROW nStartRow, SCROW nEndRow, SCROW& rFirst) const;
242 // TRUE = Zahlformat gesetzt
243 BOOL SetString( SCROW nRow, SCTAB nTab, const String& rString,
244 formula::FormulaGrammar::AddressConvention conv = formula::FormulaGrammar::CONV_OOO,
245 SvNumberFormatter* pFormatter = NULL,
246 bool bDetectNumberFormat = true );
247 void SetValue( SCROW nRow, const double& rVal);
248 void SetError( SCROW nRow, const USHORT nError);
250 void GetString( SCROW nRow, String& rString ) const;
251 void GetInputString( SCROW nRow, String& rString ) const;
252 double GetValue( SCROW nRow ) const;
253 void GetFormula( SCROW nRow, String& rFormula,
254 BOOL bAsciiExport = FALSE ) const;
255 CellType GetCellType( SCROW nRow ) const;
256 SCSIZE GetCellCount() const { return nCount; }
257 ULONG GetWeightedCount() const;
258 ULONG GetCodeCount() const; // RPN-Code in Formeln
259 USHORT GetErrCode( SCROW nRow ) const;
261 BOOL HasStringData( SCROW nRow ) const;
262 BOOL HasValueData( SCROW nRow ) const;
263 //UNUSED2009-05 USHORT GetErrorData( SCROW nRow) const;
264 BOOL HasStringCells( SCROW nStartRow, SCROW nEndRow ) const;
266 /** Returns the pointer to a cell note object at the passed row. */
267 ScPostIt* GetNote( SCROW nRow );
268 /** Sets the passed cell note object at the passed row. Takes ownership! */
269 void TakeNote( SCROW nRow, ScPostIt* pNote );
270 /** Returns and forgets a cell note object at the passed row. */
271 ScPostIt* ReleaseNote( SCROW nRow );
272 /** Deletes the note at the passed row. */
273 void DeleteNote( SCROW nRow );
275 void SetDirty();
276 void SetDirty( const ScRange& );
277 void SetDirtyVar();
278 void SetDirtyAfterLoad();
279 void SetTableOpDirty( const ScRange& );
280 void CalcAll();
281 void CalcAfterLoad();
282 void CompileAll();
283 void CompileXML( ScProgress& rProgress );
284 bool MarkUsedExternalReferences();
286 void ResetChanged( SCROW nStartRow, SCROW nEndRow );
288 void UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
289 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
290 SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
291 ScDocument* pUndoDoc = NULL );
292 void UpdateInsertTab( SCTAB nTable);
293 void UpdateInsertTabOnlyCells( SCTAB nTable);
294 void UpdateDeleteTab( SCTAB nTable, BOOL bIsMove, ScColumn* pRefUndo = NULL );
295 void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
296 void UpdateCompile( BOOL bForceIfNameInUse = FALSE );
297 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
298 ScDocument* pUndoDoc );
299 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
301 void SetTabNo(SCTAB nNewTab);
302 BOOL IsRangeNameInUse(SCROW nRow1, SCROW nRow2, USHORT nIndex) const;
303 void FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, std::set<USHORT>& rIndexes) const;
304 void ReplaceRangeNamesInUse( SCROW nRow1, SCROW nRow2, const ScIndexMap& rMap );
305 void ReplaceRangeNamesInUse( SCROW nRow1, SCROW nRow2, const ScRangeData::IndexMap& rMap );
307 const SfxPoolItem* GetAttr( SCROW nRow, USHORT nWhich ) const;
308 const ScPatternAttr* GetPattern( SCROW nRow ) const;
309 const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const;
311 ULONG GetNumberFormat( SCROW nRow ) const;
312 sal_uInt32 GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const;
314 void MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, BOOL bDeep ) const;
315 void MergePatternArea( ScMergePatternState& rState, SCROW nRow1, SCROW nRow2, BOOL bDeep ) const;
316 void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner,
317 ScLineFlags& rFlags,
318 SCROW nStartRow, SCROW nEndRow, BOOL bLeft, SCCOL nDistRight ) const;
319 void ApplyBlockFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner,
320 SCROW nStartRow, SCROW nEndRow, BOOL bLeft, SCCOL nDistRight );
322 void ApplyAttr( SCROW nRow, const SfxPoolItem& rAttr );
323 void ApplyPattern( SCROW nRow, const ScPatternAttr& rPatAttr );
324 void ApplyPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& rPatAttr,
325 ScEditDataArray* pDataArray = NULL );
326 void SetPattern( SCROW nRow, const ScPatternAttr& rPatAttr, BOOL bPutToPool = FALSE );
327 void SetPatternArea( SCROW nStartRow, SCROW nEndRow,
328 const ScPatternAttr& rPatAttr, BOOL bPutToPool = FALSE );
329 void ApplyPatternIfNumberformatIncompatible( const ScRange& rRange,
330 const ScPatternAttr& rPattern, short nNewType );
332 void ApplyStyle( SCROW nRow, const ScStyleSheet& rStyle );
333 void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle );
334 void ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark);
335 void ApplySelectionLineStyle( const ScMarkData& rMark,
336 const SvxBorderLine* pLine, BOOL bColorOnly );
338 const ScStyleSheet* GetStyle( SCROW nRow ) const;
339 const ScStyleSheet* GetSelectionStyle( const ScMarkData& rMark, BOOL& rFound ) const;
340 const ScStyleSheet* GetAreaStyle( BOOL& rFound, SCROW nRow1, SCROW nRow2 ) const;
342 void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset );
343 BOOL IsStyleSheetUsed( const ScStyleSheet& rStyle, BOOL bGatherAllStyles ) const;
345 /// May return -1 if not found
346 SCsROW SearchStyle( SCsROW nRow, const ScStyleSheet* pSearchStyle,
347 BOOL bUp, BOOL bInSelection, const ScMarkData& rMark );
348 BOOL SearchStyleRange( SCsROW& rRow, SCsROW& rEndRow, const ScStyleSheet* pSearchStyle,
349 BOOL bUp, BOOL bInSelection, const ScMarkData& rMark );
351 BOOL ApplyFlags( SCROW nStartRow, SCROW nEndRow, INT16 nFlags );
352 BOOL RemoveFlags( SCROW nStartRow, SCROW nEndRow, INT16 nFlags );
353 void ClearItems( SCROW nStartRow, SCROW nEndRow, const USHORT* pWhich );
355 void RemoveProtected( SCROW nStartRow, SCROW nEndRow );
357 SCsROW ApplySelectionCache( SfxItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray = NULL );
358 void DeleteSelection( USHORT nDelFlag, const ScMarkData& rMark );
360 void ClearSelectionItems( const USHORT* pWhich, const ScMarkData& rMark );
361 void ChangeSelectionIndent( BOOL bIncrement, const ScMarkData& rMark );
363 long GetNeededSize( SCROW nRow, OutputDevice* pDev,
364 double nPPTX, double nPPTY,
365 const Fraction& rZoomX, const Fraction& rZoomY,
366 BOOL bWidth, const ScNeededSizeOptions& rOptions );
367 USHORT GetOptimalColWidth( OutputDevice* pDev, double nPPTX, double nPPTY,
368 const Fraction& rZoomX, const Fraction& rZoomY,
369 BOOL bFormula, USHORT nOldWidth,
370 const ScMarkData* pMarkData,
371 BOOL bSimpleTextImport );
372 void GetOptimalHeight( SCROW nStartRow, SCROW nEndRow, USHORT* pHeight,
373 OutputDevice* pDev,
374 double nPPTX, double nPPTY,
375 const Fraction& rZoomX, const Fraction& rZoomY,
376 BOOL bShrink, USHORT nMinHeight, SCROW nMinStart );
377 private:
378 long GetSimpleTextNeededSize( SCSIZE nIndex, OutputDevice* pDev,
379 BOOL bWidth );
380 public:
382 /// Including current, may return -1
383 SCsROW GetNextUnprotected( SCROW nRow, BOOL bUp ) const;
385 void GetFilterEntries(SCROW nStartRow, SCROW nEndRow, TypedScStrCollection& rStrings);
386 BOOL GetDataEntries(SCROW nRow, TypedScStrCollection& rStrings, BOOL bLimit);
388 //UNUSED2008-05 SCROW NoteCount( SCROW nMaxRow = MAXROW ) const;
390 void UpdateInsertTabAbs(SCTAB nNewPos);
391 BOOL TestTabRefAbs(SCTAB nTable);
392 BOOL GetNextSpellingCell(SCROW& nRow, BOOL bInSel, const ScMarkData& rData) const;
394 void RemoveAutoSpellObj();
396 void StartListening( SvtListener& rLst, SCROW nRow );
397 void EndListening( SvtListener& rLst, SCROW nRow );
398 void MoveListeners( SvtBroadcaster& rSource, SCROW nDestRow );
399 void StartAllListeners();
400 void StartNeededListeners(); // only for cells where NeedsListening()==TRUE
401 void SetRelNameDirty();
403 void CompileDBFormula();
404 void CompileDBFormula( BOOL bCreateFormulaString );
405 void CompileNameFormula( BOOL bCreateFormulaString );
406 void CompileColRowNameFormula();
408 sal_Int32 GetMaxStringLen( SCROW nRowStart, SCROW nRowEnd, CharSet eCharSet ) const;
409 xub_StrLen GetMaxNumberStringLen( USHORT& nPrecision,
410 SCROW nRowStart, SCROW nRowEnd ) const;
412 private:
413 ScBaseCell* CloneCell(SCSIZE nIndex, USHORT nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos);
414 //UNUSED2008-05 void CorrectSymbolCells( CharSet eStreamCharSet );
418 class ScColumnIterator // alle Daten eines Bereichs durchgehen
420 const ScColumn* pColumn;
421 SCSIZE nPos;
422 SCROW nTop;
423 SCROW nBottom;
424 public:
425 ScColumnIterator( const ScColumn* pCol, SCROW nStart=0, SCROW nEnd=MAXROW );
426 ~ScColumnIterator();
428 BOOL Next( SCROW& rRow, ScBaseCell*& rpCell );
429 SCSIZE GetIndex() const;
433 class ScMarkedDataIter // Daten in selektierten Bereichen durchgehen
435 const ScColumn* pColumn;
436 SCSIZE nPos;
437 ScMarkArrayIter* pMarkIter;
438 SCROW nTop;
439 SCROW nBottom;
440 BOOL bNext;
441 BOOL bAll;
443 public:
444 ScMarkedDataIter( const ScColumn* pCol, const ScMarkData* pMarkData,
445 BOOL bAllIfNone = FALSE );
446 ~ScMarkedDataIter();
448 BOOL Next( SCSIZE& rIndex );
452 #endif