Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : : #ifndef _XMLOFF_TXTPARAIMPHINT_HXX
20 : : #define _XMLOFF_TXTPARAIMPHINT_HXX
21 : :
22 : : #include <rtl/ustring.hxx>
23 : : #include <rtl/ustrbuf.hxx>
24 : : #include <xmloff/xmlimp.hxx>
25 : : #include "XMLTextFrameContext.hxx"
26 : : #include <xmloff/XMLEventsImportContext.hxx>
27 : :
28 : : using ::rtl::OUString;
29 : : using namespace ::com::sun::star;
30 : : using namespace ::com::sun::star::uno;
31 : : using namespace ::com::sun::star::text;
32 : : using namespace ::xmloff::token;
33 : :
34 : : // ---------------------------------------------------------------------
35 : :
36 : : #define XML_HINT_STYLE 1
37 : : #define XML_HINT_REFERENCE 2
38 : : #define XML_HINT_HYPERLINK 3
39 : : #define XML_HINT_INDEX_MARK 5
40 : : #define XML_HINT_TEXT_FRAME 6
41 : : // Core impl. of the unification of drawing objects and Writer fly frames (#i26791#)
42 : : #define XML_HINT_DRAW 7
43 : :
44 : : class XMLHint_Impl
45 : : {
46 : : Reference < XTextRange > xStart;
47 : : Reference < XTextRange > xEnd;
48 : :
49 : : sal_uInt8 nType;
50 : :
51 : : public:
52 : :
53 : 121 : XMLHint_Impl( sal_uInt8 nTyp,
54 : : const Reference < XTextRange > & rS,
55 : : const Reference < XTextRange > & rE ) :
56 : : xStart( rS ),
57 : : xEnd( rE ),
58 : 121 : nType( nTyp )
59 : : {
60 : 121 : }
61 : :
62 : : XMLHint_Impl( sal_uInt8 nTyp,
63 : : const Reference < XTextRange > & rS ) :
64 : : xStart( rS ),
65 : : nType( nTyp )
66 : : {
67 : : }
68 : :
69 [ - + ]: 121 : virtual ~XMLHint_Impl() {}
70 : :
71 : 121 : const Reference < XTextRange > & GetStart() const { return xStart; }
72 : 121 : const Reference < XTextRange > & GetEnd() const { return xEnd; }
73 : 94 : void SetEnd( const Reference < XTextRange > & rPos ) { xEnd = rPos; }
74 : :
75 : : // We don't use virtual methods to differ between the sub classes,
76 : : // because this seems to be to expensive if compared to inline methods.
77 : 121 : sal_uInt8 GetType() const { return nType; }
78 : : sal_Bool IsStyle() { return XML_HINT_STYLE==nType; }
79 : 0 : sal_Bool IsReference() { return XML_HINT_REFERENCE==nType; }
80 : : sal_Bool IsHyperlink() { return XML_HINT_HYPERLINK==nType; }
81 : 0 : sal_Bool IsIndexMark() { return XML_HINT_INDEX_MARK==nType; }
82 : : };
83 : :
84 : : class XMLStyleHint_Impl : public XMLHint_Impl
85 : : {
86 : : OUString sStyleName;
87 : :
88 : : public:
89 : :
90 : 91 : XMLStyleHint_Impl( const OUString& rStyleName,
91 : : const Reference < XTextRange > & rPos ) :
92 : : XMLHint_Impl( XML_HINT_STYLE, rPos, rPos ),
93 : 91 : sStyleName( rStyleName )
94 : : {
95 : 91 : }
96 [ - + ]: 182 : virtual ~XMLStyleHint_Impl() {}
97 : :
98 : 119 : const OUString& GetStyleName() const { return sStyleName; }
99 : : };
100 : :
101 : : class XMLReferenceHint_Impl : public XMLHint_Impl
102 : : {
103 : : OUString sRefName;
104 : :
105 : : public:
106 : :
107 : 0 : XMLReferenceHint_Impl( const OUString& rRefName,
108 : : const Reference < XTextRange > & rPos ) :
109 : : XMLHint_Impl( XML_HINT_REFERENCE, rPos, rPos ),
110 : 0 : sRefName( rRefName )
111 : : {
112 : 0 : }
113 : :
114 [ # # ]: 0 : virtual ~XMLReferenceHint_Impl() {}
115 : :
116 : 0 : const OUString& GetRefName() const { return sRefName; }
117 : : };
118 : :
119 : : class XMLHyperlinkHint_Impl : public XMLHint_Impl
120 : : {
121 : : OUString sHRef;
122 : : OUString sName;
123 : : OUString sTargetFrameName;
124 : : OUString sStyleName;
125 : : OUString sVisitedStyleName;
126 : : XMLEventsImportContext* pEvents;
127 : :
128 : : public:
129 : :
130 : 3 : XMLHyperlinkHint_Impl( const Reference < XTextRange > & rPos ) :
131 : : XMLHint_Impl( XML_HINT_HYPERLINK, rPos, rPos ),
132 : 3 : pEvents( NULL )
133 : : {
134 : 3 : }
135 : :
136 : 6 : virtual ~XMLHyperlinkHint_Impl()
137 : 3 : {
138 [ - + ]: 3 : if (NULL != pEvents)
139 [ # # ]: 0 : pEvents->ReleaseRef();
140 [ - + ]: 6 : }
141 : :
142 : 3 : void SetHRef( const OUString& s ) { sHRef = s; }
143 : 3 : const OUString& GetHRef() const { return sHRef; }
144 : 0 : void SetName( const OUString& s ) { sName = s; }
145 : 3 : const OUString& GetName() const { return sName; }
146 : 0 : void SetTargetFrameName( const OUString& s ) { sTargetFrameName = s; }
147 : 3 : const OUString& GetTargetFrameName() const { return sTargetFrameName; }
148 : 0 : void SetStyleName( const OUString& s ) { sStyleName = s; }
149 : 3 : const OUString& GetStyleName() const { return sStyleName; }
150 : 0 : void SetVisitedStyleName( const OUString& s ) { sVisitedStyleName = s; }
151 : 3 : const OUString& GetVisitedStyleName() const { return sVisitedStyleName; }
152 : 3 : XMLEventsImportContext* GetEventsContext() const
153 : : {
154 : 3 : return pEvents;
155 : : }
156 : 0 : void SetEventsContext( XMLEventsImportContext* pCtxt )
157 : : {
158 : 0 : pEvents = pCtxt;
159 [ # # ]: 0 : if (pEvents != NULL)
160 : 0 : pEvents->AddRef();
161 : 0 : }
162 : : };
163 : :
164 : :
165 : : class XMLIndexMarkHint_Impl : public XMLHint_Impl
166 : : {
167 : : const Reference<beans::XPropertySet> xIndexMarkPropSet;
168 : :
169 : : const OUString sID;
170 : :
171 : : public:
172 : :
173 : 0 : XMLIndexMarkHint_Impl( const Reference < beans::XPropertySet > & rPropSet,
174 : : const Reference < XTextRange > & rPos ) :
175 : : XMLHint_Impl( XML_HINT_INDEX_MARK, rPos, rPos ),
176 : : xIndexMarkPropSet( rPropSet ),
177 : 0 : sID()
178 : : {
179 : 0 : }
180 : :
181 : 0 : XMLIndexMarkHint_Impl( const Reference < beans::XPropertySet > & rPropSet,
182 : : const Reference < XTextRange > & rPos,
183 : : OUString sIDString) :
184 : : XMLHint_Impl( XML_HINT_INDEX_MARK, rPos, rPos ),
185 : : xIndexMarkPropSet( rPropSet ),
186 : 0 : sID(sIDString)
187 : : {
188 : 0 : }
189 : :
190 [ # # ]: 0 : virtual ~XMLIndexMarkHint_Impl() {}
191 : :
192 : 0 : const Reference<beans::XPropertySet> & GetMark() const
193 : 0 : { return xIndexMarkPropSet; }
194 : 0 : const OUString& GetID() const { return sID; }
195 : : };
196 : :
197 : :
198 : : class XMLTextFrameHint_Impl : public XMLHint_Impl
199 : : {
200 : : // OD 2004-04-20 #i26791#
201 : : SvXMLImportContextRef xContext;
202 : :
203 : : public:
204 : :
205 : 0 : XMLTextFrameHint_Impl( SvXMLImportContext* pContext,
206 : : const Reference < XTextRange > & rPos ) :
207 : : XMLHint_Impl( XML_HINT_TEXT_FRAME, rPos, rPos ),
208 : 0 : xContext( pContext )
209 : : {
210 : 0 : }
211 : :
212 : 0 : virtual ~XMLTextFrameHint_Impl()
213 [ # # ]: 0 : {
214 [ # # ]: 0 : }
215 : :
216 : 0 : Reference < XTextContent > GetTextContent() const
217 : : {
218 : 0 : Reference <XTextContent > xTxt;
219 : 0 : SvXMLImportContext *pContext = &xContext;
220 [ # # ][ # # ]: 0 : if( pContext->ISA( XMLTextFrameContext ) )
[ # # ]
221 [ # # ][ # # ]: 0 : xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
[ # # ][ # # ]
[ # # ][ # # ]
222 [ # # ][ # # ]: 0 : else if( pContext->ISA( XMLTextFrameHyperlinkContext ) )
[ # # ]
223 [ # # ][ # # ]: 0 : xTxt = PTR_CAST( XMLTextFrameHyperlinkContext, pContext )
224 [ # # ][ # # ]: 0 : ->GetTextContent();
[ # # ][ # # ]
225 : :
226 : 0 : return xTxt;
227 : : }
228 : :
229 : : // Frame "to character": anchor moves from first to last char after saving (#i33242#)
230 : 0 : Reference < drawing::XShape > GetShape() const
231 : : {
232 : 0 : Reference < drawing::XShape > xShape;
233 : 0 : SvXMLImportContext *pContext = &xContext;
234 [ # # ][ # # ]: 0 : if( pContext->ISA( XMLTextFrameContext ) )
[ # # ]
235 [ # # ][ # # ]: 0 : xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
[ # # ][ # # ]
[ # # ][ # # ]
236 [ # # ][ # # ]: 0 : else if( pContext->ISA( XMLTextFrameHyperlinkContext ) )
[ # # ]
237 [ # # ][ # # ]: 0 : xShape = PTR_CAST( XMLTextFrameHyperlinkContext, pContext )->GetShape();
[ # # ][ # # ]
[ # # ][ # # ]
238 : :
239 : 0 : return xShape;
240 : : }
241 : :
242 : 0 : sal_Bool IsBoundAtChar() const
243 : : {
244 : 0 : sal_Bool bRet = sal_False;
245 : 0 : SvXMLImportContext *pContext = &xContext;
246 [ # # ]: 0 : if( pContext->ISA( XMLTextFrameContext ) )
247 : : bRet = TextContentAnchorType_AT_CHARACTER ==
248 : 0 : PTR_CAST( XMLTextFrameContext, pContext )
249 [ # # # # ]: 0 : ->GetAnchorType();
250 [ # # ]: 0 : else if( pContext->ISA( XMLTextFrameHyperlinkContext ) )
251 : : bRet = TextContentAnchorType_AT_CHARACTER ==
252 : 0 : PTR_CAST( XMLTextFrameHyperlinkContext, pContext )
253 [ # # # # ]: 0 : ->GetAnchorType();
254 : 0 : return bRet;
255 : : }
256 : : };
257 : :
258 : : // Core impl. of the unification of drawing objects and Writer fly frames (#i26791#)
259 : : class XMLDrawHint_Impl : public XMLHint_Impl
260 : : {
261 : : SvXMLImportContextRef xContext;
262 : :
263 : : public:
264 : :
265 : 27 : XMLDrawHint_Impl( SvXMLShapeContext* pContext,
266 : : const Reference < XTextRange > & rPos ) :
267 : : XMLHint_Impl( XML_HINT_DRAW, rPos, rPos ),
268 : 27 : xContext( pContext )
269 : : {
270 : 27 : }
271 : :
272 : 54 : virtual ~XMLDrawHint_Impl()
273 [ + - ]: 27 : {
274 [ - + ]: 54 : }
275 : :
276 : : // Frame "to character": anchor moves from first to last char after saving (#i33242#)
277 : 27 : Reference < drawing::XShape > GetShape() const
278 : : {
279 : 27 : return static_cast<SvXMLShapeContext*>(&xContext)->getShape();
280 : : }
281 : : };
282 : : #endif
283 : :
284 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|