Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_XESTYLE_HXX
30 : : #define SC_XESTYLE_HXX
31 : :
32 : : #include <map>
33 : : #include <tools/mempool.hxx>
34 : : #include <tools/string.hxx>
35 : : #include <svl/zforlist.hxx>
36 : : #include <svl/nfkeytab.hxx>
37 : : #include <editeng/svxfont.hxx>
38 : : #include "xerecord.hxx"
39 : : #include "xlstyle.hxx"
40 : : #include "xeroot.hxx"
41 : : #include "conditio.hxx"
42 : : #include <boost/shared_ptr.hpp>
43 : : #include <boost/scoped_ptr.hpp>
44 : : #include <boost/ptr_container/ptr_vector.hpp>
45 : :
46 : : /* ============================================================================
47 : : - Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
48 : : ============================================================================ */
49 : :
50 : : const sal_uInt16 EXC_ID_FONTLIST = 0x8031; /// For internal use only.
51 : : const sal_uInt16 EXC_ID_FORMATLIST = 0x801E; /// For internal use only.
52 : : const sal_uInt16 EXC_ID_XFLIST = 0x8043; /// For internal use only.
53 : : const sal_uInt16 EXC_ID_DXFS = 0x9999; /// For internal use only. TODO:moggi: find a better/correct value
54 : :
55 : : // PALETTE record - color information =========================================
56 : :
57 : : /** Different types of colors in a document. */
58 : : enum XclExpColorType
59 : : {
60 : : EXC_COLOR_CELLTEXT, /// Text in a cell.
61 : : EXC_COLOR_CELLBORDER, /// Border of a cell.
62 : : EXC_COLOR_CELLAREA, /// Background area of a cell.
63 : : EXC_COLOR_CHARTTEXT, /// Text color in a chart.
64 : : EXC_COLOR_CHARTLINE, /// Line in a chart.
65 : : EXC_COLOR_CHARTAREA, /// Area in a chart.
66 : : EXC_COLOR_CTRLTEXT, /// Text color in a form control.
67 : : EXC_COLOR_GRID, /// Spreadsheet grid color.
68 : : EXC_COLOR_TABBG /// Spreadsheet tab bg color.
69 : : };
70 : :
71 : : // ----------------------------------------------------------------------------
72 : :
73 : : class XclExpPaletteImpl;
74 : :
75 : : /** Stores all used colors in the document.
76 : :
77 : : Supports color reduction to the maximum count of the current BIFF version.
78 : : An instance of this class collects all colors in the conversion phase of
79 : : the export, using the InsertColor() function. It returns a unique
80 : : identidier for each passed color.
81 : :
82 : : After the entire document is converted, the Finalize() function will reduce
83 : : the palette to the number of colors supported by the current BIFF version.
84 : :
85 : : Then, in the streaming phase, the functions GetColorIndex() and
86 : : GetMixedColors() return the real Excel palette index for all color
87 : : identifiers.
88 : : */
89 : : class XclExpPalette : public XclDefaultPalette, public XclExpRecord
90 : : {
91 : : public:
92 : : explicit XclExpPalette( const XclExpRoot& rRoot );
93 : : virtual ~XclExpPalette();
94 : :
95 : : /** Inserts the color into the list and updates weighting.
96 : : @param nAutoDefault The Excel palette index for automatic color.
97 : : @return A unique ID for this color. */
98 : : sal_uInt32 InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault = 0 );
99 : : /** Returns the color ID representing a fixed Excel palette index (i.e. for auto colors). */
100 : : static sal_uInt32 GetColorIdFromIndex( sal_uInt16 nIndex );
101 : :
102 : : /** Reduces the color list to the maximum count of the current BIFF version. */
103 : : void Finalize();
104 : :
105 : : /** Returns the Excel palette index of the color with passed color ID. */
106 : : sal_uInt16 GetColorIndex( sal_uInt32 nColorId ) const;
107 : :
108 : : /** Returns a foreground and background color for the two passed color IDs.
109 : : @descr If rnXclPattern contains a solid pattern, this function tries to find
110 : : the two best fitting colors and a mix pattern (25%, 50% or 75%) for nForeColorId.
111 : : This will result in a better approximation to the passed foreground color. */
112 : : void GetMixedColors(
113 : : sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
114 : : sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const;
115 : :
116 : : /** Returns the RGB color data for a (non-zero-based) Excel palette entry.
117 : : @return The color from current or default palette or COL_AUTO, if nothing else found. */
118 : : ColorData GetColorData( sal_uInt16 nXclIndex ) const;
119 : : /** Returns the color for a (non-zero-based) Excel palette entry.
120 : : @return The color from current or default palette or COL_AUTO, if nothing else found. */
121 : 0 : inline Color GetColor( sal_uInt16 nXclIndex ) const
122 : 0 : { return Color( GetColorData( nXclIndex ) ); }
123 : :
124 : : /** Saves the PALETTE record, if it differs from the default palette. */
125 : : virtual void Save( XclExpStream& rStrm );
126 : : virtual void SaveXml( XclExpXmlStream& rStrm );
127 : :
128 : : private:
129 : : /** Writes the contents of the PALETTE record. */
130 : : virtual void WriteBody( XclExpStream& rStrm );
131 : :
132 : : private:
133 : : typedef boost::shared_ptr< XclExpPaletteImpl > XclExpPaletteImplRef;
134 : : XclExpPaletteImplRef mxImpl;
135 : : };
136 : :
137 : : // FONT record - font information =============================================
138 : :
139 : : class Font;
140 : : class SvxFont;
141 : :
142 : : const size_t EXC_FONTLIST_NOTFOUND = static_cast< size_t >( -1 );
143 : :
144 : : // ----------------------------------------------------------------------------
145 : :
146 : : /** Static helper functions for font export. */
147 : : class XclExpFontHelper
148 : : {
149 : : public:
150 : : /** Returns the script type of the first font item found in the item set and its parents. */
151 : : static sal_Int16 GetFirstUsedScript(
152 : : const XclExpRoot& rRoot,
153 : : const SfxItemSet& rItemSet );
154 : :
155 : : /** Returns a VCL font object filled from the passed item set. */
156 : : static Font GetFontFromItemSet(
157 : : const XclExpRoot& rRoot,
158 : : const SfxItemSet& rItemSet,
159 : : sal_Int16 nScript );
160 : :
161 : : /** Returns true, if at least one font related item is set in the passed item set.
162 : : @param bDeep true = Searches in parent item sets too. */
163 : : static bool CheckItems(
164 : : const XclExpRoot& rRoot,
165 : : const SfxItemSet& rItemSet,
166 : : sal_Int16 nScript,
167 : : bool bDeep );
168 : :
169 : : private:
170 : : XclExpFontHelper();
171 : : ~XclExpFontHelper();
172 : : };
173 : :
174 : : // ----------------------------------------------------------------------------
175 : :
176 : : /** Stores all data of an Excel font and provides export of FONT records. */
177 [ # # ][ # # ]: 0 : class XclExpFont : public XclExpRecord, protected XclExpRoot
[ # # ]
178 : : {
179 : : public:
180 : : explicit XclExpFont( const XclExpRoot& rRoot,
181 : : const XclFontData& rFontData, XclExpColorType eColorType );
182 : :
183 : : /** Returns read-only access to font data. */
184 : 0 : inline const XclFontData& GetFontData() const { return maData; }
185 : : /** Returns the font color identifier. */
186 : 0 : inline sal_uInt32 GetFontColorId() const { return mnColorId; }
187 : : /** Compares this font with the passed font data.
188 : : @param nHash The hash value calculated from the font data. */
189 : : virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
190 : :
191 : : virtual void SaveXml( XclExpXmlStream& rStrm );
192 : :
193 : : private:
194 : : /** Writes the contents of the FONT record. */
195 : : virtual void WriteBody( XclExpStream& rStrm );
196 : :
197 : : private:
198 : : XclFontData maData; /// All font attributes.
199 : : sal_uInt32 mnColorId; /// Unique color ID for text color.
200 : : sal_uInt32 mnHash; /// Hash value for fast comparison.
201 : : };
202 : :
203 : : // ----------------------------------------------------------------------------
204 : :
205 : : /** Used as placeholder for font index 4, which is not used in Excel. */
206 [ # # ]: 0 : class XclExpBlindFont : public XclExpFont
207 : : {
208 : : public:
209 : : explicit XclExpBlindFont( const XclExpRoot& rRoot );
210 : :
211 : : /** Returns always false to never find this font while searching the font list. */
212 : : virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
213 : :
214 : : /** Skips writing this record. */
215 : : virtual void Save( XclExpStream& rStrm );
216 : : };
217 : :
218 : : // ----------------------------------------------------------------------------
219 : :
220 : : class ScPatternAttr;
221 : :
222 : : /** Stores the data of all fonts used in the document. */
223 [ # # ][ # # ]: 0 : class XclExpFontBuffer : public XclExpRecordBase, protected XclExpRoot
[ # # ]
224 : : {
225 : : public:
226 : : explicit XclExpFontBuffer( const XclExpRoot& rRoot );
227 : :
228 : : /** Returns the specified font from font list. */
229 : : const XclExpFont* GetFont( sal_uInt16 nXclFont ) const;
230 : : /** Returns the application font data of this file, needed e.g. for column width. */
231 : : const XclFontData& GetAppFontData() const;
232 : :
233 : : /** Inserts a new font with the passed font data into the buffer if not present.
234 : : @param bAppFont true = Sets the application font; false = Inserts a new font.
235 : : @return The resulting Excel font index. */
236 : : sal_uInt16 Insert( const XclFontData& rFontData,
237 : : XclExpColorType eColorType, bool bAppFont = false );
238 : : /** Inserts the font into the buffer if not present.
239 : : @param bAppFont true = Sets the application font; false = Inserts a new font.
240 : : @return The resulting Excel font index. */
241 : : sal_uInt16 Insert( const Font& rFont,
242 : : XclExpColorType eColorType, bool bAppFont = false );
243 : : /** Inserts the SvxFont into the buffer if not present, e.g. where escapements are used.
244 : : @param bAppFont true = Sets the application font; false = Inserts a new font.
245 : : @return The resulting Excel font index. */
246 : : sal_uInt16 Insert( const SvxFont& rFont,
247 : : XclExpColorType eColorType, bool bAppFont = false );
248 : : /** Inserts the font contained in the passed item set into the buffer, if not present.
249 : : @param nScript The script type of the font properties to be used.
250 : : @param bAppFont true = Sets the application font; false = Inserts a new font.
251 : : @return The resulting Excel font index. */
252 : : sal_uInt16 Insert( const SfxItemSet& rItemSet, sal_Int16 nScript,
253 : : XclExpColorType eColorType, bool bAppFont = false );
254 : :
255 : : /** Writes all FONT records contained in this buffer. */
256 : : virtual void Save( XclExpStream& rStrm );
257 : : virtual void SaveXml( XclExpXmlStream& rStrm );
258 : :
259 : : private:
260 : : /** Initializes the default fonts for the current BIFF version. */
261 : : void InitDefaultFonts();
262 : : /** Tries to find the passed font and returns the current list index. */
263 : : size_t Find( const XclFontData& rFontData );
264 : :
265 : : private:
266 : : typedef XclExpRecordList< XclExpFont > XclExpFontList;
267 : : typedef XclExpFontList::RecordRefType XclExpFontRef;
268 : :
269 : : XclExpFontList maFontList; /// List of all FONT records.
270 : : size_t mnXclMaxSize; /// Maximum number of fonts.
271 : : };
272 : :
273 : : // FORMAT record - number formats =============================================
274 : :
275 : : /** Stores a core number format index with corresponding Excel format index. */
276 : 0 : struct XclExpNumFmt
277 : : {
278 : : sal_uLong mnScNumFmt; /// Core index of the number format.
279 : : sal_uInt16 mnXclNumFmt; /// Resulting Excel format index.
280 : : rtl::OUString maNumFmtString; /// format string
281 : :
282 : 0 : inline explicit XclExpNumFmt( sal_uLong nScNumFmt, sal_uInt16 nXclNumFmt, const rtl::OUString& rFrmt ) :
283 : 0 : mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ), maNumFmtString( rFrmt ) {}
284 : :
285 : : void SaveXml( XclExpXmlStream& rStrm );
286 : : };
287 : :
288 : : // ----------------------------------------------------------------------------
289 : :
290 : : class SvNumberFormatter;
291 : : typedef ::std::auto_ptr< SvNumberFormatter > SvNumberFormatterPtr;
292 : :
293 : : /** Stores all number formats used in the document. */
294 : : class XclExpNumFmtBuffer : public XclExpRecordBase, protected XclExpRoot
295 : : {
296 : : public:
297 : : explicit XclExpNumFmtBuffer( const XclExpRoot& rRoot );
298 : : virtual ~XclExpNumFmtBuffer();
299 : :
300 : : /** Returns the core index of the current standard number format. */
301 : 0 : inline sal_uLong GetStandardFormat() const { return mnStdFmt; }
302 : :
303 : : /** Inserts a number format into the format buffer.
304 : : @param nScNumFmt The core index of the number format.
305 : : @return The resulting Excel format index. */
306 : : sal_uInt16 Insert( sal_uLong nScNumFmt );
307 : :
308 : : /** Writes all FORMAT records contained in this buffer. */
309 : : virtual void Save( XclExpStream& rStrm );
310 : : virtual void SaveXml( XclExpXmlStream& rStrm );
311 : :
312 : : private:
313 : : /** Writes the FORMAT record with index nXclIx and format string rFormatStr. */
314 : : void WriteFormatRecord( XclExpStream& rStrm, sal_uInt16 nXclNumFmt, const String& rFormatStr );
315 : : /** Writes the FORMAT record represented by rFormat. */
316 : : void WriteFormatRecord( XclExpStream& rStrm, const XclExpNumFmt& rFormat );
317 : :
318 : : String GetFormatCode ( sal_uInt16 nScNumFmt );
319 : :
320 : : private:
321 : : typedef ::std::vector< XclExpNumFmt > XclExpNumFmtVec;
322 : :
323 : : SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion.
324 : : XclExpNumFmtVec maFormatMap; /// Maps core formats to Excel indexes.
325 : : boost::scoped_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table.
326 : : sal_uLong mnStdFmt; /// Key for standard number format.
327 : : sal_uInt16 mnXclOffset; /// Offset to first user defined format.
328 : : };
329 : :
330 : : // XF, STYLE record - Cell formatting =========================================
331 : :
332 : : /** Extends the XclCellProt struct for export.
333 : : @descr Provides functions to fill from item sets and to fill to Excel record data. */
334 : 0 : struct XclExpCellProt : public XclCellProt
335 : : {
336 : : /** Fills the protection attributes from the passed item set.
337 : : @return true = At least one protection item is set. */
338 : : bool FillFromItemSet( const SfxItemSet& rItemSet, bool bStyle = false );
339 : :
340 : : /** Fills the data to the passed fields of a BIFF3-BIFF8 XF record. */
341 : : void FillToXF3( sal_uInt16& rnProt ) const;
342 : :
343 : : void SaveXml( XclExpXmlStream& rStrm ) const;
344 : : };
345 : :
346 : : // ----------------------------------------------------------------------------
347 : :
348 : : /** Extends the XclCellAlign struct for export.
349 : : @descr Provides functions to fill from item sets and to fill to Excel record data. */
350 : 0 : struct XclExpCellAlign : public XclCellAlign
351 : : {
352 : : /** Fills the alignment attributes from the passed item set.
353 : : @descr Fills only the attributes exported in the passed BIFF version.
354 : : @param bForceLineBreak true = Set line break flag unconditionally.
355 : : @return true = At least one alignment item is set. */
356 : : bool FillFromItemSet( const SfxItemSet& rItemSet,
357 : : bool bForceLineBreak, XclBiff eBiff, bool bStyle = false );
358 : :
359 : : /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
360 : : void FillToXF5( sal_uInt16& rnAlign ) const;
361 : : /** Fills the data to the passed fields of a BIFF8 XF record. */
362 : : void FillToXF8( sal_uInt16& rnAlign, sal_uInt16& rnMiscAttrib ) const;
363 : :
364 : : void SaveXml( XclExpXmlStream& rStrm ) const;
365 : : };
366 : :
367 : : // ----------------------------------------------------------------------------
368 : :
369 : : /** Extends the XclCellBorder struct for export.
370 : : @descr Provides functions to fill from item sets and to fill to Excel record data. */
371 : : struct XclExpCellBorder : public XclCellBorder
372 : : {
373 : : sal_uInt32 mnLeftColorId; /// Color ID for left line.
374 : : sal_uInt32 mnRightColorId; /// Color ID for right line.
375 : : sal_uInt32 mnTopColorId; /// Color ID for top line.
376 : : sal_uInt32 mnBottomColorId; /// Color ID for bottom line.
377 : : sal_uInt32 mnDiagColorId; /// Color ID for diagonal line(s).
378 : :
379 : : explicit XclExpCellBorder();
380 : :
381 : : /** Fills the border attributes from the passed item set.
382 : : @descr Fills only the attributes exported in the passed BIFF version.
383 : : @return true = At least one border item is set. */
384 : : bool FillFromItemSet( const SfxItemSet& rItemSet,
385 : : XclExpPalette& rPalette, XclBiff eBiff, bool bStyle = false );
386 : : /** Fills the mn***Color base members from the mn***ColorId members. */
387 : : void SetFinalColors( const XclExpPalette& rPalette );
388 : :
389 : : /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
390 : : void FillToXF5( sal_uInt32& rnBorder, sal_uInt32& rnArea ) const;
391 : : /** Fills the data to the passed fields of a BIFF8 XF record. */
392 : : void FillToXF8( sal_uInt32& rnBorder1, sal_uInt32& rnBorder2 ) const;
393 : :
394 : : /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
395 : : void FillToCF8( sal_uInt16& rnLine, sal_uInt32& rnColor ) const;
396 : :
397 : : void SaveXml( XclExpXmlStream& rStrm ) const;
398 : : };
399 : :
400 : : // ----------------------------------------------------------------------------
401 : :
402 : : /** Extends the XclCellArea struct for export.
403 : : @descr Provides functions to fill from item sets and to fill to Excel record data. */
404 : : struct XclExpCellArea : public XclCellArea
405 : : {
406 : : sal_uInt32 mnForeColorId; /// Foreground color ID.
407 : : sal_uInt32 mnBackColorId; /// Background color ID.
408 : :
409 : : explicit XclExpCellArea();
410 : :
411 : : /** Fills the area attributes from the passed item set.
412 : : @return true = At least one area item is set. */
413 : : bool FillFromItemSet(
414 : : const SfxItemSet& rItemSet, XclExpPalette& rPalette,
415 : : bool bStyle = false );
416 : : /** Fills the mn***Color base members from the mn***ColorId members. */
417 : : void SetFinalColors( const XclExpPalette& rPalette );
418 : :
419 : : /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
420 : : void FillToXF5( sal_uInt32& rnArea ) const;
421 : : /** Fills the data to the passed fields of a BIFF8 XF record. */
422 : : void FillToXF8( sal_uInt32& rnBorder2, sal_uInt16& rnArea ) const;
423 : :
424 : : /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
425 : : void FillToCF8( sal_uInt16& rnPattern, sal_uInt16& rnColor ) const;
426 : :
427 : : void SaveXml( XclExpXmlStream& rStrm ) const;
428 : : };
429 : :
430 : 0 : struct XclExpColor
431 : : {
432 : : Color maColor;
433 : :
434 : : bool FillFromItemSet( const SfxItemSet& rItemSet );
435 : :
436 : : void SaveXml( XclExpXmlStream& rStrm ) const;
437 : : };
438 : :
439 : : // ----------------------------------------------------------------------------
440 : :
441 : : /** A combination of unique XF identifier with real Excel XF index. */
442 : : struct XclExpXFId
443 : : {
444 : : sal_uInt32 mnXFId; /// Temporary XF identifier.
445 : : sal_uInt16 mnXFIndex; /// Real Excel XF index.
446 : :
447 : : explicit XclExpXFId();
448 : : explicit XclExpXFId( sal_uInt32 nXFId );
449 : :
450 : : /** Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex. */
451 : : void ConvertXFIndex( const XclExpRoot& rRoot );
452 : : };
453 : :
454 : : // ----------------------------------------------------------------------------
455 : :
456 : : class SfxStyleSheetBase;
457 : :
458 : : /** Represents an XF record which contains all formatting data of a cell or cell style. */
459 [ # # ][ # # ]: 0 : class XclExpXF : public XclXFBase, public XclExpRecord, protected XclExpRoot
[ # # ][ # # ]
[ # # ]
460 : : {
461 : : public:
462 : : /** Constructs a cell XF record from the passed Calc cell formatting. */
463 : : explicit XclExpXF(
464 : : const XclExpRoot& rRoot,
465 : : const ScPatternAttr& rPattern,
466 : : sal_Int16 nScript,
467 : : sal_uLong nScForceNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND,
468 : : sal_uInt16 nForceXclFont = EXC_FONT_NOTFOUND,
469 : : bool bForceLineBreak = false );
470 : : /** Constructs a style XF record from the passed cell style sheet. */
471 : : explicit XclExpXF(
472 : : const XclExpRoot& rRoot,
473 : : const SfxStyleSheetBase& rStyleSheet );
474 : :
475 : : /** Returns the cell protection settings of this XF. */
476 : : const XclExpCellProt& GetProtectionData() const { return maProtection; }
477 : : /** Returns the alignment settings of this XF. */
478 : 0 : const XclExpCellAlign& GetAlignmentData() const { return maAlignment; }
479 : : /** Returns the cell border settings of this XF. */
480 : 0 : const XclExpCellBorder& GetBorderData() const { return maBorder; }
481 : : /** Returns the cell fill settings of this XF. */
482 : 0 : const XclExpCellArea& GetAreaData() const { return maArea; }
483 : :
484 : : /** Returns true, if this XF record represents the passed cell formatting.
485 : : @descr Searches for cell XFs only. */
486 : : bool Equals(
487 : : const ScPatternAttr& rPattern,
488 : : sal_uLong nScForceNumFmt,
489 : : sal_uInt16 nForceXclFont,
490 : : bool bForceLineBreak ) const;
491 : :
492 : : /** Returns true, if this XF record represents the passed style.
493 : : @descr Searches for style XFs only. */
494 : : bool Equals( const SfxStyleSheetBase& rStyleSheet ) const;
495 : :
496 : : /** Sets the resulting Excel palette index from all used color IDs (border and area). */
497 : : void SetFinalColors();
498 : :
499 : : /** Returns true, if this XF record is completely equal to the passed. */
500 : : bool Equals( const XclExpXF& rCmpXF ) const;
501 : :
502 : : void SetXmlIds( sal_uInt32 nBorderId, sal_uInt32 nFillId );
503 : :
504 : : virtual void SaveXml( XclExpXmlStream& rStrm );
505 : :
506 : : protected:
507 : : explicit XclExpXF( const XclExpRoot& rRoot, bool bCellXF );
508 : :
509 : : protected: // access for XclExpDefaultXF
510 : : const SfxItemSet* mpItemSet; /// Pointer to the item set (we do not own it).
511 : :
512 : : XclExpCellProt maProtection; /// Cell protection flags.
513 : : XclExpCellAlign maAlignment; /// All alignment attributes.
514 : : XclExpCellBorder maBorder; /// Border line style.
515 : : XclExpCellArea maArea; /// Background area style.
516 : : sal_uInt32 mnParentXFId; /// XF ID of parent XF record.
517 : : sal_uLong mnScNumFmt; /// Calc number format index.
518 : : sal_uInt16 mnXclFont; /// Excel font index.
519 : : sal_uInt16 mnXclNumFmt; /// Excel number format index.
520 : : sal_Int32 mnBorderId; /// OOXML Border Index
521 : : sal_Int32 mnFillId; /// OOXML Fill Index
522 : :
523 : : private:
524 : : using XclXFBase::Equals;
525 : :
526 : : /** Initializes with default values. */
527 : : void InitDefault();
528 : : /** Fills all members from the passed item set.
529 : : @param bDefStyle true = This is the "Default"/"Normal" style - needs special handling. */
530 : : void Init(
531 : : const SfxItemSet& rItemSet,
532 : : sal_Int16 nScript,
533 : : sal_uLong nForceScNumFmt,
534 : : sal_uInt16 nForceXclFont,
535 : : bool bForceLineBreak,
536 : : bool bDefStyle );
537 : :
538 : : /** Returns the bits specifying the used attributes.
539 : : @descr In cell XFs a set bit means a used attribute, in style XF a cleared
540 : : bit means a used attribute. This method regards the cell/style state.
541 : : @return The mask based on bit 0 (not yet bit-shifted as needed for export). */
542 : : sal_uInt8 GetUsedFlags() const;
543 : :
544 : : void WriteBody5( XclExpStream& rStrm );
545 : : void WriteBody8( XclExpStream& rStrm );
546 : :
547 : : /** Writes the contents of the XF record. */
548 : : virtual void WriteBody( XclExpStream& rStrm );
549 : : };
550 : :
551 : : // ----------------------------------------------------------------------------
552 : :
553 : : /** Represents a default XF record. Supports methods to set attributes directly. */
554 [ # # ]: 0 : class XclExpDefaultXF : public XclExpXF
555 : : {
556 : : public:
557 : : explicit XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF );
558 : :
559 : : /** Sets the Excel font index. */
560 : : void SetFont( sal_uInt16 nXclFont );
561 : : /** Sets the Excel number format index. */
562 : : void SetNumFmt( sal_uInt16 nXclNumFmt );
563 : : };
564 : :
565 : : // ----------------------------------------------------------------------------
566 : :
567 : : /** Represents a STYLE record containing the data of a cell style.
568 : : @descr The calss is able to store built-in and user-defined styles. */
569 [ # # ][ # # ]: 0 : class XclExpStyle : public XclExpRecord
570 : : {
571 : : public:
572 : : explicit XclExpStyle( sal_uInt32 nXFId, const String& rStyleName );
573 : : explicit XclExpStyle( sal_uInt32 nXFId, sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
574 : :
575 : : /** Returns true, if this record represents an Excel built-in style. */
576 : 0 : inline bool IsBuiltIn() const { return mnStyleId != EXC_STYLE_USERDEF; }
577 : :
578 : : inline const String& GetName() const { return maName; }
579 : :
580 : : virtual void SaveXml( XclExpXmlStream& rStrm );
581 : :
582 : : private:
583 : : /** Writes the contents of the STYLE record. */
584 : : virtual void WriteBody( XclExpStream& rStrm );
585 : :
586 : : private:
587 : : String maName; /// Name of the cell style.
588 : : XclExpXFId maXFId; /// XF identifier for style formatting.
589 : : sal_uInt8 mnStyleId; /// Built-in style identifier.
590 : : sal_uInt8 mnLevel; /// Outline level for RowLevel and ColLevel styles.
591 : : };
592 : :
593 : : // ----------------------------------------------------------------------------
594 : :
595 : : /** Stores all XF records (cell formats and cell styles) in the document.
596 : :
597 : : Stores also the names of user defined cell styles (STYLE records). Supports
598 : : reduction to the maximum count of XF records of the current BIFF version.
599 : :
600 : : An instance of this class collects all XF records in the conversion phase
601 : : of the export, using the Insert() and InsertStyle() functions. It returns a
602 : : unique identidier for each XF record.
603 : :
604 : : After the entire document is converted, the Finalize() function will reduce
605 : : the list to the number of XF records supported by the current BIFF version.
606 : :
607 : : Then, in the streaming phase, the function GetXFIndex() returns the real
608 : : Excel XF index for all XF identifiers.
609 : : */
610 [ # # ][ # # ]: 0 : class XclExpXFBuffer : public XclExpRecordBase, protected XclExpRoot
[ # # ][ # # ]
[ # # ]
611 : : {
612 : : public:
613 : : explicit XclExpXFBuffer( const XclExpRoot& rRoot );
614 : :
615 : : /** Inserts predefined built-in styles and user-defined styles. */
616 : : void Initialize();
617 : :
618 : : /** Finds or creates a cell XF record for the passed item set.
619 : : @return A unique XF record ID. */
620 : : sal_uInt32 Insert( const ScPatternAttr* pPattern, sal_Int16 nScript );
621 : : /** Finds or creates a cell XF record for the passed item set.
622 : : @param nForceXclFont The font to be exported. If not equal to EXC_FONT_NOTFOUND,
623 : : this font index will be used unconditionally and the cell font will be ignored.
624 : : @param bForceLineBreak true = Set line break flag unconditionally.
625 : : This is required for cells that contain multi-line text.
626 : : @return A unique XF record ID. */
627 : : sal_uInt32 InsertWithFont(
628 : : const ScPatternAttr* pPattern, sal_Int16 nScript,
629 : : sal_uInt16 nForceXclFont,
630 : : bool bForceLineBreak );
631 : : /** Finds or creates a cell XF record for the passed item set, with custom number format.
632 : : @param nXFFlags Additional flags allowing to control the creation of an XF.
633 : : @param nForceScNumFmt The number format to be exported, e.g. formula
634 : : result type. This format will always overwrite the cell's number format.
635 : : @param bForceLineBreak true = Set line break flag unconditionally.
636 : : This is required for cells that contain multi-line text.
637 : : @return A unique XF record ID. */
638 : : sal_uInt32 InsertWithNumFmt(
639 : : const ScPatternAttr* pPattern, sal_Int16 nScript,
640 : : sal_uLong nForceScNumFmt,
641 : : bool bForceLineBreak );
642 : : /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
643 : : @return A unique XF record ID. */
644 : : sal_uInt32 InsertStyle( const SfxStyleSheetBase* pStyleSheet );
645 : : /** Returns the XF identifier representing a fixed Excel XF index (e.g. for built-in XFs). */
646 : : static sal_uInt32 GetXFIdFromIndex( sal_uInt16 nXFIndex );
647 : : /** Returns the XF identifier representing the default cell XF. */
648 : : static sal_uInt32 GetDefCellXFId();
649 : :
650 : : /** Returns an XF record by its unique identifier. */
651 : : const XclExpXF* GetXFById( sal_uInt32 nXFId ) const;
652 : :
653 : : /** Reduces the XF record list to the maximum allowed number of records. */
654 : : void Finalize();
655 : :
656 : : /** Returns the Excel XF index of the XF record with passed XF ID. */
657 : : sal_uInt16 GetXFIndex( sal_uInt32 nXFId ) const;
658 : :
659 : : sal_Int32 GetXmlStyleIndex( sal_uInt32 nXFId ) const;
660 : : sal_Int32 GetXmlCellIndex( sal_uInt32 nXFId ) const;
661 : :
662 : : /** Writes all XF records contained in this buffer. */
663 : : virtual void Save( XclExpStream& rStrm );
664 : : virtual void SaveXml( XclExpXmlStream& rStrm );
665 : :
666 : : private:
667 : : typedef XclExpRecordList< XclExpXF > XclExpXFList;
668 : : typedef XclExpXFList::RecordRefType XclExpXFRef;
669 : : typedef XclExpRecordList< XclExpStyle > XclExpStyleList;
670 : :
671 : : private:
672 : : /** Returns the XF ID of the cell XF containing the passed format. */
673 : : sal_uInt32 FindXF( const ScPatternAttr& rPattern, sal_uLong nForceScNumFmt,
674 : : sal_uInt16 nForceXclFont, bool bForceLineBreak ) const;
675 : : /** Returns the XF ID of the style XF containing the passed style. */
676 : : sal_uInt32 FindXF( const SfxStyleSheetBase& rStyleSheet ) const;
677 : :
678 : : /** Returns the XF ID of a built-in style XF, searches by style identifier. */
679 : : sal_uInt32 FindBuiltInXF( sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL ) const;
680 : :
681 : : /** Tries to find the XF record containing the passed format or inserts a new record.
682 : : @return The XF record ID. */
683 : : sal_uInt32 InsertCellXF( const ScPatternAttr* pPattern, sal_Int16 nScript,
684 : : sal_uLong nForceScNumFmt,
685 : : sal_uInt16 nForceXclFont, bool bForceLineBreak );
686 : : /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
687 : : @return The XF record ID. */
688 : : sal_uInt32 InsertStyleXF( const SfxStyleSheetBase& rStyleSheet );
689 : :
690 : : /** Inserts an XF and a STYLE record for all user defined style sheets. */
691 : : void InsertUserStyles();
692 : :
693 : : /** Inserts a built-in XF record without a STYLE record and returns the XF ID.
694 : : @param bCreateStyleRec true = Creates the related STYLE record. */
695 : : sal_uInt32 AppendBuiltInXF( XclExpXFRef xXF,
696 : : sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
697 : : /** Inserts a built-in XF and STYLE record and returns the XF ID.
698 : : @param bCreateStyleRec true = Creates the related STYLE record. */
699 : : sal_uInt32 AppendBuiltInXFWithStyle( XclExpXFRef xXF,
700 : : sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
701 : :
702 : : /** Inserts all default XF and STYLE records. */
703 : : void InsertDefaultRecords();
704 : :
705 : : /** Appends a XF index to the internal ID<->index maps. */
706 : : void AppendXFIndex( sal_uInt32 nXFId );
707 : :
708 : : void AddBorderAndFill( const XclExpXF& rXF );
709 : : void SaveXFXml( XclExpXmlStream& rStrm, XclExpXF& rXF );
710 : :
711 : : private:
712 : : /** Extended info about a built-in XF. */
713 : : struct XclExpBuiltInInfo
714 : : {
715 : : sal_uInt8 mnStyleId; /// Built-in style identifier.
716 : : sal_uInt8 mnLevel; /// Level for RowLevel/ColLevel styles.
717 : : bool mbPredefined; /// true = XF still predefined.
718 : : bool mbHasStyleRec; /// true = STYLE record created.
719 : : explicit XclExpBuiltInInfo();
720 : : };
721 : : typedef ::std::map< sal_uInt32, XclExpBuiltInInfo > XclExpBuiltInMap;
722 : : typedef ::std::vector< XclExpCellBorder > XclExpBorderList;
723 : : typedef ::std::vector< XclExpCellArea > XclExpFillList;
724 : :
725 : : XclExpXFList maXFList; /// List of all XF records.
726 : : XclExpStyleList maStyleList; /// List of all STYLE records.
727 : : XclExpBuiltInMap maBuiltInMap; /// Contained elements describe built-in XFs.
728 : : ScfUInt16Vec maXFIndexVec; /// Maps XF IDs to XF indexes.
729 : : ScfUInt16Vec maStyleIndexes; /// Maps XF IDs to OOXML Style indexes
730 : : ScfUInt16Vec maCellIndexes; /// Maps XF IDs to OOXML Cell indexes
731 : : XclExpXFList maSortedXFList; /// List of XF records in XF index order.
732 : : XclExpBorderList maBorders; /// List of borders used by XF records
733 : : XclExpFillList maFills; /// List of fills used by XF records
734 : :
735 : : };
736 : :
737 : : struct XclDxfStyle
738 : : {
739 : : };
740 : :
741 : : class XclExpDxf : public XclExpRecordBase, protected XclExpRoot
742 : : {
743 : : public:
744 : : XclExpDxf( const XclExpRoot& rRoot, XclExpCellAlign* pAlign, XclExpCellBorder* pBorder,
745 : : XclExpFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpColor* pColor);
746 : : virtual ~XclExpDxf();
747 : :
748 : : virtual void SaveXml( XclExpXmlStream& rStrm );
749 : :
750 : : private:
751 : : boost::scoped_ptr<XclExpCellAlign> mpAlign;
752 : : boost::scoped_ptr<XclExpCellBorder> mpBorder;
753 : : boost::scoped_ptr<XclExpFont> mpFont;
754 : : boost::scoped_ptr<XclExpNumFmt> mpNumberFmt;
755 : : boost::scoped_ptr<XclExpCellProt> mpProt;
756 : : boost::scoped_ptr<XclExpColor> mpColor;
757 : : };
758 : :
759 : : class XclExpDxfs : public XclExpRecordBase, protected XclExpRoot
760 : : {
761 : : public:
762 : : XclExpDxfs( const XclExpRoot& rRoot );
763 [ # # ][ # # ]: 0 : virtual ~XclExpDxfs() {}
[ # # ][ # # ]
[ # # ]
764 : :
765 : : sal_Int32 GetDxfId(const rtl::OUString& rName);
766 : :
767 : : virtual void SaveXml( XclExpXmlStream& rStrm);
768 : : private:
769 : : typedef boost::ptr_vector<XclExpDxf> DxfContainer;
770 : : std::map<rtl::OUString, sal_Int32> maStyleNameToDxfId;
771 : : DxfContainer maDxf;
772 : : SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion.
773 : : boost::scoped_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table.
774 : : };
775 : :
776 : : // ============================================================================
777 : :
778 [ # # ][ # # ]: 0 : class XclExpXmlStyleSheet : public XclExpRecordBase, protected XclExpRoot
779 : : {
780 : : public:
781 : : explicit XclExpXmlStyleSheet( const XclExpRoot& rRoot );
782 : :
783 : : virtual void SaveXml( XclExpXmlStream& rStrm );
784 : : };
785 : :
786 : : // ============================================================================
787 : :
788 : : #endif
789 : :
790 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|