LibreOffice Module sw (master) 1
xmltexti.cxx
Go to the documentation of this file.
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
25#include <com/sun/star/embed/EmbeddedObjectCreator.hpp>
26#include <com/sun/star/embed/OOoEmbeddedObjectFactory.hpp>
27#include <com/sun/star/embed/XEmbeddedObject.hpp>
28#include <com/sun/star/embed/Aspects.hpp>
29#include <com/sun/star/frame/XModel.hpp>
30#include <com/sun/star/task/XInteractionHandler.hpp>
31#include <o3tl/any.hxx>
32#include <osl/diagnose.h>
33#include <rtl/ustrbuf.hxx>
34#include <sal/log.hxx>
36#include <com/sun/star/lang/XUnoTunnel.hpp>
37#include <xmloff/prstylei.hxx>
38#include <xmloff/maptype.hxx>
39#include <xmloff/xmlprmap.hxx>
40#include <xmloff/txtprmap.hxx>
41#include <xmloff/i18nmap.hxx>
42#include <xmloff/xmlimppr.hxx>
43#include <TextCursorHelper.hxx>
44#include <unoframe.hxx>
45#include <doc.hxx>
48#include <fmtfsize.hxx>
49#include <fmtanchr.hxx>
50#include <fmtcntnt.hxx>
51#include "xmlimp.hxx"
52#include "xmltbli.hxx"
53#include "xmltexti.hxx"
56#include <SwAppletImpl.hxx>
57#include <ndole.hxx>
58#include <docsh.hxx>
59#include <sfx2/docfile.hxx>
60#include <vcl/svapp.hxx>
62#include <svtools/embedhlp.hxx>
63#include <svl/urihelper.hxx>
64#include <sfx2/frmdescr.hxx>
65#include <tools/globname.hxx>
66
67#include <algorithm>
68#include <utility>
69
70using namespace ::com::sun::star;
71using namespace ::com::sun::star::uno;
72using namespace ::com::sun::star::lang;
73using namespace ::com::sun::star::text;
74using namespace ::com::sun::star::frame;
75using namespace ::com::sun::star::beans;
76using namespace xml::sax;
77
78const std::pair<OUString, SvGUID> aServiceMap[] = {
85};
86static void lcl_putHeightAndWidth ( SfxItemSet &rItemSet,
87 sal_Int32 nHeight, sal_Int32 nWidth,
88 Size *pTwipSize = nullptr )
89{
90 if( nWidth > 0 && nHeight > 0 )
91 {
92 nWidth = o3tl::toTwips(nWidth, o3tl::Length::mm100);
93 if( nWidth < MINFLY )
94 nWidth = MINFLY;
95 nHeight = o3tl::toTwips(nHeight, o3tl::Length::mm100);
96 if( nHeight < MINFLY )
97 nHeight = MINFLY;
98 rItemSet.Put( SwFormatFrameSize( SwFrameSize::Fixed, nWidth, nHeight ) );
99 }
100
101 SwFormatAnchor aAnchor( RndStdIds::FLY_AT_CHAR );
102 rItemSet.Put( aAnchor );
103
104 if( pTwipSize )
105 {
106 pTwipSize->setWidth( nWidth );
107 pTwipSize->setHeight( nHeight);
108 }
109}
110
111static void lcl_setObjectVisualArea( const uno::Reference< embed::XEmbeddedObject >& xObj,
112 sal_Int64 nAspect,
113 const Size& aVisSize,
114 const MapUnit& aUnit )
115{
116 if( !(xObj.is() && nAspect != embed::Aspects::MSOLE_ICON) )
117 return;
118
119 // convert the visual area to the objects units
120 MapUnit aObjUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
121 Size aObjVisSize = OutputDevice::LogicToLogic(aVisSize, MapMode(aUnit), MapMode(aObjUnit));
122 awt::Size aSz;
123 aSz.Width = aObjVisSize.Width();
124 aSz.Height = aObjVisSize.Height();
125
126 try
127 {
128 xObj->setVisualAreaSize( nAspect, aSz );
129 }
130 catch( uno::Exception& )
131 {
132 OSL_FAIL( "Couldn't set visual area of the object!" );
133 }
134}
135
137 const uno::Reference < XModel>& rModel,
138 SvXMLImport& rImport,
139 const uno::Reference<XPropertySet> & rInfoSet,
140 bool bInsertM, bool bStylesOnlyM,
141 bool bBlockM, bool bOrganizerM ) :
142 XMLTextImportHelper( rModel, rImport, bInsertM, bStylesOnlyM, true/*bProgress*/,
143 bBlockM, bOrganizerM ),
144 m_pRedlineHelper( nullptr )
145{
146 uno::Reference<XPropertySet> xDocPropSet( rModel, UNO_QUERY );
148 bInsertM || bBlockM, xDocPropSet, rInfoSet );
149}
150
152{
153 // the redline helper destructor sets properties on the document
154 // and may throw an exception while doing so... catch this
155 try
156 {
157 delete m_pRedlineHelper;
158 }
159 catch ( const RuntimeException& )
160 {
161 // ignore
162 }
163}
164
166 SvXMLImport& rImport,
167 sal_Int32 /*nElement*/,
168 const uno::Reference< XFastAttributeList > & xAttrList )
169{
170 return new SwXMLTableContext( static_cast<SwXMLImport&>(rImport), xAttrList );
171}
172
174{
175 OTextCursorHelper* pTextCursor = dynamic_cast<OTextCursorHelper*>(const_cast<SwXMLTextImportHelper *>(this)->GetCursor().get());
176 SAL_WARN_IF(!pTextCursor, "sw.uno", "SwXTextCursor missing");
177 SwDoc *pDoc = pTextCursor ? pTextCursor->GetDoc() : nullptr;
178
179 return pDoc && pDoc->IsInHeaderFooter( pTextCursor->GetPaM()->GetPoint()->GetNode() );
180}
181
182static SwOLENode *lcl_GetOLENode( const SwFrameFormat *pFrameFormat )
183{
184 SwOLENode *pOLENd = nullptr;
185 if( pFrameFormat )
186 {
187 const SwFormatContent& rContent = pFrameFormat->GetContent();
188 const SwNodeIndex *pNdIdx = rContent.GetContentIdx();
189 pOLENd = pNdIdx->GetNodes()[pNdIdx->GetIndex() + 1]->GetOLENode();
190 }
191 OSL_ENSURE( pOLENd, "Where is the OLE node" );
192 return pOLENd;
193}
194
196 SvXMLImport& rImport,
197 const OUString& rHRef,
198 const OUString& rStyleName,
199 const OUString& rTableName,
200 sal_Int32 nWidth, sal_Int32 nHeight )
201{
202 // this method will modify the document directly -> lock SolarMutex
203 SolarMutexGuard aGuard;
204
205 uno::Reference < XPropertySet > xPropSet;
206
207 sal_Int32 nPos = rHRef.indexOf( ':' );
208 if( -1 == nPos )
209 return xPropSet;
210
211 OUString aObjName( rHRef.copy( nPos+1) );
212
213 if( aObjName.isEmpty() )
214 return xPropSet;
215
216 OTextCursorHelper* pTextCursor = dynamic_cast<OTextCursorHelper*>(GetCursor().get());
217 SAL_WARN_IF(!pTextCursor, "sw.uno", "SwXTextCursor missing");
218 SwDoc *pDoc = static_cast<SwXMLImport&>(rImport).getDoc();
219
221 Size aTwipSize( 0, 0 );
222 tools::Rectangle aVisArea( 0, 0, nWidth, nHeight );
223 lcl_putHeightAndWidth( aItemSet, nHeight, nWidth,
224 &aTwipSize );
225
226 SwFrameFormat *pFrameFormat = nullptr;
227 SwOLENode *pOLENd = nullptr;
228 if( rHRef.startsWith("vnd.sun.star.ServiceName:") )
229 {
230 bool bInsert = false;
231 SvGlobalName aClassName;
232 for (const auto& [sFilterService, rCLASSID] : aServiceMap)
233 {
234 if (aObjName == sFilterService)
235 {
236 aClassName = SvGlobalName(rCLASSID);
237 bInsert = true;
238 break;
239 }
240 }
241
242 if( bInsert )
243 {
244 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
245 try
246 {
247 // create object with desired ClassId
248 uno::Sequence < sal_Int8 > aClass( aClassName.GetByteSequence() );
249 uno::Reference < embed::XEmbeddedObjectCreator > xFactory = embed::EmbeddedObjectCreator::create( ::comphelper::getProcessComponentContext() );
250 uno::Sequence<beans::PropertyValue> aObjArgs( comphelper::InitPropertySequence({
251 { "DefaultParentBaseURL", Any(GetXMLImport().GetBaseURL()) }
252 }));
253 uno::Reference < embed::XEmbeddedObject > xObj( xFactory->createInstanceInitNew(
254 aClass, OUString(), xStorage, "DummyName", aObjArgs), uno::UNO_QUERY );
255 if ( xObj.is() )
256 {
257 //TODO/LATER: is it enough to only set the VisAreaSize?
258 lcl_setObjectVisualArea( xObj, embed::Aspects::MSOLE_CONTENT, aTwipSize, MapUnit::MapTwip );
259 }
260
261 if( pTextCursor )
262 {
263 pFrameFormat = pDoc->getIDocumentContentOperations().InsertEmbObject(
264 *pTextCursor->GetPaM(),
265 ::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT),
266 &aItemSet);
267 pOLENd = lcl_GetOLENode( pFrameFormat );
268 }
269
270 if( pOLENd )
271 aObjName = pOLENd->GetOLEObj().GetCurrentPersistName();
272 }
273 catch ( uno::Exception& )
274 {
275 }
276 }
277 }
278 else
279 {
280 // check whether an object with this name already exists in the document
281 OUString aName;
283 for( SwContentNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
284 {
285 SwOLENode* pExistingOLENd = pNd->GetOLENode();
286 if( pExistingOLENd )
287 {
288 OUString aExistingName = pExistingOLENd->GetOLEObj().GetCurrentPersistName();
289 if ( aExistingName == aObjName )
290 {
291 OSL_FAIL( "The document contains duplicate object references, means it is partially broken, please let developers know how this document was generated!" );
292
293 OUString aTmpName = pDoc->GetPersist()->GetEmbeddedObjectContainer().CreateUniqueObjectName();
294 try
295 {
296 pDoc->GetPersist()->GetStorage()->copyElementTo( aObjName,
297 pDoc->GetPersist()->GetStorage(),
298 aTmpName );
299 aName = aTmpName;
300 }
301 catch ( uno::Exception& )
302 {
303 OSL_FAIL( "Couldn't create a copy of the object!" );
304 }
305
306 break;
307 }
308 }
309 }
310
311 if ( aName.isEmpty() )
312 aName = aObjName;
313
314 // the correct aspect will be set later
315 // TODO/LATER: Actually it should be set here
316 if( pTextCursor )
317 {
318 pFrameFormat = pDoc->getIDocumentContentOperations().InsertOLE( *pTextCursor->GetPaM(), aName, embed::Aspects::MSOLE_CONTENT, &aItemSet, nullptr );
319 pOLENd = lcl_GetOLENode( pFrameFormat );
320 }
321 aObjName = aName;
322 }
323
324 if( !pFrameFormat )
325 return xPropSet;
326
327 if( IsInsertMode() )
328 {
329 if( !pOLENd )
330 pOLENd = lcl_GetOLENode( pFrameFormat );
331 if( pOLENd )
332 pOLENd->SetOLESizeInvalid( true );
333 }
334
336 *pDoc, pFrameFormat);
338 {
339 // req for z-order
340 SwXFrame::GetOrCreateSdrObject(*static_cast<SwFlyFrameFormat*>(pFrameFormat));
341 }
342 if( !rTableName.isEmpty() )
343 {
344 const SwFormatContent& rContent = pFrameFormat->GetContent();
345 const SwNodeIndex *pNdIdx = rContent.GetContentIdx();
346 SwOLENode *pOLENode = pNdIdx->GetNodes()[pNdIdx->GetIndex() + 1]->GetOLENode();
347 OSL_ENSURE( pOLENode, "Where is the OLE node" );
348
349 OUStringBuffer aBuffer( rTableName.getLength() );
350 bool bQuoted = false;
351 bool bEscape = false;
352 bool bError = false;
353 for( sal_Int32 i=0; i < rTableName.getLength(); i++ )
354 {
355 bool bEndOfNameFound = false;
356 sal_Unicode c = rTableName[i];
357 switch( c )
358 {
359 case '\'':
360 if( bEscape )
361 {
362 aBuffer.append( c );
363 bEscape = false;
364 }
365 else if( bQuoted )
366 {
367 bEndOfNameFound = true;
368 }
369 else if( 0 == i )
370 {
371 bQuoted = true;
372 }
373 else
374 {
375 bError = true;
376 }
377 break;
378 case '\\':
379 if( bEscape )
380 {
381 aBuffer.append( c );
382 bEscape = false;
383 }
384 else
385 {
386 bEscape = true;
387 }
388 break;
389 case ' ':
390 case '.':
391 if( !bQuoted )
392 {
393 bEndOfNameFound = true;
394 }
395 else
396 {
397 aBuffer.append( c );
398 bEscape = false;
399 }
400 break;
401 default:
402 {
403 aBuffer.append( c );
404 bEscape = false;
405 }
406 break;
407 }
408 if( bError || bEndOfNameFound )
409 break;
410 }
411 if( !bError )
412 {
413 OUString sTableName( aBuffer.makeStringAndClear() );
414 pOLENode->SetChartTableName( GetRenameMap().Get( XML_TEXT_RENAME_TYPE_TABLE, sTableName ) );
415 }
416 }
417
418 sal_Int64 nDrawAspect = 0;
419 const XMLPropStyleContext *pStyle = nullptr;
420 bool bHasSizeProps = false;
421 if( !rStyleName.isEmpty() )
422 {
423 pStyle = FindAutoFrameStyle( rStyleName );
424 if( pStyle )
425 {
427 pStyle->GetStyles()
429 OSL_ENSURE( xImpPrMap.is(), "Where is the import prop mapper?" );
430 if( xImpPrMap.is() )
431 {
433 xImpPrMap->getPropertySetMapper();
434
435 sal_Int32 nCount = pStyle->GetProperties().size();
436 for( sal_Int32 i=0; i < nCount; i++ )
437 {
438 const XMLPropertyState& rProp = pStyle->GetProperties()[i];
439 sal_Int32 nIdx = rProp.mnIndex;
440 if( -1 == nIdx )
441 continue;
442
443 switch( rPropMapper->GetEntryContextId(nIdx) )
444 {
446 {
447 sal_Int32 nVal = 0;
448 rProp.maValue >>= nVal;
449 aVisArea.SetPosX( nVal );
450 }
451 break;
453 {
454 sal_Int32 nVal = 0;
455 rProp.maValue >>= nVal;
456 aVisArea.SetPosY( nVal );
457 }
458 break;
460 {
461 sal_Int32 nVal = 0;
462 rProp.maValue >>= nVal;
463 aVisArea.setWidth( nVal );
464 bHasSizeProps = true;
465 }
466 break;
468 {
469 sal_Int32 nVal = 0;
470 rProp.maValue >>= nVal;
471 aVisArea.setHeight( nVal );
472 bHasSizeProps = true;
473 }
474 break;
476 {
477 rProp.maValue >>= nDrawAspect;
478
479 if ( !nDrawAspect )
480 nDrawAspect = embed::Aspects::MSOLE_CONTENT;
481
482 if ( pOLENd )
483 pOLENd->GetOLEObj().GetObject().SetViewAspect( nDrawAspect );
484 }
485 break;
486 }
487 }
488 }
489 }
490 }
491
492 if ( bHasSizeProps )
493 {
494 uno::Reference < embed::XEmbeddedObject > xObj =
496 if( xObj.is() )
497 lcl_setObjectVisualArea( xObj, ( nDrawAspect ? nDrawAspect : embed::Aspects::MSOLE_CONTENT ),
498 aVisArea.GetSize(), MapUnit::Map100thMM );
499 }
500
501 return xPropSet;
502}
503
505 SvXMLImport& rImport,
506 const OUString& rHRef,
507 const OUString& /*rStyleName*/,
508 const OUString& /*rTableName*/,
509 sal_Int32 nWidth, sal_Int32 nHeight )
510{
511 // this method will modify the document directly -> lock SolarMutex
512 SolarMutexGuard aGuard;
513
514 uno::Reference < XPropertySet > xPropSet;
515
516 OTextCursorHelper* pTextCursor = dynamic_cast<OTextCursorHelper*>(GetCursor().get());
517 assert( pTextCursor && "SwXTextCursor missing" );
518 SwDoc *pDoc = static_cast<SwXMLImport&>(rImport).getDoc();
519
521 Size aTwipSize( 0, 0 );
522 lcl_putHeightAndWidth( aItemSet, nHeight, nWidth,
523 &aTwipSize );
524
525 // We'll need a (valid) URL. If we don't have do not insert the link and return early.
526 // Copy URL into URL object on the way.
527 INetURLObject aURLObj;
528 bool bValidURL = !rHRef.isEmpty() &&
530 INetURLObject( GetXMLImport().GetBaseURL() ), rHRef ) );
531 if( !bValidURL )
532 return xPropSet;
533
534 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
535 try
536 {
537 // create object with desired ClassId
538 uno::Reference < embed::XEmbeddedObjectCreator > xFactory =
539 embed::OOoEmbeddedObjectFactory::create(::comphelper::getProcessComponentContext());
540
541 uno::Sequence< beans::PropertyValue > aMediaDescriptor{ comphelper::makePropertyValue(
543
544 if (SfxMedium* pMedium = pDoc->GetDocShell() ? pDoc->GetDocShell()->GetMedium() : nullptr)
545 {
546 uno::Reference< task::XInteractionHandler > xInteraction = pMedium->GetInteractionHandler();
547 if ( xInteraction.is() )
548 {
549 aMediaDescriptor.realloc( 2 );
550 auto pMediaDescriptor = aMediaDescriptor.getArray();
551 pMediaDescriptor[1].Name = "InteractionHandler";
552 pMediaDescriptor[1].Value <<= xInteraction;
553 }
554
555 const auto nLen = aMediaDescriptor.getLength() + 1;
556 aMediaDescriptor.realloc(nLen);
557 auto pMediaDescriptor = aMediaDescriptor.getArray();
558 pMediaDescriptor[nLen - 1].Name = "Referer";
559 pMediaDescriptor[nLen - 1].Value <<= pMedium->GetName();
560 }
561
562 uno::Reference < embed::XEmbeddedObject > xObj(
563 xFactory->createInstanceLink(
564 xStorage, "DummyName", aMediaDescriptor, uno::Sequence< beans::PropertyValue >() ),
565 uno::UNO_QUERY_THROW );
566
567 {
568 SwFrameFormat *const pFrameFormat =
570 *pTextCursor->GetPaM(),
571 ::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT),
572 &aItemSet );
573
574 // 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???
575
577 *pDoc, pFrameFormat);
579 {
580 SwXFrame::GetOrCreateSdrObject(*
581 static_cast<SwFlyFrameFormat*>(pFrameFormat)); // req for z-order
582 }
583 }
584 }
585 catch ( uno::Exception& )
586 {
587 }
588
589 // TODO/LATER: should the rStyleName and rTableName be handled as for usual embedded object?
590
591 return xPropSet;
592}
593
594uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertApplet(
595 const OUString &rName,
596 const OUString &rCode,
597 bool bMayScript,
598 const OUString& rHRef,
599 sal_Int32 nWidth, sal_Int32 nHeight )
600{
601 // this method will modify the document directly -> lock SolarMutex
602 SolarMutexGuard aGuard;
603
604 uno::Reference < XPropertySet > xPropSet;
605 OTextCursorHelper* pTextCursor = dynamic_cast<OTextCursorHelper*>(GetCursor().get());
606 assert( pTextCursor && "SwXTextCursor missing" );
607 SwDoc *pDoc = pTextCursor->GetDoc();
608
610 lcl_putHeightAndWidth( aItemSet, nHeight, nWidth);
611
612 SwApplet_Impl aAppletImpl ( std::move(aItemSet) );
613
614 OUString sCodeBase;
615 if( !rHRef.isEmpty() )
616 sCodeBase = GetXMLImport().GetAbsoluteReference( rHRef );
617
618 aAppletImpl.CreateApplet ( rCode, rName, bMayScript, sCodeBase, GetXMLImport().GetDocumentBase() );
619
620 // set the size of the applet
621 lcl_setObjectVisualArea( aAppletImpl.GetApplet(),
622 embed::Aspects::MSOLE_CONTENT,
623 Size( nWidth, nHeight ),
624 MapUnit::Map100thMM );
625
626 SwFrameFormat *const pFrameFormat =
627 pDoc->getIDocumentContentOperations().InsertEmbObject( *pTextCursor->GetPaM(),
628 ::svt::EmbeddedObjectRef(aAppletImpl.GetApplet(), embed::Aspects::MSOLE_CONTENT),
629 &aAppletImpl.GetItemSet());
631 *pDoc, pFrameFormat);
633 {
634 // req for z-order
635 SwXFrame::GetOrCreateSdrObject(*static_cast<SwFlyFrameFormat*>(pFrameFormat));
636 }
637
638 return xPropSet;
639}
640
641uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertPlugin(
642 const OUString &rMimeType,
643 const OUString& rHRef,
644 sal_Int32 nWidth, sal_Int32 nHeight )
645{
646 uno::Reference < XPropertySet > xPropSet;
647 OTextCursorHelper* pTextCursor = dynamic_cast<OTextCursorHelper*>(GetCursor().get());
648 assert( pTextCursor && "SwXTextCursor missing" );
649 SwDoc *pDoc = pTextCursor->GetDoc();
650
652 lcl_putHeightAndWidth( aItemSet, nHeight, nWidth);
653
654 // We'll need a (valid) URL, or we need a MIME type. If we don't have
655 // either, do not insert plugin and return early. Copy URL into URL object
656 // on the way.
657 INetURLObject aURLObj;
658
659 bool bValidURL = !rHRef.isEmpty() &&
660 aURLObj.SetURL( URIHelper::SmartRel2Abs( INetURLObject( GetXMLImport().GetBaseURL() ), rHRef ) );
661 bool bValidMimeType = !rMimeType.isEmpty();
662 if( !bValidURL && !bValidMimeType )
663 return xPropSet;
664
665 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
666 try
667 {
668 // create object with desired ClassId
669 uno::Sequence < sal_Int8 > aClass( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence() );
670 uno::Reference < embed::XEmbeddedObjectCreator > xFactory = embed::EmbeddedObjectCreator::create( ::comphelper::getProcessComponentContext() );
671 uno::Reference < embed::XEmbeddedObject > xObj( xFactory->createInstanceInitNew(
672 aClass, OUString(), xStorage, "DummyName",
673 uno::Sequence < beans::PropertyValue >() ), uno::UNO_QUERY );
674
675 // set size to the object
677 embed::Aspects::MSOLE_CONTENT,
678 Size( nWidth, nHeight ),
679 MapUnit::Map100thMM );
680
682 {
683 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
684 if ( xSet.is() )
685 {
686 if( bValidURL )
687 xSet->setPropertyValue("PluginURL",
689 if( bValidMimeType )
690 xSet->setPropertyValue("PluginMimeType",
691 Any( rMimeType ) );
692 }
693
694 SwFrameFormat *const pFrameFormat =
696 *pTextCursor->GetPaM(),
697 ::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT),
698 &aItemSet);
700 *pDoc, pFrameFormat);
702 {
703 SwXFrame::GetOrCreateSdrObject(*
704 static_cast<SwFlyFrameFormat*>(pFrameFormat)); // req for z-order
705 }
706 }
707 }
708 catch ( uno::Exception& )
709 {
710 }
711
712 return xPropSet;
713}
715 const OUString& rName,
716 const OUString& rHRef,
717 const OUString& rStyleName,
718 sal_Int32 nWidth, sal_Int32 nHeight )
719{
720 // this method will modify the document directly -> lock SolarMutex
721 SolarMutexGuard aGuard;
722
723 uno::Reference < XPropertySet > xPropSet;
724 OTextCursorHelper* pTextCursor = dynamic_cast<OTextCursorHelper*>(GetCursor().get());
725 assert( pTextCursor && "SwXTextCursor missing" );
726 SwDoc *pDoc = pTextCursor->GetDoc();
727
729 lcl_putHeightAndWidth( aItemSet, nHeight, nWidth);
730
731 ScrollingMode eScrollMode = ScrollingMode::Auto;
732 bool bHasBorder = false;
733 bool bIsBorderSet = false;
734 Size aMargin( SIZE_NOT_SET, SIZE_NOT_SET );
735 const XMLPropStyleContext *pStyle = nullptr;
736 if( !rStyleName.isEmpty() )
737 {
738 pStyle = FindAutoFrameStyle( rStyleName );
739 if( pStyle )
740 {
742 pStyle->GetStyles()
744 OSL_ENSURE( xImpPrMap.is(), "Where is the import prop mapper?" );
745 if( xImpPrMap.is() )
746 {
748 xImpPrMap->getPropertySetMapper();
749
750 sal_Int32 nCount = pStyle->GetProperties().size();
751 for( sal_Int32 i=0; i < nCount; i++ )
752 {
753 const XMLPropertyState& rProp = pStyle->GetProperties()[i];
754 sal_Int32 nIdx = rProp.mnIndex;
755 if( -1 == nIdx )
756 continue;
757
758 switch( rPropMapper->GetEntryContextId(nIdx) )
759 {
761 {
762 bool bYes = *o3tl::doAccess<bool>(rProp.maValue);
763 eScrollMode = bYes ? ScrollingMode::Yes : ScrollingMode::No;
764 }
765 break;
767 {
768 bHasBorder = *o3tl::doAccess<bool>(rProp.maValue);
769 bIsBorderSet = true;
770 }
771 break;
773 {
774 sal_Int32 nVal = SIZE_NOT_SET;
775 rProp.maValue >>= nVal;
776 aMargin.setWidth( nVal );
777 }
778 break;
780 {
781 sal_Int32 nVal = SIZE_NOT_SET;
782 rProp.maValue >>= nVal;
783 aMargin.setHeight( nVal );
784 }
785 break;
786 }
787 }
788 }
789 }
790 }
791
792 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
793 try
794 {
795 // create object with desired ClassId
796 uno::Sequence < sal_Int8 > aClass( SvGlobalName( SO3_IFRAME_CLASSID ).GetByteSequence() );
797 uno::Reference < embed::XEmbeddedObjectCreator > xFactory = embed::EmbeddedObjectCreator::create( ::comphelper::getProcessComponentContext() );
798 uno::Reference < embed::XEmbeddedObject > xObj( xFactory->createInstanceInitNew(
799 aClass, OUString(), xStorage, "DummyName",
800 uno::Sequence < beans::PropertyValue >() ), uno::UNO_QUERY );
801
802 // set size to the object
804 embed::Aspects::MSOLE_CONTENT,
805 Size( nWidth, nHeight ),
806 MapUnit::Map100thMM );
807
809 {
810 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
811 if ( xSet.is() )
812 {
813 OUString sHRef = URIHelper::SmartRel2Abs(
814 INetURLObject( GetXMLImport().GetBaseURL() ), rHRef );
815
816 if (INetURLObject(sHRef).GetProtocol() == INetProtocol::Macro)
817 GetXMLImport().NotifyMacroEventRead();
818
819 xSet->setPropertyValue("FrameURL",
820 Any( sHRef ) );
821
822 xSet->setPropertyValue("FrameName",
823 Any( rName ) );
824
825 if ( eScrollMode == ScrollingMode::Auto )
826 xSet->setPropertyValue("FrameIsAutoScroll",
827 Any( true ) );
828 else
829 xSet->setPropertyValue("FrameIsScrollingMode",
830 Any( eScrollMode == ScrollingMode::Yes ) );
831
832 if ( bIsBorderSet )
833 xSet->setPropertyValue("FrameIsBorder",
834 Any( bHasBorder ) );
835 else
836 xSet->setPropertyValue("FrameIsAutoBorder",
837 Any( true ) );
838
839 xSet->setPropertyValue("FrameMarginWidth",
840 Any( sal_Int32( aMargin.Width() ) ) );
841
842 xSet->setPropertyValue("FrameMarginHeight",
843 Any( sal_Int32( aMargin.Height() ) ) );
844 }
845
846 SwFrameFormat *const pFrameFormat =
848 *pTextCursor->GetPaM(),
849 ::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT),
850 &aItemSet);
852 *pDoc, pFrameFormat);
854 {
855 // req for z-order
856 SwXFrame::GetOrCreateSdrObject(*
857 static_cast<SwFlyFrameFormat*>(pFrameFormat));
858 }
859 }
860 }
861 catch ( uno::Exception& )
862 {
863 }
864
865 return xPropSet;
866}
867
869 const uno::Reference < XPropertySet > &rPropSet,
870 std::map < const OUString, OUString > &rParamMap)
871{
872 // this method will modify the document directly -> lock SolarMutex
873 SolarMutexGuard aGuard;
874
875 SwXFrame* pFrame = dynamic_cast<SwXFrame*>(rPropSet.get());
876 assert(pFrame && "SwXFrame missing");
877 SwFrameFormat *pFrameFormat = pFrame->GetFrameFormat();
878 const SwFormatContent& rContent = pFrameFormat->GetContent();
879 const SwNodeIndex *pNdIdx = rContent.GetContentIdx();
880 SwOLENode *pOLENd = pNdIdx->GetNodes()[pNdIdx->GetIndex() + 1]->GetNoTextNode()->GetOLENode();
881 SwOLEObj& rOLEObj = pOLENd->GetOLEObj();
882
883 uno::Reference < embed::XEmbeddedObject > xEmbObj( rOLEObj.GetOleRef() );
885 return;
886
887 uno::Reference < beans::XPropertySet > xSet( xEmbObj->getComponent(), uno::UNO_QUERY );
888 if ( !xSet.is() )
889 return;
890
891 const sal_Int32 nCount = rParamMap.size();
892 uno::Sequence< beans::PropertyValue > aCommandSequence( nCount );
893
894 std::transform(rParamMap.begin(), rParamMap.end(), aCommandSequence.getArray(),
895 [](const auto& rParam)
896 {
897 return beans::PropertyValue(/* Name */ rParam.first,
898 /* Handle */ -1,
899 /* Value */ uno::Any(rParam.second),
900 /* State */ beans::PropertyState_DIRECT_VALUE);
901 });
902
903 // unfortunately the names of the properties are depending on the object
904 OUString aParaName("AppletCommands");
905 try
906 {
907 xSet->setPropertyValue( aParaName, Any( aCommandSequence ) );
908 }
909 catch ( uno::Exception& )
910 {
911 aParaName = "PluginCommands";
912 try
913 {
914 xSet->setPropertyValue( aParaName, Any( aCommandSequence ) );
915 }
916 catch ( uno::Exception& )
917 {
918 }
919 }
920}
921
922// redlining helper methods
923// (override to provide the real implementation)
925 const OUString& rType,
926 const OUString& rId,
927 const OUString& rAuthor,
928 const OUString& rComment,
929 const util::DateTime& rDateTime,
930 bool bMergeLastPara)
931{
932 // create redline helper on demand
933 OSL_ENSURE(nullptr != m_pRedlineHelper, "helper should have been created in constructor");
934 if (nullptr != m_pRedlineHelper)
935 m_pRedlineHelper->Add(rType, rId, rAuthor, rComment, rDateTime,
936 bMergeLastPara);
937}
938
940 uno::Reference<XTextCursor> & rOldCursor,
941 const OUString& rId)
942{
943 uno::Reference<XTextCursor> xRet;
944
945 if (nullptr != m_pRedlineHelper)
946 {
947 xRet = m_pRedlineHelper->CreateRedlineTextSection(rOldCursor, rId);
948 }
949
950 return xRet;
951}
952
954 const OUString& rId,
955 bool bStart,
956 bool bIsOutsideOfParagraph)
957{
958 if (nullptr != m_pRedlineHelper) {
959 uno::Reference<XTextRange> xTextRange( GetCursor()->getStart() );
960 m_pRedlineHelper->SetCursor(rId, bStart, xTextRange,
961 bIsOutsideOfParagraph);
962 }
963 // else: ignore redline (wasn't added before, else we'd have a helper)
964}
965
967{
968 OUString rId = GetOpenRedlineId();
969 if ((nullptr != m_pRedlineHelper) && !rId.isEmpty())
970 {
973 }
974 // else: ignore redline (wasn't added before, or no open redline ID
975}
976
978{
979 if ( nullptr != m_pRedlineHelper )
980 m_pRedlineHelper->SetShowChanges( bShowChanges );
981}
982
984{
985 if ( nullptr != m_pRedlineHelper )
986 m_pRedlineHelper->SetRecordChanges( bRecordChanges );
987}
988
990 const Sequence<sal_Int8> & rKey )
991{
992 if ( nullptr != m_pRedlineHelper )
994}
995
996/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral XML_IMPORT_FILTER_CALC
constexpr OUStringLiteral XML_IMPORT_FILTER_DRAW
constexpr OUStringLiteral XML_IMPORT_FILTER_WRITER
constexpr OUStringLiteral XML_IMPORT_FILTER_CHART
constexpr OUStringLiteral XML_IMPORT_FILTER_IMPRESS
constexpr OUStringLiteral XML_IMPORT_FILTER_MATH
virtual SwFlyFrameFormat * InsertOLE(const SwPaM &rRg, const OUString &rObjName, sal_Int64 nAspect, const SfxItemSet *pFlyAttrSet, const SfxItemSet *pGrfAttrSet)=0
virtual SwFlyFrameFormat * InsertEmbObject(const SwPaM &rRg, const svt::EmbeddedObjectRef &xObj, SfxItemSet *pFlyAttrSet)=0
Insert OLE-objects.
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
SfxMedium * GetMedium() const
css::uno::Reference< css::embed::XStorage > const & GetStorage()
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
css::uno::Sequence< sal_Int8 > GetByteSequence() const
XmlStyleFamily GetFamily() const
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
void CreateApplet(const OUString &rCode, const OUString &rName, bool bMayScript, const OUString &rCodeBase, std::u16string_view rBaseURL)
SfxItemSet & GetItemSet()
const css::uno::Reference< css::embed::XEmbeddedObject > & GetApplet() const
Definition: doc.hxx:197
const SwGrfFormatColl * GetDfltGrfFormatColl() const
Definition: doc.hxx:819
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:329
SfxObjectShell * GetPersist() const
Definition: docnew.cxx:653
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1337
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:169
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
bool IsInHeaderFooter(const SwNode &) const
Definition: doclay.cxx:1582
FlyAnchors.
Definition: fmtanchr.hxx:37
Content, content of frame (header, footer, fly).
Definition: fmtcntnt.hxx:32
const SwNodeIndex * GetContentIdx() const
Definition: fmtcntnt.hxx:46
const SwFormatContent & GetContent(bool=true) const
Definition: fmtcntnt.hxx:55
Style of a layout element.
Definition: frmfmt.hxx:72
TElementType * Next()
Definition: calbck.hxx:380
TElementType * First()
Definition: calbck.hxx:372
Marks a node in the document model.
Definition: ndindex.hxx:31
const SwNodes & GetNodes() const
Definition: ndindex.hxx:119
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:111
SwOLENode * GetOLENode()
Inline methods from Node.hxx.
Definition: ndole.hxx:165
const SwOLEObj & GetOLEObj() const
Definition: ndole.hxx:116
void SetChartTableName(const OUString &rNm)
Definition: ndole.hxx:157
void SetOLESizeInvalid(bool b)
Definition: ndole.hxx:138
svt::EmbeddedObjectRef & GetObject()
Definition: ndole.cxx:1063
css::uno::Reference< css::embed::XEmbeddedObject > const & GetOleRef()
Definition: ndole.cxx:1012
const OUString & GetCurrentPersistName() const
Definition: ndole.hxx:72
virtual css::uno::Reference< css::beans::XPropertySet > createAndInsertFloatingFrame(const OUString &rName, const OUString &rHRef, const OUString &rStyleName, sal_Int32 nWidth, sal_Int32 nHeight) override
Definition: xmltexti.cxx:714
virtual void RedlineSetCursor(const OUString &rId, bool bStart, bool bIsOutsideOfParagraph) override
ID used to RedlineAdd() call.
Definition: xmltexti.cxx:953
virtual void endAppletOrPlugin(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, std::map< const OUString, OUString > &rParamMap) override
Definition: xmltexti.cxx:868
virtual void SetChangesProtectionKey(const css::uno::Sequence< sal_Int8 > &rKey) override
Definition: xmltexti.cxx:989
virtual void SetShowChanges(bool bShowChanges) override
Definition: xmltexti.cxx:977
XMLRedlineImportHelper * m_pRedlineHelper
Definition: xmltexti.hxx:29
virtual css::uno::Reference< css::beans::XPropertySet > createAndInsertOLEObject(SvXMLImport &rImport, const OUString &rHRef, const OUString &rStyleName, const OUString &rTableName, sal_Int32 nWidth, sal_Int32 nHeight) override
Definition: xmltexti.cxx:195
virtual bool IsInHeaderFooter() const override
Definition: xmltexti.cxx:173
virtual css::uno::Reference< css::beans::XPropertySet > createAndInsertApplet(const OUString &rName, const OUString &rCode, bool bMayScript, const OUString &rHRef, sal_Int32 nWidth, sal_Int32 nHeight) override
Definition: xmltexti.cxx:594
SwXMLTextImportHelper(const css::uno::Reference< css::frame::XModel > &rModel, SvXMLImport &rImport, const css::uno::Reference< css::beans::XPropertySet > &rInfoSet, bool bInsertM, bool bStylesOnlyM, bool bBlockM, bool bOrganizerM)
Definition: xmltexti.cxx:136
virtual SvXMLImportContext * CreateTableChildContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmltexti.cxx:165
virtual void RedlineAdd(const OUString &rType, const OUString &rId, const OUString &rAuthor, const OUString &rComment, const css::util::DateTime &rDateTime, bool bMergeLastPara) override
Definition: xmltexti.cxx:924
virtual css::uno::Reference< css::beans::XPropertySet > createAndInsertPlugin(const OUString &rMimeType, const OUString &rHRef, sal_Int32 nWidth, sal_Int32 nHeight) override
Definition: xmltexti.cxx:641
virtual void RedlineAdjustStartNodeCursor() override
Definition: xmltexti.cxx:966
virtual ~SwXMLTextImportHelper() override
Definition: xmltexti.cxx:151
virtual css::uno::Reference< css::beans::XPropertySet > createAndInsertOOoLink(SvXMLImport &rImport, const OUString &rHRef, const OUString &rStyleName, const OUString &rTableName, sal_Int32 nWidth, sal_Int32 nHeight) override
Definition: xmltexti.cxx:504
virtual void SetRecordChanges(bool bRecordChanges) override
Definition: xmltexti.cxx:983
virtual css::uno::Reference< css::text::XTextCursor > RedlineCreateText(css::uno::Reference< css::text::XTextCursor > &rOldCursor, const OUString &rId) override
merge last paragraph
Definition: xmltexti.cxx:939
static rtl::Reference< SwXTextEmbeddedObject > CreateXTextEmbeddedObject(SwDoc &rDoc, SwFrameFormat *pFrameFormat)
Definition: unoframe.cxx:3501
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
const SvXMLStylesContext * GetStyles() const
const ::std::vector< XMLPropertyState > & GetProperties() const
void SetProtectionKey(const css::uno::Sequence< sal_Int8 > &rKey)
css::uno::Reference< css::text::XTextCursor > CreateRedlineTextSection(css::uno::Reference< css::text::XTextCursor > const &xOldCursor, const OUString &rId)
void SetCursor(const OUString &rId, bool bStart, css::uno::Reference< css::text::XTextRange > const &rRange, bool bIsOutsideOfParagraph)
void Add(std::u16string_view rType, const OUString &rId, const OUString &rAuthor, const OUString &rComment, const css::util::DateTime &rDateTime, bool bMergeLastParagraph)
void AdjustStartNodeCursor(const OUString &rId)
Adjust the start (end) position for a redline that begins in a start node.
void SetShowChanges(bool bShowChanges)
void SetRecordChanges(bool bRecordChanges)
css::uno::Reference< css::text::XTextCursor > & GetCursor()
SvI18NMap & GetRenameMap()
XMLPropStyleContext * FindAutoFrameStyle(const OUString &rName) const
SvXMLImport & GetXMLImport()
bool IsInsertMode() const
OUString const & GetOpenRedlineId() const
css::uno::Reference< css::embed::XEmbeddedObject > GetEmbeddedObject(const OUString &, OUString const *pBaseURL=nullptr)
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
#define SO3_SDRAW_CLASSID
#define SO3_PLUGIN_CLASSID
#define SO3_SIMPRESS_CLASSID
#define SO3_SCH_CLASSID
#define SO3_IFRAME_CLASSID
#define SO3_SC_CLASSID
#define SO3_SW_CLASSID
#define SO3_SM_CLASSID
void SetViewAspect(sal_Int64 nAspect)
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
void SetPosY(tools::Long y)
void setWidth(tools::Long n)
constexpr Size GetSize() const
void setHeight(tools::Long n)
void SetPosX(tools::Long x)
int nCount
Reference< XSingleServiceFactory > xFactory
@ Fixed
Frame cannot be moved in Var-direction.
ScrollingMode
#define SIZE_NOT_SET
OUString aName
sal_uInt16 nPos
#define SAL_WARN_IF(condition, area, stream)
MapUnit
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i
constexpr auto toTwips(N number, Length from)
css::uno::Any maValue
sal_Int32 mnIndex
#define MINFLY
Definition: swtypes.hxx:61
#define XML_TEXT_RENAME_TYPE_TABLE
#define CTF_FRAME_MARGIN_VERT
#define CTF_OLE_VIS_AREA_TOP
#define CTF_FRAME_DISPLAY_BORDER
#define CTF_OLE_DRAW_ASPECT
#define CTF_OLE_VIS_AREA_HEIGHT
#define CTF_OLE_VIS_AREA_WIDTH
#define CTF_FRAME_MARGIN_HORI
#define CTF_OLE_VIS_AREA_LEFT
#define CTF_FRAME_DISPLAY_SCROLLBAR
sal_uInt16 sal_Unicode
std::unique_ptr< char[]> aBuffer
static SwOLENode * lcl_GetOLENode(const SwFrameFormat *pFrameFormat)
Definition: xmltexti.cxx:182
const std::pair< OUString, SvGUID > aServiceMap[]
Definition: xmltexti.cxx:78
static void lcl_setObjectVisualArea(const uno::Reference< embed::XEmbeddedObject > &xObj, sal_Int64 nAspect, const Size &aVisSize, const MapUnit &aUnit)
Definition: xmltexti.cxx:111
static void lcl_putHeightAndWidth(SfxItemSet &rItemSet, sal_Int32 nHeight, sal_Int32 nWidth, Size *pTwipSize=nullptr)
Definition: xmltexti.cxx:86