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