Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <com/sun/star/container/XIndexAccess.hpp>
22 : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
23 : #include <com/sun/star/drawing/XDrawPage.hpp>
24 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
25 : #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
26 : #include <com/sun/star/text/XTextDocument.hpp>
27 : #include <com/sun/star/text/XTextRange.hpp>
28 :
29 : #include <xmloff/xmlnmspe.hxx>
30 : #include <xmloff/xmltkmap.hxx>
31 : #include <xmloff/xmlictxt.hxx>
32 : #include <xmloff/txtimp.hxx>
33 : #include <xmloff/nmspmap.hxx>
34 : #include <xmloff/XMLTextShapeImportHelper.hxx>
35 : #include <xmloff/XMLFontStylesContext.hxx>
36 : #include <xmloff/ProgressBarHelper.hxx>
37 : #include <doc.hxx>
38 : #include <TextCursorHelper.hxx>
39 : #include <unotext.hxx>
40 : #include <unotextrange.hxx>
41 : #include "unocrsr.hxx"
42 : #include <poolfmt.hxx>
43 : #include <ndtxt.hxx>
44 : #include <editsh.hxx>
45 : #include "xmlimp.hxx"
46 : #include "xmltexti.hxx"
47 : #include <xmloff/DocumentSettingsContext.hxx>
48 : #include <docsh.hxx>
49 : #include <editeng/unolingu.hxx>
50 : #include <svx/svdmodel.hxx>
51 : #include <svx/xmlgrhlp.hxx>
52 : #include <svx/xmleohlp.hxx>
53 : #include <sfx2/printer.hxx>
54 : #include <xmloff/xmluconv.hxx>
55 : #include <unotools/saveopt.hxx>
56 : #include <tools/diagnose_ex.h>
57 : #include <boost/unordered_set.hpp>
58 : #include <stringhash.hxx>
59 :
60 : // for locking SolarMutex: svapp + mutex
61 : #include <vcl/svapp.hxx>
62 : #include <osl/mutex.hxx>
63 : #include <unotxdoc.hxx> // for initXForms()
64 :
65 : #include <xmloff/xmlmetai.hxx>
66 : #include <xmloff/xformsimport.hxx>
67 : #include <comphelper/servicehelper.hxx>
68 :
69 : using ::rtl::OUString;
70 :
71 : using namespace ::com::sun::star;
72 : using namespace ::com::sun::star::uno;
73 : using namespace ::com::sun::star::text;
74 : using namespace ::com::sun::star::lang;
75 : using namespace ::com::sun::star::beans;
76 : using namespace ::com::sun::star::container;
77 : using namespace ::com::sun::star::i18n;
78 : using namespace ::com::sun::star::drawing;
79 : using namespace ::com::sun::star::xforms;
80 : using namespace ::xmloff::token;
81 : using namespace ::std;
82 :
83 : struct OUStringEquals
84 : {
85 : sal_Bool operator()( const rtl::OUString &r1,
86 : const rtl::OUString &r2) const
87 : {
88 : return r1 == r2;
89 : }
90 : };
91 :
92 : //----------------------------------------------------------------------------
93 :
94 : enum SwXMLDocTokens
95 : {
96 : XML_TOK_DOC_FONTDECLS,
97 : XML_TOK_DOC_STYLES,
98 : XML_TOK_DOC_AUTOSTYLES,
99 : XML_TOK_DOC_MASTERSTYLES,
100 : XML_TOK_DOC_META,
101 : XML_TOK_DOC_BODY,
102 : XML_TOK_DOC_SCRIPT,
103 : XML_TOK_DOC_SETTINGS,
104 : XML_TOK_DOC_XFORMS,
105 : XML_TOK_OFFICE_END=XML_TOK_UNKNOWN
106 : };
107 :
108 : static SvXMLTokenMapEntry aDocTokenMap[] =
109 : {
110 : { XML_NAMESPACE_OFFICE, XML_FONT_FACE_DECLS, XML_TOK_DOC_FONTDECLS },
111 : { XML_NAMESPACE_OFFICE, XML_STYLES, XML_TOK_DOC_STYLES },
112 : { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES },
113 : { XML_NAMESPACE_OFFICE, XML_MASTER_STYLES, XML_TOK_DOC_MASTERSTYLES },
114 : { XML_NAMESPACE_OFFICE, XML_META, XML_TOK_DOC_META },
115 : { XML_NAMESPACE_OFFICE, XML_BODY, XML_TOK_DOC_BODY },
116 : { XML_NAMESPACE_OFFICE, XML_SCRIPTS, XML_TOK_DOC_SCRIPT },
117 : { XML_NAMESPACE_OFFICE, XML_SETTINGS, XML_TOK_DOC_SETTINGS },
118 : { XML_NAMESPACE_XFORMS, XML_MODEL, XML_TOK_DOC_XFORMS },
119 : XML_TOKEN_MAP_END
120 : };
121 :
122 : // ----------------------------------------------------------------------------
123 :
124 : class SwXMLBodyContext_Impl : public SvXMLImportContext
125 : {
126 : const SwXMLImport& GetSwImport() const
127 : { return (const SwXMLImport&)GetImport(); }
128 17 : SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
129 :
130 : public:
131 :
132 : SwXMLBodyContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
133 : const OUString& rLName,
134 : const Reference< xml::sax::XAttributeList > & xAttrList );
135 : virtual ~SwXMLBodyContext_Impl();
136 :
137 : TYPEINFO();
138 :
139 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
140 : const OUString& rLocalName,
141 : const Reference< xml::sax::XAttributeList > & xAttrList );
142 : };
143 :
144 17 : SwXMLBodyContext_Impl::SwXMLBodyContext_Impl( SwXMLImport& rImport,
145 : sal_uInt16 nPrfx, const OUString& rLName,
146 : const Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) :
147 17 : SvXMLImportContext( rImport, nPrfx, rLName )
148 : {
149 17 : }
150 :
151 34 : SwXMLBodyContext_Impl::~SwXMLBodyContext_Impl()
152 : {
153 34 : }
154 :
155 0 : TYPEINIT1( SwXMLBodyContext_Impl, SvXMLImportContext );
156 :
157 17 : SvXMLImportContext *SwXMLBodyContext_Impl::CreateChildContext(
158 : sal_uInt16 /*nPrefix*/,
159 : const OUString& rLocalName,
160 : const Reference< xml::sax::XAttributeList > & /*xAttrList*/ )
161 : {
162 17 : return GetSwImport().CreateBodyContentContext( rLocalName );
163 : }
164 :
165 : // ----------------------------------------------------------------------------
166 :
167 : // #i69629#
168 : // enhance class <SwXMLDocContext_Impl> in order to be able to create subclasses
169 : // NB: virtually inherit so we can multiply inherit properly
170 : // in SwXMLOfficeDocContext_Impl
171 : class SwXMLDocContext_Impl : public virtual SvXMLImportContext
172 : {
173 :
174 : protected: // #i69629#
175 : const SwXMLImport& GetSwImport() const
176 : { return (const SwXMLImport&)GetImport(); }
177 341 : SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
178 :
179 : public:
180 :
181 : SwXMLDocContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
182 : const OUString& rLName,
183 : const Reference< xml::sax::XAttributeList > & xAttrList );
184 : virtual ~SwXMLDocContext_Impl();
185 :
186 : TYPEINFO();
187 :
188 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
189 : const OUString& rLocalName,
190 : const Reference< xml::sax::XAttributeList > & xAttrList );
191 : };
192 :
193 52 : SwXMLDocContext_Impl::SwXMLDocContext_Impl( SwXMLImport& rImport,
194 : sal_uInt16 nPrfx, const OUString& rLName,
195 : const Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) :
196 52 : SvXMLImportContext( rImport, nPrfx, rLName )
197 : {
198 52 : }
199 :
200 122 : SwXMLDocContext_Impl::~SwXMLDocContext_Impl()
201 : {
202 139 : }
203 :
204 0 : TYPEINIT1( SwXMLDocContext_Impl, SvXMLImportContext );
205 :
206 154 : SvXMLImportContext *SwXMLDocContext_Impl::CreateChildContext(
207 : sal_uInt16 nPrefix,
208 : const OUString& rLocalName,
209 : const Reference< xml::sax::XAttributeList > & xAttrList )
210 : {
211 154 : SvXMLImportContext *pContext = 0;
212 :
213 154 : const SvXMLTokenMap& rTokenMap = GetSwImport().GetDocElemTokenMap();
214 154 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
215 : {
216 : case XML_TOK_DOC_FONTDECLS:
217 34 : pContext = GetSwImport().CreateFontDeclsContext( rLocalName,
218 34 : xAttrList );
219 34 : break;
220 : case XML_TOK_DOC_STYLES:
221 17 : GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
222 17 : pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
223 17 : sal_False );
224 17 : break;
225 : case XML_TOK_DOC_AUTOSTYLES:
226 : // don't use the autostyles from the styles-document for the progress
227 34 : if ( ! IsXMLToken( GetLocalName(), XML_DOCUMENT_STYLES ) )
228 17 : GetSwImport().GetProgressBarHelper()->Increment
229 17 : ( PROGRESS_BAR_STEP );
230 34 : pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
231 34 : sal_True );
232 34 : break;
233 :
234 : case XML_TOK_DOC_MASTERSTYLES:
235 17 : pContext = GetSwImport().CreateMasterStylesContext( rLocalName,
236 17 : xAttrList );
237 17 : break;
238 : case XML_TOK_DOC_META:
239 : OSL_FAIL("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
240 0 : break;
241 : case XML_TOK_DOC_SCRIPT:
242 17 : pContext = GetSwImport().CreateScriptContext( rLocalName );
243 17 : break;
244 : case XML_TOK_DOC_BODY:
245 17 : GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
246 : pContext = new SwXMLBodyContext_Impl( GetSwImport(), nPrefix,
247 17 : rLocalName, xAttrList );
248 17 : break;
249 : case XML_TOK_DOC_SETTINGS:
250 18 : pContext = new XMLDocumentSettingsContext( GetImport(), nPrefix, rLocalName, xAttrList );
251 18 : break;
252 : case XML_TOK_DOC_XFORMS:
253 0 : pContext = createXFormsModelContext(GetImport(), nPrefix, rLocalName);
254 0 : break;
255 : }
256 :
257 154 : if( !pContext )
258 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
259 :
260 :
261 154 : return pContext;
262 : }
263 :
264 : // #i69629# - new subclass <SwXMLOfficeDocContext_Impl> of class <SwXMLDocContext_Impl>
265 : class SwXMLOfficeDocContext_Impl :
266 : public SwXMLDocContext_Impl, public SvXMLMetaDocumentContext
267 : {
268 : public:
269 :
270 : SwXMLOfficeDocContext_Impl( SwXMLImport& rImport,
271 : sal_uInt16 nPrfx,
272 : const OUString& rLName,
273 : const Reference< xml::sax::XAttributeList > & xAttrList,
274 : const Reference< document::XDocumentProperties >& xDocProps);
275 : virtual ~SwXMLOfficeDocContext_Impl();
276 :
277 : TYPEINFO();
278 :
279 : virtual SvXMLImportContext *CreateChildContext(
280 : sal_uInt16 nPrefix,
281 : const OUString& rLocalName,
282 : const Reference< xml::sax::XAttributeList > & xAttrList );
283 : };
284 :
285 0 : SwXMLOfficeDocContext_Impl::SwXMLOfficeDocContext_Impl(
286 : SwXMLImport& rImport,
287 : sal_uInt16 nPrfx,
288 : const OUString& rLName,
289 : const Reference< xml::sax::XAttributeList > & xAttrList,
290 : const Reference< document::XDocumentProperties >& xDocProps) :
291 : SvXMLImportContext( rImport, nPrfx, rLName ),
292 : SwXMLDocContext_Impl( rImport, nPrfx, rLName, xAttrList ),
293 0 : SvXMLMetaDocumentContext( rImport, nPrfx, rLName, xDocProps)
294 : {
295 0 : }
296 :
297 0 : SwXMLOfficeDocContext_Impl::~SwXMLOfficeDocContext_Impl()
298 : {
299 0 : }
300 :
301 0 : TYPEINIT1( SwXMLOfficeDocContext_Impl, SwXMLDocContext_Impl );
302 :
303 0 : SvXMLImportContext* SwXMLOfficeDocContext_Impl::CreateChildContext(
304 : sal_uInt16 nPrefix,
305 : const OUString& rLocalName,
306 : const Reference< xml::sax::XAttributeList > & xAttrList )
307 : {
308 0 : const SvXMLTokenMap& rTokenMap = GetSwImport().GetDocElemTokenMap();
309 :
310 : // assign paragraph styles to list levels of outline style after all styles
311 : // are imported and finished. This is the case, when <office:body> starts
312 : // in flat OpenDocument file format.
313 : {
314 0 : if ( rTokenMap.Get( nPrefix, rLocalName ) == XML_TOK_DOC_BODY )
315 : {
316 0 : GetImport().GetTextImport()->SetOutlineStyles( sal_True );
317 : }
318 : }
319 :
320 : // behave like meta base class iff we encounter office:meta
321 0 : if ( XML_TOK_DOC_META == rTokenMap.Get( nPrefix, rLocalName ) ) {
322 : return SvXMLMetaDocumentContext::CreateChildContext(
323 0 : nPrefix, rLocalName, xAttrList );
324 : } else {
325 : return SwXMLDocContext_Impl::CreateChildContext(
326 0 : nPrefix, rLocalName, xAttrList );
327 : }
328 : }
329 :
330 : // #i69629# - new subclass <SwXMLDocStylesContext_Impl> of class <SwXMLDocContext_Impl>
331 : class SwXMLDocStylesContext_Impl : public SwXMLDocContext_Impl
332 : {
333 : public:
334 :
335 : SwXMLDocStylesContext_Impl( SwXMLImport& rImport,
336 : sal_uInt16 nPrfx,
337 : const OUString& rLName,
338 : const Reference< xml::sax::XAttributeList > & xAttrList );
339 : virtual ~SwXMLDocStylesContext_Impl();
340 :
341 : TYPEINFO();
342 :
343 : virtual void EndElement();
344 : };
345 :
346 17 : SwXMLDocStylesContext_Impl::SwXMLDocStylesContext_Impl(
347 : SwXMLImport& rImport,
348 : sal_uInt16 nPrfx,
349 : const OUString& rLName,
350 : const Reference< xml::sax::XAttributeList > & xAttrList ) :
351 : SvXMLImportContext( rImport, nPrfx, rLName ),
352 17 : SwXMLDocContext_Impl( rImport, nPrfx, rLName, xAttrList )
353 : {
354 17 : }
355 :
356 51 : SwXMLDocStylesContext_Impl::~SwXMLDocStylesContext_Impl()
357 : {
358 51 : }
359 :
360 0 : TYPEINIT1( SwXMLDocStylesContext_Impl, SwXMLDocContext_Impl );
361 :
362 17 : void SwXMLDocStylesContext_Impl::EndElement()
363 : {
364 : // assign paragraph styles to list levels of outline style after all styles
365 : // are imported and finished.
366 17 : SwXMLImport& rSwImport = dynamic_cast<SwXMLImport&>( GetImport());
367 17 : GetImport().GetTextImport()->SetOutlineStyles(
368 51 : (rSwImport.GetStyleFamilyMask() & SFX_STYLE_FAMILY_PARA ) ? sal_True : sal_False);
369 17 : }
370 : //----------------------------------------------------------------------------
371 :
372 154 : const SvXMLTokenMap& SwXMLImport::GetDocElemTokenMap()
373 : {
374 154 : if( !pDocElemTokenMap )
375 52 : pDocElemTokenMap = new SvXMLTokenMap( aDocTokenMap );
376 :
377 154 : return *pDocElemTokenMap;
378 : }
379 :
380 70 : SvXMLImportContext *SwXMLImport::CreateContext(
381 : sal_uInt16 nPrefix,
382 : const OUString& rLocalName,
383 : const Reference< xml::sax::XAttributeList > & xAttrList )
384 : {
385 70 : SvXMLImportContext *pContext = 0;
386 :
387 : // #i69629# - own subclasses for <office:document> and <office:document-styles>
388 192 : if( XML_NAMESPACE_OFFICE==nPrefix &&
389 70 : ( IsXMLToken( rLocalName, XML_DOCUMENT_SETTINGS ) ||
390 52 : IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ))
391 : pContext = new SwXMLDocContext_Impl( *this, nPrefix, rLocalName,
392 35 : xAttrList );
393 70 : else if ( XML_NAMESPACE_OFFICE==nPrefix &&
394 35 : IsXMLToken( rLocalName, XML_DOCUMENT_META ) )
395 : {
396 18 : pContext = CreateMetaContext(rLocalName);
397 : }
398 34 : else if ( XML_NAMESPACE_OFFICE==nPrefix &&
399 17 : IsXMLToken( rLocalName, XML_DOCUMENT_STYLES ) )
400 : {
401 : pContext = new SwXMLDocStylesContext_Impl( *this, nPrefix, rLocalName,
402 17 : xAttrList );
403 : }
404 0 : else if ( XML_NAMESPACE_OFFICE==nPrefix &&
405 0 : IsXMLToken( rLocalName, XML_DOCUMENT ) )
406 : {
407 : uno::Reference<document::XDocumentProperties> const xDocProps(
408 0 : GetDocumentProperties());
409 : // flat OpenDocument file format
410 : pContext = new SwXMLOfficeDocContext_Impl( *this, nPrefix, rLocalName,
411 0 : xAttrList, xDocProps);
412 : }
413 : else
414 0 : pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
415 :
416 70 : return pContext;
417 : }
418 :
419 71 : SwXMLImport::SwXMLImport(
420 : const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
421 : sal_uInt16 nImportFlags)
422 : : SvXMLImport( xServiceFactory, nImportFlags ),
423 : pSttNdIdx( 0 ),
424 : pTableItemMapper( 0 ),
425 : pDocElemTokenMap( 0 ),
426 : pTableElemTokenMap( 0 ),
427 : pTableCellAttrTokenMap( 0 ),
428 : pGraphicResolver( 0 ),
429 : pEmbeddedResolver( 0 ),
430 : nStyleFamilyMask( SFX_STYLE_FAMILY_ALL ),
431 : bLoadDoc( sal_True ),
432 : bInsert( sal_False ),
433 : bBlock( sal_False ),
434 : bShowProgress( sal_True ),
435 : bOrganizerMode( sal_False ),
436 : bInititedXForms( sal_False ),
437 71 : bPreserveRedlineMode( sal_True )
438 : {
439 71 : _InitItemImport();
440 :
441 71 : }
442 :
443 213 : SwXMLImport::~SwXMLImport() throw ()
444 : {
445 71 : delete pDocElemTokenMap;
446 71 : delete pTableElemTokenMap;
447 71 : delete pTableCellAttrTokenMap;
448 71 : _FinitItemImport();
449 142 : }
450 :
451 0 : void SwXMLImport::setTextInsertMode(
452 : const Reference< XTextRange > & rInsertPos )
453 : {
454 0 : bInsert = sal_True;
455 :
456 0 : Reference < XText > xText = rInsertPos->getText();
457 : Reference < XTextCursor > xTextCursor =
458 0 : xText->createTextCursorByRange( rInsertPos );
459 0 : GetTextImport()->SetCursor( xTextCursor );
460 0 : }
461 :
462 0 : void SwXMLImport::setStyleInsertMode( sal_uInt16 nFamilies,
463 : sal_Bool bOverwrite )
464 : {
465 0 : bInsert = !bOverwrite;
466 0 : nStyleFamilyMask = nFamilies;
467 0 : bLoadDoc = sal_False;
468 0 : }
469 :
470 0 : void SwXMLImport::setBlockMode( )
471 : {
472 0 : bBlock = sal_True;
473 0 : }
474 :
475 0 : void SwXMLImport::setOrganizerMode( )
476 : {
477 0 : bOrganizerMode = sal_True;
478 0 : }
479 :
480 : namespace
481 : {
482 : class theSwXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXMLImportUnoTunnelId > {};
483 : }
484 :
485 0 : const Sequence< sal_Int8 > & SwXMLImport::getUnoTunnelId() throw()
486 : {
487 0 : return theSwXMLImportUnoTunnelId::get().getSeq();
488 : }
489 :
490 0 : sal_Int64 SAL_CALL SwXMLImport::getSomething( const Sequence< sal_Int8 >& rId )
491 : throw(RuntimeException)
492 : {
493 0 : if( rId.getLength() == 16
494 0 : && 0 == memcmp( getUnoTunnelId().getConstArray(),
495 0 : rId.getConstArray(), 16 ) )
496 : {
497 0 : return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
498 : }
499 0 : return SvXMLImport::getSomething( rId );
500 : }
501 :
502 35 : static OTextCursorHelper *lcl_xml_GetSwXTextCursor( const Reference < XTextCursor >& rTextCursor )
503 : {
504 35 : Reference<XUnoTunnel> xCrsrTunnel( rTextCursor, UNO_QUERY );
505 : OSL_ENSURE( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
506 35 : if( !xCrsrTunnel.is() )
507 0 : return 0;
508 : OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper *>(
509 35 : sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
510 : OSL_ENSURE( pTxtCrsr, "SwXTextCursor missing" );
511 35 : return pTxtCrsr;
512 : }
513 :
514 71 : void SwXMLImport::startDocument( void )
515 : throw( xml::sax::SAXException, uno::RuntimeException )
516 : {
517 : // delegate to parent
518 71 : SvXMLImport::startDocument();
519 :
520 : OSL_ENSURE( GetModel().is(), "model is missing" );
521 71 : if( !GetModel().is() )
522 : return;
523 :
524 : // this method will modify the document directly -> lock SolarMutex
525 71 : SolarMutexGuard aGuard;
526 :
527 :
528 71 : Reference< XPropertySet > xImportInfo( getImportInfo() );
529 71 : Reference< XPropertySetInfo > xPropertySetInfo;
530 71 : if( xImportInfo.is() )
531 71 : xPropertySetInfo = xImportInfo->getPropertySetInfo();
532 71 : if( xPropertySetInfo.is() )
533 : {
534 71 : Any aAny;
535 : // insert style mode?
536 : OUString sStyleInsertModeFamilies(
537 71 : RTL_CONSTASCII_USTRINGPARAM("StyleInsertModeFamilies"));
538 71 : if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeFamilies) )
539 : {
540 71 : aAny = xImportInfo->getPropertyValue(sStyleInsertModeFamilies);
541 71 : Sequence< OUString> aFamiliesSeq;
542 71 : if( aAny >>= aFamiliesSeq )
543 : {
544 0 : OUString sFrameStyles( RTL_CONSTASCII_USTRINGPARAM ( "FrameStyles" ) );
545 0 : OUString sPageStyles( RTL_CONSTASCII_USTRINGPARAM ( "PageStyles" ) );
546 0 : OUString sCharacterStyles( RTL_CONSTASCII_USTRINGPARAM ( "CharacterStyles" ) );
547 0 : OUString sParagraphStyles( RTL_CONSTASCII_USTRINGPARAM ( "ParagraphStyles" ) );
548 0 : OUString sNumberingStyles( RTL_CONSTASCII_USTRINGPARAM ( "NumberingStyles" ) );
549 0 : sal_uInt16 nFamilyMask = 0U;
550 0 : sal_Int32 nCount = aFamiliesSeq.getLength();
551 0 : const OUString *pSeq = aFamiliesSeq.getConstArray();
552 0 : for( sal_Int32 i=0; i < nCount; i++ )
553 : {
554 0 : const OUString& rFamily = pSeq[i];
555 0 : if( rFamily==sFrameStyles )
556 0 : nFamilyMask |= SFX_STYLE_FAMILY_FRAME;
557 0 : else if( rFamily==sPageStyles )
558 0 : nFamilyMask |= SFX_STYLE_FAMILY_PAGE;
559 0 : else if( rFamily==sCharacterStyles )
560 0 : nFamilyMask |= SFX_STYLE_FAMILY_CHAR;
561 0 : else if( rFamily==sParagraphStyles )
562 0 : nFamilyMask |= SFX_STYLE_FAMILY_PARA;
563 0 : else if( rFamily==sNumberingStyles )
564 0 : nFamilyMask |= SFX_STYLE_FAMILY_PSEUDO;
565 : }
566 :
567 0 : sal_Bool bOverwrite = sal_False;
568 : OUString sStyleInsertModeOverwrite(
569 0 : RTL_CONSTASCII_USTRINGPARAM("StyleInsertModeOverwrite"));
570 0 : if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeOverwrite) )
571 : {
572 0 : aAny = xImportInfo->getPropertyValue(sStyleInsertModeOverwrite);
573 0 : if( aAny.getValueType() == ::getBooleanCppuType() &&
574 0 : *static_cast<const sal_Bool*>(aAny.getValue()) )
575 0 : bOverwrite = sal_True;
576 : }
577 :
578 0 : setStyleInsertMode( nFamilyMask, bOverwrite );
579 71 : }
580 : }
581 :
582 : // text insert mode?
583 : OUString sTextInsertModeRange(
584 71 : RTL_CONSTASCII_USTRINGPARAM("TextInsertModeRange"));
585 71 : if( xPropertySetInfo->hasPropertyByName(sTextInsertModeRange) )
586 : {
587 71 : aAny = xImportInfo->getPropertyValue(sTextInsertModeRange);
588 71 : Reference<XTextRange> xInsertTextRange;
589 71 : if( aAny >>= xInsertTextRange )
590 0 : setTextInsertMode( xInsertTextRange );
591 : }
592 :
593 : // auto text mode
594 : OUString sAutoTextMode(
595 71 : RTL_CONSTASCII_USTRINGPARAM("AutoTextMode"));
596 71 : if( xPropertySetInfo->hasPropertyByName(sAutoTextMode) )
597 : {
598 71 : aAny = xImportInfo->getPropertyValue(sAutoTextMode);
599 71 : if( aAny.getValueType() == ::getBooleanCppuType() &&
600 0 : *static_cast<const sal_Bool*>(aAny.getValue()) )
601 0 : setBlockMode();
602 : }
603 :
604 : // organizer mode
605 : OUString sOrganizerMode(
606 71 : RTL_CONSTASCII_USTRINGPARAM("OrganizerMode"));
607 71 : if( xPropertySetInfo->hasPropertyByName(sOrganizerMode) )
608 : {
609 71 : aAny = xImportInfo->getPropertyValue(sOrganizerMode);
610 71 : if( aAny.getValueType() == ::getBooleanCppuType() &&
611 0 : *static_cast<const sal_Bool*>(aAny.getValue()) )
612 0 : setOrganizerMode();
613 71 : }
614 : }
615 :
616 : // There only is a text cursor by now if we are in insert mode. In any
617 : // other case we have to create one at the start of the document.
618 : // We also might change into the insert mode later, so we have to make
619 : // sure to first set the insert mode and then create the text import
620 : // helper. Otherwise it won't have the insert flag set!
621 71 : OTextCursorHelper *pTxtCrsr = 0;
622 71 : Reference < XTextCursor > xTextCursor;
623 71 : if( HasTextImport() )
624 0 : xTextCursor = GetTextImport()->GetCursor();
625 71 : if( !xTextCursor.is() )
626 : {
627 71 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
628 71 : Reference < XText > xText = xTextDoc->getText();
629 71 : xTextCursor = xText->createTextCursor();
630 71 : SwCrsrShell *pCrsrSh = 0;
631 71 : SwDoc *pDoc = 0;
632 71 : if( IMPORT_ALL == getImportFlags() )
633 : {
634 0 : pTxtCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
635 : OSL_ENSURE( pTxtCrsr, "SwXTextCursor missing" );
636 0 : if( !pTxtCrsr )
637 : return;
638 :
639 0 : pDoc = pTxtCrsr->GetDoc();
640 : OSL_ENSURE( pDoc, "SwDoc missing" );
641 0 : if( !pDoc )
642 : return;
643 :
644 : // Is there a edit shell. If yes, then we are currently inserting
645 : // a document. We then have to insert at the current edit shell's
646 : // cursor position. That not quite clean code, but there is no other
647 : // way currently.
648 0 : pCrsrSh = pDoc->GetEditShell();
649 : }
650 71 : if( pCrsrSh )
651 : {
652 : const uno::Reference<text::XTextRange> xInsertTextRange(
653 : SwXTextRange::CreateXTextRange(
654 0 : *pDoc, *pCrsrSh->GetCrsr()->GetPoint(), 0 ) );
655 0 : setTextInsertMode( xInsertTextRange );
656 0 : xTextCursor = GetTextImport()->GetCursor();
657 0 : pTxtCrsr = 0;
658 : }
659 : else
660 71 : GetTextImport()->SetCursor( xTextCursor );
661 : }
662 :
663 71 : if( (getImportFlags() & (IMPORT_CONTENT|IMPORT_MASTERSTYLES)) == 0 )
664 : return;
665 :
666 35 : if( !pTxtCrsr )
667 35 : pTxtCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
668 : OSL_ENSURE( pTxtCrsr, "SwXTextCursor missing" );
669 35 : if( !pTxtCrsr )
670 : return;
671 :
672 35 : SwDoc *pDoc = pTxtCrsr->GetDoc();
673 : OSL_ENSURE( pDoc, "SwDoc missing" );
674 35 : if( !pDoc )
675 : return;
676 :
677 35 : if( (getImportFlags() & IMPORT_CONTENT) != 0 && !IsStylesOnlyMode() )
678 : {
679 17 : pSttNdIdx = new SwNodeIndex( pDoc->GetNodes() );
680 17 : if( IsInsertMode() )
681 : {
682 0 : SwPaM *pPaM = pTxtCrsr->GetPaM();
683 0 : const SwPosition* pPos = pPaM->GetPoint();
684 :
685 : // Split once and remember the node that has been splitted.
686 0 : pDoc->SplitNode( *pPos, false );
687 0 : *pSttNdIdx = pPos->nNode.GetIndex()-1;
688 :
689 : // Split again.
690 0 : pDoc->SplitNode( *pPos, false );
691 :
692 : // Insert all content into the new node
693 0 : pPaM->Move( fnMoveBackward );
694 : pDoc->SetTxtFmtColl
695 0 : ( *pPaM, pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD, false ) );
696 : }
697 : }
698 :
699 : // We need a draw model to be able to set the z order
700 35 : pDoc->GetOrCreateDrawModel(); // #i52858# - method name changed
701 :
702 : // SJ: #i49801# locking the modell to disable repaints
703 35 : SdrModel* pDrawModel = pDoc->GetDrawModel();
704 35 : if ( pDrawModel )
705 35 : pDrawModel->setLock(true);
706 :
707 35 : if( !GetGraphicResolver().is() )
708 : {
709 0 : pGraphicResolver = SvXMLGraphicHelper::Create( GRAPHICHELPER_MODE_READ );
710 0 : Reference< document::XGraphicObjectResolver > xGraphicResolver( pGraphicResolver );
711 0 : SetGraphicResolver( xGraphicResolver );
712 : }
713 :
714 35 : if( !GetEmbeddedResolver().is() )
715 : {
716 0 : SfxObjectShell *pPersist = pDoc->GetPersist();
717 0 : if( pPersist )
718 : {
719 : pEmbeddedResolver = SvXMLEmbeddedObjectHelper::Create(
720 : *pPersist,
721 0 : EMBEDDEDOBJECTHELPER_MODE_READ );
722 0 : Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver( pEmbeddedResolver );
723 0 : SetEmbeddedResolver( xEmbeddedResolver );
724 : }
725 71 : }
726 : }
727 :
728 70 : void SwXMLImport::endDocument( void )
729 : throw( xml::sax::SAXException, uno::RuntimeException )
730 : {
731 : OSL_ENSURE( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
732 70 : if( !GetModel().is() )
733 70 : return;
734 :
735 : // this method will modify the document directly -> lock SolarMutex
736 70 : SolarMutexGuard aGuard;
737 :
738 70 : if( pGraphicResolver )
739 0 : SvXMLGraphicHelper::Destroy( pGraphicResolver );
740 70 : if( pEmbeddedResolver )
741 0 : SvXMLEmbeddedObjectHelper::Destroy( pEmbeddedResolver );
742 : // Clear the shape import to sort the shapes (and not in the
743 : // destructor that might be called after the import has finished
744 : // for Java filters.
745 70 : if( HasShapeImport() )
746 34 : ClearShapeImport();
747 :
748 :
749 70 : SwDoc *pDoc = 0;
750 70 : if( (getImportFlags() & IMPORT_CONTENT) != 0 && !IsStylesOnlyMode() )
751 : {
752 34 : Reference<XUnoTunnel> xCrsrTunnel( GetTextImport()->GetCursor(),
753 17 : UNO_QUERY);
754 : OSL_ENSURE( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
755 : OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper *>(
756 17 : sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
757 : OSL_ENSURE( pTxtCrsr, "SwXTextCursor missing" );
758 17 : SwPaM *pPaM = pTxtCrsr->GetPaM();
759 17 : if( IsInsertMode() && pSttNdIdx->GetIndex() )
760 : {
761 : // If we are in insert mode, join the splitted node that is in front
762 : // of the new content with the first new node. Or in other words:
763 : // Revert the first split node.
764 0 : SwTxtNode* pTxtNode = pSttNdIdx->GetNode().GetTxtNode();
765 0 : SwNodeIndex aNxtIdx( *pSttNdIdx );
766 0 : if( pTxtNode && pTxtNode->CanJoinNext( &aNxtIdx ) &&
767 0 : pSttNdIdx->GetIndex() + 1 == aNxtIdx.GetIndex() )
768 : {
769 : // If the PaM points to the first new node, move the PaM to the
770 : // end of the previous node.
771 0 : if( pPaM && pPaM->GetPoint()->nNode == aNxtIdx )
772 : {
773 0 : pPaM->GetPoint()->nNode = *pSttNdIdx;
774 0 : pPaM->GetPoint()->nContent.Assign( pTxtNode,
775 0 : pTxtNode->GetTxt().Len() );
776 : }
777 :
778 : #if OSL_DEBUG_LEVEL > 0
779 : // !!! This should be impossible !!!!
780 : OSL_ENSURE( pSttNdIdx->GetIndex()+1 !=
781 : pPaM->GetBound( sal_True ).nNode.GetIndex(),
782 : "PaM.Bound1 point to new node " );
783 : OSL_ENSURE( pSttNdIdx->GetIndex()+1 !=
784 : pPaM->GetBound( sal_False ).nNode.GetIndex(),
785 : "PaM.Bound2 points to new node" );
786 :
787 : if( pSttNdIdx->GetIndex()+1 ==
788 : pPaM->GetBound( sal_True ).nNode.GetIndex() )
789 : {
790 : sal_uInt16 nCntPos =
791 : pPaM->GetBound( sal_True ).nContent.GetIndex();
792 : pPaM->GetBound( sal_True ).nContent.Assign( pTxtNode,
793 : pTxtNode->GetTxt().Len() + nCntPos );
794 : }
795 : if( pSttNdIdx->GetIndex()+1 ==
796 : pPaM->GetBound( sal_False ).nNode.GetIndex() )
797 : {
798 : sal_uInt16 nCntPos =
799 : pPaM->GetBound( sal_False ).nContent.GetIndex();
800 : pPaM->GetBound( sal_False ).nContent.Assign( pTxtNode,
801 : pTxtNode->GetTxt().Len() + nCntPos );
802 : }
803 : #endif
804 : // If the first new node isn't empty, convert the node's text
805 : // attributes into hints. Otherwise, set the new node's
806 : // paragraph style at the previous (empty) node.
807 0 : SwTxtNode* pDelNd = aNxtIdx.GetNode().GetTxtNode();
808 0 : if( pTxtNode->GetTxt().Len() )
809 0 : pDelNd->FmtToTxtAttr( pTxtNode );
810 : else
811 0 : pTxtNode->ChgFmtColl( pDelNd->GetTxtColl() );
812 0 : pTxtNode->JoinNext();
813 0 : }
814 : }
815 :
816 17 : SwPosition* pPos = pPaM->GetPoint();
817 : OSL_ENSURE( !pPos->nContent.GetIndex(), "last paragraph isn't empty" );
818 17 : if( !pPos->nContent.GetIndex() )
819 : {
820 : SwTxtNode* pCurrNd;
821 17 : sal_uLong nNodeIdx = pPos->nNode.GetIndex();
822 17 : pDoc = pPaM->GetDoc();
823 :
824 : OSL_ENSURE( pPos->nNode.GetNode().IsCntntNode(),
825 : "insert position is not a content node" );
826 17 : if( !IsInsertMode() )
827 : {
828 : // If we're not in insert mode, the last node is deleted.
829 17 : const SwNode *pPrev = pDoc->GetNodes()[nNodeIdx -1];
830 19 : if( pPrev->IsCntntNode() ||
831 1 : ( pPrev->IsEndNode() &&
832 1 : pPrev->StartOfSectionNode()->IsSectionNode() ) )
833 : {
834 17 : SwCntntNode* pCNd = pPaM->GetCntntNode();
835 34 : if( pCNd && pCNd->StartOfSectionIndex()+2 <
836 17 : pCNd->EndOfSectionIndex() )
837 : {
838 17 : pPaM->GetBound(sal_True).nContent.Assign( 0, 0 );
839 17 : pPaM->GetBound(sal_False).nContent.Assign( 0, 0 );
840 17 : pDoc->GetNodes().Delete( pPaM->GetPoint()->nNode );
841 : }
842 : }
843 : }
844 0 : else if( 0 != (pCurrNd = pDoc->GetNodes()[nNodeIdx]->GetTxtNode()) )
845 : {
846 : // Id we're in insert mode, the empty node is joined with
847 : // the next and the previous one.
848 0 : if( pCurrNd->CanJoinNext( &pPos->nNode ))
849 : {
850 0 : SwTxtNode* pNextNd = pPos->nNode.GetNode().GetTxtNode();
851 0 : pPos->nContent.Assign( pNextNd, 0 );
852 0 : pPaM->SetMark(); pPaM->DeleteMark();
853 0 : pNextNd->JoinPrev();
854 :
855 : // Remove line break that has been inserted by the import,
856 : // but only if one has been inserted!
857 0 : if( pNextNd->CanJoinPrev(/* &pPos->nNode*/ ) &&
858 0 : *pSttNdIdx != pPos->nNode )
859 : {
860 0 : pNextNd->JoinPrev();
861 : }
862 : }
863 0 : else if( !pCurrNd->GetTxt().Len() )
864 : {
865 0 : pPos->nContent.Assign( 0, 0 );
866 0 : pPaM->SetMark(); pPaM->DeleteMark();
867 0 : pDoc->GetNodes().Delete( pPos->nNode, 1 );
868 0 : pPaM->Move( fnMoveBackward );
869 : }
870 : }
871 17 : }
872 : }
873 :
874 : /* Was called too early. Moved from SwXMLBodyContext_Impl::EndElement */
875 :
876 70 : GetTextImport()->RedlineAdjustStartNodeCursor( sal_False );
877 :
878 140 : if( (getImportFlags() & IMPORT_CONTENT) != 0 ||
879 70 : ((getImportFlags() & IMPORT_MASTERSTYLES) != 0 && IsStylesOnlyMode()) )
880 : {
881 : // pDoc might be 0. In this case UpdateTxtCollCondition is looking
882 : // for it itself.
883 17 : UpdateTxtCollConditions( pDoc );
884 : }
885 :
886 70 : GetTextImport()->ResetCursor();
887 :
888 70 : delete pSttNdIdx;
889 70 : pSttNdIdx = 0;
890 :
891 70 : if( (getImportFlags() == IMPORT_ALL ) )
892 : {
893 : // Notify math objects. If we are in the package filter this will
894 : // be done by the filter object itself
895 0 : if( IsInsertMode() )
896 0 : pDoc->PrtOLENotify( sal_False );
897 0 : else if ( pDoc->IsOLEPrtNotifyPending() )
898 0 : pDoc->PrtOLENotify( sal_True );
899 : }
900 :
901 : // SJ: #i49801# -> now permitting repaints
902 70 : if ( pDoc )
903 : {
904 17 : SdrModel* pDrawModel = pDoc->GetDrawModel();
905 17 : if ( pDrawModel )
906 17 : pDrawModel->setLock(false);
907 : }
908 :
909 : // #i90243#
910 70 : if ( bInititedXForms )
911 : {
912 0 : Reference< xforms::XFormsSupplier > xFormsSupp( GetModel(), UNO_QUERY );
913 0 : Reference< XNameAccess > xXForms;
914 0 : if ( xFormsSupp.is() )
915 0 : xXForms = xFormsSupp->getXForms().get();
916 :
917 0 : if ( xXForms.is() )
918 : {
919 : try
920 : {
921 0 : Sequence< beans::PropertyValue > aXFormsSettings;
922 :
923 0 : ::rtl::OUString sXFormsSettingsName( GetXMLToken( XML_XFORM_MODEL_SETTINGS ) );
924 0 : if ( xLateInitSettings.is() && xLateInitSettings->hasByName( sXFormsSettingsName ) )
925 : {
926 0 : OSL_VERIFY( xLateInitSettings->getByName( sXFormsSettingsName ) >>= aXFormsSettings );
927 0 : applyXFormsSettings( xXForms, aXFormsSettings );
928 0 : }
929 : }
930 0 : catch( const Exception& )
931 : {
932 : DBG_UNHANDLED_EXCEPTION();
933 : }
934 0 : }
935 : }
936 :
937 : // delegate to parent: takes care of error handling
938 70 : SvXMLImport::endDocument();
939 70 : ClearTextImport();
940 : }
941 :
942 :
943 : // Locally derive XMLTextShapeImportHelper, so we can take care of the
944 : // form import This is Writer, but not text specific, so it should go
945 : // here!
946 : class SvTextShapeImportHelper : public XMLTextShapeImportHelper
947 : {
948 : // hold own reference form import helper, because the SvxImport
949 : // stored in the superclass, from whom we originally got the
950 : // reference, is already destroyed when we want to use it in the
951 : // destructor
952 : UniReference< ::xmloff::OFormLayerXMLImport > rFormImport;
953 :
954 : // hold reference to the one page (if it exists) for calling startPage()
955 : // and endPage. If !xPage.is(), then this document doesn't have a
956 : // XDrawPage.
957 : Reference<drawing::XDrawPage> xPage;
958 :
959 : public:
960 :
961 : SvTextShapeImportHelper(SvXMLImport& rImp);
962 : virtual ~SvTextShapeImportHelper();
963 : };
964 :
965 34 : SvTextShapeImportHelper::SvTextShapeImportHelper(SvXMLImport& rImp) :
966 34 : XMLTextShapeImportHelper(rImp)
967 : {
968 34 : Reference<drawing::XDrawPageSupplier> xSupplier(rImp.GetModel(),UNO_QUERY);
969 34 : if (xSupplier.is())
970 : {
971 34 : if (rImp.GetFormImport().is())
972 : {
973 34 : rImp.GetFormImport()->startPage(xSupplier->getDrawPage());
974 34 : rFormImport = rImp.GetFormImport();
975 : }
976 :
977 34 : xPage = xSupplier->getDrawPage();
978 34 : Reference<XShapes> xShapes( xPage, UNO_QUERY );
979 34 : XMLShapeImportHelper::startPage( xShapes );
980 34 : }
981 34 : }
982 :
983 102 : SvTextShapeImportHelper::~SvTextShapeImportHelper()
984 : {
985 34 : rFormImport->endPage();
986 :
987 34 : if (xPage.is())
988 : {
989 34 : Reference<XShapes> xShapes( xPage, UNO_QUERY );
990 34 : XMLShapeImportHelper::endPage(xShapes);
991 : }
992 68 : }
993 :
994 :
995 71 : XMLTextImportHelper* SwXMLImport::CreateTextImport()
996 : {
997 71 : return new SwXMLTextImportHelper( GetModel(), *this, getImportInfo(),
998 71 : IsInsertMode(),
999 71 : IsStylesOnlyMode(), bShowProgress,
1000 142 : IsBlockMode(), IsOrganizerMode(),
1001 355 : bPreserveRedlineMode );
1002 : }
1003 :
1004 34 : XMLShapeImportHelper* SwXMLImport::CreateShapeImport()
1005 : {
1006 34 : return new SvTextShapeImportHelper( *this );
1007 : }
1008 :
1009 34 : SvXMLImportContext *SwXMLImport::CreateFontDeclsContext(
1010 : const OUString& rLocalName,
1011 : const Reference< xml::sax::XAttributeList > & xAttrList )
1012 : {
1013 : XMLFontStylesContext *pFSContext =
1014 : new XMLFontStylesContext( *this, XML_NAMESPACE_OFFICE,
1015 : rLocalName, xAttrList,
1016 34 : osl_getThreadTextEncoding() );
1017 34 : SetFontDecls( pFSContext );
1018 34 : return pFSContext;
1019 : }
1020 18 : void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
1021 : {
1022 18 : if (IsInsertMode() || IsStylesOnlyMode() || IsBlockMode() || IsOrganizerMode() || !GetModel().is() )
1023 : return;
1024 :
1025 : // this method will modify the document directly -> lock SolarMutex
1026 18 : SolarMutexGuard aGuard;
1027 :
1028 18 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
1029 18 : Reference < XText > xText = xTextDoc->getText();
1030 18 : Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
1031 : OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
1032 18 : if( !xTextTunnel.is() )
1033 : return;
1034 :
1035 : SwXText *pText = reinterpret_cast< SwXText *>(
1036 18 : sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
1037 : OSL_ENSURE( pText, "SwXText missing" );
1038 18 : if( !pText )
1039 : return;
1040 :
1041 18 : SwDoc *pDoc = pText->GetDoc();
1042 18 : Rectangle aRect;
1043 18 : if( pDoc->GetDocShell() )
1044 18 : aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
1045 : //TODO/LATER: why that cast?!
1046 : //aRect = ((SfxInPlaceObject *)pDoc->GetDocShell())->GetVisArea();
1047 :
1048 18 : sal_Int32 nCount = aViewProps.getLength();
1049 18 : const PropertyValue *pValue = aViewProps.getConstArray();
1050 :
1051 18 : sal_Int64 nTmp = 0;
1052 18 : sal_Bool bShowRedlineChanges = sal_False, bBrowseMode = sal_False;
1053 18 : sal_Bool bChangeShowRedline = sal_False, bChangeBrowseMode = sal_False;
1054 :
1055 : //TODO/LATER: why that cast?!
1056 18 : sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
1057 : //sal_Bool bTwip = pDoc->GetDocShell()->SfxInPlaceObject::GetMapUnit ( ) == MAP_TWIP;
1058 :
1059 146 : for (sal_Int32 i = 0; i < nCount ; i++)
1060 : {
1061 128 : if ( pValue->Name == "ViewAreaTop" )
1062 : {
1063 18 : pValue->Value >>= nTmp;
1064 18 : aRect.setY( static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp) );
1065 : }
1066 110 : else if ( pValue->Name == "ViewAreaLeft" )
1067 : {
1068 18 : pValue->Value >>= nTmp;
1069 18 : aRect.setX( static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp) );
1070 : }
1071 92 : else if ( pValue->Name == "ViewAreaWidth" )
1072 : {
1073 18 : pValue->Value >>= nTmp;
1074 18 : Size aSize( aRect.GetSize() );
1075 18 : aSize.Width() = static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp);
1076 18 : aRect.SetSize( aSize );
1077 : }
1078 74 : else if ( pValue->Name == "ViewAreaHeight" )
1079 : {
1080 18 : pValue->Value >>= nTmp;
1081 18 : Size aSize( aRect.GetSize() );
1082 18 : aSize.Height() = static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp);
1083 18 : aRect.SetSize( aSize );
1084 : }
1085 56 : else if ( pValue->Name == "ShowRedlineChanges" )
1086 : {
1087 18 : bShowRedlineChanges = *(sal_Bool *)(pValue->Value.getValue());
1088 18 : bChangeShowRedline = sal_True;
1089 : }
1090 : // Headers and footers are not displayed in BrowseView anymore
1091 38 : else if ( pValue->Name == "InBrowseMode" )
1092 : {
1093 18 : bBrowseMode = *(sal_Bool *)(pValue->Value.getValue());
1094 18 : bChangeBrowseMode = sal_True;
1095 : }
1096 128 : pValue++;
1097 : }
1098 18 : if( pDoc->GetDocShell() )
1099 18 : pDoc->GetDocShell()->SetVisArea ( aRect );
1100 :
1101 18 : if (bChangeBrowseMode)
1102 18 : pDoc->set(IDocumentSettingAccess::BROWSE_MODE, bBrowseMode );
1103 :
1104 18 : if (bChangeShowRedline)
1105 18 : GetTextImport()->SetShowChanges( bShowRedlineChanges );
1106 : }
1107 :
1108 18 : void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aConfigProps)
1109 : {
1110 : // this method will modify the document directly -> lock SolarMutex
1111 18 : SolarMutexGuard aGuard;
1112 :
1113 18 : Reference< lang::XMultiServiceFactory > xFac( GetModel(), UNO_QUERY );
1114 18 : if( !xFac.is() )
1115 : return;
1116 :
1117 18 : Reference< XPropertySet > xProps( xFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ), UNO_QUERY );
1118 18 : if( !xProps.is() )
1119 : return;
1120 :
1121 18 : Reference< XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
1122 18 : if( !xInfo.is() )
1123 : return;
1124 :
1125 18 : boost::unordered_set< String, StringHashRef, StringEqRef > aSet;
1126 18 : aSet.insert(String("ForbiddenCharacters", RTL_TEXTENCODING_ASCII_US));
1127 18 : aSet.insert(String("IsKernAsianPunctuation", RTL_TEXTENCODING_ASCII_US));
1128 18 : aSet.insert(String("CharacterCompressionType", RTL_TEXTENCODING_ASCII_US));
1129 18 : aSet.insert(String("LinkUpdateMode", RTL_TEXTENCODING_ASCII_US));
1130 18 : aSet.insert(String("FieldAutoUpdate", RTL_TEXTENCODING_ASCII_US));
1131 18 : aSet.insert(String("ChartAutoUpdate", RTL_TEXTENCODING_ASCII_US));
1132 18 : aSet.insert(String("AddParaTableSpacing", RTL_TEXTENCODING_ASCII_US));
1133 18 : aSet.insert(String("AddParaTableSpacingAtStart", RTL_TEXTENCODING_ASCII_US));
1134 18 : aSet.insert(String("PrintAnnotationMode", RTL_TEXTENCODING_ASCII_US));
1135 18 : aSet.insert(String("PrintBlackFonts", RTL_TEXTENCODING_ASCII_US));
1136 18 : aSet.insert(String("PrintControls", RTL_TEXTENCODING_ASCII_US));
1137 18 : aSet.insert(String("PrintDrawings", RTL_TEXTENCODING_ASCII_US));
1138 18 : aSet.insert(String("PrintGraphics", RTL_TEXTENCODING_ASCII_US));
1139 18 : aSet.insert(String("PrintLeftPages", RTL_TEXTENCODING_ASCII_US));
1140 18 : aSet.insert(String("PrintPageBackground", RTL_TEXTENCODING_ASCII_US));
1141 18 : aSet.insert(String("PrintProspect", RTL_TEXTENCODING_ASCII_US));
1142 18 : aSet.insert(String("PrintReversed", RTL_TEXTENCODING_ASCII_US));
1143 18 : aSet.insert(String("PrintRightPages", RTL_TEXTENCODING_ASCII_US));
1144 18 : aSet.insert(String("PrintFaxName", RTL_TEXTENCODING_ASCII_US));
1145 18 : aSet.insert(String("PrintPaperFromSetup", RTL_TEXTENCODING_ASCII_US));
1146 18 : aSet.insert(String("PrintTables", RTL_TEXTENCODING_ASCII_US));
1147 18 : aSet.insert(String("PrintSingleJobs", RTL_TEXTENCODING_ASCII_US));
1148 18 : aSet.insert(String("UpdateFromTemplate", RTL_TEXTENCODING_ASCII_US));
1149 18 : aSet.insert(String("PrinterIndependentLayout", RTL_TEXTENCODING_ASCII_US));
1150 18 : aSet.insert(String("PrintEmptyPages", RTL_TEXTENCODING_ASCII_US));
1151 18 : aSet.insert(String("SmallCapsPercentage66", RTL_TEXTENCODING_ASCII_US));
1152 18 : aSet.insert(String("TabOverflow", RTL_TEXTENCODING_ASCII_US));
1153 18 : aSet.insert(String("UnbreakableNumberings", RTL_TEXTENCODING_ASCII_US));
1154 18 : aSet.insert(String("ClippedPictures", RTL_TEXTENCODING_ASCII_US));
1155 18 : aSet.insert(String("BackgroundParaOverDrawings", RTL_TEXTENCODING_ASCII_US));
1156 :
1157 18 : sal_Int32 nCount = aConfigProps.getLength();
1158 18 : const PropertyValue* pValues = aConfigProps.getConstArray();
1159 :
1160 18 : SvtSaveOptions aSaveOpt;
1161 18 : sal_Bool bIsUserSetting = aSaveOpt.IsLoadUserSettings(),
1162 18 : bSet = bIsUserSetting;
1163 :
1164 : // for some properties we don't want to use the application
1165 : // default if they're missing. So we watch for them in the loop
1166 : // below, and set them if not found
1167 18 : bool bPrinterIndependentLayout = false;
1168 18 : bool bUseOldNumbering = false;
1169 18 : bool bOutlineLevelYieldsOutlineRule = false;
1170 18 : bool bAddExternalLeading = false;
1171 18 : bool bAddParaSpacingToTableCells = false;
1172 18 : bool bUseFormerLineSpacing = false;
1173 18 : bool bUseFormerObjectPositioning = false;
1174 18 : bool bUseFormerTextWrapping = false;
1175 18 : bool bConsiderWrapOnObjPos = false;
1176 18 : bool bIgnoreFirstLineIndentInNumbering = false;
1177 18 : bool bDoNotJustifyLinesWithManualBreak = false;
1178 18 : bool bDoNotResetParaAttrsForNumFont = false;
1179 18 : bool bLoadReadonly = false;
1180 18 : bool bDoNotCaptureDrawObjsOnPage( false );
1181 18 : bool bClipAsCharacterAnchoredWriterFlyFrames( false );
1182 18 : bool bUnixForceZeroExtLeading = false;
1183 18 : bool bUseOldPrinterMetrics = false;
1184 18 : bool bSmallCapsPercentage66 = false;
1185 18 : bool bTabOverflow = false;
1186 18 : bool bUnbreakableNumberings = false;
1187 18 : bool bClippedPictures = false;
1188 18 : bool bBackgroundParaOverDrawings = false;
1189 :
1190 18 : OUString sRedlineProtectionKey( RTL_CONSTASCII_USTRINGPARAM( "RedlineProtectionKey" ) );
1191 :
1192 18 : const PropertyValue* currentDatabaseDataSource = NULL;
1193 18 : const PropertyValue* currentDatabaseCommand = NULL;
1194 18 : const PropertyValue* currentDatabaseCommandType = NULL;
1195 18 : OUString currentDatabaseDataSourceKey( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseDataSource" ));
1196 18 : OUString currentDatabaseCommandKey( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseCommand" ));
1197 18 : OUString currentDatabaseCommandTypeKey( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseCommandType" ));
1198 :
1199 1248 : while( nCount-- )
1200 : {
1201 1212 : if( !bIsUserSetting )
1202 : {
1203 : // test over the hash value if the entry is in the table.
1204 0 : String aStr(pValues->Name);
1205 :
1206 0 : bSet = aSet.find(aStr) == aSet.end();
1207 : }
1208 :
1209 1212 : if( bSet )
1210 : {
1211 : try
1212 : {
1213 1212 : if( xInfo->hasPropertyByName( pValues->Name ) )
1214 : {
1215 1212 : if( pValues->Name.equals( sRedlineProtectionKey ) )
1216 : {
1217 17 : Sequence<sal_Int8> aKey;
1218 17 : pValues->Value >>= aKey;
1219 17 : GetTextImport()->SetChangesProtectionKey( aKey );
1220 : }
1221 : else
1222 : {
1223 : // HACK: Setting these out of order does not work.
1224 1195 : if( pValues->Name.equals( currentDatabaseDataSourceKey ))
1225 18 : currentDatabaseDataSource = pValues;
1226 1177 : else if( pValues->Name.equals( currentDatabaseCommandKey ))
1227 18 : currentDatabaseCommand = pValues;
1228 1159 : else if( pValues->Name.equals( currentDatabaseCommandTypeKey ))
1229 18 : currentDatabaseCommandType = pValues;
1230 : else
1231 1141 : xProps->setPropertyValue( pValues->Name,
1232 1141 : pValues->Value );
1233 : }
1234 : }
1235 :
1236 : // did we find any of the non-default cases?
1237 1212 : if ( pValues->Name == "PrinterIndependentLayout" )
1238 18 : bPrinterIndependentLayout = true;
1239 1194 : else if ( pValues->Name == "AddExternalLeading" )
1240 17 : bAddExternalLeading = true;
1241 1177 : else if ( pValues->Name == "AddParaSpacingToTableCells" )
1242 17 : bAddParaSpacingToTableCells = true;
1243 1160 : else if ( pValues->Name == "UseFormerLineSpacing" )
1244 17 : bUseFormerLineSpacing = true;
1245 1143 : else if ( pValues->Name == "UseFormerObjectPositioning" )
1246 17 : bUseFormerObjectPositioning = true;
1247 1126 : else if ( pValues->Name == "UseFormerTextWrapping" )
1248 17 : bUseFormerTextWrapping = true;
1249 1109 : else if ( pValues->Name == "UseOldNumbering" )
1250 18 : bUseOldNumbering = true;
1251 1091 : else if ( pValues->Name == "OutlineLevelYieldsNumbering" )
1252 17 : bOutlineLevelYieldsOutlineRule = true;
1253 1074 : else if ( pValues->Name == "ConsiderTextWrapOnObjPos" )
1254 17 : bConsiderWrapOnObjPos = true;
1255 1057 : else if ( pValues->Name == "IgnoreFirstLineIndentInNumbering" )
1256 17 : bIgnoreFirstLineIndentInNumbering = true;
1257 1040 : else if ( pValues->Name == "DoNotJustifyLinesWithManualBreak" )
1258 17 : bDoNotJustifyLinesWithManualBreak = true;
1259 1023 : else if ( pValues->Name == "DoNotResetParaAttrsForNumFont" )
1260 17 : bDoNotResetParaAttrsForNumFont = true;
1261 1006 : else if ( pValues->Name == "LoadReadonly" )
1262 17 : bLoadReadonly = true;
1263 989 : else if ( pValues->Name == "DoNotCaptureDrawObjsOnPage" )
1264 17 : bDoNotCaptureDrawObjsOnPage = true;
1265 972 : else if ( pValues->Name == "ClipAsCharacterAnchoredWriterFlyFrames" )
1266 17 : bClipAsCharacterAnchoredWriterFlyFrames = true;
1267 955 : else if ( pValues->Name == "UnxForceZeroExtLeading" )
1268 17 : bUnixForceZeroExtLeading = true;
1269 938 : else if ( pValues->Name == "UseOldPrinterMetrics" )
1270 17 : bUseOldPrinterMetrics = true;
1271 921 : else if ( pValues->Name == "SmallCapsPercentage66" )
1272 14 : bSmallCapsPercentage66 = true;
1273 907 : else if ( pValues->Name == "TabOverflow" )
1274 14 : bTabOverflow = true;
1275 893 : else if ( pValues->Name == "UnbreakableNumberings" )
1276 14 : bUnbreakableNumberings = true;
1277 879 : else if ( pValues->Name == "ClippedPictures" )
1278 5 : bClippedPictures = true;
1279 874 : else if ( pValues->Name == "BackgroundParaOverDrawings" )
1280 5 : bBackgroundParaOverDrawings = true;
1281 : }
1282 0 : catch( Exception& )
1283 : {
1284 : OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" );
1285 : }
1286 : }
1287 1212 : pValues++;
1288 : }
1289 :
1290 : try
1291 : {
1292 18 : if( currentDatabaseDataSource != NULL )
1293 18 : xProps->setPropertyValue( currentDatabaseDataSource->Name, currentDatabaseDataSource->Value );
1294 18 : if( currentDatabaseCommand != NULL )
1295 18 : xProps->setPropertyValue( currentDatabaseCommand->Name, currentDatabaseCommand->Value );
1296 18 : if( currentDatabaseCommandType != NULL )
1297 18 : xProps->setPropertyValue( currentDatabaseCommandType->Name, currentDatabaseCommandType->Value );
1298 0 : } catch( Exception& )
1299 : {
1300 : OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" );
1301 : }
1302 :
1303 : // finally, treat the non-default cases
1304 : // introduce boolean, that indicates a document, written by version prior SO8.
1305 18 : const bool bDocumentPriorSO8 = !bConsiderWrapOnObjPos;
1306 :
1307 18 : if( ! bPrinterIndependentLayout )
1308 : {
1309 0 : Any aAny;
1310 0 : sal_Int16 nTmp = document::PrinterIndependentLayout::DISABLED;
1311 0 : aAny <<= nTmp;
1312 0 : xProps->setPropertyValue(
1313 : OUString( RTL_CONSTASCII_USTRINGPARAM("PrinterIndependentLayout") ),
1314 0 : aAny );
1315 : }
1316 :
1317 18 : if( ! bAddExternalLeading )
1318 : {
1319 1 : xProps->setPropertyValue(
1320 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("AddExternalLeading")), makeAny( false ) );
1321 : }
1322 :
1323 18 : if( ! bUseFormerLineSpacing )
1324 : {
1325 1 : xProps->setPropertyValue(
1326 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerLineSpacing")), makeAny( true ) );
1327 : }
1328 :
1329 18 : if( !bUseFormerObjectPositioning )
1330 : {
1331 1 : xProps->setPropertyValue(
1332 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerObjectPositioning")), makeAny( true ) );
1333 : }
1334 :
1335 18 : if( !bUseOldNumbering )
1336 : {
1337 0 : Any aAny;
1338 0 : sal_Bool bOldNum = true;
1339 0 : aAny.setValue(&bOldNum, ::getBooleanCppuType());
1340 0 : xProps->setPropertyValue
1341 : (OUString( RTL_CONSTASCII_USTRINGPARAM("UseOldNumbering")),
1342 0 : aAny );
1343 : }
1344 :
1345 18 : if( !bOutlineLevelYieldsOutlineRule )
1346 : {
1347 1 : Any aAny;
1348 1 : sal_Bool bTmp = true;
1349 1 : aAny.setValue(&bTmp, ::getBooleanCppuType());
1350 1 : xProps->setPropertyValue
1351 : (OUString( RTL_CONSTASCII_USTRINGPARAM
1352 : ("OutlineLevelYieldsNumbering")),
1353 1 : aAny );
1354 : }
1355 :
1356 18 : if( !bAddParaSpacingToTableCells )
1357 : {
1358 1 : xProps->setPropertyValue(
1359 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("AddParaSpacingToTableCells")), makeAny( false ) );
1360 : }
1361 :
1362 18 : if( !bUseFormerTextWrapping )
1363 : {
1364 1 : xProps->setPropertyValue(
1365 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerTextWrapping")), makeAny( true ) );
1366 : }
1367 :
1368 18 : if( !bConsiderWrapOnObjPos )
1369 : {
1370 1 : xProps->setPropertyValue(
1371 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("ConsiderTextWrapOnObjPos")), makeAny( false ) );
1372 : }
1373 :
1374 : // #i47448#
1375 : // For SO7pp4, part of the 'new numbering' stuff has been backported from
1376 : // SO8. Unfortunately, only part of it and by using the same compatibility option
1377 : // like in SO8. Therefore documents generated with SO7pp4, containing
1378 : // numbered paragraphs with first line indent differ between SO7pp4 and
1379 : // SO8. In order to fix this for SO8pp1, I introduce a new compatiblity
1380 : // flag 'bIgnoreFirstLineIndentInNumbering'. This flag has to be set for all
1381 : // documents < SO8, but not for SO8. So if the property is not present, the
1382 : // flag will be set to 'true'. SO8 documents surely have the
1383 : // 'ConsiderWrapOnObjPos' property set (no matter if 'true' or 'false'),
1384 : // therefore the correct condition to set this flag is this:
1385 18 : if( !bIgnoreFirstLineIndentInNumbering && bDocumentPriorSO8 )
1386 : {
1387 1 : xProps->setPropertyValue(
1388 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("IgnoreFirstLineIndentInNumbering")), makeAny( true ) );
1389 : }
1390 :
1391 : // This flag has to be set for all documents < SO8
1392 18 : if ( !bDoNotJustifyLinesWithManualBreak && bDocumentPriorSO8 )
1393 : {
1394 1 : xProps->setPropertyValue(
1395 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotJustifyLinesWithManualBreak")), makeAny( true ) );
1396 : }
1397 :
1398 : // This flag has to be set for all documents < SO8
1399 18 : if ( !bDoNotResetParaAttrsForNumFont && bDocumentPriorSO8 )
1400 : {
1401 1 : xProps->setPropertyValue(
1402 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotResetParaAttrsForNumFont")), makeAny( true ) );
1403 : }
1404 :
1405 18 : if ( !bLoadReadonly )
1406 : {
1407 1 : xProps->setPropertyValue(
1408 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("LoadReadonly") ), makeAny( false ) );
1409 : }
1410 :
1411 : // This flag has to be set for all documents < SO8
1412 18 : if ( !bDoNotCaptureDrawObjsOnPage && bDocumentPriorSO8 )
1413 : {
1414 1 : xProps->setPropertyValue(
1415 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotCaptureDrawObjsOnPage") ), makeAny( true ) );
1416 : }
1417 :
1418 : // This flag has to be set for all documents < SO8
1419 18 : if ( !bClipAsCharacterAnchoredWriterFlyFrames && bDocumentPriorSO8 )
1420 : {
1421 1 : xProps->setPropertyValue(
1422 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("ClipAsCharacterAnchoredWriterFlyFrames") ), makeAny( true ) );
1423 : }
1424 :
1425 18 : if ( !bUnixForceZeroExtLeading )
1426 : {
1427 1 : xProps->setPropertyValue(
1428 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("UnxForceZeroExtLeading") ), makeAny( true ) );
1429 : }
1430 :
1431 18 : if ( !bUseOldPrinterMetrics )
1432 : {
1433 1 : xProps->setPropertyValue(
1434 1 : OUString( RTL_CONSTASCII_USTRINGPARAM("UseOldPrinterMetrics") ), makeAny( true ) );
1435 : }
1436 :
1437 : // Old LO versions had 66 as the value for small caps percentage, later changed to 80.
1438 : // In order to keep backwards compatibility, SmallCapsPercentage66 option is written to .odt
1439 : // files, and the default for new documents is 'false'. Files without this option
1440 : // are considered to be old files, so set the compatibility option too.
1441 18 : if ( !bSmallCapsPercentage66 )
1442 : {
1443 4 : xProps->setPropertyValue(
1444 4 : OUString( RTL_CONSTASCII_USTRINGPARAM("SmallCapsPercentage66") ), makeAny( true ) );
1445 : }
1446 :
1447 18 : if ( !bTabOverflow )
1448 : {
1449 4 : xProps->setPropertyValue(
1450 4 : OUString( RTL_CONSTASCII_USTRINGPARAM("TabOverflow") ), makeAny( false ) );
1451 : }
1452 :
1453 18 : if ( !bUnbreakableNumberings )
1454 : {
1455 4 : xProps->setPropertyValue(
1456 4 : OUString( RTL_CONSTASCII_USTRINGPARAM("UnbreakableNumberings") ), makeAny( false ) );
1457 : }
1458 :
1459 18 : if ( !bClippedPictures )
1460 : {
1461 13 : xProps->setPropertyValue(
1462 13 : OUString( RTL_CONSTASCII_USTRINGPARAM("ClippedPictures") ), makeAny( false ) );
1463 : }
1464 :
1465 18 : if ( !bBackgroundParaOverDrawings )
1466 13 : xProps->setPropertyValue("BackgroundParaOverDrawings", makeAny( false ) );
1467 :
1468 18 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
1469 18 : Reference < XText > xText = xTextDoc->getText();
1470 18 : Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
1471 : OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
1472 18 : if( xTextTunnel.is() )
1473 : {
1474 : SwXText *pText = reinterpret_cast< SwXText *>(
1475 18 : sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
1476 : OSL_ENSURE( pText, "SwXText missing" );
1477 18 : if( pText )
1478 : {
1479 18 : SwDoc *pDoc = pText->GetDoc();
1480 18 : if( pDoc )
1481 : {
1482 18 : SfxPrinter *pPrinter = pDoc->getPrinter( false );
1483 18 : if( pPrinter )
1484 : {
1485 : // If the printer is known, then the OLE objects will
1486 : // already have correct sizes, and we don't have to call
1487 : // PrtOLENotify again. Otherwise we have to call it.
1488 : // The flag might be set from setting the printer, so it
1489 : // it is required to clear it.
1490 2 : pDoc->SetOLEPrtNotifyPending( !pPrinter->IsKnown() );
1491 :
1492 : // old printer metrics compatibility
1493 4 : if ( pDoc->get(IDocumentSettingAccess::USE_OLD_PRINTER_METRICS ) &&
1494 2 : !pDoc->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
1495 : {
1496 2 : pPrinter->Compat_OldPrinterMetrics( true );
1497 2 : pDoc->GetDocShell()->UpdateFontList();
1498 : }
1499 : }
1500 : }
1501 : }
1502 18 : }
1503 : }
1504 :
1505 :
1506 0 : void SwXMLImport::SetDocumentSpecificSettings(
1507 : const ::rtl::OUString& _rSettingsGroupName,
1508 : const Sequence< PropertyValue>& _rSettings )
1509 : {
1510 : // the only doc-specific settings group we know so far are the XForms settings
1511 0 : if ( !IsXMLToken( _rSettingsGroupName, XML_XFORM_MODEL_SETTINGS ) )
1512 0 : return;
1513 :
1514 : // preserve the settings for a later iteration - we are currently reading the settings.xml,
1515 : // the content.xml will be read later, by another instance of SwXMLImport
1516 : OSL_ENSURE( xLateInitSettings.is(), "SwXMLImport::SetDocumentSpecificSettings: no storage for those settings!" );
1517 0 : if ( !xLateInitSettings.is() )
1518 0 : return;
1519 :
1520 : try
1521 : {
1522 0 : if ( xLateInitSettings->hasByName( _rSettingsGroupName ) )
1523 : {
1524 0 : xLateInitSettings->replaceByName( _rSettingsGroupName, makeAny( _rSettings ) );
1525 : OSL_FAIL( "SwXMLImport::SetDocumentSpecificSettings: already have settings for this model!" );
1526 : }
1527 : else
1528 0 : xLateInitSettings->insertByName( _rSettingsGroupName, makeAny( _rSettings ) );
1529 : }
1530 0 : catch( const Exception& )
1531 : {
1532 : DBG_UNHANDLED_EXCEPTION();
1533 : }
1534 : }
1535 :
1536 71 : void SwXMLImport::initialize(
1537 : const Sequence<Any>& aArguments )
1538 : throw( uno::Exception, uno::RuntimeException)
1539 : {
1540 : // delegate to super class
1541 71 : SvXMLImport::initialize(aArguments);
1542 :
1543 : // we are only looking for a PropertyValue "PreserveRedlineMode"
1544 71 : sal_Int32 nLength = aArguments.getLength();
1545 390 : for(sal_Int32 i = 0; i < nLength; i++)
1546 : {
1547 319 : beans::PropertyValue aValue;
1548 319 : if ( aArguments[i] >>= aValue )
1549 : {
1550 0 : if (aValue.Name.equalsAsciiL(
1551 0 : RTL_CONSTASCII_STRINGPARAM("PreserveRedlineMode")))
1552 : {
1553 0 : OSL_VERIFY( aValue.Value >>= bPreserveRedlineMode );
1554 : }
1555 0 : continue;
1556 : }
1557 :
1558 319 : beans::NamedValue aNamedValue;
1559 319 : if ( aArguments[i] >>= aNamedValue )
1560 : {
1561 53 : if (aNamedValue.Name.equalsAsciiL(
1562 53 : RTL_CONSTASCII_STRINGPARAM("LateInitSettings")))
1563 : {
1564 53 : OSL_VERIFY( aNamedValue.Value >>= xLateInitSettings );
1565 : }
1566 : }
1567 319 : }
1568 71 : }
1569 :
1570 :
1571 : //
1572 : // UNO component registration helper functions
1573 : //
1574 :
1575 33 : OUString SAL_CALL SwXMLImport_getImplementationName() throw()
1576 : {
1577 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
1578 33 : "com.sun.star.comp.Writer.XMLOasisImporter" ) );
1579 : }
1580 :
1581 0 : uno::Sequence< OUString > SAL_CALL SwXMLImport_getSupportedServiceNames()
1582 : throw()
1583 : {
1584 0 : const OUString aServiceName( SwXMLImport_getImplementationName() );
1585 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1586 0 : return aSeq;
1587 : }
1588 :
1589 0 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImport_createInstance(
1590 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1591 : throw( uno::Exception )
1592 : {
1593 0 : return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_ALL );
1594 : }
1595 :
1596 43 : OUString SAL_CALL SwXMLImportStyles_getImplementationName() throw()
1597 : {
1598 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
1599 43 : "com.sun.star.comp.Writer.XMLOasisStylesImporter" ) );
1600 : }
1601 :
1602 5 : uno::Sequence< OUString > SAL_CALL SwXMLImportStyles_getSupportedServiceNames()
1603 : throw()
1604 : {
1605 5 : const OUString aServiceName( SwXMLImportStyles_getImplementationName() );
1606 5 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1607 5 : return aSeq;
1608 : }
1609 :
1610 18 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImportStyles_createInstance(
1611 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1612 : throw( uno::Exception )
1613 : {
1614 : return (cppu::OWeakObject*)new SwXMLImport(
1615 : rSMgr,
1616 : IMPORT_STYLES | IMPORT_MASTERSTYLES | IMPORT_AUTOSTYLES |
1617 18 : IMPORT_FONTDECLS );
1618 : }
1619 :
1620 38 : OUString SAL_CALL SwXMLImportContent_getImplementationName() throw()
1621 : {
1622 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
1623 38 : "com.sun.star.comp.Writer.XMLOasisContentImporter" ) );
1624 : }
1625 :
1626 5 : uno::Sequence< OUString > SAL_CALL SwXMLImportContent_getSupportedServiceNames()
1627 : throw()
1628 : {
1629 5 : const OUString aServiceName( SwXMLImportContent_getImplementationName() );
1630 5 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1631 5 : return aSeq;
1632 : }
1633 :
1634 17 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImportContent_createInstance(
1635 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1636 : throw( uno::Exception )
1637 : {
1638 : return (cppu::OWeakObject*)new SwXMLImport(
1639 : rSMgr,
1640 : IMPORT_AUTOSTYLES | IMPORT_CONTENT | IMPORT_SCRIPTS |
1641 17 : IMPORT_FONTDECLS );
1642 : }
1643 :
1644 33 : OUString SAL_CALL SwXMLImportMeta_getImplementationName() throw()
1645 : {
1646 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
1647 33 : "com.sun.star.comp.Writer.XMLOasisMetaImporter" ) );
1648 : }
1649 :
1650 5 : uno::Sequence< OUString > SAL_CALL SwXMLImportMeta_getSupportedServiceNames()
1651 : throw()
1652 : {
1653 5 : const OUString aServiceName( SwXMLImportMeta_getImplementationName() );
1654 5 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1655 5 : return aSeq;
1656 : }
1657 :
1658 18 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImportMeta_createInstance(
1659 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1660 : throw( uno::Exception )
1661 : {
1662 18 : return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_META );
1663 : }
1664 :
1665 28 : OUString SAL_CALL SwXMLImportSettings_getImplementationName() throw()
1666 : {
1667 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
1668 28 : "com.sun.star.comp.Writer.XMLOasisSettingsImporter" ) );
1669 : }
1670 :
1671 5 : uno::Sequence< OUString > SAL_CALL SwXMLImportSettings_getSupportedServiceNames()
1672 : throw()
1673 : {
1674 5 : const OUString aServiceName( SwXMLImportSettings_getImplementationName() );
1675 5 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1676 5 : return aSeq;
1677 : }
1678 :
1679 18 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImportSettings_createInstance(
1680 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1681 : throw( uno::Exception )
1682 : {
1683 18 : return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_SETTINGS );
1684 : }
1685 :
1686 :
1687 : // XServiceInfo
1688 : // override empty method from parent class
1689 0 : OUString SAL_CALL SwXMLImport::getImplementationName()
1690 : throw(RuntimeException)
1691 : {
1692 0 : switch( getImportFlags() )
1693 : {
1694 : case IMPORT_ALL:
1695 0 : return SwXMLImport_getImplementationName();
1696 : case (IMPORT_STYLES|IMPORT_MASTERSTYLES|IMPORT_AUTOSTYLES|IMPORT_FONTDECLS):
1697 0 : return SwXMLImportStyles_getImplementationName();
1698 : case (IMPORT_AUTOSTYLES|IMPORT_CONTENT|IMPORT_SCRIPTS|IMPORT_FONTDECLS):
1699 0 : return SwXMLImportContent_getImplementationName();
1700 : case IMPORT_META:
1701 0 : return SwXMLImportMeta_getImplementationName();
1702 : case IMPORT_SETTINGS:
1703 0 : return SwXMLImportSettings_getImplementationName();
1704 : default:
1705 : // generic name for 'unknown' cases
1706 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
1707 0 : "com.sun.star.comp.Writer.SwXMLImport" ) );
1708 : }
1709 : }
1710 :
1711 153 : SwDoc* SwImport::GetDocFromXMLImport( SvXMLImport& rImport )
1712 : {
1713 153 : uno::Reference<lang::XUnoTunnel> xModelTunnel( rImport.GetModel(), uno::UNO_QUERY );
1714 : SwXTextDocument *pTxtDoc = reinterpret_cast< SwXTextDocument *>(
1715 153 : sal::static_int_cast< sal_IntPtr >( xModelTunnel->getSomething(SwXTextDocument::getUnoTunnelId() )));
1716 : OSL_ENSURE( pTxtDoc, "Where is my model?" );
1717 : OSL_ENSURE( pTxtDoc->GetDocShell(), "Where is my shell?" );
1718 153 : SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
1719 : OSL_ENSURE( pDoc, "Where is my document?" );
1720 153 : return pDoc;
1721 : }
1722 :
1723 :
1724 0 : void SwXMLImport::initXForms()
1725 : {
1726 : // obtain SwDoc
1727 0 : Reference<XUnoTunnel> xDocTunnel( GetModel(), UNO_QUERY );
1728 0 : if( ! xDocTunnel.is() )
1729 : return;
1730 : SwXTextDocument* pXTextDocument = reinterpret_cast<SwXTextDocument*>(
1731 0 : xDocTunnel->getSomething( SwXTextDocument::getUnoTunnelId() ) );
1732 0 : if( pXTextDocument == NULL )
1733 : return;
1734 :
1735 0 : SwDoc *pDoc = pXTextDocument->GetDocShell()->GetDoc();
1736 :
1737 : // init XForms (if not already done)
1738 : // (no default model, since we'll load the models)
1739 0 : if( ! pDoc->isXForms() )
1740 0 : pDoc->initXForms( false );
1741 :
1742 0 : bInititedXForms = sal_True;
1743 : }
1744 :
1745 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|