xref: /aoo42x/main/sd/source/core/drawdoc.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "PageListWatcher.hxx"
32 #include <com/sun/star/text/WritingMode.hpp>
33 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
34 #include <com/sun/star/i18n/ScriptType.hpp>
35 #include <editeng/forbiddencharacterstable.hxx>
36 
37 #include <svx/svxids.hrc>
38 #include <svl/srchitem.hxx>
39 #include <editeng/eeitem.hxx>
40 #include <editeng/scriptspaceitem.hxx>
41 
42 #include <unotools/useroptions.hxx>
43 
44 #include <sfx2/printer.hxx>
45 #include <sfx2/app.hxx>
46 #include <sfx2/linkmgr.hxx>
47 #include <svx/dialogs.hrc>
48 #include "Outliner.hxx"
49 #include "app.hxx"
50 #include <editeng/eeitem.hxx>
51 #include <editeng/editstat.hxx>
52 #include <editeng/fontitem.hxx>
53 #include <svl/flagitem.hxx>
54 #include <svx/svdoattr.hxx>
55 #include <svx/svdotext.hxx>
56 #include <editeng/bulitem.hxx>
57 #include <editeng/numitem.hxx>
58 #include <svx/svditer.hxx>
59 #include <editeng/unolingu.hxx>
60 #include <svl/itempool.hxx>
61 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
62 #include <svx/xtable.hxx>
63 #include <com/sun/star/linguistic2/XHyphenator.hpp>
64 #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
65 #include <com/sun/star/beans/XPropertySet.hpp>
66 #include <editeng/outlobj.hxx>
67 #include <unotools/saveopt.hxx>
68 #include <comphelper/extract.hxx>
69 #include <i18npool/mslangid.hxx>
70 #include <unotools/charclass.hxx>
71 #include <comphelper/processfactory.hxx>
72 #ifndef _SVTOOLS_PATHOPTIONS_HXX_
73 #include <unotools/pathoptions.hxx>
74 #endif
75 #include <unotools/lingucfg.hxx>
76 #include <unotools/linguprops.hxx>
77 
78 #include "eetext.hxx"
79 #include "drawdoc.hxx"
80 #include "sdpage.hxx"
81 #include "pglink.hxx"
82 #include "sdattr.hxx"
83 #include "glob.hrc"
84 #include "glob.hxx"
85 #include "stlpool.hxx"
86 #include "sdiocmpt.hxx"
87 #include "sdresid.hxx"
88 #include "cusshow.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 // #90477#
97 #include <tools/tenccvt.hxx>
98 
99 using ::rtl::OUString;
100 using namespace ::sd;
101 using namespace ::com::sun::star;
102 using namespace ::com::sun::star::uno;
103 using namespace ::com::sun::star::lang;
104 using namespace ::com::sun::star::linguistic2;
105 
106 //////////////////////////////////////////////////////////////////////////////
107 
108 TYPEINIT1( SdDrawDocument, FmFormModel );
109 
110 SdDrawDocument* SdDrawDocument::pDocLockedInsertingLinks = NULL;
111 
112 //////////////////////////////////////////////////////////////////////////////
113 
114 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 	mbStartWithNavigator(false)
128 {
129 }
130 
131 // ---------------------------------------------------------------------------
132 
133 PresentationSettings::PresentationSettings( const PresentationSettings& r )
134 :	maPresPage( r.maPresPage ),
135 	mbAll( r.mbAll ),
136 	mbEndless( r.mbEndless ),
137 	mbCustomShow( r.mbCustomShow ),
138 	mbManual( r.mbManual ),
139 	mbMouseVisible( r.mbMouseVisible ),
140 	mbMouseAsPen( r.mbMouseAsPen ),
141 	mbLockedPages( r.mbLockedPages ),
142 	mbAlwaysOnTop( r.mbAlwaysOnTop ),
143 	mbFullScreen( r.mbFullScreen ),
144 	mbAnimationAllowed( r.mbAnimationAllowed ),
145 	mnPauseTimeout( r.mnPauseTimeout ),
146 	mbShowPauseLogo( r.mbShowPauseLogo ),
147 	mbStartWithNavigator( r.mbStartWithNavigator )
148 {
149 }
150 
151 // ---------------------------------------------------------------------------
152 
153 SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh)
154 : FmFormModel( SvtPathOptions().GetPalettePath(), NULL, pDrDocSh )
155 , mpOutliner(NULL)
156 , mpInternalOutliner(NULL)
157 , mpWorkStartupTimer(NULL)
158 , mpOnlineSpellingTimer(NULL)
159 , mpOnlineSpellingList(NULL)
160 , mpOnlineSearchItem(NULL)
161 , mpFrameViewList( new List() )
162 , mpCustomShowList(NULL)
163 , mpDocSh(static_cast< ::sd::DrawDocShell*>(pDrDocSh))
164 , mpCreatingTransferable( NULL )
165 , mbHasOnlineSpellErrors(sal_False)
166 , mbInitialOnlineSpellingEnabled(sal_True)
167 , mbNewOrLoadCompleted(sal_False)
168 , mbStartWithPresentation( false )
169 , meLanguage( LANGUAGE_SYSTEM )
170 , meLanguageCJK( LANGUAGE_SYSTEM )
171 , meLanguageCTL( LANGUAGE_SYSTEM )
172 , mePageNumType(SVX_ARABIC)
173 , mbAllocDocSh(sal_False)
174 , meDocType(eType)
175 , mpCharClass(NULL)
176 , mpLocale(NULL)
177 , mpDrawPageListWatcher(0)
178 , mpMasterPageListWatcher(0)
179 {
180 	// #109538#
181 	mpDrawPageListWatcher = ::std::auto_ptr<ImpDrawPageListWatcher>(
182         new ImpDrawPageListWatcher(*this));
183 	mpMasterPageListWatcher = ::std::auto_ptr<ImpMasterPageListWatcher>(
184         new ImpMasterPageListWatcher(*this));
185 
186 	SetObjectShell(pDrDocSh);		// fuer das VCDrawModel
187 
188 	if (mpDocSh)
189 	{
190 		SetSwapGraphics(sal_True);
191 	}
192 
193 	// Masseinheit (von App) und Massstab (von SdMod) setzen
194 	sal_Int32 nX, nY;
195 	SdOptions* pOptions = SD_MOD()->GetSdOptions(meDocType);
196 	pOptions->GetScale( nX, nY );
197 
198     // #92067# Allow UI scale only for draw documents.
199     if( eType == DOCUMENT_TYPE_DRAW )
200         SetUIUnit( (FieldUnit)pOptions->GetMetric(), Fraction( nX, nY ) );	// user-defined
201     else
202         SetUIUnit( (FieldUnit)pOptions->GetMetric(), Fraction( 1, 1 ) );	// default
203 
204 	SetScaleUnit(MAP_100TH_MM);
205 	SetScaleFraction(Fraction(1, 1));
206 	SetDefaultFontHeight(847);     // 24p
207 
208 	pItemPool->SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
209 	pItemPool->FreezeIdRanges();
210 	SetTextDefaults();
211 
212 	// die DrawingEngine muss auch wissen, wo er ist
213 	FmFormModel::SetStyleSheetPool( new SdStyleSheetPool( GetPool(), this ) );
214 
215 	// Dem DrawOutliner den StyleSheetPool setzen, damit Textobjekte richtig
216 	// eingelesen werden koennen. Der Link zum StyleRequest-Handler des
217 	// Dokuments wird erst in NewOrLoadCompleted gesetzt, da erst dann alle
218 	// Vorlagen existieren.
219 	SdrOutliner& rOutliner = GetDrawOutliner();
220 	rOutliner.SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
221 	SetCalcFieldValueHdl( &rOutliner );
222 
223 	// set linguistic options
224 	{
225         const SvtLinguConfig    aLinguConfig;
226 		SvtLinguOptions			aOptions;
227 		aLinguConfig.GetOptions( aOptions );
228 
229 		SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage,
230             ::com::sun::star::i18n::ScriptType::LATIN), EE_CHAR_LANGUAGE );
231 		SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CJK,
232             ::com::sun::star::i18n::ScriptType::ASIAN), EE_CHAR_LANGUAGE_CJK );
233 		SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CTL,
234             ::com::sun::star::i18n::ScriptType::COMPLEX), EE_CHAR_LANGUAGE_CTL );
235 
236 		mbOnlineSpell = aOptions.bIsSpellAuto;
237 	}
238 
239 	LanguageType eRealLanguage = MsLangId::getRealLanguage( meLanguage );
240 	mpLocale = new ::com::sun::star::lang::Locale( MsLangId::convertLanguageToLocale( eRealLanguage ));
241 	mpCharClass = new CharClass( *mpLocale );
242 
243 	// If the current application language is a language that uses right-to-left text...
244 	LanguageType eRealCTLLanguage = Application::GetSettings().GetLanguage();
245 	if( MsLangId::isRightToLeft( eRealCTLLanguage ) )
246 	{
247 		// ... then we have to set this as a default
248 		SetDefaultWritingMode( ::com::sun::star::text::WritingMode_RL_TB );
249 	}
250 
251 	// for korean and japanese languages we have a different default for apply spacing between asian, latin and ctl text
252 	if( ( LANGUAGE_KOREAN  == eRealCTLLanguage ) || ( LANGUAGE_KOREAN_JOHAB == eRealCTLLanguage ) || ( LANGUAGE_JAPANESE == eRealCTLLanguage ) )
253 	{
254         GetPool().GetSecondaryPool()->SetPoolDefaultItem( SvxScriptSpaceItem( sal_False, EE_PARA_ASIANCJKSPACING ) );
255 	}
256 
257 	// DefTab und SpellOptions setzen
258 	// Jetzt am Modul (SD)
259 	sal_uInt16 nDefTab = pOptions->GetDefTab();
260 	SetDefaultTabulator( nDefTab );
261 
262 	try
263 	{
264 	    Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
265 	    if ( xSpellChecker.is() )
266 		    rOutliner.SetSpeller( xSpellChecker );
267 
268 	    Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
269 	    if( xHyphenator.is() )
270 		    rOutliner.SetHyphenator( xHyphenator );
271 
272 		SetForbiddenCharsTable( new SvxForbiddenCharactersTable( ::comphelper::getProcessServiceFactory() ) );
273 	}
274 	catch(...)
275 	{
276 		DBG_ERROR("Can't get SpellChecker");
277 	}
278 
279 	rOutliner.SetDefaultLanguage( Application::GetSettings().GetLanguage() );
280 
281 	if (mpDocSh)
282 	{
283 		SetLinkManager( new sfx2::LinkManager(mpDocSh) );
284 	}
285 
286 	sal_uLong nCntrl = rOutliner.GetControlWord();
287 	nCntrl |= EE_CNTRL_ALLOWBIGOBJS;
288 	nCntrl |= EE_CNTRL_URLSFXEXECUTE;
289 
290 	if (mbOnlineSpell)
291 		nCntrl |= EE_CNTRL_ONLINESPELLING;
292 	else
293 		nCntrl &= ~EE_CNTRL_ONLINESPELLING;
294 
295 	nCntrl &= ~ EE_CNTRL_ULSPACESUMMATION;
296     if ( meDocType != DOCUMENT_TYPE_IMPRESS )
297         SetSummationOfParagraphs( sal_False );
298     else
299     {
300         SetSummationOfParagraphs( pOptions->IsSummationOfParagraphs() );
301     	if ( pOptions->IsSummationOfParagraphs() )
302 	    	nCntrl |= EE_CNTRL_ULSPACESUMMATION;
303     }
304 	rOutliner.SetControlWord(nCntrl);
305 
306     // Initialize the printer independent layout mode.
307     SetPrinterIndependentLayout (pOptions->GetPrinterIndependentLayout());
308 
309 	// Dem HitTestOutliner den StyleSheetPool setzen.
310 	// Der Link zum StyleRequest-Handler des
311 	// Dokuments wird erst in NewOrLoadCompleted gesetzt, da erst dann alle
312 	// Vorlagen existieren.
313 	SfxItemSet aSet2( pHitTestOutliner->GetEmptyItemSet() );
314 	pHitTestOutliner->SetStyleSheetPool( (SfxStyleSheetPool*)GetStyleSheetPool() );
315 
316 	SetCalcFieldValueHdl( pHitTestOutliner );
317 
318 	try
319 	{
320 	    Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
321 	    if ( xSpellChecker.is() )
322 		    pHitTestOutliner->SetSpeller( xSpellChecker );
323 
324 	    Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
325 	    if( xHyphenator.is() )
326 		    pHitTestOutliner->SetHyphenator( xHyphenator );
327 	}
328 	catch(...)
329 	{
330 		DBG_ERROR("Can't get SpellChecker");
331 	}
332 
333 	pHitTestOutliner->SetDefaultLanguage( Application::GetSettings().GetLanguage() );
334 
335 	sal_uLong nCntrl2 = pHitTestOutliner->GetControlWord();
336 	nCntrl2 |= EE_CNTRL_ALLOWBIGOBJS;
337 	nCntrl2 |= EE_CNTRL_URLSFXEXECUTE;
338 	nCntrl2 &= ~EE_CNTRL_ONLINESPELLING;
339 
340 	nCntrl2 &= ~ EE_CNTRL_ULSPACESUMMATION;
341 	if ( pOptions->IsSummationOfParagraphs() )
342 		nCntrl2 |= EE_CNTRL_ULSPACESUMMATION;
343 
344 	pHitTestOutliner->SetControlWord( nCntrl2 );
345 
346 	/**************************************************************************
347 	* Layer anlegen
348 	*
349 	* Es werden auf Pages und MasterPages folgende Default-Layer angelegt:
350 	*
351 	* Layer STR_LAYOUT	  : Standardlayer f�r alle Zeichenobjekte
352 	*
353 	* Layer STR_BCKGRND   : Hintergrund der MasterPage
354 	*						(auf normalen Pages z.Z. keine Verwendung)
355 	*
356 	* Layer STR_BCKGRNDOBJ: Objekte auf dem Hintergrund der MasterPage
357 	*						(auf normalen Pages z.Z. keine Verwendung)
358 	*
359 	* Layer STR_CONTROLS  : Standardlayer f�r Controls
360 	*
361 	**************************************************************************/
362 	{
363 		String aControlLayerName( SdResId(STR_LAYER_CONTROLS) );
364 
365 		SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
366 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_LAYOUT)) );
367 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_BCKGRND)) );
368 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_BCKGRNDOBJ)) );
369 		rLayerAdmin.NewLayer( aControlLayerName );
370 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_MEASURELINES)) );
371 
372 		rLayerAdmin.SetControlLayerName(aControlLayerName);
373 	}
374 
375 
376 }
377 
378 /*************************************************************************
379 |*
380 |* Destruktor
381 |*
382 \************************************************************************/
383 
384 SdDrawDocument::~SdDrawDocument()
385 {
386 	Broadcast(SdrHint(HINT_MODELCLEARED));
387 
388 	if (mpWorkStartupTimer)
389 	{
390 		if ( mpWorkStartupTimer->IsActive() )
391 			mpWorkStartupTimer->Stop();
392 
393 		delete mpWorkStartupTimer;
394 		mpWorkStartupTimer = NULL;
395 	}
396 
397 	StopOnlineSpelling();
398 	delete mpOnlineSearchItem;
399 	mpOnlineSearchItem = NULL;
400 
401 	CloseBookmarkDoc();
402 	SetAllocDocSh(sal_False);
403 
404 	// #116168#
405 	ClearModel(sal_True);
406 
407 	if (pLinkManager)
408 	{
409 		// BaseLinks freigeben
410 		if ( pLinkManager->GetLinks().Count() )
411 		{
412 			pLinkManager->Remove( 0, pLinkManager->GetLinks().Count() );
413 		}
414 
415 		delete pLinkManager;
416 		pLinkManager = NULL;
417 	}
418 
419 	::sd::FrameView* pFrameView = NULL;
420 
421 	for (sal_uLong i = 0; i < mpFrameViewList->Count(); i++)
422 	{
423 		// Ggf. FrameViews loeschen
424 		pFrameView =
425             static_cast< ::sd::FrameView*>(mpFrameViewList->GetObject(i));
426 
427 		if (pFrameView)
428 			delete pFrameView;
429 	}
430 
431 	delete mpFrameViewList;
432 	mpFrameViewList = NULL;
433 
434 	if (mpCustomShowList)
435 	{
436 		for (sal_uLong j = 0; j < mpCustomShowList->Count(); j++)
437 		{
438 			// Ggf. CustomShows loeschen
439 			SdCustomShow* pCustomShow = (SdCustomShow*) mpCustomShowList->GetObject(j);
440 			delete pCustomShow;
441 		}
442 
443 		delete mpCustomShowList;
444 		mpCustomShowList = NULL;
445 	}
446 
447 	delete mpOutliner;
448 	mpOutliner = NULL;
449 
450 	delete mpInternalOutliner;
451 	mpInternalOutliner = NULL;
452 
453 	delete mpLocale;
454 	mpLocale = NULL;
455 
456 	delete mpCharClass;
457 	mpCharClass = NULL;
458 }
459 
460 /*************************************************************************
461 |*
462 |* Diese Methode erzeugt ein neues Dokument (SdDrawDocument) und gibt einen
463 |* Zeiger darauf zurueck. Die Drawing Engine benutzt diese Methode um das
464 |* Dokument oder Teile davon ins Clipboard/DragServer stellen zu koennen.
465 |*
466 \************************************************************************/
467 
468 SdrModel* SdDrawDocument::AllocModel() const
469 {
470 	SdDrawDocument* pNewModel = NULL;
471 
472 	if( mpCreatingTransferable )
473 	{
474 		// Dokument wird fuer Drag&Drop/Clipboard erzeugt, dafuer muss dem Dokument eine DocShell (SvPersist) bekannt sein
475         SfxObjectShell*   pObj = NULL;
476 		::sd::DrawDocShell*		pNewDocSh = NULL;
477 
478     	if( meDocType == DOCUMENT_TYPE_IMPRESS )
479     		mpCreatingTransferable->SetDocShell( new ::sd::DrawDocShell(
480                 SFX_CREATE_MODE_EMBEDDED, sal_True, meDocType ) );
481 		else
482 	        mpCreatingTransferable->SetDocShell( new ::sd::GraphicDocShell(
483                 SFX_CREATE_MODE_EMBEDDED, sal_True, meDocType ) );
484 
485         pNewDocSh = static_cast< ::sd::DrawDocShell*>( pObj = mpCreatingTransferable->GetDocShell() );
486 		pNewDocSh->DoInitNew( NULL );
487 		pNewModel = pNewDocSh->GetDoc();
488 
489 		// Nur fuer Clipboard notwendig,
490 		// fuer Drag&Drop erfolgt dieses im DragServer
491 		SdStyleSheetPool* pOldStylePool = (SdStyleSheetPool*) GetStyleSheetPool();
492 		SdStyleSheetPool* pNewStylePool = (SdStyleSheetPool*) pNewModel->GetStyleSheetPool();
493 
494 		pNewStylePool->CopyGraphicSheets(*pOldStylePool);
495 		pNewStylePool->CopyCellSheets(*pOldStylePool);
496 		pNewStylePool->CopyTableStyles(*pOldStylePool);
497 
498 
499 		for (sal_uInt16 i = 0; i < GetMasterSdPageCount(PK_STANDARD); i++)
500 		{
501 			// Alle Layouts der MasterPage mitnehmen
502 			String aOldLayoutName(((SdDrawDocument*) this)->GetMasterSdPage(i, PK_STANDARD)->GetLayoutName());
503 			aOldLayoutName.Erase( aOldLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
504 			SdStyleSheetVector aCreatedSheets;
505 			pNewStylePool->CopyLayoutSheets(aOldLayoutName, *pOldStylePool, aCreatedSheets );
506 		}
507 
508 		pNewModel->NewOrLoadCompleted( DOC_LOADED );  // loaded from source document
509 	}
510 	else if( mbAllocDocSh )
511 	{
512 		// Es wird eine DocShell erzeugt, welche mit GetAllocedDocSh() zurueckgegeben wird
513 		SdDrawDocument* pDoc = (SdDrawDocument*) this;
514 		pDoc->SetAllocDocSh(sal_False);
515 		pDoc->mxAllocedDocShRef = new ::sd::DrawDocShell(
516             SFX_CREATE_MODE_EMBEDDED, sal_True, meDocType);
517 		pDoc->mxAllocedDocShRef->DoInitNew(NULL);
518 		pNewModel = pDoc->mxAllocedDocShRef->GetDoc();
519 	}
520 	else
521 	{
522 		pNewModel = new SdDrawDocument(meDocType, NULL);
523 	}
524 
525 	return pNewModel;
526 }
527 
528 /*************************************************************************
529 |*
530 |* Diese Methode erzeugt eine neue Seite (SdPage) und gibt einen Zeiger
531 |* darauf zurueck. Die Drawing Engine benutzt diese Methode beim Laden
532 |* zur Erzeugung von Seiten (deren Typ sie ja nicht kennt, da es ABLEITUNGEN
533 |* der SdrPage sind).
534 |*
535 \************************************************************************/
536 
537 SdrPage* SdDrawDocument::AllocPage(FASTBOOL bMasterPage)
538 {
539 	return new SdPage(*this, NULL, (sal_Bool)bMasterPage);
540 }
541 
542 /*************************************************************************
543 |*
544 |* SetChanged(), das Model wurde geaendert
545 |*
546 \************************************************************************/
547 
548 void SdDrawDocument::SetChanged(sal_Bool bFlag)
549 {
550 	if (mpDocSh)
551 	{
552 		if (mbNewOrLoadCompleted && mpDocSh->IsEnableSetModified())
553 		{
554 			// weitergeben an Basisklasse
555 			FmFormModel::SetChanged(bFlag);
556 
557 			// an ObjectShell weiterleiten
558 			mpDocSh->SetModified(bFlag);
559 		}
560 	}
561 	else
562 	{
563 		// weitergeben an Basisklasse
564 		FmFormModel::SetChanged(bFlag);
565 	}
566 }
567 
568 /*************************************************************************
569 |*
570 |* NbcSetChanged(), the model changed, don't call anybody else
571 |*
572 \************************************************************************/
573 
574 void SdDrawDocument::NbcSetChanged(sal_Bool bFlag)
575 {
576     // #100237# forward to baseclass
577     FmFormModel::SetChanged(bFlag);
578 }
579 
580 /*************************************************************************
581 |*
582 |* NewOrLoadCompleted
583 |*
584 |* Wird gerufen, wenn das Dokument geladen wurde bzw. feststeht, dass es
585 |* nicht mehr geladen wird.
586 |*
587 \************************************************************************/
588 
589 void SdDrawDocument::NewOrLoadCompleted(DocCreationMode eMode)
590 {
591 	if (eMode == NEW_DOC)
592 	{
593 		// Neues Dokument:
594 		// Praesentations- und Standardvorlagen erzeugen,
595 		// Pool fuer virtuelle Controls erzeugen
596 		CreateLayoutTemplates();
597 		CreateDefaultCellStyles();
598 
599 		static_cast< SdStyleSheetPool* >( mxStyleSheetPool.get() )->CreatePseudosIfNecessary();
600 	}
601 	else if (eMode == DOC_LOADED)
602 	{
603 			// Dokument wurde geladen:
604 
605 		CheckMasterPages();
606 
607 		if ( GetMasterSdPageCount(PK_STANDARD) > 1 )
608 			RemoveUnnecessaryMasterPages( NULL, sal_True, sal_False );
609 
610 		for ( sal_uInt16 i = 0; i < GetPageCount(); i++ )
611 		{
612 			// Check for correct layout names
613 			SdPage* pPage = (SdPage*) GetPage( i );
614 
615 			if(pPage->TRG_HasMasterPage())
616 			{
617 				SdPage& rMaster = (SdPage&)pPage->TRG_GetMasterPage();
618 
619 				if(rMaster.GetLayoutName() != pPage->GetLayoutName())
620 				{
621 					pPage->SetLayoutName(rMaster.GetLayoutName());
622 				}
623 			}
624 		}
625 
626 		for ( sal_uInt16 nPage = 0; nPage < GetMasterPageCount(); nPage++)
627 		{
628 			// LayoutName and PageName must be the same
629 			SdPage* pPage = (SdPage*) GetMasterPage( nPage );
630 
631 			String aName( pPage->GetLayoutName() );
632 			aName.Erase( aName.SearchAscii( SD_LT_SEPARATOR ) );
633 
634 			if( aName != pPage->GetName() )
635 				pPage->SetName( aName );
636 		}
637 
638 		// Sprachabhaengige Namen der StandardLayer erzeugen
639 		RestoreLayerNames();
640 
641 		// Sprachabhaengige Namen der Vorlagen setzen
642 		static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->UpdateStdNames();
643 
644 		// Ggf. fehlende Vorlagen erzeugen (es gab z.B. frueher keinen Subtitle)
645 		static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->CreatePseudosIfNecessary();
646 	}
647 
648 	// Standardvorlage an der Drawing Engine setzen
649 	String aName( SdResId(STR_STANDARD_STYLESHEET_NAME));
650 	SetDefaultStyleSheet(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(aName, SD_STYLE_FAMILY_GRAPHICS)));
651 
652 	// Draw-Outliner und  Dokument Outliner initialisieren,
653 	// aber nicht den globalen Outliner, den der ist ja nicht
654 	// dokumentspezifisch wie StyleSheetPool und StyleRequestHandler
655 	::Outliner& rDrawOutliner = GetDrawOutliner();
656 	rDrawOutliner.SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
657 	sal_uLong nCntrl = rDrawOutliner.GetControlWord();
658 	if (mbOnlineSpell)
659 		nCntrl |= EE_CNTRL_ONLINESPELLING;
660 	else
661 		nCntrl &= ~EE_CNTRL_ONLINESPELLING;
662 	rDrawOutliner.SetControlWord(nCntrl);
663 
664 	// HitTest-Outliner und  Dokument Outliner initialisieren,
665 	// aber nicht den globalen Outliner, den der ist ja nicht
666 	// dokumentspezifisch wie StyleSheetPool und StyleRequestHandler
667 	pHitTestOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
668 
669 	if(mpOutliner)
670 	{
671 		mpOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
672 	}
673 	if(mpInternalOutliner)
674 	{
675 		mpInternalOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
676 	}
677 
678 	if ( eMode == DOC_LOADED )
679 	{
680 		// Praesentationsobjekte muessen wieder Listener der entsprechenden
681 		// Vorlagen werden
682 		SdStyleSheetPool* pSPool = (SdStyleSheetPool*) GetStyleSheetPool();
683 		sal_uInt16 nPage, nPageCount;
684 
685 		// #96323# create missing layout style sheets for broken documents
686 		//		   that where created with the 5.2
687 		nPageCount = GetMasterSdPageCount( PK_STANDARD );
688 		for (nPage = 0; nPage < nPageCount; nPage++)
689 		{
690 			SdPage* pPage = GetMasterSdPage(nPage, PK_STANDARD);
691 			pSPool->CreateLayoutStyleSheets( pPage->GetName(), sal_True );
692 		}
693 
694 		// Standard- und Notizseiten:
695 		for (nPage = 0; nPage < GetPageCount(); nPage++)
696 		{
697 			SdPage* pPage = (SdPage*)GetPage(nPage);
698 			NewOrLoadCompleted( pPage, pSPool );
699 		}
700 
701 		// Masterpages:
702 		for (nPage = 0; nPage < GetMasterPageCount(); nPage++)
703 		{
704 			SdPage* pPage = (SdPage*)GetMasterPage(nPage);
705 
706 			NewOrLoadCompleted( pPage, pSPool );
707 		}
708 	}
709 
710 	mbNewOrLoadCompleted = sal_True;
711 
712 	/**************************************************************************
713 	* Alle gelinkten Pages aktualisieren
714 	**************************************************************************/
715 	SdPage* pPage = NULL;
716 	sal_uInt16 nMaxSdPages = GetSdPageCount(PK_STANDARD);
717 
718 	for (sal_uInt16 nSdPage=0; nSdPage < nMaxSdPages; nSdPage++)
719 	{
720 		pPage = (SdPage*) GetSdPage(nSdPage, PK_STANDARD);
721 
722 		if (pPage && pPage->GetFileName().Len() && pPage->GetBookmarkName().Len())
723 		{
724 			pPage->SetModel(this);
725 		}
726 	}
727 
728 	UpdateAllLinks();
729 
730 	SetChanged( sal_False );
731 }
732 
733 /** updates all links, only links in this document should by resolved */
734 void SdDrawDocument::UpdateAllLinks()
735 {
736 	if ( !pDocLockedInsertingLinks && pLinkManager && pLinkManager->GetLinks().Count() )
737 	{
738 		pDocLockedInsertingLinks = this; // lock inserting links. only links in this document should by resolved
739 
740 		pLinkManager->UpdateAllLinks();  // query box: update all links?
741 
742 		if( pDocLockedInsertingLinks == this )
743 			pDocLockedInsertingLinks = NULL;  // unlock inserting links
744 	}
745 }
746 
747 /** this loops over the presentation objectes of a page and repairs some new settings
748 	from old binary files and resets all default strings for empty presentation objects.
749 */
750 void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool )
751 {
752 /* cl removed because not needed anymore since binfilter
753 	SdrObjListIter aShapeIter( *pPage );
754 	while( aShapeIter.IsMore() )
755 	{
756 		OutlinerParaObject* pOPO = aShapeIter.Next()->GetOutlinerParaObject();
757 		if( pOPO )
758 		{
759 			if( pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
760 				pOPO->SetOutlinerMode( OUTLINERMODE_TEXTOBJECT );
761 
762 			pOPO->FinishLoad( pSPool );
763 		}
764 	}
765 */
766 
767 	const sd::ShapeList& rPresentationShapes( pPage->GetPresentationShapeList() );
768 	if(!rPresentationShapes.isEmpty())
769 	{
770 		// Listen mit Titel- und Gliederungsvorlagen erstellen
771 		String aName = pPage->GetLayoutName();
772 		aName.Erase( aName.SearchAscii( SD_LT_SEPARATOR ));
773 
774 		List* pOutlineList = pSPool->CreateOutlineSheetList(aName);
775 		SfxStyleSheet* pTitleSheet = (SfxStyleSheet*)
776 										pSPool->GetTitleSheet(aName);
777 
778 		SdrObject* pObj = rPresentationShapes.getNextShape(0);
779 
780 		// jetzt nach Titel- und Gliederungstextobjekten suchen und
781 		// Objekte zu Listenern machen
782 		while(pObj)
783 		{
784 			if (pObj->GetObjInventor() == SdrInventor)
785 			{
786 				OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
787 				sal_uInt16 nId = pObj->GetObjIdentifier();
788 
789 				if (nId == OBJ_TITLETEXT)
790 				{
791 					if( pOPO && pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
792 						pOPO->SetOutlinerMode( OUTLINERMODE_TITLEOBJECT );
793 
794 					// sal_True: harte Attribute dabei nicht loeschen
795 					if (pTitleSheet)
796 						pObj->SetStyleSheet(pTitleSheet, sal_True);
797 				}
798 				else if (nId == OBJ_OUTLINETEXT)
799 				{
800 					if( pOPO && pOPO->GetOutlinerMode() == OUTLINERMODE_DONTKNOW )
801 						pOPO->SetOutlinerMode( OUTLINERMODE_OUTLINEOBJECT );
802 
803 					for (sal_uInt16 nSheet = 0; nSheet < 10; nSheet++)
804 					{
805 						SfxStyleSheet* pSheet = (SfxStyleSheet*)pOutlineList->GetObject(nSheet);
806 						if (pSheet)
807 						{
808 							pObj->StartListening(*pSheet);
809 
810 							if( nSheet == 0)
811 								// Textrahmen hoert auf StyleSheet der Ebene1
812 								pObj->NbcSetStyleSheet(pSheet, sal_True);
813 						}
814 					}
815 				}
816 
817 				if (pObj->ISA(SdrTextObj) && pObj->IsEmptyPresObj() && pPage)
818 				{
819 					PresObjKind ePresObjKind = pPage->GetPresObjKind(pObj);
820 					String aString( pPage->GetPresObjText(ePresObjKind) );
821 
822 					if (aString.Len())
823 					{
824 						sd::Outliner* pInternalOutl = GetInternalOutliner(sal_True);
825 						pPage->SetObjText( (SdrTextObj*) pObj, pInternalOutl, ePresObjKind, aString );
826 						pObj->NbcSetStyleSheet( pPage->GetStyleSheetForPresObj( ePresObjKind ), sal_True );
827 						pInternalOutl->Clear();
828 					}
829 				}
830 			}
831 
832 			pObj = rPresentationShapes.getNextShape(pObj);
833 		}
834 
835 		delete pOutlineList;
836 	}
837 }
838 
839 /*************************************************************************
840 |*
841 |* Lokaler Outliner, welcher fuer den Gliederungsmodus verwendet wird
842 |* In diesen Outliner werden ggf. OutlinerViews inserted!
843 |*
844 \************************************************************************/
845 
846 ::sd::Outliner* SdDrawDocument::GetOutliner(sal_Bool bCreateOutliner)
847 {
848 	if (!mpOutliner && bCreateOutliner)
849 	{
850 		mpOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
851 
852 		if (mpDocSh)
853 			mpOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
854 
855 		mpOutliner->SetDefTab( nDefaultTabulator );
856 		mpOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
857 	}
858 
859 	return(mpOutliner);
860 }
861 
862 
863 /*************************************************************************
864 |*
865 |* Interner Outliner, welcher fuer die Erzeugung von Textobjekten
866 |* verwendet wird.
867 |* In diesen Outliner werden keine OutlinerViews inserted!
868 |*
869 \************************************************************************/
870 
871 ::sd::Outliner* SdDrawDocument::GetInternalOutliner(sal_Bool bCreateOutliner)
872 {
873 	if ( !mpInternalOutliner && bCreateOutliner )
874 	{
875 		mpInternalOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
876 		// MT:
877 		// Dieser Outliner wird nur fuer das Erzeugen spezieller Textobjekte
878 		// verwendet. Da in diesen Textobjekten keine Portion-Informationen
879 		// gespeichert werden muessen, kann/soll der Update-Mode immer sal_False bleiben.
880 		mpInternalOutliner->SetUpdateMode( sal_False );
881 		mpInternalOutliner->EnableUndo( sal_False );
882 
883 		if (mpDocSh)
884 			mpInternalOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
885 
886 		mpInternalOutliner->SetDefTab( nDefaultTabulator );
887 		mpInternalOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
888 	}
889 
890 	DBG_ASSERT( !mpInternalOutliner || ( mpInternalOutliner->GetUpdateMode() == sal_False ) , "InternalOutliner: UpdateMode = sal_True !" );
891 	DBG_ASSERT( !mpInternalOutliner || ( mpInternalOutliner->IsUndoEnabled() == sal_False ), "InternalOutliner: Undo = sal_True !" );
892 
893 	// MT: Wer ihn vollmuellt, macht ihn auch gleich wieder leer:
894 	// Vorteile:
895 	// a) Keine unnoetigen Clear-Aufrufe
896 	// b) Kein Muell im Speicher.
897 	DBG_ASSERT( !mpInternalOutliner || ( ( mpInternalOutliner->GetParagraphCount() == 1 ) && ( mpInternalOutliner->GetText( mpInternalOutliner->GetParagraph( 0 ) ).Len() == 0 ) ), "InternalOutliner: Nicht leer!" );
898 
899 	return mpInternalOutliner;
900 }
901 
902 /*************************************************************************
903 |*
904 |* OnlineSpelling ein/aus
905 |*
906 \************************************************************************/
907 
908 void SdDrawDocument::SetOnlineSpell(sal_Bool bIn)
909 {
910 	mbOnlineSpell = bIn;
911 	sal_uLong nCntrl = 0;
912 
913 	if(mpOutliner)
914 	{
915 		nCntrl = mpOutliner->GetControlWord();
916 
917 		if(mbOnlineSpell)
918 			nCntrl |= EE_CNTRL_ONLINESPELLING;
919 		else
920 			nCntrl &= ~EE_CNTRL_ONLINESPELLING;
921 
922 		mpOutliner->SetControlWord(nCntrl);
923 	}
924 
925 	if (mpInternalOutliner)
926 	{
927 		nCntrl = mpInternalOutliner->GetControlWord();
928 
929 		if (mbOnlineSpell)
930 			nCntrl |= EE_CNTRL_ONLINESPELLING;
931 		else
932 			nCntrl &= ~EE_CNTRL_ONLINESPELLING;
933 
934 		mpInternalOutliner->SetControlWord(nCntrl);
935 	}
936 
937 	::Outliner& rOutliner = GetDrawOutliner();
938 
939 	nCntrl = rOutliner.GetControlWord();
940 
941 	if (mbOnlineSpell)
942 		nCntrl |= EE_CNTRL_ONLINESPELLING;
943 	else
944 		nCntrl &= ~EE_CNTRL_ONLINESPELLING;
945 
946 	rOutliner.SetControlWord(nCntrl);
947 
948 	if (mbOnlineSpell)
949 	{
950 		StartOnlineSpelling();
951 	}
952 	else
953 	{
954 		StopOnlineSpelling();
955 	}
956 }
957 
958 
959 /*************************************************************************
960 |*
961 |* OnlineSpelling: Markierung ein/aus
962 |*
963 \************************************************************************/
964 
965 uno::Reference< uno::XInterface > SdDrawDocument::createUnoModel()
966 {
967 	uno::Reference< uno::XInterface > xModel;
968 
969 	try
970 	{
971 		if ( mpDocSh )
972 			xModel = mpDocSh->GetModel();
973 	}
974 	catch( uno::RuntimeException& )
975 	{
976 	}
977 
978 	return xModel;
979 }
980 
981 SvxNumType SdDrawDocument::GetPageNumType() const
982 {
983 	return mePageNumType;
984 }
985 
986 
987 
988 
989 void SdDrawDocument::SetPrinterIndependentLayout (sal_Int32 nMode)
990 {
991 	// #108104#
992     // DBG_ASSERT (mpDocSh!=NULL, "No available document shell to set ref device at.");
993 
994 	switch (nMode)
995     {
996         case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
997         case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
998             // Just store supported modes and inform the doc shell.
999             mnPrinterIndependentLayout = nMode;
1000 
1001 			// #108104#
1002 			// Since it is possible that a SdDrawDocument is constructed without a
1003 			// SdDrawDocShell the pointer member mpDocSh needs to be tested
1004 			// before the call is executed. This is e.-g. used for copy/paste.
1005 			if(mpDocSh)
1006 			{
1007 				mpDocSh->UpdateRefDevice ();
1008 			}
1009 
1010             break;
1011 
1012         default:
1013             // Ignore unknown values.
1014             break;
1015     }
1016 }
1017 
1018 sal_Int32 SdDrawDocument::GetPrinterIndependentLayout (void)
1019 {
1020     return mnPrinterIndependentLayout;
1021 }
1022 
1023 bool SdDrawDocument::IsStartWithPresentation() const
1024 {
1025 	return mbStartWithPresentation;
1026 }
1027 
1028 void SdDrawDocument::SetStartWithPresentation( bool bStartWithPresentation )
1029 {
1030 	mbStartWithPresentation = bStartWithPresentation;
1031 }
1032 
1033 // #109538#
1034 void SdDrawDocument::PageListChanged()
1035 {
1036 	mpDrawPageListWatcher->Invalidate();
1037 }
1038 
1039 // #109538#
1040 void SdDrawDocument::MasterPageListChanged()
1041 {
1042 	mpMasterPageListWatcher->Invalidate();
1043 }
1044 
1045 void SdDrawDocument::SetCalcFieldValueHdl(::Outliner* pOutliner)
1046 {
1047 	pOutliner->SetCalcFieldValueHdl(LINK(SD_MOD(), SdModule, CalcFieldValueHdl));
1048 }
1049 
1050 sal_uInt16 SdDrawDocument::GetAnnotationAuthorIndex( const rtl::OUString& rAuthor )
1051 {
1052     // force current user to have first color
1053     if( maAnnotationAuthors.empty() )
1054     {
1055         SvtUserOptions aUserOptions;
1056         maAnnotationAuthors.push_back( aUserOptions.GetFullName() );
1057     }
1058 
1059     sal_uInt16 idx = 0;
1060     for( std::vector< OUString >::iterator iter( maAnnotationAuthors.begin() ); iter != maAnnotationAuthors.end(); iter++ )
1061     {
1062         if( (*iter) == rAuthor )
1063         {
1064             break;
1065         }
1066         idx++;
1067     }
1068 
1069     if( idx == maAnnotationAuthors.size() )
1070     {
1071         maAnnotationAuthors.push_back( rAuthor );
1072     }
1073 
1074     return idx;
1075 }
1076 
1077 // eof
1078