xref: /aoo42x/main/sd/source/core/drawdoc.cxx (revision 9e9dd2d5)
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 , mpOutliner(NULL)
152 , mpInternalOutliner(NULL)
153 , mpWorkStartupTimer(NULL)
154 , mpOnlineSpellingTimer(NULL)
155 , mpOnlineSpellingList(NULL)
156 , mpOnlineSearchItem(NULL)
157 , mpFrameViewList( new List() )
158 , mpCustomShowList(NULL)
159 , mpDocSh(static_cast< ::sd::DrawDocShell*>(pDrDocSh))
160 , mpCreatingTransferable( NULL )
161 , mbHasOnlineSpellErrors(sal_False)
162 , mbInitialOnlineSpellingEnabled(sal_True)
163 , mbNewOrLoadCompleted(sal_False)
164 , mbStartWithPresentation( false )
165 , meLanguage( LANGUAGE_SYSTEM )
166 , meLanguageCJK( LANGUAGE_SYSTEM )
167 , meLanguageCTL( LANGUAGE_SYSTEM )
168 , mePageNumType(SVX_ARABIC)
169 , mbAllocDocSh(sal_False)
170 , meDocType(eType)
171 , mpCharClass(NULL)
172 , mpLocale(NULL)
173 , mpDrawPageListWatcher(0)
174 , mpMasterPageListWatcher(0)
175 {
176 	// #109538#
177 	mpDrawPageListWatcher = ::std::auto_ptr<ImpDrawPageListWatcher>(
178         new ImpDrawPageListWatcher(*this));
179 	mpMasterPageListWatcher = ::std::auto_ptr<ImpMasterPageListWatcher>(
180         new ImpMasterPageListWatcher(*this));
181 
182 	SetObjectShell(pDrDocSh);		// fuer das VCDrawModel
183 
184 	if (mpDocSh)
185 	{
186 		SetSwapGraphics(sal_True);
187 	}
188 
189 	// Masseinheit (von App) und Massstab (von SdMod) setzen
190 	sal_Int32 nX, nY;
191 	SdOptions* pOptions = SD_MOD()->GetSdOptions(meDocType);
192 	pOptions->GetScale( nX, nY );
193 
194     // #92067# Allow UI scale only for draw documents.
195     if( eType == DOCUMENT_TYPE_DRAW )
196         SetUIUnit( (FieldUnit)pOptions->GetMetric(), Fraction( nX, nY ) );	// user-defined
197     else
198         SetUIUnit( (FieldUnit)pOptions->GetMetric(), Fraction( 1, 1 ) );	// default
199 
200 	SetScaleUnit(MAP_100TH_MM);
201 	SetScaleFraction(Fraction(1, 1));
202 	SetDefaultFontHeight(847);     // 24p
203 
204 	pItemPool->SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
205 	pItemPool->FreezeIdRanges();
206 	SetTextDefaults();
207 
208 	// die DrawingEngine muss auch wissen, wo er ist
209 	FmFormModel::SetStyleSheetPool( new SdStyleSheetPool( GetPool(), this ) );
210 
211 	// Dem DrawOutliner den StyleSheetPool setzen, damit Textobjekte richtig
212 	// eingelesen werden koennen. Der Link zum StyleRequest-Handler des
213 	// Dokuments wird erst in NewOrLoadCompleted gesetzt, da erst dann alle
214 	// Vorlagen existieren.
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 	// DefTab und SpellOptions setzen
254 	// Jetzt am Modul (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 	// Dem HitTestOutliner den StyleSheetPool setzen.
306 	// Der Link zum StyleRequest-Handler des
307 	// Dokuments wird erst in NewOrLoadCompleted gesetzt, da erst dann alle
308 	// Vorlagen existieren.
309 	SfxItemSet aSet2( pHitTestOutliner->GetEmptyItemSet() );
310 	pHitTestOutliner->SetStyleSheetPool( (SfxStyleSheetPool*)GetStyleSheetPool() );
311 
312 	SetCalcFieldValueHdl( pHitTestOutliner );
313 
314 	try
315 	{
316 	    Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
317 	    if ( xSpellChecker.is() )
318 		    pHitTestOutliner->SetSpeller( xSpellChecker );
319 
320 	    Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
321 	    if( xHyphenator.is() )
322 		    pHitTestOutliner->SetHyphenator( xHyphenator );
323 	}
324 	catch(...)
325 	{
326 		DBG_ERROR("Can't get SpellChecker");
327 	}
328 
329 	pHitTestOutliner->SetDefaultLanguage( Application::GetSettings().GetLanguage() );
330 
331 	sal_uLong nCntrl2 = pHitTestOutliner->GetControlWord();
332 	nCntrl2 |= EE_CNTRL_ALLOWBIGOBJS;
333 	nCntrl2 |= EE_CNTRL_URLSFXEXECUTE;
334 	nCntrl2 &= ~EE_CNTRL_ONLINESPELLING;
335 
336 	nCntrl2 &= ~ EE_CNTRL_ULSPACESUMMATION;
337 	if ( pOptions->IsSummationOfParagraphs() )
338 		nCntrl2 |= EE_CNTRL_ULSPACESUMMATION;
339 
340 	pHitTestOutliner->SetControlWord( nCntrl2 );
341 
342 	/**************************************************************************
343 	* Layer anlegen
344 	*
345 	* Es werden auf Pages und MasterPages folgende Default-Layer angelegt:
346 	*
347 	* Layer STR_LAYOUT	  : Standardlayer f�r alle Zeichenobjekte
348 	*
349 	* Layer STR_BCKGRND   : Hintergrund der MasterPage
350 	*						(auf normalen Pages z.Z. keine Verwendung)
351 	*
352 	* Layer STR_BCKGRNDOBJ: Objekte auf dem Hintergrund der MasterPage
353 	*						(auf normalen Pages z.Z. keine Verwendung)
354 	*
355 	* Layer STR_CONTROLS  : Standardlayer f�r Controls
356 	*
357 	**************************************************************************/
358 	{
359 		String aControlLayerName( SdResId(STR_LAYER_CONTROLS) );
360 
361 		SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
362 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_LAYOUT)) );
363 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_BCKGRND)) );
364 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_BCKGRNDOBJ)) );
365 		rLayerAdmin.NewLayer( aControlLayerName );
366 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_MEASURELINES)) );
367 
368 		rLayerAdmin.SetControlLayerName(aControlLayerName);
369 	}
370 
371 
372 }
373 
374 /*************************************************************************
375 |*
376 |* Destruktor
377 |*
378 \************************************************************************/
379 
380 SdDrawDocument::~SdDrawDocument()
381 {
382 	Broadcast(SdrHint(HINT_MODELCLEARED));
383 
384 	if (mpWorkStartupTimer)
385 	{
386 		if ( mpWorkStartupTimer->IsActive() )
387 			mpWorkStartupTimer->Stop();
388 
389 		delete mpWorkStartupTimer;
390 		mpWorkStartupTimer = NULL;
391 	}
392 
393 	StopOnlineSpelling();
394 	delete mpOnlineSearchItem;
395 	mpOnlineSearchItem = NULL;
396 
397 	CloseBookmarkDoc();
398 	SetAllocDocSh(sal_False);
399 
400 	// #116168#
401 	ClearModel(sal_True);
402 
403 	if (pLinkManager)
404 	{
405 		// BaseLinks freigeben
406 		if ( pLinkManager->GetLinks().Count() )
407 		{
408 			pLinkManager->Remove( 0, pLinkManager->GetLinks().Count() );
409 		}
410 
411 		delete pLinkManager;
412 		pLinkManager = NULL;
413 	}
414 
415 	::sd::FrameView* pFrameView = NULL;
416 
417 	for (sal_uLong i = 0; i < mpFrameViewList->Count(); i++)
418 	{
419 		// Ggf. FrameViews loeschen
420 		pFrameView =
421             static_cast< ::sd::FrameView*>(mpFrameViewList->GetObject(i));
422 
423 		if (pFrameView)
424 			delete pFrameView;
425 	}
426 
427 	delete mpFrameViewList;
428 	mpFrameViewList = NULL;
429 
430 	if (mpCustomShowList)
431 	{
432 		for (sal_uLong j = 0; j < mpCustomShowList->Count(); j++)
433 		{
434 			// Ggf. CustomShows loeschen
435 			SdCustomShow* pCustomShow = (SdCustomShow*) mpCustomShowList->GetObject(j);
436 			delete pCustomShow;
437 		}
438 
439 		delete mpCustomShowList;
440 		mpCustomShowList = NULL;
441 	}
442 
443 	delete mpOutliner;
444 	mpOutliner = NULL;
445 
446 	delete mpInternalOutliner;
447 	mpInternalOutliner = NULL;
448 
449 	delete mpLocale;
450 	mpLocale = NULL;
451 
452 	delete mpCharClass;
453 	mpCharClass = NULL;
454 }
455 
456 /*************************************************************************
457 |*
458 |* Diese Methode erzeugt ein neues Dokument (SdDrawDocument) und gibt einen
459 |* Zeiger darauf zurueck. Die Drawing Engine benutzt diese Methode um das
460 |* Dokument oder Teile davon ins Clipboard/DragServer stellen zu koennen.
461 |*
462 \************************************************************************/
463 
464 SdrModel* SdDrawDocument::AllocModel() const
465 {
466 	SdDrawDocument* pNewModel = NULL;
467 
468 	if( mpCreatingTransferable )
469 	{
470 		// Dokument wird fuer Drag&Drop/Clipboard erzeugt, dafuer muss dem Dokument eine DocShell (SvPersist) bekannt sein
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 		// Nur fuer Clipboard notwendig,
486 		// fuer Drag&Drop erfolgt dieses im 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 			// Alle Layouts der MasterPage mitnehmen
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 		// Es wird eine DocShell erzeugt, welche mit GetAllocedDocSh() zurueckgegeben wird
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 |* Diese Methode erzeugt eine neue Seite (SdPage) und gibt einen Zeiger
527 |* darauf zurueck. Die Drawing Engine benutzt diese Methode beim Laden
528 |* zur Erzeugung von Seiten (deren Typ sie ja nicht kennt, da es ABLEITUNGEN
529 |* der SdrPage sind).
530 |*
531 \************************************************************************/
532 
533 SdrPage* SdDrawDocument::AllocPage(FASTBOOL bMasterPage)
534 {
535 	return new SdPage(*this, NULL, (sal_Bool)bMasterPage);
536 }
537 
538 /*************************************************************************
539 |*
540 |* SetChanged(), das Model wurde geaendert
541 |*
542 \************************************************************************/
543 
544 void SdDrawDocument::SetChanged(sal_Bool bFlag)
545 {
546 	if (mpDocSh)
547 	{
548 		if (mbNewOrLoadCompleted && mpDocSh->IsEnableSetModified())
549 		{
550 			// weitergeben an Basisklasse
551 			FmFormModel::SetChanged(bFlag);
552 
553 			// an ObjectShell weiterleiten
554 			mpDocSh->SetModified(bFlag);
555 		}
556 	}
557 	else
558 	{
559 		// weitergeben an Basisklasse
560 		FmFormModel::SetChanged(bFlag);
561 	}
562 }
563 
564 /*************************************************************************
565 |*
566 |* NbcSetChanged(), the model changed, don't call anybody else
567 |*
568 \************************************************************************/
569 
570 void SdDrawDocument::NbcSetChanged(sal_Bool bFlag)
571 {
572     // #100237# forward to baseclass
573     FmFormModel::SetChanged(bFlag);
574 }
575 
576 /*************************************************************************
577 |*
578 |* NewOrLoadCompleted
579 |*
580 |* Wird gerufen, wenn das Dokument geladen wurde bzw. feststeht, dass es
581 |* nicht mehr geladen wird.
582 |*
583 \************************************************************************/
584 
585 void SdDrawDocument::NewOrLoadCompleted(DocCreationMode eMode)
586 {
587 	if (eMode == NEW_DOC)
588 	{
589 		// Neues Dokument:
590 		// Praesentations- und Standardvorlagen erzeugen,
591 		// Pool fuer virtuelle Controls erzeugen
592 		CreateLayoutTemplates();
593 		CreateDefaultCellStyles();
594 
595 		static_cast< SdStyleSheetPool* >( mxStyleSheetPool.get() )->CreatePseudosIfNecessary();
596 	}
597 	else if (eMode == DOC_LOADED)
598 	{
599 			// Dokument wurde geladen:
600 
601 		CheckMasterPages();
602 
603 		if ( GetMasterSdPageCount(PK_STANDARD) > 1 )
604 			RemoveUnnecessaryMasterPages( NULL, sal_True, sal_False );
605 
606 		for ( sal_uInt16 i = 0; i < GetPageCount(); i++ )
607 		{
608 			// Check for correct layout names
609 			SdPage* pPage = (SdPage*) GetPage( i );
610 
611 			if(pPage->TRG_HasMasterPage())
612 			{
613 				SdPage& rMaster = (SdPage&)pPage->TRG_GetMasterPage();
614 
615 				if(rMaster.GetLayoutName() != pPage->GetLayoutName())
616 				{
617 					pPage->SetLayoutName(rMaster.GetLayoutName());
618 				}
619 			}
620 		}
621 
622 		for ( sal_uInt16 nPage = 0; nPage < GetMasterPageCount(); nPage++)
623 		{
624 			// LayoutName and PageName must be the same
625 			SdPage* pPage = (SdPage*) GetMasterPage( nPage );
626 
627 			String aName( pPage->GetLayoutName() );
628 			aName.Erase( aName.SearchAscii( SD_LT_SEPARATOR ) );
629 
630 			if( aName != pPage->GetName() )
631 				pPage->SetName( aName );
632 		}
633 
634 		// Sprachabhaengige Namen der StandardLayer erzeugen
635 		RestoreLayerNames();
636 
637 		// Sprachabhaengige Namen der Vorlagen setzen
638 		static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->UpdateStdNames();
639 
640 		// Ggf. fehlende Vorlagen erzeugen (es gab z.B. frueher keinen Subtitle)
641 		static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->CreatePseudosIfNecessary();
642 	}
643 
644 	// Standardvorlage an der Drawing Engine setzen
645 	String aName( SdResId(STR_STANDARD_STYLESHEET_NAME));
646 	SetDefaultStyleSheet(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(aName, SD_STYLE_FAMILY_GRAPHICS)));
647 
648     // #119287# Set default StyleSheet for SdrGrafObj and SdrOle2Obj
649 	SetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(String( SdResId(STR_POOLSHEET_OBJNOLINENOFILL)), SD_STYLE_FAMILY_GRAPHICS)));
650 
651 	// Draw-Outliner und  Dokument Outliner initialisieren,
652 	// aber nicht den globalen Outliner, den der ist ja nicht
653 	// dokumentspezifisch wie StyleSheetPool und StyleRequestHandler
654 	::Outliner& rDrawOutliner = GetDrawOutliner();
655 	rDrawOutliner.SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
656 	sal_uLong nCntrl = rDrawOutliner.GetControlWord();
657 	if (mbOnlineSpell)
658 		nCntrl |= EE_CNTRL_ONLINESPELLING;
659 	else
660 		nCntrl &= ~EE_CNTRL_ONLINESPELLING;
661 	rDrawOutliner.SetControlWord(nCntrl);
662 
663 	// HitTest-Outliner und  Dokument Outliner initialisieren,
664 	// aber nicht den globalen Outliner, den der ist ja nicht
665 	// dokumentspezifisch wie StyleSheetPool und StyleRequestHandler
666 	pHitTestOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
667 
668 	if(mpOutliner)
669 	{
670 		mpOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
671 	}
672 	if(mpInternalOutliner)
673 	{
674 		mpInternalOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
675 	}
676 
677 	if ( eMode == DOC_LOADED )
678 	{
679 		// Praesentationsobjekte muessen wieder Listener der entsprechenden
680 		// Vorlagen werden
681 		SdStyleSheetPool* pSPool = (SdStyleSheetPool*) GetStyleSheetPool();
682 		sal_uInt16 nPage, nPageCount;
683 
684 		// #96323# create missing layout style sheets for broken documents
685 		//		   that where created with the 5.2
686 		nPageCount = GetMasterSdPageCount( PK_STANDARD );
687 		for (nPage = 0; nPage < nPageCount; nPage++)
688 		{
689 			SdPage* pPage = GetMasterSdPage(nPage, PK_STANDARD);
690 			pSPool->CreateLayoutStyleSheets( pPage->GetName(), sal_True );
691 		}
692 
693 		// Standard- und Notizseiten:
694 		for (nPage = 0; nPage < GetPageCount(); nPage++)
695 		{
696 			SdPage* pPage = (SdPage*)GetPage(nPage);
697 			NewOrLoadCompleted( pPage, pSPool );
698 		}
699 
700 		// Masterpages:
701 		for (nPage = 0; nPage < GetMasterPageCount(); nPage++)
702 		{
703 			SdPage* pPage = (SdPage*)GetMasterPage(nPage);
704 
705 			NewOrLoadCompleted( pPage, pSPool );
706 		}
707 	}
708 
709 	mbNewOrLoadCompleted = sal_True;
710 
711 	/**************************************************************************
712 	* Alle gelinkten Pages aktualisieren
713 	**************************************************************************/
714 	SdPage* pPage = NULL;
715 	sal_uInt16 nMaxSdPages = GetSdPageCount(PK_STANDARD);
716 
717 	for (sal_uInt16 nSdPage=0; nSdPage < nMaxSdPages; nSdPage++)
718 	{
719 		pPage = (SdPage*) GetSdPage(nSdPage, PK_STANDARD);
720 
721 		if (pPage && pPage->GetFileName().Len() && pPage->GetBookmarkName().Len())
722 		{
723 			pPage->SetModel(this);
724 		}
725 	}
726 
727 	UpdateAllLinks();
728 
729 	SetChanged( sal_False );
730 }
731 
732 /** updates all links, only links in this document should by resolved */
733 void SdDrawDocument::UpdateAllLinks()
734 {
735 	if ( !pDocLockedInsertingLinks && pLinkManager && pLinkManager->GetLinks().Count() )
736 	{
737 		pDocLockedInsertingLinks = this; // lock inserting links. only links in this document should by resolved
738 
739 		pLinkManager->UpdateAllLinks();  // query box: update all links?
740 
741 		if( pDocLockedInsertingLinks == this )
742 			pDocLockedInsertingLinks = NULL;  // unlock inserting links
743 	}
744 }
745 
746 /** this loops over the presentation objectes of a page and repairs some new settings
747 	from old binary files and resets all default strings for empty presentation objects.
748 */
749 void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool )
750 {
751 /* cl removed because not needed anymore since binfilter
752 	SdrObjListIter aShapeIter( *pPage );
753 	while( aShapeIter.IsMore() )
754 	{
755 		OutlinerParaObject* pOPO = aShapeIter.Next()->GetOutlinerParaObject();
756 		if( pOPO )
757 		{
758 			if( pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
759 				pOPO->SetOutlinerMode( OUTLINERMODE_TEXTOBJECT );
760 
761 			pOPO->FinishLoad( pSPool );
762 		}
763 	}
764 */
765 
766 	const sd::ShapeList& rPresentationShapes( pPage->GetPresentationShapeList() );
767 	if(!rPresentationShapes.isEmpty())
768 	{
769 		// Listen mit Titel- und Gliederungsvorlagen erstellen
770 		String aName = pPage->GetLayoutName();
771 		aName.Erase( aName.SearchAscii( SD_LT_SEPARATOR ));
772 
773 		List* pOutlineList = pSPool->CreateOutlineSheetList(aName);
774 		SfxStyleSheet* pTitleSheet = (SfxStyleSheet*)
775 										pSPool->GetTitleSheet(aName);
776 
777 		SdrObject* pObj = rPresentationShapes.getNextShape(0);
778 
779 		// jetzt nach Titel- und Gliederungstextobjekten suchen und
780 		// Objekte zu Listenern machen
781 		while(pObj)
782 		{
783 			if (pObj->GetObjInventor() == SdrInventor)
784 			{
785 				OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
786 				sal_uInt16 nId = pObj->GetObjIdentifier();
787 
788 				if (nId == OBJ_TITLETEXT)
789 				{
790 					if( pOPO && pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
791 						pOPO->SetOutlinerMode( OUTLINERMODE_TITLEOBJECT );
792 
793 					// sal_True: harte Attribute dabei nicht loeschen
794 					if (pTitleSheet)
795 						pObj->SetStyleSheet(pTitleSheet, sal_True);
796 				}
797 				else if (nId == OBJ_OUTLINETEXT)
798 				{
799 					if( pOPO && pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
800 						pOPO->SetOutlinerMode( OUTLINERMODE_OUTLINEOBJECT );
801 
802 					for (sal_uInt16 nSheet = 0; nSheet < 10; nSheet++)
803 					{
804 						SfxStyleSheet* pSheet = (SfxStyleSheet*)pOutlineList->GetObject(nSheet);
805 						if (pSheet)
806 						{
807 							pObj->StartListening(*pSheet);
808 
809 							if( nSheet == 0)
810 								// Textrahmen hoert auf StyleSheet der Ebene1
811 								pObj->NbcSetStyleSheet(pSheet, sal_True);
812 						}
813 					}
814 				}
815 
816 				if (pObj->ISA(SdrTextObj) && pObj->IsEmptyPresObj() && pPage)
817 				{
818 					PresObjKind ePresObjKind = pPage->GetPresObjKind(pObj);
819 					String aString( pPage->GetPresObjText(ePresObjKind) );
820 
821 					if (aString.Len())
822 					{
823 						sd::Outliner* pInternalOutl = GetInternalOutliner(sal_True);
824 						pPage->SetObjText( (SdrTextObj*) pObj, pInternalOutl, ePresObjKind, aString );
825 						pObj->NbcSetStyleSheet( pPage->GetStyleSheetForPresObj( ePresObjKind ), sal_True );
826 						pInternalOutl->Clear();
827 					}
828 				}
829 			}
830 
831 			pObj = rPresentationShapes.getNextShape(pObj);
832 		}
833 
834 		delete pOutlineList;
835 	}
836 }
837 
838 /*************************************************************************
839 |*
840 |* Lokaler Outliner, welcher fuer den Gliederungsmodus verwendet wird
841 |* In diesen Outliner werden ggf. OutlinerViews inserted!
842 |*
843 \************************************************************************/
844 
845 ::sd::Outliner* SdDrawDocument::GetOutliner(sal_Bool bCreateOutliner)
846 {
847 	if (!mpOutliner && bCreateOutliner)
848 	{
849 		mpOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
850 
851 		if (mpDocSh)
852 			mpOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
853 
854 		mpOutliner->SetDefTab( nDefaultTabulator );
855 		mpOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
856 	}
857 
858 	return(mpOutliner);
859 }
860 
861 
862 /*************************************************************************
863 |*
864 |* Interner Outliner, welcher fuer die Erzeugung von Textobjekten
865 |* verwendet wird.
866 |* In diesen Outliner werden keine OutlinerViews inserted!
867 |*
868 \************************************************************************/
869 
870 ::sd::Outliner* SdDrawDocument::GetInternalOutliner(sal_Bool bCreateOutliner)
871 {
872 	if ( !mpInternalOutliner && bCreateOutliner )
873 	{
874 		mpInternalOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
875 		// MT:
876 		// Dieser Outliner wird nur fuer das Erzeugen spezieller Textobjekte
877 		// verwendet. Da in diesen Textobjekten keine Portion-Informationen
878 		// gespeichert werden muessen, kann/soll der Update-Mode immer sal_False bleiben.
879 		mpInternalOutliner->SetUpdateMode( sal_False );
880 		mpInternalOutliner->EnableUndo( sal_False );
881 
882 		if (mpDocSh)
883 			mpInternalOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
884 
885 		mpInternalOutliner->SetDefTab( nDefaultTabulator );
886 		mpInternalOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
887 	}
888 
889 	DBG_ASSERT( !mpInternalOutliner || ( mpInternalOutliner->GetUpdateMode() == sal_False ) , "InternalOutliner: UpdateMode = sal_True !" );
890 	DBG_ASSERT( !mpInternalOutliner || ( mpInternalOutliner->IsUndoEnabled() == sal_False ), "InternalOutliner: Undo = sal_True !" );
891 
892 	// MT: Wer ihn vollmuellt, macht ihn auch gleich wieder leer:
893 	// Vorteile:
894 	// a) Keine unnoetigen Clear-Aufrufe
895 	// b) Kein Muell im Speicher.
896 	DBG_ASSERT( !mpInternalOutliner || ( ( mpInternalOutliner->GetParagraphCount() == 1 ) && ( mpInternalOutliner->GetText( mpInternalOutliner->GetParagraph( 0 ) ).Len() == 0 ) ), "InternalOutliner: Nicht leer!" );
897 
898 	return mpInternalOutliner;
899 }
900 
901 /*************************************************************************
902 |*
903 |* OnlineSpelling ein/aus
904 |*
905 \************************************************************************/
906 
907 void SdDrawDocument::SetOnlineSpell(sal_Bool bIn)
908 {
909 	mbOnlineSpell = bIn;
910 	sal_uLong nCntrl = 0;
911 
912 	if(mpOutliner)
913 	{
914 		nCntrl = mpOutliner->GetControlWord();
915 
916 		if(mbOnlineSpell)
917 			nCntrl |= EE_CNTRL_ONLINESPELLING;
918 		else
919 			nCntrl &= ~EE_CNTRL_ONLINESPELLING;
920 
921 		mpOutliner->SetControlWord(nCntrl);
922 	}
923 
924 	if (mpInternalOutliner)
925 	{
926 		nCntrl = mpInternalOutliner->GetControlWord();
927 
928 		if (mbOnlineSpell)
929 			nCntrl |= EE_CNTRL_ONLINESPELLING;
930 		else
931 			nCntrl &= ~EE_CNTRL_ONLINESPELLING;
932 
933 		mpInternalOutliner->SetControlWord(nCntrl);
934 	}
935 
936 	::Outliner& rOutliner = GetDrawOutliner();
937 
938 	nCntrl = rOutliner.GetControlWord();
939 
940 	if (mbOnlineSpell)
941 		nCntrl |= EE_CNTRL_ONLINESPELLING;
942 	else
943 		nCntrl &= ~EE_CNTRL_ONLINESPELLING;
944 
945 	rOutliner.SetControlWord(nCntrl);
946 
947 	if (mbOnlineSpell)
948 	{
949 		StartOnlineSpelling();
950 	}
951 	else
952 	{
953 		StopOnlineSpelling();
954 	}
955 }
956 
957 
958 /*************************************************************************
959 |*
960 |* OnlineSpelling: Markierung ein/aus
961 |*
962 \************************************************************************/
963 
964 uno::Reference< uno::XInterface > SdDrawDocument::createUnoModel()
965 {
966 	uno::Reference< uno::XInterface > xModel;
967 
968 	try
969 	{
970 		if ( mpDocSh )
971 			xModel = mpDocSh->GetModel();
972 	}
973 	catch( uno::RuntimeException& )
974 	{
975 	}
976 
977 	return xModel;
978 }
979 
980 SvxNumType SdDrawDocument::GetPageNumType() const
981 {
982 	return mePageNumType;
983 }
984 
985 
986 
987 
988 void SdDrawDocument::SetPrinterIndependentLayout (sal_Int32 nMode)
989 {
990 	// #108104#
991     // DBG_ASSERT (mpDocSh!=NULL, "No available document shell to set ref device at.");
992 
993 	switch (nMode)
994     {
995         case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
996         case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
997             // Just store supported modes and inform the doc shell.
998             mnPrinterIndependentLayout = nMode;
999 
1000 			// #108104#
1001 			// Since it is possible that a SdDrawDocument is constructed without a
1002 			// SdDrawDocShell the pointer member mpDocSh needs to be tested
1003 			// before the call is executed. This is e.-g. used for copy/paste.
1004 			if(mpDocSh)
1005 			{
1006 				mpDocSh->UpdateRefDevice ();
1007 			}
1008 
1009             break;
1010 
1011         default:
1012             // Ignore unknown values.
1013             break;
1014     }
1015 }
1016 
1017 sal_Int32 SdDrawDocument::GetPrinterIndependentLayout (void)
1018 {
1019     return mnPrinterIndependentLayout;
1020 }
1021 
1022 bool SdDrawDocument::IsStartWithPresentation() const
1023 {
1024 	return mbStartWithPresentation;
1025 }
1026 
1027 void SdDrawDocument::SetStartWithPresentation( bool bStartWithPresentation )
1028 {
1029 	mbStartWithPresentation = bStartWithPresentation;
1030 }
1031 
1032 // #109538#
1033 void SdDrawDocument::PageListChanged()
1034 {
1035 	mpDrawPageListWatcher->Invalidate();
1036 }
1037 
1038 // #109538#
1039 void SdDrawDocument::MasterPageListChanged()
1040 {
1041 	mpMasterPageListWatcher->Invalidate();
1042 }
1043 
1044 void SdDrawDocument::SetCalcFieldValueHdl(::Outliner* pOutliner)
1045 {
1046 	pOutliner->SetCalcFieldValueHdl(LINK(SD_MOD(), SdModule, CalcFieldValueHdl));
1047 }
1048 
1049 sal_uInt16 SdDrawDocument::GetAnnotationAuthorIndex( const rtl::OUString& rAuthor )
1050 {
1051     // force current user to have first color
1052     if( maAnnotationAuthors.empty() )
1053     {
1054         SvtUserOptions aUserOptions;
1055         maAnnotationAuthors.push_back( aUserOptions.GetFullName() );
1056     }
1057 
1058     sal_uInt16 idx = 0;
1059     for( std::vector< OUString >::iterator iter( maAnnotationAuthors.begin() ); iter != maAnnotationAuthors.end(); iter++ )
1060     {
1061         if( (*iter) == rAuthor )
1062         {
1063             break;
1064         }
1065         idx++;
1066     }
1067 
1068     if( idx == maAnnotationAuthors.size() )
1069     {
1070         maAnnotationAuthors.push_back( rAuthor );
1071     }
1072 
1073     return idx;
1074 }
1075 
1076 // eof
1077