diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-15 13:55:39 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-18 13:16:23 +0200 |
commit | 7d14555ef7e867c5b1a0e195e3ef056885697c59 (patch) | |
tree | af39963caf1328d41756e4463a2a39019448026d /sd/source | |
parent | 0083b33650c2f584ceff6eeaf9ef6993bfe0ae9b (diff) |
convert SvxDateFormat to scoped enum
And simplify the code in sd/headerfooterdlg, no
need for the complex encoding of date and time when we
can just index into a static array.
Change-Id: I677400bf1f956c81eba665b71dbda9183b63f55c
Reviewed-on: https://gerrit.libreoffice.org/42346
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd/source')
-rw-r--r-- | sd/source/core/sdpage.cxx | 6 | ||||
-rw-r--r-- | sd/source/filter/eppt/eppt.cxx | 8 | ||||
-rw-r--r-- | sd/source/filter/ppt/pptin.cxx | 3 | ||||
-rw-r--r-- | sd/source/ui/app/sdmod2.cxx | 3 | ||||
-rw-r--r-- | sd/source/ui/app/sdpopup.cxx | 16 | ||||
-rw-r--r-- | sd/source/ui/dlg/dlgfield.cxx | 18 | ||||
-rw-r--r-- | sd/source/ui/dlg/headerfooterdlg.cxx | 56 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unopage.cxx | 9 |
9 files changed, 70 insertions, 53 deletions
diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx index 9ef9fee3c543..57f11cdebf51 100644 --- a/sd/source/core/sdpage.cxx +++ b/sd/source/core/sdpage.cxx @@ -3126,7 +3126,8 @@ HeaderFooterSettings::HeaderFooterSettings() mbSlideNumberVisible = false; mbDateTimeVisible = true; mbDateTimeIsFixed = true; - meDateTimeFormat = SVXDATEFORMAT_A; + meDateFormat = SvxDateFormat::A; + meTimeFormat = SvxTimeFormat::AppDefault; } bool HeaderFooterSettings::operator==( const HeaderFooterSettings& rSettings ) const @@ -3138,7 +3139,8 @@ bool HeaderFooterSettings::operator==( const HeaderFooterSettings& rSettings ) c (mbSlideNumberVisible == rSettings.mbSlideNumberVisible) && (mbDateTimeVisible == rSettings.mbDateTimeVisible) && (mbDateTimeIsFixed == rSettings.mbDateTimeIsFixed) && - (meDateTimeFormat == rSettings.meDateTimeFormat) && + (meDateFormat == rSettings.meDateFormat) && + (meTimeFormat == rSettings.meTimeFormat) && (maDateTimeText == rSettings.maDateTimeText); } diff --git a/sd/source/filter/eppt/eppt.cxx b/sd/source/filter/eppt/eppt.cxx index 24fad7dd7bd8..2bd1fcb2e2ae 100644 --- a/sd/source/filter/eppt/eppt.cxx +++ b/sd/source/filter/eppt/eppt.cxx @@ -619,17 +619,17 @@ void PPTWriter::ImplCreateHeaderFooters( css::uno::Reference< css::beans::XPrope SvxTimeFormat eTimeFormat = (SvxTimeFormat)( ( nFormat >> 4 ) & 0xf ); switch( eDateFormat ) { - case SVXDATEFORMAT_F : + case SvxDateFormat::F : nFormat = 1; break; - case SVXDATEFORMAT_D : + case SvxDateFormat::D : nFormat = 2; break; - case SVXDATEFORMAT_C : + case SvxDateFormat::C : nFormat = 4; break; default: - case SVXDATEFORMAT_A : + case SvxDateFormat::A : nFormat = 0; } switch( eTimeFormat ) diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx index fe102637b60e..263e27deb041 100644 --- a/sd/source/filter/ppt/pptin.cxx +++ b/sd/source/filter/ppt/pptin.cxx @@ -1460,7 +1460,8 @@ void ImplSdPPTImport::SetHeaderFooterPageSettings( SdPage* pPage, const PptSlide SvxDateFormat eDateFormat; SvxTimeFormat eTimeFormat; PPTFieldEntry::GetDateTime( pHFE->nAtom & 0xff, eDateFormat, eTimeFormat ); - rHeaderFooterSettings.meDateTimeFormat = eDateFormat | ( static_cast<int>(eTimeFormat) << 4 ); + rHeaderFooterSettings.meDateFormat = eDateFormat; + rHeaderFooterSettings.meTimeFormat = eTimeFormat; } break; case 1 : diff --git a/sd/source/ui/app/sdmod2.cxx b/sd/source/ui/app/sdmod2.cxx index 89f0285abca0..f7c76b3e54b1 100644 --- a/sd/source/ui/app/sdmod2.cxx +++ b/sd/source/ui/app/sdmod2.cxx @@ -391,7 +391,8 @@ IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, pInfo, void) Date aDate( Date::SYSTEM ); tools::Time aTime( tools::Time::SYSTEM ); LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() ); - aRepresentation = SvxDateTimeField::GetFormatted( aDate, aTime, (SvxDateFormat)rSettings.meDateTimeFormat, *GetNumberFormatter(), eLang ); + aRepresentation = SvxDateTimeField::GetFormatted( aDate, aTime, + rSettings.meDateFormat, rSettings.meTimeFormat, *GetNumberFormatter(), eLang ); } } } diff --git a/sd/source/ui/app/sdpopup.cxx b/sd/source/ui/app/sdpopup.cxx index 2a9f8d9615bb..19d63c06b452 100644 --- a/sd/source/ui/app/sdpopup.cxx +++ b/sd/source/ui/app/sdpopup.cxx @@ -65,24 +65,24 @@ void SdFieldPopup::Fill( LanguageType eLanguage ) else CheckItem( 2 ); - //SVXDATEFORMAT_APPDEFAULT, // is not used - //SVXDATEFORMAT_SYSTEM, // is not used + //SvxDateFormat::AppDefault, // is not used + //SvxDateFormat::System, // is not used InsertItem( nID++, SdResId( STR_STANDARD_SMALL ), nStyle ); InsertItem( nID++, SdResId( STR_STANDARD_BIG ), nStyle ); SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter(); - aDateField.SetFormat( SVXDATEFORMAT_A ); // 13.02.96 + aDateField.SetFormat( SvxDateFormat::A ); // 13.02.96 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); - aDateField.SetFormat( SVXDATEFORMAT_B ); // 13.02.1996 + aDateField.SetFormat( SvxDateFormat::B ); // 13.02.1996 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); - aDateField.SetFormat( SVXDATEFORMAT_C ); // 13.Feb 1996 + aDateField.SetFormat( SvxDateFormat::C ); // 13.Feb 1996 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); - aDateField.SetFormat( SVXDATEFORMAT_D ); // 13.Februar 1996 + aDateField.SetFormat( SvxDateFormat::D ); // 13.Februar 1996 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); - aDateField.SetFormat( SVXDATEFORMAT_E ); // Die, 13.Februar 1996 + aDateField.SetFormat( SvxDateFormat::E ); // Die, 13.Februar 1996 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); - aDateField.SetFormat( SVXDATEFORMAT_F ); // Dienstag, 13.Februar 1996 + aDateField.SetFormat( SvxDateFormat::F ); // Dienstag, 13.Februar 1996 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle ); CheckItem( (sal_uInt16) ( pDateField->GetFormat() ) + 1 ); // - 2 + 3 ! diff --git a/sd/source/ui/dlg/dlgfield.cxx b/sd/source/ui/dlg/dlgfield.cxx index 188dfbded6e9..726a852f1305 100644 --- a/sd/source/ui/dlg/dlgfield.cxx +++ b/sd/source/ui/dlg/dlgfield.cxx @@ -177,26 +177,26 @@ void SdModifyFieldDlg::FillFormatList() const SvxDateField* pDateField = static_cast<const SvxDateField*>( pField ); SvxDateField aDateField( *pDateField ); - //SVXDATEFORMAT_APPDEFAULT, // not used - //SVXDATEFORMAT_SYSTEM, // not used + //SvxDateFormat::AppDefault, // not used + //SvxDateFormat::System, // not used m_pLbFormat->InsertEntry( SdResId( STR_STANDARD_SMALL ) ); m_pLbFormat->InsertEntry( SdResId( STR_STANDARD_BIG ) ); SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter(); - aDateField.SetFormat( SVXDATEFORMAT_A ); // 13.02.96 + aDateField.SetFormat( SvxDateFormat::A ); // 13.02.96 m_pLbFormat->InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); - aDateField.SetFormat( SVXDATEFORMAT_B ); // 13.02.1996 + aDateField.SetFormat( SvxDateFormat::B ); // 13.02.1996 m_pLbFormat->InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); - aDateField.SetFormat( SVXDATEFORMAT_C ); // 13.Feb 1996 + aDateField.SetFormat( SvxDateFormat::C ); // 13.Feb 1996 m_pLbFormat->InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); - aDateField.SetFormat( SVXDATEFORMAT_D ); // 13.Februar 1996 + aDateField.SetFormat( SvxDateFormat::D ); // 13.Februar 1996 m_pLbFormat->InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); - aDateField.SetFormat( SVXDATEFORMAT_E ); // Die, 13.Februar 1996 + aDateField.SetFormat( SvxDateFormat::E ); // Die, 13.Februar 1996 m_pLbFormat->InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); - aDateField.SetFormat( SVXDATEFORMAT_F ); // Dienstag, 13.Februar 1996 + aDateField.SetFormat( SvxDateFormat::F ); // Dienstag, 13.Februar 1996 m_pLbFormat->InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); - m_pLbFormat->SelectEntryPos( (sal_uInt16) ( pDateField->GetFormat() - 2 ) ); + m_pLbFormat->SelectEntryPos( static_cast<sal_uInt16>(pDateField->GetFormat()) - 2 ); } else if( dynamic_cast< const SvxExtTimeField *>( pField ) != nullptr ) { diff --git a/sd/source/ui/dlg/headerfooterdlg.cxx b/sd/source/ui/dlg/headerfooterdlg.cxx index 922aa47c027f..2cc869c8e3ab 100644 --- a/sd/source/ui/dlg/headerfooterdlg.cxx +++ b/sd/source/ui/dlg/headerfooterdlg.cxx @@ -91,23 +91,27 @@ namespace sd { const int nDateTimeFormatsCount = 12; -int const nDateTimeFormats[nDateTimeFormatsCount] = +struct DateAndTimeFormat { + SvxDateFormat meDateFormat; + SvxTimeFormat meTimeFormat; +}; +DateAndTimeFormat const nDateTimeFormats[nDateTimeFormatsCount] = { - SVXDATEFORMAT_A, - SVXDATEFORMAT_B, - SVXDATEFORMAT_C, - SVXDATEFORMAT_D, - SVXDATEFORMAT_E, - SVXDATEFORMAT_F, + { SvxDateFormat::A, SvxTimeFormat::AppDefault }, + { SvxDateFormat::B, SvxTimeFormat::AppDefault }, + { SvxDateFormat::C, SvxTimeFormat::AppDefault }, + { SvxDateFormat::D, SvxTimeFormat::AppDefault }, + { SvxDateFormat::E, SvxTimeFormat::AppDefault }, + { SvxDateFormat::F, SvxTimeFormat::AppDefault }, - SVXDATEFORMAT_A | (static_cast<int>(SvxTimeFormat::HH24_MM) << 4), - SVXDATEFORMAT_A | (static_cast<int>(SvxTimeFormat::HH12_MM) << 4), + { SvxDateFormat::A, SvxTimeFormat::HH24_MM }, + { SvxDateFormat::A, SvxTimeFormat::HH12_MM }, - static_cast<int>(SvxTimeFormat::HH24_MM) << 4, - static_cast<int>(SvxTimeFormat::HH24_MM_SS) << 4, + { SvxDateFormat::AppDefault, SvxTimeFormat::HH24_MM }, + { SvxDateFormat::AppDefault, SvxTimeFormat::HH24_MM_SS }, - static_cast<int>(SvxTimeFormat::HH12_MM) << 4, - static_cast<int>(SvxTimeFormat::HH12_MM_SS) << 4 + { SvxDateFormat::AppDefault, SvxTimeFormat::HH12_MM }, + { SvxDateFormat::AppDefault, SvxTimeFormat::HH12_MM_SS }, }; class HeaderFooterTabPage : public TabPage @@ -146,7 +150,7 @@ private: DECL_LINK( UpdateOnClickHdl, Button*, void ); DECL_LINK( LanguageChangeHdl, ListBox&, void ); - void FillFormatList(int eFormat); + void FillFormatList(sal_Int32 nSelectedPos); void GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet ); void GetOrSetDateTimeLanguage( LanguageType &rLanguage, bool bSet, SdPage* pPage ); @@ -439,7 +443,7 @@ HeaderFooterTabPage::HeaderFooterTabPage( vcl::Window* pWindow, SdDrawDocument* meOldLanguage = MsLangId::getRealLanguage( meOldLanguage ); mpCBDateTimeLanguage->SelectLanguage( meOldLanguage ); - FillFormatList(SVXDATEFORMAT_A); + FillFormatList(0); } HeaderFooterTabPage::~HeaderFooterTabPage() @@ -471,10 +475,10 @@ void HeaderFooterTabPage::dispose() IMPL_LINK_NOARG(HeaderFooterTabPage, LanguageChangeHdl, ListBox&, void) { - FillFormatList( (int)reinterpret_cast<sal_IntPtr>(mpCBDateTimeFormat->GetSelectEntryData()) ); + FillFormatList( mpCBDateTimeFormat->GetSelectEntryPos() ); } -void HeaderFooterTabPage::FillFormatList( int eFormat ) +void HeaderFooterTabPage::FillFormatList( sal_Int32 nSelectedPos ) { LanguageType eLanguage = mpCBDateTimeLanguage->GetSelectLanguage(); @@ -483,15 +487,14 @@ void HeaderFooterTabPage::FillFormatList( int eFormat ) Date aDate( Date::SYSTEM ); tools::Time aTime( tools::Time::SYSTEM ); - int nFormat; - for( nFormat = 0; nFormat < nDateTimeFormatsCount; nFormat++ ) + for( int nFormat = 0; nFormat < nDateTimeFormatsCount; nFormat++ ) { OUString aStr( SvxDateTimeField::GetFormatted( - aDate, aTime, nDateTimeFormats[nFormat], + aDate, aTime, + nDateTimeFormats[nFormat].meDateFormat, nDateTimeFormats[nFormat].meTimeFormat, *(SD_MOD()->GetNumberFormatter()), eLanguage ) ); const sal_Int32 nEntry = mpCBDateTimeFormat->InsertEntry( aStr ); - mpCBDateTimeFormat->SetEntryData( nEntry, reinterpret_cast<void*>((sal_IntPtr)nDateTimeFormats[nFormat] )); - if( nDateTimeFormats[nFormat] == eFormat ) + if( nFormat == nSelectedPos ) { mpCBDateTimeFormat->SelectEntryPos( nEntry ); mpCBDateTimeFormat->SetText( aStr ); @@ -520,8 +523,7 @@ void HeaderFooterTabPage::init( const HeaderFooterSettings& rSettings, bool bNot for( sal_Int32 nPos = 0; nPos < mpCBDateTimeFormat->GetEntryCount(); nPos++ ) { - int nFormat = (int)reinterpret_cast<sal_IntPtr>(mpCBDateTimeFormat->GetEntryData( nPos )); - if( nFormat == rSettings.meDateTimeFormat ) + if( nDateTimeFormats[nPos].meDateFormat == rSettings.meDateFormat && nDateTimeFormats[nPos].meTimeFormat == rSettings.meTimeFormat ) { mpCBDateTimeFormat->SelectEntryPos( nPos ); mpCBDateTimeFormat->SetText( mpCBDateTimeFormat->GetEntry(nPos) ); @@ -544,7 +546,11 @@ void HeaderFooterTabPage::getData( HeaderFooterSettings& rSettings, bool& rNotOn rSettings.maHeaderText = mpTBHeader->GetText(); if( mpCBDateTimeFormat->GetSelectEntryCount() == 1 ) - rSettings.meDateTimeFormat = (int)reinterpret_cast<sal_IntPtr>(mpCBDateTimeFormat->GetSelectEntryData()); + { + sal_Int32 nPos = mpCBDateTimeFormat->GetSelectEntryPos(); + rSettings.meDateFormat = nDateTimeFormats[nPos].meDateFormat; + rSettings.meTimeFormat = nDateTimeFormats[nPos].meTimeFormat; + } LanguageType eLanguage = mpCBDateTimeLanguage->GetSelectLanguage(); if( eLanguage != meOldLanguage ) diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 341a74dd8c62..cc129aa487f3 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -1590,7 +1590,9 @@ void ImplPDFExportComments( const uno::Reference< drawing::XDrawPage >& xPage, v Date aDate( aDateTime.Day, aDateTime.Month, aDateTime.Year ); ::tools::Time aTime( ::tools::Time::EMPTY ); - OUString aStr( SvxDateTimeField::GetFormatted( aDate, aTime, SVXDATEFORMAT_B, *(SD_MOD()->GetNumberFormatter()), eLanguage ) ); + OUString aStr = SvxDateTimeField::GetFormatted( aDate, aTime, + SvxDateFormat::B, SvxTimeFormat::AppDefault, + *(SD_MOD()->GetNumberFormatter()), eLanguage ); vcl::PDFNote aNote; OUString sTitle( xAnnotation->getAuthor() ); diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx index 84f7a8399f36..76167735cf7b 100644 --- a/sd/source/ui/unoidl/unopage.cxx +++ b/sd/source/ui/unoidl/unopage.cxx @@ -922,7 +922,8 @@ void SAL_CALL SdGenericDrawPage::setPropertyValue( const OUString& aPropertyName if( ! ( aValue >>= nValue ) ) throw lang::IllegalArgumentException(); - aHeaderFooterSettings.meDateTimeFormat = nValue; + aHeaderFooterSettings.meDateFormat = static_cast<SvxDateFormat>(nValue & 0x0f); + aHeaderFooterSettings.meTimeFormat = static_cast<SvxTimeFormat>((nValue >> 4) & 0x0f); break; } } @@ -1289,7 +1290,11 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName ) } break; case WID_PAGE_DATETIMEFORMAT: - aAny <<= (sal_Int32)GetPage()->getHeaderFooterSettings().meDateTimeFormat; + { + auto const & rSettings = GetPage()->getHeaderFooterSettings(); + sal_Int32 x = static_cast<sal_Int32>(rSettings.meDateFormat) & (static_cast<sal_Int32>(rSettings.meTimeFormat) << 4); + aAny <<= x; + } break; case WID_TRANSITION_TYPE: |