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 : #include <libxml/xmlwriter.h>
21 :
22 : #include "PageListWatcher.hxx"
23 : #include <com/sun/star/text/WritingMode.hpp>
24 : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
25 : #include <com/sun/star/i18n/ScriptType.hpp>
26 : #include <editeng/forbiddencharacterstable.hxx>
27 :
28 : #include <svx/svxids.hrc>
29 : #include <svl/srchitem.hxx>
30 : #include <editeng/eeitem.hxx>
31 : #include <editeng/scriptspaceitem.hxx>
32 :
33 : #include <unotools/useroptions.hxx>
34 : #include <officecfg/Office/Impress.hxx>
35 :
36 : #include <sfx2/printer.hxx>
37 : #include <sfx2/app.hxx>
38 : #include <sfx2/linkmgr.hxx>
39 : #include <svx/dialogs.hrc>
40 : #include "Outliner.hxx"
41 : #include "sdmod.hxx"
42 : #include <editeng/editstat.hxx>
43 : #include <editeng/fontitem.hxx>
44 : #include <svl/flagitem.hxx>
45 : #include <svx/svdoattr.hxx>
46 : #include <svx/svdotext.hxx>
47 : #include <editeng/bulletitem.hxx>
48 : #include <editeng/numitem.hxx>
49 : #include <svx/svditer.hxx>
50 : #include <editeng/unolingu.hxx>
51 : #include <svl/itempool.hxx>
52 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 : #include <svx/xtable.hxx>
54 : #include <com/sun/star/linguistic2/XHyphenator.hpp>
55 : #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
56 : #include <com/sun/star/beans/XPropertySet.hpp>
57 : #include <editeng/outlobj.hxx>
58 : #include <unotools/saveopt.hxx>
59 : #include <comphelper/extract.hxx>
60 : #include <comphelper/getexpandeduri.hxx>
61 : #include <i18nlangtag/mslangid.hxx>
62 : #include <i18nlangtag/languagetag.hxx>
63 : #include <unotools/charclass.hxx>
64 : #include <comphelper/processfactory.hxx>
65 : #include <unotools/pathoptions.hxx>
66 : #include <unotools/lingucfg.hxx>
67 : #include <unotools/linguprops.hxx>
68 : #include <com/sun/star/uno/Reference.hxx>
69 : #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
70 : #include <com/sun/star/xml/dom/XDocument.hpp>
71 : #include <com/sun/star/xml/dom/XNode.hpp>
72 : #include <com/sun/star/xml/dom/XNodeList.hpp>
73 : #include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
74 : #include <com/sun/star/xml/dom/DocumentBuilder.hpp>
75 : #include <com/sun/star/uno/XComponentContext.hpp>
76 : #include <rtl/ustring.hxx>
77 : #include <rtl/uri.hxx>
78 :
79 : #include <editeng/outliner.hxx>
80 : #include "drawdoc.hxx"
81 : #include "sdpage.hxx"
82 : #include "pglink.hxx"
83 : #include "sdattr.hxx"
84 : #include "glob.hrc"
85 : #include "glob.hxx"
86 : #include "stlpool.hxx"
87 : #include "sdiocmpt.hxx"
88 : #include "sdresid.hxx"
89 : #include "cusshow.hxx"
90 : #include "customshowlist.hxx"
91 : #include "../ui/inc/DrawDocShell.hxx"
92 : #include "../ui/inc/GraphicDocShell.hxx"
93 : #include "../ui/inc/sdxfer.hxx"
94 : #include "../ui/inc/ViewShell.hxx"
95 : #include "../ui/inc/optsitem.hxx"
96 : #include "../ui/inc/FrameView.hxx"
97 :
98 : #include <tools/tenccvt.hxx>
99 : #include <vcl/settings.hxx>
100 :
101 : using namespace ::sd;
102 : using namespace ::com::sun::star;
103 : using namespace ::com::sun::star::uno;
104 : using namespace ::com::sun::star::lang;
105 : using namespace ::com::sun::star::linguistic2;
106 :
107 : using namespace com::sun::star::xml::dom;
108 : using ::com::sun::star::uno::Reference;
109 : using ::com::sun::star::lang::XMultiServiceFactory;
110 : using ::com::sun::star::beans::PropertyValue;
111 :
112 1656 : TYPEINIT1( SdDrawDocument, FmFormModel );
113 :
114 : SdDrawDocument* SdDrawDocument::pDocLockedInsertingLinks = NULL;
115 :
116 320 : PresentationSettings::PresentationSettings()
117 : : mbAll( true ),
118 : mbEndless( false ),
119 : mbCustomShow(false),
120 : mbManual( false ),
121 : mbMouseVisible( false ),
122 : mbMouseAsPen( false ),
123 : mbLockedPages( false ),
124 : mbAlwaysOnTop( false ),
125 : mbFullScreen( true ),
126 : mbAnimationAllowed( true ),
127 : mnPauseTimeout( 10 ),
128 : mbShowPauseLogo( false ),
129 320 : mbStartWithNavigator(false)
130 : {
131 320 : }
132 :
133 0 : PresentationSettings::PresentationSettings( const PresentationSettings& r )
134 : : maPresPage( r.maPresPage ),
135 : mbAll( r.mbAll ),
136 : mbEndless( r.mbEndless ),
137 : mbCustomShow( r.mbCustomShow ),
138 : mbManual( r.mbManual ),
139 : mbMouseVisible( r.mbMouseVisible ),
140 : mbMouseAsPen( r.mbMouseAsPen ),
141 : mbLockedPages( r.mbLockedPages ),
142 : mbAlwaysOnTop( r.mbAlwaysOnTop ),
143 : mbFullScreen( r.mbFullScreen ),
144 : mbAnimationAllowed( r.mbAnimationAllowed ),
145 : mnPauseTimeout( r.mnPauseTimeout ),
146 : mbShowPauseLogo( r.mbShowPauseLogo ),
147 0 : mbStartWithNavigator( r.mbStartWithNavigator )
148 : {
149 0 : }
150 :
151 320 : SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh)
152 640 : : FmFormModel( SvtPathOptions().GetPalettePath(), NULL, pDrDocSh )
153 : , bReadOnly(false)
154 : , mpOutliner(NULL)
155 : , mpInternalOutliner(NULL)
156 : , mpWorkStartupTimer(NULL)
157 : , mpOnlineSpellingIdle(NULL)
158 : , mpOnlineSpellingList(NULL)
159 : , mpOnlineSearchItem(NULL)
160 : , mpCustomShowList(NULL)
161 : , mpDocSh(static_cast< ::sd::DrawDocShell*>(pDrDocSh))
162 : , mpCreatingTransferable( NULL )
163 : , mbHasOnlineSpellErrors(false)
164 : , mbInitialOnlineSpellingEnabled(true)
165 : , mbNewOrLoadCompleted(false)
166 : , mbStartWithPresentation( false )
167 : , mbExitAfterPresenting( false )
168 : , meLanguage( LANGUAGE_SYSTEM )
169 : , meLanguageCJK( LANGUAGE_SYSTEM )
170 : , meLanguageCTL( LANGUAGE_SYSTEM )
171 : , mePageNumType(SVX_ARABIC)
172 : , mbAllocDocSh(false)
173 : , meDocType(eType)
174 : , mpCharClass(NULL)
175 : , mpLocale(NULL)
176 640 : , mbUseEmbedFonts(false)
177 : {
178 320 : mpDrawPageListWatcher.reset(new ImpDrawPageListWatcher(*this));
179 320 : mpMasterPageListWatcher.reset(new ImpMasterPageListWatcher(*this));
180 :
181 320 : InitLayoutVector();
182 320 : InitObjectVector();
183 320 : SetObjectShell(pDrDocSh); // for VCDrawModel
184 :
185 320 : if (mpDocSh)
186 : {
187 318 : SetSwapGraphics(true);
188 : }
189 :
190 : // Set measuring unit (of the application) and scale (of SdMod)
191 : sal_Int32 nX, nY;
192 320 : SdOptions* pOptions = SD_MOD()->GetSdOptions(meDocType);
193 320 : pOptions->GetScale( nX, nY );
194 :
195 : // Allow UI scale only for draw documents.
196 320 : if( eType == DOCUMENT_TYPE_DRAW )
197 92 : SetUIUnit( (FieldUnit)pOptions->GetMetric(), Fraction( nX, nY ) ); // user-defined
198 : else
199 228 : SetUIUnit( (FieldUnit)pOptions->GetMetric(), Fraction( 1, 1 ) ); // default
200 :
201 320 : SetScaleUnit(MAP_100TH_MM);
202 320 : SetScaleFraction(Fraction(1, 1));
203 320 : SetDefaultFontHeight(847); // 24p
204 :
205 320 : pItemPool->SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
206 320 : pItemPool->FreezeIdRanges();
207 320 : SetTextDefaults();
208 :
209 : // DrawingEngine has to know where it is...
210 320 : FmFormModel::SetStyleSheetPool( new SdStyleSheetPool( GetPool(), this ) );
211 :
212 : // Set StyleSheetPool for DrawOutliner, so text objects can be read correctly.
213 : // The link to the StyleRequest handler of the document is set later, in
214 : // NewOrLoadCompleted, because only then do all the templates exist.
215 320 : SdrOutliner& rOutliner = GetDrawOutliner();
216 320 : rOutliner.SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
217 320 : SetCalcFieldValueHdl( &rOutliner );
218 :
219 : // set linguistic options
220 : {
221 320 : const SvtLinguConfig aLinguConfig;
222 640 : SvtLinguOptions aOptions;
223 320 : aLinguConfig.GetOptions( aOptions );
224 :
225 : SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage,
226 320 : ::com::sun::star::i18n::ScriptType::LATIN), EE_CHAR_LANGUAGE );
227 : SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CJK,
228 320 : ::com::sun::star::i18n::ScriptType::ASIAN), EE_CHAR_LANGUAGE_CJK );
229 : SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CTL,
230 320 : ::com::sun::star::i18n::ScriptType::COMPLEX), EE_CHAR_LANGUAGE_CTL );
231 :
232 640 : mbOnlineSpell = aOptions.bIsSpellAuto;
233 : }
234 :
235 320 : LanguageType eRealLanguage = MsLangId::getRealLanguage( meLanguage );
236 320 : LanguageTag aLanguageTag( eRealLanguage);
237 320 : mpLocale = new ::com::sun::star::lang::Locale( aLanguageTag.getLocale());
238 320 : mpCharClass = new CharClass( aLanguageTag );
239 :
240 : // If the current application language is a language that uses right-to-left text...
241 320 : LanguageType eRealCTLLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
242 320 : if( MsLangId::isRightToLeft( eRealCTLLanguage ) )
243 : {
244 : // ... then we have to set this as a default
245 0 : SetDefaultWritingMode( ::com::sun::star::text::WritingMode_RL_TB );
246 : }
247 :
248 : // for korean and japanese languages we have a different default for apply spacing between asian, latin and ctl text
249 320 : if (MsLangId::isKorean(eRealCTLLanguage) || (LANGUAGE_JAPANESE == eRealCTLLanguage))
250 : {
251 0 : GetPool().GetSecondaryPool()->SetPoolDefaultItem( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
252 : }
253 :
254 : // Set DefTab and SpellOptions for the SD module
255 320 : sal_uInt16 nDefTab = pOptions->GetDefTab();
256 320 : SetDefaultTabulator( nDefTab );
257 :
258 : try
259 : {
260 320 : Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
261 320 : if ( xSpellChecker.is() )
262 320 : rOutliner.SetSpeller( xSpellChecker );
263 :
264 640 : Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
265 320 : if( xHyphenator.is() )
266 320 : rOutliner.SetHyphenator( xHyphenator );
267 :
268 640 : SetForbiddenCharsTable( new SvxForbiddenCharactersTable( ::comphelper::getProcessComponentContext() ) );
269 : }
270 0 : catch(...)
271 : {
272 : OSL_FAIL("Can't get SpellChecker");
273 : }
274 :
275 320 : rOutliner.SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
276 :
277 320 : if (mpDocSh)
278 : {
279 318 : SetLinkManager( new sfx2::LinkManager(mpDocSh) );
280 : }
281 :
282 320 : EEControlBits nCntrl = rOutliner.GetControlWord();
283 320 : nCntrl |= EEControlBits::ALLOWBIGOBJS;
284 :
285 320 : if (mbOnlineSpell)
286 320 : nCntrl |= EEControlBits::ONLINESPELLING;
287 : else
288 0 : nCntrl &= ~EEControlBits::ONLINESPELLING;
289 :
290 320 : nCntrl &= ~ EEControlBits::ULSPACESUMMATION;
291 320 : if ( meDocType != DOCUMENT_TYPE_IMPRESS )
292 92 : SetSummationOfParagraphs( false );
293 : else
294 : {
295 228 : SetSummationOfParagraphs( pOptions->IsSummationOfParagraphs() );
296 228 : if ( pOptions->IsSummationOfParagraphs() )
297 0 : nCntrl |= EEControlBits::ULSPACESUMMATION;
298 : }
299 320 : rOutliner.SetControlWord(nCntrl);
300 :
301 : // Initialize the printer independent layout mode
302 320 : SetPrinterIndependentLayout (pOptions->GetPrinterIndependentLayout());
303 :
304 : // Set the StyleSheetPool for HitTestOutliner.
305 : // The link to the StyleRequest handler of the document is set later, in
306 : // NewOrLoadCompleted, because only then do all the templates exist.
307 640 : SfxItemSet aSet2( pHitTestOutliner->GetEmptyItemSet() );
308 320 : pHitTestOutliner->SetStyleSheetPool( static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()) );
309 :
310 320 : SetCalcFieldValueHdl( pHitTestOutliner );
311 :
312 : try
313 : {
314 320 : Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
315 320 : if ( xSpellChecker.is() )
316 320 : pHitTestOutliner->SetSpeller( xSpellChecker );
317 :
318 640 : Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
319 320 : if( xHyphenator.is() )
320 640 : pHitTestOutliner->SetHyphenator( xHyphenator );
321 : }
322 0 : catch(...)
323 : {
324 : OSL_FAIL("Can't get SpellChecker");
325 : }
326 :
327 320 : pHitTestOutliner->SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
328 :
329 320 : EEControlBits nCntrl2 = pHitTestOutliner->GetControlWord();
330 320 : nCntrl2 |= EEControlBits::ALLOWBIGOBJS;
331 320 : nCntrl2 &= ~EEControlBits::ONLINESPELLING;
332 :
333 320 : nCntrl2 &= ~ EEControlBits::ULSPACESUMMATION;
334 320 : if ( pOptions->IsSummationOfParagraphs() )
335 0 : nCntrl2 |= EEControlBits::ULSPACESUMMATION;
336 :
337 320 : pHitTestOutliner->SetControlWord( nCntrl2 );
338 :
339 : /** Create layers
340 : *
341 : * We create the following default layers on all pages and master pages:
342 : *
343 : * STR_LAYOUT : default layer for drawing objects
344 : *
345 : * STR_BCKGRND : background of the master page
346 : * (currently unused within normal pages)
347 : *
348 : * STR_BCKGRNDOBJ: objects on the background of master pages
349 : * (currently unused within normal pages)
350 : *
351 : * STR_CONTROLS : default layer for controls
352 : */
353 :
354 : {
355 320 : OUString aControlLayerName( SD_RESSTR(STR_LAYER_CONTROLS) );
356 :
357 320 : SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
358 320 : rLayerAdmin.NewLayer( SD_RESSTR(STR_LAYER_LAYOUT) );
359 320 : rLayerAdmin.NewLayer( SD_RESSTR(STR_LAYER_BCKGRND) );
360 320 : rLayerAdmin.NewLayer( SD_RESSTR(STR_LAYER_BCKGRNDOBJ) );
361 320 : rLayerAdmin.NewLayer( aControlLayerName );
362 320 : rLayerAdmin.NewLayer( SD_RESSTR(STR_LAYER_MEASURELINES) );
363 :
364 320 : rLayerAdmin.SetControlLayerName(aControlLayerName);
365 320 : }
366 :
367 320 : }
368 :
369 : // Destructor
370 945 : SdDrawDocument::~SdDrawDocument()
371 : {
372 315 : Broadcast(SdrHint(HINT_MODELCLEARED));
373 :
374 315 : if (mpWorkStartupTimer)
375 : {
376 0 : if ( mpWorkStartupTimer->IsActive() )
377 0 : mpWorkStartupTimer->Stop();
378 :
379 0 : delete mpWorkStartupTimer;
380 0 : mpWorkStartupTimer = NULL;
381 : }
382 :
383 315 : StopOnlineSpelling();
384 315 : delete mpOnlineSearchItem;
385 315 : mpOnlineSearchItem = NULL;
386 :
387 315 : CloseBookmarkDoc();
388 315 : SetAllocDocSh(false);
389 :
390 315 : ClearModel(true);
391 :
392 315 : if (pLinkManager)
393 : {
394 : // Release BaseLinks
395 313 : if ( !pLinkManager->GetLinks().empty() )
396 : {
397 0 : pLinkManager->Remove( 0, pLinkManager->GetLinks().size() );
398 : }
399 :
400 313 : delete pLinkManager;
401 313 : pLinkManager = NULL;
402 : }
403 :
404 315 : std::vector<sd::FrameView*>::iterator pIter;
405 357 : for ( pIter = maFrameViewList.begin(); pIter != maFrameViewList.end(); ++pIter )
406 42 : delete *pIter;
407 :
408 315 : if (mpCustomShowList)
409 : {
410 6 : for (sal_uLong j = 0; j < mpCustomShowList->size(); j++)
411 : {
412 : // If necessary, delete CustomShows
413 3 : SdCustomShow* pCustomShow = (*mpCustomShowList)[j];
414 3 : delete pCustomShow;
415 : }
416 :
417 3 : delete mpCustomShowList;
418 3 : mpCustomShowList = NULL;
419 : }
420 :
421 315 : delete mpOutliner;
422 315 : mpOutliner = NULL;
423 :
424 315 : delete mpInternalOutliner;
425 315 : mpInternalOutliner = NULL;
426 :
427 315 : delete mpLocale;
428 315 : mpLocale = NULL;
429 :
430 315 : delete mpCharClass;
431 315 : mpCharClass = NULL;
432 630 : }
433 :
434 0 : SdrModel* SdDrawDocument::AllocModel() const
435 : {
436 0 : return AllocSdDrawDocument();
437 : }
438 :
439 : // This method creates a new document (SdDrawDocument) and returns a pointer to
440 : // said document. The drawing engine uses this method to put the document (or
441 : // parts of it) into the clipboard/DragServer.
442 0 : SdDrawDocument* SdDrawDocument::AllocSdDrawDocument() const
443 : {
444 0 : SdDrawDocument* pNewModel = NULL;
445 :
446 0 : if( mpCreatingTransferable )
447 : {
448 : // Document is created for drag & drop/clipboard. To be able to
449 : // do this, the document has to know a DocShell (SvPersist).
450 0 : SfxObjectShell* pObj = NULL;
451 0 : ::sd::DrawDocShell* pNewDocSh = NULL;
452 :
453 0 : if( meDocType == DOCUMENT_TYPE_IMPRESS )
454 : mpCreatingTransferable->SetDocShell( new ::sd::DrawDocShell(
455 0 : SfxObjectCreateMode::EMBEDDED, true, meDocType ) );
456 : else
457 : mpCreatingTransferable->SetDocShell( new ::sd::GraphicDocShell(
458 0 : SfxObjectCreateMode::EMBEDDED, true, meDocType ) );
459 :
460 0 : pNewDocSh = static_cast< ::sd::DrawDocShell*>( pObj = mpCreatingTransferable->GetDocShell() );
461 0 : pNewDocSh->DoInitNew( NULL );
462 0 : pNewModel = pNewDocSh->GetDoc();
463 :
464 : // Only necessary for clipboard -
465 : // for drag & drop this is handled by DragServer
466 0 : SdStyleSheetPool* pOldStylePool = static_cast<SdStyleSheetPool*>( GetStyleSheetPool() );
467 0 : SdStyleSheetPool* pNewStylePool = static_cast<SdStyleSheetPool*>( pNewModel->GetStyleSheetPool() );
468 :
469 0 : pNewStylePool->CopyGraphicSheets(*pOldStylePool);
470 0 : pNewStylePool->CopyCellSheets(*pOldStylePool);
471 0 : pNewStylePool->CopyTableStyles(*pOldStylePool);
472 :
473 0 : for (sal_uInt16 i = 0; i < GetMasterSdPageCount(PK_STANDARD); i++)
474 : {
475 : // Move with all of the master page's layouts
476 0 : OUString aOldLayoutName(const_cast<SdDrawDocument*>(this)->GetMasterSdPage(i, PK_STANDARD)->GetLayoutName());
477 0 : aOldLayoutName = aOldLayoutName.copy( 0, aOldLayoutName.indexOf( SD_LT_SEPARATOR ) );
478 0 : SdStyleSheetVector aCreatedSheets;
479 0 : pNewStylePool->CopyLayoutSheets(aOldLayoutName, *pOldStylePool, aCreatedSheets );
480 0 : }
481 :
482 0 : pNewModel->NewOrLoadCompleted( DOC_LOADED ); // loaded from source document
483 : }
484 0 : else if( mbAllocDocSh )
485 : {
486 : // Create a DocShell which is then returned with GetAllocedDocSh()
487 0 : SdDrawDocument* pDoc = const_cast<SdDrawDocument*>(this);
488 0 : pDoc->SetAllocDocSh(false);
489 0 : pDoc->mxAllocedDocShRef = new ::sd::DrawDocShell(
490 0 : SfxObjectCreateMode::EMBEDDED, true, meDocType);
491 0 : pDoc->mxAllocedDocShRef->DoInitNew(NULL);
492 0 : pNewModel = pDoc->mxAllocedDocShRef->GetDoc();
493 : }
494 : else
495 : {
496 0 : pNewModel = new SdDrawDocument(meDocType, NULL);
497 : }
498 :
499 0 : return pNewModel;
500 : }
501 :
502 2358 : SdPage* SdDrawDocument::AllocSdPage(bool bMasterPage)
503 : {
504 2358 : return new SdPage(*this, bMasterPage);
505 : }
506 :
507 : // This method creates a new page (SdPage) and returns a pointer to said page.
508 : // The drawing engine uses this method to create pages (whose types it does
509 : // not know, as they are _derivatives_ of SdrPage) when loading.
510 136 : SdrPage* SdDrawDocument::AllocPage(bool bMasterPage)
511 : {
512 136 : return AllocSdPage(bMasterPage);
513 : }
514 :
515 : // When the model has changed
516 305697 : void SdDrawDocument::SetChanged(bool bFlag)
517 : {
518 305697 : if (mpDocSh)
519 : {
520 305677 : if (mbNewOrLoadCompleted && mpDocSh->IsEnableSetModified())
521 : {
522 : // Pass on to base class
523 45865 : FmFormModel::SetChanged(bFlag);
524 :
525 : // Forward to ObjectShell
526 45865 : mpDocSh->SetModified(bFlag);
527 : }
528 : }
529 : else
530 : {
531 : // Pass on to base class
532 20 : FmFormModel::SetChanged(bFlag);
533 : }
534 305697 : }
535 :
536 : // The model changed, don't call anything else
537 46489 : void SdDrawDocument::NbcSetChanged(bool bFlag)
538 : {
539 : // forward to baseclass
540 46489 : FmFormModel::SetChanged(bFlag);
541 46489 : }
542 :
543 : // NewOrLoadCompleted is called when the document is loaded, or when it is clear
544 : // it won't load any more.
545 255 : void SdDrawDocument::NewOrLoadCompleted(DocCreationMode eMode)
546 : {
547 255 : if (eMode == NEW_DOC)
548 : {
549 : // New document:
550 : // create slideshow and default templates,
551 : // create pool for virtual controls
552 255 : CreateLayoutTemplates();
553 255 : CreateDefaultCellStyles();
554 :
555 255 : static_cast< SdStyleSheetPool* >( mxStyleSheetPool.get() )->CreatePseudosIfNecessary();
556 : }
557 0 : else if (eMode == DOC_LOADED)
558 : {
559 : // Document has finished loading
560 :
561 0 : CheckMasterPages();
562 :
563 0 : if ( GetMasterSdPageCount(PK_STANDARD) > 1 )
564 0 : RemoveUnnecessaryMasterPages( NULL, true, false );
565 :
566 0 : for ( sal_uInt16 i = 0; i < GetPageCount(); i++ )
567 : {
568 : // Check for correct layout names
569 0 : SdPage* pPage = static_cast<SdPage*>( GetPage( i ) );
570 :
571 0 : if(pPage->TRG_HasMasterPage())
572 : {
573 0 : SdPage& rMaster = static_cast<SdPage&>(pPage->TRG_GetMasterPage() );
574 :
575 0 : if(rMaster.GetLayoutName() != pPage->GetLayoutName())
576 : {
577 0 : pPage->SetLayoutName(rMaster.GetLayoutName());
578 : }
579 : }
580 : }
581 :
582 0 : for ( sal_uInt16 nPage = 0; nPage < GetMasterPageCount(); nPage++)
583 : {
584 : // LayoutName and PageName must be the same
585 0 : SdPage* pPage = static_cast<SdPage*>( GetMasterPage( nPage ) );
586 :
587 0 : OUString aName( pPage->GetLayoutName() );
588 0 : aName = aName.copy( 0, aName.indexOf( SD_LT_SEPARATOR ) );
589 :
590 0 : if( aName != pPage->GetName() )
591 0 : pPage->SetName( aName );
592 0 : }
593 :
594 : // Create names of the default layers in the user's language
595 0 : RestoreLayerNames();
596 :
597 : // Create names of the styles in the user's language
598 0 : static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->UpdateStdNames();
599 :
600 : // Create any missing styles - eg. formerly, there was no Subtitle style
601 0 : static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->CreatePseudosIfNecessary();
602 : }
603 :
604 : // Set default style of Drawing Engine
605 255 : OUString aName( SD_RESSTR(STR_STANDARD_STYLESHEET_NAME));
606 255 : SetDefaultStyleSheet(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(aName, SD_STYLE_FAMILY_GRAPHICS)));
607 :
608 : // #i119287# Set default StyleSheet for SdrGrafObj and SdrOle2Obj
609 255 : SetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(SD_RESSTR(STR_POOLSHEET_OBJNOLINENOFILL), SD_STYLE_FAMILY_GRAPHICS)));
610 :
611 : // Initialize DrawOutliner and DocumentOutliner, but don't initialize the
612 : // global outliner, as it is not document specific like StyleSheetPool and
613 : // StyleRequestHandler are.
614 255 : ::Outliner& rDrawOutliner = GetDrawOutliner();
615 255 : rDrawOutliner.SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
616 255 : EEControlBits nCntrl = rDrawOutliner.GetControlWord();
617 255 : if (mbOnlineSpell)
618 255 : nCntrl |= EEControlBits::ONLINESPELLING;
619 : else
620 0 : nCntrl &= ~EEControlBits::ONLINESPELLING;
621 255 : rDrawOutliner.SetControlWord(nCntrl);
622 :
623 : // Initialize HitTestOutliner and DocumentOutliner, but don't initialize the
624 : // global outliner, as it is not document specific like StyleSheetPool and
625 : // StyleRequestHandler are.
626 255 : pHitTestOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
627 :
628 255 : if(mpOutliner)
629 : {
630 0 : mpOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
631 : }
632 255 : if(mpInternalOutliner)
633 : {
634 3 : mpInternalOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
635 : }
636 :
637 255 : if ( eMode == DOC_LOADED )
638 : {
639 : // Make presentation objects listeners of the appropriate styles
640 0 : SdStyleSheetPool* pSPool = static_cast<SdStyleSheetPool*>( GetStyleSheetPool() );
641 : sal_uInt16 nPage, nPageCount;
642 :
643 : // create missing layout style sheets for broken documents
644 : // that where created with the 5.2
645 0 : nPageCount = GetMasterSdPageCount( PK_STANDARD );
646 0 : for (nPage = 0; nPage < nPageCount; nPage++)
647 : {
648 0 : SdPage* pPage = GetMasterSdPage(nPage, PK_STANDARD);
649 0 : pSPool->CreateLayoutStyleSheets( pPage->GetName(), true );
650 : }
651 :
652 : // Default and notes pages:
653 0 : for (nPage = 0; nPage < GetPageCount(); nPage++)
654 : {
655 0 : SdPage* pPage = static_cast<SdPage*>(GetPage(nPage));
656 0 : NewOrLoadCompleted( pPage, pSPool );
657 : }
658 :
659 : // Master pages:
660 0 : for (nPage = 0; nPage < GetMasterPageCount(); nPage++)
661 : {
662 0 : SdPage* pPage = static_cast<SdPage*>(GetMasterPage(nPage));
663 :
664 0 : NewOrLoadCompleted( pPage, pSPool );
665 : }
666 : }
667 :
668 255 : mbNewOrLoadCompleted = true;
669 :
670 : // Update all linked pages
671 255 : sal_uInt16 nMaxSdPages = GetSdPageCount(PK_STANDARD);
672 :
673 258 : for (sal_uInt16 nSdPage=0; nSdPage < nMaxSdPages; nSdPage++)
674 : {
675 3 : SdPage* pPage = GetSdPage(nSdPage, PK_STANDARD);
676 :
677 3 : if (pPage && !pPage->GetFileName().isEmpty() && pPage->GetBookmarkName().getLength())
678 : {
679 0 : pPage->SetModel(this);
680 : }
681 : }
682 :
683 255 : UpdateAllLinks();
684 :
685 255 : SetChanged( false );
686 255 : }
687 :
688 : /** updates all links, only links in this document should by resolved */
689 299 : void SdDrawDocument::UpdateAllLinks()
690 : {
691 299 : if ( !pDocLockedInsertingLinks && pLinkManager && !pLinkManager->GetLinks().empty() )
692 : {
693 3 : pDocLockedInsertingLinks = this; // lock inserting links. only links in this document should by resolved
694 :
695 3 : pLinkManager->UpdateAllLinks(); // query box: update all links?
696 :
697 3 : if( pDocLockedInsertingLinks == this )
698 3 : pDocLockedInsertingLinks = NULL; // unlock inserting links
699 : }
700 299 : }
701 :
702 : /** this loops over the presentation objects of a page and repairs some new settings
703 : from old binary files and resets all default strings for empty presentation objects.
704 : */
705 0 : void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool )
706 : {
707 0 : sd::ShapeList& rPresentationShapes( pPage->GetPresentationShapeList() );
708 0 : if(!rPresentationShapes.isEmpty())
709 : {
710 : // Create lists of title and outline styles
711 0 : OUString aName = pPage->GetLayoutName();
712 0 : aName = aName.copy( 0, aName.indexOf( SD_LT_SEPARATOR ) );
713 :
714 0 : std::vector<SfxStyleSheetBase*> aOutlineList;
715 0 : pSPool->CreateOutlineSheetList(aName,aOutlineList);
716 :
717 0 : SfxStyleSheet* pTitleSheet = static_cast<SfxStyleSheet*>(pSPool->GetTitleSheet(aName));
718 :
719 0 : SdrObject* pObj = 0;
720 0 : rPresentationShapes.seekShape(0);
721 :
722 : // Now look for title and outline text objects, then make those objects
723 : // listeners.
724 0 : while( (pObj = rPresentationShapes.getNextShape()) )
725 : {
726 0 : if (pObj->GetObjInventor() == SdrInventor)
727 : {
728 0 : OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
729 0 : sal_uInt16 nId = pObj->GetObjIdentifier();
730 :
731 0 : if (nId == OBJ_TITLETEXT)
732 : {
733 0 : if( pOPO && pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
734 0 : pOPO->SetOutlinerMode( OUTLINERMODE_TITLEOBJECT );
735 :
736 : // sal_True: don't delete "hard" attributes when doing this.
737 0 : if (pTitleSheet)
738 0 : pObj->SetStyleSheet(pTitleSheet, true);
739 : }
740 0 : else if (nId == OBJ_OUTLINETEXT)
741 : {
742 0 : if( pOPO && pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
743 0 : pOPO->SetOutlinerMode( OUTLINERMODE_OUTLINEOBJECT );
744 :
745 0 : std::vector<SfxStyleSheetBase*>::iterator iter;
746 0 : for (iter = aOutlineList.begin(); iter != aOutlineList.end(); ++iter)
747 : {
748 0 : SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(*iter);
749 :
750 0 : if (pSheet)
751 : {
752 0 : pObj->StartListening(*pSheet);
753 :
754 0 : if( iter == aOutlineList.begin())
755 : // text frame listens to stylesheet of layer 1
756 0 : pObj->NbcSetStyleSheet(pSheet, true);
757 : }
758 : }
759 : }
760 :
761 0 : if (pObj->ISA(SdrTextObj) && pObj->IsEmptyPresObj())
762 : {
763 0 : PresObjKind ePresObjKind = pPage->GetPresObjKind(pObj);
764 0 : OUString aString( pPage->GetPresObjText(ePresObjKind) );
765 :
766 0 : if (!aString.isEmpty())
767 : {
768 0 : sd::Outliner* pInternalOutl = GetInternalOutliner(true);
769 0 : pPage->SetObjText( static_cast<SdrTextObj*>(pObj), pInternalOutl, ePresObjKind, aString );
770 0 : pObj->NbcSetStyleSheet( pPage->GetStyleSheetForPresObj( ePresObjKind ), true );
771 0 : pInternalOutl->Clear();
772 0 : }
773 : }
774 : }
775 0 : }
776 : }
777 0 : }
778 :
779 : // Local outliner that is used for outline mode. In this outliner, OutlinerViews
780 : // may be inserted.
781 508 : ::sd::Outliner* SdDrawDocument::GetOutliner(bool bCreateOutliner)
782 : {
783 508 : if (!mpOutliner && bCreateOutliner)
784 : {
785 0 : mpOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
786 :
787 0 : if (mpDocSh)
788 0 : mpOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
789 :
790 0 : mpOutliner->SetDefTab( nDefaultTabulator );
791 0 : mpOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
792 : }
793 :
794 508 : return mpOutliner;
795 : }
796 :
797 : // Internal outliner that is used to create text objects. We don't insert any
798 : // OutlinerViews into this outliner!
799 6570 : ::sd::Outliner* SdDrawDocument::GetInternalOutliner(bool bCreateOutliner)
800 : {
801 6570 : if ( !mpInternalOutliner && bCreateOutliner )
802 : {
803 250 : mpInternalOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
804 :
805 : // This outliner is only used to create special text objects. As no
806 : // information about portions is saved in this outliner, the update mode
807 : // can/should always remain sal_False.
808 250 : mpInternalOutliner->SetUpdateMode( false );
809 250 : mpInternalOutliner->EnableUndo( false );
810 :
811 250 : if (mpDocSh)
812 250 : mpInternalOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
813 :
814 250 : mpInternalOutliner->SetDefTab( nDefaultTabulator );
815 250 : mpInternalOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
816 : }
817 :
818 : DBG_ASSERT( !mpInternalOutliner || ( ! mpInternalOutliner->GetUpdateMode() ) , "InternalOutliner: UpdateMode = sal_True !" );
819 : DBG_ASSERT( !mpInternalOutliner || ( ! mpInternalOutliner->IsUndoEnabled() ), "InternalOutliner: Undo = sal_True !" );
820 :
821 : // If you add stuff here, always clear it out.
822 : // Advantages:
823 : // a) no unnecessary Clear calls
824 : // b) no wasted memory
825 : DBG_ASSERT( !mpInternalOutliner || ( ( mpInternalOutliner->GetParagraphCount() == 1 ) && ( mpInternalOutliner->GetText( mpInternalOutliner->GetParagraph( 0 ) ).isEmpty() ) ), "InternalOutliner: not empty!" );
826 :
827 6570 : return mpInternalOutliner;
828 : }
829 :
830 : // OnlineSpelling on/off
831 0 : void SdDrawDocument::SetOnlineSpell(bool bIn)
832 : {
833 0 : mbOnlineSpell = bIn;
834 : EEControlBits nCntrl;
835 :
836 0 : if(mpOutliner)
837 : {
838 0 : nCntrl = mpOutliner->GetControlWord();
839 :
840 0 : if(mbOnlineSpell)
841 0 : nCntrl |= EEControlBits::ONLINESPELLING;
842 : else
843 0 : nCntrl &= ~EEControlBits::ONLINESPELLING;
844 :
845 0 : mpOutliner->SetControlWord(nCntrl);
846 : }
847 :
848 0 : if (mpInternalOutliner)
849 : {
850 0 : nCntrl = mpInternalOutliner->GetControlWord();
851 :
852 0 : if (mbOnlineSpell)
853 0 : nCntrl |= EEControlBits::ONLINESPELLING;
854 : else
855 0 : nCntrl &= ~EEControlBits::ONLINESPELLING;
856 :
857 0 : mpInternalOutliner->SetControlWord(nCntrl);
858 : }
859 :
860 0 : ::Outliner& rOutliner = GetDrawOutliner();
861 :
862 0 : nCntrl = rOutliner.GetControlWord();
863 :
864 0 : if (mbOnlineSpell)
865 0 : nCntrl |= EEControlBits::ONLINESPELLING;
866 : else
867 0 : nCntrl &= ~EEControlBits::ONLINESPELLING;
868 :
869 0 : rOutliner.SetControlWord(nCntrl);
870 :
871 0 : if (mbOnlineSpell)
872 : {
873 0 : StartOnlineSpelling();
874 : }
875 : else
876 : {
877 0 : StopOnlineSpelling();
878 : }
879 0 : }
880 :
881 : // OnlineSpelling: highlighting on/off
882 249 : uno::Reference< uno::XInterface > SdDrawDocument::createUnoModel()
883 : {
884 249 : uno::Reference< uno::XInterface > xModel;
885 :
886 : try
887 : {
888 249 : if ( mpDocSh )
889 249 : xModel = mpDocSh->GetModel();
890 : }
891 0 : catch( uno::RuntimeException& )
892 : {
893 : }
894 :
895 249 : return xModel;
896 : }
897 :
898 3443 : SvxNumType SdDrawDocument::GetPageNumType() const
899 : {
900 3443 : return mePageNumType;
901 : }
902 :
903 364 : void SdDrawDocument::SetPrinterIndependentLayout (sal_Int32 nMode)
904 : {
905 364 : switch (nMode)
906 : {
907 : case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
908 : case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
909 : // Just store supported modes and inform the doc shell
910 364 : mnPrinterIndependentLayout = nMode;
911 :
912 : // Since it is possible that a SdDrawDocument is constructed without a
913 : // SdDrawDocShell the pointer member mpDocSh needs to be tested
914 : // before the call is executed. This is e. g. used for copy/paste.
915 364 : if(mpDocSh)
916 : {
917 362 : mpDocSh->UpdateRefDevice ();
918 : }
919 :
920 364 : break;
921 :
922 : default:
923 : // Ignore unknown values
924 0 : break;
925 : }
926 364 : }
927 :
928 0 : void SdDrawDocument::SetStartWithPresentation( bool bStartWithPresentation )
929 : {
930 0 : mbStartWithPresentation = bStartWithPresentation;
931 0 : }
932 :
933 0 : void SdDrawDocument::SetExitAfterPresenting( bool bExitAfterPresenting )
934 : {
935 0 : mbExitAfterPresenting = bExitAfterPresenting;
936 0 : }
937 :
938 3446 : void SdDrawDocument::PageListChanged()
939 : {
940 3446 : mpDrawPageListWatcher->Invalidate();
941 3446 : }
942 :
943 1872 : void SdDrawDocument::MasterPageListChanged()
944 : {
945 1872 : mpMasterPageListWatcher->Invalidate();
946 1872 : }
947 :
948 640 : void SdDrawDocument::SetCalcFieldValueHdl(::Outliner* pOutliner)
949 : {
950 640 : pOutliner->SetCalcFieldValueHdl(LINK(SD_MOD(), SdModule, CalcFieldValueHdl));
951 640 : }
952 :
953 0 : sal_uInt16 SdDrawDocument::GetAnnotationAuthorIndex( const OUString& rAuthor )
954 : {
955 : // force current user to have first color
956 0 : if( maAnnotationAuthors.empty() )
957 : {
958 0 : SvtUserOptions aUserOptions;
959 0 : maAnnotationAuthors.push_back( aUserOptions.GetFullName() );
960 : }
961 :
962 0 : sal_uInt16 idx = 0;
963 0 : const std::vector< OUString >::const_iterator aEnd( maAnnotationAuthors.end());
964 0 : for( std::vector< OUString >::const_iterator iter( maAnnotationAuthors.begin() ); iter != aEnd; ++iter )
965 : {
966 0 : if( (*iter) == rAuthor )
967 : {
968 0 : break;
969 : }
970 0 : idx++;
971 : }
972 :
973 0 : if( idx == maAnnotationAuthors.size() )
974 : {
975 0 : maAnnotationAuthors.push_back( rAuthor );
976 : }
977 :
978 0 : return idx;
979 : }
980 :
981 320 : void SdDrawDocument::InitLayoutVector()
982 : {
983 : const Reference<css::uno::XComponentContext> xContext(
984 320 : ::comphelper::getProcessComponentContext() );
985 :
986 : // get file list from configuration
987 : Sequence< rtl::OUString > aFiles(
988 640 : officecfg::Office::Impress::Misc::LayoutListFiles::get(xContext) );
989 :
990 640 : rtl::OUString sFilename;
991 640 : for( sal_Int32 i=0; i < aFiles.getLength(); ++i )
992 : {
993 320 : sFilename = comphelper::getExpandedUri(xContext, aFiles[i]);
994 :
995 : // load layout file into DOM
996 : Reference< XMultiServiceFactory > xServiceFactory(
997 320 : xContext->getServiceManager() , UNO_QUERY_THROW );
998 : const Reference<XDocumentBuilder> xDocBuilder(
999 640 : DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) ));
1000 :
1001 : try
1002 : {
1003 : // loop over every layout entry in current file
1004 320 : const Reference<XDocument> xDoc = xDocBuilder->parseURI( sFilename );
1005 640 : const Reference<XNodeList> layoutlist = xDoc->getElementsByTagName("layout");
1006 320 : const int nElements = layoutlist->getLength();
1007 5120 : for(int index=0; index < nElements; index++)
1008 5120 : maLayoutInfo.push_back( layoutlist->item(index) );
1009 : }
1010 0 : catch (const uno::Exception &)
1011 : {
1012 : // skip missing config. files
1013 : }
1014 640 : }
1015 320 : }
1016 :
1017 320 : void SdDrawDocument::InitObjectVector()
1018 : {
1019 : const Reference<css::uno::XComponentContext> xContext(
1020 320 : ::comphelper::getProcessComponentContext() );
1021 :
1022 : // get file list from configuration
1023 : Sequence< rtl::OUString > aFiles(
1024 640 : officecfg::Office::Impress::Misc::PresObjListFiles::get(xContext) );
1025 :
1026 640 : rtl::OUString sFilename;
1027 640 : for( sal_Int32 i=0; i < aFiles.getLength(); ++i )
1028 : {
1029 320 : sFilename = comphelper::getExpandedUri(xContext, aFiles[i]);
1030 :
1031 : // load presentation object file into DOM
1032 : Reference< XMultiServiceFactory > xServiceFactory(
1033 320 : xContext->getServiceManager() , UNO_QUERY_THROW );
1034 : const Reference<XDocumentBuilder> xDocBuilder(
1035 640 : DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) ));
1036 :
1037 : try
1038 : {
1039 : // loop over every object entry in current file
1040 320 : const Reference<XDocument> xDoc = xDocBuilder->parseURI( sFilename );
1041 640 : const Reference<XNodeList> objectlist = xDoc->getElementsByTagName("object");
1042 320 : const int nElements = objectlist->getLength();
1043 2560 : for(int index=0; index < nElements; index++)
1044 2560 : maPresObjectInfo.push_back( objectlist->item(index) );
1045 : }
1046 0 : catch (const uno::Exception &)
1047 : {
1048 : // skip missing config. files
1049 : }
1050 640 : }
1051 320 : }
1052 :
1053 0 : void SdDrawDocument::dumpAsXml(xmlTextWriterPtr pWriter) const
1054 : {
1055 0 : bool bOwns = false;
1056 0 : if (!pWriter)
1057 : {
1058 0 : pWriter = xmlNewTextWriterFilename("model.xml", 0);
1059 0 : xmlTextWriterStartDocument(pWriter, NULL, NULL, NULL);
1060 0 : bOwns = true;
1061 : }
1062 0 : FmFormModel::dumpAsXml(pWriter);
1063 0 : if (bOwns)
1064 : {
1065 0 : xmlTextWriterEndDocument(pWriter);
1066 0 : xmlFreeTextWriter(pWriter);
1067 : }
1068 66 : }
1069 :
1070 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|