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