LibreOffice Module sd (master) 1
sdpopup.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 <sal/config.h>
21
22#include <string_view>
23
24#include <editeng/flditem.hxx>
25#include <sfx2/objsh.hxx>
26#include <sfx2/docfile.hxx>
28#include <vcl/svapp.hxx>
29
30#include <strings.hrc>
31#include <sdpopup.hxx>
32#include <sdresid.hxx>
33#include <sdmod.hxx>
34#include <DrawDocShell.hxx>
35
36/*
37 * Popup menu for editing of field command
38 */
40 : m_xBuilder(Application::CreateBuilder(nullptr, "modules/simpress/ui/fieldmenu.ui"))
41 , m_xPopup(m_xBuilder->weld_menu("menu"))
42 , m_pField(pInField)
43{
44 Fill(eLanguage);
45}
46
48{
49}
50
52{
53 sal_uInt16 nID = 1;
54 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FIX));
55 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_VAR));
56 m_xPopup->append_separator("separator1");
57
58 if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
59 {
60 SvxDateField aDateField( *pDateField );
61
62 if (pDateField->GetType() == SvxDateType::Fix)
63 m_xPopup->set_active("1", true);
64 else
65 m_xPopup->set_active("2", true);
66
67 //SvxDateFormat::AppDefault, // is not used
68 //SvxDateFormat::System, // is not used
69 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_STANDARD_SMALL));
70 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_STANDARD_BIG));
71
72 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
73 aDateField.SetFormat( SvxDateFormat::A ); // 13.02.96
74 m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
75 aDateField.SetFormat( SvxDateFormat::B ); // 13.02.1996
76 m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
77 aDateField.SetFormat( SvxDateFormat::C ); // 13.Feb 1996
78 m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
79
80 aDateField.SetFormat( SvxDateFormat::D ); // 13.Februar 1996
81 m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
82 aDateField.SetFormat( SvxDateFormat::E ); // Die, 13.Februar 1996
83 m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
84 aDateField.SetFormat( SvxDateFormat::F ); // Dienstag, 13.Februar 1996
85 m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
86
87 m_xPopup->set_active(OUString::number(static_cast<sal_uInt16>( pDateField->GetFormat() ) + 1), true); // - 2 + 3 !
88 }
89 else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
90 {
91 SvxExtTimeField aTimeField( *pTimeField );
92
93 if( pTimeField->GetType() == SvxTimeType::Fix )
94 m_xPopup->set_active("1", true);
95 else
96 m_xPopup->set_active("2", true);
97
98 //SvxTimeFormat::AppDefault, // is not used
99 //SvxTimeFormat::System, // is not used
100 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_STANDARD_NORMAL));
101
102 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
103 aTimeField.SetFormat( SvxTimeFormat::HH24_MM ); // 13:49
104 m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
105 aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS ); // 13:49:38
106 m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
107 aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS_00 ); // 13:49:38.78
108 m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
109
110 aTimeField.SetFormat( SvxTimeFormat::HH12_MM ); // 01:49
111 m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
112 aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS ); // 01:49:38
113 m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
114 aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS_00 ); // 01:49:38.78
115 m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
116 //SvxTimeFormat::HH12_MM_AMPM, // 01:49 PM
117 //SvxTimeFormat::HH12_MM_SS_AMPM, // 01:49:38 PM
118 //SvxTimeFormat::HH12_MM_SS_00_AMPM // 01:49:38.78 PM
119
120 m_xPopup->set_active(OUString::number(static_cast<sal_uInt16>( pTimeField->GetFormat() ) + 1), true); // - 2 + 3 !
121 }
122 else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( m_pField ) )
123 {
124 //SvxExtFileField aFileField( *pFileField );
125
126 if( pFileField->GetType() == SvxFileType::Fix )
127 m_xPopup->set_active("1", true);
128 else
129 m_xPopup->set_active("2", true);
130
131 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FILEFORMAT_NAME_EXT));
132 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FILEFORMAT_FULLPATH));
133 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FILEFORMAT_PATH));
134 m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FILEFORMAT_NAME));
135
136 m_xPopup->set_active(OUString::number(static_cast<sal_uInt16>( pFileField->GetFormat() ) + 3), true);
137 }
138 else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( m_pField ) )
139 {
140 SvxAuthorField aAuthorField( *pAuthorField );
141
142 if( pAuthorField->GetType() == SvxAuthorType::Fix )
143 m_xPopup->set_active("1", true);
144 else
145 m_xPopup->set_active("2", true);
146
147 for( sal_uInt16 i = 0; i < 4; i++ )
148 {
149 aAuthorField.SetFormat( static_cast<SvxAuthorFormat>(i) );
150 m_xPopup->append_radio(OUString::number(nID++), aAuthorField.GetFormatted());
151 }
152 m_xPopup->set_active(OUString::number(static_cast<sal_uInt16>( pAuthorField->GetFormat() ) + 3), true);
153 }
154}
155
157{
158 OUString sIdent = m_xPopup->popup_at_rect(pParent, rRect);
159 if (sIdent.isEmpty())
160 return;
161
162 if (sIdent == "1" || sIdent == "2")
163 {
164 m_xPopup->set_active("1", sIdent == "1");
165 m_xPopup->set_active("2", sIdent == "2");
166 }
167 else
168 {
169 int nCount = m_xPopup->n_children();
170 for (int i = 3; i < nCount; i++)
171 m_xPopup->set_active(
172 OUString::number(i), sIdent == std::u16string_view(OUString::number(i)));
173 }
174}
175
181{
182 SvxFieldData* pNewField = nullptr;
183
184 sal_uInt16 nCount = m_xPopup->n_children();
185
186 if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
187 {
189 SvxDateFormat eFormat;
190 sal_uInt16 i;
191
192 if (m_xPopup->get_active("1"))
193 eType = SvxDateType::Fix;
194 else
195 eType = SvxDateType::Var;
196
197 for( i = 3; i < nCount; i++ )
198 {
199 if (m_xPopup->get_active(OUString::number(i)))
200 break;
201 }
202 eFormat = static_cast<SvxDateFormat>( i - 1 );
203
204 if( pDateField->GetFormat() != eFormat ||
205 pDateField->GetType() != eType )
206 {
207 pNewField = new SvxDateField( *pDateField );
208 static_cast<SvxDateField*>( pNewField )->SetType( eType );
209 static_cast<SvxDateField*>( pNewField )->SetFormat( eFormat );
210
211 if( (pDateField->GetType() == SvxDateType::Var) && (eType == SvxDateType::Fix) )
212 {
213 Date aDate( Date::SYSTEM );
214 static_cast<SvxDateField*>( pNewField )->SetFixDate( aDate );
215 }
216 }
217 }
218 else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
219 {
221 SvxTimeFormat eFormat;
222 sal_uInt16 i;
223
224 if (m_xPopup->get_active("1"))
225 eType = SvxTimeType::Fix;
226 else
227 eType = SvxTimeType::Var;
228
229 for( i = 3; i < nCount; i++ )
230 {
231 if (m_xPopup->get_active(OUString::number(i)))
232 break;
233 }
234 eFormat = static_cast<SvxTimeFormat>( i - 1 );
235
236 if( pTimeField->GetFormat() != eFormat ||
237 pTimeField->GetType() != eType )
238 {
239 pNewField = new SvxExtTimeField( *pTimeField );
240 static_cast<SvxExtTimeField*>( pNewField )->SetType( eType );
241 static_cast<SvxExtTimeField*>( pNewField )->SetFormat( eFormat );
242
243 if( (pTimeField->GetType() == SvxTimeType::Var) && (eType == SvxTimeType::Fix) )
244 {
246 static_cast<SvxExtTimeField*>( pNewField )->SetFixTime( aTime );
247 }
248
249 }
250 }
251 else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( m_pField ) )
252 {
254 SvxFileFormat eFormat;
255 sal_uInt16 i;
256
257 if (m_xPopup->get_active("1"))
258 eType = SvxFileType::Fix;
259 else
260 eType = SvxFileType::Var;
261
262 for( i = 3; i < nCount; i++ )
263 {
264 if (m_xPopup->get_active(OUString::number(i)))
265 break;
266 }
267 eFormat = static_cast<SvxFileFormat>( i - 3 );
268
269 if( pFileField->GetFormat() != eFormat ||
270 pFileField->GetType() != eType )
271 {
272 ::sd::DrawDocShell* pDocSh = dynamic_cast<::sd::DrawDocShell* >( SfxObjectShell::Current() );
273
274 if( pDocSh )
275 {
276 OUString aName;
277 if( pDocSh->HasName() )
278 aName = pDocSh->GetMedium()->GetName();
279
280 // Get current filename, not the one stored in the old field
281 pNewField = new SvxExtFileField( aName );
282 static_cast<SvxExtFileField*>( pNewField )->SetType( eType );
283 static_cast<SvxExtFileField*>( pNewField )->SetFormat( eFormat );
284 }
285 }
286 }
287 else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( m_pField ) )
288 {
290 SvxAuthorFormat eFormat;
291 sal_uInt16 i;
292
293 if (m_xPopup->get_active("1"))
294 eType = SvxAuthorType::Fix;
295 else
296 eType = SvxAuthorType::Var;
297
298 for( i = 3; i < nCount; i++ )
299 {
300 if (m_xPopup->get_active(OUString::number(i)))
301 break;
302 }
303 eFormat = static_cast<SvxAuthorFormat>( i - 3 );
304
305 if( pAuthorField->GetFormat() != eFormat ||
306 pAuthorField->GetType() != eType )
307 {
308 // Get current state of address, not the old one
309 SvtUserOptions aUserOptions;
310 pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
311 static_cast<SvxAuthorField*>( pNewField )->SetType( eType );
312 static_cast<SvxAuthorField*>( pNewField )->SetFormat( eFormat );
313 }
314 }
315 return pNewField;
316}
317
318/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Execute(weld::Window *pParent, const tools::Rectangle &rRect)
Definition: sdpopup.cxx:156
SvxFieldData * GetField()
Returns a new field, owned by caller.
Definition: sdpopup.cxx:180
const SvxFieldData * m_pField
Definition: sdpopup.hxx:35
void Fill(LanguageType eLanguage)
Definition: sdpopup.cxx:51
std::unique_ptr< weld::Menu > m_xPopup
Definition: sdpopup.hxx:34
SdFieldPopup(const SvxFieldData *pInField, LanguageType eLanguage)
Definition: sdpopup.cxx:39
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
int nCount
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)