xref: /trunk/main/sw/source/filter/xml/xmltexti.cxx (revision efeef26f)
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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <comphelper/storagehelper.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <com/sun/star/embed/EmbedStates.hpp>
31 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
32 #include <com/sun/star/embed/XLinkCreator.hpp>
33 #include <com/sun/star/embed/XEmbeddedObject.hpp>
34 #include <com/sun/star/embed/XVisualObject.hpp>
35 #include <com/sun/star/embed/Aspects.hpp>
36 #include <com/sun/star/task/XInteractionHandler.hpp>
37 #include <rtl/ustrbuf.hxx>
38 #include <sot/clsids.hxx>
39 #include <com/sun/star/lang/XUnoTunnel.hpp>
40 #include <xmloff/prstylei.hxx>
41 #include <xmloff/maptype.hxx>
42 #include <xmloff/xmlprmap.hxx>
43 #include <xmloff/txtprmap.hxx>
44 #include <xmloff/i18nmap.hxx>
45 #include "unocrsr.hxx"
46 #include "TextCursorHelper.hxx"
47 #include "unoframe.hxx"
48 #include "doc.hxx"
49 #include "unocoll.hxx"
50 #include <fmtfsize.hxx>
51 #include <fmtanchr.hxx>
52 #include <fmtcntnt.hxx>
53 #include "xmlimp.hxx"
54 #include "xmltbli.hxx"
55 #include "xmltexti.hxx"
56 #include "XMLRedlineImportHelper.hxx"
57 #include <xmloff/XMLFilterServiceNames.h>
58 #include <SwAppletImpl.hxx>
59 #include <ndole.hxx>
60 #include <docsh.hxx>
61 #include <sfx2/docfile.hxx>
62 #include <switerator.hxx>
63 
64 // for locking SolarMutex: svapp + mutex
65 #include <vcl/svapp.hxx>
66 #include <vos/mutex.hxx>
67 
68 #include <toolkit/helper/vclunohelper.hxx>
69 #include <svtools/embedhlp.hxx>
70 #include <svl/urihelper.hxx>
71 
72 
73 using ::rtl::OUString;
74 using ::rtl::OUStringBuffer;
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::text;
79 using namespace ::com::sun::star::frame;
80 using namespace ::com::sun::star::beans;
81 using namespace xml::sax;
82 
83 
84 struct XMLServiceMapEntry_Impl
85 {
86 	const sal_Char *sFilterService;
87 	sal_Int32	   nFilterServiceLen;
88 
89 	sal_uInt32	n1;
90 	sal_uInt16	n2, n3;
91 	sal_uInt8	n4, n5, n6, n7, n8, n9, n10, n11;
92 };
93 
94 #define SERVICE_MAP_ENTRY( app, s ) \
95 	{ XML_IMPORT_FILTER_##app, sizeof(XML_IMPORT_FILTER_##app)-1, \
96       SO3_##s##_CLASSID	}
97 
98 const XMLServiceMapEntry_Impl aServiceMap[] =
99 {
100 	SERVICE_MAP_ENTRY( WRITER, SW ),
101 	SERVICE_MAP_ENTRY( CALC, SC ),
102 	SERVICE_MAP_ENTRY( DRAW, SDRAW ),
103 	SERVICE_MAP_ENTRY( IMPRESS, SIMPRESS ),
104 	SERVICE_MAP_ENTRY( CHART, SCH ),
105 	SERVICE_MAP_ENTRY( MATH, SM ),
106 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
107 };
lcl_putHeightAndWidth(SfxItemSet & rItemSet,sal_Int32 nHeight,sal_Int32 nWidth,long * pTwipHeight=0,long * pTwipWidth=0)108 static void lcl_putHeightAndWidth ( SfxItemSet &rItemSet,
109 		sal_Int32 nHeight, sal_Int32 nWidth,
110 		long *pTwipHeight=0, long *pTwipWidth=0 )
111 {
112 	if( nWidth > 0 && nHeight > 0 )
113 	{
114 		nWidth = MM100_TO_TWIP( nWidth );
115 		if( nWidth < MINFLY )
116 			nWidth = MINFLY;
117 		nHeight = MM100_TO_TWIP( nHeight );
118 		if( nHeight < MINFLY )
119 			nHeight = MINFLY;
120 		rItemSet.Put( SwFmtFrmSize( ATT_FIX_SIZE, nWidth, nHeight ) );
121 	}
122 
123     SwFmtAnchor aAnchor( FLY_AT_CHAR );
124 	rItemSet.Put( aAnchor );
125 
126 	if( pTwipWidth )
127 		*pTwipWidth = nWidth;
128 	if( pTwipHeight )
129 		*pTwipHeight = nHeight;
130 }
131 
lcl_setObjectVisualArea(const uno::Reference<embed::XEmbeddedObject> & xObj,sal_Int64 nAspect,const Size & aVisSize,const MapUnit & aUnit)132 static void lcl_setObjectVisualArea( const uno::Reference< embed::XEmbeddedObject >& xObj,
133 									sal_Int64 nAspect,
134 									const Size& aVisSize,
135 									const MapUnit& aUnit )
136 {
137 	if( xObj.is() && nAspect != embed::Aspects::MSOLE_ICON )
138 	{
139 		// convert the visual area to the objects units
140 		MapUnit aObjUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
141 		Size aObjVisSize = OutputDevice::LogicToLogic( aVisSize, aUnit, aObjUnit );
142 		awt::Size aSz;
143 		aSz.Width = aObjVisSize.Width();
144 		aSz.Height = aObjVisSize.Height();
145 
146 		try
147 		{
148 			xObj->setVisualAreaSize( nAspect, aSz );
149 		}
150 		catch( uno::Exception& )
151 		{
152 			OSL_ASSERT( "Couldn't set visual area of the object!\n" );
153 		}
154 	}
155 }
156 
SwXMLTextImportHelper(const uno::Reference<XModel> & rModel,SvXMLImport & rImport,const uno::Reference<XPropertySet> & rInfoSet,sal_Bool bInsertM,sal_Bool bStylesOnlyM,sal_Bool _bProgress,sal_Bool bBlockM,sal_Bool bOrganizerM,sal_Bool)157 SwXMLTextImportHelper::SwXMLTextImportHelper(
158 		const uno::Reference < XModel>& rModel,
159         SvXMLImport& rImport,
160         const uno::Reference<XPropertySet> & rInfoSet,
161 		sal_Bool bInsertM, sal_Bool bStylesOnlyM, sal_Bool _bProgress,
162 		sal_Bool bBlockM, sal_Bool bOrganizerM,
163 		sal_Bool /*bPreserveRedlineMode*/ ) :
164 	XMLTextImportHelper( rModel, rImport, bInsertM, bStylesOnlyM, _bProgress,
165                          bBlockM, bOrganizerM ),
166 	pRedlineHelper( NULL )
167 {
168 	uno::Reference<XPropertySet> xDocPropSet( rModel, UNO_QUERY );
169 	pRedlineHelper = new XMLRedlineImportHelper(
170 		bInsertM || bBlockM, xDocPropSet, rInfoSet );
171 }
172 
~SwXMLTextImportHelper()173 SwXMLTextImportHelper::~SwXMLTextImportHelper()
174 {
175     // #90463# the redline helper destructor sets properties on the document
176     //         and may through an exception while doing so... catch this
177     try
178     {
179         delete pRedlineHelper;
180     }
181     catch ( const RuntimeException& )
182     {
183         // ignore
184     }
185 }
186 
CreateTableChildContext(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<XAttributeList> & xAttrList)187 SvXMLImportContext *SwXMLTextImportHelper::CreateTableChildContext(
188 				SvXMLImport& rImport,
189 				sal_uInt16 nPrefix, const OUString& rLocalName,
190 				const uno::Reference< XAttributeList > & xAttrList )
191 {
192 	return new SwXMLTableContext(
193 				(SwXMLImport&)rImport, nPrefix, rLocalName, xAttrList );
194 }
195 
IsInHeaderFooter() const196 sal_Bool SwXMLTextImportHelper::IsInHeaderFooter() const
197 {
198 	uno::Reference<XUnoTunnel> xCrsrTunnel(
199 			((SwXMLTextImportHelper *)this)->GetCursor(), UNO_QUERY );
200 	ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
201 	OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper * >(
202 				sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
203 	ASSERT( pTxtCrsr, "SwXTextCursor missing" );
204 	SwDoc *pDoc = pTxtCrsr->GetDoc();
205 
206 	return pDoc && pDoc->IsInHeaderFooter( pTxtCrsr->GetPaM()->GetPoint()->nNode );
207 }
208 
lcl_GetOLENode(const SwFrmFmt * pFrmFmt)209 SwOLENode *lcl_GetOLENode( const SwFrmFmt *pFrmFmt )
210 {
211 	SwOLENode *pOLENd = 0;
212 	if( pFrmFmt )
213 	{
214 		const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt();
215 		const SwNodeIndex *pNdIdx = rCntnt.GetCntntIdx();
216 		pOLENd = pNdIdx->GetNodes()[pNdIdx->GetIndex() + 1]->GetOLENode();
217 	}
218 	ASSERT( pOLENd, "Where is the OLE node" );
219 	return pOLENd;
220 }
221 
createAndInsertOLEObject(SvXMLImport & rImport,const OUString & rHRef,const OUString & rStyleName,const OUString & rTblName,sal_Int32 nWidth,sal_Int32 nHeight)222 uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOLEObject(
223         SvXMLImport& rImport,
224 		const OUString& rHRef,
225 		const OUString& rStyleName,
226 		const OUString& rTblName,
227 		sal_Int32 nWidth, sal_Int32 nHeight )
228 {
229     // this method will modify the document directly -> lock SolarMutex
230 	vos::OGuard aGuard(Application::GetSolarMutex());
231 
232 	uno::Reference < XPropertySet > xPropSet;
233 
234 	sal_Int32 nPos = rHRef.indexOf( ':' );
235 	if( -1 == nPos )
236 		return xPropSet;
237 
238 	OUString aObjName( rHRef.copy( nPos+1) );
239 
240 	if( !aObjName.getLength() )
241 		return xPropSet;
242 
243 	uno::Reference<XUnoTunnel> xCrsrTunnel( GetCursor(), UNO_QUERY );
244 	ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
245 	OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper * >(
246 				sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
247 	ASSERT( pTxtCrsr, "SwXTextCursor missing" );
248 	SwDoc *pDoc = SwImport::GetDocFromXMLImport( rImport );
249 
250 	SfxItemSet aItemSet( pDoc->GetAttrPool(), RES_FRMATR_BEGIN,
251 						 RES_FRMATR_END );
252 	Size aTwipSize( 0, 0 );
253 	Rectangle aVisArea( 0, 0, nWidth, nHeight );
254     lcl_putHeightAndWidth( aItemSet, nHeight, nWidth,
255 						   &aTwipSize.Height(), &aTwipSize.Width() );
256 
257 	SwFrmFmt *pFrmFmt = 0;
258 	SwOLENode *pOLENd = 0;
259 	if( rHRef.copy( 0, nPos ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.ServiceName") ) )
260 	{
261 		sal_Bool bInsert = sal_False;
262 		SvGlobalName aClassName;
263 		const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
264 		while( pEntry->sFilterService )
265 		{
266 			if( aObjName.equalsAsciiL( pEntry->sFilterService,
267 									 pEntry->nFilterServiceLen ) )
268 			{
269 				aClassName = SvGlobalName( pEntry->n1, pEntry->n2,
270 										   pEntry->n3, pEntry->n4,
271 										   pEntry->n5, pEntry->n6,
272 										   pEntry->n7, pEntry->n8,
273 										   pEntry->n9, pEntry->n10,
274 										   pEntry->n11  );
275 				bInsert = sal_True;
276 				break;
277 			}
278 			pEntry++;
279 		}
280 
281 		if( bInsert )
282 		{
283             uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
284             try
285             {
286                 // create object with desired ClassId
287                 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
288                 ::rtl::OUString aName = ::rtl::OUString::createFromAscii( "DummyName" );
289                 uno::Sequence < sal_Int8 > aClass( aClassName.GetByteSequence() );
290                 uno::Reference < embed::XEmbedObjectCreator > xFactory( ::comphelper::getProcessServiceFactory()->createInstance(
291                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.EmbeddedObjectCreator")) ), uno::UNO_QUERY );
292                 uno::Reference < embed::XEmbeddedObject > xObj =
293                     uno::Reference < embed::XEmbeddedObject >( xFactory->createInstanceInitNew(
294                     aClass, ::rtl::OUString(), xStorage, aName,
295                     uno::Sequence < beans::PropertyValue >() ), uno::UNO_QUERY );
296                 if ( xObj.is() )
297                 {
298                     //TODO/LATER: is it enough to only set the VisAreaSize?
299 					lcl_setObjectVisualArea( xObj, nAspect, aTwipSize, MAP_TWIP );
300                 }
301 
302                 pFrmFmt = pDoc->Insert( *pTxtCrsr->GetPaM(),
303 										::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ),
304 										&aItemSet,
305 										NULL,
306 										NULL );
307                 pOLENd = lcl_GetOLENode( pFrmFmt );
308                 if( pOLENd )
309                     aObjName = pOLENd->GetOLEObj().GetCurrentPersistName();
310             }
311             catch ( uno::Exception& )
312             {
313             }
314 		}
315 	}
316 	else
317 	{
318 		// check whether an object with this name already exists in the document
319 		String aName;
320 		SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() );
321 		for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
322 		{
323 			SwOLENode* pExistingOLENd = pNd->GetOLENode();
324 			if( pExistingOLENd )
325 			{
326             	::rtl::OUString aExistingName = pExistingOLENd->GetOLEObj().GetCurrentPersistName();
327 				if ( aExistingName.equals( aObjName ) )
328 				{
329 					OSL_ENSURE( sal_False, "The document contains duplicate object references, means it is partially broken, please let developers know how this document was generated!\n" );
330 
331 					::rtl::OUString aTmpName = pDoc->GetPersist()->GetEmbeddedObjectContainer().CreateUniqueObjectName();
332 					try
333 					{
334 						pDoc->GetPersist()->GetStorage()->copyElementTo( aObjName,
335 																		 pDoc->GetPersist()->GetStorage(),
336 																		 aTmpName );
337 						aName = aTmpName;
338 					}
339 					catch ( uno::Exception& )
340 					{
341 						OSL_ENSURE( sal_False, "Couldn't create a copy of the object!\n" );
342 					}
343 
344 					break;
345 				}
346 			}
347     	}
348 
349 		if ( !aName.Len() )
350 			aName = aObjName;
351 
352 		// the correct aspect will be set later
353 		// TODO/LATER: Actually it should be set here
354         if( pTxtCrsr )
355         {
356             pFrmFmt = pDoc->InsertOLE( *pTxtCrsr->GetPaM(), aName, embed::Aspects::MSOLE_CONTENT, &aItemSet, NULL, NULL );
357             pOLENd = lcl_GetOLENode( pFrmFmt );
358         }
359 		aObjName = aName;
360 	}
361 
362 	if( !pFrmFmt )
363 		return xPropSet;
364 
365 	if( IsInsertMode() )
366 	{
367 		if( !pOLENd )
368 			pOLENd = lcl_GetOLENode( pFrmFmt );
369 		if( pOLENd )
370 			pOLENd->SetOLESizeInvalid( sal_True );
371 	}
372 
373 	SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE );
374 	xPropSet = pXFrame;
375 	if( pDoc->GetDrawModel() )
376 		SwXFrame::GetOrCreateSdrObject(
377 				static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order
378 	if( rTblName.getLength() )
379 	{
380 		const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt();
381 		const SwNodeIndex *pNdIdx = rCntnt.GetCntntIdx();
382 		SwOLENode *pOLENode = pNdIdx->GetNodes()[pNdIdx->GetIndex() + 1]->GetOLENode();
383 		ASSERT( pOLENode, "Where is the OLE node" );
384 
385 		OUStringBuffer aBuffer( rTblName.getLength() );
386 		sal_Bool bQuoted = sal_False;
387 		sal_Bool bEscape = sal_False;
388 		sal_Bool bError = sal_False;
389 		for( sal_Int32 i=0; i < rTblName.getLength(); i++ )
390 		{
391 			sal_Bool bEndOfNameFound = sal_False;
392 			sal_Unicode c = rTblName[i];
393 			switch( c )
394 			{
395 			case '\'':
396 				if( bEscape )
397 				{
398 					aBuffer.append( c );
399 					bEscape = sal_False;
400 				}
401 				else if( bQuoted )
402 				{
403 					bEndOfNameFound = sal_True;
404 				}
405 				else if( 0 == i )
406 				{
407 					bQuoted = sal_True;
408 				}
409 				else
410 				{
411 					bError = sal_True;
412 				}
413 				break;
414 			case '\\':
415 				if( bEscape )
416 				{
417 					aBuffer.append( c );
418 					bEscape = sal_False;
419 				}
420 				else
421 				{
422 					bEscape = sal_True;
423 				}
424 				break;
425 			case ' ':
426 			case '.':
427 				if( !bQuoted )
428 				{
429 					bEndOfNameFound = sal_True;
430 				}
431 				else
432 				{
433 					aBuffer.append( c );
434 					bEscape = sal_False;
435 				}
436 				break;
437 			default:
438 				{
439 					aBuffer.append( c );
440 					bEscape = sal_False;
441 				}
442 				break;
443 			}
444 			if( bError || bEndOfNameFound )
445 				break;
446 		}
447 		if( !bError )
448 		{
449 			OUString sTblName( aBuffer.makeStringAndClear() );
450 			pOLENode->SetChartTblName( GetRenameMap().Get( XML_TEXT_RENAME_TYPE_TABLE, sTblName ) );
451 		}
452 	}
453 
454 	sal_Int64 nDrawAspect = 0;
455 	const XMLPropStyleContext *pStyle = 0;
456 	sal_Bool bHasSizeProps = sal_False;
457 	if( rStyleName.getLength() )
458 	{
459 		pStyle = FindAutoFrameStyle( rStyleName );
460 		if( pStyle )
461 		{
462 			UniReference < SvXMLImportPropertyMapper > xImpPrMap =
463 				pStyle->GetStyles()
464 					  ->GetImportPropertyMapper(pStyle->GetFamily());
465 			ASSERT( xImpPrMap.is(), "Where is the import prop mapper?" );
466 			if( xImpPrMap.is() )
467 			{
468 				UniReference<XMLPropertySetMapper> rPropMapper =
469 				xImpPrMap->getPropertySetMapper();
470 
471 				sal_Int32 nCount = pStyle->GetProperties().size();
472 				for( sal_Int32 i=0; i < nCount; i++ )
473 				{
474 					const XMLPropertyState& rProp = pStyle->GetProperties()[i];
475 					sal_Int32 nIdx = rProp.mnIndex;
476 					if( -1 == nIdx )
477 						continue;
478 
479 					switch( rPropMapper->GetEntryContextId(nIdx) )
480 					{
481 					case CTF_OLE_VIS_AREA_LEFT:
482 						{
483 							sal_Int32 nVal = 0;
484 							rProp.maValue >>= nVal;
485 							aVisArea.setX( nVal );
486 						}
487 						break;
488 					case CTF_OLE_VIS_AREA_TOP:
489 						{
490 							sal_Int32 nVal = 0;
491 							rProp.maValue >>= nVal;
492 							aVisArea.setY( nVal );
493 						}
494 						break;
495 					case CTF_OLE_VIS_AREA_WIDTH:
496 						{
497 							sal_Int32 nVal = 0;
498 							rProp.maValue >>= nVal;
499 							aVisArea.setWidth( nVal );
500 							bHasSizeProps = sal_True;
501 						}
502 						break;
503 					case CTF_OLE_VIS_AREA_HEIGHT:
504 						{
505 							sal_Int32 nVal = 0;
506 							rProp.maValue >>= nVal;
507 							aVisArea.setHeight( nVal );
508 							bHasSizeProps = sal_True;
509 						}
510 						break;
511 					case CTF_OLE_DRAW_ASPECT:
512 						{
513 							rProp.maValue >>= nDrawAspect;
514 
515 							if ( !nDrawAspect )
516 								nDrawAspect = embed::Aspects::MSOLE_CONTENT;
517 
518 							if ( pOLENd )
519 								pOLENd->GetOLEObj().GetObject().SetViewAspect( nDrawAspect );
520 						}
521 						break;
522 					}
523 				}
524 			}
525 		}
526 	}
527 
528 	if ( bHasSizeProps )
529 	{
530     	uno::Reference < embed::XEmbeddedObject > xObj =
531 					pDoc->GetPersist()->GetEmbeddedObjectContainer().GetEmbeddedObject( aObjName );
532     	if( xObj.is() )
533 			lcl_setObjectVisualArea( xObj, ( nDrawAspect ? nDrawAspect : embed::Aspects::MSOLE_CONTENT ),
534 								 	aVisArea.GetSize(), MAP_100TH_MM );
535 	}
536 
537 	return xPropSet;
538 }
539 
createAndInsertOOoLink(SvXMLImport & rImport,const OUString & rHRef,const OUString &,const OUString &,sal_Int32 nWidth,sal_Int32 nHeight)540 uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOOoLink(
541         SvXMLImport& rImport,
542 		const OUString& rHRef,
543 		const OUString& /*rStyleName*/,
544 		const OUString& /*rTblName*/,
545 		sal_Int32 nWidth, sal_Int32 nHeight )
546 {
547     // this method will modify the document directly -> lock SolarMutex
548 	vos::OGuard aGuard(Application::GetSolarMutex());
549 
550 	uno::Reference < XPropertySet > xPropSet;
551 
552 	uno::Reference<XUnoTunnel> xCrsrTunnel( GetCursor(), UNO_QUERY );
553 	ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
554 	OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper * >(
555 				sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
556 	ASSERT( pTxtCrsr, "SwXTextCursor missing" );
557 	SwDoc *pDoc = SwImport::GetDocFromXMLImport( rImport );
558 
559 	SfxItemSet aItemSet( pDoc->GetAttrPool(), RES_FRMATR_BEGIN,
560 						 RES_FRMATR_END );
561 	Size aTwipSize( 0, 0 );
562 	Rectangle aVisArea( 0, 0, nWidth, nHeight );
563     lcl_putHeightAndWidth( aItemSet, nHeight, nWidth,
564 						   &aTwipSize.Height(), &aTwipSize.Width() );
565 
566     // We'll need a (valid) URL. If we don't have do not insert the link and return early.
567 	// Copy URL into URL oject on the way.
568    	INetURLObject aURLObj;
569     bool bValidURL = rHRef.getLength() != 0 &&
570                      aURLObj.SetURL( URIHelper::SmartRel2Abs(
571                                 INetURLObject( GetXMLImport().GetBaseURL() ), rHRef ) );
572     if( !bValidURL )
573 		return xPropSet;
574 
575     uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
576     try
577     {
578         // create object with desired ClassId
579         ::rtl::OUString aName = ::rtl::OUString::createFromAscii( "DummyName" );
580         uno::Reference < embed::XLinkCreator > xFactory( ::comphelper::getProcessServiceFactory()->createInstance(
581                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.OOoEmbeddedObjectFactory")) ),
582 				uno::UNO_QUERY_THROW );
583 
584 		uno::Sequence< beans::PropertyValue > aMediaDescriptor( 1 );
585 		aMediaDescriptor[0].Name = ::rtl::OUString::createFromAscii( "URL" );
586 		aMediaDescriptor[0].Value <<= ::rtl::OUString( aURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
587 		if ( pDoc && pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() )
588 		{
589 			uno::Reference< task::XInteractionHandler > xInteraction =
590 										pDoc->GetDocShell()->GetMedium()->GetInteractionHandler();
591 			if ( xInteraction.is() )
592 			{
593 				aMediaDescriptor.realloc( 2 );
594 				aMediaDescriptor[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) );
595 				aMediaDescriptor[1].Value <<= xInteraction;
596 			}
597 		}
598 
599         uno::Reference < embed::XEmbeddedObject > xObj(
600 			xFactory->createInstanceLink(
601 				xStorage, aName, aMediaDescriptor, uno::Sequence< beans::PropertyValue >() ),
602 			uno::UNO_QUERY_THROW );
603 
604         {
605             SwFrmFmt *pFrmFmt = pDoc->Insert( *pTxtCrsr->GetPaM(),
606 											::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ),
607                                             &aItemSet,
608 											NULL,
609 											NULL );
610 
611             // TODO/LATER: in future may need a way to set replacement image url to the link ( may be even to the object ), needs oasis cws???
612 
613             SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE );
614             xPropSet = pXFrame;
615             if( pDoc->GetDrawModel() )
616                 SwXFrame::GetOrCreateSdrObject(
617                         static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order
618         }
619     }
620     catch ( uno::Exception& )
621     {
622     }
623 
624 	// TODO/LATER: should the rStyleName and rTblName be handled as for usual embedded object?
625 
626 	return xPropSet;
627 }
628 
createAndInsertApplet(const OUString & rName,const OUString & rCode,sal_Bool bMayScript,const OUString & rHRef,sal_Int32 nWidth,sal_Int32 nHeight)629 uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertApplet(
630 		const OUString &rName,
631 		const OUString &rCode,
632 		sal_Bool bMayScript,
633 		const OUString& rHRef,
634 		sal_Int32 nWidth, sal_Int32 nHeight )
635 {
636     // this method will modify the document directly -> lock SolarMutex
637 	vos::OGuard aGuard(Application::GetSolarMutex());
638 
639 	uno::Reference < XPropertySet > xPropSet;
640 	uno::Reference<XUnoTunnel> xCrsrTunnel( GetCursor(), UNO_QUERY );
641 	ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
642 	OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper * >(
643 				sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
644 	ASSERT( pTxtCrsr, "SwXTextCursor missing" );
645 	SwDoc *pDoc = pTxtCrsr->GetDoc();
646 
647 	SfxItemSet aItemSet( pDoc->GetAttrPool(), RES_FRMATR_BEGIN,
648 						 RES_FRMATR_END );
649     lcl_putHeightAndWidth( aItemSet, nHeight, nWidth);
650 
651 	SwApplet_Impl aAppletImpl ( aItemSet );
652 
653     String sCodeBase;
654     if( rHRef.getLength() )
655         sCodeBase = GetXMLImport().GetAbsoluteReference( rHRef );
656 
657     aAppletImpl.CreateApplet ( rCode, rName, bMayScript, sCodeBase, GetXMLImport().GetDocumentBase() );
658 
659 	// set the size of the applet
660 	lcl_setObjectVisualArea( aAppletImpl.GetApplet(),
661 							embed::Aspects::MSOLE_CONTENT,
662 							Size( nWidth, nHeight ),
663 							MAP_100TH_MM );
664 
665 	SwFrmFmt *pFrmFmt = pDoc->Insert( *pTxtCrsr->GetPaM(),
666 									   ::svt::EmbeddedObjectRef( aAppletImpl.GetApplet(), embed::Aspects::MSOLE_CONTENT ),
667 									   &aAppletImpl.GetItemSet(),
668 									   NULL,
669 									   NULL);
670 	SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE );
671 	xPropSet = pXFrame;
672 	if( pDoc->GetDrawModel() )
673 		SwXFrame::GetOrCreateSdrObject(
674 				static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order
675 
676 	return xPropSet;
677 }
678 
createAndInsertPlugin(const OUString & rMimeType,const OUString & rHRef,sal_Int32 nWidth,sal_Int32 nHeight)679 uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertPlugin(
680 		const OUString &rMimeType,
681 		const OUString& rHRef,
682 		sal_Int32 nWidth, sal_Int32 nHeight )
683 {
684 	uno::Reference < XPropertySet > xPropSet;
685 	uno::Reference<XUnoTunnel> xCrsrTunnel( GetCursor(), UNO_QUERY );
686 	ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
687 	OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper * >(
688 			sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
689 	ASSERT( pTxtCrsr, "SwXTextCursor missing" );
690 	SwDoc *pDoc = pTxtCrsr->GetDoc();
691 
692 	SfxItemSet aItemSet( pDoc->GetAttrPool(), RES_FRMATR_BEGIN,
693 						 RES_FRMATR_END );
694     lcl_putHeightAndWidth( aItemSet, nHeight, nWidth);
695 
696     // We'll need a (valid) URL, or we need a MIME type. If we don't have
697     // either, do not insert plugin and return early. Copy URL into URL oject
698     // on the way.
699    	INetURLObject aURLObj;
700 
701     bool bValidURL = rHRef.getLength() != 0 &&
702                      aURLObj.SetURL( URIHelper::SmartRel2Abs( INetURLObject( GetXMLImport().GetBaseURL() ), rHRef ) );
703     bool bValidMimeType = rMimeType.getLength() != 0;
704 	if( !bValidURL && !bValidMimeType )
705 		return xPropSet;
706 
707     uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
708     try
709     {
710         // create object with desired ClassId
711         ::rtl::OUString aName = ::rtl::OUString::createFromAscii( "DummyName" );
712         uno::Sequence < sal_Int8 > aClass( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence() );
713         uno::Reference < embed::XEmbedObjectCreator > xFactory( ::comphelper::getProcessServiceFactory()->createInstance(
714                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.EmbeddedObjectCreator")) ), uno::UNO_QUERY );
715         uno::Reference < embed::XEmbeddedObject > xObj =
716             uno::Reference < embed::XEmbeddedObject >( xFactory->createInstanceInitNew(
717             aClass, ::rtl::OUString(), xStorage, aName,
718             uno::Sequence < beans::PropertyValue >() ), uno::UNO_QUERY );
719 
720 		// set size to the object
721 		lcl_setObjectVisualArea( xObj,
722 								embed::Aspects::MSOLE_CONTENT,
723 								Size( nWidth, nHeight ),
724 								MAP_100TH_MM );
725 
726         if ( svt::EmbeddedObjectRef::TryRunningState( xObj ) )
727         {
728             uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
729             if ( xSet.is() )
730             {
731                 if( bValidURL )
732                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
733                         makeAny( ::rtl::OUString( aURLObj.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
734                 if( bValidMimeType )
735                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginMimeType"),
736                         makeAny( ::rtl::OUString( rMimeType ) ) );
737             }
738 
739             SwFrmFmt *pFrmFmt = pDoc->Insert( *pTxtCrsr->GetPaM(),
740                                             ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ),
741                                             &aItemSet,
742 											NULL,
743 											NULL);
744             SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE );
745             xPropSet = pXFrame;
746             if( pDoc->GetDrawModel() )
747                 SwXFrame::GetOrCreateSdrObject(
748                         static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order
749         }
750     }
751     catch ( uno::Exception& )
752     {
753     }
754 
755 	return xPropSet;
756 }
createAndInsertFloatingFrame(const OUString & rName,const OUString & rHRef,const OUString & rStyleName,sal_Int32 nWidth,sal_Int32 nHeight)757 uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertFloatingFrame(
758 		const OUString& rName,
759 		const OUString& rHRef,
760 		const OUString& rStyleName,
761 		sal_Int32 nWidth, sal_Int32 nHeight )
762 {
763     // this method will modify the document directly -> lock SolarMutex
764 	vos::OGuard aGuard(Application::GetSolarMutex());
765 
766 	uno::Reference < XPropertySet > xPropSet;
767 	uno::Reference<XUnoTunnel> xCrsrTunnel( GetCursor(), UNO_QUERY );
768 	ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
769 	OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper * >(
770 				sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
771 	ASSERT( pTxtCrsr, "SwXTextCursor missing" );
772 	SwDoc *pDoc = pTxtCrsr->GetDoc();
773 
774 	SfxItemSet aItemSet( pDoc->GetAttrPool(), RES_FRMATR_BEGIN,
775 						 RES_FRMATR_END );
776     lcl_putHeightAndWidth( aItemSet, nHeight, nWidth);
777 
778 	ScrollingMode eScrollMode = ScrollingAuto;
779 	sal_Bool bHasBorder = sal_False;
780 	sal_Bool bIsBorderSet = sal_False;
781 	Size aMargin( SIZE_NOT_SET, SIZE_NOT_SET );
782 	const XMLPropStyleContext *pStyle = 0;
783 	if( rStyleName.getLength() )
784 	{
785 		pStyle = FindAutoFrameStyle( rStyleName );
786 		if( pStyle )
787 		{
788 			UniReference < SvXMLImportPropertyMapper > xImpPrMap =
789 				pStyle->GetStyles()
790 					  ->GetImportPropertyMapper(pStyle->GetFamily());
791 			ASSERT( xImpPrMap.is(), "Where is the import prop mapper?" );
792 			if( xImpPrMap.is() )
793 			{
794 				UniReference<XMLPropertySetMapper> rPropMapper =
795 				xImpPrMap->getPropertySetMapper();
796 
797 				sal_Int32 nCount = pStyle->GetProperties().size();
798 				for( sal_Int32 i=0; i < nCount; i++ )
799 				{
800 					const XMLPropertyState& rProp = pStyle->GetProperties()[i];
801 					sal_Int32 nIdx = rProp.mnIndex;
802 					if( -1 == nIdx )
803 						continue;
804 
805 					switch( rPropMapper->GetEntryContextId(nIdx) )
806 					{
807 					case CTF_FRAME_DISPLAY_SCROLLBAR:
808 						{
809 							sal_Bool bYes = *(sal_Bool *)rProp.maValue.getValue();
810 							eScrollMode = bYes ? ScrollingYes : ScrollingNo;
811 						}
812 						break;
813 					case CTF_FRAME_DISPLAY_BORDER:
814 						{
815 							bHasBorder = *(sal_Bool *)rProp.maValue.getValue();
816 							bIsBorderSet = sal_True;
817 						}
818 						break;
819 					case CTF_FRAME_MARGIN_HORI:
820 						{
821 							sal_Int32 nVal = SIZE_NOT_SET;
822 							rProp.maValue >>= nVal;
823 							aMargin.Width() = nVal;
824 						}
825 						break;
826 					case CTF_FRAME_MARGIN_VERT:
827 						{
828 							sal_Int32 nVal = SIZE_NOT_SET;
829 							rProp.maValue >>= nVal;
830 							aMargin.Height() = nVal;
831 						}
832 						break;
833 					}
834 				}
835 			}
836 		}
837 	}
838 
839     uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
840     try
841     {
842         // create object with desired ClassId
843         ::rtl::OUString aName = ::rtl::OUString::createFromAscii( "DummyName" );
844         uno::Sequence < sal_Int8 > aClass( SvGlobalName( SO3_IFRAME_CLASSID ).GetByteSequence() );
845         uno::Reference < embed::XEmbedObjectCreator > xFactory( ::comphelper::getProcessServiceFactory()->createInstance(
846                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.EmbeddedObjectCreator")) ), uno::UNO_QUERY );
847         uno::Reference < embed::XEmbeddedObject > xObj =
848             uno::Reference < embed::XEmbeddedObject >( xFactory->createInstanceInitNew(
849             aClass, ::rtl::OUString(), xStorage, aName,
850             uno::Sequence < beans::PropertyValue >() ), uno::UNO_QUERY );
851 
852 		// set size to the object
853 		lcl_setObjectVisualArea( xObj,
854 								embed::Aspects::MSOLE_CONTENT,
855 								Size( nWidth, nHeight ),
856 								MAP_100TH_MM );
857 
858         if ( svt::EmbeddedObjectRef::TryRunningState( xObj ) )
859         {
860             uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
861             if ( xSet.is() )
862             {
863                 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameURL"),
864                     makeAny( ::rtl::OUString( URIHelper::SmartRel2Abs(
865                             INetURLObject( GetXMLImport().GetBaseURL() ), rHRef ) ) ) );
866 
867                 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameName"),
868                     makeAny( ::rtl::OUString( rName ) ) );
869 
870                 if ( eScrollMode == ScrollingAuto )
871                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll"),
872                         makeAny( sal_True ) );
873                 else
874                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode"),
875                         makeAny( (sal_Bool) (eScrollMode == ScrollingYes) ) );
876 
877                 if ( bIsBorderSet )
878                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder"),
879                         makeAny( bHasBorder ) );
880                 else
881                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder"),
882                         makeAny( sal_True ) );
883 
884                 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth"),
885                     makeAny( sal_Int32( aMargin.Width() ) ) );
886 
887                 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight"),
888                     makeAny( sal_Int32( aMargin.Height() ) ) );
889             }
890 
891             SwFrmFmt *pFrmFmt = pDoc->Insert( *pTxtCrsr->GetPaM(),
892                                             ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ),
893                                             &aItemSet,
894 											NULL,
895 											NULL);
896             SwXFrame *pXFrame = SwXFrames::GetObject( *pFrmFmt, FLYCNTTYPE_OLE );
897             xPropSet = pXFrame;
898             if( pDoc->GetDrawModel() )
899                 SwXFrame::GetOrCreateSdrObject(
900                         static_cast<SwFlyFrmFmt*>( pXFrame->GetFrmFmt() ) ); // req for z-order
901         }
902     }
903     catch ( uno::Exception& )
904     {
905     }
906 
907 	return xPropSet;
908 }
909 
endAppletOrPlugin(const uno::Reference<XPropertySet> & rPropSet,::std::map<const::rtl::OUString,::rtl::OUString,::comphelper::UStringLess> & rParamMap)910 void SwXMLTextImportHelper::endAppletOrPlugin(
911         const uno::Reference < XPropertySet > &rPropSet,
912         ::std::map < const ::rtl::OUString, ::rtl::OUString, ::comphelper::UStringLess > &rParamMap)
913 {
914     // this method will modify the document directly -> lock SolarMutex
915 	vos::OGuard aGuard(Application::GetSolarMutex());
916 
917     uno::Reference<XUnoTunnel> xCrsrTunnel( rPropSet, UNO_QUERY );
918 	ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for embedded" );
919 	SwXFrame *pFrame = reinterpret_cast< SwXFrame * >(
920 				sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( SwXFrame::getUnoTunnelId() )));
921 	ASSERT( pFrame, "SwXFrame missing" );
922 	SwFrmFmt *pFrmFmt = pFrame->GetFrmFmt();
923 	const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt();
924 	const SwNodeIndex *pNdIdx = rCntnt.GetCntntIdx();
925 	SwOLENode *pOLENd = pNdIdx->GetNodes()[pNdIdx->GetIndex() + 1]->GetNoTxtNode()->GetOLENode();
926     SwOLEObj& rOLEObj = pOLENd->GetOLEObj();
927 
928     uno::Reference < embed::XEmbeddedObject > xEmbObj( rOLEObj.GetOleRef() );
929     if ( svt::EmbeddedObjectRef::TryRunningState( xEmbObj ) )
930     {
931         uno::Reference < beans::XPropertySet > xSet( xEmbObj->getComponent(), uno::UNO_QUERY );
932         if ( xSet.is() )
933         {
934             const sal_Int32 nCount = rParamMap.size();
935             uno::Sequence< beans::PropertyValue > aCommandSequence( nCount );
936 
937             ::std::map < const ::rtl::OUString, ::rtl::OUString, ::comphelper::UStringLess > ::iterator aIter = rParamMap.begin();
938             ::std::map < const ::rtl::OUString, ::rtl::OUString, ::comphelper::UStringLess > ::iterator aEnd = rParamMap.end();
939             sal_Int32 nIndex=0;
940             while (aIter != aEnd )
941             {
942                 aCommandSequence[nIndex].Name = (*aIter).first;
943                 aCommandSequence[nIndex].Handle = -1;
944                 aCommandSequence[nIndex].Value = makeAny( OUString((*aIter).second) );
945                 aCommandSequence[nIndex].State = beans::PropertyState_DIRECT_VALUE;
946                 aIter++, nIndex++;
947             }
948 
949             // unfortunately the names of the properties are depending on the object
950             ::rtl::OUString aParaName = ::rtl::OUString::createFromAscii("AppletCommands");
951             try
952             {
953                 xSet->setPropertyValue( aParaName, makeAny( aCommandSequence ) );
954             }
955             catch ( uno::Exception& )
956             {
957                 aParaName = ::rtl::OUString::createFromAscii("PluginCommands");
958                 try
959                 {
960                     xSet->setPropertyValue( aParaName, makeAny( aCommandSequence ) );
961                 }
962                 catch ( uno::Exception& )
963                 {
964                 }
965             }
966         }
967     }
968 }
969 
CreateTextImport()970 XMLTextImportHelper* SwXMLImport::CreateTextImport()
971 {
972 	return new SwXMLTextImportHelper( GetModel(), *this, getImportInfo(),
973 									  IsInsertMode(),
974 									  IsStylesOnlyMode(), bShowProgress,
975 									  IsBlockMode(), IsOrganizerMode(),
976 									  bPreserveRedlineMode );
977 }
978 
979 
980 // redlining helper methods
981 // (override to provide the real implementation)
982 
RedlineAdd(const OUString & rType,const OUString & rId,const OUString & rAuthor,const OUString & rComment,const util::DateTime & rDateTime,sal_Bool bMergeLastPara)983 void SwXMLTextImportHelper::RedlineAdd(
984 	const OUString& rType,
985 	const OUString& rId,
986 	const OUString& rAuthor,
987 	const OUString& rComment,
988 	const util::DateTime& rDateTime,
989     sal_Bool bMergeLastPara)
990 {
991 	// create redline helper on demand
992 	DBG_ASSERT(NULL != pRedlineHelper, "helper should have been created in constructor");
993 	if (NULL != pRedlineHelper)
994 		pRedlineHelper->Add(rType, rId, rAuthor, rComment, rDateTime,
995                             bMergeLastPara);
996 }
997 
RedlineCreateText(uno::Reference<XTextCursor> & rOldCursor,const OUString & rId)998 uno::Reference<XTextCursor> SwXMLTextImportHelper::RedlineCreateText(
999 	uno::Reference<XTextCursor> & rOldCursor,
1000 	const OUString& rId)
1001 {
1002 	uno::Reference<XTextCursor> xRet;
1003 
1004 	if (NULL != pRedlineHelper)
1005 	{
1006 		xRet = pRedlineHelper->CreateRedlineTextSection(rOldCursor, rId);
1007 	}
1008 
1009 	return xRet;
1010 }
1011 
RedlineSetCursor(const OUString & rId,sal_Bool bStart,sal_Bool bIsOutsideOfParagraph)1012 void SwXMLTextImportHelper::RedlineSetCursor(
1013 	const OUString& rId,
1014 	sal_Bool bStart,
1015 	sal_Bool bIsOutsideOfParagraph)
1016 {
1017 	if (NULL != pRedlineHelper) {
1018         uno::Reference<XTextRange> xTextRange( GetCursor()->getStart() );
1019 		pRedlineHelper->SetCursor(rId, bStart, xTextRange,
1020 								  bIsOutsideOfParagraph);
1021     }
1022 	// else: ignore redline (wasn't added before, else we'd have a helper)
1023 }
1024 
RedlineAdjustStartNodeCursor(sal_Bool bStart)1025 void SwXMLTextImportHelper::RedlineAdjustStartNodeCursor(
1026 	sal_Bool bStart)
1027 {
1028 	OUString rId = GetOpenRedlineId();
1029 	if ((NULL != pRedlineHelper) && (rId.getLength() > 0))
1030 	{
1031         uno::Reference<XTextRange> xTextRange( GetCursor()->getStart() );
1032 		pRedlineHelper->AdjustStartNodeCursor(rId, bStart, xTextRange );
1033 		ResetOpenRedlineId();
1034 	}
1035 	// else: ignore redline (wasn't added before, or no open redline ID
1036 }
1037 
SetShowChanges(sal_Bool bShowChanges)1038 void SwXMLTextImportHelper::SetShowChanges( sal_Bool bShowChanges )
1039 {
1040 	if ( NULL != pRedlineHelper )
1041 		pRedlineHelper->SetShowChanges( bShowChanges );
1042 }
1043 
SetRecordChanges(sal_Bool bRecordChanges)1044 void SwXMLTextImportHelper::SetRecordChanges( sal_Bool bRecordChanges )
1045 {
1046 	if ( NULL != pRedlineHelper )
1047 		pRedlineHelper->SetRecordChanges( bRecordChanges );
1048 }
1049 
SetChangesProtectionKey(const Sequence<sal_Int8> & rKey)1050 void SwXMLTextImportHelper::SetChangesProtectionKey(
1051 	const Sequence<sal_Int8> & rKey )
1052 {
1053 	if ( NULL != pRedlineHelper )
1054 		pRedlineHelper->SetProtectionKey( rKey );
1055 }
1056 
1057 
1058 
1059