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