1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmltexti.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <comphelper/storagehelper.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <com/sun/star/embed/EmbedStates.hpp>
38 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
39 #include <com/sun/star/embed/XLinkCreator.hpp>
40 #include <com/sun/star/embed/XEmbeddedObject.hpp>
41 #include <com/sun/star/embed/XVisualObject.hpp>
42 #include <com/sun/star/embed/Aspects.hpp>
43 #include <com/sun/star/task/XInteractionHandler.hpp>
44 #include <rtl/ustrbuf.hxx>
45 #include <sot/clsids.hxx>
46 #include <com/sun/star/lang/XUnoTunnel.hpp>
47 #include <xmloff/prstylei.hxx>
48 #include <xmloff/maptype.hxx>
49 #include <xmloff/xmlprmap.hxx>
50 #ifndef _XMLOFF_TXTPRMAP_HXX
51 #include <xmloff/txtprmap.hxx>
53 #include <xmloff/i18nmap.hxx>
54 #include "unocrsr.hxx"
56 #include "unoframe.hxx"
58 #include "unocoll.hxx"
59 #include <fmtfsize.hxx>
60 #include <fmtanchr.hxx>
62 #include "xmltbli.hxx"
63 #include "xmltexti.hxx"
64 #include "XMLRedlineImportHelper.hxx"
65 #include <xmloff/XMLFilterServiceNames.h>
66 #include <SwAppletImpl.hxx>
69 #include <sfx2/docfile.hxx>
71 // for locking SolarMutex: svapp + mutex
72 #include <vcl/svapp.hxx>
73 #include <vos/mutex.hxx>
75 #include <toolkit/helper/vclunohelper.hxx>
76 #include <svtools/embedhlp.hxx>
77 #include <svtools/urihelper.hxx>
79 using ::rtl::OUString
;
80 using ::rtl::OUStringBuffer
;
81 using namespace ::com::sun::star
;
82 using namespace ::com::sun::star::uno
;
83 using namespace ::com::sun::star::lang
;
84 using namespace ::com::sun::star::text
;
85 using namespace ::com::sun::star::frame
;
86 using namespace ::com::sun::star::beans
;
87 using namespace xml::sax
;
90 struct XMLServiceMapEntry_Impl
92 const sal_Char
*sFilterService
;
93 sal_Int32 nFilterServiceLen
;
97 sal_uInt8 n4
, n5
, n6
, n7
, n8
, n9
, n10
, n11
;
100 #define SERVICE_MAP_ENTRY( app, s ) \
101 { XML_IMPORT_FILTER_##app, sizeof(XML_IMPORT_FILTER_##app)-1, \
104 const XMLServiceMapEntry_Impl aServiceMap
[] =
106 SERVICE_MAP_ENTRY( WRITER
, SW
),
107 SERVICE_MAP_ENTRY( CALC
, SC
),
108 SERVICE_MAP_ENTRY( DRAW
, SDRAW
),
109 SERVICE_MAP_ENTRY( IMPRESS
, SIMPRESS
),
110 SERVICE_MAP_ENTRY( CHART
, SCH
),
111 SERVICE_MAP_ENTRY( MATH
, SM
),
112 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
114 static void lcl_putHeightAndWidth ( SfxItemSet
&rItemSet
,
115 sal_Int32 nHeight
, sal_Int32 nWidth
,
116 long *pTwipHeight
=0, long *pTwipWidth
=0 )
118 if( nWidth
> 0 && nHeight
> 0 )
120 nWidth
= MM100_TO_TWIP( nWidth
);
121 if( nWidth
< MINFLY
)
123 nHeight
= MM100_TO_TWIP( nHeight
);
124 if( nHeight
< MINFLY
)
126 rItemSet
.Put( SwFmtFrmSize( ATT_FIX_SIZE
, nWidth
, nHeight
) );
129 SwFmtAnchor
aAnchor( FLY_AUTO_CNTNT
);
130 rItemSet
.Put( aAnchor
);
133 *pTwipWidth
= nWidth
;
135 *pTwipHeight
= nHeight
;
138 static void lcl_setObjectVisualArea( const uno::Reference
< embed::XEmbeddedObject
>& xObj
,
140 const Size
& aVisSize
,
141 const MapUnit
& aUnit
)
143 if( xObj
.is() && nAspect
!= embed::Aspects::MSOLE_ICON
)
145 // convert the visual area to the objects units
146 MapUnit aObjUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
147 Size aObjVisSize
= OutputDevice::LogicToLogic( aVisSize
, aUnit
, aObjUnit
);
149 aSz
.Width
= aObjVisSize
.Width();
150 aSz
.Height
= aObjVisSize
.Height();
154 xObj
->setVisualAreaSize( nAspect
, aSz
);
156 catch( uno::Exception
& )
158 OSL_ASSERT( "Couldn't set visual area of the object!\n" );
163 SwXMLTextImportHelper::SwXMLTextImportHelper(
164 const uno::Reference
< XModel
>& rModel
,
165 SvXMLImport
& rImport
,
166 const uno::Reference
<XPropertySet
> & rInfoSet
,
167 sal_Bool bInsertM
, sal_Bool bStylesOnlyM
, sal_Bool _bProgress
,
168 sal_Bool bBlockM
, sal_Bool bOrganizerM
,
169 sal_Bool
/*bPreserveRedlineMode*/ ) :
170 XMLTextImportHelper( rModel
, rImport
, bInsertM
, bStylesOnlyM
, _bProgress
,
171 bBlockM
, bOrganizerM
),
172 pRedlineHelper( NULL
)
174 uno::Reference
<XPropertySet
> xDocPropSet( rModel
, UNO_QUERY
);
175 pRedlineHelper
= new XMLRedlineImportHelper(
176 bInsertM
|| bBlockM
, xDocPropSet
, rInfoSet
);
179 SwXMLTextImportHelper::~SwXMLTextImportHelper()
181 // #90463# the redline helper destructor sets properties on the document
182 // and may through an exception while doing so... catch this
185 delete pRedlineHelper
;
187 catch ( const RuntimeException
& )
193 SvXMLImportContext
*SwXMLTextImportHelper::CreateTableChildContext(
194 SvXMLImport
& rImport
,
195 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
196 const uno::Reference
< XAttributeList
> & xAttrList
)
198 return new SwXMLTableContext(
199 (SwXMLImport
&)rImport
, nPrefix
, rLocalName
, xAttrList
);
202 sal_Bool
SwXMLTextImportHelper::IsInHeaderFooter() const
204 uno::Reference
<XUnoTunnel
> xCrsrTunnel(
205 ((SwXMLTextImportHelper
*)this)->GetCursor(), UNO_QUERY
);
206 ASSERT( xCrsrTunnel
.is(), "missing XUnoTunnel for Cursor" );
207 OTextCursorHelper
*pTxtCrsr
= reinterpret_cast< OTextCursorHelper
* >(
208 sal::static_int_cast
< sal_IntPtr
>( xCrsrTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId() )));
209 ASSERT( pTxtCrsr
, "SwXTextCursor missing" );
210 SwDoc
*pDoc
= pTxtCrsr
->GetDoc();
212 return pDoc
&& pDoc
->IsInHeaderFooter( pTxtCrsr
->GetPaM()->GetPoint()->nNode
);
215 SwOLENode
*lcl_GetOLENode( const SwFrmFmt
*pFrmFmt
)
217 SwOLENode
*pOLENd
= 0;
220 const SwFmtCntnt
& rCntnt
= pFrmFmt
->GetCntnt();
221 const SwNodeIndex
*pNdIdx
= rCntnt
.GetCntntIdx();
222 pOLENd
= pNdIdx
->GetNodes()[pNdIdx
->GetIndex() + 1]->GetOLENode();
224 ASSERT( pOLENd
, "Where is the OLE node" );
228 uno::Reference
< XPropertySet
> SwXMLTextImportHelper::createAndInsertOLEObject(
229 SvXMLImport
& rImport
,
230 const OUString
& rHRef
,
231 const OUString
& rStyleName
,
232 const OUString
& rTblName
,
233 sal_Int32 nWidth
, sal_Int32 nHeight
)
235 // this method will modify the document directly -> lock SolarMutex
236 vos::OGuard
aGuard(Application::GetSolarMutex());
238 uno::Reference
< XPropertySet
> xPropSet
;
240 sal_Int32 nPos
= rHRef
.indexOf( ':' );
244 OUString
aObjName( rHRef
.copy( nPos
+1) );
246 if( !aObjName
.getLength() )
249 uno::Reference
<XUnoTunnel
> xCrsrTunnel( GetCursor(), UNO_QUERY
);
250 ASSERT( xCrsrTunnel
.is(), "missing XUnoTunnel for Cursor" );
251 OTextCursorHelper
*pTxtCrsr
= reinterpret_cast< OTextCursorHelper
* >(
252 sal::static_int_cast
< sal_IntPtr
>( xCrsrTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId() )));
253 ASSERT( pTxtCrsr
, "SwXTextCursor missing" );
254 SwDoc
*pDoc
= SwImport::GetDocFromXMLImport( rImport
);
256 SfxItemSet
aItemSet( pDoc
->GetAttrPool(), RES_FRMATR_BEGIN
,
258 Size
aTwipSize( 0, 0 );
259 Rectangle
aVisArea( 0, 0, nWidth
, nHeight
);
260 lcl_putHeightAndWidth( aItemSet
, nHeight
, nWidth
,
261 &aTwipSize
.Height(), &aTwipSize
.Width() );
263 SwFrmFmt
*pFrmFmt
= 0;
264 SwOLENode
*pOLENd
= 0;
265 if( rHRef
.copy( 0, nPos
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.ServiceName") ) )
267 sal_Bool bInsert
= sal_False
;
268 SvGlobalName aClassName
;
269 const XMLServiceMapEntry_Impl
*pEntry
= aServiceMap
;
270 while( pEntry
->sFilterService
)
272 if( aObjName
.equalsAsciiL( pEntry
->sFilterService
,
273 pEntry
->nFilterServiceLen
) )
275 aClassName
= SvGlobalName( pEntry
->n1
, pEntry
->n2
,
276 pEntry
->n3
, pEntry
->n4
,
277 pEntry
->n5
, pEntry
->n6
,
278 pEntry
->n7
, pEntry
->n8
,
279 pEntry
->n9
, pEntry
->n10
,
289 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
292 // create object with desired ClassId
293 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
294 ::rtl::OUString aName
= ::rtl::OUString::createFromAscii( "DummyName" );
295 uno::Sequence
< sal_Int8
> aClass( aClassName
.GetByteSequence() );
296 uno::Reference
< embed::XEmbedObjectCreator
> xFactory( ::comphelper::getProcessServiceFactory()->createInstance(
297 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.EmbeddedObjectCreator")) ), uno::UNO_QUERY
);
298 uno::Reference
< embed::XEmbeddedObject
> xObj
=
299 uno::Reference
< embed::XEmbeddedObject
>( xFactory
->createInstanceInitNew(
300 aClass
, ::rtl::OUString(), xStorage
, aName
,
301 uno::Sequence
< beans::PropertyValue
>() ), uno::UNO_QUERY
);
304 //TODO/LATER: is it enough to only set the VisAreaSize?
305 lcl_setObjectVisualArea( xObj
, nAspect
, aTwipSize
, MAP_TWIP
);
308 pFrmFmt
= pDoc
->Insert( *pTxtCrsr
->GetPaM(),
309 ::svt::EmbeddedObjectRef( xObj
, embed::Aspects::MSOLE_CONTENT
),
313 pOLENd
= lcl_GetOLENode( pFrmFmt
);
315 aObjName
= pOLENd
->GetOLEObj().GetCurrentPersistName();
317 catch ( uno::Exception
& )
324 // check whether an object with this name already exists in the document
326 SwClientIter
aIter( *(SwModify
*)pDoc
->GetDfltGrfFmtColl() );
327 for( SwCntntNode
* pNd
= (SwCntntNode
*)aIter
.First( TYPE( SwCntntNode
) );
328 pNd
; pNd
= (SwCntntNode
*)aIter
.Next() )
330 SwOLENode
* pExistingOLENd
= pNd
->GetOLENode();
333 ::rtl::OUString aExistingName
= pExistingOLENd
->GetOLEObj().GetCurrentPersistName();
334 if ( aExistingName
.equals( aObjName
) )
336 OSL_ENSURE( sal_False
, "The document contains duplicate object references, means it is partially broken, please let developers know how this document was generated!\n" );
338 ::rtl::OUString aTmpName
= pDoc
->GetPersist()->GetEmbeddedObjectContainer().CreateUniqueObjectName();
341 pDoc
->GetPersist()->GetStorage()->copyElementTo( aObjName
,
342 pDoc
->GetPersist()->GetStorage(),
346 catch ( uno::Exception
& )
348 OSL_ENSURE( sal_False
, "Couldn't create a copy of the object!\n" );
359 // the correct aspect will be set later
360 // TODO/LATER: Actually it should be set here
363 pFrmFmt
= pDoc
->InsertOLE( *pTxtCrsr
->GetPaM(), aName
, embed::Aspects::MSOLE_CONTENT
, &aItemSet
, NULL
, NULL
);
364 pOLENd
= lcl_GetOLENode( pFrmFmt
);
375 pOLENd
= lcl_GetOLENode( pFrmFmt
);
377 pOLENd
->SetOLESizeInvalid( sal_True
);
380 SwXFrame
*pXFrame
= SwXFrames::GetObject( *pFrmFmt
, FLYCNTTYPE_OLE
);
382 if( pDoc
->GetDrawModel() )
383 SwXFrame::GetOrCreateSdrObject(
384 static_cast<SwFlyFrmFmt
*>( pXFrame
->GetFrmFmt() ) ); // req for z-order
385 if( rTblName
.getLength() )
387 const SwFmtCntnt
& rCntnt
= pFrmFmt
->GetCntnt();
388 const SwNodeIndex
*pNdIdx
= rCntnt
.GetCntntIdx();
389 SwOLENode
*pOLENode
= pNdIdx
->GetNodes()[pNdIdx
->GetIndex() + 1]->GetOLENode();
390 ASSERT( pOLENode
, "Where is the OLE node" );
392 OUStringBuffer
aBuffer( rTblName
.getLength() );
393 sal_Bool bQuoted
= sal_False
;
394 sal_Bool bEscape
= sal_False
;
395 sal_Bool bError
= sal_False
;
396 for( sal_Int32 i
=0; i
< rTblName
.getLength(); i
++ )
398 sal_Bool bEndOfNameFound
= sal_False
;
399 sal_Unicode c
= rTblName
[i
];
410 bEndOfNameFound
= sal_True
;
436 bEndOfNameFound
= sal_True
;
451 if( bError
|| bEndOfNameFound
)
456 OUString
sTblName( aBuffer
.makeStringAndClear() );
457 pOLENode
->SetChartTblName( GetRenameMap().Get( XML_TEXT_RENAME_TYPE_TABLE
, sTblName
) );
461 sal_Int64 nDrawAspect
= 0;
462 const XMLPropStyleContext
*pStyle
= 0;
463 sal_Bool bHasSizeProps
= sal_False
;
464 if( rStyleName
.getLength() )
466 pStyle
= FindAutoFrameStyle( rStyleName
);
469 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
471 ->GetImportPropertyMapper(pStyle
->GetFamily());
472 ASSERT( xImpPrMap
.is(), "Where is the import prop mapper?" );
475 UniReference
<XMLPropertySetMapper
> rPropMapper
=
476 xImpPrMap
->getPropertySetMapper();
478 sal_Int32 nCount
= pStyle
->GetProperties().size();
479 for( sal_Int32 i
=0; i
< nCount
; i
++ )
481 const XMLPropertyState
& rProp
= pStyle
->GetProperties()[i
];
482 sal_Int32 nIdx
= rProp
.mnIndex
;
486 switch( rPropMapper
->GetEntryContextId(nIdx
) )
488 case CTF_OLE_VIS_AREA_LEFT
:
491 rProp
.maValue
>>= nVal
;
492 aVisArea
.setX( nVal
);
495 case CTF_OLE_VIS_AREA_TOP
:
498 rProp
.maValue
>>= nVal
;
499 aVisArea
.setY( nVal
);
502 case CTF_OLE_VIS_AREA_WIDTH
:
505 rProp
.maValue
>>= nVal
;
506 aVisArea
.setWidth( nVal
);
507 bHasSizeProps
= sal_True
;
510 case CTF_OLE_VIS_AREA_HEIGHT
:
513 rProp
.maValue
>>= nVal
;
514 aVisArea
.setHeight( nVal
);
515 bHasSizeProps
= sal_True
;
518 case CTF_OLE_DRAW_ASPECT
:
520 rProp
.maValue
>>= nDrawAspect
;
523 nDrawAspect
= embed::Aspects::MSOLE_CONTENT
;
526 pOLENd
->GetOLEObj().GetObject().SetViewAspect( nDrawAspect
);
537 uno::Reference
< embed::XEmbeddedObject
> xObj
=
538 pDoc
->GetPersist()->GetEmbeddedObjectContainer().GetEmbeddedObject( aObjName
);
540 lcl_setObjectVisualArea( xObj
, ( nDrawAspect
? nDrawAspect
: embed::Aspects::MSOLE_CONTENT
),
541 aVisArea
.GetSize(), MAP_100TH_MM
);
547 uno::Reference
< XPropertySet
> SwXMLTextImportHelper::createAndInsertOOoLink(
548 SvXMLImport
& rImport
,
549 const OUString
& rHRef
,
550 const OUString
& /*rStyleName*/,
551 const OUString
& /*rTblName*/,
552 sal_Int32 nWidth
, sal_Int32 nHeight
)
554 // this method will modify the document directly -> lock SolarMutex
555 vos::OGuard
aGuard(Application::GetSolarMutex());
557 uno::Reference
< XPropertySet
> xPropSet
;
559 uno::Reference
<XUnoTunnel
> xCrsrTunnel( GetCursor(), UNO_QUERY
);
560 ASSERT( xCrsrTunnel
.is(), "missing XUnoTunnel for Cursor" );
561 OTextCursorHelper
*pTxtCrsr
= reinterpret_cast< OTextCursorHelper
* >(
562 sal::static_int_cast
< sal_IntPtr
>( xCrsrTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId() )));
563 ASSERT( pTxtCrsr
, "SwXTextCursor missing" );
564 SwDoc
*pDoc
= SwImport::GetDocFromXMLImport( rImport
);
566 SfxItemSet
aItemSet( pDoc
->GetAttrPool(), RES_FRMATR_BEGIN
,
568 Size
aTwipSize( 0, 0 );
569 Rectangle
aVisArea( 0, 0, nWidth
, nHeight
);
570 lcl_putHeightAndWidth( aItemSet
, nHeight
, nWidth
,
571 &aTwipSize
.Height(), &aTwipSize
.Width() );
573 // We'll need a (valid) URL. If we don't have do not insert the link and return early.
574 // Copy URL into URL oject on the way.
575 INetURLObject aURLObj
;
576 bool bValidURL
= rHRef
.getLength() != 0 &&
577 aURLObj
.SetURL( URIHelper::SmartRel2Abs(
578 INetURLObject( GetXMLImport().GetBaseURL() ), rHRef
) );
582 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
585 // create object with desired ClassId
586 ::rtl::OUString aName
= ::rtl::OUString::createFromAscii( "DummyName" );
587 uno::Reference
< embed::XLinkCreator
> xFactory( ::comphelper::getProcessServiceFactory()->createInstance(
588 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.OOoEmbeddedObjectFactory")) ),
589 uno::UNO_QUERY_THROW
);
591 uno::Sequence
< beans::PropertyValue
> aMediaDescriptor( 1 );
592 aMediaDescriptor
[0].Name
= ::rtl::OUString::createFromAscii( "URL" );
593 aMediaDescriptor
[0].Value
<<= ::rtl::OUString( aURLObj
.GetMainURL( INetURLObject::NO_DECODE
) );
594 if ( pDoc
&& pDoc
->GetDocShell() && pDoc
->GetDocShell()->GetMedium() )
596 uno::Reference
< task::XInteractionHandler
> xInteraction
=
597 pDoc
->GetDocShell()->GetMedium()->GetInteractionHandler();
598 if ( xInteraction
.is() )
600 aMediaDescriptor
.realloc( 2 );
601 aMediaDescriptor
[1].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) );
602 aMediaDescriptor
[1].Value
<<= xInteraction
;
606 uno::Reference
< embed::XEmbeddedObject
> xObj(
607 xFactory
->createInstanceLink(
608 xStorage
, aName
, aMediaDescriptor
, uno::Sequence
< beans::PropertyValue
>() ),
609 uno::UNO_QUERY_THROW
);
612 SwFrmFmt
*pFrmFmt
= pDoc
->Insert( *pTxtCrsr
->GetPaM(),
613 ::svt::EmbeddedObjectRef( xObj
, embed::Aspects::MSOLE_CONTENT
),
618 // 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???
620 SwXFrame
*pXFrame
= SwXFrames::GetObject( *pFrmFmt
, FLYCNTTYPE_OLE
);
622 if( pDoc
->GetDrawModel() )
623 SwXFrame::GetOrCreateSdrObject(
624 static_cast<SwFlyFrmFmt
*>( pXFrame
->GetFrmFmt() ) ); // req for z-order
627 catch ( uno::Exception
& )
631 // TODO/LATER: should the rStyleName and rTblName be handled as for usual embedded object?
636 uno::Reference
< XPropertySet
> SwXMLTextImportHelper::createAndInsertApplet(
637 const OUString
&rName
,
638 const OUString
&rCode
,
640 const OUString
& rHRef
,
641 sal_Int32 nWidth
, sal_Int32 nHeight
)
643 // this method will modify the document directly -> lock SolarMutex
644 vos::OGuard
aGuard(Application::GetSolarMutex());
646 uno::Reference
< XPropertySet
> xPropSet
;
647 uno::Reference
<XUnoTunnel
> xCrsrTunnel( GetCursor(), UNO_QUERY
);
648 ASSERT( xCrsrTunnel
.is(), "missing XUnoTunnel for Cursor" );
649 OTextCursorHelper
*pTxtCrsr
= reinterpret_cast< OTextCursorHelper
* >(
650 sal::static_int_cast
< sal_IntPtr
>( xCrsrTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId() )));
651 ASSERT( pTxtCrsr
, "SwXTextCursor missing" );
652 SwDoc
*pDoc
= pTxtCrsr
->GetDoc();
654 SfxItemSet
aItemSet( pDoc
->GetAttrPool(), RES_FRMATR_BEGIN
,
656 lcl_putHeightAndWidth( aItemSet
, nHeight
, nWidth
);
658 SwApplet_Impl
aAppletImpl ( aItemSet
);
661 if( rHRef
.getLength() )
662 sCodeBase
= GetXMLImport().GetAbsoluteReference( rHRef
);
664 aAppletImpl
.CreateApplet ( rCode
, rName
, bMayScript
, sCodeBase
, GetXMLImport().GetDocumentBase() );
666 // set the size of the applet
667 lcl_setObjectVisualArea( aAppletImpl
.GetApplet(),
668 embed::Aspects::MSOLE_CONTENT
,
669 Size( nWidth
, nHeight
),
672 SwFrmFmt
*pFrmFmt
= pDoc
->Insert( *pTxtCrsr
->GetPaM(),
673 ::svt::EmbeddedObjectRef( aAppletImpl
.GetApplet(), embed::Aspects::MSOLE_CONTENT
),
674 &aAppletImpl
.GetItemSet(),
677 SwXFrame
*pXFrame
= SwXFrames::GetObject( *pFrmFmt
, FLYCNTTYPE_OLE
);
679 if( pDoc
->GetDrawModel() )
680 SwXFrame::GetOrCreateSdrObject(
681 static_cast<SwFlyFrmFmt
*>( pXFrame
->GetFrmFmt() ) ); // req for z-order
686 uno::Reference
< XPropertySet
> SwXMLTextImportHelper::createAndInsertPlugin(
687 const OUString
&rMimeType
,
688 const OUString
& rHRef
,
689 sal_Int32 nWidth
, sal_Int32 nHeight
)
691 uno::Reference
< XPropertySet
> xPropSet
;
692 uno::Reference
<XUnoTunnel
> xCrsrTunnel( GetCursor(), UNO_QUERY
);
693 ASSERT( xCrsrTunnel
.is(), "missing XUnoTunnel for Cursor" );
694 OTextCursorHelper
*pTxtCrsr
= reinterpret_cast< OTextCursorHelper
* >(
695 sal::static_int_cast
< sal_IntPtr
>( xCrsrTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId() )));
696 ASSERT( pTxtCrsr
, "SwXTextCursor missing" );
697 SwDoc
*pDoc
= pTxtCrsr
->GetDoc();
699 SfxItemSet
aItemSet( pDoc
->GetAttrPool(), RES_FRMATR_BEGIN
,
701 lcl_putHeightAndWidth( aItemSet
, nHeight
, nWidth
);
703 // We'll need a (valid) URL, or we need a MIME type. If we don't have
704 // either, do not insert plugin and return early. Copy URL into URL oject
706 INetURLObject aURLObj
;
708 bool bValidURL
= rHRef
.getLength() != 0 &&
709 aURLObj
.SetURL( URIHelper::SmartRel2Abs( INetURLObject( GetXMLImport().GetBaseURL() ), rHRef
) );
710 bool bValidMimeType
= rMimeType
.getLength() != 0;
711 if( !bValidURL
&& !bValidMimeType
)
714 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
717 // create object with desired ClassId
718 ::rtl::OUString aName
= ::rtl::OUString::createFromAscii( "DummyName" );
719 uno::Sequence
< sal_Int8
> aClass( SvGlobalName( SO3_PLUGIN_CLASSID
).GetByteSequence() );
720 uno::Reference
< embed::XEmbedObjectCreator
> xFactory( ::comphelper::getProcessServiceFactory()->createInstance(
721 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.EmbeddedObjectCreator")) ), uno::UNO_QUERY
);
722 uno::Reference
< embed::XEmbeddedObject
> xObj
=
723 uno::Reference
< embed::XEmbeddedObject
>( xFactory
->createInstanceInitNew(
724 aClass
, ::rtl::OUString(), xStorage
, aName
,
725 uno::Sequence
< beans::PropertyValue
>() ), uno::UNO_QUERY
);
727 // set size to the object
728 lcl_setObjectVisualArea( xObj
,
729 embed::Aspects::MSOLE_CONTENT
,
730 Size( nWidth
, nHeight
),
733 if ( svt::EmbeddedObjectRef::TryRunningState( xObj
) )
735 uno::Reference
< beans::XPropertySet
> xSet( xObj
->getComponent(), uno::UNO_QUERY
);
739 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
740 makeAny( ::rtl::OUString( aURLObj
.GetMainURL( INetURLObject::NO_DECODE
) ) ) );
742 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("PluginMimeType"),
743 makeAny( ::rtl::OUString( rMimeType
) ) );
746 SwFrmFmt
*pFrmFmt
= pDoc
->Insert( *pTxtCrsr
->GetPaM(),
747 ::svt::EmbeddedObjectRef( xObj
, embed::Aspects::MSOLE_CONTENT
),
751 SwXFrame
*pXFrame
= SwXFrames::GetObject( *pFrmFmt
, FLYCNTTYPE_OLE
);
753 if( pDoc
->GetDrawModel() )
754 SwXFrame::GetOrCreateSdrObject(
755 static_cast<SwFlyFrmFmt
*>( pXFrame
->GetFrmFmt() ) ); // req for z-order
758 catch ( uno::Exception
& )
764 uno::Reference
< XPropertySet
> SwXMLTextImportHelper::createAndInsertFloatingFrame(
765 const OUString
& rName
,
766 const OUString
& rHRef
,
767 const OUString
& rStyleName
,
768 sal_Int32 nWidth
, sal_Int32 nHeight
)
770 // this method will modify the document directly -> lock SolarMutex
771 vos::OGuard
aGuard(Application::GetSolarMutex());
773 uno::Reference
< XPropertySet
> xPropSet
;
774 uno::Reference
<XUnoTunnel
> xCrsrTunnel( GetCursor(), UNO_QUERY
);
775 ASSERT( xCrsrTunnel
.is(), "missing XUnoTunnel for Cursor" );
776 OTextCursorHelper
*pTxtCrsr
= reinterpret_cast< OTextCursorHelper
* >(
777 sal::static_int_cast
< sal_IntPtr
>( xCrsrTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId() )));
778 ASSERT( pTxtCrsr
, "SwXTextCursor missing" );
779 SwDoc
*pDoc
= pTxtCrsr
->GetDoc();
781 SfxItemSet
aItemSet( pDoc
->GetAttrPool(), RES_FRMATR_BEGIN
,
783 lcl_putHeightAndWidth( aItemSet
, nHeight
, nWidth
);
785 ScrollingMode eScrollMode
= ScrollingAuto
;
786 sal_Bool bHasBorder
= sal_False
;
787 sal_Bool bIsBorderSet
= sal_False
;
788 Size
aMargin( SIZE_NOT_SET
, SIZE_NOT_SET
);
789 const XMLPropStyleContext
*pStyle
= 0;
790 if( rStyleName
.getLength() )
792 pStyle
= FindAutoFrameStyle( rStyleName
);
795 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
797 ->GetImportPropertyMapper(pStyle
->GetFamily());
798 ASSERT( xImpPrMap
.is(), "Where is the import prop mapper?" );
801 UniReference
<XMLPropertySetMapper
> rPropMapper
=
802 xImpPrMap
->getPropertySetMapper();
804 sal_Int32 nCount
= pStyle
->GetProperties().size();
805 for( sal_Int32 i
=0; i
< nCount
; i
++ )
807 const XMLPropertyState
& rProp
= pStyle
->GetProperties()[i
];
808 sal_Int32 nIdx
= rProp
.mnIndex
;
812 switch( rPropMapper
->GetEntryContextId(nIdx
) )
814 case CTF_FRAME_DISPLAY_SCROLLBAR
:
816 sal_Bool bYes
= *(sal_Bool
*)rProp
.maValue
.getValue();
817 eScrollMode
= bYes
? ScrollingYes
: ScrollingNo
;
820 case CTF_FRAME_DISPLAY_BORDER
:
822 bHasBorder
= *(sal_Bool
*)rProp
.maValue
.getValue();
823 bIsBorderSet
= sal_True
;
826 case CTF_FRAME_MARGIN_HORI
:
828 sal_Int32 nVal
= SIZE_NOT_SET
;
829 rProp
.maValue
>>= nVal
;
830 aMargin
.Width() = nVal
;
833 case CTF_FRAME_MARGIN_VERT
:
835 sal_Int32 nVal
= SIZE_NOT_SET
;
836 rProp
.maValue
>>= nVal
;
837 aMargin
.Height() = nVal
;
846 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
849 // create object with desired ClassId
850 ::rtl::OUString aName
= ::rtl::OUString::createFromAscii( "DummyName" );
851 uno::Sequence
< sal_Int8
> aClass( SvGlobalName( SO3_IFRAME_CLASSID
).GetByteSequence() );
852 uno::Reference
< embed::XEmbedObjectCreator
> xFactory( ::comphelper::getProcessServiceFactory()->createInstance(
853 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.EmbeddedObjectCreator")) ), uno::UNO_QUERY
);
854 uno::Reference
< embed::XEmbeddedObject
> xObj
=
855 uno::Reference
< embed::XEmbeddedObject
>( xFactory
->createInstanceInitNew(
856 aClass
, ::rtl::OUString(), xStorage
, aName
,
857 uno::Sequence
< beans::PropertyValue
>() ), uno::UNO_QUERY
);
859 // set size to the object
860 lcl_setObjectVisualArea( xObj
,
861 embed::Aspects::MSOLE_CONTENT
,
862 Size( nWidth
, nHeight
),
865 if ( svt::EmbeddedObjectRef::TryRunningState( xObj
) )
867 uno::Reference
< beans::XPropertySet
> xSet( xObj
->getComponent(), uno::UNO_QUERY
);
870 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameURL"),
871 makeAny( ::rtl::OUString( URIHelper::SmartRel2Abs(
872 INetURLObject( GetXMLImport().GetBaseURL() ), rHRef
) ) ) );
874 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameName"),
875 makeAny( ::rtl::OUString( rName
) ) );
877 if ( eScrollMode
== ScrollingAuto
)
878 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll"),
879 makeAny( sal_True
) );
881 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode"),
882 makeAny( (sal_Bool
) (eScrollMode
== ScrollingYes
) ) );
885 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder"),
886 makeAny( bHasBorder
) );
888 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder"),
889 makeAny( sal_True
) );
891 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth"),
892 makeAny( sal_Int32( aMargin
.Width() ) ) );
894 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight"),
895 makeAny( sal_Int32( aMargin
.Height() ) ) );
898 SwFrmFmt
*pFrmFmt
= pDoc
->Insert( *pTxtCrsr
->GetPaM(),
899 ::svt::EmbeddedObjectRef( xObj
, embed::Aspects::MSOLE_CONTENT
),
903 SwXFrame
*pXFrame
= SwXFrames::GetObject( *pFrmFmt
, FLYCNTTYPE_OLE
);
905 if( pDoc
->GetDrawModel() )
906 SwXFrame::GetOrCreateSdrObject(
907 static_cast<SwFlyFrmFmt
*>( pXFrame
->GetFrmFmt() ) ); // req for z-order
910 catch ( uno::Exception
& )
917 void SwXMLTextImportHelper::endAppletOrPlugin(
918 const uno::Reference
< XPropertySet
> &rPropSet
,
919 ::std::map
< const ::rtl::OUString
, ::rtl::OUString
, ::comphelper::UStringLess
> &rParamMap
)
921 // this method will modify the document directly -> lock SolarMutex
922 vos::OGuard
aGuard(Application::GetSolarMutex());
924 uno::Reference
<XUnoTunnel
> xCrsrTunnel( rPropSet
, UNO_QUERY
);
925 ASSERT( xCrsrTunnel
.is(), "missing XUnoTunnel for embedded" );
926 SwXFrame
*pFrame
= reinterpret_cast< SwXFrame
* >(
927 sal::static_int_cast
< sal_IntPtr
>( xCrsrTunnel
->getSomething( SwXFrame::getUnoTunnelId() )));
928 ASSERT( pFrame
, "SwXFrame missing" );
929 SwFrmFmt
*pFrmFmt
= pFrame
->GetFrmFmt();
930 const SwFmtCntnt
& rCntnt
= pFrmFmt
->GetCntnt();
931 const SwNodeIndex
*pNdIdx
= rCntnt
.GetCntntIdx();
932 SwOLENode
*pOLENd
= pNdIdx
->GetNodes()[pNdIdx
->GetIndex() + 1]->GetNoTxtNode()->GetOLENode();
933 SwOLEObj
& rOLEObj
= pOLENd
->GetOLEObj();
935 uno::Reference
< embed::XEmbeddedObject
> xEmbObj( rOLEObj
.GetOleRef() );
936 if ( svt::EmbeddedObjectRef::TryRunningState( xEmbObj
) )
938 uno::Reference
< beans::XPropertySet
> xSet( xEmbObj
->getComponent(), uno::UNO_QUERY
);
941 const sal_Int32 nCount
= rParamMap
.size();
942 uno::Sequence
< beans::PropertyValue
> aCommandSequence( nCount
);
944 ::std::map
< const ::rtl::OUString
, ::rtl::OUString
, ::comphelper::UStringLess
> ::iterator aIter
= rParamMap
.begin();
945 ::std::map
< const ::rtl::OUString
, ::rtl::OUString
, ::comphelper::UStringLess
> ::iterator aEnd
= rParamMap
.end();
947 while (aIter
!= aEnd
)
949 aCommandSequence
[nIndex
].Name
= (*aIter
).first
;
950 aCommandSequence
[nIndex
].Handle
= -1;
951 aCommandSequence
[nIndex
].Value
= makeAny( OUString((*aIter
).second
) );
952 aCommandSequence
[nIndex
].State
= beans::PropertyState_DIRECT_VALUE
;
956 // unfortunately the names of the properties are depending on the object
957 ::rtl::OUString aParaName
= ::rtl::OUString::createFromAscii("AppletCommands");
960 xSet
->setPropertyValue( aParaName
, makeAny( aCommandSequence
) );
962 catch ( uno::Exception
& )
964 aParaName
= ::rtl::OUString::createFromAscii("PluginCommands");
967 xSet
->setPropertyValue( aParaName
, makeAny( aCommandSequence
) );
969 catch ( uno::Exception
& )
977 XMLTextImportHelper
* SwXMLImport::CreateTextImport()
979 return new SwXMLTextImportHelper( GetModel(), *this, getImportInfo(),
981 IsStylesOnlyMode(), bShowProgress
,
982 IsBlockMode(), IsOrganizerMode(),
983 bPreserveRedlineMode
);
987 // redlining helper methods
988 // (override to provide the real implementation)
990 void SwXMLTextImportHelper::RedlineAdd(
991 const OUString
& rType
,
993 const OUString
& rAuthor
,
994 const OUString
& rComment
,
995 const util::DateTime
& rDateTime
,
996 sal_Bool bMergeLastPara
)
998 // create redline helper on demand
999 DBG_ASSERT(NULL
!= pRedlineHelper
, "helper should have been created in constructor");
1000 if (NULL
!= pRedlineHelper
)
1001 pRedlineHelper
->Add(rType
, rId
, rAuthor
, rComment
, rDateTime
,
1005 uno::Reference
<XTextCursor
> SwXMLTextImportHelper::RedlineCreateText(
1006 uno::Reference
<XTextCursor
> & rOldCursor
,
1007 const OUString
& rId
)
1009 uno::Reference
<XTextCursor
> xRet
;
1011 if (NULL
!= pRedlineHelper
)
1013 xRet
= pRedlineHelper
->CreateRedlineTextSection(rOldCursor
, rId
);
1019 void SwXMLTextImportHelper::RedlineSetCursor(
1020 const OUString
& rId
,
1022 sal_Bool bIsOutsideOfParagraph
)
1024 if (NULL
!= pRedlineHelper
) {
1025 uno::Reference
<XTextRange
> xTextRange( GetCursor()->getStart() );
1026 pRedlineHelper
->SetCursor(rId
, bStart
, xTextRange
,
1027 bIsOutsideOfParagraph
);
1029 // else: ignore redline (wasn't added before, else we'd have a helper)
1032 void SwXMLTextImportHelper::RedlineAdjustStartNodeCursor(
1035 OUString rId
= GetOpenRedlineId();
1036 if ((NULL
!= pRedlineHelper
) && (rId
.getLength() > 0))
1038 uno::Reference
<XTextRange
> xTextRange( GetCursor()->getStart() );
1039 pRedlineHelper
->AdjustStartNodeCursor(rId
, bStart
, xTextRange
);
1040 ResetOpenRedlineId();
1042 // else: ignore redline (wasn't added before, or no open redline ID
1045 void SwXMLTextImportHelper::SetShowChanges( sal_Bool bShowChanges
)
1047 if ( NULL
!= pRedlineHelper
)
1048 pRedlineHelper
->SetShowChanges( bShowChanges
);
1051 void SwXMLTextImportHelper::SetRecordChanges( sal_Bool bRecordChanges
)
1053 if ( NULL
!= pRedlineHelper
)
1054 pRedlineHelper
->SetRecordChanges( bRecordChanges
);
1057 void SwXMLTextImportHelper::SetChangesProtectionKey(
1058 const Sequence
<sal_Int8
> & rKey
)
1060 if ( NULL
!= pRedlineHelper
)
1061 pRedlineHelper
->SetProtectionKey( rKey
);