~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/kword/msword-odf/wv2/src/styles.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the wvWare 2 project
 
2
   Copyright (C) 2001-2003 Werner Trobin <trobin@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 02111-1307, USA.
 
17
*/
 
18
 
 
19
#ifndef STYLES_H
 
20
#define STYLES_H
 
21
 
 
22
#include "word97_generated.h"
 
23
#include "wv2_export.h"
 
24
 
 
25
namespace wvWare
 
26
{
 
27
 
 
28
class OLEStreamReader;
 
29
class OLEStreamWriter;
 
30
 
 
31
namespace Word97
 
32
{
 
33
 
 
34
/**
 
35
 * STyle Definition (STD)
 
36
 */
 
37
struct STD
 
38
{
 
39
    /**
 
40
     * Creates an empty STD structure and sets the defaults
 
41
     */
 
42
    STD();
 
43
    /**
 
44
     * Simply calls read(...)
 
45
     */
 
46
    STD( U16 baseSize, U16 totalSize, OLEStreamReader* stream, bool preservePos = false );
 
47
    /**
 
48
     * Attention: This struct allocates memory on the heap
 
49
     */
 
50
    STD( const STD& rhs );
 
51
    ~STD();
 
52
 
 
53
    STD& operator=( const STD& rhs );
 
54
 
 
55
    /**
 
56
     * This method reads the STD structure from the stream.
 
57
     * If  preservePos is true we push/pop the position of
 
58
     * the stream to save the state. If it's false the state
 
59
     * of stream will be changed!
 
60
     */
 
61
    bool read( U16 baseSize, U16 totalSize, OLEStreamReader* stream, bool preservePos = false );
 
62
 
 
63
    /**
 
64
     * Same as reading :)
 
65
     */
 
66
    bool write( U16 baseSize, OLEStreamWriter* stream, bool preservePos = false ) const;
 
67
 
 
68
    /**
 
69
     * Set all the fields to the inital value (default is 0)
 
70
     */
 
71
    void clear();
 
72
 
 
73
    // Data
 
74
    /**
 
75
     * invariant style identifier
 
76
     */
 
77
    U16 sti:12;
 
78
 
 
79
    /**
 
80
     * spare field for any temporary use, always reset back to zero!
 
81
     */
 
82
    U16 fScratch:1;
 
83
 
 
84
    /**
 
85
     * PHEs of all text with this style are wrong
 
86
     */
 
87
    U16 fInvalHeight:1;
 
88
 
 
89
    /**
 
90
     * UPEs have been generated
 
91
     */
 
92
    U16 fHasUpe:1;
 
93
 
 
94
    /**
 
95
     * std has been mass-copied; if unused at save time, style should be deleted
 
96
     */
 
97
    U16 fMassCopy:1;
 
98
 
 
99
    /**
 
100
     * style type code
 
101
     */
 
102
    U16 sgc:4;
 
103
 
 
104
    /**
 
105
     * base style
 
106
     */
 
107
    U16 istdBase:12;
 
108
 
 
109
    /**
 
110
     * # of UPXs (and UPEs)
 
111
     */
 
112
    U16 cupx:4;
 
113
 
 
114
    /**
 
115
     * next style
 
116
     */
 
117
    U16 istdNext:12;
 
118
 
 
119
    /**
 
120
     * offset to end of upx's, start of upe's
 
121
     */
 
122
    U16 bchUpe;
 
123
 
 
124
    /**
 
125
     * auto redefine style when appropriate
 
126
     */
 
127
    U16 fAutoRedef:1;
 
128
 
 
129
    /**
 
130
     * hidden from UI?
 
131
     */
 
132
    U16 fHidden:1;
 
133
 
 
134
    /**
 
135
     * unused bits
 
136
     */
 
137
    U16 unused8_3:14;
 
138
 
 
139
    /**
 
140
     * sub-names are separated by chDelimStyle
 
141
     */
 
142
    UString xstzName;
 
143
 
 
144
    U8* grupx;
 
145
 
 
146
    // Internal, for bookkeeping
 
147
    U16 grupxLen;
 
148
 
 
149
private:
 
150
    void clearInternal();
 
151
    void readStyleName( U16 baseSize, OLEStreamReader* stream );
 
152
}; // STD
 
153
 
 
154
bool operator==( const STD& lhs, const STD& rhs );
 
155
bool operator!=( const STD& lhs, const STD& rhs );
 
156
 
 
157
}  // namespace Word97
 
158
 
 
159
 
 
160
class StyleSheet;
 
161
class ParagraphProperties;
 
162
class ListInfoProvider;
 
163
 
 
164
// The structure to hold the UPE for character styles.
 
165
struct UPECHPX
 
166
{
 
167
    UPECHPX() : istd( 0 ), cb( 0 ), grpprl( 0 ) {}
 
168
    ~UPECHPX() { delete [] grpprl; }
 
169
 
 
170
    U16 istd;
 
171
    U8 cb;
 
172
    U8* grpprl;
 
173
 
 
174
private:
 
175
    UPECHPX( const UPECHPX& rhs );
 
176
    UPECHPX& operator=( const UPECHPX& rhs );
 
177
};
 
178
 
 
179
/**
 
180
 * This class represents one single style.
 
181
 */
 
182
// It would maybe be worth to optimize the construction a bit, like creating
 
183
// the PAP and the CHP on copying from the base style, and not before (TODO)
 
184
class WV2_EXPORT Style
 
185
{
 
186
public:
 
187
    enum StyleType { sgcUnknown = 0, sgcPara = 1, sgcChp = 2 };
 
188
 
 
189
    Style( U16 baseSize, OLEStreamReader* tableStream, U16* ftc );
 
190
    ~Style();
 
191
 
 
192
    /**
 
193
     * The stylesheet can have "empty" slots
 
194
     */
 
195
    bool isEmpty() const { return m_isEmpty; }
 
196
    /**
 
197
     * Did we already unwrap the style?
 
198
     */
 
199
    bool isWrapped() const { return m_isWrapped; }
 
200
 
 
201
    /**
 
202
     * Unwrap the style and create a valid PAP/CHP
 
203
     */
 
204
    void unwrapStyle( const StyleSheet& stylesheet, WordVersion version );
 
205
 
 
206
    /**
 
207
     * Get the (unique?) sti of that style
 
208
     */
 
209
    U16 sti() const;
 
210
 
 
211
    /**
 
212
     * Get the type of the style (paragraph/character style)
 
213
     */
 
214
    StyleType type() const;
 
215
 
 
216
    /**
 
217
     * Style name
 
218
     */
 
219
    UString name() const;
 
220
 
 
221
    /**
 
222
     * Id of following style
 
223
     */
 
224
    U16 followingStyle() const;
 
225
 
 
226
    /*
 
227
     * For paragraph styles only
 
228
     */
 
229
    const ParagraphProperties& paragraphProperties() const;
 
230
    /*
 
231
     * For paragraph styles only
 
232
     */
 
233
    const Word97::CHP& chp() const;
 
234
    /*
 
235
     * For character styles only
 
236
     */
 
237
    const UPECHPX& upechpx() const;
 
238
 
 
239
private:
 
240
    Style( const Style& rhs );
 
241
    Style& operator=( const Style& rhs );
 
242
 
 
243
    // This helper method merges two CHPX structures to one
 
244
    // (needed for character styles)
 
245
    void mergeUpechpx( const Style* parentStyle, WordVersion version );
 
246
 
 
247
    bool m_isEmpty;
 
248
    bool m_isWrapped;
 
249
public:
 
250
    Word97::STD* m_std;
 
251
private:
 
252
 
 
253
    mutable ParagraphProperties *m_properties; // "mutable" in case someone goes mad
 
254
    mutable Word97::CHP *m_chp; //  with the styles. We have to create a default style
 
255
    mutable UPECHPX *m_upechpx; // to avoid crashes and still have to keep ownership!
 
256
};
 
257
 
 
258
 
 
259
/**
 
260
 * This class holds all the styles this Word document
 
261
 * defines. You can query styles by ID (sti) or index (istd)
 
262
 */
 
263
class WV2_EXPORT StyleSheet
 
264
{
 
265
public:
 
266
    StyleSheet( OLEStreamReader* tableStream, U32 fcStshf, U32 lcbStshf );
 
267
    ~StyleSheet();
 
268
 
 
269
    /**
 
270
     * Return the number of styles.
 
271
     */
 
272
    unsigned int size() const;
 
273
    const Style* styleByIndex( U16 istd ) const;
 
274
 
 
275
    const Style* styleByID( U16 sti ) const;
 
276
 
 
277
    U16 indexByID( U16 sti, bool& ok ) const;
 
278
 
 
279
private:
 
280
    StyleSheet( const StyleSheet& rhs );
 
281
    StyleSheet& operator=( const StyleSheet& rhs );
 
282
 
 
283
    Word97::STSHI m_stsh;
 
284
    std::vector<Style*> m_styles;
 
285
};
 
286
 
 
287
}  // namespace wvWare
 
288
 
 
289
#endif // STYLES_H