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