xref: /trunk/main/sd/source/ui/app/sdmod2.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 #include <editeng/eeitem.hxx>
31 #include <editeng/flditem.hxx>
32 #include <sfx2/printer.hxx>
33 #include <svl/inethist.hxx>
34 #include <svl/poolitem.hxx>
35 #include <svl/flagitem.hxx>
36 #include <unotools/useroptions.hxx>
37 #include <sfx2/bindings.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <sfx2/request.hxx>
42 
43 #include <editeng/measfld.hxx>
44 #include <editeng/editstat.hxx>
45 #include <editeng/editeng.hxx>
46 
47 #include <svx/dialogs.hrc>
48 #include <svx/svdotext.hxx>
49 #include <svx/svdpagv.hxx>
50 #include <svx/svdopage.hxx>
51 
52 #include <sfx2/sfxdlg.hxx>
53 
54 
55 #include <svx/sdr/contact/displayinfo.hxx>
56 
57 #define _SD_DLL                 // fuer SD_MOD()
58 #include "sdmod.hxx"
59 #include "sddll.hxx"
60 #include "app.hrc"
61 #include "glob.hrc"
62 #include "strings.hrc"
63 #include "res_bmp.hrc"
64 #include "ViewShell.hxx"
65 #ifndef SD_FRAMW_VIEW_HXX
66 #include "FrameView.hxx"
67 #endif
68 #include "sdattr.hxx"
69 #include "tpoption.hrc"
70 #include "optsitem.hxx"
71 #include "DrawDocShell.hxx"
72 #include "drawdoc.hxx"
73 #include "Outliner.hxx"
74 #include "sdresid.hxx"
75 #include "pres.hxx"
76 #include "DrawViewShell.hxx"
77 #include "OutlineViewShell.hxx"
78 #include "OutlineView.hxx"
79 #include "ViewShellBase.hxx"
80 #include "sdpage.hxx"
81 #include "sdxfer.hxx"
82 #include "sdabstdlg.hxx"
83 #include "tpoption.hrc"
84 #include "prntopts.hrc"
85 #include <svl/intitem.hxx>
86 
87 /** retrieves the page that is currently painted. This will only be the master page
88 	if the current drawn view only shows the master page*/
89 static SdPage* GetCurrentPage( sd::ViewShell* pViewSh, EditFieldInfo* pInfo, bool& bMasterView )
90 {
91 	if( !pInfo )
92 		return 0;
93 
94 	bMasterView = false;
95 	SdPage* pPage = dynamic_cast< SdPage* >( pInfo->GetSdrPage() );
96 	SdrOutliner* pOutliner = dynamic_cast< SdrOutliner* >( pInfo->GetOutliner() );
97 
98 	// special case, someone already set the current page on the EditFieldInfo
99 	// This is used from the svx::UnoGraphicsExporter f.e.
100 	if( pPage )
101 	{
102 		bMasterView = false;
103 		return pPage;
104 	}
105 
106 	// first try to check if we are inside the outline view
107 	sd::OutlineView* pSdView = NULL;
108 	if( pViewSh && pViewSh->ISA(sd::OutlineViewShell))
109 		pSdView = static_cast<sd::OutlineView*> (static_cast<sd::OutlineViewShell*>(pViewSh)->GetView());
110 
111 	if (pSdView != NULL && (pOutliner ==  pSdView->GetOutliner()))
112     {
113         // outline mode
114         int nPgNum = 0;
115         Outliner* pOutl = pSdView->GetOutliner();
116         long nPos = pInfo->GetPara();
117         sal_uLong nParaPos = 0;
118 
119         for( Paragraph* pPara = pOutl->GetParagraph( 0 ); pPara && nPos >= 0; pPara = pOutl->GetParagraph( ++nParaPos ), nPos-- )
120         {
121             if( pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
122                 nPgNum++;
123         }
124 
125 		pPage = pViewSh->GetDoc()->GetSdPage( (sal_uInt16)nPgNum, PK_STANDARD );
126 	}
127 	else
128 	{
129 		// draw mode, slide mode and preview. Get the processed page from the outliner
130 		if(pOutliner)
131 		{
132 			pPage = dynamic_cast< SdPage* >(const_cast< SdrPage* >(pOutliner->getVisualizedPage()));
133 		}
134 
135 		// The path using GetPaintingPageView() and GetCurrentPaintingDisplayInfo()
136 		// is no longer needed. I debugged and checked all usages of PageNumber decompositions
137 		// which all use the new possibility of setting the visualized page at the SdrOutliner.
138 
139 		// if all else failed, geht the current page from the object that is
140 		// currently formated from the document
141 		if(!pPage)
142 		{
143 			const SdrTextObj* pTextObj = (pViewSh && pViewSh->GetDoc()) ? pViewSh->GetDoc()->GetFormattingTextObj() : NULL;
144 
145 			if( pTextObj )
146 			{
147 				pPage = dynamic_cast< SdPage* >( pTextObj->GetPage() );
148 			}
149 		}
150 
151 		if(pPage)
152 		{
153 			bMasterView = pPage && pPage->IsMasterPage();
154 		}
155 	}
156 
157 	return pPage;
158 }
159 
160 /*************************************************************************
161 |*
162 |* Link fuer CalcFieldValue des Outliners
163 |*
164 \************************************************************************/
165 
166 IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, pInfo)
167 {
168 	if (pInfo)
169 	{
170 		const SvxFieldData* pField = pInfo->GetField().GetField();
171         ::sd::DrawDocShell*     pDocShell = NULL;
172 		SdDrawDocument* pDoc = 0;
173 
174 		SdrOutliner* pSdrOutliner = dynamic_cast< SdrOutliner* >( pInfo->GetOutliner() );
175         if( pSdrOutliner )
176         {
177             const SdrTextObj* pTextObj = pSdrOutliner->GetTextObj();
178 
179 			if( pTextObj )
180 				pDoc = dynamic_cast< SdDrawDocument* >( pTextObj->GetModel() );
181 
182 			if( pDoc )
183                 pDocShell = pDoc->GetDocSh();
184         }
185 
186         if( !pDocShell )
187             pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
188 
189 		const SvxDateField* pDateField = 0;
190 		const SvxExtTimeField* pExtTimeField = 0;
191 		const SvxExtFileField* pExtFileField = 0;
192 		const SvxAuthorField* pAuthorField = 0;
193 		const SvxURLField* pURLField = 0;
194 
195 		if( (pDateField = dynamic_cast< const SvxDateField* >(pField)) != 0 )
196 		{
197 			LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
198 			pInfo->SetRepresentation( pDateField->GetFormatted( *GetNumberFormatter(), eLang ) );
199 		}
200 		else if( (pExtTimeField = dynamic_cast< const SvxExtTimeField *>(pField)) != 0 )
201 		{
202 			LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
203 			pInfo->SetRepresentation( pExtTimeField->GetFormatted( *GetNumberFormatter(), eLang ) );
204 		}
205 		else if( (pExtFileField = dynamic_cast< const SvxExtFileField * >(pField)) != 0 )
206 		{
207 			if( pDocShell && (pExtFileField->GetType() != SVXFILETYPE_FIX) )
208 			{
209 				String aName;
210 				if( pDocShell->HasName() )
211 					aName = pDocShell->GetMedium()->GetName();
212 				else
213 					aName = pDocShell->GetName();
214 
215 				const_cast< SvxExtFileField* >(pExtFileField)->SetFile( aName );
216 			}
217 			pInfo->SetRepresentation( pExtFileField->GetFormatted() );
218 
219 		}
220 		else if( (pAuthorField = dynamic_cast< const SvxAuthorField* >( pField )) != 0  )
221 		{
222 			if( pAuthorField->GetType() != SVXAUTHORTYPE_FIX )
223 			{
224                 SvtUserOptions aUserOptions;
225                 SvxAuthorField aAuthorField(
226                         aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID(),
227                         pAuthorField->GetType(), pAuthorField->GetFormat() );
228 
229                 *(const_cast< SvxAuthorField* >(pAuthorField)) = aAuthorField;
230 			}
231 			pInfo->SetRepresentation( pAuthorField->GetFormatted() );
232 
233 		}
234 		else if( dynamic_cast< const SvxPageField*  >(pField) )
235 		{
236 			String aRepresentation;
237 			aRepresentation += sal_Unicode( ' ' );
238 
239 			::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : NULL;
240 			if(pViewSh == NULL)
241             {
242                 ::sd::ViewShellBase* pBase = PTR_CAST(::sd::ViewShellBase, SfxViewShell::Current());
243                 if(pBase)
244                     pViewSh = pBase->GetMainViewShell().get();
245             }
246 			if( !pDoc && pViewSh )
247 				pDoc = pViewSh->GetDoc();
248 
249 			bool bMasterView;
250 			SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
251 
252 			if( pPage && pDoc && !bMasterView )
253 			{
254 				int nPgNum;
255 
256 				if( (pPage->GetPageKind() == PK_HANDOUT) && pViewSh )
257 				{
258 					nPgNum = pViewSh->GetPrintedHandoutPageNum();
259 				}
260 				else
261 				{
262 					nPgNum = (pPage->GetPageNum() - 1) / 2 + 1;
263 				}
264 				aRepresentation = pDoc->CreatePageNumValue((sal_uInt16)nPgNum);
265 			}
266 			else
267 			{
268 				static String aNumberText( SdResId( STR_FIELD_PLACEHOLDER_NUMBER ) );
269 				aRepresentation = aNumberText;
270 			}
271 
272 			pInfo->SetRepresentation( aRepresentation );
273 		}
274 		else if( dynamic_cast< const SvxPagesField*  >(pField) )
275 		{
276 			String aRepresentation;
277 			aRepresentation += sal_Unicode( ' ' );
278 
279 			::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : NULL;
280 			if(pViewSh == NULL)
281             {
282                 ::sd::ViewShellBase* pBase = PTR_CAST(::sd::ViewShellBase, SfxViewShell::Current());
283                 if(pBase)
284                     pViewSh = pBase->GetMainViewShell().get();
285             }
286 			if( !pDoc && pViewSh )
287 				pDoc = pViewSh->GetDoc();
288 
289 			bool bMasterView;
290 			SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
291 
292             sal_uInt16 nPageCount = 0;
293 
294             if( !bMasterView )
295             {
296 			    if( pPage && (pPage->GetPageKind() == PK_HANDOUT) && pViewSh )
297 			    {
298 				    nPageCount = pViewSh->GetPrintedHandoutPageCount();
299 			    }
300 			    else if( pDoc )
301 			    {
302                     nPageCount = (sal_uInt16)pDoc->GetSdPageCount(PK_STANDARD);
303                 }
304             }
305 
306             if( nPageCount > 0 )
307             {
308 				aRepresentation = pDoc->CreatePageNumValue(nPageCount);
309 			}
310 			else
311 			{
312 				static String aNumberText( SdResId( STR_FIELD_PLACEHOLDER_COUNT ) );
313 				aRepresentation = aNumberText;
314 			}
315 
316 			pInfo->SetRepresentation( aRepresentation );
317 		}
318 		else if( (pURLField = dynamic_cast< const SvxURLField* >(pField)) != 0 )
319 		{
320 			switch ( pURLField->GetFormat() )
321 			{
322 				case SVXURLFORMAT_APPDEFAULT: //!!! einstellbar an App???
323 				case SVXURLFORMAT_REPR:
324 					pInfo->SetRepresentation( pURLField->GetRepresentation() );
325 					break;
326 
327 				case SVXURLFORMAT_URL:
328 					pInfo->SetRepresentation( pURLField->GetURL() );
329 					break;
330 			}
331 
332 			String aURL = pURLField->GetURL();
333 
334             svtools::ColorConfig aConfig;
335             svtools::ColorConfigEntry eEntry =
336                 INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS;
337 			pInfo->SetTxtColor( aConfig.GetColorValue(eEntry).nColor );
338 		}
339 		else if ( dynamic_cast< const SdrMeasureField* >(pField))
340 		{
341 			pInfo->ClearFldColor();
342 		}
343 		else
344 		{
345 			String aRepresentation;
346 
347 			bool bHeaderField = dynamic_cast< const SvxHeaderField* >( pField ) != 0;
348 			bool bFooterField = !bHeaderField && (dynamic_cast< const SvxFooterField* >( pField ) != 0 );
349 			bool bDateTimeField = !bHeaderField && !bFooterField && (dynamic_cast< const SvxDateTimeField* >( pField ) != 0);
350 
351 			if( bHeaderField || bFooterField || bDateTimeField )
352 			{
353 				sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : NULL;
354 				bool bMasterView = false;
355 				SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
356 
357 				if( (pPage == NULL) || bMasterView )
358 				{
359 					if( bHeaderField )
360 					{
361 						static String aHeaderStr( SdResId( STR_FIELD_PLACEHOLDER_HEADER ) );
362 						aRepresentation = aHeaderStr;
363 					}
364 					else if (bFooterField )
365 					{
366 						static String aFooterStr( SdResId( STR_FIELD_PLACEHOLDER_FOOTER ) );
367 						aRepresentation = aFooterStr;
368 					}
369 					else if (bDateTimeField )
370 					{
371 						static String aDateTimeStr( SdResId( STR_FIELD_PLACEHOLDER_DATETIME ) );
372 						aRepresentation = aDateTimeStr;
373 					}
374 				}
375 				else
376 				{
377 					const sd::HeaderFooterSettings &rSettings = pPage->getHeaderFooterSettings();
378 
379 					if( bHeaderField )
380 					{
381 						aRepresentation = rSettings.maHeaderText;
382 					}
383 					else if( bFooterField )
384 					{
385 						aRepresentation = rSettings.maFooterText;
386 					}
387 					else if( bDateTimeField )
388 					{
389 						if( rSettings.mbDateTimeIsFixed )
390 						{
391 							aRepresentation = rSettings.maDateTimeText;
392 						}
393 						else
394 						{
395 							Date aDate;
396 							Time aTime;
397 							LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
398 							aRepresentation = SvxDateTimeField::GetFormatted( aDate, aTime, (SvxDateFormat)rSettings.meDateTimeFormat, *GetNumberFormatter(), eLang );
399 						}
400 					}
401 				}
402 			}
403 			else
404 			{
405 				DBG_ERROR("sd::SdModule::CalcFieldValueHdl(), unknown field type!");
406 			}
407 
408 			if( aRepresentation.Len() == 0 )				// TODO: Edit engine doesn't handle empty fields?
409 				aRepresentation += sal_Unicode( ' ' );
410 			pInfo->SetRepresentation( aRepresentation );
411 		}
412 	}
413 
414 	return(0);
415 }
416 
417 
418 
419 /*************************************************************************
420 |*
421 |* virt. Methoden fuer Optionendialog
422 |*
423 \************************************************************************/
424 SfxItemSet*	 SdModule::CreateItemSet( sal_uInt16 nSlot )
425 {
426 	::sd::FrameView* pFrameView = NULL;
427 	::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
428 	SdDrawDocument* pDoc = NULL;
429 
430 	// Hier wird der DocType vom Optionsdialog gesetzt (nicht Dokument!)
431 	DocumentType eDocType = DOCUMENT_TYPE_IMPRESS;
432 	if( nSlot == SID_SD_GRAPHIC_OPTIONS )
433 		eDocType = DOCUMENT_TYPE_DRAW;
434 
435 	::sd::ViewShell* pViewShell = NULL;
436 
437 	if (pDocSh)
438 	{
439 		pDoc = pDocSh->GetDoc();
440 
441 		// Wenn der Optionsdialog zum Dokumenttyp identisch ist,
442 		// kann auch die FrameView mit uebergeben werden:
443 		if( pDoc && eDocType == pDoc->GetDocumentType() )
444 			pFrameView = pDocSh->GetFrameView();
445 
446 		pViewShell = pDocSh->GetViewShell();
447 		if (pViewShell != NULL)
448             pViewShell->WriteFrameViewData();
449 	}
450 
451 	SdOptions* pOptions = GetSdOptions(eDocType);
452 
453 	// Pool hat standardmaessig MapUnit Twips (Baeh!)
454 	SfxItemPool& rPool = GetPool();
455 	rPool.SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
456 
457 	SfxItemSet*	 pRet = new SfxItemSet( rPool,
458 						SID_ATTR_METRIC, SID_ATTR_METRIC,
459 						SID_ATTR_DEFTABSTOP, SID_ATTR_DEFTABSTOP,
460 
461 						ATTR_OPTIONS_LAYOUT, ATTR_OPTIONS_LAYOUT,
462 						ATTR_OPTIONS_CONTENTS, ATTR_OPTIONS_CONTENTS,
463 						ATTR_OPTIONS_MISC, ATTR_OPTIONS_MISC,
464 
465 						ATTR_OPTIONS_SNAP, ATTR_OPTIONS_SNAP,
466 
467 						ATTR_OPTIONS_SCALE_START, ATTR_OPTIONS_SCALE_END,
468 
469 						ATTR_OPTIONS_PRINT, ATTR_OPTIONS_PRINT,
470 
471 						SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS,
472 						0 );
473 
474 	// TP_OPTIONS_LAYOUT:
475 	pRet->Put( SdOptionsLayoutItem( ATTR_OPTIONS_LAYOUT, pOptions, pFrameView ) );
476 
477 	sal_uInt16 nDefTab = 0;
478 	if( pFrameView)
479 		nDefTab = pDoc->GetDefaultTabulator();
480 	else
481 		nDefTab = pOptions->GetDefTab();
482 	pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, nDefTab ) );
483 
484 	FieldUnit nMetric = (FieldUnit)0xffff;
485 	if( pFrameView)
486 		nMetric = pDoc->GetUIUnit();
487 	else
488 		nMetric = (FieldUnit)pOptions->GetMetric();
489 
490 	if( nMetric == (FieldUnit)0xffff )
491 		nMetric = GetFieldUnit();
492 
493 	pRet->Put( SfxUInt16Item( SID_ATTR_METRIC, (sal_uInt16)nMetric ) );
494 
495 	// TP_OPTIONS_CONTENTS:
496 	pRet->Put( SdOptionsContentsItem( ATTR_OPTIONS_CONTENTS, pOptions, pFrameView ) );
497 
498 	// TP_OPTIONS_MISC:
499     SdOptionsMiscItem aSdOptionsMiscItem( ATTR_OPTIONS_MISC, pOptions, pFrameView );
500     if ( pFrameView )
501     {
502         aSdOptionsMiscItem.GetOptionsMisc().SetSummationOfParagraphs( pDoc->IsSummationOfParagraphs() );
503         aSdOptionsMiscItem.GetOptionsMisc().SetPrinterIndependentLayout (
504             (sal_uInt16)pDoc->GetPrinterIndependentLayout());
505     }
506 	pRet->Put( aSdOptionsMiscItem );
507 
508 
509 	// TP_OPTIONS_SNAP:
510 	pRet->Put( SdOptionsSnapItem( ATTR_OPTIONS_SNAP, pOptions, pFrameView ) );
511 
512 	// TP_SCALE:
513 	sal_uInt32 nW = 10L;
514 	sal_uInt32 nH = 10L;
515 	sal_Int32  nX;
516 	sal_Int32  nY;
517 	if( pDocSh )
518 	{
519 		SdrPage* pPage = (SdrPage*) pDoc->GetSdPage(0, PK_STANDARD);
520 		Size aSize(pPage->GetSize());
521 		nW = aSize.Width();
522 		nH = aSize.Height();
523 	}
524 
525 	if(pFrameView)
526 	{
527 		const Fraction& rFraction =  pDoc->GetUIScale();
528 		nX=rFraction.GetNumerator();
529 		nY=rFraction.GetDenominator();
530 	}
531 	else
532 	{
533 		// Optionen aus Configdatei holen
534 		pOptions->GetScale( nX, nY );
535 	}
536 
537 	pRet->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) );
538 	pRet->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) );
539 	pRet->Put( SfxUInt32Item( ATTR_OPTIONS_SCALE_WIDTH, nW ) );
540 	pRet->Put( SfxUInt32Item( ATTR_OPTIONS_SCALE_HEIGHT, nH ) );
541 
542 
543 	// TP_OPTIONS_PRINT:
544 	pRet->Put( SdOptionsPrintItem( ATTR_OPTIONS_PRINT, pOptions ) );
545 
546 	// RID_SVXPAGE_GRID:
547 	pRet->Put( SdOptionsGridItem( SID_ATTR_GRID_OPTIONS, pOptions ) );
548 
549 	return pRet;
550 }
551 void SdModule::ApplyItemSet( sal_uInt16 nSlot, const SfxItemSet& rSet )
552 {
553 	const SfxPoolItem*	pItem = NULL;
554 	sal_Bool bNewDefTab = sal_False;
555 	sal_Bool bNewPrintOptions = sal_False;
556 	sal_Bool bMiscOptions = sal_False;
557 
558 	::sd::FrameView* pFrameView = NULL;
559 	::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
560 	SdDrawDocument* pDoc = NULL;
561 	// Hier wird der DocType vom Optionsdialog gesetzt (nicht Dokument!)
562 	DocumentType eDocType = DOCUMENT_TYPE_IMPRESS;
563 	if( nSlot == SID_SD_GRAPHIC_OPTIONS )
564 		eDocType = DOCUMENT_TYPE_DRAW;
565 
566 	::sd::ViewShell* pViewShell = NULL;
567 
568 	if (pDocSh)
569 	{
570 		pDoc = pDocSh->GetDoc();
571 
572 		// Wenn der Optionsdialog zum Dokumenttyp identisch ist,
573 		// kann auch die FrameView mit uebergeben werden:
574 		if( pDoc && eDocType == pDoc->GetDocumentType() )
575 			pFrameView = pDocSh->GetFrameView();
576 
577 		pViewShell = pDocSh->GetViewShell();
578         if (pViewShell != NULL)
579             pViewShell->WriteFrameViewData();
580 	}
581 	SdOptions* pOptions = GetSdOptions(eDocType);
582 	// Raster
583 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS ,
584 							sal_False, (const SfxPoolItem**) &pItem ))
585 	{
586 		const SdOptionsGridItem* pGridItem = (SdOptionsGridItem*) pItem;
587 		pGridItem->SetOptions( pOptions );
588 	}
589 
590 	// Layout
591 	const SdOptionsLayoutItem* pLayoutItem = NULL;
592 	if( SFX_ITEM_SET == rSet.GetItemState( ATTR_OPTIONS_LAYOUT,
593 							sal_False, (const SfxPoolItem**) &pLayoutItem ))
594 	{
595 		pLayoutItem->SetOptions( pOptions );
596 	}
597 
598 	// Metric
599 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_METRIC, sal_False, &pItem ) )
600 	{
601 		if( pDoc && eDocType == pDoc->GetDocumentType() )
602 			PutItem( *pItem );
603 		pOptions->SetMetric( ( (SfxUInt16Item*) pItem )->GetValue() );
604 	}
605 	sal_uInt16 nDefTab = pOptions->GetDefTab();
606 	// Default-Tabulator
607 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_DEFTABSTOP, sal_False, &pItem ) )
608 	{
609 		nDefTab = ( (SfxUInt16Item*) pItem )->GetValue();
610 		pOptions->SetDefTab( nDefTab );
611 
612 		bNewDefTab = sal_True;
613 	}
614 
615     // Massstab
616     if( SFX_ITEM_SET == rSet.GetItemState( ATTR_OPTIONS_SCALE_X, sal_False, &pItem ) )
617     {
618         sal_Int32 nX = ( (SfxInt32Item*) pItem )->GetValue();
619         if( SFX_ITEM_SET == rSet.GetItemState( ATTR_OPTIONS_SCALE_Y, sal_False, &pItem ) )
620         {
621             sal_Int32 nY = ( (SfxInt32Item*) pItem )->GetValue();
622             pOptions->SetScale( nX, nY );
623 
624             // #92067# Apply to document only if doc type match
625             if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
626             {
627                 pDoc->SetUIScale( Fraction( nX, nY ) );
628                 if( pViewShell )
629                     pViewShell->SetRuler( pViewShell->HasRuler() );
630             }
631         }
632     }
633 
634 	// Contents (Inhalte)
635 	const SdOptionsContentsItem* pContentsItem = NULL;
636 	if( SFX_ITEM_SET == rSet.GetItemState( ATTR_OPTIONS_CONTENTS,
637 							sal_False, (const SfxPoolItem**) &pContentsItem ))
638 	{
639 		pContentsItem->SetOptions( pOptions );
640 	}
641 
642 	// Misc (Sonstiges)
643 	const SdOptionsMiscItem* pMiscItem = NULL;
644 	if( SFX_ITEM_SET == rSet.GetItemState( ATTR_OPTIONS_MISC,
645 							sal_False, (const SfxPoolItem**) &pMiscItem ))
646 	{
647 		pMiscItem->SetOptions( pOptions );
648 		bMiscOptions = sal_True;
649 	}
650 
651 	// Fangen/Einrasten
652 	const SdOptionsSnapItem* pSnapItem = NULL;
653 	if( SFX_ITEM_SET == rSet.GetItemState( ATTR_OPTIONS_SNAP,
654 							sal_False, (const SfxPoolItem**) &pSnapItem ))
655 	{
656 		pSnapItem->SetOptions( pOptions );
657 	}
658 
659 	SfxItemSet aPrintSet( GetPool(),
660 					SID_PRINTER_NOTFOUND_WARN,	SID_PRINTER_NOTFOUND_WARN,
661 					SID_PRINTER_CHANGESTODOC,	SID_PRINTER_CHANGESTODOC,
662 					ATTR_OPTIONS_PRINT, 		ATTR_OPTIONS_PRINT,
663 					0 );
664 
665 	// Drucken
666 	const SdOptionsPrintItem* pPrintItem = NULL;
667 	if( SFX_ITEM_SET == rSet.GetItemState( ATTR_OPTIONS_PRINT,
668 							sal_False, (const SfxPoolItem**) &pPrintItem ))
669 	{
670 		pPrintItem->SetOptions( pOptions );
671 
672 		// PrintOptionsSet setzen
673 		SdOptionsPrintItem aPrintItem( ATTR_OPTIONS_PRINT, pOptions );
674 		SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC );
675 		sal_uInt16		nFlags = 0;
676 
677 		nFlags =  (aPrintItem.GetOptionsPrint().IsWarningSize() ? SFX_PRINTER_CHG_SIZE : 0) |
678 				(aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SFX_PRINTER_CHG_ORIENTATION : 0);
679 		aFlagItem.SetValue( nFlags );
680 
681 		aPrintSet.Put( aPrintItem );
682 		aPrintSet.Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) );
683 		aPrintSet.Put( aFlagItem );
684 
685 		bNewPrintOptions = sal_True;
686 	}
687 
688 	// Nur, wenn auch der Dokumenttyp uebereinstimmt...
689 	if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
690 	{
691 		if( bNewPrintOptions )
692 		{
693 			pDocSh->GetPrinter(sal_True)->SetOptions( aPrintSet );
694 		}
695 
696 		// Am Model den DefTab setzen
697 		if( bNewDefTab )
698 		{
699 			SdDrawDocument* pDocument = pDocSh->GetDoc();
700 			pDocument->SetDefaultTabulator( nDefTab );
701 
702 			::sd::Outliner* pOutl = pDocument->GetOutliner( sal_False );
703 			if( pOutl )
704 				pOutl->SetDefTab( nDefTab );
705 
706 			::sd::Outliner* pInternalOutl = pDocument->GetInternalOutliner( sal_False );
707 			if( pInternalOutl )
708 				pInternalOutl->SetDefTab( nDefTab );
709 		}
710 		if ( bMiscOptions )
711 		{
712             pDoc->SetSummationOfParagraphs( pMiscItem->GetOptionsMisc().IsSummationOfParagraphs() );
713 			sal_uInt32 nSum = pMiscItem->GetOptionsMisc().IsSummationOfParagraphs() ? EE_CNTRL_ULSPACESUMMATION : 0;
714 			sal_uInt32 nCntrl;
715 
716 			SdDrawDocument* pDocument = pDocSh->GetDoc();
717 			SdrOutliner& rOutl = pDocument->GetDrawOutliner( sal_False );
718 			nCntrl = rOutl.GetControlWord() &~ EE_CNTRL_ULSPACESUMMATION;
719 			rOutl.SetControlWord( nCntrl | nSum );
720 			::sd::Outliner* pOutl = pDocument->GetOutliner( sal_False );
721 			if( pOutl )
722 			{
723 				nCntrl = pOutl->GetControlWord() &~ EE_CNTRL_ULSPACESUMMATION;
724 				pOutl->SetControlWord( nCntrl | nSum );
725 			}
726 			pOutl = pDocument->GetInternalOutliner( sal_False );
727 			if( pOutl )
728 			{
729 				nCntrl = pOutl->GetControlWord() &~ EE_CNTRL_ULSPACESUMMATION;
730 				pOutl->SetControlWord( nCntrl | nSum );
731 			}
732 
733             // Set printer independent layout mode.
734 			if( pDoc->GetPrinterIndependentLayout() != pMiscItem->GetOptionsMisc().GetPrinterIndependentLayout() )
735 	            pDoc->SetPrinterIndependentLayout (pMiscItem->GetOptionsMisc().GetPrinterIndependentLayout());
736 		}
737 	}
738 
739 	pOptions->StoreConfig();
740 
741 	// Nur, wenn auch der Dokumenttyp uebereinstimmt...
742 	if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
743 	{
744 		FieldUnit eUIUnit = (FieldUnit) pOptions->GetMetric();
745 		pDoc->SetUIUnit(eUIUnit);
746 
747 		if (pViewShell)
748 		{
749 			// #74495# make sure no one is in text edit mode, cause there
750 			// are some pointers remembered else (!)
751 			if(pViewShell->GetView())
752 				pViewShell->GetView()->SdrEndTextEdit();
753 
754 			::sd::FrameView* pFrame = pViewShell->GetFrameView();
755 			pFrame->Update(pOptions);
756 			pViewShell->ReadFrameViewData(pFrame);
757 			pViewShell->SetUIUnit(eUIUnit);
758 			pViewShell->SetDefTabHRuler( nDefTab );
759 		}
760 	}
761 
762 	if( pViewShell && pViewShell->GetViewFrame() )
763 		pViewShell->GetViewFrame()->GetBindings().InvalidateAll( sal_True );
764 }
765 
766 SfxTabPage* SdModule::CreateTabPage( sal_uInt16 nId, Window* pParent, const SfxItemSet& rSet )
767 {
768 	SfxTabPage* pRet = NULL;
769 	SfxAllItemSet aSet(*(rSet.GetPool()));
770 	SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
771 	if( pFact )
772 	{
773 		switch(nId)
774 		{
775 			case SID_SD_TP_CONTENTS:
776 			case SID_SI_TP_CONTENTS:
777 			{	::CreateTabPage fnCreatePage = pFact->GetSdOptionsContentsTabPageCreatorFunc();
778 				if( fnCreatePage )
779 					pRet = (*fnCreatePage)( pParent, rSet );
780 			}
781 			break;
782 			case SID_SD_TP_SNAP:
783 			case SID_SI_TP_SNAP:
784 			{	::CreateTabPage fnCreatePage = pFact->GetSdOptionsSnapTabPageCreatorFunc();
785 				if( fnCreatePage )
786 					pRet = (*fnCreatePage)( pParent, rSet );
787 			}
788 			break;
789 			case SID_SD_TP_PRINT:
790 			case SID_SI_TP_PRINT:
791 			{
792 				::CreateTabPage fnCreatePage = pFact->GetSdPrintOptionsTabPageCreatorFunc();
793 				if( fnCreatePage )
794 				{
795 					pRet = (*fnCreatePage)( pParent, rSet );
796 					if(SID_SD_TP_PRINT == nId)
797 						aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE));
798 					pRet->PageCreated(aSet);
799 				}
800 			}
801 			break;
802 			case SID_SI_TP_MISC:
803 			case SID_SD_TP_MISC:
804 			{
805 				::CreateTabPage fnCreatePage = pFact->GetSdOptionsMiscTabPageCreatorFunc();
806 				if( fnCreatePage )
807 				{
808 					pRet = (*fnCreatePage)( pParent, rSet );
809 					if(SID_SD_TP_MISC == nId)
810 						aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE));
811 					else
812 						aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_IMPRESS_MODE));
813 					pRet->PageCreated(aSet);
814 				}
815 			}
816 			break;
817 			case RID_OFA_TP_INTERNATIONAL_SD:
818 			case RID_OFA_TP_INTERNATIONAL_IMPR:
819 			case RID_SVXPAGE_TEXTANIMATION :
820 			{
821 				SfxAbstractDialogFactory* pSfxFact = SfxAbstractDialogFactory::Create();
822 				if ( pSfxFact )
823 				{
824 					::CreateTabPage fnCreatePage = pSfxFact->GetTabPageCreatorFunc( nId );
825 					if ( fnCreatePage )
826 						pRet = (*fnCreatePage)( pParent, rSet );
827 				}
828 			}
829 			break;
830 		}
831 		DBG_ASSERT( pRet, "SdModule::CreateTabPage(): no valid ID for TabPage!" );
832 	}
833 
834 	return pRet;
835 }
836