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