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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/* 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 as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 KOOASISCONTEXT_H
#define KOOASISCONTEXT_H
#include <KoOasisLoadingContext.h>
class KoVariableSettings;
class KoTextParag;
class KoParagStyle;
class KoGenStyles;
class KoVariableCollection;
#include "KoListStyleStack.h"
#include "KoTextBookmark.h"
// ####### TODO rename to KoTextOasisLoadingContext (wow that's long).
// ####### maybe KoTextLoadingContext?
/**
* Used during loading of Oasis format (and discarded at the end of the loading).
* In addition to what KoOasisLoadingContext stores, this class has 'state' information:
* a stack with the currently used styles (with its ancestors in the stack),
* another one with the list styles currently applicable (one item in the stack per list level).
*
* @author David Faure <[email protected]>
*/
class KOTEXT_EXPORT KoOasisContext : public KoOasisLoadingContext
{
public:
/**
* Stores reference to the KoOasisStyles parsed by KoDocument.
* Make sure that the KoOasisStyles instance outlives this KoOasisContext instance.
* (This is the case during loaiding, when using the KoOasisStyles given by KoDocument)
* @param doc KoDocument, needed by some field variables
* @param varColl reference to the collection that creates and stores variables (fields)
* @param styles reference to the KoOasisStyles parsed by KoDocument
* @param store pointer to store, if available, for e.g. loading images.
*/
KoOasisContext( KoDocument* doc, KoVariableCollection& varColl,
KoOasisStyles& styles, KoStore* store );
~KoOasisContext();
KoVariableCollection& variableCollection() { return m_varColl; }
///// List handling
KoListStyleStack& listStyleStack() { return m_listStyleStack; }
TQString currentListStyleName() const { return m_currentListStyleName; }
void setCurrentListStyleName( const TQString& s ) { m_currentListStyleName = s; }
/// Used for lists (numbered paragraphs)
/// @return true on success (a list style was found and pushed)
bool pushListLevelStyle( const TQString& listStyleName, int level );
/// Used for outline levels
bool pushOutlineListLevelStyle( int level );
/// Set cursor position (set by KoTextParag upon finding the processing instruction)
void setCursorPosition( KoTextParag* cursorTextParagraph,
int cursorTextIndex );
KoTextParag* cursorTextParagraph() const { return m_cursorTextParagraph; }
int cursorTextIndex() const { return m_cursorTextIndex; }
private:
/// @return true on success (a list style was found and pushed)
bool pushListLevelStyle( const TQString& listStyleName, const TQDomElement& fullListStyle, int level );
private:
KoListStyleStack m_listStyleStack;
TQString m_currentListStyleName;
KoVariableCollection& m_varColl;
KoTextParag* m_cursorTextParagraph;
int m_cursorTextIndex;
class Private;
Private *d;
};
// TODO extract non-text base class for kofficecore, see KoOasisLoadingContext
// ####### TODO rename to KoTextOasisSavingContext (wow that's long).
// ####### maybe KoTextSavingContext?
/**
* Used during saving to Oasis format (and discarded at the end of the saving).
*
* Among other things, this class acts as a repository of fonts used by a
* document during saving, in order to create the office:font-face-decls element.
*
* @author David Faure <[email protected]>
*/
class KOTEXT_EXPORT KoSavingContext
{
public:
enum SavingMode { Store, Flat };
/// Constructor
/// @param mainStyles
/// @param settings optional, used for saving the page-number in the first paragraph
/// @param hasColumns optional, used by KoParagLayout for the type of page breaks
/// @param savingMode either Store (a KoStore will be used) or Flat (all data must be inline in the XML)
KoSavingContext( KoGenStyles& mainStyles, KoVariableSettings* settings = 0, bool hasColumns = false, SavingMode savingMode = Store );
~KoSavingContext();
KoGenStyles& mainStyles() { return m_mainStyles; }
/// @return the saving mode: Store (a KoStore will be used) or Flat (all data must be inline in the XML)
SavingMode savingMode() const { return m_savingMode; }
/// Set cursor position (so that KoTextParag can insert a processing instruction)
void setCursorPosition( KoTextParag* cursorTextParagraph,
int cursorTextIndex );
KoTextParag* cursorTextParagraph() const { return m_cursorTextParagraph; }
int cursorTextIndex() const { return m_cursorTextIndex; }
/// Store bookmarks [for the current text paragraph beind saved]
/// so that KoTextParag can save them at the right place inside the text
struct BookmarkPosition {
BookmarkPosition() : name(), pos( -1 ), startEqualsEnd( false ) {} // for TQValueList
BookmarkPosition( const TQString& nm, int p, bool simple )
: name( nm ), pos( p ), startEqualsEnd( simple ) {}
TQString name;
int pos;
bool startEqualsEnd;
bool operator<( BookmarkPosition& rhs ) const {
return pos < rhs.pos;
}
};
typedef TQValueList<BookmarkPosition> BookmarkPositions;
void setBookmarkPositions( const BookmarkPositions& bkStarts,
const BookmarkPositions& bkEnds ) {
m_bookmarkStarts = bkStarts;
m_bookmarkEnds = bkEnds;
}
const BookmarkPositions& bookmarkStarts() const { return m_bookmarkStarts; }
const BookmarkPositions& bookmarkEnds() const { return m_bookmarkEnds; }
void addFontFace( const TQString& fontName );
typedef TQMap<TQString, bool> FontFaces;
void writeFontFaces( KoXmlWriter& writer );
// See KoParagLayout::saveOasis
bool hasColumns() const { return m_hasColumns; }
// See KoTextParag::saveOasis
KoVariableSettings* variableSettings() const { return m_variableSettings; }
private:
KoGenStyles& m_mainStyles;
SavingMode m_savingMode;
BookmarkPositions m_bookmarkStarts, m_bookmarkEnds;
KoTextParag* m_cursorTextParagraph;
int m_cursorTextIndex;
FontFaces m_fontFaces;
KoVariableSettings* m_variableSettings;
bool m_hasColumns;
class Private;
Private *d;
};
#endif /* KOOASISCONTEXT_H */
|