summaryrefslogtreecommitdiffstats
path: root/lib/kotext/KoStyleCollection.h
blob: 811bbaea5f5a9218b1bf823df0ec26a68bf08872 (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) 2001-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 kostyle_h
#define kostyle_h

#include <tqdom.h>
#include <tqvaluevector.h>
#include "KoParagStyle.h"
#include "KoUserStyleCollection.h"

class KoGenStyles;
class KoParagStyle;
class KoOasisContext;
class KoSavingContext;

struct KoStyleChangeDef {
    KoStyleChangeDef() {
        paragLayoutChanged = -1;
        formatChanged = -1;
    }
    KoStyleChangeDef( int parag, int format) {
        paragLayoutChanged = parag;
        formatChanged = format;
    };
    int paragLayoutChanged;
    int formatChanged;
};
typedef TQMap<KoParagStyle *, KoStyleChangeDef> KoStyleChangeDefMap;

/// TODO rename to KoParagStyleCollection - or should char styles be part of it too?
class KOTEXT_EXPORT KoStyleCollection : public KoUserStyleCollection
{
public:
    KoStyleCollection();
    ~KoStyleCollection();

    //const TQPtrList<KoParagStyle> & styleList() const { return m_styleList; }

    // compat method, TODO: remove
    TQStringList translatedStyleNames() const { return displayNameList(); }

    /**
     * See KoUserStyleCollection::addStyle.
     * Overloaded for convenience.
     */
    KoParagStyle* addStyle( KoParagStyle* sty ) {
        return static_cast<KoParagStyle*>( KoUserStyleCollection::addStyle( sty ) );
    }

    /**
     * Find style based on the internal name @p name.
     * Overloaded for convenience.
     */
    KoParagStyle* findStyle( const TQString & name ) const {
        return static_cast<KoParagStyle*>( KoUserStyleCollection::findStyle( name, TQString::fromLatin1( "Standard" ) ) );
    }

    /**
     * Find style based on the display name @p displayName.
     * Overloaded for convenience.
     */
    KoParagStyle* findStyleByDisplayName( const TQString & name ) const {
        return static_cast<KoParagStyle*>( KoUserStyleCollection::findStyleByDisplayName( name ) );
    }

    /**
     * Return style number @p i.
     */
    KoParagStyle* styleAt( int i ) { return static_cast<KoParagStyle*>( m_styleList[i] ); }


    /// Import a number of styles (e.g. loaded from another document)
    void importStyles( const KoStyleCollection& styleList );

    /// Loads the entire style collection, in the OASIS OpenDocument format
    /// @return the number of new styles loaded
    int loadOasisStyles( KoOasisContext& context );

    /// Save the entire style collection in the OASIS OpenDocument format
    /// @p styleType is the STYLE_* value for this style.
    void saveOasis( KoGenStyles& styles, int styleType, KoSavingContext& context ) const;

    /// Save the text:outline-style element, mostly for OOo.
    void saveOasisOutlineStyles( KoXmlWriter& writer ) const;

    /// @return the list of outline styles
    TQValueVector<KoParagStyle *> outlineStyles() const;

    /// @return the [first] outline style for a given level. Can be 0 if not found.
    KoParagStyle* outlineStyleForLevel( int level ) const;

    /// @return the [first] non-outline numbered style for a given level. Can be 0 if not found.
    KoParagStyle* numberedStyleForLevel( int level ) const;

    /// @return the "default" format. There isn't really such a notion at the moment
    /// (how would the user define it? etc.), and it's usually not needed, except
    /// in very specific cases (e.g. in increaseOutlineLevel() for "not a heading")
    /// The current implementation is to return Standard or the first one in the collection.
    KoParagStyle* defaultStyle() const;

#ifndef NDEBUG
    void printDebug() const;
#endif
};

#endif