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