xref: /aoo42x/main/sd/source/ui/dlg/headerfooterdlg.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 #ifdef SD_DLLIMPLEMENTATION
32 #undef SD_DLLIMPLEMENTATION
33 #endif
34 
35 #ifndef _SVX_DIALOGS_HRC
36 #include <svx/dialogs.hrc>
37 #endif
38 #include <editeng/eeitem.hxx>
39 #include <editeng/flditem.hxx>
40 #include <editeng/langitem.hxx>
41 #include <svx/langbox.hxx>
42 #include <svx/svdotext.hxx>
43 #include <editeng/editeng.hxx>
44 #include <sfx2/viewfrm.hxx>
45 
46 #ifndef _SD_SDRESID_HXX
47 #include "sdresid.hxx"
48 #endif
49 
50 #include <vcl/fixed.hxx>
51 #include <vcl/button.hxx>
52 #include <vcl/edit.hxx>
53 #include <vcl/combobox.hxx>
54 
55 #include "helpids.h"
56 #include "Outliner.hxx"
57 #include "dialogs.hrc"
58 #include "headerfooterdlg.hxx"
59 #include "DrawDocShell.hxx"
60 #include "drawdoc.hxx"
61 #include "ViewShell.hxx"
62 
63 ///////////////////////////////////////////////////////////////////////
64 // preview control for presentation layout
65 ///////////////////////////////////////////////////////////////////////
66 #include <vcl/ctrl.hxx>
67 #ifndef _SV_COLOR_HXX
68 #include <tools/color.hxx>
69 #endif
70 #include <i18npool/mslangid.hxx>
71 #include <svtools/colorcfg.hxx>
72 #include <svx/xlndsit.hxx>
73 #include <svx/xlineit0.hxx>
74 #include <svx/xlnclit.hxx>
75 #include <vcl/decoview.hxx>
76 
77 #include "undoheaderfooter.hxx"
78 #include "sdundogr.hxx"
79 #include "ViewShell.hxx"
80 
81 #include <basegfx/matrix/b2dhommatrix.hxx>
82 #include <basegfx/polygon/b2dpolygontools.hxx>
83 #include <basegfx/polygon/b2dpolypolygontools.hxx>
84 
85 namespace sd
86 {
87 
88 class PresLayoutPreview : public Control
89 {
90 private:
91 	SdPage*	mpMaster;
92 	HeaderFooterSettings maSettings;
93 	Size maPageSize;
94 	Rectangle maOutRect;
95 
96 private:
97 	void Paint( OutputDevice& aOut, SdrTextObj* pObj, bool bVisible, bool bDotted = false );
98 
99 public:
100 	PresLayoutPreview( ::Window* pParent, const ResId& rResId, SdPage* pMaster );
101 	~PresLayoutPreview();
102 
103 	virtual void Paint( const Rectangle& rRect );
104 
105 	void update( HeaderFooterSettings& rSettings );
106 };
107 
108 }
109 
110 ///////////////////////////////////////////////////////////////////////
111 // tab page for slide & header'n'notes
112 ///////////////////////////////////////////////////////////////////////
113 
114 namespace sd
115 {
116 
117 const int nDateTimeFormatsCount = 10;
118 int nDateTimeFormats[nDateTimeFormatsCount] =
119 {
120 	SVXDATEFORMAT_A,
121 	SVXDATEFORMAT_F,
122 	SVXDATEFORMAT_D,
123 	SVXDATEFORMAT_C,
124 
125 	SVXDATEFORMAT_A | (SVXTIMEFORMAT_24_HM << 4),
126 	SVXDATEFORMAT_A | (SVXTIMEFORMAT_12_HM << 4),
127 
128 	(SVXTIMEFORMAT_24_HM << 4),
129 	(SVXTIMEFORMAT_24_HMS <<4),
130 
131 	(SVXTIMEFORMAT_12_HM << 4 ),
132 	(SVXTIMEFORMAT_12_HMS << 4 )
133 };
134 
135 class HeaderFooterTabPage : public TabPage
136 {
137 private:
138 	FixedLine	maFLIncludeOnPage;
139 
140 	CheckBox	maCBHeader;
141 	FixedText	maFTHeader;
142 	Edit		maTBHeader;
143 
144 	FixedLine	maFLDateTime;
145 	CheckBox	maCBDateTime;
146 	RadioButton	maRBDateTimeFixed;
147 	RadioButton maRBDateTimeAutomatic;
148 	Edit		maTBDateTimeFixed;
149 	ListBox		maCBDateTimeFormat;
150 	FixedText	maFTDateTimeLanguage;
151 	SvxLanguageBox	maCBDateTimeLanguage;
152 
153 	FixedLine	maFLFooter;
154 	CheckBox	maCBFooter;
155 	FixedText	maFTFooter;
156 	Edit		maTBFooter;
157 
158 	FixedLine	maFLSlideNumber;
159 	CheckBox	maCBSlideNumber;
160 
161 	FixedLine	maFLNotOnTitle;
162 	CheckBox	maCBNotOnTitle;
163 
164 	PushButton		maPBApplyToAll;
165 	PushButton		maPBApply;
166 	CancelButton	maPBCancel;
167 	HelpButton		maPBHelp;
168 
169 	PresLayoutPreview	maCTPreview;
170 
171 	SdPage*				mpCurrentPage;
172 	SdDrawDocument *	mpDoc;
173 	HeaderFooterDialog* mpDialog;
174 	LanguageType		meOldLanguage;
175 
176 	bool			mbHandoutMode;
177 
178 	DECL_LINK( UpdateOnClickHdl, void * );
179 
180 	DECL_LINK( ClickApplyToAllHdl, void * );
181 	DECL_LINK( ClickApplyHdl, void * );
182 	DECL_LINK( ClickCancelHdl, void * );
183 
184 	DECL_LINK( LanguageChangeHdl, void * );
185 
186 	void FillFormatList(int eFormat);
187 	void GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet );
188 	void GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet, SdPage* pPage );
189 
190 public:
191 	HeaderFooterTabPage( HeaderFooterDialog* pDialog, ::Window* pParent, SdDrawDocument* pDoc, SdPage* pActualPage, bool bHandoutMode );
192 	~HeaderFooterTabPage();
193 
194 	static  SfxTabPage* Create( ::Window*, const SfxItemSet& );
195 	static  sal_uInt16*	   GetRanges();
196 
197 	void	init( const HeaderFooterSettings& rSettings, bool bNotOnTitle, bool bHasApply );
198 	void	getData( HeaderFooterSettings& rSettings, bool& rNotOnTitle );
199 	void	update();
200 };
201 
202 }
203 
204 ///////////////////////////////////////////////////////////////////////
205 
206 using namespace ::sd;
207 
208 
209 HeaderFooterDialog::HeaderFooterDialog( ViewShell* pViewShell, ::Window* pParent, SdDrawDocument* pDoc, SdPage* pCurrentPage ) :
210 		TabDialog ( pParent, SdResId( RID_SD_DLG_HEADERFOOTER ) ),
211 		maTabCtrl( this, SdResId( 1 ) ),
212 		mpDoc( pDoc ),
213 		mpCurrentPage( pCurrentPage ),
214 		mpViewShell( pViewShell )
215 {
216 	FreeResource();
217 
218 	SdPage* pSlide;
219 	SdPage* pNotes;
220 	if( pCurrentPage->GetPageKind() == PK_STANDARD )
221 	{
222 		pSlide = pCurrentPage;
223 		pNotes = (SdPage*)pDoc->GetPage( pCurrentPage->GetPageNum() + 1 );
224 	}
225 	else if( pCurrentPage->GetPageKind() == PK_NOTES )
226 	{
227 		pNotes = pCurrentPage;
228 		pSlide = (SdPage*)pDoc->GetPage( pCurrentPage->GetPageNum() -1 );
229 		mpCurrentPage = pSlide;
230 	}
231 	else
232 	{
233 		// handout
234 		pSlide = pDoc->GetSdPage( 0, PK_STANDARD );
235 		pNotes = pDoc->GetSdPage( 0, PK_NOTES );
236 		mpCurrentPage = NULL;
237 	}
238 
239 //	maTabCtrl.SetHelpId( HID_XML_FILTER_TABPAGE_CTRL );
240 	maTabCtrl.Show();
241 
242 	mpSlideTabPage = new HeaderFooterTabPage( this, &maTabCtrl, pDoc, pSlide, false );
243 	mpSlideTabPage->SetHelpId( HID_SD_TABPAGE_HEADERFOOTER_SLIDE );
244 	maTabCtrl.SetTabPage( RID_SD_TABPAGE_HEADERFOOTER_SLIDE, mpSlideTabPage );
245 
246 	Size aSiz = mpSlideTabPage->GetSizePixel();
247 	Size aCtrlSiz = maTabCtrl.GetOutputSizePixel();
248 	// set size on TabControl only if smaller than TabPage
249 	if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() )
250 	{
251 		maTabCtrl.SetOutputSizePixel( aSiz );
252 		aCtrlSiz = aSiz;
253 	}
254 
255 	mpNotesHandoutsTabPage = new HeaderFooterTabPage( this, &maTabCtrl, pDoc, pNotes, true );
256 	mpNotesHandoutsTabPage->SetHelpId( HID_SD_TABPAGE_HEADERFOOTER_NOTESHANDOUT );
257 	maTabCtrl.SetTabPage( RID_SD_TABPAGE_HEADERFOOTER_NOTESHANDOUT, mpNotesHandoutsTabPage );
258 
259 	aSiz = mpNotesHandoutsTabPage->GetSizePixel();
260 	if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() )
261 	{
262 		maTabCtrl.SetOutputSizePixel( aSiz );
263 		aCtrlSiz = aSiz;
264 	}
265 
266 	ActivatePageHdl( &maTabCtrl );
267 
268 	AdjustLayout();
269 
270 	maTabCtrl.SetActivatePageHdl( LINK( this, HeaderFooterDialog, ActivatePageHdl ) );
271 	maTabCtrl.SetDeactivatePageHdl( LINK( this, HeaderFooterDialog, DeactivatePageHdl ) );
272 
273 	maSlideSettings = pSlide->getHeaderFooterSettings();
274 
275 	const HeaderFooterSettings& rTitleSettings = mpDoc->GetSdPage(0, PK_STANDARD)->getHeaderFooterSettings();
276 	bool bNotOnTitle = !rTitleSettings.mbFooterVisible && !rTitleSettings.mbSlideNumberVisible && !rTitleSettings.mbDateTimeVisible;
277 
278 	mpSlideTabPage->init( maSlideSettings, bNotOnTitle, mpCurrentPage != NULL );
279 
280 	maNotesHandoutSettings = pNotes->getHeaderFooterSettings();
281 	mpNotesHandoutsTabPage->init( maNotesHandoutSettings, false, false );
282 }
283 
284 // -----------------------------------------------------------------------
285 
286 HeaderFooterDialog::~HeaderFooterDialog()
287 {
288 	delete mpSlideTabPage;
289 	delete mpNotesHandoutsTabPage;
290 }
291 
292 // -----------------------------------------------------------------------
293 
294 IMPL_LINK( HeaderFooterDialog, ActivatePageHdl, TabControl *, pTabCtrl )
295 {
296 	const sal_uInt16 nId = pTabCtrl->GetCurPageId();
297 	TabPage* pTabPage = pTabCtrl->GetTabPage( nId );
298 	pTabPage->Show();
299 
300 	return 0;
301 }
302 
303 // -----------------------------------------------------------------------
304 
305 IMPL_LINK( HeaderFooterDialog, DeactivatePageHdl, TabControl *, EMPTYARG )
306 {
307 	return sal_True;
308 }
309 
310 // -----------------------------------------------------------------------
311 
312 short HeaderFooterDialog::Execute()
313 {
314 	sal_uInt16 nRet = TabDialog::Execute();
315 	if( nRet )
316 		mpViewShell->GetDocSh()->SetModified();
317     return nRet;
318 }
319 
320 // -----------------------------------------------------------------------
321 
322 void HeaderFooterDialog::ApplyToAll( TabPage* pPage )
323 {
324 	apply( true, pPage == mpSlideTabPage );
325 	EndDialog(1);
326 }
327 
328 // -----------------------------------------------------------------------
329 
330 void HeaderFooterDialog::Apply( TabPage* pPage )
331 {
332 	apply( false, pPage == mpSlideTabPage );
333 	EndDialog(1);
334 }
335 
336 // -----------------------------------------------------------------------
337 
338 void HeaderFooterDialog::Cancel( TabPage* )
339 {
340 	EndDialog();
341 }
342 
343 // -----------------------------------------------------------------------
344 
345 void HeaderFooterDialog::apply( bool bToAll, bool bForceSlides )
346 {
347 	SdUndoGroup* pUndoGroup = new SdUndoGroup(mpDoc);
348 	String aComment( GetText() );
349 	pUndoGroup->SetComment( aComment );
350 
351 	HeaderFooterSettings aNewSettings;
352 	bool bNewNotOnTitle;
353 
354 	// change slide settings first ...
355 
356 	mpSlideTabPage->getData( aNewSettings, bNewNotOnTitle );
357 
358 	// only if we pressed apply or apply all on the slide tab page or if the slide settings
359 	// have been changed
360 	if( bForceSlides || !(aNewSettings == maSlideSettings) )
361 	{
362 		// apply to all slides
363 		if( bToAll )
364 		{
365 			int nPageCount = mpDoc->GetSdPageCount( PK_STANDARD );
366 			int nPage;
367 			for( nPage = 0; nPage < nPageCount; nPage++ )
368 			{
369 				SdPage* pPage = mpDoc->GetSdPage( (sal_uInt16)nPage, PK_STANDARD );
370 				change( pUndoGroup, pPage, aNewSettings );
371 			}
372 		}
373 		else
374 		{
375 			// apply only to the current slide
376 			DBG_ASSERT( mpCurrentPage && mpCurrentPage->GetPageKind() == PK_STANDARD, "no current page to apply to!" );
377 			if( mpCurrentPage && (mpCurrentPage->GetPageKind() == PK_STANDARD) )
378 			{
379 				change( pUndoGroup, mpCurrentPage, aNewSettings );
380 			}
381 		}
382 	}
383 
384 	// if we don't want to have header&footer on the first slide
385 	if( bNewNotOnTitle )
386 	{
387 		// just hide them, plain simple UI feature
388 		HeaderFooterSettings aTempSettings = mpDoc->GetSdPage( 0, PK_STANDARD )->getHeaderFooterSettings();
389 
390 		aTempSettings.mbFooterVisible = false;
391 		aTempSettings.mbSlideNumberVisible = false;
392 		aTempSettings.mbDateTimeVisible = false;
393 
394 		change( pUndoGroup, mpDoc->GetSdPage( 0, PK_STANDARD ), aTempSettings );
395 	}
396 
397 	// now notes settings
398 
399 	mpNotesHandoutsTabPage->getData( aNewSettings, bNewNotOnTitle );
400 
401 	// only if we pressed apply or apply all on the notes tab page or if the notes settings
402 	// have been changed
403 	if( !bForceSlides || !(aNewSettings == maNotesHandoutSettings) )
404 	{
405 		// first set to all notes pages
406 		int nPageCount = mpDoc->GetSdPageCount( PK_NOTES );
407 		int nPage;
408 		for( nPage = 0; nPage < nPageCount; nPage++ )
409 		{
410 			SdPage* pPage = mpDoc->GetSdPage( (sal_uInt16)nPage, PK_NOTES );
411 
412 			change( pUndoGroup, pPage, aNewSettings );
413 		}
414 
415 		// and last but not least to the handout page
416 		change( pUndoGroup, mpDoc->GetMasterSdPage( 0, PK_HANDOUT ), aNewSettings );
417 	}
418 
419 	// Undo Gruppe dem Undo Manager uebergeben
420 	mpViewShell->GetViewFrame()->GetObjectShell()->GetUndoManager()->AddUndoAction(pUndoGroup);
421 }
422 
423 // -----------------------------------------------------------------------
424 
425 void HeaderFooterDialog::change( SdUndoGroup* pUndoGroup, SdPage* pPage, const HeaderFooterSettings& rNewSettings )
426 {
427 	pUndoGroup->AddAction(new SdHeaderFooterUndoAction(mpDoc, pPage, rNewSettings ));
428 	pPage->setHeaderFooterSettings( rNewSettings );
429 }
430 
431 ///////////////////////////////////////////////////////////////////////
432 
433 inline void moveY( ::Window& rWin, int deltaY )
434 {
435     Point aPos = rWin.GetPosPixel();
436 	aPos.Y() += deltaY;
437 	rWin.SetPosPixel( aPos );
438 }
439 
440 HeaderFooterTabPage::HeaderFooterTabPage( HeaderFooterDialog* pDialog, ::Window* pWindow, SdDrawDocument* pDoc, SdPage* pActualPage, bool bHandoutMode ) :
441 		TabPage( pWindow, SdResId( RID_SD_TABPAGE_HEADERFOOTER ) ),
442 		maFLIncludeOnPage( this, SdResId( FL_INCLUDE_ON_PAGE ) ),
443 		maCBHeader( this, SdResId( CB_HEADER ) ),
444 		maFTHeader( this, SdResId( FT_HEADER ) ),
445 		maTBHeader( this, SdResId( TB_HEADER_FIXED ) ),
446 		maFLDateTime( this, SdResId( FL_DATETIME ) ),
447 		maCBDateTime( this, SdResId( CB_DATETIME ) ),
448 		maRBDateTimeFixed( this, SdResId( RB_DATETIME_FIXED ) ),
449 		maRBDateTimeAutomatic( this, SdResId( RB_DATETIME_AUTOMATIC ) ),
450 		maTBDateTimeFixed( this, SdResId( TB_DATETIME_FIXED ) ),
451 		maCBDateTimeFormat( this, SdResId( CB_DATETIME_FORMAT ) ),
452 		maFTDateTimeLanguage( this, SdResId( FT_DATETIME_LANGUAGE ) ),
453 		maCBDateTimeLanguage( this, SdResId( CB_DATETIME_LANGUAGE ) ),
454 
455 		maFLFooter( this, SdResId( FL_FOOTER ) ),
456 		maCBFooter( this, SdResId( CB_FOOTER ) ),
457 		maFTFooter( this, SdResId( FT_FOOTER ) ),
458 		maTBFooter( this, SdResId( TB_FOOTER_FIXED ) ),
459 
460 		maFLSlideNumber( this, SdResId( FL_SLIDENUMBER ) ),
461 		maCBSlideNumber( this, SdResId( CB_SLIDENUMBER ) ),
462 
463 		maFLNotOnTitle( this, SdResId( FL_NOTONTITLE ) ),
464 		maCBNotOnTitle( this, SdResId( CB_NOTONTITLE ) ),
465 
466 		maPBApplyToAll( this, SdResId( BT_APPLYTOALL ) ),
467 		maPBApply( this, SdResId( BT_APPLY ) ),
468 		maPBCancel( this, SdResId( BT_CANCEL ) ),
469 		maPBHelp( this, SdResId( BT_HELP ) ),
470 
471 		maCTPreview( this, SdResId( CT_PREVIEW ),
472 			pActualPage ?
473 				(pActualPage->IsMasterPage() ? pActualPage : (SdPage*)(&(pActualPage->TRG_GetMasterPage()))) :
474 				(pDoc->GetMasterSdPage( 0, bHandoutMode ? PK_NOTES : PK_STANDARD )) ),
475 		mpCurrentPage(pActualPage),
476 		mpDoc(pDoc),
477 		mpDialog(pDialog),
478 		mbHandoutMode( bHandoutMode )
479 
480 {
481 	pDoc->StopWorkStartupDelay();
482 
483 	if( !mbHandoutMode )
484 	{
485 		int deltaY = maCBHeader.GetPosPixel().Y() - maCBDateTime.GetPosPixel().Y();
486 
487 		moveY( maCBDateTime, deltaY );
488 		moveY( maRBDateTimeFixed, deltaY );
489 		moveY( maRBDateTimeAutomatic, deltaY );
490 		moveY( maTBDateTimeFixed, deltaY );
491 		moveY( maCBDateTimeFormat, deltaY );
492 		moveY( maFTDateTimeLanguage, deltaY );
493 		moveY( maCBDateTimeLanguage, deltaY );
494 		moveY( maFLFooter, deltaY );
495 		moveY( maCBFooter, deltaY );
496 		moveY( maFTFooter, deltaY );
497 		moveY( maTBFooter, deltaY );
498 		moveY( maFLSlideNumber, deltaY );
499 		moveY( maCBSlideNumber, deltaY );
500 		moveY( maFLNotOnTitle, deltaY );
501 		moveY( maCBNotOnTitle, deltaY );
502 	}
503 	else
504 	{
505 		int deltaY = maPBApply.GetPosPixel().Y() - maPBCancel.GetPosPixel().Y();
506 
507 		moveY( maPBCancel, deltaY );
508 		moveY( maPBHelp, deltaY );
509 
510 		String aPageNumberStr( SdResId( STR_PAGE_NUMBER ) );
511 		maCBSlideNumber.SetText( aPageNumberStr );
512 
513 		String aIncludeOnPageStr( SdResId( STR_INCLUDE_ON_PAGE ) );
514 		maFLIncludeOnPage.SetText( aIncludeOnPageStr );
515 	}
516 
517 	FreeResource();
518 
519 	maPBApply.Show( !mbHandoutMode );
520 	maCBHeader.Show( mbHandoutMode );
521 	maFTHeader.Show( mbHandoutMode );
522 	maTBHeader.Show( mbHandoutMode );
523 	maFLDateTime.Show( mbHandoutMode );
524 	maFLNotOnTitle.Show( !mbHandoutMode );
525 	maCBNotOnTitle.Show( !mbHandoutMode );
526 
527 	maCBDateTime.SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
528 	maRBDateTimeFixed.SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
529 	maRBDateTimeAutomatic.SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
530 	maCBFooter.SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
531 	maCBHeader.SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
532 	maCBSlideNumber.SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
533 
534 	maPBApplyToAll.SetClickHdl( LINK( this, HeaderFooterTabPage, ClickApplyToAllHdl ) );
535 	maPBApply.SetClickHdl( LINK( this, HeaderFooterTabPage, ClickApplyHdl ) );
536 	maPBCancel.SetClickHdl( LINK( this, HeaderFooterTabPage, ClickCancelHdl ) );
537 
538 	maCBDateTimeLanguage.SetLanguageList( LANG_LIST_ALL|LANG_LIST_ONLY_KNOWN, false );
539 	maCBDateTimeLanguage.SetSelectHdl( LINK( this, HeaderFooterTabPage, LanguageChangeHdl ) );
540 
541 	GetOrSetDateTimeLanguage( meOldLanguage, false );
542 	meOldLanguage = MsLangId::getRealLanguage( meOldLanguage );
543 	maCBDateTimeLanguage.SelectLanguage( meOldLanguage );
544 
545 	FillFormatList(SVXDATEFORMAT_A);
546 
547 	maTBHeader.SetAccessibleRelationMemberOf(&maCBHeader);
548     maRBDateTimeFixed.SetAccessibleRelationMemberOf(&maCBDateTime);
549     maRBDateTimeAutomatic.SetAccessibleRelationMemberOf(&maCBDateTime);
550 	maTBDateTimeFixed.SetAccessibleName(maRBDateTimeFixed.GetText());
551 	maTBDateTimeFixed.SetAccessibleRelationMemberOf(&maCBDateTime);
552 	maTBDateTimeFixed.SetAccessibleRelationLabeledBy(&maRBDateTimeFixed);
553 	maCBDateTimeFormat.SetAccessibleRelationMemberOf(&maCBDateTime);
554 	maCBDateTimeFormat.SetAccessibleName(maRBDateTimeAutomatic.GetText());
555 	maCBDateTimeFormat.SetAccessibleRelationLabeledBy(&maRBDateTimeAutomatic);
556 	maCBDateTimeLanguage.SetAccessibleRelationMemberOf(&maCBDateTime);
557 	maTBFooter.SetAccessibleRelationMemberOf(&maCBFooter);
558 	maCBSlideNumber.SetAccessibleRelationMemberOf(&maFLIncludeOnPage);
559 	maCBFooter.SetAccessibleRelationMemberOf(&maFLIncludeOnPage);
560 }
561 // -----------------------------------------------------------------------
562 
563 HeaderFooterTabPage::~HeaderFooterTabPage()
564 {
565 }
566 
567 // -----------------------------------------------------------------------
568 
569 IMPL_LINK( HeaderFooterTabPage, LanguageChangeHdl, void *, EMPTYARG )
570 {
571 	FillFormatList( (int)(sal_IntPtr)maCBDateTimeFormat.GetEntryData( maCBDateTimeFormat.GetSelectEntryPos() ) );
572 
573 
574 	return 0L;
575 }
576 
577 // -----------------------------------------------------------------------
578 
579 void HeaderFooterTabPage::FillFormatList( int eFormat )
580 {
581 	LanguageType eLanguage = maCBDateTimeLanguage.GetSelectLanguage();
582 
583 	maCBDateTimeFormat.Clear();
584 
585 	Date aDate;
586 	Time aTime;
587 
588 	int nFormat;
589 	for( nFormat = 0; nFormat < nDateTimeFormatsCount; nFormat++ )
590 	{
591 		String aStr( SvxDateTimeField::GetFormatted( aDate, aTime, nDateTimeFormats[nFormat], *(SD_MOD()->GetNumberFormatter()), eLanguage ) );
592 		sal_uInt16 nEntry = maCBDateTimeFormat.InsertEntry( aStr );
593 		maCBDateTimeFormat.SetEntryData( nEntry, (void*)nDateTimeFormats[nFormat] );
594 		if( nDateTimeFormats[nFormat] == eFormat )
595 		{
596 			maCBDateTimeFormat.SelectEntryPos( nEntry );
597 			maCBDateTimeFormat.SetText( aStr );
598 		}
599 	}
600 }
601 
602 // -----------------------------------------------------------------------
603 
604 void HeaderFooterTabPage::init( const HeaderFooterSettings& rSettings, bool bNotOnTitle, bool bHasApply )
605 {
606 	maCBDateTime.Check( rSettings.mbDateTimeVisible );
607 	maRBDateTimeFixed.Check( rSettings.mbDateTimeIsFixed );
608 	maRBDateTimeAutomatic.Check( !rSettings.mbDateTimeIsFixed );
609 	maTBDateTimeFixed.SetText( rSettings.maDateTimeText );
610 
611 	maCBHeader.Check( rSettings.mbHeaderVisible );
612 	maTBHeader.SetText( rSettings.maHeaderText );
613 
614 	maCBFooter.Check( rSettings.mbFooterVisible );
615 	maTBFooter.SetText( rSettings.maFooterText );
616 
617 	maCBSlideNumber.Check( rSettings.mbSlideNumberVisible );
618 
619 	maCBNotOnTitle.Check( bNotOnTitle );
620 	maPBApply.Enable( bHasApply );
621 
622 	maCBDateTimeLanguage.SelectLanguage( meOldLanguage );
623 
624 	sal_uInt16 nPos;
625 	for( nPos = 0; nPos < maCBDateTimeFormat.GetEntryCount(); nPos++ )
626 	{
627 		int nFormat = (int)(sal_IntPtr)maCBDateTimeFormat.GetEntryData( nPos );
628 		if( nFormat == rSettings.meDateTimeFormat )
629 		{
630 			maCBDateTimeFormat.SelectEntryPos( nPos );
631 			maCBDateTimeFormat.SetText( maCBDateTimeFormat.GetEntry(nPos) );
632 			break;
633 		}
634 	}
635 
636 	update();
637 }
638 
639 // -----------------------------------------------------------------------
640 
641 void HeaderFooterTabPage::getData( HeaderFooterSettings& rSettings, bool& rNotOnTitle )
642 {
643 	rSettings.mbDateTimeVisible = maCBDateTime.IsChecked();
644 	rSettings.mbDateTimeIsFixed = maRBDateTimeFixed.IsChecked();
645 	rSettings.maDateTimeText = maTBDateTimeFixed.GetText();
646 	rSettings.mbFooterVisible = maCBFooter.IsChecked();
647 	rSettings.maFooterText = maTBFooter.GetText();
648 	rSettings.mbSlideNumberVisible = maCBSlideNumber.IsChecked();
649 	rSettings.mbHeaderVisible = maCBHeader.IsChecked();
650 	rSettings.maHeaderText = maTBHeader.GetText();
651 
652 	if( maCBDateTimeFormat.GetSelectEntryCount() == 1 )
653 		rSettings.meDateTimeFormat = (int)(sal_IntPtr)maCBDateTimeFormat.GetEntryData( maCBDateTimeFormat.GetSelectEntryPos() );
654 
655 	LanguageType eLanguage = maCBDateTimeLanguage.GetSelectLanguage();
656 	if( eLanguage != meOldLanguage )
657 		GetOrSetDateTimeLanguage( eLanguage, true );
658 
659 	rNotOnTitle = maCBNotOnTitle.IsChecked();
660 }
661 
662 // -----------------------------------------------------------------------
663 
664 void HeaderFooterTabPage::update()
665 {
666 	maRBDateTimeFixed.Enable( maCBDateTime.IsChecked() );
667 	maTBDateTimeFixed.Enable( maRBDateTimeFixed.IsChecked() && maCBDateTime.IsChecked() );
668 	maRBDateTimeAutomatic.Enable( maCBDateTime.IsChecked() );
669 	maCBDateTimeFormat.Enable( maCBDateTime.IsChecked() && maRBDateTimeAutomatic.IsChecked() );
670 	maFTDateTimeLanguage.Enable( maCBDateTime.IsChecked() && maRBDateTimeAutomatic.IsChecked() );
671 	maCBDateTimeLanguage.Enable( maCBDateTime.IsChecked() && maRBDateTimeAutomatic.IsChecked() );
672 
673 	maFTFooter.Enable( maCBFooter.IsChecked() );
674 	maTBFooter.Enable( maCBFooter.IsChecked() );
675 
676 	maFTHeader.Enable( maCBHeader.IsChecked() );
677 	maTBHeader.Enable( maCBHeader.IsChecked() );
678 
679 	HeaderFooterSettings aSettings;
680 	bool bNotOnTitle;
681 	getData( aSettings, bNotOnTitle );
682 	maCTPreview.update( aSettings );
683 }
684 
685 // -----------------------------------------------------------------------
686 
687 IMPL_LINK( HeaderFooterTabPage, UpdateOnClickHdl, void *, EMPTYARG )
688 {
689 	update();
690 
691 	return 0;
692 }
693 
694 // -----------------------------------------------------------------------
695 
696 IMPL_LINK( HeaderFooterTabPage, ClickApplyToAllHdl, void *, EMPTYARG )
697 {
698 	mpDialog->ApplyToAll( this );
699 	return 0;
700 }
701 
702 // -----------------------------------------------------------------------
703 
704 IMPL_LINK( HeaderFooterTabPage, ClickApplyHdl, void *, EMPTYARG )
705 {
706 	mpDialog->Apply( this );
707 	return 0;
708 }
709 
710 // -----------------------------------------------------------------------
711 
712 IMPL_LINK( HeaderFooterTabPage, ClickCancelHdl, void *, EMPTYARG )
713 {
714 	mpDialog->Cancel( this );
715 	return 0;
716 }
717 
718 // -----------------------------------------------------------------------
719 
720 void HeaderFooterTabPage::GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet )
721 {
722 	if( mbHandoutMode )
723 	{
724 		// if set, set it on all notes master pages
725 		if( bSet )
726 		{
727 			sal_uInt16 nPageCount = mpDoc->GetMasterSdPageCount( PK_NOTES );
728 			sal_uInt16 nPage;
729 			for( nPage = 0; nPage < nPageCount; nPage++ )
730 			{
731 				GetOrSetDateTimeLanguage( rLanguage, bSet, mpDoc->GetMasterSdPage( nPage, PK_NOTES ) );
732 			}
733 		}
734 
735 		// and set it, or just get it from the handout master page
736 		GetOrSetDateTimeLanguage( rLanguage, bSet, mpDoc->GetMasterSdPage( 0, PK_HANDOUT ) );
737 	}
738 	else
739 	{
740 		// get the language from the first master page
741 		// or set it to all master pages
742 		sal_uInt16 nPageCount = bSet ? mpDoc->GetMasterSdPageCount( PK_NOTES ) : 1;
743 		sal_uInt16 nPage;
744 		for( nPage = 0; nPage < nPageCount; nPage++ )
745 		{
746 			GetOrSetDateTimeLanguage( rLanguage, bSet, mpDoc->GetMasterSdPage( nPage, PK_STANDARD ) );
747 		}
748 	}
749 }
750 
751 // -----------------------------------------------------------------------
752 
753 void HeaderFooterTabPage::GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet, SdPage* pPage )
754 {
755 	if( pPage )
756 	{
757 		SdrTextObj* pObj = (SdrTextObj*)pPage->GetPresObj( PRESOBJ_DATETIME );
758 		if( pObj )
759 		{
760 			Outliner* pOutl = mpDoc->GetInternalOutliner();
761 			pOutl->Init( OUTLINERMODE_TEXTOBJECT );
762 			sal_uInt16 nOutlMode = pOutl->GetMode();
763 
764 			EditEngine* pEdit = const_cast< EditEngine* >(&pOutl->GetEditEngine());
765 
766 			OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
767 			if( pOPO )
768 				pOutl->SetText( *pOPO );
769 
770 			EFieldInfo aFieldInfo;
771 			aFieldInfo.pFieldItem = NULL;
772 
773 			sal_uInt16 nParaCount = pEdit->GetParagraphCount();
774 			sal_uInt16 nPara;
775 			for( nPara = 0; (nPara < nParaCount) && (aFieldInfo.pFieldItem == NULL); nPara++ )
776 			{
777 				sal_uInt16 nFieldCount = pEdit->GetFieldCount( nPara );
778 				sal_uInt16 nField;
779 				for( nField = 0; (nField < nFieldCount) && (aFieldInfo.pFieldItem == NULL); nField++ )
780 				{
781 					aFieldInfo = pEdit->GetFieldInfo( nPara, nField );
782 					if( aFieldInfo.pFieldItem )
783 					{
784 						const SvxFieldData* pFieldData = aFieldInfo.pFieldItem->GetField();
785                         if( pFieldData && pFieldData->ISA( SvxDateTimeField ) )
786 						{
787 							break;
788 						}
789 					}
790 					aFieldInfo.pFieldItem = NULL;
791 				}
792 			}
793 
794 
795 			if( aFieldInfo.pFieldItem != NULL )
796 			{
797 				if( bSet )
798 				{
799 					SfxItemSet aSet( pEdit->GetAttribs( aFieldInfo.aPosition.nPara, aFieldInfo.aPosition.nIndex, aFieldInfo.aPosition.nIndex+1, bSet ? GETATTRIBS_CHARATTRIBS : GETATTRIBS_ALL ) );
800 
801 					SvxLanguageItem aItem( rLanguage, EE_CHAR_LANGUAGE );
802 					aSet.Put( aItem );
803 
804 					SvxLanguageItem aItemCJK( rLanguage, EE_CHAR_LANGUAGE_CJK );
805 					aSet.Put( aItemCJK );
806 
807 					SvxLanguageItem aItemCTL( rLanguage, EE_CHAR_LANGUAGE_CTL );
808 					aSet.Put( aItemCTL );
809 
810 					ESelection aSel( aFieldInfo.aPosition.nPara, aFieldInfo.aPosition.nIndex, aFieldInfo.aPosition.nPara, aFieldInfo.aPosition.nIndex+1 );
811 					pEdit->QuickSetAttribs( aSet, aSel );
812 
813 					pObj->SetOutlinerParaObject( pOutl->CreateParaObject() );
814 					pOutl->UpdateFields();
815 				}
816 				else
817 				{
818 					rLanguage =  pOutl->GetLanguage( aFieldInfo.aPosition.nPara, aFieldInfo.aPosition.nIndex );
819 				}
820 			}
821 
822 			pOutl->Clear();
823 			pOutl->Init( nOutlMode );
824 		}
825 	}
826 }
827 
828 ///////////////////////////////////////////////////////////////////////
829 
830 PresLayoutPreview::PresLayoutPreview( ::Window* pParent, const ResId& rResId, SdPage* pMaster )
831 :Control( pParent, rResId ), mpMaster( pMaster ), maPageSize( pMaster->GetSize() )
832 {
833 }
834 
835 // -----------------------------------------------------------------------
836 
837 PresLayoutPreview::~PresLayoutPreview()
838 {
839 }
840 
841 // -----------------------------------------------------------------------
842 
843 void PresLayoutPreview::update( HeaderFooterSettings& rSettings )
844 {
845 	maSettings = rSettings;
846 	Invalidate();
847 }
848 
849 // -----------------------------------------------------------------------
850 
851 void PresLayoutPreview::Paint( OutputDevice& aOut, SdrTextObj* pObj, bool bVisible, bool bDotted /* = false*/ )
852 {
853     // get object transformation
854     basegfx::B2DHomMatrix aObjectTransform;
855     basegfx::B2DPolyPolygon aObjectPolyPolygon;
856     pObj->TRGetBaseGeometry(aObjectTransform, aObjectPolyPolygon);
857 
858     // build complete transformation by adding view transformation from
859     // logic page coordinates to local pixel coordinates
860 	const double fScaleX((double)maOutRect.getWidth() / (double)maPageSize.Width());
861 	const double fScaleY((double)maOutRect.getHeight() / (double)maPageSize.Height());
862     aObjectTransform.scale(fScaleX, fScaleY);
863     aObjectTransform.translate(maOutRect.TopLeft().X(), maOutRect.TopLeft().Y());
864 
865     // create geometry using unit range and object transform
866     basegfx::B2DPolyPolygon aGeometry(basegfx::tools::createUnitPolygon());
867     aGeometry.transform(aObjectTransform);
868 
869     // apply line pattern if wanted
870     if(bDotted)
871     {
872         ::std::vector<double> aPattern;
873         static double fFactor(1.0);
874         aPattern.push_back(3.0 * fFactor);
875         aPattern.push_back(1.0 * fFactor);
876 
877         basegfx::B2DPolyPolygon aDashed;
878         basegfx::tools::applyLineDashing(aGeometry, aPattern, &aDashed);
879         aGeometry = aDashed;
880     }
881 
882     // determine line color
883     svtools::ColorConfig aColorConfig;
884 	svtools::ColorConfigValue aColor( aColorConfig.GetColorValue( bVisible ? svtools::FONTCOLOR : svtools::OBJECTBOUNDARIES ) );
885 
886     // paint at OutDev
887     aOut.SetLineColor(Color(aColor.nColor));
888     aOut.SetFillColor();
889 
890     for(sal_uInt32 a(0); a < aGeometry.count(); a++)
891     {
892         aOut.DrawPolyLine(aGeometry.getB2DPolygon(a));
893     }
894 }
895 
896 // -----------------------------------------------------------------------
897 
898 void PresLayoutPreview::Paint( const Rectangle& )
899 {
900 	Push();
901 
902     svtools::ColorConfig aColorConfig;
903 	svtools::ColorConfigValue aColor( aColorConfig.GetColorValue( svtools::APPBACKGROUND ) );
904 
905 	maOutRect = Rectangle( Point(0,0), GetOutputSize() );
906 
907 	// calculate page size with correct aspect ratio
908 	int nWidth, nHeight;
909 	if( maPageSize.Width() > maPageSize.Height() )
910 	{
911 		nWidth = maOutRect.GetWidth();
912 		nHeight = long( (double)(nWidth * maPageSize.Height()) / (double)maPageSize.Width() );
913 	}
914 	else
915 	{
916 		nHeight = maOutRect.GetHeight();
917 		nWidth = long( (double)(nHeight * maPageSize.Width()) / (double)maPageSize.Height() );
918 	}
919 
920 	maOutRect.nLeft += (maOutRect.GetWidth() - nWidth) >> 1;
921 	maOutRect.nRight = maOutRect.nLeft + nWidth - 1;
922 	maOutRect.nTop += (maOutRect.GetHeight() - nHeight) >> 1;
923 	maOutRect.nBottom = maOutRect.nTop + nHeight - 1;
924 
925 	// draw decoration frame
926 	DecorationView aDecoView( this );
927 	maOutRect = aDecoView.DrawFrame( maOutRect, FRAME_HIGHLIGHT_IN );
928 
929 	// draw page background
930 	SetFillColor( Color(COL_WHITE) );
931 	DrawRect( maOutRect );
932 
933 	// paint presentation objects from masterpage
934 	SdrTextObj* pMasterTitle = (SdrTextObj*)mpMaster->GetPresObj( PRESOBJ_TITLE );
935 	SdrTextObj* pMasterOutline = (SdrTextObj*)mpMaster->GetPresObj( mpMaster->GetPageKind()==PK_NOTES ? PRESOBJ_NOTES : PRESOBJ_OUTLINE );
936 	SdrTextObj* pHeader = (SdrTextObj*)mpMaster->GetPresObj( PRESOBJ_HEADER );
937 	SdrTextObj* pFooter = (SdrTextObj*)mpMaster->GetPresObj( PRESOBJ_FOOTER );
938 	SdrTextObj* pDate   = (SdrTextObj*)mpMaster->GetPresObj( PRESOBJ_DATETIME );
939 	SdrTextObj* pNumber = (SdrTextObj*)mpMaster->GetPresObj( PRESOBJ_SLIDENUMBER );
940 
941 	if( pMasterTitle )
942 		Paint( *this, pMasterTitle, true, true );
943 	if( pMasterOutline )
944 		Paint( *this, pMasterOutline, true, true );
945 	if( pHeader )
946 		Paint( *this, pHeader, maSettings.mbHeaderVisible );
947 	if( pFooter )
948 		Paint( *this, pFooter, maSettings.mbFooterVisible );
949 	if( pDate )
950 		Paint( *this, pDate, maSettings.mbDateTimeVisible );
951 	if( pNumber )
952 		Paint( *this, pNumber, maSettings.mbSlideNumberVisible );
953 
954 	Pop();
955 }
956