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 
XMLHint_Impl(sal_uInt8 nTyp,const Reference<XTextRange> & rS,const Reference<XTextRange> & rE)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 
XMLHint_Impl(sal_uInt8 nTyp,const Reference<XTextRange> & rS)69 	XMLHint_Impl( sal_uInt8 nTyp,
70 				  const Reference < XTextRange > & rS ) :
71 		xStart( rS ),
72 		nType( nTyp )
73 	{
74 	}
75 
~XMLHint_Impl()76 	virtual ~XMLHint_Impl() {}
77 
GetStart() const78 	const Reference < XTextRange > & GetStart() const { return xStart; }
GetEnd() const79 	const Reference < XTextRange > & GetEnd() const { return xEnd; }
SetEnd(const Reference<XTextRange> & rPos)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.
GetType() const84 	sal_uInt8 GetType() const { return nType; }
IsStyle()85 	sal_Bool IsStyle() { return XML_HINT_STYLE==nType; }
IsReference()86 	sal_Bool IsReference() { return XML_HINT_REFERENCE==nType; }
IsHyperlink()87 	sal_Bool IsHyperlink() { return XML_HINT_HYPERLINK==nType; }
IsIndexMark()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 
XMLStyleHint_Impl(const OUString & rStyleName,const Reference<XTextRange> & rPos)97 	XMLStyleHint_Impl( const OUString& rStyleName,
98 				  	   const Reference < XTextRange > & rPos ) :
99 		XMLHint_Impl( XML_HINT_STYLE, rPos, rPos ),
100 		sStyleName( rStyleName )
101 	{
102 	}
~XMLStyleHint_Impl()103 	virtual ~XMLStyleHint_Impl() {}
104 
GetStyleName() const105 	const OUString& GetStyleName() const { return sStyleName; }
106 };
107 
108 class XMLReferenceHint_Impl : public XMLHint_Impl
109 {
110 	OUString				 sRefName;
111 
112 public:
113 
XMLReferenceHint_Impl(const OUString & rRefName,const Reference<XTextRange> & rPos)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 
~XMLReferenceHint_Impl()121 	virtual ~XMLReferenceHint_Impl() {}
122 
GetRefName() const123 	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 
XMLHyperlinkHint_Impl(const Reference<XTextRange> & rPos)137 	XMLHyperlinkHint_Impl( const Reference < XTextRange > & rPos ) :
138 		XMLHint_Impl( XML_HINT_HYPERLINK, rPos, rPos ),
139 		pEvents( NULL )
140 	{
141 	}
142 
~XMLHyperlinkHint_Impl()143 	virtual ~XMLHyperlinkHint_Impl()
144 	{
145 		if (NULL != pEvents)
146 			pEvents->ReleaseRef();
147 	}
148 
SetHRef(const OUString & s)149 	void SetHRef( const OUString& s ) { sHRef = s; }
GetHRef() const150 	const OUString& GetHRef() const { return sHRef; }
SetName(const OUString & s)151 	void SetName( const OUString& s ) { sName = s; }
GetName() const152 	const OUString& GetName() const { return sName; }
SetTargetFrameName(const OUString & s)153 	void SetTargetFrameName( const OUString& s ) { sTargetFrameName = s; }
GetTargetFrameName() const154 	const OUString& GetTargetFrameName() const { return sTargetFrameName; }
SetStyleName(const OUString & s)155 	void SetStyleName( const OUString& s ) { sStyleName = s; }
GetStyleName() const156 	const OUString& GetStyleName() const { return sStyleName; }
SetVisitedStyleName(const OUString & s)157 	void SetVisitedStyleName( const OUString& s ) { sVisitedStyleName = s; }
GetVisitedStyleName() const158 	const OUString& GetVisitedStyleName() const { return sVisitedStyleName; }
GetEventsContext() const159     XMLEventsImportContext* GetEventsContext() const
160     {
161         return pEvents;
162     }
SetEventsContext(XMLEventsImportContext * pCtxt)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 
XMLIndexMarkHint_Impl(const Reference<beans::XPropertySet> & rPropSet,const Reference<XTextRange> & rPos)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 
XMLIndexMarkHint_Impl(const Reference<beans::XPropertySet> & rPropSet,const Reference<XTextRange> & rPos,OUString sIDString)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 
~XMLIndexMarkHint_Impl()197 	virtual ~XMLIndexMarkHint_Impl() {}
198 
GetMark() const199 	const Reference<beans::XPropertySet> & GetMark() const
200 		{ return xIndexMarkPropSet; }
GetID() const201 	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 
XMLTextFrameHint_Impl(SvXMLImportContext * pContext,const Reference<XTextRange> & rPos)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 
~XMLTextFrameHint_Impl()219     virtual ~XMLTextFrameHint_Impl()
220     {
221     }
222 
GetTextContent() const223 	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#
GetShape() const237     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 
IsBoundAtChar() const250 	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 
XMLDrawHint_Impl(SvXMLShapeContext * pContext,const Reference<XTextRange> & rPos)273     XMLDrawHint_Impl( SvXMLShapeContext* pContext,
274                       const Reference < XTextRange > & rPos ) :
275         XMLHint_Impl( XML_HINT_DRAW, rPos, rPos ),
276         xContext( pContext )
277     {
278     }
279 
~XMLDrawHint_Impl()280     virtual ~XMLDrawHint_Impl()
281     {
282     }
283 
284     // --> OD 2004-08-24 #i33242#
GetShape() const285     Reference < drawing::XShape > GetShape() const
286     {
287         return static_cast<SvXMLShapeContext*>(&xContext)->getShape();
288     }
289     // <--
290 };
291 // <--
292 #endif
293