1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_COLUMN_HXX 25 #define SC_COLUMN_HXX 26 27 #include "markarr.hxx" 28 #include "global.hxx" 29 #include "address.hxx" 30 #include "rangenam.hxx" 31 #include <tools/solar.h> 32 33 #include <set> 34 35 class Fraction; 36 class OutputDevice; 37 class Rectangle; 38 class SfxBroadcaster; 39 class SfxItemPoolCache; 40 class SfxItemSet; 41 class SvtListener; 42 class SfxPoolItem; 43 class SfxStyleSheetBase; 44 class SvxBorderLine; 45 class SvxBoxInfoItem; 46 class SvxBoxItem; 47 48 class ScAttrIterator; 49 class ScAttrArray; 50 class ScBaseCell; 51 class ScDocument; 52 class ScFormulaCell; 53 class ScMarkData; 54 class ScPatternAttr; 55 class ScStyleSheet; 56 class SvtBroadcaster; 57 class TypedScStrCollection; 58 class ScProgress; 59 class ScPostIt; 60 struct ScFunctionData; 61 struct ScLineFlags; 62 struct ScMergePatternState; 63 class ScDPTableDataCache; 64 class ScFlatBoolRowSegments; 65 66 #define COLUMN_DELTA 4 67 68 69 struct ScNeededSizeOptions 70 { 71 const ScPatternAttr* pPattern; 72 sal_Bool bFormula; 73 sal_Bool bSkipMerged; 74 sal_Bool bGetFont; 75 sal_Bool bTotalSize; 76 ScNeededSizeOptionsScNeededSizeOptions77 ScNeededSizeOptions() 78 { 79 pPattern = NULL; 80 bFormula = sal_False; 81 bSkipMerged = sal_True; 82 bGetFont = sal_True; 83 bTotalSize = sal_False; 84 } 85 }; 86 87 struct ColEntry 88 { 89 SCROW nRow; 90 ScBaseCell* pCell; 91 }; 92 93 94 class ScColumn 95 { 96 private: 97 SCCOL nCol; 98 SCTAB nTab; 99 100 SCSIZE nCount; 101 SCSIZE nLimit; 102 ColEntry* pItems; 103 104 ScAttrArray* pAttrArray; 105 ScDocument* pDocument; 106 107 friend class ScDocument; // fuer 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 sal_Bool bDoubleAlloc; // fuer Import: Groesse beim Allozieren verdoppeln 121 122 public: 123 ScColumn(); 124 ~ScColumn(); 125 126 void Init(SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc); 127 128 sal_Bool Search( SCROW nRow, SCSIZE& nIndex ) const; 129 ScBaseCell* GetCell( SCROW nRow ) const; 130 void Insert( SCROW nRow, ScBaseCell* pCell ); 131 void Insert( SCROW nRow, sal_uLong nFormatIndex, ScBaseCell* pCell ); 132 void Append( SCROW nRow, ScBaseCell* pCell ); 133 void Delete( SCROW nRow ); 134 void DeleteAtIndex( SCSIZE nIndex ); 135 void FreeAll(); 136 void Resize( SCSIZE nSize ); 137 void SwapRow( SCROW nRow1, SCROW nRow2 ); 138 void SwapCell( SCROW nRow, ScColumn& rCol); 139 140 //UNUSED2009-05 sal_Bool HasLines( SCROW nRow1, SCROW nRow2, Rectangle& rSizes, 141 //UNUSED2009-05 sal_Bool bLeft, sal_Bool bRight ) const; 142 bool HasAttrib( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const; 143 sal_Bool HasAttribSelection( const ScMarkData& rMark, sal_uInt16 nMask ) const; 144 sal_Bool ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow, 145 SCCOL& rPaintCol, SCROW& rPaintRow, 146 sal_Bool bRefresh, sal_Bool bAttrs ); 147 148 sal_Bool IsEmptyVisData(sal_Bool bNotes) const; // ohne Broadcaster 149 sal_Bool IsEmptyData() const; 150 sal_Bool IsEmptyAttr() const; 151 sal_Bool IsEmpty() const; 152 153 // nur Daten: 154 sal_Bool IsEmptyBlock(SCROW nStartRow, SCROW nEndRow, bool bIgnoreNotes = false) const; 155 SCSIZE GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirection eDir ) const; 156 sal_Bool HasDataAt(SCROW nRow) const; 157 sal_Bool HasVisibleDataAt(SCROW nRow) const; 158 SCROW GetFirstDataPos() const; 159 SCROW GetLastDataPos() const; 160 SCROW GetLastVisDataPos(sal_Bool bNotes) const; // ohne Broadcaster 161 SCROW GetFirstVisDataPos(sal_Bool bNotes) const; 162 sal_Bool GetPrevDataPos(SCROW& rRow) const; 163 sal_Bool GetNextDataPos(SCROW& rRow) const; 164 void FindDataAreaPos(SCROW& rRow, long nMovY) const; // (ohne Broadcaster) 165 void FindUsed( SCROW nStartRow, SCROW nEndRow, sal_Bool* pUsed ) const; 166 167 SCSIZE VisibleCount( SCROW nStartRow, SCROW nEndRow ) const; 168 169 sal_uInt16 GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const; 170 sal_Bool HasSelectionMatrixFragment(const ScMarkData& rMark) const; 171 172 sal_Bool GetFirstVisibleAttr( SCROW& rFirstRow ) const; 173 sal_Bool GetLastVisibleAttr( SCROW& rLastRow ) const; 174 /* 175 Get the last cell's row number , which have visual attribute or visual data in a column 176 */ 177 sal_Bool GetLastAttr( SCROW& rLastRow ) const; 178 sal_Bool HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const; 179 sal_Bool IsVisibleAttrEqual( const ScColumn& rCol, SCROW nStartRow = 0, 180 SCROW nEndRow = MAXROW ) const; 181 sal_Bool IsAllAttrEqual( const ScColumn& rCol, SCROW nStartRow, SCROW nEndRow ) const; 182 183 sal_Bool TestInsertCol( SCROW nStartRow, SCROW nEndRow) const; 184 sal_Bool TestInsertRow( SCSIZE nSize ) const; 185 void InsertRow( SCROW nStartRow, SCSIZE nSize ); 186 void DeleteRow( SCROW nStartRow, SCSIZE nSize ); 187 void DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag ); 188 void DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag ); 189 void CopyToClip(SCROW nRow1, SCROW nRow2, ScColumn& rColumn, sal_Bool bKeepScenarioFlags, sal_Bool bCloneNoteCaptions); 190 void CopyFromClip(SCROW nRow1, SCROW nRow2, long nDy, 191 sal_uInt16 nInsFlag, sal_Bool bAsLink, sal_Bool bSkipAttrForEmpty, ScColumn& rColumn); 192 void StartListeningInArea( SCROW nRow1, SCROW nRow2 ); 193 void BroadcastInArea( SCROW nRow1, SCROW nRow2 ); 194 195 void RemoveEditAttribs( SCROW nStartRow, SCROW nEndRow ); 196 197 // Markierung von diesem Dokument 198 void MixMarked( const ScMarkData& rMark, sal_uInt16 nFunction, 199 sal_Bool bSkipEmpty, ScColumn& rSrcCol ); 200 void MixData( SCROW nRow1, SCROW nRow2, sal_uInt16 nFunction, sal_Bool bSkipEmpty, 201 ScColumn& rSrcCol ); 202 203 ScFormulaCell* CreateRefCell( ScDocument* pDestDoc, const ScAddress& rDestPos, 204 SCSIZE nIndex, sal_uInt16 nFlags ) const; 205 206 ScAttrIterator* CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const; 207 GetCol() const208 SCCOL GetCol() const { return nCol; } 209 210 // UpdateSelectionFunction: Mehrfachselektion 211 void UpdateSelectionFunction( const ScMarkData& rMark, 212 ScFunctionData& rData, 213 ScFlatBoolRowSegments& rHiddenRows, 214 sal_Bool bDoExclude, SCROW nExStartRow, SCROW nExEndRow ); 215 void UpdateAreaFunction( ScFunctionData& rData, 216 ScFlatBoolRowSegments& rHiddenRows, 217 SCROW nStartRow, SCROW nEndRow ); 218 219 void CopyToColumn(SCROW nRow1, SCROW nRow2, sal_uInt16 nFlags, sal_Bool bMarked, 220 ScColumn& rColumn, const ScMarkData* pMarkData = NULL, 221 sal_Bool bAsLink = sal_False ); 222 void UndoToColumn(SCROW nRow1, SCROW nRow2, sal_uInt16 nFlags, sal_Bool bMarked, 223 ScColumn& rColumn, const ScMarkData* pMarkData = NULL ); 224 225 void CopyScenarioFrom( const ScColumn& rSrcCol ); 226 void CopyScenarioTo( ScColumn& rDestCol ) const; 227 sal_Bool TestCopyScenarioTo( const ScColumn& rDestCol ) const; 228 void MarkScenarioIn( ScMarkData& rDestMark ) const; 229 230 void CopyUpdated( const ScColumn& rPosCol, ScColumn& rDestCol ) const; 231 232 void SwapCol(ScColumn& rCol); 233 void MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol); 234 235 sal_Bool HasEditCells(SCROW nStartRow, SCROW nEndRow, SCROW& rFirst) const; 236 237 // sal_True = Zahlformat gesetzt 238 sal_Bool SetString( SCROW nRow, SCTAB nTab, const String& rString, 239 formula::FormulaGrammar::AddressConvention conv = formula::FormulaGrammar::CONV_OOO, 240 SvNumberFormatter* pFormatter = NULL, 241 bool bDetectNumberFormat = true ); 242 void SetValue( SCROW nRow, const double& rVal); 243 void SetError( SCROW nRow, const sal_uInt16 nError); 244 245 void GetString( SCROW nRow, String& rString ) const; 246 void GetInputString( SCROW nRow, String& rString ) const; 247 double GetValue( SCROW nRow ) const; 248 void GetFormula( SCROW nRow, String& rFormula, 249 sal_Bool bAsciiExport = sal_False ) const; 250 CellType GetCellType( SCROW nRow ) const; GetCellCount() const251 SCSIZE GetCellCount() const { return nCount; } 252 sal_uLong GetWeightedCount() const; 253 sal_uLong GetCodeCount() const; // RPN-Code in Formeln 254 sal_uInt16 GetErrCode( SCROW nRow ) const; 255 256 sal_Bool HasStringData( SCROW nRow ) const; 257 sal_Bool HasValueData( SCROW nRow ) const; 258 //UNUSED2009-05 sal_uInt16 GetErrorData( SCROW nRow) const; 259 sal_Bool HasStringCells( SCROW nStartRow, SCROW nEndRow ) const; 260 261 /** Returns the pointer to a cell note object at the passed row. */ 262 ScPostIt* GetNote( SCROW nRow ); 263 /** Sets the passed cell note object at the passed row. Takes ownership! */ 264 void TakeNote( SCROW nRow, ScPostIt* pNote ); 265 /** Returns and forgets a cell note object at the passed row. */ 266 ScPostIt* ReleaseNote( SCROW nRow ); 267 /** Deletes the note at the passed row. */ 268 void DeleteNote( SCROW nRow ); 269 270 void SetDirty(); 271 void SetDirty( const ScRange& ); 272 void SetDirtyVar(); 273 void SetDirtyAfterLoad(); 274 void SetTableOpDirty( const ScRange& ); 275 void CalcAll(); 276 void CalcAfterLoad(); 277 void CompileAll(); 278 void CompileXML( ScProgress& rProgress ); 279 280 void ResetChanged( SCROW nStartRow, SCROW nEndRow ); 281 282 void UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, 283 SCCOL nCol2, SCROW nRow2, SCTAB nTab2, 284 SCsCOL nDx, SCsROW nDy, SCsTAB nDz, 285 ScDocument* pUndoDoc = NULL ); 286 void UpdateInsertTab( SCTAB nTable); 287 void UpdateInsertTabOnlyCells( SCTAB nTable); 288 void UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScColumn* pRefUndo = NULL ); 289 void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo); 290 void UpdateCompile( sal_Bool bForceIfNameInUse = sal_False ); 291 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest, 292 ScDocument* pUndoDoc ); 293 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ); 294 295 void SetTabNo(SCTAB nNewTab); 296 sal_Bool IsRangeNameInUse(SCROW nRow1, SCROW nRow2, sal_uInt16 nIndex) const; 297 void FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, std::set<sal_uInt16>& rIndexes) const; 298 void ReplaceRangeNamesInUse( SCROW nRow1, SCROW nRow2, const ScRangeData::IndexMap& rMap ); 299 300 const SfxPoolItem* GetAttr( SCROW nRow, sal_uInt16 nWhich ) const; 301 const ScPatternAttr* GetPattern( SCROW nRow ) const; 302 const ScPatternAttr* GetPatternRange( SCROW& rStartRow, SCROW& rEndRow, SCROW nRow ) const; 303 const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const; 304 305 sal_uLong GetNumberFormat( SCROW nRow ) const; 306 307 void MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, sal_Bool bDeep ) const; 308 void MergePatternArea( ScMergePatternState& rState, SCROW nRow1, SCROW nRow2, sal_Bool bDeep ) const; 309 void MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner, 310 ScLineFlags& rFlags, 311 SCROW nStartRow, SCROW nEndRow, sal_Bool bLeft, SCCOL nDistRight ) const; 312 void ApplyBlockFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner, 313 SCROW nStartRow, SCROW nEndRow, sal_Bool bLeft, SCCOL nDistRight ); 314 315 void ApplyAttr( SCROW nRow, const SfxPoolItem& rAttr ); 316 void ApplyPattern( SCROW nRow, const ScPatternAttr& rPatAttr ); 317 void ApplyPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& rPatAttr ); 318 void SetPattern( SCROW nRow, const ScPatternAttr& rPatAttr, sal_Bool bPutToPool = sal_False ); 319 void SetPatternArea( SCROW nStartRow, SCROW nEndRow, 320 const ScPatternAttr& rPatAttr, sal_Bool bPutToPool = sal_False ); 321 void ApplyPatternIfNumberformatIncompatible( const ScRange& rRange, 322 const ScPatternAttr& rPattern, short nNewType ); 323 324 void ApplyStyle( SCROW nRow, const ScStyleSheet& rStyle ); 325 void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle ); 326 void ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark); 327 void ApplySelectionLineStyle( const ScMarkData& rMark, 328 const SvxBorderLine* pLine, sal_Bool bColorOnly ); 329 330 const ScStyleSheet* GetStyle( SCROW nRow ) const; 331 const ScStyleSheet* GetSelectionStyle( const ScMarkData& rMark, sal_Bool& rFound ) const; 332 const ScStyleSheet* GetAreaStyle( sal_Bool& rFound, SCROW nRow1, SCROW nRow2 ) const; 333 334 void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset ); 335 sal_Bool IsStyleSheetUsed( const ScStyleSheet& rStyle, sal_Bool bGatherAllStyles ) const; 336 337 /// May return -1 if not found 338 SCsROW SearchStyle( SCsROW nRow, const ScStyleSheet* pSearchStyle, 339 sal_Bool bUp, sal_Bool bInSelection, const ScMarkData& rMark ); 340 sal_Bool SearchStyleRange( SCsROW& rRow, SCsROW& rEndRow, const ScStyleSheet* pSearchStyle, 341 sal_Bool bUp, sal_Bool bInSelection, const ScMarkData& rMark ); 342 343 sal_Bool ApplyFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags ); 344 sal_Bool RemoveFlags( SCROW nStartRow, SCROW nEndRow, sal_Int16 nFlags ); 345 void ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* pWhich ); 346 347 void RemoveProtected( SCROW nStartRow, SCROW nEndRow ); 348 349 SCsROW ApplySelectionCache( SfxItemPoolCache* pCache, const ScMarkData& rMark ); 350 void DeleteSelection( sal_uInt16 nDelFlag, const ScMarkData& rMark ); 351 352 void ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark ); 353 void ChangeSelectionIndent( sal_Bool bIncrement, const ScMarkData& rMark ); 354 355 long GetNeededSize( SCROW nRow, OutputDevice* pDev, 356 double nPPTX, double nPPTY, 357 const Fraction& rZoomX, const Fraction& rZoomY, 358 sal_Bool bWidth, const ScNeededSizeOptions& rOptions ); 359 sal_uInt16 GetOptimalColWidth( OutputDevice* pDev, double nPPTX, double nPPTY, 360 const Fraction& rZoomX, const Fraction& rZoomY, 361 sal_Bool bFormula, sal_uInt16 nOldWidth, 362 const ScMarkData* pMarkData, 363 sal_Bool bSimpleTextImport ); 364 void GetOptimalHeight( SCROW nStartRow, SCROW nEndRow, sal_uInt16* pHeight, 365 OutputDevice* pDev, 366 double nPPTX, double nPPTY, 367 const Fraction& rZoomX, const Fraction& rZoomY, 368 sal_Bool bShrink, sal_uInt16 nMinHeight, SCROW nMinStart ); 369 template< typename TAddLebal, typename TAddData > 370 void FillDPCacheT( long nDim, SCROW nStartRow, SCROW nEndRow, const TAddLebal & , const TAddData & ); 371 void FillDPCache( ScDPTableDataCache * pCache, long nDim, SCROW nStartRow, SCROW nEndRow ); 372 private: 373 long GetSimpleTextNeededSize( SCSIZE nIndex, OutputDevice* pDev, 374 sal_Bool bWidth ); 375 public: 376 377 /// Including current, may return -1 378 SCsROW GetNextUnprotected( SCROW nRow, sal_Bool bUp ) const; 379 380 void GetFilterEntries(SCROW nStartRow, SCROW nEndRow, TypedScStrCollection& rStrings, bool& rHasDates); 381 sal_Bool GetDataEntries(SCROW nRow, TypedScStrCollection& rStrings, sal_Bool bLimit); 382 383 //UNUSED2008-05 SCROW NoteCount( SCROW nMaxRow = MAXROW ) const; 384 385 void UpdateInsertTabAbs(SCTAB nNewPos); 386 sal_Bool TestTabRefAbs(SCTAB nTable); 387 sal_Bool GetNextSpellingCell(SCROW& nRow, sal_Bool bInSel, const ScMarkData& rData) const; 388 389 void RemoveAutoSpellObj(); 390 391 void StartListening( SvtListener& rLst, SCROW nRow ); 392 void EndListening( SvtListener& rLst, SCROW nRow ); 393 void MoveListeners( SvtBroadcaster& rSource, SCROW nDestRow ); 394 void StartAllListeners(); 395 void StartNeededListeners(); // only for cells where NeedsListening()==TRUE 396 void SetRelNameDirty(); 397 398 void CompileDBFormula(); 399 void CompileDBFormula( sal_Bool bCreateFormulaString ); 400 void CompileNameFormula( sal_Bool bCreateFormulaString ); 401 void CompileColRowNameFormula(); 402 403 sal_Int32 GetMaxStringLen( SCROW nRowStart, SCROW nRowEnd, CharSet eCharSet ) const; 404 xub_StrLen GetMaxNumberStringLen( sal_uInt16& nPrecision, 405 SCROW nRowStart, SCROW nRowEnd ) const; 406 407 SCSIZE GetPatternCount( ); 408 SCSIZE GetPatternCount( SCROW nRw1, SCROW nRw2 ); 409 bool ReservedPatternCount( SCSIZE nReserved ); 410 private: 411 ScBaseCell* CloneCell(SCSIZE nIndex, sal_uInt16 nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos); 412 //UNUSED2008-05 void CorrectSymbolCells( CharSet eStreamCharSet ); 413 }; 414 415 416 class ScColumnIterator // alle Daten eines Bereichs durchgehen 417 { 418 const ScColumn* pColumn; 419 SCSIZE nPos; 420 SCROW nTop; 421 SCROW nBottom; 422 public: 423 ScColumnIterator( const ScColumn* pCol, SCROW nStart=0, SCROW nEnd=MAXROW ); 424 ~ScColumnIterator(); 425 426 sal_Bool Next( SCROW& rRow, ScBaseCell*& rpCell ); 427 SCSIZE GetIndex() const; 428 }; 429 430 431 class ScMarkedDataIter // Daten in selektierten Bereichen durchgehen 432 { 433 const ScColumn* pColumn; 434 SCSIZE nPos; 435 ScMarkArrayIter* pMarkIter; 436 SCROW nTop; 437 SCROW nBottom; 438 sal_Bool bNext; 439 sal_Bool bAll; 440 441 public: 442 ScMarkedDataIter( const ScColumn* pCol, const ScMarkData* pMarkData, 443 sal_Bool bAllIfNone = sal_False ); 444 ~ScMarkedDataIter(); 445 446 sal_Bool Next( SCSIZE& rIndex ); 447 }; 448 449 450 #endif 451 452 453