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