LibreOffice Module sd (master) 1
dlgfield.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
28
29#include <strings.hrc>
30#include <sdresid.hxx>
31#include <sdmod.hxx>
32#include <dlgfield.hxx>
33#include <DrawDocShell.hxx>
34#include <utility>
35
40 : GenericDialogController(pWindow, "modules/simpress/ui/dlgfield.ui", "EditFieldsDialog")
41 , m_aInputSet(std::move(aSet))
42 , m_pField(pInField)
43 , m_xRbtFix(m_xBuilder->weld_radio_button("fixedRB"))
44 , m_xRbtVar(m_xBuilder->weld_radio_button("varRB"))
45 , m_xLbLanguage(new SvxLanguageBox(m_xBuilder->weld_combo_box("languageLB")))
46 , m_xLbFormat(m_xBuilder->weld_combo_box("formatLB"))
47{
48 m_xLbLanguage->SetLanguageList( SvxLanguageListFlags::ALL|SvxLanguageListFlags::ONLY_KNOWN, false );
49 m_xLbLanguage->connect_changed(LINK(this, SdModifyFieldDlg, LanguageChangeHdl));
51}
52
54{
55}
56
62{
63 SvxFieldData* pNewField = nullptr;
64
65 if( m_xRbtFix->get_state_changed_from_saved() ||
66 m_xRbtVar->get_state_changed_from_saved() ||
67 m_xLbFormat->get_value_changed_from_saved() )
68 {
69 if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
70 {
72 SvxDateFormat eFormat;
73
74 if( m_xRbtFix->get_active() )
75 eType = SvxDateType::Fix;
76 else
77 eType = SvxDateType::Var;
78
79 eFormat = static_cast<SvxDateFormat>( m_xLbFormat->get_active() + 2 );
80
81 pNewField = new SvxDateField( *pDateField );
82 static_cast<SvxDateField*>( pNewField )->SetType( eType );
83 static_cast<SvxDateField*>( pNewField )->SetFormat( eFormat );
84 }
85 else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
86 {
88 SvxTimeFormat eFormat;
89
90 if( m_xRbtFix->get_active() )
91 eType = SvxTimeType::Fix;
92 else
93 eType = SvxTimeType::Var;
94
95 eFormat = static_cast<SvxTimeFormat>( m_xLbFormat->get_active() + 2 );
96
97 pNewField = new SvxExtTimeField( *pTimeField );
98 static_cast<SvxExtTimeField*>( pNewField )->SetType( eType );
99 static_cast<SvxExtTimeField*>( pNewField )->SetFormat( eFormat );
100 }
101 else if( dynamic_cast< const SvxExtFileField *>( m_pField ) != nullptr )
102 {
104 SvxFileFormat eFormat;
105
106 if( m_xRbtFix->get_active() )
107 eType = SvxFileType::Fix;
108 else
109 eType = SvxFileType::Var;
110
111 eFormat = static_cast<SvxFileFormat>( m_xLbFormat->get_active() );
112
113 ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell* >(SfxObjectShell::Current() );
114
115 if( pDocSh )
116 {
117 OUString aName;
118 if( pDocSh->HasName() )
119 aName = pDocSh->GetMedium()->GetName();
120
121 // Get current filename, not the one stored in the old field
122 pNewField = new SvxExtFileField( aName );
123 static_cast<SvxExtFileField*>( pNewField )->SetType( eType );
124 static_cast<SvxExtFileField*>( pNewField )->SetFormat( eFormat );
125 }
126 }
127 else if( dynamic_cast< const SvxAuthorField *>( m_pField ) != nullptr )
128 {
130 SvxAuthorFormat eFormat;
131
132 if( m_xRbtFix->get_active() )
133 eType = SvxAuthorType::Fix;
134 else
135 eType = SvxAuthorType::Var;
136
137 eFormat = static_cast<SvxAuthorFormat>( m_xLbFormat->get_active() );
138
139 // Get current state of address, not the old one
140 SvtUserOptions aUserOptions;
141 pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
142 static_cast<SvxAuthorField*>( pNewField )->SetType( eType );
143 static_cast<SvxAuthorField*>( pNewField )->SetFormat( eFormat );
144 }
145 }
146
147 return pNewField;
148}
149
151{
152 LanguageType eLangType = m_xLbLanguage->get_active_id();
153
154 m_xLbFormat->clear();
155
156 if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
157 {
158 SvxDateField aDateField( *pDateField );
159
160 //SvxDateFormat::AppDefault, // not used
161 //SvxDateFormat::System, // not used
162 m_xLbFormat->append_text( SdResId( STR_STANDARD_SMALL ) );
163 m_xLbFormat->append_text( SdResId( STR_STANDARD_BIG ) );
164
165 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
166 aDateField.SetFormat( SvxDateFormat::A ); // 13.02.96
167 m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
168 aDateField.SetFormat( SvxDateFormat::B ); // 13.02.1996
169 m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
170 aDateField.SetFormat( SvxDateFormat::C ); // 13.Feb 1996
171 m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
172 aDateField.SetFormat( SvxDateFormat::D ); // 13.February 1996
173 m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
174 aDateField.SetFormat( SvxDateFormat::E ); // Tue, 13.February 1996
175 m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
176 aDateField.SetFormat( SvxDateFormat::F ); // Tuesday, 13.February 1996
177 m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
178
179 m_xLbFormat->set_active( static_cast<sal_uInt16>(pDateField->GetFormat()) - 2 );
180 }
181 else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
182 {
183 SvxExtTimeField aTimeField( *pTimeField );
184
185 //SvxTimeFormat::AppDefault, // not used
186 //SvxTimeFormat::System, // not used
187 m_xLbFormat->append_text( SdResId( STR_STANDARD_NORMAL ) );
188
189 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
190 aTimeField.SetFormat( SvxTimeFormat::HH24_MM ); // 13:49
191 m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
192 aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS ); // 13:49:38
193 m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
194 aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS_00 ); // 13:49:38.78
195 m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
196 aTimeField.SetFormat( SvxTimeFormat::HH12_MM ); // 01:49
197 m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
198 aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS ); // 01:49:38
199 m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
200 aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS_00 ); // 01:49:38.78
201 m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
202 //SvxTimeFormat::HH12_MM_AMPM, // 01:49 PM
203 //SvxTimeFormat::HH12_MM_SS_AMPM, // 01:49:38 PM
204 //SvxTimeFormat::HH12_MM_SS_00_AMPM // 01:49:38.78 PM
205
206 m_xLbFormat->set_active( static_cast<sal_uInt16>(pTimeField->GetFormat()) - 2 );
207 }
208 else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( m_pField ) )
209 {
210 m_xLbFormat->append_text( SdResId( STR_FILEFORMAT_NAME_EXT ) );
211 m_xLbFormat->append_text( SdResId( STR_FILEFORMAT_FULLPATH ) );
212 m_xLbFormat->append_text( SdResId( STR_FILEFORMAT_PATH ) );
213 m_xLbFormat->append_text( SdResId( STR_FILEFORMAT_NAME ) );
214
215 m_xLbFormat->set_active( static_cast<sal_uInt16>( pFileField->GetFormat() ) );
216 }
217 else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( m_pField ) )
218 {
219 SvxAuthorField aAuthorField( *pAuthorField );
220
221 for( sal_uInt16 i = 0; i < 4; i++ )
222 {
223 aAuthorField.SetFormat( static_cast<SvxAuthorFormat>(i) );
224 m_xLbFormat->append_text( aAuthorField.GetFormatted() );
225 }
226
227 m_xLbFormat->set_active( static_cast<sal_uInt16>( pAuthorField->GetFormat() ) );
228
229 }
230
231}
232
234{
235 m_xLbFormat->clear();
236
237 if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
238 {
239 if( pDateField->GetType() == SvxDateType::Fix )
240 m_xRbtFix->set_active(true);
241 else
242 m_xRbtVar->set_active(true);
243 }
244 else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
245 {
246 if( pTimeField->GetType() == SvxTimeType::Fix )
247 m_xRbtFix->set_active(true);
248 else
249 m_xRbtVar->set_active(true);
250 }
251 else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( m_pField ) )
252 {
253 if( pFileField->GetType() == SvxFileType::Fix )
254 m_xRbtFix->set_active(true);
255 else
256 m_xRbtVar->set_active(true);
257 }
258 else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( m_pField ) )
259 {
260 if( pAuthorField->GetType() == SvxAuthorType::Fix )
261 m_xRbtFix->set_active(true);
262 else
263 m_xRbtVar->set_active(true);
264 }
265 m_xRbtFix->save_state();
266 m_xRbtVar->save_state();
267
269 m_xLbLanguage->set_active_id(pItem->GetLanguage());
270
271 m_xLbLanguage->save_active_id();
272
274 m_xLbFormat->save_value();
275}
276
278{
279 FillFormatList();
280}
281
283{
284 SfxItemSet aOutput( *m_aInputSet.GetPool(), svl::Items<EE_CHAR_LANGUAGE, EE_CHAR_LANGUAGE_CTL> );
285
286 if (m_xLbLanguage->get_active_id_changed_from_saved())
287 {
288 LanguageType eLangType = m_xLbLanguage->get_active_id();
289 SvxLanguageItem aItem( eLangType, EE_CHAR_LANGUAGE );
290 aOutput.Put( aItem );
291
292 SvxLanguageItem aItemCJK( eLangType, EE_CHAR_LANGUAGE_CJK );
293 aOutput.Put( aItemCJK );
294
295 SvxLanguageItem aItemCTL( eLangType, EE_CHAR_LANGUAGE_CTL );
296 aOutput.Put( aItemCTL );
297 }
298
299 return aOutput;
300}
301
302/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
dialog to adjust field-commands
Definition: dlgfield.hxx:33
std::unique_ptr< weld::RadioButton > m_xRbtFix
Definition: dlgfield.hxx:38
const SvxFieldData * m_pField
Definition: dlgfield.hxx:36
std::unique_ptr< weld::ComboBox > m_xLbFormat
Definition: dlgfield.hxx:41
SvxFieldData * GetField()
Returns the new field, owned by caller.
Definition: dlgfield.cxx:61
SdModifyFieldDlg(weld::Window *pWindow, const SvxFieldData *pInField, SfxItemSet aSet)
dialog to edit field commands
Definition: dlgfield.cxx:39
void FillFormatList()
Definition: dlgfield.cxx:150
std::unique_ptr< SvxLanguageBox > m_xLbLanguage
Definition: dlgfield.hxx:40
void FillControls()
Definition: dlgfield.cxx:233
virtual ~SdModifyFieldDlg() override
Definition: dlgfield.cxx:53
SfxItemSet m_aInputSet
Definition: dlgfield.hxx:35
std::unique_ptr< weld::RadioButton > m_xRbtVar
Definition: dlgfield.hxx:39
SfxItemSet GetItemSet() const
Definition: dlgfield.cxx:282
SfxItemPool * GetPool() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const OUString & GetName() const
bool HasName() const
SfxMedium * GetMedium() const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
OUString GetFirstName() const
OUString GetID() const
OUString GetLastName() const
OUString GetFormatted() const
void SetFormat(SvxAuthorFormat eFmt)
OUString GetFormatted(SvNumberFormatter &rFormatter, LanguageType eLanguage) const
void SetFormat(SvxDateFormat eFmt)
void SetFormat(SvxTimeFormat eFmt)
OUString GetFormatted(SvNumberFormatter &rFormatter, LanguageType eLanguage) const
IMPL_LINK_NOARG(SdModifyFieldDlg, LanguageChangeHdl, weld::ComboBox &, void)
Definition: dlgfield.cxx:277
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CTL(EE_CHAR_START+16)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE(EE_CHAR_START+14)
SvxAuthorFormat
SvxFileType
SvxFileFormat
SvxTimeFormat
SvxAuthorType
SvxTimeType
SvxDateType
SvxDateFormat
DocumentType eType
OUString aName
int i
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
#define SD_MOD()
Definition: sdmod.hxx:184
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)