xref: /aoo4110/main/sc/source/filter/inc/xistyle.hxx (revision b1cdbd2c)
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_XISTYLE_HXX
25 #define SC_XISTYLE_HXX
26 
27 #include <list>
28 #include <tools/mempool.hxx>
29 #include <svl/lstner.hxx>
30 #include "rangelst.hxx"
31 #include "patattr.hxx"
32 #include "xladdress.hxx"
33 #include "xlstyle.hxx"
34 #include "xiroot.hxx"
35 
36 class ScDocumentPool;
37 
38 /* ============================================================================
39 - Buffers for style records (PALETTE, FONT, FORMAT, XF)
40     and a container for XF indexes for every used cell in a sheet.
41 ============================================================================ */
42 
43 // PALETTE record - color information =========================================
44 
45 /** Stores the default colors for the current BIFF version and the contents of
46     a PALETTE record. */
47 class XclImpPalette : public XclDefaultPalette
48 {
49 public:
50     explicit            XclImpPalette( const XclImpRoot& rRoot );
51 
52     /** Clears all buffered data, used to set up for a new sheet. */
53     void                Initialize();
54 
55     /** Returns the RGB color data for a (non-zero-based) Excel palette entry.
56         @descr  First looks for a color read from file, then looks for a default color.
57         @return  The color from current or default palette or COL_AUTO, if nothing else found. */
58     ColorData           GetColorData( sal_uInt16 nXclIndex ) const;
59     /** Returns the color for a (non-zero-based) Excel palette entry.
60         @descr  First looks for a color read from file, then looks for a default color.
61         @return  The color from current or default palette or COL_AUTO, if nothing else found. */
GetColor(sal_uInt16 nXclIndex) const62     inline Color        GetColor( sal_uInt16 nXclIndex ) const
63                             { return Color( GetColorData( nXclIndex ) ); }
64     /** Returns the palette colors as UNO sequence. */
65     ::com::sun::star::uno::Sequence< sal_Int32 >
66                         CreateColorSequence() const;
67 
68     /** Reads a PALETTE record. */
69     void                ReadPalette( XclImpStream& rStrm );
70 
71 private:
72     typedef ::std::vector< ColorData > ColorDataVec;
73     ColorDataVec        maColorTable;       /// Colors read from file.
74 };
75 
76 // FONT record - font information =============================================
77 
78 /** Stores all data of an Excel font and provides import of FONT records. */
79 class XclImpFont : protected XclImpRoot
80 {
81 public:
82     explicit            XclImpFont( const XclImpRoot& rRoot );
83 
84     /** Constructs a font from font data.
85         @descr  Special handling for font style (bold, italic) in font name,
86         overwrites settings in rFontData. */
87     explicit            XclImpFont( const XclImpRoot& rRoot, const XclFontData& rFontData );
88 
89     /** Sets all font attributes to used or unused. */
90     void                SetAllUsedFlags( bool bUsed );
91     /** Sets the passed font data and all used flags to 'used'. */
92     void                SetFontData( const XclFontData& rFontData, bool bHasCharSet );
93 
94     /** Returns read-only access to font data. */
GetFontData() const95     inline const XclFontData& GetFontData() const { return maData; }
96     /** Returns true, if the font character set is valid. */
HasCharSet() const97     inline bool         HasCharSet() const { return mbHasCharSet; }
98     /** Returns true, if the font contains superscript or subscript. */
HasEscapement() const99     inline bool         HasEscapement() const { return maData.mnEscapem != EXC_FONTESC_NONE; }
100     /** Returns the text encoding for strings used with this font. */
101     rtl_TextEncoding    GetFontEncoding() const;
102 
103     /** Returns true, if this font contains characters for Western scripts. */
HasWesternChars() const104     inline bool         HasWesternChars() const { return mbHasWstrn; }
105     /** Returns true, if this font contains characters for Asian scripts (CJK). */
HasAsianChars() const106     inline bool         HasAsianChars() const { return mbHasAsian; }
107     /** Returns true, if this font contains characters for Complex scripts (CTL). */
HasComplexChars() const108     inline bool         HasComplexChars() const { return mbHasCmplx; }
109 
110     /** Reads a FONT record for all BIFF versions. */
111     void                ReadFont( XclImpStream& rStrm );
112     /** Reads an EFONT record (BIFF2 font color). */
113     void                ReadEfont( XclImpStream& rStrm );
114     /** Reads the font block from a CF (conditional format) record. */
115     void                ReadCFFontBlock( XclImpStream& rStrm );
116 
117     /** Fills all font properties to the item set.
118         @param rItemSet  The destination item set.
119         @param eType  The type of Which-IDs.
120         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
121     void                FillToItemSet( SfxItemSet& rItemSet, XclFontItemType eType,
122                             bool bSkipPoolDefs = false ) const;
123     /** Writes all font properties to the passed property set.
124         @param pFontColor  If set, overrides internal stored font color. */
125     void                WriteFontProperties( ScfPropertySet& rPropSet,
126                             XclFontPropSetType eType, const Color* pFontColor = 0 ) const;
127 
128 private:
129     /** Reads and sets height and flags. */
130     void                ReadFontData2( XclImpStream& rStrm );
131     /** Reads and sets height, flags, color, boldness, script, family and charset. */
132     void                ReadFontData5( XclImpStream& rStrm );
133 
134     /** Reads and sets the font color. */
135     void                ReadFontColor( XclImpStream& rStrm );
136 
137     /** Reads and sets a byte string as font name. */
138     void                ReadFontName2( XclImpStream& rStrm );
139     /** Reads and sets a Unicode string as font name. */
140     void                ReadFontName8( XclImpStream& rStrm );
141 
142     /** Tests whether the font contains CJK or CTL characters.
143         @descr  This is only a weak guess using preselected characters. */
144     void                GuessScriptType();
145 
146 private:
147     XclFontData         maData;         /// All font attributes.
148     bool                mbHasCharSet;   /// true = Font contains own character set info.
149     bool                mbHasWstrn;     /// true = Font contains Western script characters.
150     bool                mbHasAsian;     /// true = Font contains Asian script characters.
151     bool                mbHasCmplx;     /// true = Font contains Complex script characters.
152     bool                mbFontNameUsed; /// true = Font name, family, charset used.
153     bool                mbHeightUsed;   /// true = Font height used.
154     bool                mbColorUsed;    /// true = Color used.
155     bool                mbWeightUsed;   /// true = Weight used.
156     bool                mbEscapemUsed;  /// true = Escapement type used.
157     bool                mbUnderlUsed;   /// true = Underline style used.
158     bool                mbItalicUsed;   /// true = Italic used.
159     bool                mbStrikeUsed;   /// true = Strikeout used.
160     bool                mbOutlineUsed;  /// true = Outlined used.
161     bool                mbShadowUsed;   /// true = Shadowed used.
162 };
163 
164 // ----------------------------------------------------------------------------
165 
166 /** Stores the data of all fonts occurred in an Excel file. */
167 class XclImpFontBuffer : protected XclImpRoot, ScfNoCopy
168 {
169 public:
170     explicit            XclImpFontBuffer( const XclImpRoot& rRoot );
171 
172     /** Clears all buffered data, used to set up for a new sheet. */
173     void                Initialize();
174 
175     /** Returns the object that stores all contents of a FONT record. */
176     const XclImpFont*   GetFont( sal_uInt16 nFontIndex ) const;
177     /** Returns the application font data of this file, needed i.e. for column width. */
GetAppFontData() const178     inline const XclFontData& GetAppFontData() const { return maAppFont; }
179 
180     /** Reads a FONT record. */
181     void                ReadFont( XclImpStream& rStrm );
182     /** Reads an EFONT record (BIFF2 font color). */
183     void                ReadEfont( XclImpStream& rStrm );
184 
185     /** Fills all font properties from a FONT record to the item set.
186         @param rItemSet  The destination item set.
187         @param eType  The type of Which-IDs.
188         @param nFontIdx  The Excel index of the font.
189         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
190     void                FillToItemSet( SfxItemSet& rItemSet, XclFontItemType eType,
191                             sal_uInt16 nFontIdx, bool bSkipPoolDefs = false ) const;
192     /** Writes all font properties to the passed property set.
193         @param pFontColor  If set, overrides internal stored font color. */
194     void                WriteFontProperties(
195                             ScfPropertySet& rPropSet, XclFontPropSetType eType,
196                             sal_uInt16 nFontIdx, const Color* pFontColor = 0 ) const;
197     /** Writes default font properties for form controls to the passed property set. */
198     void                WriteDefaultCtrlFontProperties( ScfPropertySet& rPropSet ) const;
199 
200 private:
201     /** Updates the application default font. */
202     void                UpdateAppFont( const XclFontData& rFontData, bool bHasCharSet );
203 
204 private:
205     ScfDelList< XclImpFont > maFontList;    /// List of all FONT records in the Excel file.
206     XclFontData         maAppFont;          /// Application font (for column width).
207     XclImpFont          maFont4;            /// Built-in font with index 4.
208     XclImpFont          maCtrlFont;         /// BIFF5 default form controls font (Helv,8pt,bold).
209 };
210 
211 // FORMAT record - number formats =============================================
212 
213 /** Stores all user defined number formats occured in the file. */
214 class XclImpNumFmtBuffer : public XclNumFmtBuffer, protected XclImpRoot
215 {
216 public:
217     explicit            XclImpNumFmtBuffer( const XclImpRoot& rRoot );
218 
219     /** Clears all buffered data, used to set up for a new sheet. */
220     void                Initialize();
221 
222     /** Reads a FORMAT record. */
223     void                ReadFormat( XclImpStream& rStrm );
224     /** Creates the number formats in the Calc document. */
225     void                CreateScFormats();
226 
227     /** Returns the format key with the passed Excel index or NUMBERFORMAT_ENTRY_NOT_FOUND on error. */
228     sal_uLong               GetScFormat( sal_uInt16 nXclNumFmt ) const;
229 
230     /** Fills an Excel number format to the passed item set.
231         @param rItemSet  The destination item set.
232         @param nXclNumFmt  The Excel number format index.
233         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
234     void                FillToItemSet(
235                             SfxItemSet& rItemSet, sal_uInt16 nXclNumFmt,
236                             bool bSkipPoolDefs = false ) const;
237     /** Fills a Calc number format to the passed item set.
238         @param rItemSet  The destination item set.
239         @param nScNumFmt  The Calc number formatter index of the format.
240         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
241     void                FillScFmtToItemSet(
242                             SfxItemSet& rItemSet, sal_uLong nScNumFmt,
243                             bool bSkipPoolDefs = false ) const;
244 
245 private:
246     typedef ::std::map< sal_uInt16, sal_uLong > XclImpIndexMap;
247 
248     XclImpIndexMap      maIndexMap;     /// Maps Excel format indexes to Calc formats.
249     sal_uInt16          mnNextXclIdx;   /// Index counter for BIFF2-BIFF4.
250 };
251 
252 // XF, STYLE record - Cell formatting =========================================
253 
254 /** Extends the XclCellProt struct for import.
255     @descr  Provides functions to fill from Excel record data and to fill to item sets. */
256 struct XclImpCellProt : public XclCellProt
257 {
258     /** Fills this struct with BIFF2 XF record data. */
259     void                FillFromXF2( sal_uInt8 nNumFmt );
260     /** Fills this struct with BIFF3-BIFF8 XF record data. */
261     void                FillFromXF3( sal_uInt16 nProt );
262 
263     /** Inserts items representing this protection style into the item set.
264         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
265     void                FillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
266 };
267 
268 // ----------------------------------------------------------------------------
269 
270 /** Extends the XclCellAlign struct for import.
271     @descr  Provides functions to fill from Excel record data and to fill to item sets. */
272 struct XclImpCellAlign : public XclCellAlign
273 {
274     /** Fills this struct with BIFF2 XF record data. */
275     void                FillFromXF2( sal_uInt8 nFlags );
276     /** Fills this struct with BIFF3 XF record data. */
277     void                FillFromXF3( sal_uInt16 nAlign );
278     /** Fills this struct with BIFF4 XF record data. */
279     void                FillFromXF4( sal_uInt16 nAlign );
280     /** Fills this struct with BIFF5/BIFF7 XF record data. */
281     void                FillFromXF5( sal_uInt16 nAlign );
282     /** Fills this struct with BIFF8 XF record data. */
283     void                FillFromXF8( sal_uInt16 nAlign, sal_uInt16 nMiscAttrib );
284 
285     /** Inserts items representing this alignment style into the item set.
286         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
287     void                FillToItemSet( SfxItemSet& rItemSet, const XclImpFont* pFont, bool bSkipPoolDefs = false ) const;
288 };
289 
290 // ----------------------------------------------------------------------------
291 
292 /** Extends the XclCellBorder struct for import.
293     @descr  Provides functions to fill from Excel record data and to fill to item sets. */
294 struct XclImpCellBorder : public XclCellBorder
295 {
296     bool                mbLeftUsed;     /// true = Left line style used.
297     bool                mbRightUsed;    /// true = Right line style used.
298     bool                mbTopUsed;      /// true = Top line style used.
299     bool                mbBottomUsed;   /// true = Bottom line style used.
300     bool                mbDiagUsed;     /// true = Diagonal line style used.
301 
302     explicit            XclImpCellBorder();
303 
304     /** Sets outer line states and diagonal line states to used or unused. */
305     void                SetUsedFlags( bool bOuterUsed, bool bDiagUsed );
306 
307     /** Fills this struct with BIFF2 XF record data. */
308     void                FillFromXF2( sal_uInt8 nFlags );
309     /** Fills this struct with BIFF3/BIFF4 XF record data. */
310     void                FillFromXF3( sal_uInt32 nBorder );
311     /** Fills this struct with BIFF5/BIFF7 XF record data. */
312     void                FillFromXF5( sal_uInt32 nBorder, sal_uInt32 nArea );
313     /** Fills this struct with BIFF8 XF record data. */
314     void                FillFromXF8( sal_uInt32 nBorder1, sal_uInt32 nBorder2 );
315 
316     /** Fills this struct with BIFF8 CF (conditional format) record data. */
317     void                FillFromCF8( sal_uInt16 nLineStyle, sal_uInt32 nLineColor, sal_uInt32 nFlags );
318 
319     /** Returns true, if any of the outer border lines is visible. */
320     bool                HasAnyOuterBorder() const;
321 
322     /** Inserts a box item representing this border style into the item set.
323         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
324     void                FillToItemSet(
325                             SfxItemSet& rItemSet,
326                             const XclImpPalette& rPalette,
327                             bool bSkipPoolDefs = false ) const;
328 };
329 
330 // ----------------------------------------------------------------------------
331 
332 /** Extends the XclCellArea struct for import.
333     @descr  Provides functions to fill from Excel record data and to fill to item sets. */
334 struct XclImpCellArea : public XclCellArea
335 {
336     bool                mbForeUsed;     /// true = Foreground color used.
337     bool                mbBackUsed;     /// true = Background color used.
338     bool                mbPattUsed;     /// true = Pattern used.
339 
340     explicit            XclImpCellArea();
341 
342     /** Sets colors and pattern state to used or unused. */
343     void                SetUsedFlags( bool bUsed );
344 
345     /** Fills this struct with BIFF2 XF record data. */
346     void                FillFromXF2( sal_uInt8 nFlags );
347     /** Fills this struct with BIFF3/BIFF4 XF record data. */
348     void                FillFromXF3( sal_uInt16 nArea );
349     /** Fills this struct with BIFF5/BIFF7 XF record data. */
350     void                FillFromXF5( sal_uInt32 nArea );
351     /** Fills this struct with BIFF8 XF record data. */
352     void                FillFromXF8( sal_uInt32 nBorder2, sal_uInt16 nArea );
353 
354     /** Fills this struct with BIFF8 CF (conditional format) record data. */
355     void                FillFromCF8( sal_uInt16 nPattern, sal_uInt16 nColor, sal_uInt32 nFlags );
356 
357     /** Inserts a brush item representing this area style into the item set.
358         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
359     void                FillToItemSet(
360                             SfxItemSet& rItemSet,
361                             const XclImpPalette& rPalette,
362                             bool bSkipPoolDefs = false ) const;
363 };
364 
365 // ----------------------------------------------------------------------------
366 
367 /** Represents an XF record index with additional information. */
368 class XclImpXFIndex
369 {
370 public:
XclImpXFIndex(sal_uInt16 nXFIndex,bool bBoolCell=false)371     inline explicit     XclImpXFIndex( sal_uInt16 nXFIndex, bool bBoolCell = false ) :
372                             mnXFIndex( nXFIndex ), mbBoolCell( bBoolCell ) {}
373 
GetXFIndex() const374     inline sal_uInt16   GetXFIndex() const { return mnXFIndex; }
IsBoolCell() const375     inline bool         IsBoolCell() const { return mbBoolCell; }
376 
377 private:
378     sal_uInt16          mnXFIndex;      /// The XF record index.
379     bool                mbBoolCell;     /// true = A Boolean value cell.
380 };
381 
operator ==(const XclImpXFIndex & rLeft,const XclImpXFIndex & rRight)382 inline bool operator==( const XclImpXFIndex& rLeft, const XclImpXFIndex& rRight )
383 { return (rLeft.GetXFIndex() == rRight.GetXFIndex()) && (rLeft.IsBoolCell() == rRight.IsBoolCell()); }
384 
operator !=(const XclImpXFIndex & rLeft,const XclImpXFIndex & rRight)385 inline bool operator!=( const XclImpXFIndex& rLeft, const XclImpXFIndex& rRight )
386 { return !(rLeft == rRight); }
387 
388 // ----------------------------------------------------------------------------
389 
390 /** Contains all data of a XF record and a Calc item set. */
391 class XclImpXF : public XclXFBase, protected XclImpRoot, ScfNoCopy, public SfxListener
392 {
393 public:
394     explicit            XclImpXF( const XclImpRoot& rRoot );
395     virtual             ~XclImpXF();
396 
397     /** Reads an XF record. */
398     void                ReadXF( XclImpStream& rStrm );
399 
GetHorAlign() const400     inline sal_uInt8    GetHorAlign() const { return maAlignment.mnHorAlign; }
GetVerAlign() const401     inline sal_uInt8    GetVerAlign() const { return maAlignment.mnVerAlign; }
GetFontIndex() const402     inline sal_uInt16   GetFontIndex() const { return mnXclFont; }
403 
404     /** Creates a Calc item set containing an item set with all cell properties.
405         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items.
406         @return  A read-only reference to the item set stored internally. */
407     const ScPatternAttr& CreatePattern( bool bSkipPoolDefs = false );
408 
409     /** Inserts all formatting attributes to the specified area in the Calc document.
410         @param nForcedNumFmt  If not set to NUMBERFORMAT_ENTRY_NOT_FOUND, it will overwrite
411         the number format of the XF. */
412     void                ApplyPattern(
413                             SCCOL nScCol1, SCROW nScRow1,
414                             SCCOL nScCol2, SCROW nScRow2,
415                             SCTAB nScTab,
416                             sal_uLong nForceScNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND );
417 	virtual void 		Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
418     /** Converts formatting information from BIFF2 cell record data directly. */
419     static void         ApplyPatternForBiff2CellFormat(
420                             const XclImpRoot& rRoot, const ScAddress& rScPos,
421                             sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 );
422 
423 private:
424     void                ReadXF2( XclImpStream& rStrm );
425     void                ReadXF3( XclImpStream& rStrm );
426     void                ReadXF4( XclImpStream& rStrm );
427     void                ReadXF5( XclImpStream& rStrm );
428     void                ReadXF8( XclImpStream& rStrm );
429 
430     /** Sets all "attribute used" flags according to the passed mask.
431         @descr  In cell XFs, a set bit represents "used", in style XFs it is a cleared bit.
432         Therefore mbCellXF must be set correctly before calling this method. */
433     void                SetUsedFlags( sal_uInt8 nUsedFlags );
434 
435 private:
436     typedef ::std::auto_ptr< ScPatternAttr > ScPatternAttrPtr;
437 
438     ScPatternAttrPtr    mpPattern;          /// Calc item set.
439 	const ScPatternAttr*    mpPooledPattern;
440     ScStyleSheet*       mpStyleSheet;       /// Calc cell style sheet.
441 
442     XclImpCellProt      maProtection;       /// Cell protection flags.
443     XclImpCellAlign     maAlignment;        /// All alignment attributes.
444     XclImpCellBorder    maBorder;           /// Border line style.
445     XclImpCellArea      maArea;             /// Background area style.
446     sal_uInt16          mnXclNumFmt;        /// Index to number format.
447     sal_uInt16          mnXclFont;          /// Index to font record.
448 };
449 
450 // ----------------------------------------------------------------------------
451 
452 /** Contains all data of a cell style associated with an XF record. */
453 class XclImpStyle : protected XclImpRoot
454 {
455 public:
456     explicit            XclImpStyle( const XclImpRoot& rRoot );
457 
458     /** Reads a STYLE record. */
459     void                ReadStyle( XclImpStream& rStrm );
460 
GetName() const461     inline const String& GetName() const { return maName; }
GetXfId() const462     inline sal_uInt16   GetXfId() const { return mnXfId; }
IsBuiltin() const463     inline bool         IsBuiltin() const { return mbBuiltin && (mnBuiltinId != EXC_STYLE_USERDEF); }
GetBuiltinId() const464     inline sal_uInt8    GetBuiltinId() const { return mnBuiltinId; }
GetLevel() const465     inline sal_uInt8    GetLevel() const { return mnLevel; }
466 
467     /** Creates a cell style sheet and inserts it into the Calc document.
468         @return  The pointer to the cell style sheet, or 0, if there is no style sheet. */
469     ScStyleSheet*       CreateStyleSheet();
470     /** Creates the Calc style sheet, if this is a user-defined style. */
471     void                CreateUserStyle( const String& rFinalName );
472 
473 private:
474     String              maName;             /// Cell style name.
475     sal_uInt16          mnXfId;             /// Formatting for this cell style.
476     sal_uInt8           mnBuiltinId;        /// Identifier for builtin styles.
477     sal_uInt8           mnLevel;            /// Level for builtin column/row styles.
478     bool                mbBuiltin;          /// True = builtin style.
479     bool                mbCustom;           /// True = customized builtin style.
480     bool                mbHidden;           /// True = style not visible in GUI.
481 
482     String              maFinalName;        /// Final name used in the Calc document.
483     ScStyleSheet*       mpStyleSheet;       /// Calc cell style sheet.
484 };
485 
486 // ----------------------------------------------------------------------------
487 
488 /** Contains all XF records occured in the file.
489     @descr  This class is able to read XF records (BIFF2 - BIFF8) and STYLE records (BIFF8). */
490 class XclImpXFBuffer : protected XclImpRoot, ScfNoCopy
491 {
492 public:
493     explicit            XclImpXFBuffer( const XclImpRoot& rRoot );
494 
495     /** Clears all buffered data, used to set up for a new sheet. */
496     void                Initialize();
497 
498     /** Reads an XF record. */
499     void                ReadXF( XclImpStream& rStrm );
500     /** Reads a STYLE record. */
501     void                ReadStyle( XclImpStream& rStrm );
502 
503     /** Returns the object that stores all contents of an XF record. */
GetXF(sal_uInt16 nXFIndex) const504     inline XclImpXF*    GetXF( sal_uInt16 nXFIndex ) const
505                             { return maXFList.GetObject( nXFIndex ); }
506 
507     /** Returns the index to the Excel font used in the specified XF record. */
508     sal_uInt16          GetFontIndex( sal_uInt16 nXFIndex ) const;
509     /** Returns the Excel font used in the specified XF record. */
510     const XclImpFont*   GetFont( sal_uInt16 nXFIndex ) const;
511 
512     /** Creates all user defined style sheets. */
513     void                CreateUserStyles();
514     /** Creates a cell style sheet of the passed XF and inserts it into the Calc document.
515         @return  The pointer to the cell style sheet, or 0, if there is no style sheet. */
516     ScStyleSheet*       CreateStyleSheet( sal_uInt16 nXFIndex );
517 
518     /** Inserts formatting attributes from an XF to the specified area in the Calc document.
519         @param nForcedNumFmt  If not set to NUMBERFORMAT_ENTRY_NOT_FOUND, it will overwrite
520         the number format of the XF. */
521     void                ApplyPattern(
522                             SCCOL nScCol1, SCROW nScRow1,
523                             SCCOL nScCol2, SCROW nScRow2,
524                             SCTAB nScTab, const XclImpXFIndex& rXFIndex );
525 
526 private:
527     typedef ScfDelList< XclImpStyle >               XclImpStyleList;
528     typedef ::std::map< sal_uInt16, XclImpStyle* >  XclImpStyleMap;
529 
530     ScfDelList< XclImpXF > maXFList;        /// List of contents of all XF record.
531     XclImpStyleList     maBuiltinStyles;    /// List of built-in cell styles.
532     XclImpStyleList     maUserStyles;       /// List of user defined cell styles.
533     XclImpStyleMap      maStylesByXf;       /// Maps XF records to cell styles.
534 };
535 
536 // Buffer for XF indexes in cells =============================================
537 
538 /** Contains an (encoded) XF index for a range of rows in a single column. */
539 class XclImpXFRange
540 {
541     DECL_FIXEDMEMPOOL_NEWDEL( XclImpXFRange )
542 
543 public:
544     SCROW               mnScRow1;       /// The first row of an equal-formatted range.
545     SCROW               mnScRow2;       /// The last row of an equal-formatted range.
546     XclImpXFIndex       maXFIndex;      /// Extended XF index.
547 
548     inline explicit     XclImpXFRange( SCROW nScRow, const XclImpXFIndex& rXFIndex );
549     inline explicit     XclImpXFRange( SCROW nFirstScRow, SCROW nLastScRow, const XclImpXFIndex& rXFIndex );
550 
551     /** Returns true, if nScRow is contained in own row range. */
552     inline bool         Contains( SCROW nScRow ) const;
553 
554     /** Returns true, if the range has been expanded. */
555     bool                Expand( SCROW nScRow, const XclImpXFIndex& rXFIndex );
556     /** Returns true, if the range has been expanded. */
557     bool                Expand( const XclImpXFRange& rNextRange );
558 };
559 
XclImpXFRange(SCROW nScRow,const XclImpXFIndex & rXFIndex)560 inline XclImpXFRange::XclImpXFRange( SCROW nScRow, const XclImpXFIndex& rXFIndex ) :
561     mnScRow1( nScRow ),
562     mnScRow2( nScRow ),
563     maXFIndex( rXFIndex )
564 {
565 }
566 
XclImpXFRange(SCROW nFirstScRow,SCROW nLastScRow,const XclImpXFIndex & rXFIndex)567 inline XclImpXFRange::XclImpXFRange( SCROW nFirstScRow, SCROW nLastScRow, const XclImpXFIndex& rXFIndex ) :
568     mnScRow1( nFirstScRow ),
569     mnScRow2( nLastScRow ),
570     maXFIndex( rXFIndex )
571 {
572 }
573 
Contains(SCROW nScRow) const574 inline bool XclImpXFRange::Contains( SCROW nScRow ) const
575 {
576     return (mnScRow1 <= nScRow) && (nScRow <= mnScRow2);
577 }
578 
579 // ----------------------------------------------------------------------------
580 
581 /** Contains the XF indexes for every used cell in a column. */
582 class XclImpXFRangeColumn : ScfNoCopy
583 {
584 public:
XclImpXFRangeColumn()585     inline explicit     XclImpXFRangeColumn() {}
586 
587     /** Returns the first formatted cell range in this column. */
First()588     inline XclImpXFRange* First() { return maIndexList.First(); }
589     /** Returns the next formatted cell range in this column. */
Next()590     inline XclImpXFRange* Next() { return maIndexList.Next(); }
591 
592     /** Inserts a single row range into the list. */
593     void                SetDefaultXF( const XclImpXFIndex& rXFIndex );
594 
595     /** Inserts a new (encoded) XF index (first try to expand the last range). */
596     void                SetXF( SCROW nScRow, const XclImpXFIndex& rXFIndex );
597 
598 private:
599     /** Finds the previous and next row range from row position nScRow.
600         @descr  If an XF still exists, it is contained in rpPrevRange. */
601     void                Find(
602                             XclImpXFRange*& rpPrevRange,
603                             XclImpXFRange*& rpNextRange,
604                             sal_uLong& rnNextIndex,
605                             SCROW nScRow ) const;
606 
607     /** Tries to concatenate a range with its predecessor.
608         @descr  The ranges must have the same XF index and must not have a gap.
609         The resulting range has the index nIndex-1. */
610     void                TryConcatPrev( sal_uLong nIndex );
611 
612 private:
613     ScfDelList< XclImpXFRange > maIndexList;    /// The list of XF index range.
614 };
615 
616 // ----------------------------------------------------------------------------
617 
618 /** Contains the XF indexes for every used cell in a single sheet. */
619 class XclImpXFRangeBuffer : protected XclImpRoot, ScfNoCopy
620 {
621 public:
622     explicit            XclImpXFRangeBuffer( const XclImpRoot& rRoot );
623     virtual             ~XclImpXFRangeBuffer();
624 
625     /** Clears all buffered data, used to set up for a new sheet. */
626     void                Initialize();
627 
628     /** Inserts a new XF index. */
629     void                SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
630     /** Inserts a new XF index for blank cells. */
631     void                SetBlankXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
632     /** Inserts a new XF index for boolean cells. */
633     void                SetBoolXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
634     /** Inserts a new XF index for all cells in a row. */
635     void                SetRowDefXF( SCROW nScRow, sal_uInt16 nXFIndex );
636     /** Inserts a new XF index for all cells in a column. */
637     void                SetColumnDefXF( SCCOL nScCol, sal_uInt16 nXFIndex );
638 
639     /** Inserts a range of hyperlink cells. */
640     void                SetHyperlink( const XclRange& rXclRange, const String& rUrl );
641 
642     /** Inserts the first cell of a merged cell range. */
643     void                SetMerge( SCCOL nScCol, SCROW nScRow );
644     /** Inserts a complete merged cell range. */
645     void                SetMerge( SCCOL nScCol1, SCROW nScRow1, SCCOL nScCol2, SCROW nScRow2 );
646 
647     /** Applies styles and cell merging to the current sheet in the document. */
648     void                Finalize();
649 
650 private:
651     /** Insertion mode of an XF index. */
652     enum XclImpXFInsertMode
653     {
654         xlXFModeCell,               /// Filled cell.
655         xlXFModeBoolCell,           /// Cell with a single Boolean value.
656         xlXFModeBlank,              /// Blank cell.
657         xlXFModeRow                 /// Row default XF.
658     };
659 
660 private:
661     /** Inserts a new XF index for the specified cell type. */
662     void                SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex, XclImpXFInsertMode eMode );
663 
664     /** Copies border of the last cell of the range to the first cell to keep it visible
665         when the range is merged.
666         @param nLine
667         BOX_LINE_RIGHT = copy most-right border of top row;
668         BOX_LINE_BOTTOM = copy most-bottom border of first column. */
669     void                SetBorderLine( const ScRange& rRange, SCTAB nScTab, sal_uInt16 nLine );
670 
671 private:
672     typedef ScfRef< XclImpXFRangeColumn >           XclImpXFRangeColumnRef;
673     typedef ::std::vector< XclImpXFRangeColumnRef > XclImpXFRangeColumnVec;
674     typedef ::std::pair< XclRange, String >         XclImpHyperlinkRange;
675     typedef ::std::list< XclImpHyperlinkRange >     XclImpHyperlinkList;
676 
677     XclImpXFRangeColumnVec maColumns;       /// Array of column XF index buffers.
678     XclImpHyperlinkList maHyperlinks;       /// Maps URLs to hyperlink cells.
679     ScRangeList         maMergeList;        /// List of merged cell ranges.
680 };
681 
682 // ============================================================================
683 
684 #endif
685 
686