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