1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/* This file is part of the KDE project
Copyright (C) 2004-2006 David Faure <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOOASISSTYLES_H
#define KOOASISSTYLES_H
#include <tqdom.h>
#include <tqdict.h>
#include <tqvaluevector.h>
#include <tqmap.h>
#include <koffice_export.h>
class KoGenStyles;
class KoXmlWriter;
class TQBrush;
class KoGenStyle;
class KoStyleStack;
/**
* Repository of styles used during loading of OASIS/OOo file
*/
class KOFFICECORE_EXPORT KoOasisStyles
{
public:
KoOasisStyles();
~KoOasisStyles();
/// Look into @p doc for styles and remember them
/// @param doc document to look into
/// @param stylesDotXml true when loading styles.xml, false otherwise
void createStyleMap( const TQDomDocument& doc, bool stylesDotXml );
/**
* Look up a style by name.
* This method can find styles defined by the tags "style:page-layout",
* "style:presentation-page-layout", or "style:font-decl".
* Do NOT use this method for style:style styles.
*
* @param name the style name
* @return the dom element representing the style, or TQString() if it wasn't found.
*/
const TQDomElement* findStyle( const TQString& name ) const;
/**
* Look up a style:style by name.
* @param name the style name
* @param family the style family (for a style:style, use 0 otherwise)
* @return the dom element representing the style, or TQString() if it wasn't found.
*/
const TQDomElement* findStyle( const TQString& name, const TQString& family ) const;
/// Similar to findStyle but for auto-styles in styles.xml only.
const TQDomElement* findStyleAutoStyle( const TQString& name, const TQString& family ) const;
/// @return the style:styles that are "user styles", i.e. those from office:styles
/// findStyle() is used for lookup. userStyles() is used to load all user styles upfront.
TQValueVector<TQDomElement> userStyles() const;
/// @return the default style for a given family ("graphic","paragraph","table" etc.)
/// Returns 0 if no default style for this family is available
const TQDomElement* defaultStyle( const TQString& family ) const;
/// @return the office:style element
const TQDomElement& officeStyle() const { return m_officeStyle; }
/// @return all list styles ("text:list-style" elements), hashed by name
const TQDict<TQDomElement>& listStyles() const { return m_listStyles; }
/// @return master pages ("style:master-page" elements), hashed by name
const TQDict<TQDomElement>& masterPages() const { return m_masterPages; }
/// @return draw styles, hashed by name
const TQDict<TQDomElement>& drawStyles() const { return m_drawStyles; }
/// @return all styles ("style:style" elements) for a given family, hashed by name
const TQDict<TQDomElement>& styles(const TQString& family) const;
/// Prefix and suffix are always included into formatStr. Having them as separate fields simply
/// allows to extract them from formatStr, to display them in separate widgets.
struct NumericStyleFormat
{
TQString formatStr;
TQString prefix;
TQString suffix;
enum { Number, Scientific, Fraction, Currency, Percentage,
Date, Time, Boolean, Text } type;
int precision;
TQString currencySymbol;
};
typedef TQMap<TQString, NumericStyleFormat> DataFormatsMap;
/// Value (date/time/number...) formats found while parsing styles. Used e.g. for fields.
/// Key: format name. Value:
const DataFormatsMap& dataFormats() const { return m_dataFormats; }
static TQString saveOasisDateStyle( KoGenStyles &mainStyles, const TQString & _format, bool klocaleFormat,
const TQString &_prefix = TQString() , const TQString &_suffix= TQString() );
static TQString saveOasisTimeStyle( KoGenStyles &mainStyles, const TQString & _format, bool klocaleFormat,
const TQString &_prefix = TQString() , const TQString &_suffix= TQString() );
static TQString saveOasisFractionStyle( KoGenStyles &mainStyles, const TQString & _format,
const TQString &_prefix = TQString() , const TQString &_suffix= TQString() );
static TQString saveOasisScientificStyle( KoGenStyles &mainStyles, const TQString & _format,
const TQString &_prefix = TQString() , const TQString &_suffix= TQString() );
static TQString saveOasisNumberStyle( KoGenStyles &mainStyles, const TQString & _format,
const TQString &_prefix = TQString() , const TQString &_suffix= TQString() );
static TQString saveOasisPercentageStyle( KoGenStyles &mainStyles, const TQString & _format,
const TQString &_prefix = TQString() , const TQString &_suffix= TQString() );
static TQString saveOasisCurrencyStyle( KoGenStyles &mainStyles, const TQString & _format, const TQString &symbol,
const TQString &_prefix = TQString() , const TQString &_suffix= TQString() );
static TQString saveOasisTextStyle( KoGenStyles &mainStyles, const TQString & _format,
const TQString &_prefix = TQString() , const TQString &_suffix= TQString() );
static void saveOasisFillStyle( KoGenStyle &styleFill, KoGenStyles& mainStyles, const TQBrush & brush );
static TQString saveOasisHatchStyle( KoGenStyles& mainStyles, const TQBrush &brush );
static TQBrush loadOasisFillStyle( const KoStyleStack &styleStack, const TQString & fill, const KoOasisStyles & oasisStyles );
private:
/// Add styles to styles map
void insertStyles( const TQDomElement& styles, bool styleAutoStyles = false );
private:
void insertOfficeStyles( const TQDomElement& styles );
void insertStyle( const TQDomElement& style, bool styleAutoStyles );
void importDataStyle( const TQDomElement& parent );
static bool saveOasisTimeFormat( KoXmlWriter &elementWriter, TQString & format, TQString & text, bool &antislash );
static void parseOasisDateKlocale(KoXmlWriter &elementWriter, TQString & format, TQString & text );
static bool saveOasisKlocaleTimeFormat( KoXmlWriter &elementWriter, TQString & format, TQString & text );
static void parseOasisTimeKlocale(KoXmlWriter &elementWriter, TQString & format, TQString & text );
static void addKofficeNumericStyleExtension( KoXmlWriter & elementWriter, const TQString &_suffix, const TQString &_prefix );
KoOasisStyles( const KoOasisStyles & ); // forbidden
KoOasisStyles& operator=( const KoOasisStyles & ); // forbidden
private:
TQDict<TQDomElement> m_styles; // page-layout, font-decl etc.
TQDict<TQDomElement> m_defaultStyle;
TQDomElement m_officeStyle;
TQDict<TQDomElement> m_masterPages;
TQDict<TQDomElement> m_listStyles;
TQDict<TQDomElement> m_drawStyles;
DataFormatsMap m_dataFormats;
class Private;
Private * const d;
};
#endif /* KOOASISSTYLES_H */
|