1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/objsh.hxx>
23 #include <sfx2/docfile.hxx>
24 #include <svl/itemset.hxx>
25 #include <svx/langbox.hxx>
26 #include <editeng/langitem.hxx>
27 #include <unotools/useroptions.hxx>
29 #include <strings.hrc>
30 #include <sdresid.hxx>
32 #include <dlgfield.hxx>
33 #include <DrawDocShell.hxx>
36 * dialog to edit field commands
38 SdModifyFieldDlg::SdModifyFieldDlg(weld::Window
* pWindow
, const SvxFieldData
* pInField
, const SfxItemSet
& rSet
)
39 : GenericDialogController(pWindow
, "modules/simpress/ui/dlgfield.ui", "EditFieldsDialog")
42 , m_xRbtFix(m_xBuilder
->weld_radio_button("fixedRB"))
43 , m_xRbtVar(m_xBuilder
->weld_radio_button("varRB"))
44 , m_xLbLanguage(new LanguageBox(m_xBuilder
->weld_combo_box("languageLB")))
45 , m_xLbFormat(m_xBuilder
->weld_combo_box("formatLB"))
47 m_xLbLanguage
->SetLanguageList( SvxLanguageListFlags::ALL
|SvxLanguageListFlags::ONLY_KNOWN
, false );
48 m_xLbLanguage
->connect_changed(LINK(this, SdModifyFieldDlg
, LanguageChangeHdl
));
52 SdModifyFieldDlg::~SdModifyFieldDlg()
57 * Returns the new field, owned by caller.
58 * Returns NULL if nothing has changed.
60 SvxFieldData
* SdModifyFieldDlg::GetField()
62 SvxFieldData
* pNewField
= nullptr;
64 if( m_xRbtFix
->get_state_changed_from_saved() ||
65 m_xRbtVar
->get_state_changed_from_saved() ||
66 m_xLbFormat
->get_value_changed_from_saved() )
68 if( dynamic_cast< const SvxDateField
*>( m_pField
) != nullptr )
70 const SvxDateField
* pDateField
= static_cast<const SvxDateField
*>(m_pField
);
72 SvxDateFormat eFormat
;
74 if( m_xRbtFix
->get_active() )
75 eType
= SvxDateType::Fix
;
77 eType
= SvxDateType::Var
;
79 eFormat
= static_cast<SvxDateFormat
>( m_xLbFormat
->get_active() + 2 );
81 pNewField
= new SvxDateField( *pDateField
);
82 static_cast<SvxDateField
*>( pNewField
)->SetType( eType
);
83 static_cast<SvxDateField
*>( pNewField
)->SetFormat( eFormat
);
85 else if( dynamic_cast< const SvxExtTimeField
*>( m_pField
) != nullptr )
87 const SvxExtTimeField
* pTimeField
= static_cast<const SvxExtTimeField
*>( m_pField
);
89 SvxTimeFormat eFormat
;
91 if( m_xRbtFix
->get_active() )
92 eType
= SvxTimeType::Fix
;
94 eType
= SvxTimeType::Var
;
96 eFormat
= static_cast<SvxTimeFormat
>( m_xLbFormat
->get_active() + 2 );
98 pNewField
= new SvxExtTimeField( *pTimeField
);
99 static_cast<SvxExtTimeField
*>( pNewField
)->SetType( eType
);
100 static_cast<SvxExtTimeField
*>( pNewField
)->SetFormat( eFormat
);
102 else if( dynamic_cast< const SvxExtFileField
*>( m_pField
) != nullptr )
104 const SvxExtFileField
* pFileField
= static_cast<const SvxExtFileField
*>( m_pField
);
106 SvxFileFormat eFormat
;
108 if( m_xRbtFix
->get_active() )
109 eType
= SvxFileType::Fix
;
111 eType
= SvxFileType::Var
;
113 eFormat
= static_cast<SvxFileFormat
>( m_xLbFormat
->get_active() );
115 ::sd::DrawDocShell
* pDocSh
= dynamic_cast< ::sd::DrawDocShell
* >(SfxObjectShell::Current() );
119 SvxExtFileField
aFileField( *pFileField
);
122 if( pDocSh
->HasName() )
123 aName
= pDocSh
->GetMedium()->GetName();
125 // Get current filename, not the one stored in the old field
126 pNewField
= new SvxExtFileField( aName
);
127 static_cast<SvxExtFileField
*>( pNewField
)->SetType( eType
);
128 static_cast<SvxExtFileField
*>( pNewField
)->SetFormat( eFormat
);
131 else if( dynamic_cast< const SvxAuthorField
*>( m_pField
) != nullptr )
134 SvxAuthorFormat eFormat
;
136 if( m_xRbtFix
->get_active() )
137 eType
= SvxAuthorType::Fix
;
139 eType
= SvxAuthorType::Var
;
141 eFormat
= static_cast<SvxAuthorFormat
>( m_xLbFormat
->get_active() );
143 // Get current state of address, not the old one
144 SvtUserOptions aUserOptions
;
145 pNewField
= new SvxAuthorField( aUserOptions
.GetFirstName(), aUserOptions
.GetLastName(), aUserOptions
.GetID() );
146 static_cast<SvxAuthorField
*>( pNewField
)->SetType( eType
);
147 static_cast<SvxAuthorField
*>( pNewField
)->SetFormat( eFormat
);
154 void SdModifyFieldDlg::FillFormatList()
156 LanguageType eLangType
= m_xLbLanguage
->get_active_id();
158 m_xLbFormat
->clear();
160 if( dynamic_cast< const SvxDateField
*>( m_pField
) != nullptr )
162 const SvxDateField
* pDateField
= static_cast<const SvxDateField
*>( m_pField
);
163 SvxDateField
aDateField( *pDateField
);
165 //SvxDateFormat::AppDefault, // not used
166 //SvxDateFormat::System, // not used
167 m_xLbFormat
->append_text( SdResId( STR_STANDARD_SMALL
) );
168 m_xLbFormat
->append_text( SdResId( STR_STANDARD_BIG
) );
170 SvNumberFormatter
* pNumberFormatter
= SD_MOD()->GetNumberFormatter();
171 aDateField
.SetFormat( SvxDateFormat::A
); // 13.02.96
172 m_xLbFormat
->append_text( aDateField
.GetFormatted( *pNumberFormatter
, eLangType
) );
173 aDateField
.SetFormat( SvxDateFormat::B
); // 13.02.1996
174 m_xLbFormat
->append_text( aDateField
.GetFormatted( *pNumberFormatter
, eLangType
) );
175 aDateField
.SetFormat( SvxDateFormat::C
); // 13.Feb 1996
176 m_xLbFormat
->append_text( aDateField
.GetFormatted( *pNumberFormatter
, eLangType
) );
177 aDateField
.SetFormat( SvxDateFormat::D
); // 13.Februar 1996
178 m_xLbFormat
->append_text( aDateField
.GetFormatted( *pNumberFormatter
, eLangType
) );
179 aDateField
.SetFormat( SvxDateFormat::E
); // Die, 13.Februar 1996
180 m_xLbFormat
->append_text( aDateField
.GetFormatted( *pNumberFormatter
, eLangType
) );
181 aDateField
.SetFormat( SvxDateFormat::F
); // Dienstag, 13.Februar 1996
182 m_xLbFormat
->append_text( aDateField
.GetFormatted( *pNumberFormatter
, eLangType
) );
184 m_xLbFormat
->set_active( static_cast<sal_uInt16
>(pDateField
->GetFormat()) - 2 );
186 else if( dynamic_cast< const SvxExtTimeField
*>( m_pField
) != nullptr )
188 const SvxExtTimeField
* pTimeField
= static_cast<const SvxExtTimeField
*>( m_pField
);
189 SvxExtTimeField
aTimeField( *pTimeField
);
191 //SvxTimeFormat::AppDefault, // not used
192 //SvxTimeFormat::System, // not used
193 m_xLbFormat
->append_text( SdResId( STR_STANDARD_NORMAL
) );
195 SvNumberFormatter
* pNumberFormatter
= SD_MOD()->GetNumberFormatter();
196 aTimeField
.SetFormat( SvxTimeFormat::HH24_MM
); // 13:49
197 m_xLbFormat
->append_text( aTimeField
.GetFormatted( *pNumberFormatter
, eLangType
) );
198 aTimeField
.SetFormat( SvxTimeFormat::HH24_MM_SS
); // 13:49:38
199 m_xLbFormat
->append_text( aTimeField
.GetFormatted( *pNumberFormatter
, eLangType
) );
200 aTimeField
.SetFormat( SvxTimeFormat::HH24_MM_SS_00
); // 13:49:38.78
201 m_xLbFormat
->append_text( aTimeField
.GetFormatted( *pNumberFormatter
, eLangType
) );
202 aTimeField
.SetFormat( SvxTimeFormat::HH12_MM
); // 01:49
203 m_xLbFormat
->append_text( aTimeField
.GetFormatted( *pNumberFormatter
, eLangType
) );
204 aTimeField
.SetFormat( SvxTimeFormat::HH12_MM_SS
); // 01:49:38
205 m_xLbFormat
->append_text( aTimeField
.GetFormatted( *pNumberFormatter
, eLangType
) );
206 aTimeField
.SetFormat( SvxTimeFormat::HH12_MM_SS_00
); // 01:49:38.78
207 m_xLbFormat
->append_text( aTimeField
.GetFormatted( *pNumberFormatter
, eLangType
) );
208 //SvxTimeFormat::HH12_MM_AMPM, // 01:49 PM
209 //SvxTimeFormat::HH12_MM_SS_AMPM, // 01:49:38 PM
210 //SvxTimeFormat::HH12_MM_SS_00_AMPM // 01:49:38.78 PM
212 m_xLbFormat
->set_active( static_cast<sal_uInt16
>(pTimeField
->GetFormat()) - 2 );
214 else if( dynamic_cast< const SvxExtFileField
*>( m_pField
) != nullptr )
216 const SvxExtFileField
* pFileField
= static_cast<const SvxExtFileField
*>( m_pField
);
217 SvxExtFileField
aFileField( *pFileField
);
219 m_xLbFormat
->append_text( SdResId( STR_FILEFORMAT_NAME_EXT
) );
220 m_xLbFormat
->append_text( SdResId( STR_FILEFORMAT_FULLPATH
) );
221 m_xLbFormat
->append_text( SdResId( STR_FILEFORMAT_PATH
) );
222 m_xLbFormat
->append_text( SdResId( STR_FILEFORMAT_NAME
) );
224 m_xLbFormat
->set_active( static_cast<sal_uInt16
>( pFileField
->GetFormat() ) );
226 else if( dynamic_cast< const SvxAuthorField
*>( m_pField
) != nullptr )
228 const SvxAuthorField
* pAuthorField
= static_cast<const SvxAuthorField
*>( m_pField
);
229 SvxAuthorField
aAuthorField( *pAuthorField
);
231 for( sal_uInt16 i
= 0; i
< 4; i
++ )
233 aAuthorField
.SetFormat( static_cast<SvxAuthorFormat
>(i
) );
234 m_xLbFormat
->append_text( aAuthorField
.GetFormatted() );
237 m_xLbFormat
->set_active( static_cast<sal_uInt16
>( pAuthorField
->GetFormat() ) );
243 void SdModifyFieldDlg::FillControls()
245 m_xLbFormat
->clear();
247 if( dynamic_cast< const SvxDateField
*>( m_pField
) != nullptr )
249 const SvxDateField
* pDateField
= static_cast<const SvxDateField
*>(m_pField
);
250 SvxDateField
aDateField( *pDateField
);
252 if( pDateField
->GetType() == SvxDateType::Fix
)
253 m_xRbtFix
->set_active(true);
255 m_xRbtVar
->set_active(true);
257 else if( dynamic_cast< const SvxExtTimeField
*>( m_pField
) != nullptr )
259 const SvxExtTimeField
* pTimeField
= static_cast<const SvxExtTimeField
*>(m_pField
);
260 SvxExtTimeField
aTimeField( *pTimeField
);
262 if( pTimeField
->GetType() == SvxTimeType::Fix
)
263 m_xRbtFix
->set_active(true);
265 m_xRbtVar
->set_active(true);
267 else if( dynamic_cast< const SvxExtFileField
*>( m_pField
) != nullptr )
269 const SvxExtFileField
* pFileField
= static_cast<const SvxExtFileField
*>(m_pField
);
270 SvxExtFileField
aFileField( *pFileField
);
272 if( pFileField
->GetType() == SvxFileType::Fix
)
273 m_xRbtFix
->set_active(true);
275 m_xRbtVar
->set_active(true);
277 else if( dynamic_cast< const SvxAuthorField
*>( m_pField
) != nullptr )
279 const SvxAuthorField
* pAuthorField
= static_cast<const SvxAuthorField
*>(m_pField
);
280 SvxAuthorField
aAuthorField( *pAuthorField
);
282 if( pAuthorField
->GetType() == SvxAuthorType::Fix
)
283 m_xRbtFix
->set_active(true);
285 m_xRbtVar
->set_active(true);
287 m_xRbtFix
->save_state();
288 m_xRbtVar
->save_state();
290 const SfxPoolItem
* pItem
;
291 if( SfxItemState::SET
== m_aInputSet
.GetItemState(EE_CHAR_LANGUAGE
, true, &pItem
) )
292 m_xLbLanguage
->set_active_id(static_cast<const SvxLanguageItem
*>(pItem
)->GetLanguage());
294 m_xLbLanguage
->save_active_id();
297 m_xLbFormat
->save_value();
300 IMPL_LINK_NOARG(SdModifyFieldDlg
, LanguageChangeHdl
, weld::ComboBox
&, void)
305 SfxItemSet
SdModifyFieldDlg::GetItemSet()
307 SfxItemSet
aOutput( *m_aInputSet
.GetPool(), svl::Items
<EE_CHAR_LANGUAGE
, EE_CHAR_LANGUAGE_CTL
>{} );
309 if (m_xLbLanguage
->get_active_id_changed_from_saved())
311 LanguageType eLangType
= m_xLbLanguage
->get_active_id();
312 SvxLanguageItem
aItem( eLangType
, EE_CHAR_LANGUAGE
);
313 aOutput
.Put( aItem
);
315 SvxLanguageItem
aItemCJK( eLangType
, EE_CHAR_LANGUAGE_CJK
);
316 aOutput
.Put( aItemCJK
);
318 SvxLanguageItem
aItemCTL( eLangType
, EE_CHAR_LANGUAGE_CTL
);
319 aOutput
.Put( aItemCTL
);
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */