summaryrefslogtreecommitdiffstats
path: root/lib/kofficecore/KoOasisLoadingContext.h
blob: c36a0fb1ed2fc12128dc5d16672fa994750552f5 (plain)
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
/* This file is part of the KDE project
   Copyright (C) 2005 David Faure <faure@kde.org>

   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 KOOASISLOADINGCONTEXT_H
#define KOOASISLOADINGCONTEXT_H

class KoXmlWriter;
class TQDomElement;
class KoDocument;
class KoOasisStyles;
class KoPictureCollection;
class KoStore;

#include <tqmap.h>
#include <koffice_export.h>
#include <tqstringlist.h>
#include <KoStyleStack.h>

/**
 * Used during loading of Oasis format (and discarded at the end of the loading).
 *
 * @author David Faure <faure@kde.org>
 */
class KOFFICECORE_EXPORT KoOasisLoadingContext
{
public:
    /**
     * Stores reference to the KoOasisStyles and stored passed by KoDocument.
     * Make sure that the KoOasisStyles instance outlives this KoOasisLoadingContext instance.
     * (This is the case during loading, when using the KoOasisStyles given by KoDocument)
     *
     * @param doc the KoDocument being loaded
     * @param styles reference to the KoOasisStyles parsed by KoDocument
     * @param store pointer to store, if available, for e.g. loading images.
     */
    KoOasisLoadingContext( KoDocument* doc, KoOasisStyles& styles, KoStore* store );
    ~KoOasisLoadingContext();

    KoDocument* koDocument() { return m_doc; }
    KoStore* store() { return m_store; }

    KoOasisStyles& oasisStyles() { return m_styles; }
    KoStyleStack& styleStack() { return m_styleStack; }

    const TQDomDocument& manifestDocument() const { return m_manifestDoc; }

    /// Return the <meta:generator> of the document, e.g. "KOffice/1.4.0a"
    TQString generator() const;

    /**
     * Convenience method for loading the style of an object
     * before loading that object.
     *
     * Read attribute (nsURI,attrName) from the given dom element,
     * treat that attribute as a style name, and load that style
     * including all its parent styles.
     * @param element the dom element to read the attribute from
     * @param nsURI the namespace URI of the attribute to read
     * @param attrName the name of the attribute to read
     * @param family the style family used for this object
     */
    void fillStyleStack( const TQDomElement& element, const char* nsURI, const char* attrName, const char* family );

    /**
     * Add @p style to the stack, as well as all its parent styles
     * and the default style for this style family.
     *
     * @param style the dom element containing the style to add to the stack
     * @param family the family to use when looking up parent styles
     * @param usingStylesAutoStyles if true, the parent styles are looked up
     *   in the automatic styles from styles.xml, instead of looking up
     *   in the automatic styles from content.xml as we usually do.
     *   This is useful for loading headers and footers for instance.
     *   See setUseStylesAutoStyles(), which makes fillStyleStack() set this bool.
     *
     * Usually you would call fillStyleStack() instead.
     */
    void addStyles( const TQDomElement* style, const char* family, bool usingStylesAutoStyles = false );

    /// Set to true while loading headers and footers, to remember to use auto styles
    /// from styles.xml
    void setUseStylesAutoStyles( bool useStylesAutoStyles ) { m_useStylesAutoStyles = useStylesAutoStyles; }
    //bool useStylesAutoStyles() const { return m_useStylesAutoStyles; }

private:
    void parseMeta() const;

private:
    KoDocument* m_doc;
    KoStore* m_store;
    KoOasisStyles& m_styles;
    KoStyleStack m_styleStack;

    mutable TQString m_generator;
    mutable bool m_metaXmlParsed;
    bool m_useStylesAutoStyles;
    bool m_unused1; // padding, can be used later
    bool m_unused2; // padding, can be used later

    TQDomDocument m_manifestDoc;

    class Private;
    Private *d;
};

#endif /* KOOASISLOADINGCONTEXT_H */