1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <editeng/eeitem.hxx>
#include <editeng/flditem.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/docfile.hxx>
#include <svl/itemset.hxx>
#include <svx/langbox.hxx>
#include <editeng/langitem.hxx>
#include <unotools/useroptions.hxx>
#include <strings.hrc>
#include <sdresid.hxx>
#include <sdmod.hxx>
#include <dlgfield.hxx>
#include <DrawDocShell.hxx>
/**
* dialog to edit field commands
*/
SdModifyFieldDlg::SdModifyFieldDlg(weld::Window* pWindow, const SvxFieldData* pInField, const SfxItemSet& rSet)
: GenericDialogController(pWindow, "modules/simpress/ui/dlgfield.ui", "EditFieldsDialog")
, m_aInputSet(rSet)
, m_pField(pInField)
, m_xRbtFix(m_xBuilder->weld_radio_button("fixedRB"))
, m_xRbtVar(m_xBuilder->weld_radio_button("varRB"))
, m_xLbLanguage(new SvxLanguageBox(m_xBuilder->weld_combo_box("languageLB")))
, m_xLbFormat(m_xBuilder->weld_combo_box("formatLB"))
{
m_xLbLanguage->SetLanguageList( SvxLanguageListFlags::ALL|SvxLanguageListFlags::ONLY_KNOWN, false );
m_xLbLanguage->connect_changed(LINK(this, SdModifyFieldDlg, LanguageChangeHdl));
FillControls();
}
SdModifyFieldDlg::~SdModifyFieldDlg()
{
}
/**
* Returns the new field, owned by caller.
* Returns NULL if nothing has changed.
*/
SvxFieldData* SdModifyFieldDlg::GetField()
{
SvxFieldData* pNewField = nullptr;
if( m_xRbtFix->get_state_changed_from_saved() ||
m_xRbtVar->get_state_changed_from_saved() ||
m_xLbFormat->get_value_changed_from_saved() )
{
if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
{
SvxDateType eType;
SvxDateFormat eFormat;
if( m_xRbtFix->get_active() )
eType = SvxDateType::Fix;
else
eType = SvxDateType::Var;
eFormat = static_cast<SvxDateFormat>( m_xLbFormat->get_active() + 2 );
pNewField = new SvxDateField( *pDateField );
static_cast<SvxDateField*>( pNewField )->SetType( eType );
static_cast<SvxDateField*>( pNewField )->SetFormat( eFormat );
}
else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
{
SvxTimeType eType;
SvxTimeFormat eFormat;
if( m_xRbtFix->get_active() )
eType = SvxTimeType::Fix;
else
eType = SvxTimeType::Var;
eFormat = static_cast<SvxTimeFormat>( m_xLbFormat->get_active() + 2 );
pNewField = new SvxExtTimeField( *pTimeField );
static_cast<SvxExtTimeField*>( pNewField )->SetType( eType );
static_cast<SvxExtTimeField*>( pNewField )->SetFormat( eFormat );
}
else if( dynamic_cast< const SvxExtFileField *>( m_pField ) != nullptr )
{
SvxFileType eType;
SvxFileFormat eFormat;
if( m_xRbtFix->get_active() )
eType = SvxFileType::Fix;
else
eType = SvxFileType::Var;
eFormat = static_cast<SvxFileFormat>( m_xLbFormat->get_active() );
::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell* >(SfxObjectShell::Current() );
if( pDocSh )
{
OUString aName;
if( pDocSh->HasName() )
aName = pDocSh->GetMedium()->GetName();
// Get current filename, not the one stored in the old field
pNewField = new SvxExtFileField( aName );
static_cast<SvxExtFileField*>( pNewField )->SetType( eType );
static_cast<SvxExtFileField*>( pNewField )->SetFormat( eFormat );
}
}
else if( dynamic_cast< const SvxAuthorField *>( m_pField ) != nullptr )
{
SvxAuthorType eType;
SvxAuthorFormat eFormat;
if( m_xRbtFix->get_active() )
eType = SvxAuthorType::Fix;
else
eType = SvxAuthorType::Var;
eFormat = static_cast<SvxAuthorFormat>( m_xLbFormat->get_active() );
// Get current state of address, not the old one
SvtUserOptions aUserOptions;
pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
static_cast<SvxAuthorField*>( pNewField )->SetType( eType );
static_cast<SvxAuthorField*>( pNewField )->SetFormat( eFormat );
}
}
return pNewField;
}
void SdModifyFieldDlg::FillFormatList()
{
LanguageType eLangType = m_xLbLanguage->get_active_id();
m_xLbFormat->clear();
if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
{
SvxDateField aDateField( *pDateField );
//SvxDateFormat::AppDefault, // not used
//SvxDateFormat::System, // not used
m_xLbFormat->append_text( SdResId( STR_STANDARD_SMALL ) );
m_xLbFormat->append_text( SdResId( STR_STANDARD_BIG ) );
SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
aDateField.SetFormat( SvxDateFormat::A ); // 13.02.96
m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
aDateField.SetFormat( SvxDateFormat::B ); // 13.02.1996
m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
aDateField.SetFormat( SvxDateFormat::C ); // 13.Feb 1996
m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
aDateField.SetFormat( SvxDateFormat::D ); // 13.Februar 1996
m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
aDateField.SetFormat( SvxDateFormat::E ); // Die, 13.Februar 1996
m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
aDateField.SetFormat( SvxDateFormat::F ); // Dienstag, 13.Februar 1996
m_xLbFormat->append_text( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
m_xLbFormat->set_active( static_cast<sal_uInt16>(pDateField->GetFormat()) - 2 );
}
else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
{
SvxExtTimeField aTimeField( *pTimeField );
//SvxTimeFormat::AppDefault, // not used
//SvxTimeFormat::System, // not used
m_xLbFormat->append_text( SdResId( STR_STANDARD_NORMAL ) );
SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
aTimeField.SetFormat( SvxTimeFormat::HH24_MM ); // 13:49
m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS ); // 13:49:38
m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS_00 ); // 13:49:38.78
m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
aTimeField.SetFormat( SvxTimeFormat::HH12_MM ); // 01:49
m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS ); // 01:49:38
m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS_00 ); // 01:49:38.78
m_xLbFormat->append_text( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
//SvxTimeFormat::HH12_MM_AMPM, // 01:49 PM
//SvxTimeFormat::HH12_MM_SS_AMPM, // 01:49:38 PM
//SvxTimeFormat::HH12_MM_SS_00_AMPM // 01:49:38.78 PM
m_xLbFormat->set_active( static_cast<sal_uInt16>(pTimeField->GetFormat()) - 2 );
}
else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( m_pField ) )
{
m_xLbFormat->append_text( SdResId( STR_FILEFORMAT_NAME_EXT ) );
m_xLbFormat->append_text( SdResId( STR_FILEFORMAT_FULLPATH ) );
m_xLbFormat->append_text( SdResId( STR_FILEFORMAT_PATH ) );
m_xLbFormat->append_text( SdResId( STR_FILEFORMAT_NAME ) );
m_xLbFormat->set_active( static_cast<sal_uInt16>( pFileField->GetFormat() ) );
}
else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( m_pField ) )
{
SvxAuthorField aAuthorField( *pAuthorField );
for( sal_uInt16 i = 0; i < 4; i++ )
{
aAuthorField.SetFormat( static_cast<SvxAuthorFormat>(i) );
m_xLbFormat->append_text( aAuthorField.GetFormatted() );
}
m_xLbFormat->set_active( static_cast<sal_uInt16>( pAuthorField->GetFormat() ) );
}
}
void SdModifyFieldDlg::FillControls()
{
m_xLbFormat->clear();
if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
{
if( pDateField->GetType() == SvxDateType::Fix )
m_xRbtFix->set_active(true);
else
m_xRbtVar->set_active(true);
}
else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
{
if( pTimeField->GetType() == SvxTimeType::Fix )
m_xRbtFix->set_active(true);
else
m_xRbtVar->set_active(true);
}
else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( m_pField ) )
{
if( pFileField->GetType() == SvxFileType::Fix )
m_xRbtFix->set_active(true);
else
m_xRbtVar->set_active(true);
}
else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( m_pField ) )
{
if( pAuthorField->GetType() == SvxAuthorType::Fix )
m_xRbtFix->set_active(true);
else
m_xRbtVar->set_active(true);
}
m_xRbtFix->save_state();
m_xRbtVar->save_state();
if( const SvxLanguageItem* pItem = m_aInputSet.GetItemIfSet(EE_CHAR_LANGUAGE ) )
m_xLbLanguage->set_active_id(pItem->GetLanguage());
m_xLbLanguage->save_active_id();
FillFormatList();
m_xLbFormat->save_value();
}
IMPL_LINK_NOARG(SdModifyFieldDlg, LanguageChangeHdl, weld::ComboBox&, void)
{
FillFormatList();
}
SfxItemSet SdModifyFieldDlg::GetItemSet() const
{
SfxItemSet aOutput( *m_aInputSet.GetPool(), svl::Items<EE_CHAR_LANGUAGE, EE_CHAR_LANGUAGE_CTL> );
if (m_xLbLanguage->get_active_id_changed_from_saved())
{
LanguageType eLangType = m_xLbLanguage->get_active_id();
SvxLanguageItem aItem( eLangType, EE_CHAR_LANGUAGE );
aOutput.Put( aItem );
SvxLanguageItem aItemCJK( eLangType, EE_CHAR_LANGUAGE_CJK );
aOutput.Put( aItemCJK );
SvxLanguageItem aItemCTL( eLangType, EE_CHAR_LANGUAGE_CTL );
aOutput.Put( aItemCTL );
}
return aOutput;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|