xref: /AOO41X/main/xmloff/source/text/txtparaimphint.hxx (revision 05236b1a0a8122ee73deabdbaef6d40a9b9d7792)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _XMLOFF_TXTPARAIMPHINT_HXX
24 #define _XMLOFF_TXTPARAIMPHINT_HXX
25 
26 #include <rtl/ustring.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <tools/debug.hxx>
29 #include <svl/svarray.hxx>
30 #include <xmloff/xmlimp.hxx>
31 #include "XMLTextFrameContext.hxx"
32 #include <xmloff/XMLEventsImportContext.hxx>
33 
34 using ::rtl::OUString;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::text;
38 using namespace ::xmloff::token;
39 
40 // ---------------------------------------------------------------------
41 
42 #define XML_HINT_STYLE 1
43 #define XML_HINT_REFERENCE 2
44 #define XML_HINT_HYPERLINK 3
45 #define XML_HINT_INDEX_MARK 5
46 #define XML_HINT_TEXT_FRAME 6
47 // --> DVO, OD 2004-07-14 #i26791#
48 #define XML_HINT_DRAW 7
49 // <--
50 
51 class XMLHint_Impl
52 {
53 	Reference < XTextRange > xStart;
54 	Reference < XTextRange > xEnd;
55 
56 	sal_uInt8 nType;
57 
58 public:
59 
60 	XMLHint_Impl( sal_uInt8 nTyp,
61 				  const Reference < XTextRange > & rS,
62 				  const Reference < XTextRange > & rE ) :
63 		xStart( rS ),
64 		xEnd( rE ),
65 		nType( nTyp )
66 	{
67 	}
68 
69 	XMLHint_Impl( sal_uInt8 nTyp,
70 				  const Reference < XTextRange > & rS ) :
71 		xStart( rS ),
72 		nType( nTyp )
73 	{
74 	}
75 
76 	virtual ~XMLHint_Impl() {}
77 
78 	const Reference < XTextRange > & GetStart() const { return xStart; }
79 	const Reference < XTextRange > & GetEnd() const { return xEnd; }
80 	void SetEnd( const Reference < XTextRange > & rPos ) { xEnd = rPos; }
81 
82 	// We don't use virtual methods to differ between the sub classes,
83 	// because this seems to be to expensive if compared to inline methods.
84 	sal_uInt8 GetType() const { return nType; }
85 	sal_Bool IsStyle() { return XML_HINT_STYLE==nType; }
86 	sal_Bool IsReference() { return XML_HINT_REFERENCE==nType; }
87 	sal_Bool IsHyperlink() { return XML_HINT_HYPERLINK==nType; }
88 	sal_Bool IsIndexMark() { return XML_HINT_INDEX_MARK==nType; }
89 };
90 
91 class XMLStyleHint_Impl : public XMLHint_Impl
92 {
93 	OUString				 sStyleName;
94 
95 public:
96 
97 	XMLStyleHint_Impl( const OUString& rStyleName,
98 				  	   const Reference < XTextRange > & rPos ) :
99 		XMLHint_Impl( XML_HINT_STYLE, rPos, rPos ),
100 		sStyleName( rStyleName )
101 	{
102 	}
103 	virtual ~XMLStyleHint_Impl() {}
104 
105 	const OUString& GetStyleName() const { return sStyleName; }
106 };
107 
108 class XMLReferenceHint_Impl : public XMLHint_Impl
109 {
110 	OUString				 sRefName;
111 
112 public:
113 
114 	XMLReferenceHint_Impl( const OUString& rRefName,
115 				  		   const Reference < XTextRange > & rPos ) :
116 		XMLHint_Impl( XML_HINT_REFERENCE, rPos, rPos ),
117 		sRefName( rRefName )
118 	{
119 	}
120 
121 	virtual ~XMLReferenceHint_Impl() {}
122 
123 	const OUString& GetRefName() const { return sRefName; }
124 };
125 
126 class XMLHyperlinkHint_Impl : public XMLHint_Impl
127 {
128 	OUString				 sHRef;
129 	OUString				 sName;
130 	OUString				 sTargetFrameName;
131 	OUString				 sStyleName;
132 	OUString				 sVisitedStyleName;
133 	XMLEventsImportContext*	 pEvents;
134 
135 public:
136 
137 	XMLHyperlinkHint_Impl( const Reference < XTextRange > & rPos ) :
138 		XMLHint_Impl( XML_HINT_HYPERLINK, rPos, rPos ),
139 		pEvents( NULL )
140 	{
141 	}
142 
143 	virtual ~XMLHyperlinkHint_Impl()
144 	{
145 		if (NULL != pEvents)
146 			pEvents->ReleaseRef();
147 	}
148 
149 	void SetHRef( const OUString& s ) { sHRef = s; }
150 	const OUString& GetHRef() const { return sHRef; }
151 	void SetName( const OUString& s ) { sName = s; }
152 	const OUString& GetName() const { return sName; }
153 	void SetTargetFrameName( const OUString& s ) { sTargetFrameName = s; }
154 	const OUString& GetTargetFrameName() const { return sTargetFrameName; }
155 	void SetStyleName( const OUString& s ) { sStyleName = s; }
156 	const OUString& GetStyleName() const { return sStyleName; }
157 	void SetVisitedStyleName( const OUString& s ) { sVisitedStyleName = s; }
158 	const OUString& GetVisitedStyleName() const { return sVisitedStyleName; }
159     XMLEventsImportContext* GetEventsContext() const
160     {
161         return pEvents;
162     }
163     void SetEventsContext( XMLEventsImportContext* pCtxt )
164     {
165         pEvents = pCtxt;
166         if (pEvents != NULL)
167             pEvents->AddRef();
168     }
169 };
170 
171 
172 class XMLIndexMarkHint_Impl : public XMLHint_Impl
173 {
174 	const Reference<beans::XPropertySet> xIndexMarkPropSet;
175 
176 	const OUString sID;
177 
178 public:
179 
180 	XMLIndexMarkHint_Impl( const Reference < beans::XPropertySet > & rPropSet,
181 						   const Reference < XTextRange > & rPos ) :
182 		XMLHint_Impl( XML_HINT_INDEX_MARK, rPos, rPos ),
183 		xIndexMarkPropSet( rPropSet ),
184 		sID()
185 	{
186 	}
187 
188 	XMLIndexMarkHint_Impl( const Reference < beans::XPropertySet > & rPropSet,
189 						   const Reference < XTextRange > & rPos,
190 						   OUString sIDString) :
191 		XMLHint_Impl( XML_HINT_INDEX_MARK, rPos, rPos ),
192 		xIndexMarkPropSet( rPropSet ),
193 		sID(sIDString)
194 	{
195 	}
196 
197 	virtual ~XMLIndexMarkHint_Impl() {}
198 
199 	const Reference<beans::XPropertySet> & GetMark() const
200 		{ return xIndexMarkPropSet; }
201 	const OUString& GetID() const { return sID; }
202 };
203 
204 
205 class XMLTextFrameHint_Impl : public XMLHint_Impl
206 {
207     // OD 2004-04-20 #i26791#
208     SvXMLImportContextRef xContext;
209 
210 public:
211 
212     XMLTextFrameHint_Impl( SvXMLImportContext* pContext,
213                            const Reference < XTextRange > & rPos ) :
214         XMLHint_Impl( XML_HINT_TEXT_FRAME, rPos, rPos ),
215         xContext( pContext )
216     {
217     }
218 
219     virtual ~XMLTextFrameHint_Impl()
220     {
221     }
222 
223 	Reference < XTextContent > GetTextContent() const
224 	{
225 		Reference <XTextContent > xTxt;
226 		SvXMLImportContext *pContext = &xContext;
227 		if( pContext->ISA( XMLTextFrameContext ) )
228 			xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
229 		else if( pContext->ISA( XMLTextFrameHyperlinkContext ) )
230 			xTxt = PTR_CAST( XMLTextFrameHyperlinkContext, pContext )
231 						->GetTextContent();
232 
233 		return xTxt;
234 	}
235 
236     // --> OD 2004-08-24 #i33242#
237     Reference < drawing::XShape > GetShape() const
238     {
239         Reference < drawing::XShape > xShape;
240         SvXMLImportContext *pContext = &xContext;
241         if( pContext->ISA( XMLTextFrameContext ) )
242             xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
243         else if( pContext->ISA( XMLTextFrameHyperlinkContext ) )
244             xShape = PTR_CAST( XMLTextFrameHyperlinkContext, pContext )->GetShape();
245 
246         return xShape;
247     }
248     // <--
249 
250 	sal_Bool IsBoundAtChar() const
251 	{
252 		sal_Bool bRet = sal_False;
253 		SvXMLImportContext *pContext = &xContext;
254 		if( pContext->ISA( XMLTextFrameContext ) )
255 			bRet = TextContentAnchorType_AT_CHARACTER ==
256 				PTR_CAST( XMLTextFrameContext, pContext )
257 					->GetAnchorType();
258 		else if( pContext->ISA( XMLTextFrameHyperlinkContext ) )
259 			bRet = TextContentAnchorType_AT_CHARACTER ==
260 				PTR_CAST( XMLTextFrameHyperlinkContext, pContext )
261 					->GetAnchorType();
262 		return bRet;
263 	}
264 };
265 
266 // --> DVO, OD 2004-07-14 #i26791#
267 class XMLDrawHint_Impl : public XMLHint_Impl
268 {
269     SvXMLImportContextRef xContext;
270 
271 public:
272 
273     XMLDrawHint_Impl( SvXMLShapeContext* pContext,
274                       const Reference < XTextRange > & rPos ) :
275         XMLHint_Impl( XML_HINT_DRAW, rPos, rPos ),
276         xContext( pContext )
277     {
278     }
279 
280     virtual ~XMLDrawHint_Impl()
281     {
282     }
283 
284     // --> OD 2004-08-24 #i33242#
285     Reference < drawing::XShape > GetShape() const
286     {
287         return static_cast<SvXMLShapeContext*>(&xContext)->getShape();
288     }
289     // <--
290 };
291 // <--
292 #endif
293