bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / headerfooterdlg.cxx
blob4e88df4262ffbfe100afeae0e0fc20e165292d3a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <editeng/eeitem.hxx>
21 #include <editeng/flditem.hxx>
22 #include <editeng/langitem.hxx>
23 #include <svx/langbox.hxx>
24 #include <svx/svdotext.hxx>
25 #include <editeng/editeng.hxx>
26 #include <editeng/outlobj.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <tools/debug.hxx>
30 #include <vcl/button.hxx>
31 #include <vcl/edit.hxx>
32 #include <vcl/fixed.hxx>
33 #include <vcl/layout.hxx>
35 #include <Outliner.hxx>
36 #include <headerfooterdlg.hxx>
37 #include <DrawDocShell.hxx>
38 #include <drawdoc.hxx>
39 #include <ViewShell.hxx>
40 #include <sdmod.hxx>
42 // preview control for presentation layout
43 #include <vcl/ctrl.hxx>
44 #include <tools/color.hxx>
45 #include <i18nlangtag/mslangid.hxx>
46 #include <svtools/colorcfg.hxx>
47 #include <vcl/decoview.hxx>
48 #include <vcl/builderfactory.hxx>
50 #include <undoheaderfooter.hxx>
51 #include <sdundogr.hxx>
53 #include <basegfx/matrix/b2dhommatrix.hxx>
54 #include <basegfx/polygon/b2dpolygontools.hxx>
55 #include <basegfx/polygon/b2dpolypolygontools.hxx>
57 namespace sd
60 class PresLayoutPreview : public Control
62 private:
63 SdPage* mpMaster;
64 HeaderFooterSettings maSettings;
65 Size maPageSize;
66 ::tools::Rectangle maOutRect;
68 private:
69 void Paint(vcl::RenderContext& rRenderContext, SdrTextObj const * pObj, bool bVisible, bool bDotted = false);
71 public:
72 explicit PresLayoutPreview(vcl::Window* pParent);
74 virtual void Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect) override;
75 virtual Size GetOptimalSize() const override;
77 void init(SdPage* pMaster);
78 void update(HeaderFooterSettings const & rSettings);
83 // tab page for slide & header'n'notes
85 namespace sd
88 const int nDateTimeFormatsCount = 12;
89 struct DateAndTimeFormat {
90 SvxDateFormat const meDateFormat;
91 SvxTimeFormat const meTimeFormat;
93 DateAndTimeFormat const nDateTimeFormats[nDateTimeFormatsCount] =
95 { SvxDateFormat::A, SvxTimeFormat::AppDefault },
96 { SvxDateFormat::B, SvxTimeFormat::AppDefault },
97 { SvxDateFormat::C, SvxTimeFormat::AppDefault },
98 { SvxDateFormat::D, SvxTimeFormat::AppDefault },
99 { SvxDateFormat::E, SvxTimeFormat::AppDefault },
100 { SvxDateFormat::F, SvxTimeFormat::AppDefault },
102 { SvxDateFormat::A, SvxTimeFormat::HH24_MM },
103 { SvxDateFormat::A, SvxTimeFormat::HH12_MM },
105 { SvxDateFormat::AppDefault, SvxTimeFormat::HH24_MM },
106 { SvxDateFormat::AppDefault, SvxTimeFormat::HH24_MM_SS },
108 { SvxDateFormat::AppDefault, SvxTimeFormat::HH12_MM },
109 { SvxDateFormat::AppDefault, SvxTimeFormat::HH12_MM_SS },
112 class HeaderFooterTabPage : public TabPage
114 private:
116 VclPtr<FixedText> mpFTIncludeOn;
118 VclPtr<CheckBox> mpCBHeader;
119 VclPtr<VclContainer> mpHeaderBox;
120 VclPtr<Edit> mpTBHeader;
122 VclPtr<CheckBox> mpCBDateTime;
123 VclPtr<RadioButton> mpRBDateTimeFixed;
124 VclPtr<RadioButton> mpRBDateTimeAutomatic;
125 VclPtr<Edit> mpTBDateTimeFixed;
126 VclPtr<ListBox> mpCBDateTimeFormat;
127 VclPtr<FixedText> mpFTDateTimeLanguage;
128 VclPtr<SvxLanguageBox> mpCBDateTimeLanguage;
130 VclPtr<CheckBox> mpCBFooter;
131 VclPtr<VclContainer> mpFooterBox;
132 VclPtr<Edit> mpTBFooter;
134 VclPtr<CheckBox> mpCBSlideNumber;
136 VclPtr<CheckBox> mpCBNotOnTitle;
138 VclPtr<PresLayoutPreview> mpCTPreview;
140 SdDrawDocument* mpDoc;
141 LanguageType meOldLanguage;
143 bool const mbHandoutMode;
145 DECL_LINK( UpdateOnClickHdl, Button*, void );
146 DECL_LINK( LanguageChangeHdl, ListBox&, void );
148 void FillFormatList(sal_Int32 nSelectedPos);
149 void GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet );
150 void GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet, SdPage* pPage );
152 public:
153 HeaderFooterTabPage( vcl::Window* pParent, SdDrawDocument* pDoc, SdPage* pActualPage, bool bHandoutMode );
154 virtual ~HeaderFooterTabPage() override;
155 virtual void dispose() override;
157 void init( const HeaderFooterSettings& rSettings, bool bNotOnTitle );
158 void getData( HeaderFooterSettings& rSettings, bool& rNotOnTitle );
159 void update();
164 using namespace ::sd;
166 HeaderFooterDialog::HeaderFooterDialog( ViewShell* pViewShell, vcl::Window* pParent, SdDrawDocument* pDoc, SdPage* pCurrentPage ) :
167 TabDialog ( pParent, "HeaderFooterDialog", "modules/simpress/ui/headerfooterdialog.ui" ),
168 mpDoc( pDoc ),
169 mpCurrentPage( pCurrentPage ),
170 mpViewShell( pViewShell )
172 get(mpTabCtrl, "tabs" );
174 SdPage* pSlide;
175 SdPage* pNotes;
176 if( pCurrentPage->GetPageKind() == PageKind::Standard )
178 pSlide = pCurrentPage;
179 pNotes = static_cast<SdPage*>(pDoc->GetPage( pCurrentPage->GetPageNum() + 1 ));
181 else if( pCurrentPage->GetPageKind() == PageKind::Notes )
183 pNotes = pCurrentPage;
184 pSlide = static_cast<SdPage*>(pDoc->GetPage( pCurrentPage->GetPageNum() -1 ));
185 mpCurrentPage = pSlide;
187 else
189 // handout
190 pSlide = pDoc->GetSdPage( 0, PageKind::Standard );
191 pNotes = pDoc->GetSdPage( 0, PageKind::Notes );
192 mpCurrentPage = nullptr;
195 pDoc->StopWorkStartupDelay();
196 mpTabCtrl->Show();
198 mnSlidesId = mpTabCtrl->GetPageId("slides");
199 mpSlideTabPage = VclPtr<HeaderFooterTabPage>::Create( mpTabCtrl, pDoc, pSlide, false );
200 mpTabCtrl->SetTabPage( mnSlidesId, mpSlideTabPage );
202 Size aSiz = mpSlideTabPage->GetSizePixel();
203 Size aCtrlSiz = mpTabCtrl->GetOutputSizePixel();
204 // set size on TabControl only if smaller than TabPage
205 if ( aCtrlSiz.Width() < aSiz.Width() || aCtrlSiz.Height() < aSiz.Height() )
207 mpTabCtrl->SetOutputSizePixel( aSiz );
208 aCtrlSiz = aSiz;
211 sal_uInt16 nNotesId = mpTabCtrl->GetPageId("notes");
212 mpNotesHandoutsTabPage = VclPtr<HeaderFooterTabPage>::Create( mpTabCtrl, pDoc, pNotes, true );
213 mpTabCtrl->SetTabPage( nNotesId, mpNotesHandoutsTabPage );
215 get(maPBApplyToAll, "apply_all" );
216 get(maPBApply, "apply" );
217 get(maPBCancel, "cancel" );
219 ActivatePageHdl( mpTabCtrl );
221 mpTabCtrl->SetActivatePageHdl( LINK( this, HeaderFooterDialog, ActivatePageHdl ) );
223 maPBApplyToAll->SetClickHdl( LINK( this, HeaderFooterDialog, ClickApplyToAllHdl ) );
224 maPBApply->SetClickHdl( LINK( this, HeaderFooterDialog, ClickApplyHdl ) );
225 maPBCancel->SetClickHdl( LINK( this, HeaderFooterDialog, ClickCancelHdl ) );
227 maSlideSettings = pSlide->getHeaderFooterSettings();
229 const HeaderFooterSettings& rTitleSettings = mpDoc->GetSdPage(0, PageKind::Standard)->getHeaderFooterSettings();
230 bool bNotOnTitle = !rTitleSettings.mbFooterVisible && !rTitleSettings.mbSlideNumberVisible && !rTitleSettings.mbDateTimeVisible;
232 mpSlideTabPage->init( maSlideSettings, bNotOnTitle );
234 maNotesHandoutSettings = pNotes->getHeaderFooterSettings();
235 mpNotesHandoutsTabPage->init( maNotesHandoutSettings, false );
238 HeaderFooterDialog::~HeaderFooterDialog()
240 disposeOnce();
243 void HeaderFooterDialog::dispose()
245 mpSlideTabPage.disposeAndClear();
246 mpNotesHandoutsTabPage.disposeAndClear();
247 mpTabCtrl.clear();
248 maPBApplyToAll.clear();
249 maPBApply.clear();
250 maPBCancel.clear();
251 TabDialog::dispose();
254 IMPL_LINK( HeaderFooterDialog, ActivatePageHdl, TabControl *, pTabCtrl, void )
256 const sal_uInt16 nId = pTabCtrl->GetCurPageId();
257 TabPage* pTabPage = pTabCtrl->GetTabPage( nId );
258 pTabPage->Show();
259 maPBApply->Show( nId == mnSlidesId );
260 maPBApply->Enable( mpCurrentPage != nullptr );
263 IMPL_LINK_NOARG(HeaderFooterDialog, ClickApplyToAllHdl, Button*, void)
265 ApplyToAll();
268 IMPL_LINK_NOARG(HeaderFooterDialog, ClickApplyHdl, Button*, void)
270 Apply();
273 IMPL_LINK_NOARG(HeaderFooterDialog, ClickCancelHdl, Button*, void)
275 EndDialog();
278 short HeaderFooterDialog::Execute()
280 sal_uInt16 nRet = TabDialog::Execute();
281 if( nRet )
282 mpViewShell->GetDocSh()->SetModified();
283 return nRet;
286 void HeaderFooterDialog::ApplyToAll()
288 sal_uInt16 tabId = mpTabCtrl->GetCurPageId();
289 apply( true, tabId == mnSlidesId );
290 EndDialog(1);
293 void HeaderFooterDialog::Apply()
295 sal_uInt16 tabId = mpTabCtrl->GetCurPageId();
296 apply( false, tabId == mnSlidesId );
297 EndDialog(1);
300 void HeaderFooterDialog::apply( bool bToAll, bool bForceSlides )
302 std::unique_ptr<SdUndoGroup> pUndoGroup(new SdUndoGroup(mpDoc));
303 OUString aComment( GetText() );
304 pUndoGroup->SetComment( aComment );
306 HeaderFooterSettings aNewSettings;
307 bool bNewNotOnTitle;
309 // change slide settings first ...
311 mpSlideTabPage->getData( aNewSettings, bNewNotOnTitle );
313 // only if we pressed apply or apply all on the slide tab page or if the slide settings
314 // have been changed
315 if( bForceSlides || !(aNewSettings == maSlideSettings) )
317 // apply to all slides
318 if( bToAll )
320 int nPageCount = mpDoc->GetSdPageCount( PageKind::Standard );
321 int nPage;
322 for( nPage = 0; nPage < nPageCount; nPage++ )
324 SdPage* pPage = mpDoc->GetSdPage( static_cast<sal_uInt16>(nPage), PageKind::Standard );
325 change( pUndoGroup.get(), pPage, aNewSettings );
328 else
330 // apply only to the current slide
331 DBG_ASSERT( mpCurrentPage && mpCurrentPage->GetPageKind() == PageKind::Standard, "no current page to apply to!" );
332 if( mpCurrentPage && (mpCurrentPage->GetPageKind() == PageKind::Standard) )
334 change( pUndoGroup.get(), mpCurrentPage, aNewSettings );
339 // if we don't want to have header&footer on the first slide
340 if( bNewNotOnTitle )
342 // just hide them, plain simple UI feature
343 HeaderFooterSettings aTempSettings = mpDoc->GetSdPage( 0, PageKind::Standard )->getHeaderFooterSettings();
345 aTempSettings.mbFooterVisible = false;
346 aTempSettings.mbSlideNumberVisible = false;
347 aTempSettings.mbDateTimeVisible = false;
349 change( pUndoGroup.get(), mpDoc->GetSdPage( 0, PageKind::Standard ), aTempSettings );
352 // now notes settings
354 mpNotesHandoutsTabPage->getData( aNewSettings, bNewNotOnTitle );
356 // only if we pressed apply or apply all on the notes tab page or if the notes settings
357 // have been changed
358 if( !bForceSlides || !(aNewSettings == maNotesHandoutSettings) )
360 // first set to all notes pages
361 int nPageCount = mpDoc->GetSdPageCount( PageKind::Notes );
362 int nPage;
363 for( nPage = 0; nPage < nPageCount; nPage++ )
365 SdPage* pPage = mpDoc->GetSdPage( static_cast<sal_uInt16>(nPage), PageKind::Notes );
367 change( pUndoGroup.get(), pPage, aNewSettings );
370 // and last but not least to the handout page
371 change( pUndoGroup.get(), mpDoc->GetMasterSdPage( 0, PageKind::Handout ), aNewSettings );
374 // give the undo group to the undo manager
375 mpViewShell->GetViewFrame()->GetObjectShell()->GetUndoManager()->AddUndoAction(std::move(pUndoGroup));
378 void HeaderFooterDialog::change( SdUndoGroup* pUndoGroup, SdPage* pPage, const HeaderFooterSettings& rNewSettings )
380 pUndoGroup->AddAction(new SdHeaderFooterUndoAction(mpDoc, pPage, rNewSettings ));
381 pPage->setHeaderFooterSettings( rNewSettings );
384 namespace {
386 void recursive_rename_ui_element(vcl::Window& rWindow, const OUString& rPrefix)
388 OUString aID = rWindow.get_id();
389 if (aID.isEmpty())
391 rWindow.set_id(rPrefix + aID);
394 size_t nChildCount = rWindow.GetChildCount();
395 for (size_t i = 0; i < nChildCount; ++i)
397 vcl::Window* pChild = rWindow.GetChild(i);
398 if (pChild)
399 recursive_rename_ui_element(*pChild, rPrefix);
405 HeaderFooterTabPage::HeaderFooterTabPage( vcl::Window* pWindow, SdDrawDocument* pDoc, SdPage* pActualPage, bool bHandoutMode ) :
406 TabPage( pWindow, "HeaderFooterTab", "modules/simpress/ui/headerfootertab.ui" ),
407 mpDoc(pDoc),
408 mbHandoutMode( bHandoutMode )
410 get(mpFTIncludeOn, "include_label");
411 get(mpCBHeader, "header_cb" );
412 get(mpHeaderBox, "header_box" );
413 get(mpTBHeader, "header_text" );
414 get(mpCBDateTime, "datetime_cb" );
415 get(mpRBDateTimeFixed, "rb_fixed" );
416 get(mpRBDateTimeAutomatic, "rb_auto" );
417 get(mpTBDateTimeFixed, "datetime_value" );
418 get(mpCBDateTimeFormat, "datetime_format_list" );
419 get(mpFTDateTimeLanguage, "language_label" );
420 get(mpCBDateTimeLanguage, "language_list" );
422 get(mpCBFooter, "footer_cb" );
423 get(mpFooterBox, "footer_box" );
424 get(mpTBFooter, "footer_text" );
426 get(mpCBSlideNumber, "slide_number" );
428 get(mpCBNotOnTitle, "not_on_title" );
430 get(mpCTPreview, "preview");
431 mpCTPreview->init( pActualPage ?
432 (pActualPage->IsMasterPage() ? pActualPage : static_cast<SdPage*>(&(pActualPage->TRG_GetMasterPage()))) :
433 (pDoc->GetMasterSdPage( 0, bHandoutMode ? PageKind::Notes : PageKind::Standard )) );
435 if( mbHandoutMode )
437 OUString sPageNo = get<FixedText>("replacement_a")->GetText();
438 mpCBSlideNumber->SetText( sPageNo );
440 OUString sFrameTitle = get<FixedText>("replacement_b")->GetText();
441 mpFTIncludeOn->SetText( sFrameTitle );
444 mpCBHeader->Show( mbHandoutMode );
445 mpHeaderBox->Show( mbHandoutMode );
446 mpCBNotOnTitle->Show( !mbHandoutMode );
448 mpCBDateTime->SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
449 mpRBDateTimeFixed->SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
450 mpRBDateTimeAutomatic->SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
451 mpCBFooter->SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
452 mpCBHeader->SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
453 mpCBSlideNumber->SetClickHdl( LINK( this, HeaderFooterTabPage, UpdateOnClickHdl ) );
455 mpCBDateTimeLanguage->SetLanguageList( SvxLanguageListFlags::ALL|SvxLanguageListFlags::ONLY_KNOWN, false, false );
456 mpCBDateTimeLanguage->SetSelectHdl( LINK( this, HeaderFooterTabPage, LanguageChangeHdl ) );
458 GetOrSetDateTimeLanguage( meOldLanguage, false );
459 meOldLanguage = MsLangId::getRealLanguage( meOldLanguage );
460 mpCBDateTimeLanguage->SelectLanguage( meOldLanguage );
462 FillFormatList(0);
464 if (mbHandoutMode)
465 recursive_rename_ui_element(*this, "handout");
466 else
467 recursive_rename_ui_element(*this, "slide");
470 HeaderFooterTabPage::~HeaderFooterTabPage()
472 disposeOnce();
475 void HeaderFooterTabPage::dispose()
477 mpFTIncludeOn.clear();
478 mpCBHeader.clear();
479 mpHeaderBox.clear();
480 mpTBHeader.clear();
481 mpCBDateTime.clear();
482 mpRBDateTimeFixed.clear();
483 mpRBDateTimeAutomatic.clear();
484 mpTBDateTimeFixed.clear();
485 mpCBDateTimeFormat.clear();
486 mpFTDateTimeLanguage.clear();
487 mpCBDateTimeLanguage.clear();
488 mpCBFooter.clear();
489 mpFooterBox.clear();
490 mpTBFooter.clear();
491 mpCBSlideNumber.clear();
492 mpCBNotOnTitle.clear();
493 mpCTPreview.clear();
494 TabPage::dispose();
497 IMPL_LINK_NOARG(HeaderFooterTabPage, LanguageChangeHdl, ListBox&, void)
499 FillFormatList( mpCBDateTimeFormat->GetSelectedEntryPos() );
502 void HeaderFooterTabPage::FillFormatList( sal_Int32 nSelectedPos )
504 LanguageType eLanguage = mpCBDateTimeLanguage->GetSelectedLanguage();
506 mpCBDateTimeFormat->Clear();
508 DateTime aDateTime( DateTime::SYSTEM );
510 for( int nFormat = 0; nFormat < nDateTimeFormatsCount; nFormat++ )
512 OUString aStr( SvxDateTimeField::GetFormatted(
513 aDateTime, aDateTime,
514 nDateTimeFormats[nFormat].meDateFormat, nDateTimeFormats[nFormat].meTimeFormat,
515 *(SD_MOD()->GetNumberFormatter()), eLanguage ) );
516 const sal_Int32 nEntry = mpCBDateTimeFormat->InsertEntry( aStr );
517 if( nFormat == nSelectedPos )
519 mpCBDateTimeFormat->SelectEntryPos( nEntry );
520 mpCBDateTimeFormat->SetText( aStr );
525 void HeaderFooterTabPage::init( const HeaderFooterSettings& rSettings, bool bNotOnTitle )
527 mpCBDateTime->Check( rSettings.mbDateTimeVisible );
528 mpRBDateTimeFixed->Check( rSettings.mbDateTimeIsFixed );
529 mpRBDateTimeAutomatic->Check( !rSettings.mbDateTimeIsFixed );
530 mpTBDateTimeFixed->SetText( rSettings.maDateTimeText );
532 mpCBHeader->Check( rSettings.mbHeaderVisible );
533 mpTBHeader->SetText( rSettings.maHeaderText );
535 mpCBFooter->Check( rSettings.mbFooterVisible );
536 mpTBFooter->SetText( rSettings.maFooterText );
538 mpCBSlideNumber->Check( rSettings.mbSlideNumberVisible );
540 mpCBNotOnTitle->Check( bNotOnTitle );
542 mpCBDateTimeLanguage->SelectLanguage( meOldLanguage );
544 for( sal_Int32 nPos = 0; nPos < mpCBDateTimeFormat->GetEntryCount(); nPos++ )
546 if( nDateTimeFormats[nPos].meDateFormat == rSettings.meDateFormat && nDateTimeFormats[nPos].meTimeFormat == rSettings.meTimeFormat )
548 mpCBDateTimeFormat->SelectEntryPos( nPos );
549 mpCBDateTimeFormat->SetText( mpCBDateTimeFormat->GetEntry(nPos) );
550 break;
554 update();
557 void HeaderFooterTabPage::getData( HeaderFooterSettings& rSettings, bool& rNotOnTitle )
559 rSettings.mbDateTimeVisible = mpCBDateTime->IsChecked();
560 rSettings.mbDateTimeIsFixed = mpRBDateTimeFixed->IsChecked();
561 rSettings.maDateTimeText = mpTBDateTimeFixed->GetText();
562 rSettings.mbFooterVisible = mpCBFooter->IsChecked();
563 rSettings.maFooterText = mpTBFooter->GetText();
564 rSettings.mbSlideNumberVisible = mpCBSlideNumber->IsChecked();
565 rSettings.mbHeaderVisible = mpCBHeader->IsChecked();
566 rSettings.maHeaderText = mpTBHeader->GetText();
568 if( mpCBDateTimeFormat->GetSelectedEntryCount() == 1 )
570 sal_Int32 nPos = mpCBDateTimeFormat->GetSelectedEntryPos();
571 rSettings.meDateFormat = nDateTimeFormats[nPos].meDateFormat;
572 rSettings.meTimeFormat = nDateTimeFormats[nPos].meTimeFormat;
575 LanguageType eLanguage = mpCBDateTimeLanguage->GetSelectedLanguage();
576 if( eLanguage != meOldLanguage )
577 GetOrSetDateTimeLanguage( eLanguage, true );
579 rNotOnTitle = mpCBNotOnTitle->IsChecked();
582 void HeaderFooterTabPage::update()
584 mpRBDateTimeFixed->Enable( mpCBDateTime->IsChecked() );
585 mpTBDateTimeFixed->Enable( mpRBDateTimeFixed->IsChecked() && mpCBDateTime->IsChecked() );
586 mpRBDateTimeAutomatic->Enable( mpCBDateTime->IsChecked() );
587 mpCBDateTimeFormat->Enable( mpCBDateTime->IsChecked() && mpRBDateTimeAutomatic->IsChecked() );
588 mpFTDateTimeLanguage->Enable( mpCBDateTime->IsChecked() && mpRBDateTimeAutomatic->IsChecked() );
589 mpCBDateTimeLanguage->Enable( mpCBDateTime->IsChecked() && mpRBDateTimeAutomatic->IsChecked() );
591 mpFooterBox->Enable( mpCBFooter->IsChecked() );
593 mpHeaderBox->Enable( mpCBHeader->IsChecked() );
595 HeaderFooterSettings aSettings;
596 bool bNotOnTitle;
597 getData( aSettings, bNotOnTitle );
598 mpCTPreview->update( aSettings );
601 IMPL_LINK_NOARG(HeaderFooterTabPage, UpdateOnClickHdl, Button*, void)
603 update();
606 void HeaderFooterTabPage::GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet )
608 if( mbHandoutMode )
610 // if set, set it on all notes master pages
611 if( bSet )
613 sal_uInt16 nPageCount = mpDoc->GetMasterSdPageCount( PageKind::Notes );
614 sal_uInt16 nPage;
615 for( nPage = 0; nPage < nPageCount; nPage++ )
617 GetOrSetDateTimeLanguage( rLanguage, bSet, mpDoc->GetMasterSdPage( nPage, PageKind::Notes ) );
621 // #i119985# and set it, or just get it from the notes master page
622 GetOrSetDateTimeLanguage( rLanguage, bSet, mpDoc->GetMasterSdPage( 0, PageKind::Notes ) );
624 else
626 // get the language from the first master page
627 // or set it to all master pages
628 sal_uInt16 nPageCount = bSet ? mpDoc->GetMasterSdPageCount( PageKind::Notes ) : 1;
629 sal_uInt16 nPage;
630 for( nPage = 0; nPage < nPageCount; nPage++ )
632 GetOrSetDateTimeLanguage( rLanguage, bSet, mpDoc->GetMasterSdPage( nPage, PageKind::Standard ) );
637 void HeaderFooterTabPage::GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet, SdPage* pPage )
639 if( !pPage )
640 return;
642 SdrTextObj* pObj = static_cast<SdrTextObj*>(pPage->GetPresObj( PRESOBJ_DATETIME ));
643 if( !pObj )
644 return;
646 Outliner* pOutl = mpDoc->GetInternalOutliner();
647 pOutl->Init( OutlinerMode::TextObject );
648 OutlinerMode nOutlMode = pOutl->GetMode();
650 EditEngine* pEdit = const_cast< EditEngine* >(&pOutl->GetEditEngine());
652 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
653 if( pOPO )
654 pOutl->SetText( *pOPO );
656 EPosition aDateFieldPosition;
657 bool bHasDateFieldItem = false;
659 sal_Int32 nParaCount = pEdit->GetParagraphCount();
660 for (sal_Int32 nPara = 0; (nPara < nParaCount) && !bHasDateFieldItem; ++nPara)
662 sal_uInt16 nFieldCount = pEdit->GetFieldCount(nPara);
663 for (sal_uInt16 nField = 0; (nField < nFieldCount); ++nField)
665 EFieldInfo aFieldInfo = pEdit->GetFieldInfo(nPara, nField);
666 if (aFieldInfo.pFieldItem)
668 const SvxFieldData* pFieldData = aFieldInfo.pFieldItem->GetField();
669 if (dynamic_cast<const SvxDateTimeField*>(pFieldData) != nullptr ||
670 dynamic_cast<const SvxDateField*>(pFieldData) != nullptr)
672 bHasDateFieldItem = true;
673 aDateFieldPosition = aFieldInfo.aPosition;
674 break;
680 if (bHasDateFieldItem)
682 if( bSet )
684 SfxItemSet aSet(pEdit->GetAttribs(aDateFieldPosition.nPara,
685 aDateFieldPosition.nIndex,
686 aDateFieldPosition.nIndex+1,
687 GetAttribsFlags::CHARATTRIBS));
689 SvxLanguageItem aItem( rLanguage, EE_CHAR_LANGUAGE );
690 aSet.Put( aItem );
692 SvxLanguageItem aItemCJK( rLanguage, EE_CHAR_LANGUAGE_CJK );
693 aSet.Put( aItemCJK );
695 SvxLanguageItem aItemCTL( rLanguage, EE_CHAR_LANGUAGE_CTL );
696 aSet.Put( aItemCTL );
698 ESelection aSel(aDateFieldPosition.nPara, aDateFieldPosition.nIndex,
699 aDateFieldPosition.nPara, aDateFieldPosition.nIndex+1 );
700 pEdit->QuickSetAttribs( aSet, aSel );
702 pObj->SetOutlinerParaObject( pOutl->CreateParaObject() );
703 pOutl->UpdateFields();
705 else
707 rLanguage = pOutl->GetLanguage(aDateFieldPosition.nPara,
708 aDateFieldPosition.nIndex );
712 pOutl->Clear();
713 pOutl->Init( nOutlMode );
716 PresLayoutPreview::PresLayoutPreview( vcl::Window* pParent )
717 : Control(pParent)
718 , mpMaster(nullptr)
722 VCL_BUILDER_FACTORY(PresLayoutPreview)
724 Size PresLayoutPreview::GetOptimalSize() const
726 return LogicToPixel(Size(80, 80), MapMode(MapUnit::MapAppFont));
729 void PresLayoutPreview::init( SdPage *pMaster )
731 mpMaster = pMaster;
732 maPageSize = pMaster->GetSize();
735 void PresLayoutPreview::update( HeaderFooterSettings const & rSettings )
737 maSettings = rSettings;
738 Invalidate();
741 void PresLayoutPreview::Paint(vcl::RenderContext& rRenderContext, SdrTextObj const * pObj, bool bVisible, bool bDotted /* = false*/ )
743 // get object transformation
744 basegfx::B2DHomMatrix aObjectTransform;
745 basegfx::B2DPolyPolygon aObjectPolyPolygon;
746 pObj->TRGetBaseGeometry(aObjectTransform, aObjectPolyPolygon);
748 // build complete transformation by adding view transformation from
749 // logic page coordinates to local pixel coordinates
750 const double fScaleX(static_cast<double>(maOutRect.getWidth()) / static_cast<double>(maPageSize.Width()));
751 const double fScaleY(static_cast<double>(maOutRect.getHeight()) / static_cast<double>(maPageSize.Height()));
752 aObjectTransform.scale(fScaleX, fScaleY);
753 aObjectTransform.translate(maOutRect.TopLeft().X(), maOutRect.TopLeft().Y());
755 // create geometry using unit range and object transform
756 basegfx::B2DPolyPolygon aGeometry(basegfx::utils::createUnitPolygon());
757 aGeometry.transform(aObjectTransform);
759 // apply line pattern if wanted
760 if (bDotted)
762 std::vector<double> aPattern;
763 static const double fFactor(1.0);
764 aPattern.push_back(3.0 * fFactor);
765 aPattern.push_back(1.0 * fFactor);
767 basegfx::B2DPolyPolygon aDashed;
768 basegfx::utils::applyLineDashing(aGeometry, aPattern, &aDashed);
769 aGeometry = aDashed;
772 // determine line color
773 svtools::ColorConfig aColorConfig;
774 svtools::ColorConfigValue aColor( aColorConfig.GetColorValue( bVisible ? svtools::FONTCOLOR : svtools::OBJECTBOUNDARIES ) );
776 // paint at OutDev
777 rRenderContext.SetLineColor(aColor.nColor);
778 rRenderContext.SetFillColor();
780 for (sal_uInt32 a(0); a < aGeometry.count(); a++)
782 rRenderContext.DrawPolyLine(aGeometry.getB2DPolygon(a));
786 void PresLayoutPreview::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle&)
788 rRenderContext.Push();
790 maOutRect = ::tools::Rectangle(Point(0,0), rRenderContext.GetOutputSize());
792 // calculate page size with correct aspect ratio
793 int nWidth, nHeight;
794 if( maPageSize.Width() > maPageSize.Height() )
796 nWidth = maOutRect.GetWidth();
797 nHeight = maPageSize.Width() == 0 ? 0 : long( static_cast<double>(nWidth * maPageSize.Height()) / static_cast<double>(maPageSize.Width()) );
799 else
801 nHeight = maOutRect.GetHeight();
802 nWidth = maPageSize.Height() == 0 ? 0 : long( static_cast<double>(nHeight * maPageSize.Width()) / static_cast<double>(maPageSize.Height()) );
805 maOutRect.AdjustLeft((maOutRect.GetWidth() - nWidth) >> 1 );
806 maOutRect.SetRight( maOutRect.Left() + nWidth - 1 );
807 maOutRect.AdjustTop((maOutRect.GetHeight() - nHeight) >> 1 );
808 maOutRect.SetBottom( maOutRect.Top() + nHeight - 1 );
810 // draw decoration frame
811 DecorationView aDecoView(&rRenderContext);
812 maOutRect = aDecoView.DrawFrame(maOutRect, DrawFrameStyle::In);
814 // draw page background
815 rRenderContext.SetFillColor(COL_WHITE);
816 rRenderContext.DrawRect(maOutRect);
818 // paint presentation objects from masterpage
819 if (nullptr != mpMaster)
821 SdrTextObj* pMasterTitle = static_cast<SdrTextObj*>(mpMaster->GetPresObj(PRESOBJ_TITLE));
822 SdrTextObj* pMasterOutline = static_cast<SdrTextObj*>(mpMaster->GetPresObj(mpMaster->GetPageKind() == PageKind::Notes ? PRESOBJ_NOTES : PRESOBJ_OUTLINE));
823 SdrTextObj* pHeader = static_cast<SdrTextObj*>(mpMaster->GetPresObj(PRESOBJ_HEADER));
824 SdrTextObj* pFooter = static_cast<SdrTextObj*>(mpMaster->GetPresObj(PRESOBJ_FOOTER));
825 SdrTextObj* pDate = static_cast<SdrTextObj*>(mpMaster->GetPresObj(PRESOBJ_DATETIME));
826 SdrTextObj* pNumber = static_cast<SdrTextObj*>(mpMaster->GetPresObj(PRESOBJ_SLIDENUMBER));
828 if (pMasterTitle)
829 Paint(rRenderContext, pMasterTitle, true, true);
830 if (pMasterOutline)
831 Paint(rRenderContext, pMasterOutline, true, true);
832 if (pHeader)
833 Paint(rRenderContext, pHeader, maSettings.mbHeaderVisible);
834 if (pFooter)
835 Paint(rRenderContext, pFooter, maSettings.mbFooterVisible);
836 if (pDate)
837 Paint(rRenderContext, pDate, maSettings.mbDateTimeVisible);
838 if (pNumber)
839 Paint(rRenderContext, pNumber, maSettings.mbSlideNumberVisible);
842 rRenderContext.Pop();
845 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */