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