KoGenStyles.h
1/* This file is part of the KDE project
2 Copyright (C) 2004-2006 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17*/
18
19#ifndef KOGENSTYLES_H
20#define KOGENSTYLES_H
21
22#include <tqdict.h>
23#include <tqmap.h>
24#include <tqvaluevector.h>
25
26#include <koffice_export.h>
27
28class KoXmlWriter;
29class KoGenStyle;
30
59class KOFFICECORE_EXPORT KoGenStyles
60{
61public:
64
74 enum Flags { // bitfield
75 NoFlag = 0,
76 ForceNumbering = 0, // it's the default anyway
77 DontForceNumbering = 1
78 };
79 // KDE4 TODO: use TQFlags and change the arg type in lookup
80
97 TQString lookup( const KoGenStyle& style, const TQString& name = TQString(), int flags = NoFlag );
98
99 typedef TQMap<KoGenStyle, TQString> StyleMap;
104 const StyleMap& styles() const { return m_styleMap; }
105
106 struct NamedStyle {
107 const KoGenStyle* style;
108 TQString name;
109 };
119 TQValueList<NamedStyle> styles( int type, bool markedForStylesXml = false ) const;
120
124 const KoGenStyle* style( const TQString& name ) const;
125
133 KoGenStyle* styleForModification( const TQString& name );
134
147 void markStyleForStylesXml( const TQString& name );
148
152 void dump();
153
154private:
155 TQString makeUniqueName( const TQString& base, int flags ) const;
156
158 StyleMap m_styleMap;
159
163 typedef TQMap<TQString, bool> NameMap; // KDE4: TQSet
164 NameMap m_styleNames;
165 NameMap m_autoStylesInStylesDotXml;
166
168 typedef TQValueVector<NamedStyle> StyleArray;
169 StyleArray m_styleArray;
170
171 class Private;
172 Private *d;
173};
174
182class KOFFICECORE_EXPORT KoGenStyle
183{
184public:
192 enum { STYLE_PAGELAYOUT = 0,
193 STYLE_USER = 1,
194 STYLE_AUTO = 2,
195 STYLE_MASTER = 3,
196 STYLE_LIST = 4,
197 STYLE_AUTO_LIST = 5,
198 STYLE_NUMERIC_NUMBER = 6,
199 STYLE_NUMERIC_DATE = 7,
200 STYLE_NUMERIC_TIME = 8,
201 STYLE_NUMERIC_FRACTION = 9,
202 STYLE_NUMERIC_PERCENTAGE = 10,
203 STYLE_NUMERIC_SCIENTIFIC = 11,
204 STYLE_NUMERIC_CURRENCY = 12,
205 STYLE_NUMERIC_TEXT = 13,
206 STYLE_HATCH = 14,
207 STYLE_GRAPHICAUTO = 15};
208
221 explicit KoGenStyle( int type = 0, const char* familyName = 0,
222 const TQString& parentName = TQString() );
223 ~KoGenStyle();
224
225 /*
226 * setAutoStyleInStylesDotXml(true) marks a given automatic style as being needed in styles.xml.
227 * For instance styles used by headers and footers need to go there, since
228 * they are saved in styles.xml, and styles.xml must be independent from content.xml.
229 *
230 * The application should use KoGenStyles::styles( type, true ) in order to retrieve
231 * those styles and save them separately.
232 */
233 void setAutoStyleInStylesDotXml( bool b ) { m_autoStyleInStylesDotXml = b; }
235 bool autoStyleInStylesDotXml() const { return m_autoStyleInStylesDotXml; }
236
237 /*
238 * setDefaultStyle(true) marks a given style as being the default style.
239 * This means we expect that you will call writeStyle( ...,"style:default-style"),
240 * and its name will be ommitted in the output.
241 */
242 void setDefaultStyle( bool b ) { m_defaultStyle = b; }
244 bool isDefaultStyle() const { return m_defaultStyle; }
245
247 int type() const { return m_type; }
248
250 const char* familyName() const { return m_familyName.data(); }
251
253 TQString parentName() const { return m_parentName; }
254
274 {
280 DefaultType = 0,
287 Reserved1,
288 Reserved2,
289 ChildElement,
290 N_NumTypes
291 };
292
294 void addProperty( const TQString& propName, const TQString& propValue, PropertyType type = DefaultType ) {
295 m_properties[type].insert( propName, propValue );
296 }
298 void addProperty( const TQString& propName, const char* propValue, PropertyType type = DefaultType ) {
299 m_properties[type].insert( propName, TQString::fromUtf8( propValue ) );
300 }
302 void addProperty( const TQString& propName, int propValue, PropertyType type = DefaultType ) {
303 m_properties[type].insert( propName, TQString::number( propValue ) );
304 }
306 void addProperty( const TQString& propName, bool propValue, PropertyType type = DefaultType ) {
307 m_properties[type].insert( propName, propValue ? "true" : "false" );
308 }
309
316 void addPropertyPt( const TQString& propName, double propValue, PropertyType type = DefaultType );
317
323 void addAttribute( const TQString& attrName, const TQString& attrValue ) {
324 m_attributes.insert( attrName, attrValue );
325 }
327 void addAttribute( const TQString& attrName, const char* attrValue ) {
328 m_attributes.insert( attrName, TQString::fromUtf8( attrValue ) );
329 }
331 void addAttribute( const TQString& attrName, int attrValue ) {
332 m_attributes.insert( attrName, TQString::number( attrValue ) );
333 }
334
336 void addAttribute( const TQString& attrName, bool attrValue ) {
337 m_attributes.insert( attrName, attrValue ? "true" : "false" );
338 }
339
346 void addAttributePt( const TQString& attrName, double attrValue );
347
367 void addChildElement( const TQString& elementName, const TQString& elementContents ) {
368 m_properties[ChildElement].insert( elementName, elementContents );
369 }
370
375 void addStyleMap( const TQMap<TQString, TQString>& styleMap ) {
376 m_maps.append( styleMap );
377 }
378
384 bool isEmpty() const {
385 if ( !m_attributes.isEmpty() || ! m_maps.isEmpty() )
386 return false;
387 for ( uint i = 0 ; i < N_NumTypes ; ++i )
388 if ( ! m_properties[i].isEmpty() )
389 return false;
390 return true;
391 }
392
406 void writeStyle( KoXmlWriter* writer, KoGenStyles& styles, const char* elementName, const TQString& name,
407 const char* propertiesElementName, bool closeElement = true, bool drawElement = false ) const;
408
416 bool operator<( const KoGenStyle &other ) const;
417
419 bool operator==( const KoGenStyle &other ) const;
420
421private:
422 TQString property( const TQString& propName, PropertyType type ) const {
423 TQMap<TQString, TQString>::const_iterator it = m_properties[type].find( propName );
424 if ( it != m_properties[type].end() )
425 return it.data();
426 return TQString();
427 }
428
429 TQString attribute( const TQString& propName ) const {
430 TQMap<TQString, TQString>::const_iterator it = m_attributes.find( propName );
431 if ( it != m_attributes.end() )
432 return it.data();
433 return TQString();
434 }
435
436 void writeStyleProperties( KoXmlWriter* writer, PropertyType i,
437 const char* elementName, const KoGenStyle* parentStyle ) const;
438
439#ifndef NDEBUG
440 void printDebug() const;
441#endif
442
443private:
444 // Note that the copy constructor and assignment operator are allowed.
445 // Better not use pointers below!
446 int m_type;
447 TQCString m_familyName;
448 TQString m_parentName;
450 TQMap<TQString, TQString> m_properties[N_NumTypes];
451 TQMap<TQString, TQString> m_attributes;
452 typedef TQMap<TQString, TQString> StyleMap;
453 TQValueVector<StyleMap> m_maps; // we can't really sort the maps between themselves...
454
455 bool m_autoStyleInStylesDotXml;
456 bool m_defaultStyle;
457 short m_unused2;
458
459 // For lookup
460 friend class KoGenStyles;
461};
462
463#endif /* KOGENSTYLES_H */
A generic style, i.e.
void addChildElement(const TQString &elementName, const TQString &elementContents)
Add a child element to the style properties.
void addProperty(const TQString &propName, int propValue, PropertyType type=DefaultType)
Overloaded version of addProperty that converts an int to a string.
const char * familyName() const
Return the family name.
bool isEmpty() const
void addStyleMap(const TQMap< TQString, TQString > &styleMap)
Add a style:map to the style.
void addProperty(const TQString &propName, bool propValue, PropertyType type=DefaultType)
Overloaded version of addProperty that converts a bool to a string (false/true)
void addAttribute(const TQString &attrName, int attrValue)
Overloaded version of addAttribute that converts an int to a string.
void addAttribute(const TQString &attrName, const char *attrValue)
Overloaded version of addAttribute that takes a char*, usually for "...".
PropertyType
The types of properties.
@ GraphicType
GraphicType is always graphic-properties.
@ TextType
TextType is always text-properties.
@ ParagraphType
ParagraphType is always paragraph-properties.
TQString parentName() const
Return the name of style's parent, if set.
int type() const
Return the type of this style, as set in the constructor.
bool isDefaultStyle() const
void addProperty(const TQString &propName, const TQString &propValue, PropertyType type=DefaultType)
Add a property to the style.
void addAttribute(const TQString &attrName, bool attrValue)
Overloaded version of addAttribute that converts a bool to a string.
void addProperty(const TQString &propName, const char *propValue, PropertyType type=DefaultType)
Overloaded version of addProperty that takes a char*, usually for "...".
bool autoStyleInStylesDotXml() const
void addAttribute(const TQString &attrName, const TQString &attrValue)
Add an attribute to the style The difference between property and attributes is a bit oasis-format-sp...
Repository of styles used during saving of OASIS/OOo file.
Definition KoGenStyles.h:60
const StyleMap & styles() const
Return the entire collection of styles Use this for saving the styles.
Flags
Those are flags for the lookup() call.
Definition KoGenStyles.h:74
A class for writing out XML (to any TQIODevice), with a special attention on performance.
Definition KoXmlWriter.h:37