xref: /trunk/main/sd/source/core/drawdoc.cxx (revision 1b9d1397)
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 
PresentationSettings()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 
PresentationSettings(const PresentationSettings & r)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 
SdDrawDocument(DocumentType eType,SfxObjectShell * pDrDocSh)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         sfx2::LinkManager *linkMgr = new sfx2::LinkManager(mpDocSh);
280         linkMgr->SetAutoAskUpdateAllLinks();
281 		SetLinkManager( linkMgr );
282 	}
283 
284 	sal_uLong nCntrl = rOutliner.GetControlWord();
285 	nCntrl |= EE_CNTRL_ALLOWBIGOBJS;
286 	nCntrl |= EE_CNTRL_URLSFXEXECUTE;
287 
288 	if (mbOnlineSpell)
289 		nCntrl |= EE_CNTRL_ONLINESPELLING;
290 	else
291 		nCntrl &= ~EE_CNTRL_ONLINESPELLING;
292 
293 	nCntrl &= ~ EE_CNTRL_ULSPACESUMMATION;
294     if ( meDocType != DOCUMENT_TYPE_IMPRESS )
295         SetSummationOfParagraphs( sal_False );
296     else
297     {
298         SetSummationOfParagraphs( pOptions->IsSummationOfParagraphs() );
299     	if ( pOptions->IsSummationOfParagraphs() )
300 	    	nCntrl |= EE_CNTRL_ULSPACESUMMATION;
301     }
302 	rOutliner.SetControlWord(nCntrl);
303 
304     // Initialize the printer independent layout mode.
305     SetPrinterIndependentLayout (pOptions->GetPrinterIndependentLayout());
306 
307 	// Set the StyleSheetPool to the HitTestOutliner.
308 	// The link to the StyleRequest handler of the document will be set
309 	// first in NewOrLoadCompleted, because only then all templates exist.
310 	SfxItemSet aSet2( pHitTestOutliner->GetEmptyItemSet() );
311 	pHitTestOutliner->SetStyleSheetPool( (SfxStyleSheetPool*)GetStyleSheetPool() );
312 
313 	SetCalcFieldValueHdl( pHitTestOutliner );
314 
315 	try
316 	{
317 	    Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
318 	    if ( xSpellChecker.is() )
319 		    pHitTestOutliner->SetSpeller( xSpellChecker );
320 
321 	    Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
322 	    if( xHyphenator.is() )
323 		    pHitTestOutliner->SetHyphenator( xHyphenator );
324 	}
325 	catch(...)
326 	{
327 		DBG_ERROR("Can't get SpellChecker");
328 	}
329 
330 	pHitTestOutliner->SetDefaultLanguage( Application::GetSettings().GetLanguage() );
331 
332 	sal_uLong nCntrl2 = pHitTestOutliner->GetControlWord();
333 	nCntrl2 |= EE_CNTRL_ALLOWBIGOBJS;
334 	nCntrl2 |= EE_CNTRL_URLSFXEXECUTE;
335 	nCntrl2 &= ~EE_CNTRL_ONLINESPELLING;
336 
337 	nCntrl2 &= ~ EE_CNTRL_ULSPACESUMMATION;
338 	if ( pOptions->IsSummationOfParagraphs() )
339 		nCntrl2 |= EE_CNTRL_ULSPACESUMMATION;
340 
341 	pHitTestOutliner->SetControlWord( nCntrl2 );
342 
343 	/**************************************************************************
344 	* Create layer
345 	*
346 	* The following default layer will created on Pages and MasterPages:
347 	*
348 	* Layer STR_LAYOUT	: Default layer for all drawing objects
349 	*
350 	* Layer STR_BCKGRND	: Background of the MasterPage
351 	*			  (it's currently not used on normal Pages)
352 	*
353 	* Layer STR_BCKGRNDOBJ	: Objects on the background of the MasterPage
354 	*			  (it's currently not used on normal Pages)
355 	*
356 	* Layer STR_CONTROLS 	: Default layer for Controls
357 	*
358 	**************************************************************************/
359 	{
360 		String aControlLayerName( SdResId(STR_LAYER_CONTROLS) );
361 
362 		SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
363 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_LAYOUT)) );
364 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_BCKGRND)) );
365 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_BCKGRNDOBJ)) );
366 		rLayerAdmin.NewLayer( aControlLayerName );
367 		rLayerAdmin.NewLayer( String(SdResId(STR_LAYER_MEASURELINES)) );
368 
369 		rLayerAdmin.SetControlLayerName(aControlLayerName);
370 	}
371 
372 
373 }
374 
375 /*************************************************************************
376 |*
377 |* Destructor
378 |*
379 \************************************************************************/
380 
~SdDrawDocument()381 SdDrawDocument::~SdDrawDocument()
382 {
383 	Broadcast(SdrHint(HINT_MODELCLEARED));
384 
385 	if (mpWorkStartupTimer)
386 	{
387 		if ( mpWorkStartupTimer->IsActive() )
388 			mpWorkStartupTimer->Stop();
389 
390 		delete mpWorkStartupTimer;
391 		mpWorkStartupTimer = NULL;
392 	}
393 
394 	StopOnlineSpelling();
395 	delete mpOnlineSearchItem;
396 	mpOnlineSearchItem = NULL;
397 
398 	CloseBookmarkDoc();
399 	SetAllocDocSh(sal_False);
400 
401 	// #116168#
402 	ClearModel(sal_True);
403 
404 	if (pLinkManager)
405 	{
406 		// deallocate BaseLinks
407 		if ( pLinkManager->GetLinks().Count() )
408 		{
409 			pLinkManager->Remove( 0, pLinkManager->GetLinks().Count() );
410 		}
411 
412 		delete pLinkManager;
413 		pLinkManager = NULL;
414 	}
415 
416 	::sd::FrameView* pFrameView = NULL;
417 
418 	for (sal_uLong i = 0; i < mpFrameViewList->Count(); i++)
419 	{
420 		// if necessary delete FrameViews
421 		pFrameView =
422             static_cast< ::sd::FrameView*>(mpFrameViewList->GetObject(i));
423 
424 		if (pFrameView)
425 			delete pFrameView;
426 	}
427 
428 	delete mpFrameViewList;
429 	mpFrameViewList = NULL;
430 
431 	if (mpCustomShowList)
432 	{
433 		for (sal_uLong j = 0; j < mpCustomShowList->Count(); j++)
434 		{
435 			// if necessary delete CustomShows
436 			SdCustomShow* pCustomShow = (SdCustomShow*) mpCustomShowList->GetObject(j);
437 			delete pCustomShow;
438 		}
439 
440 		delete mpCustomShowList;
441 		mpCustomShowList = NULL;
442 	}
443 
444 	delete mpOutliner;
445 	mpOutliner = NULL;
446 
447 	delete mpInternalOutliner;
448 	mpInternalOutliner = NULL;
449 
450 	delete mpLocale;
451 	mpLocale = NULL;
452 
453 	delete mpCharClass;
454 	mpCharClass = NULL;
455 }
456 
457 /*************************************************************************
458 |*
459 |* This methods creates a new document (SdDrawDocument) and gives back a
460 |* pointer to it. The Drawing Engine uses this method to be able to put
461 |* the document or parts of it into Clipboard/DragServer.
462 |*
463 \************************************************************************/
464 
AllocModel() const465 SdrModel* SdDrawDocument::AllocModel() const
466 {
467 	SdDrawDocument* pNewModel = NULL;
468 
469 	if( mpCreatingTransferable )
470 	{
471 		// the document will created for Drag&Drop/Clipboard,
472 		// for this the document has to know a DocShell (SvPersist)
473         SfxObjectShell*   pObj = NULL;
474 		::sd::DrawDocShell*		pNewDocSh = NULL;
475 
476     	if( meDocType == DOCUMENT_TYPE_IMPRESS )
477     		mpCreatingTransferable->SetDocShell( new ::sd::DrawDocShell(
478                 SFX_CREATE_MODE_EMBEDDED, sal_True, meDocType ) );
479 		else
480 	        mpCreatingTransferable->SetDocShell( new ::sd::GraphicDocShell(
481                 SFX_CREATE_MODE_EMBEDDED, sal_True, meDocType ) );
482 
483         pNewDocSh = static_cast< ::sd::DrawDocShell*>( pObj = mpCreatingTransferable->GetDocShell() );
484 		pNewDocSh->DoInitNew( NULL );
485 		pNewModel = pNewDocSh->GetDoc();
486 
487 		// only necessary for Clipboard,
488 		// for Drag&Drop this will happen in DragServer
489 		SdStyleSheetPool* pOldStylePool = (SdStyleSheetPool*) GetStyleSheetPool();
490 		SdStyleSheetPool* pNewStylePool = (SdStyleSheetPool*) pNewModel->GetStyleSheetPool();
491 
492 		pNewStylePool->CopyGraphicSheets(*pOldStylePool);
493 		pNewStylePool->CopyCellSheets(*pOldStylePool);
494 		pNewStylePool->CopyTableStyles(*pOldStylePool);
495 
496 
497 		for (sal_uInt16 i = 0; i < GetMasterSdPageCount(PK_STANDARD); i++)
498 		{
499 			// take all layouts of the MasterPage
500 			String aOldLayoutName(((SdDrawDocument*) this)->GetMasterSdPage(i, PK_STANDARD)->GetLayoutName());
501 			aOldLayoutName.Erase( aOldLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
502 			SdStyleSheetVector aCreatedSheets;
503 			pNewStylePool->CopyLayoutSheets(aOldLayoutName, *pOldStylePool, aCreatedSheets );
504 		}
505 
506 		pNewModel->NewOrLoadCompleted( DOC_LOADED );  // loaded from source document
507 	}
508 	else if( mbAllocDocSh )
509 	{
510 		// a DocShell will be created which will be returned with GetAllocedDocSh()
511 		SdDrawDocument* pDoc = (SdDrawDocument*) this;
512 		pDoc->SetAllocDocSh(sal_False);
513 		pDoc->mxAllocedDocShRef = new ::sd::DrawDocShell(
514             SFX_CREATE_MODE_EMBEDDED, sal_True, meDocType);
515 		pDoc->mxAllocedDocShRef->DoInitNew(NULL);
516 		pNewModel = pDoc->mxAllocedDocShRef->GetDoc();
517 	}
518 	else
519 	{
520 		pNewModel = new SdDrawDocument(meDocType, NULL);
521 	}
522 
523 	return pNewModel;
524 }
525 
526 /*************************************************************************
527 |*
528 |* This methods creates a new page (SdPage) and gives back a pointer to it.
529 |* The Drawing Engine uses this method when loading to create pages (whose
530 |* types are not knowed for it because these are DERIVATIONS of SdrPage).
531 |*
532 \************************************************************************/
533 
AllocPage(FASTBOOL bMasterPage)534 SdrPage* SdDrawDocument::AllocPage(FASTBOOL bMasterPage)
535 {
536 	return new SdPage(*this, NULL, (sal_Bool)bMasterPage);
537 }
538 
539 /*************************************************************************
540 |*
541 |* SetChanged(), the modele was changed
542 |*
543 \************************************************************************/
544 
SetChanged(sal_Bool bFlag)545 void SdDrawDocument::SetChanged(sal_Bool bFlag)
546 {
547 	if (mpDocSh)
548 	{
549 		if (mbNewOrLoadCompleted && mpDocSh->IsEnableSetModified())
550 		{
551 			// forward to baseclass
552 			FmFormModel::SetChanged(bFlag);
553 
554 			// pass to ObjectShell
555 			mpDocSh->SetModified(bFlag);
556 		}
557 	}
558 	else
559 	{
560 		// forward to baseclass
561 		FmFormModel::SetChanged(bFlag);
562 	}
563 }
564 
565 /*************************************************************************
566 |*
567 |* NbcSetChanged(), the model changed, don't call anybody else
568 |*
569 \************************************************************************/
570 
NbcSetChanged(sal_Bool bFlag)571 void SdDrawDocument::NbcSetChanged(sal_Bool bFlag)
572 {
573     // #100237# forward to baseclass
574     FmFormModel::SetChanged(bFlag);
575 }
576 
577 /*************************************************************************
578 |*
579 |* NewOrLoadCompleted
580 |*
581 |* Will be called when the document was loaded respectively when it is
582 |* certain that it will not be loaded any longer.
583 |*
584 \************************************************************************/
585 
NewOrLoadCompleted(DocCreationMode eMode)586 void SdDrawDocument::NewOrLoadCompleted(DocCreationMode eMode)
587 {
588 	if (eMode == NEW_DOC)
589 	{
590 		// new document:
591 		// create Presentation and default templates,
592 		// create pool for virtual controls
593 		CreateLayoutTemplates();
594 		CreateDefaultCellStyles();
595 
596 		static_cast< SdStyleSheetPool* >( mxStyleSheetPool.get() )->CreatePseudosIfNecessary();
597 	}
598 	else if (eMode == DOC_LOADED)
599 	{
600 			// document was loaded:
601 
602 		CheckMasterPages();
603 
604 		if ( GetMasterSdPageCount(PK_STANDARD) > 1 )
605 			RemoveUnnecessaryMasterPages( NULL, sal_True, sal_False );
606 
607 		for ( sal_uInt16 i = 0; i < GetPageCount(); i++ )
608 		{
609 			// Check for correct layout names
610 			SdPage* pPage = (SdPage*) GetPage( i );
611 
612 			if(pPage->TRG_HasMasterPage())
613 			{
614 				SdPage& rMaster = (SdPage&)pPage->TRG_GetMasterPage();
615 
616 				if(rMaster.GetLayoutName() != pPage->GetLayoutName())
617 				{
618 					pPage->SetLayoutName(rMaster.GetLayoutName());
619 				}
620 			}
621 		}
622 
623 		for ( sal_uInt16 nPage = 0; nPage < GetMasterPageCount(); nPage++)
624 		{
625 			// LayoutName and PageName must be the same
626 			SdPage* pPage = (SdPage*) GetMasterPage( nPage );
627 
628 			String aName( pPage->GetLayoutName() );
629 			aName.Erase( aName.SearchAscii( SD_LT_SEPARATOR ) );
630 
631 			if( aName != pPage->GetName() )
632 				pPage->SetName( aName );
633 		}
634 
635 		// create language-dependent names of the default layer
636 		RestoreLayerNames();
637 
638 		// set language-dependent names of the templates
639 		static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->UpdateStdNames();
640 
641 		// if necessary create missing templates (e.g., formerly there was no Subtitle)
642 		static_cast<SdStyleSheetPool*>(mxStyleSheetPool.get())->CreatePseudosIfNecessary();
643 	}
644 
645 	// set default template at the Drawing Engine
646 	String aName( SdResId(STR_STANDARD_STYLESHEET_NAME));
647 	SetDefaultStyleSheet(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(aName, SD_STYLE_FAMILY_GRAPHICS)));
648 
649     // #119287# Set default StyleSheet for SdrGrafObj and SdrOle2Obj
650 	SetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(static_cast<SfxStyleSheet*>(mxStyleSheetPool->Find(String( SdResId(STR_POOLSHEET_OBJNOLINENOFILL)), SD_STYLE_FAMILY_GRAPHICS)));
651 
652 	// initialize Draw-Outliner and Document Outliner,
653 	// but not the global Outliner because it is not document-specific
654 	// like StyleSheetPool and 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 	// initialize HitTest-Outliner and Document Outliner,
665 	// but not the global Outliner because it is not document-specific
666 	// like StyleSheetPool and 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 		// presentation objects have to be Listener again of the respective templates
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 		// Default and note pages:
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 	* Update all linked Pages
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 */
UpdateAllLinks()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 */
NewOrLoadCompleted(SdPage * pPage,SdStyleSheetPool * pSPool)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 		// create lists with title and outline templates
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 		// now search for title and outline text objects and
780 		// change objects into Listener
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: in doing so do not delete hard attributes
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 								// text frame listen to StyleSheet of Layer1
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 |* Local Outliner that is used for the outline mode.
841 |* If necessary, insert OutlinerViews into this outliner !
842 |*
843 \************************************************************************/
844 
GetOutliner(sal_Bool bCreateOutliner)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 |* Internal Outliner that is used for creating text objects.
865 |* No OutlinerViews will be inserted into this Outliner!
866 |*
867 \************************************************************************/
868 
GetInternalOutliner(sal_Bool bCreateOutliner)869 ::sd::Outliner* SdDrawDocument::GetInternalOutliner(sal_Bool bCreateOutliner)
870 {
871 	if ( !mpInternalOutliner && bCreateOutliner )
872 	{
873 		mpInternalOutliner = new ::sd::Outliner( this, OUTLINERMODE_TEXTOBJECT );
874 		// MT:
875 		// This Outliner is used to create special text objects only.
876 		// As no portion information have to be saved in these text objects,
877 		// the update mode can/should stay always sal_False.
878 		mpInternalOutliner->SetUpdateMode( sal_False );
879 		mpInternalOutliner->EnableUndo( sal_False );
880 
881 		if (mpDocSh)
882 			mpInternalOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
883 
884 		mpInternalOutliner->SetDefTab( nDefaultTabulator );
885 		mpInternalOutliner->SetStyleSheetPool((SfxStyleSheetPool*)GetStyleSheetPool());
886 	}
887 
888 	DBG_ASSERT( !mpInternalOutliner || ( mpInternalOutliner->GetUpdateMode() == sal_False ) , "InternalOutliner: UpdateMode = sal_True !" );
889 	DBG_ASSERT( !mpInternalOutliner || ( mpInternalOutliner->IsUndoEnabled() == sal_False ), "InternalOutliner: Undo = sal_True !" );
890 
891 	// MT: Who fills it with spam has to empty it right after:
892 	// Advantages:
893 	// a) No uncessary clear calls.
894 	// b) No spam in memory.
895 	DBG_ASSERT( !mpInternalOutliner || ( ( mpInternalOutliner->GetParagraphCount() == 1 ) && ( mpInternalOutliner->GetText( mpInternalOutliner->GetParagraph( 0 ) ).Len() == 0 ) ), "InternalOutliner: Nicht leer!" );
896 
897 	return mpInternalOutliner;
898 }
899 
900 /*************************************************************************
901 |*
902 |* OnlineSpelling on/off
903 |*
904 \************************************************************************/
905 
SetOnlineSpell(sal_Bool bIn)906 void SdDrawDocument::SetOnlineSpell(sal_Bool bIn)
907 {
908 	mbOnlineSpell = bIn;
909 	sal_uLong nCntrl = 0;
910 
911 	if(mpOutliner)
912 	{
913 		nCntrl = mpOutliner->GetControlWord();
914 
915 		if(mbOnlineSpell)
916 			nCntrl |= EE_CNTRL_ONLINESPELLING;
917 		else
918 			nCntrl &= ~EE_CNTRL_ONLINESPELLING;
919 
920 		mpOutliner->SetControlWord(nCntrl);
921 	}
922 
923 	if (mpInternalOutliner)
924 	{
925 		nCntrl = mpInternalOutliner->GetControlWord();
926 
927 		if (mbOnlineSpell)
928 			nCntrl |= EE_CNTRL_ONLINESPELLING;
929 		else
930 			nCntrl &= ~EE_CNTRL_ONLINESPELLING;
931 
932 		mpInternalOutliner->SetControlWord(nCntrl);
933 	}
934 
935 	::Outliner& rOutliner = GetDrawOutliner();
936 
937 	nCntrl = rOutliner.GetControlWord();
938 
939 	if (mbOnlineSpell)
940 		nCntrl |= EE_CNTRL_ONLINESPELLING;
941 	else
942 		nCntrl &= ~EE_CNTRL_ONLINESPELLING;
943 
944 	rOutliner.SetControlWord(nCntrl);
945 
946 	if (mbOnlineSpell)
947 	{
948 		StartOnlineSpelling();
949 	}
950 	else
951 	{
952 		StopOnlineSpelling();
953 	}
954 }
955 
956 
957 /*************************************************************************
958 |*
959 |* OnlineSpelling: Marking on/off
960 |*
961 \************************************************************************/
962 
createUnoModel()963 uno::Reference< uno::XInterface > SdDrawDocument::createUnoModel()
964 {
965 	uno::Reference< uno::XInterface > xModel;
966 
967 	try
968 	{
969 		if ( mpDocSh )
970 			xModel = mpDocSh->GetModel();
971 	}
972 	catch( uno::RuntimeException& )
973 	{
974 	}
975 
976 	return xModel;
977 }
978 
GetPageNumType() const979 SvxNumType SdDrawDocument::GetPageNumType() const
980 {
981 	return mePageNumType;
982 }
983 
984 
985 
986 
SetPrinterIndependentLayout(sal_Int32 nMode)987 void SdDrawDocument::SetPrinterIndependentLayout (sal_Int32 nMode)
988 {
989 	// #108104#
990     // DBG_ASSERT (mpDocSh!=NULL, "No available document shell to set ref device at.");
991 
992 	switch (nMode)
993     {
994         case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
995         case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
996             // Just store supported modes and inform the doc shell.
997             mnPrinterIndependentLayout = nMode;
998 
999 			// #108104#
1000 			// Since it is possible that a SdDrawDocument is constructed without a
1001 			// SdDrawDocShell the pointer member mpDocSh needs to be tested
1002 			// before the call is executed. This is e.-g. used for copy/paste.
1003 			if(mpDocSh)
1004 			{
1005 				mpDocSh->UpdateRefDevice ();
1006 			}
1007 
1008             break;
1009 
1010         default:
1011             // Ignore unknown values.
1012             break;
1013     }
1014 }
1015 
GetPrinterIndependentLayout(void)1016 sal_Int32 SdDrawDocument::GetPrinterIndependentLayout (void)
1017 {
1018     return mnPrinterIndependentLayout;
1019 }
1020 
IsStartWithPresentation() const1021 bool SdDrawDocument::IsStartWithPresentation() const
1022 {
1023 	return mbStartWithPresentation;
1024 }
1025 
SetStartWithPresentation(bool bStartWithPresentation)1026 void SdDrawDocument::SetStartWithPresentation( bool bStartWithPresentation )
1027 {
1028 	mbStartWithPresentation = bStartWithPresentation;
1029 }
1030 
1031 // #109538#
PageListChanged()1032 void SdDrawDocument::PageListChanged()
1033 {
1034 	mpDrawPageListWatcher->Invalidate();
1035 }
1036 
1037 // #109538#
MasterPageListChanged()1038 void SdDrawDocument::MasterPageListChanged()
1039 {
1040 	mpMasterPageListWatcher->Invalidate();
1041 }
1042 
SetCalcFieldValueHdl(::Outliner * pOutliner)1043 void SdDrawDocument::SetCalcFieldValueHdl(::Outliner* pOutliner)
1044 {
1045 	pOutliner->SetCalcFieldValueHdl(LINK(SD_MOD(), SdModule, CalcFieldValueHdl));
1046 }
1047 
GetAnnotationAuthorIndex(const rtl::OUString & rAuthor)1048 sal_uInt16 SdDrawDocument::GetAnnotationAuthorIndex( const rtl::OUString& rAuthor )
1049 {
1050     // force current user to have first color
1051     if( maAnnotationAuthors.empty() )
1052     {
1053         SvtUserOptions aUserOptions;
1054         maAnnotationAuthors.push_back( aUserOptions.GetFullName() );
1055     }
1056 
1057     sal_uInt16 idx = 0;
1058     for( std::vector< OUString >::iterator iter( maAnnotationAuthors.begin() ); iter != maAnnotationAuthors.end(); iter++ )
1059     {
1060         if( (*iter) == rAuthor )
1061         {
1062             break;
1063         }
1064         idx++;
1065     }
1066 
1067     if( idx == maAnnotationAuthors.size() )
1068     {
1069         maAnnotationAuthors.push_back( rAuthor );
1070     }
1071 
1072     return idx;
1073 }
1074 
1075 // eof
1076