1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <sal/types.h>
24 #include <com/sun/star/drawing/XShape.hpp>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <tools/ref.hxx>
29 @file resourcemodel.hxx
31 The classes in this file define the interfaces for the resource
32 model of the DocTokenizer:
34 @image html doctok.png
36 A resource is a set of events that describe an object. A resource
37 is only an abstract concept. It is not instantiated to a class.
39 A reference to a resource represents the object that the resource
40 describes. The reference can be resolved thereby generating the
41 events of the resource.
43 A handler receives the events generated by resolving a
44 reference. There are several types of handlers each accepting their
45 specific set of events.
47 References always have a parameter determining the kind of handler
48 they send the events they generate to. The set of events generated
49 by resolving the reference is a subset of the events received by
53 typedef sal_uInt32 Id
;
55 namespace writerfilter
57 struct CommentProperties
;
60 Reference to a resource that generates events and sends them to a
63 The reference can be resolved, i.e. the resource generates its
64 events. The events must be suitable for the handler type given by
65 the template parameter.
67 @attention The parameter of the template does not determine the
68 type of the reference's target. It determines the type of the handler!
72 A Word document can be represented as a stream of events. Event
73 types in a Word document are text, properties, tables, starts and
74 ends of groups. These can be handled by a stream handler (@see
75 Stream). Thus a reference to a Word document is resolved by
76 sending these events to a stream handler.
79 template <class T
> class SAL_DLLPUBLIC_TEMPLATE Reference
: public virtual SvRefBase
85 @attention The ownership of a reference is transferred when
86 the reference is passed.
88 typedef tools::SvRef
<Reference
<T
>> Pointer_t
;
91 Resolves the reference.
93 The events of the references target resource are generated and
96 @param rHandler handler which receives the events
98 virtual void resolve(T
& rHandler
) = 0;
100 Reference() = default;
101 Reference(Reference
const&) = default;
102 Reference(Reference
&&) = default;
103 Reference
& operator=(Reference
const&) = default;
104 Reference
& operator=(Reference
&&) = default;
107 ~Reference() override
{}
114 Handler for properties.
116 class Properties
: public virtual SvRefBase
120 Receives an attribute.
122 @param name name of the attribute
123 @param val value of the attribute
125 virtual void attribute(Id name
, Value
& val
) = 0;
130 @param sprm the SPRM received
132 virtual void sprm(Sprm
& sprm
) = 0;
135 ~Properties() override
{}
141 class Table
: public virtual SvRefBase
144 typedef tools::SvRef
<Table
> Pointer_t
;
147 Receives an entry of the table.
149 @param pos position of the entry in the table
150 @param ref reference to properties of the entry
152 virtual void entry(int pos
, writerfilter::Reference
<Properties
>::Pointer_t ref
) = 0;
159 Handler for binary objects.
165 Receives binary data of the object.
167 @param buf pointer to buffer containing the data
168 @param len size of buffer
170 virtual void data(const sal_uInt8
* buf
, size_t len
) = 0;
176 const sal_uInt8 cFieldLock
= 0x8;
177 const sal_uInt8 cFieldStart
= 0x13;
178 const sal_uInt8 cFieldSep
= 0x14;
179 const sal_uInt8 cFieldEnd
= 0x15;
187 Handler for a stream.
189 class Stream
: public virtual SvRefBase
193 Pointer to this stream.
195 typedef tools::SvRef
<Stream
> Pointer_t
;
198 Receives start mark for group with the same section properties.
200 virtual void startSectionGroup() = 0;
203 Receives end mark for group with the same section properties.
205 virtual void endSectionGroup() = 0;
207 /// The current section is the last one in this body text.
208 virtual void markLastSectionGroup(){};
210 virtual void setDocumentReference(writerfilter::ooxml::OOXMLDocument
* pDocument
) = 0;
213 Receives start mark for group with the same paragraph properties.
215 virtual void startParagraphGroup() = 0;
218 Receives end mark for group with the same paragraph properties.
220 virtual void endParagraphGroup() = 0;
222 virtual void markLastParagraphInSection(){};
225 Receives start mark for group with the same character properties.
227 virtual void startCharacterGroup() = 0;
230 Receives end mark for group with the same character properties.
232 virtual void endCharacterGroup() = 0;
237 virtual void startShape(css::uno::Reference
<css::drawing::XShape
> const& xShape
) = 0;
239 virtual void endShape() = 0;
242 Receives a text-box-content.
244 virtual void startTextBoxContent() = 0;
246 virtual void endTextBoxContent() = 0;
249 Receives 8-bit per character text.
251 @param data buffer containing the text
252 @param len number of characters in the text
254 virtual void text(const sal_uInt8
* data
, size_t len
) = 0;
257 Receives 16-bit per character text.
259 @param data buffer containing the text
260 @param len number of characters in the text.
262 virtual void utext(const sal_uInt8
* data
, size_t len
) = 0;
265 * Offset in EMUs for a shape.
267 * Call *before* an ooxml::CT_PosH/V_posOffset sprm is sent.
269 virtual void positionOffset(const OUString
& rText
, bool bVertical
) = 0;
270 /// Returns the last set offsets of a shape in HMM.
271 virtual css::awt::Point
getPositionOffset() = 0;
273 * Horizontal and vertical alignment for a shape.
275 * Call *before* an ooxml:CT_PosH/V_align sprm is sent.
277 virtual void align(const OUString
& rText
, bool bVertical
) = 0;
278 virtual void positivePercentage(const OUString
& rText
) = 0;
281 Receives properties of the current run of text.
283 @param ref reference to the properties
285 virtual void props(writerfilter::Reference
<Properties
>::Pointer_t ref
) = 0;
290 @param name name of the table
291 @param ref reference to the table
293 virtual void table(Id name
, writerfilter::Reference
<Table
>::Pointer_t ref
) = 0;
296 Receives a substream.
298 @param name name of the substream
299 @param ref reference to the substream
301 virtual void substream(Id name
, writerfilter::Reference
<Stream
>::Pointer_t ref
) = 0;
304 Debugging: Receives information about current point in stream.
306 @param info the information
308 virtual void info(const std::string
& info
) = 0;
310 /// Receives start mark for glossary document entry.
311 virtual void startGlossaryEntry() = 0;
313 /// Receives end mark for glossary document entry.
314 virtual void endGlossaryEntry() = 0;
316 /// Receives identifier for node entry.
317 virtual void checkId(const sal_Int32 nId
) = 0;
319 virtual void commentProps(const OUString
& /*sId*/, const CommentProperties
& /*rProps*/) {}
322 ~Stream() override
{}
328 The methods of this class may throw exceptions if a certain aspect
329 makes no sense for a certain value, e.g. the integer value of a
332 class Value
: public virtual SvRefBase
338 typedef tools::SvRef
<Value
> Pointer_t
;
341 Returns integer representation of the value.
343 virtual int getInt() const = 0;
346 Returns string representation of the value.
348 virtual OUString
getString() const = 0;
351 Returns representation of the value as uno::Any.
353 virtual css::uno::Any
getAny() const = 0;
356 Returns properties of this value.
358 virtual writerfilter::Reference
<Properties
>::Pointer_t
getProperties() = 0;
361 Returns binary object of this value.
363 virtual writerfilter::Reference
<BinaryObj
>::Pointer_t
getBinary() = 0;
366 Returns string representation of this value.
369 virtual std::string
toString() const = 0;
374 An SPRM: Section, Paragraph and Run Modifier
377 class Sprm
: public virtual SvRefBase
380 typedef tools::SvRef
<Sprm
> Pointer_t
;
383 Returns id of the SPRM.
385 virtual sal_uInt32
getId() const = 0;
388 Returns value of the SPRM.
390 virtual Value::Pointer_t
getValue() = 0;
393 Returns reference to properties contained in the SPRM.
396 virtual writerfilter::Reference
<Properties
>::Pointer_t
getProps() = 0;
399 Returns name of sprm.
402 virtual std::string
getName() const = 0;
406 Returns string representation of sprm.
409 virtual std::string
toString() const = 0;
416 typedef sal_Int32 Token_t
;
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */