update emoji autocorrect entries from po-files
[LibreOffice.git] / sd / source / core / drawdoc.cxx
blobfcf678ec669fde4ca33de07cf565960ec9834425
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <libxml/xmlwriter.h>
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>
28 #include <svx/svxids.hrc>
29 #include <svl/srchitem.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <editeng/scriptspaceitem.hxx>
33 #include <unotools/useroptions.hxx>
34 #include <officecfg/Office/Impress.hxx>
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>
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"
98 #include <tools/tenccvt.hxx>
99 #include <vcl/settings.hxx>
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;
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;
112 TYPEINIT1( SdDrawDocument, FmFormModel );
114 SdDrawDocument* SdDrawDocument::pDocLockedInsertingLinks = NULL;
116 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 mbStartWithNavigator(false)
133 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 mbStartWithNavigator( r.mbStartWithNavigator )
151 SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh)
152 : 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 , mbUseEmbedFonts(false)
178 mpDrawPageListWatcher.reset(new ImpDrawPageListWatcher(*this));
179 mpMasterPageListWatcher.reset(new ImpMasterPageListWatcher(*this));
181 InitLayoutVector();
182 InitObjectVector();
183 SetObjectShell(pDrDocSh); // for VCDrawModel
185 if (mpDocSh)
187 SetSwapGraphics(true);
190 // Set measuring unit (of the application) and scale (of SdMod)
191 sal_Int32 nX, nY;
192 SdOptions* pOptions = SD_MOD()->GetSdOptions(meDocType);
193 pOptions->GetScale( nX, nY );
195 // Allow UI scale only for draw documents.
196 if( eType == DOCUMENT_TYPE_DRAW )
197 SetUIUnit( (FieldUnit)pOptions->GetMetric(), Fraction( nX, nY ) ); // user-defined
198 else
199 SetUIUnit( (FieldUnit)pOptions->GetMetric(), Fraction( 1, 1 ) ); // default
201 SetScaleUnit(MAP_100TH_MM);
202 SetScaleFraction(Fraction(1, 1));
203 SetDefaultFontHeight(847); // 24p
205 pItemPool->SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
206 pItemPool->FreezeIdRanges();
207 SetTextDefaults();
209 // DrawingEngine has to know where it is...
210 FmFormModel::SetStyleSheetPool( new SdStyleSheetPool( GetPool(), this ) );
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 SdrOutliner& rOutliner = GetDrawOutliner();
216 rOutliner.SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
217 SetCalcFieldValueHdl( &rOutliner );
219 // set linguistic options
221 const SvtLinguConfig aLinguConfig;
222 SvtLinguOptions aOptions;
223 aLinguConfig.GetOptions( aOptions );
225 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage,
226 ::com::sun::star::i18n::ScriptType::LATIN), EE_CHAR_LANGUAGE );
227 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CJK,
228 ::com::sun::star::i18n::ScriptType::ASIAN), EE_CHAR_LANGUAGE_CJK );
229 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CTL,
230 ::com::sun::star::i18n::ScriptType::COMPLEX), EE_CHAR_LANGUAGE_CTL );
232 mbOnlineSpell = aOptions.bIsSpellAuto;
235 LanguageType eRealLanguage = MsLangId::getRealLanguage( meLanguage );
236 LanguageTag aLanguageTag( eRealLanguage);
237 mpLocale = new ::com::sun::star::lang::Locale( aLanguageTag.getLocale());
238 mpCharClass = new CharClass( aLanguageTag );
240 // If the current application language is a language that uses right-to-left text...
241 LanguageType eRealCTLLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
242 if( MsLangId::isRightToLeft( eRealCTLLanguage ) )
244 // ... then we have to set this as a default
245 SetDefaultWritingMode( ::com::sun::star::text::WritingMode_RL_TB );
248 // for korean and japanese languages we have a different default for apply spacing between asian, latin and ctl text
249 if (MsLangId::isKorean(eRealCTLLanguage) || (LANGUAGE_JAPANESE == eRealCTLLanguage))
251 GetPool().GetSecondaryPool()->SetPoolDefaultItem( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
254 // Set DefTab and SpellOptions for the SD module
255 sal_uInt16 nDefTab = pOptions->GetDefTab();
256 SetDefaultTabulator( nDefTab );
260 Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
261 if ( xSpellChecker.is() )
262 rOutliner.SetSpeller( xSpellChecker );
264 Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
265 if( xHyphenator.is() )
266 rOutliner.SetHyphenator( xHyphenator );
268 SetForbiddenCharsTable( new SvxForbiddenCharactersTable( ::comphelper::getProcessComponentContext() ) );
270 catch(...)
272 OSL_FAIL("Can't get SpellChecker");
275 rOutliner.SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
277 if (mpDocSh)
279 SetLinkManager( new sfx2::LinkManager(mpDocSh) );
282 EEControlBits nCntrl = rOutliner.GetControlWord();
283 nCntrl |= EEControlBits::ALLOWBIGOBJS;
285 if (mbOnlineSpell)
286 nCntrl |= EEControlBits::ONLINESPELLING;
287 else
288 nCntrl &= ~EEControlBits::ONLINESPELLING;
290 nCntrl &= ~ EEControlBits::ULSPACESUMMATION;
291 if ( meDocType != DOCUMENT_TYPE_IMPRESS )
292 SetSummationOfParagraphs( false );
293 else
295 SetSummationOfParagraphs( pOptions->IsSummationOfParagraphs() );
296 if ( pOptions->IsSummationOfParagraphs() )
297 nCntrl |= EEControlBits::ULSPACESUMMATION;
299 rOutliner.SetControlWord(nCntrl);
301 // Initialize the printer independent layout mode
302 SetPrinterIndependentLayout (pOptions->GetPrinterIndependentLayout());
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 SfxItemSet aSet2( pHitTestOutliner->GetEmptyItemSet() );
308 pHitTestOutliner->SetStyleSheetPool( static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()) );
310 SetCalcFieldValueHdl( pHitTestOutliner );
314 Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
315 if ( xSpellChecker.is() )
316 pHitTestOutliner->SetSpeller( xSpellChecker );
318 Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
319 if( xHyphenator.is() )
320 pHitTestOutliner->SetHyphenator( xHyphenator );
322 catch(...)
324 OSL_FAIL("Can't get SpellChecker");
327 pHitTestOutliner->SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
329 EEControlBits nCntrl2 = pHitTestOutliner->GetControlWord();
330 nCntrl2 |= EEControlBits::ALLOWBIGOBJS;
331 nCntrl2 &= ~EEControlBits::ONLINESPELLING;
333 nCntrl2 &= ~ EEControlBits::ULSPACESUMMATION;
334 if ( pOptions->IsSummationOfParagraphs() )
335 nCntrl2 |= EEControlBits::ULSPACESUMMATION;
337 pHitTestOutliner->SetControlWord( nCntrl2 );
339 /** Create layers
341 * We create the following default layers on all pages and master pages:
343 * STR_LAYOUT : default layer for drawing objects
345 * STR_BCKGRND : background of the master page
346 * (currently unused within normal pages)
348 * STR_BCKGRNDOBJ: objects on the background of master pages
349 * (currently unused within normal pages)
351 * STR_CONTROLS : default layer for controls
355 OUString aControlLayerName( SD_RESSTR(STR_LAYER_CONTROLS) );
357 SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
358 rLayerAdmin.NewLayer( SD_RESSTR(STR_LAYER_LAYOUT) );
359 rLayerAdmin.NewLayer( SD_RESSTR(STR_LAYER_BCKGRND) );
360 rLayerAdmin.NewLayer( SD_RESSTR(STR_LAYER_BCKGRNDOBJ) );
361 rLayerAdmin.NewLayer( aControlLayerName );
362 rLayerAdmin.NewLayer( SD_RESSTR(STR_LAYER_MEASURELINES) );
364 rLayerAdmin.SetControlLayerName(aControlLayerName);
369 // Destructor
370 SdDrawDocument::~SdDrawDocument()
372 Broadcast(SdrHint(HINT_MODELCLEARED));
374 if (mpWorkStartupTimer)
376 if ( mpWorkStartupTimer->IsActive() )
377 mpWorkStartupTimer->Stop();
379 delete mpWorkStartupTimer;
380 mpWorkStartupTimer = NULL;
383 StopOnlineSpelling();
384 delete mpOnlineSearchItem;
385 mpOnlineSearchItem = NULL;
387 CloseBookmarkDoc();
388 SetAllocDocSh(false);
390 ClearModel(true);
392 if (pLinkManager)
394 // Release BaseLinks
395 if ( !pLinkManager->GetLinks().empty() )
397 pLinkManager->Remove( 0, pLinkManager->GetLinks().size() );
400 delete pLinkManager;
401 pLinkManager = NULL;
404 std::vector<sd::FrameView*>::iterator pIter;
405 for ( pIter = maFrameViewList.begin(); pIter != maFrameViewList.end(); ++pIter )
406 delete *pIter;
408 if (mpCustomShowList)
410 for (sal_uLong j = 0; j < mpCustomShowList->size(); j++)
412 // If necessary, delete CustomShows
413 SdCustomShow* pCustomShow = (*mpCustomShowList)[j];
414 delete pCustomShow;
417 delete mpCustomShowList;
418 mpCustomShowList = NULL;
421 delete mpOutliner;
422 mpOutliner = NULL;
424 delete mpInternalOutliner;
425 mpInternalOutliner = NULL;
427 delete mpLocale;
428 mpLocale = NULL;
430 delete mpCharClass;
431 mpCharClass = NULL;
434 SdrModel* SdDrawDocument::AllocModel() const
436 return AllocSdDrawDocument();
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 SdDrawDocument* SdDrawDocument::AllocSdDrawDocument() const
444 SdDrawDocument* pNewModel = NULL;
446 if( mpCreatingTransferable )
448 // Document is created for drag & drop/clipboard. To be able to
449 // do this, the document has to know a DocShell (SvPersist).
450 SfxObjectShell* pObj = NULL;
451 ::sd::DrawDocShell* pNewDocSh = NULL;
453 if( meDocType == DOCUMENT_TYPE_IMPRESS )
454 mpCreatingTransferable->SetDocShell( new ::sd::DrawDocShell(
455 SfxObjectCreateMode::EMBEDDED, true, meDocType ) );
456 else
457 mpCreatingTransferable->SetDocShell( new ::sd::GraphicDocShell(
458 SfxObjectCreateMode::EMBEDDED, true, meDocType ) );
460 pNewDocSh = static_cast< ::sd::DrawDocShell*>( pObj = mpCreatingTransferable->GetDocShell() );
461 pNewDocSh->DoInitNew( NULL );
462 pNewModel = pNewDocSh->GetDoc();
464 // Only necessary for clipboard -
465 // for drag & drop this is handled by DragServer
466 SdStyleSheetPool* pOldStylePool = static_cast<SdStyleSheetPool*>( GetStyleSheetPool() );
467 SdStyleSheetPool* pNewStylePool = static_cast<SdStyleSheetPool*>( pNewModel->GetStyleSheetPool() );
469 pNewStylePool->CopyGraphicSheets(*pOldStylePool);
470 pNewStylePool->CopyCellSheets(*pOldStylePool);
471 pNewStylePool->CopyTableStyles(*pOldStylePool);
473 for (sal_uInt16 i = 0; i < GetMasterSdPageCount(PK_STANDARD); i++)
475 // Move with all of the master page's layouts
476 OUString aOldLayoutName(const_cast<SdDrawDocument*>(this)->GetMasterSdPage(i, PK_STANDARD)->GetLayoutName());
477 aOldLayoutName = aOldLayoutName.copy( 0, aOldLayoutName.indexOf( SD_LT_SEPARATOR ) );
478 SdStyleSheetVector aCreatedSheets;
479 pNewStylePool->CopyLayoutSheets(aOldLayoutName, *pOldStylePool, aCreatedSheets );
482 pNewModel->NewOrLoadCompleted( DOC_LOADED ); // loaded from source document
484 else if( mbAllocDocSh )
486 // Create a DocShell which is then returned with GetAllocedDocSh()
487 SdDrawDocument* pDoc = const_cast<SdDrawDocument*>(this);
488 pDoc->SetAllocDocSh(false);
489 pDoc->mxAllocedDocShRef = new ::sd::DrawDocShell(
490 SfxObjectCreateMode::EMBEDDED, true, meDocType);
491 pDoc->mxAllocedDocShRef->DoInitNew(NULL);
492 pNewModel = pDoc->mxAllocedDocShRef->GetDoc();
494 else
496 pNewModel = new SdDrawDocument(meDocType, NULL);
499 return pNewModel;
502 SdPage* SdDrawDocument::AllocSdPage(bool bMasterPage)
504 return new SdPage(*this, bMasterPage);
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 SdrPage* SdDrawDocument::AllocPage(bool bMasterPage)
512 return AllocSdPage(bMasterPage);
515 // When the model has changed
516 void SdDrawDocument::SetChanged(bool bFlag)
518 if (mpDocSh)
520 if (mbNewOrLoadCompleted && mpDocSh->IsEnableSetModified())
522 // Pass on to base class
523 FmFormModel::SetChanged(bFlag);
525 // Forward to ObjectShell
526 mpDocSh->SetModified(bFlag);
529 else
531 // Pass on to base class
532 FmFormModel::SetChanged(bFlag);
536 // The model changed, don't call anything else
537 void SdDrawDocument::NbcSetChanged(bool bFlag)
539 // forward to baseclass
540 FmFormModel::SetChanged(bFlag);
543 // NewOrLoadCompleted is called when the document is loaded, or when it is clear
544 // it won't load any more.
545 void SdDrawDocument::NewOrLoadCompleted(DocCreationMode eMode)
547 if (eMode == NEW_DOC)
549 // New document:
550 // create slideshow and default templates,
551 // create pool for virtual controls
552 CreateLayoutTemplates();
553 CreateDefaultCellStyles();
555 static_cast< SdStyleSheetPool* >( mxStyleSheetPool.get() )->CreatePseudosIfNecessary();
557 else if (eMode == DOC_LOADED)
559 // Document has finished loading
561 CheckMasterPages();
563 if ( GetMasterSdPageCount(PK_STANDARD) > 1 )
564 RemoveUnnecessaryMasterPages( NULL, true, false );
566 for ( sal_uInt16 i = 0; i < GetPageCount(); i++ )
568 // Check for correct layout names
569 SdPage* pPage = static_cast<SdPage*>( GetPage( i ) );
571 if(pPage->TRG_HasMasterPage())
573 SdPage& rMaster = static_cast<SdPage&>(pPage->TRG_GetMasterPage() );
575 if(rMaster.GetLayoutName() != pPage->GetLayoutName())
577 pPage->SetLayoutName(rMaster.GetLayoutName());
582 for ( sal_uInt16 nPage = 0; nPage < GetMasterPageCount(); nPage++)
584 // LayoutName and PageName must be the same
585 SdPage* pPage = static_cast<SdPage*>( GetMasterPage( nPage ) );
587 OUString aName( pPage->GetLayoutName() );
588 aName = aName.copy( 0, aName.indexOf( SD_LT_SEPARATOR ) );
590 if( aName != pPage->GetName() )
591 pPage->SetName( aName );
594 // Create names of the default layers in the user's language
595 RestoreLayerNames();
597 // Create names of the styles in the user's language
598 static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->UpdateStdNames();
600 // Create any missing styles - eg. formerly, there was no Subtitle style
601 static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->CreatePseudosIfNecessary();
604 // Set default style of Drawing Engine
605 OUString aName( SD_RESSTR(STR_STANDARD_STYLESHEET_NAME));
606 SetDefaultStyleSheet(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(aName, SD_STYLE_FAMILY_GRAPHICS)));
608 // #i119287# Set default StyleSheet for SdrGrafObj and SdrOle2Obj
609 SetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(SD_RESSTR(STR_POOLSHEET_OBJNOLINENOFILL), SD_STYLE_FAMILY_GRAPHICS)));
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 ::Outliner& rDrawOutliner = GetDrawOutliner();
615 rDrawOutliner.SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
616 EEControlBits nCntrl = rDrawOutliner.GetControlWord();
617 if (mbOnlineSpell)
618 nCntrl |= EEControlBits::ONLINESPELLING;
619 else
620 nCntrl &= ~EEControlBits::ONLINESPELLING;
621 rDrawOutliner.SetControlWord(nCntrl);
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 pHitTestOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
628 if(mpOutliner)
630 mpOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
632 if(mpInternalOutliner)
634 mpInternalOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
637 if ( eMode == DOC_LOADED )
639 // Make presentation objects listeners of the appropriate styles
640 SdStyleSheetPool* pSPool = static_cast<SdStyleSheetPool*>( GetStyleSheetPool() );
641 sal_uInt16 nPage, nPageCount;
643 // create missing layout style sheets for broken documents
644 // that where created with the 5.2
645 nPageCount = GetMasterSdPageCount( PK_STANDARD );
646 for (nPage = 0; nPage < nPageCount; nPage++)
648 SdPage* pPage = GetMasterSdPage(nPage, PK_STANDARD);
649 pSPool->CreateLayoutStyleSheets( pPage->GetName(), true );
652 // Default and notes pages:
653 for (nPage = 0; nPage < GetPageCount(); nPage++)
655 SdPage* pPage = static_cast<SdPage*>(GetPage(nPage));
656 NewOrLoadCompleted( pPage, pSPool );
659 // Master pages:
660 for (nPage = 0; nPage < GetMasterPageCount(); nPage++)
662 SdPage* pPage = static_cast<SdPage*>(GetMasterPage(nPage));
664 NewOrLoadCompleted( pPage, pSPool );
668 mbNewOrLoadCompleted = true;
670 // Update all linked pages
671 sal_uInt16 nMaxSdPages = GetSdPageCount(PK_STANDARD);
673 for (sal_uInt16 nSdPage=0; nSdPage < nMaxSdPages; nSdPage++)
675 SdPage* pPage = GetSdPage(nSdPage, PK_STANDARD);
677 if (pPage && !pPage->GetFileName().isEmpty() && pPage->GetBookmarkName().getLength())
679 pPage->SetModel(this);
683 UpdateAllLinks();
685 SetChanged( false );
688 /** updates all links, only links in this document should by resolved */
689 void SdDrawDocument::UpdateAllLinks()
691 if ( !pDocLockedInsertingLinks && pLinkManager && !pLinkManager->GetLinks().empty() )
693 pDocLockedInsertingLinks = this; // lock inserting links. only links in this document should by resolved
695 pLinkManager->UpdateAllLinks(); // query box: update all links?
697 if( pDocLockedInsertingLinks == this )
698 pDocLockedInsertingLinks = NULL; // unlock inserting links
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.
705 void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool )
707 sd::ShapeList& rPresentationShapes( pPage->GetPresentationShapeList() );
708 if(!rPresentationShapes.isEmpty())
710 // Create lists of title and outline styles
711 OUString aName = pPage->GetLayoutName();
712 aName = aName.copy( 0, aName.indexOf( SD_LT_SEPARATOR ) );
714 std::vector<SfxStyleSheetBase*> aOutlineList;
715 pSPool->CreateOutlineSheetList(aName,aOutlineList);
717 SfxStyleSheet* pTitleSheet = static_cast<SfxStyleSheet*>(pSPool->GetTitleSheet(aName));
719 SdrObject* pObj = 0;
720 rPresentationShapes.seekShape(0);
722 // Now look for title and outline text objects, then make those objects
723 // listeners.
724 while( (pObj = rPresentationShapes.getNextShape()) )
726 if (pObj->GetObjInventor() == SdrInventor)
728 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
729 sal_uInt16 nId = pObj->GetObjIdentifier();
731 if (nId == OBJ_TITLETEXT)
733 if( pOPO && pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
734 pOPO->SetOutlinerMode( OUTLINERMODE_TITLEOBJECT );
736 // sal_True: don't delete "hard" attributes when doing this.
737 if (pTitleSheet)
738 pObj->SetStyleSheet(pTitleSheet, true);
740 else if (nId == OBJ_OUTLINETEXT)
742 if( pOPO && pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
743 pOPO->SetOutlinerMode( OUTLINERMODE_OUTLINEOBJECT );
745 std::vector<SfxStyleSheetBase*>::iterator iter;
746 for (iter = aOutlineList.begin(); iter != aOutlineList.end(); ++iter)
748 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(*iter);
750 if (pSheet)
752 pObj->StartListening(*pSheet);
754 if( iter == aOutlineList.begin())
755 // text frame listens to stylesheet of layer 1
756 pObj->NbcSetStyleSheet(pSheet, true);
761 if (pObj->ISA(SdrTextObj) && pObj->IsEmptyPresObj())
763 PresObjKind ePresObjKind = pPage->GetPresObjKind(pObj);
764 OUString aString( pPage->GetPresObjText(ePresObjKind) );
766 if (!aString.isEmpty())
768 sd::Outliner* pInternalOutl = GetInternalOutliner(true);
769 pPage->SetObjText( static_cast<SdrTextObj*>(pObj), pInternalOutl, ePresObjKind, aString );
770 pObj->NbcSetStyleSheet( pPage->GetStyleSheetForPresObj( ePresObjKind ), true );
771 pInternalOutl->Clear();
779 // Local outliner that is used for outline mode. In this outliner, OutlinerViews
780 // may be inserted.
781 ::sd::Outliner* SdDrawDocument::GetOutliner(bool bCreateOutliner)
783 if (!mpOutliner && bCreateOutliner)
785 mpOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
787 if (mpDocSh)
788 mpOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
790 mpOutliner->SetDefTab( nDefaultTabulator );
791 mpOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
794 return mpOutliner;
797 // Internal outliner that is used to create text objects. We don't insert any
798 // OutlinerViews into this outliner!
799 ::sd::Outliner* SdDrawDocument::GetInternalOutliner(bool bCreateOutliner)
801 if ( !mpInternalOutliner && bCreateOutliner )
803 mpInternalOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
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 mpInternalOutliner->SetUpdateMode( false );
809 mpInternalOutliner->EnableUndo( false );
811 if (mpDocSh)
812 mpInternalOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
814 mpInternalOutliner->SetDefTab( nDefaultTabulator );
815 mpInternalOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
818 DBG_ASSERT( !mpInternalOutliner || ( ! mpInternalOutliner->GetUpdateMode() ) , "InternalOutliner: UpdateMode = sal_True !" );
819 DBG_ASSERT( !mpInternalOutliner || ( ! mpInternalOutliner->IsUndoEnabled() ), "InternalOutliner: Undo = sal_True !" );
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!" );
827 return mpInternalOutliner;
830 // OnlineSpelling on/off
831 void SdDrawDocument::SetOnlineSpell(bool bIn)
833 mbOnlineSpell = bIn;
834 EEControlBits nCntrl;
836 if(mpOutliner)
838 nCntrl = mpOutliner->GetControlWord();
840 if(mbOnlineSpell)
841 nCntrl |= EEControlBits::ONLINESPELLING;
842 else
843 nCntrl &= ~EEControlBits::ONLINESPELLING;
845 mpOutliner->SetControlWord(nCntrl);
848 if (mpInternalOutliner)
850 nCntrl = mpInternalOutliner->GetControlWord();
852 if (mbOnlineSpell)
853 nCntrl |= EEControlBits::ONLINESPELLING;
854 else
855 nCntrl &= ~EEControlBits::ONLINESPELLING;
857 mpInternalOutliner->SetControlWord(nCntrl);
860 ::Outliner& rOutliner = GetDrawOutliner();
862 nCntrl = rOutliner.GetControlWord();
864 if (mbOnlineSpell)
865 nCntrl |= EEControlBits::ONLINESPELLING;
866 else
867 nCntrl &= ~EEControlBits::ONLINESPELLING;
869 rOutliner.SetControlWord(nCntrl);
871 if (mbOnlineSpell)
873 StartOnlineSpelling();
875 else
877 StopOnlineSpelling();
881 // OnlineSpelling: highlighting on/off
882 uno::Reference< uno::XInterface > SdDrawDocument::createUnoModel()
884 uno::Reference< uno::XInterface > xModel;
888 if ( mpDocSh )
889 xModel = mpDocSh->GetModel();
891 catch( uno::RuntimeException& )
895 return xModel;
898 SvxNumType SdDrawDocument::GetPageNumType() const
900 return mePageNumType;
903 void SdDrawDocument::SetPrinterIndependentLayout (sal_Int32 nMode)
905 switch (nMode)
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 mnPrinterIndependentLayout = nMode;
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 if(mpDocSh)
917 mpDocSh->UpdateRefDevice ();
920 break;
922 default:
923 // Ignore unknown values
924 break;
928 void SdDrawDocument::SetStartWithPresentation( bool bStartWithPresentation )
930 mbStartWithPresentation = bStartWithPresentation;
933 void SdDrawDocument::SetExitAfterPresenting( bool bExitAfterPresenting )
935 mbExitAfterPresenting = bExitAfterPresenting;
938 void SdDrawDocument::PageListChanged()
940 mpDrawPageListWatcher->Invalidate();
943 void SdDrawDocument::MasterPageListChanged()
945 mpMasterPageListWatcher->Invalidate();
948 void SdDrawDocument::SetCalcFieldValueHdl(::Outliner* pOutliner)
950 pOutliner->SetCalcFieldValueHdl(LINK(SD_MOD(), SdModule, CalcFieldValueHdl));
953 sal_uInt16 SdDrawDocument::GetAnnotationAuthorIndex( const OUString& rAuthor )
955 // force current user to have first color
956 if( maAnnotationAuthors.empty() )
958 SvtUserOptions aUserOptions;
959 maAnnotationAuthors.push_back( aUserOptions.GetFullName() );
962 sal_uInt16 idx = 0;
963 const std::vector< OUString >::const_iterator aEnd( maAnnotationAuthors.end());
964 for( std::vector< OUString >::const_iterator iter( maAnnotationAuthors.begin() ); iter != aEnd; ++iter )
966 if( (*iter) == rAuthor )
968 break;
970 idx++;
973 if( idx == maAnnotationAuthors.size() )
975 maAnnotationAuthors.push_back( rAuthor );
978 return idx;
981 void SdDrawDocument::InitLayoutVector()
983 const Reference<css::uno::XComponentContext> xContext(
984 ::comphelper::getProcessComponentContext() );
986 // get file list from configuration
987 Sequence< rtl::OUString > aFiles(
988 officecfg::Office::Impress::Misc::LayoutListFiles::get(xContext) );
990 rtl::OUString sFilename;
991 for( sal_Int32 i=0; i < aFiles.getLength(); ++i )
993 sFilename = comphelper::getExpandedUri(xContext, aFiles[i]);
995 // load layout file into DOM
996 Reference< XMultiServiceFactory > xServiceFactory(
997 xContext->getServiceManager() , UNO_QUERY_THROW );
998 const Reference<XDocumentBuilder> xDocBuilder(
999 DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) ));
1003 // loop over every layout entry in current file
1004 const Reference<XDocument> xDoc = xDocBuilder->parseURI( sFilename );
1005 const Reference<XNodeList> layoutlist = xDoc->getElementsByTagName("layout");
1006 const int nElements = layoutlist->getLength();
1007 for(int index=0; index < nElements; index++)
1008 maLayoutInfo.push_back( layoutlist->item(index) );
1010 catch (const uno::Exception &)
1012 // skip missing config. files
1017 void SdDrawDocument::InitObjectVector()
1019 const Reference<css::uno::XComponentContext> xContext(
1020 ::comphelper::getProcessComponentContext() );
1022 // get file list from configuration
1023 Sequence< rtl::OUString > aFiles(
1024 officecfg::Office::Impress::Misc::PresObjListFiles::get(xContext) );
1026 rtl::OUString sFilename;
1027 for( sal_Int32 i=0; i < aFiles.getLength(); ++i )
1029 sFilename = comphelper::getExpandedUri(xContext, aFiles[i]);
1031 // load presentation object file into DOM
1032 Reference< XMultiServiceFactory > xServiceFactory(
1033 xContext->getServiceManager() , UNO_QUERY_THROW );
1034 const Reference<XDocumentBuilder> xDocBuilder(
1035 DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) ));
1039 // loop over every object entry in current file
1040 const Reference<XDocument> xDoc = xDocBuilder->parseURI( sFilename );
1041 const Reference<XNodeList> objectlist = xDoc->getElementsByTagName("object");
1042 const int nElements = objectlist->getLength();
1043 for(int index=0; index < nElements; index++)
1044 maPresObjectInfo.push_back( objectlist->item(index) );
1046 catch (const uno::Exception &)
1048 // skip missing config. files
1053 void SdDrawDocument::dumpAsXml(xmlTextWriterPtr pWriter) const
1055 bool bOwns = false;
1056 if (!pWriter)
1058 pWriter = xmlNewTextWriterFilename("model.xml", 0);
1059 xmlTextWriterStartDocument(pWriter, NULL, NULL, NULL);
1060 bOwns = true;
1062 FmFormModel::dumpAsXml(pWriter);
1063 if (bOwns)
1065 xmlTextWriterEndDocument(pWriter);
1066 xmlFreeTextWriter(pWriter);
1070 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */