Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / app / sdpopup.cxx
blob08a1c06db958fdfc3a0768bb8fd7b0f6524533e9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <editeng/editeng.hxx>
23 #include <editeng/flditem.hxx>
24 #include <svl/zforlist.hxx>
25 #include <sfx2/objsh.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <unotools/useroptions.hxx>
29 #include <strings.hrc>
30 #include <sdpopup.hxx>
31 #include <sdresid.hxx>
32 #include <sdmod.hxx>
33 #include <drawdoc.hxx>
34 #include <DrawDocShell.hxx>
37 * Popup menu for editing of field command
39 SdFieldPopup::SdFieldPopup( const SvxFieldData* pInField, LanguageType eLanguage ) :
40 PopupMenu (),
41 pField ( pInField )
43 Fill( eLanguage );
46 SdFieldPopup::~SdFieldPopup()
50 void SdFieldPopup::Fill( LanguageType eLanguage )
52 sal_uInt16 nID = 1;
53 MenuItemBits nStyle = MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK;
54 InsertItem( nID++, SdResId( STR_FIX ), nStyle );
55 InsertItem( nID++, SdResId( STR_VAR ), nStyle );
56 InsertSeparator();
58 if( dynamic_cast< const SvxDateField *>( pField ) != nullptr )
60 const SvxDateField* pDateField = static_cast<const SvxDateField*>( pField );
61 SvxDateField aDateField( *pDateField );
63 if( pDateField->GetType() == SvxDateType::Fix )
64 CheckItem( 1 );
65 else
66 CheckItem( 2 );
68 //SvxDateFormat::AppDefault, // is not used
69 //SvxDateFormat::System, // is not used
70 InsertItem( nID++, SdResId( STR_STANDARD_SMALL ), nStyle );
71 InsertItem( nID++, SdResId( STR_STANDARD_BIG ), nStyle );
73 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
74 aDateField.SetFormat( SvxDateFormat::A ); // 13.02.96
75 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
76 aDateField.SetFormat( SvxDateFormat::B ); // 13.02.1996
77 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
78 aDateField.SetFormat( SvxDateFormat::C ); // 13.Feb 1996
79 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
81 aDateField.SetFormat( SvxDateFormat::D ); // 13.Februar 1996
82 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
83 aDateField.SetFormat( SvxDateFormat::E ); // Die, 13.Februar 1996
84 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
85 aDateField.SetFormat( SvxDateFormat::F ); // Dienstag, 13.Februar 1996
86 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
88 CheckItem( static_cast<sal_uInt16>( pDateField->GetFormat() ) + 1 ); // - 2 + 3 !
90 else if( dynamic_cast< const SvxExtTimeField *>( pField ) != nullptr )
92 const SvxExtTimeField* pTimeField = static_cast<const SvxExtTimeField*>( pField );
93 SvxExtTimeField aTimeField( *pTimeField );
95 if( pTimeField->GetType() == SvxTimeType::Fix )
96 CheckItem( 1 );
97 else
98 CheckItem( 2 );
100 //SvxTimeFormat::AppDefault, // is not used
101 //SvxTimeFormat::System, // is not used
102 InsertItem( nID++, SdResId( STR_STANDARD_NORMAL ), nStyle );
104 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
105 aTimeField.SetFormat( SvxTimeFormat::HH24_MM ); // 13:49
106 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
107 aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS ); // 13:49:38
108 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
109 aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS_00 ); // 13:49:38.78
110 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
112 aTimeField.SetFormat( SvxTimeFormat::HH12_MM ); // 01:49
113 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
114 aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS ); // 01:49:38
115 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
116 aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS_00 ); // 01:49:38.78
117 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
118 //SvxTimeFormat::HH12_MM_AMPM, // 01:49 PM
119 //SvxTimeFormat::HH12_MM_SS_AMPM, // 01:49:38 PM
120 //SvxTimeFormat::HH12_MM_SS_00_AMPM // 01:49:38.78 PM
122 CheckItem( static_cast<sal_uInt16>( pTimeField->GetFormat() ) + 1 ); // - 2 + 3 !
124 else if( dynamic_cast< const SvxExtFileField *>( pField ) != nullptr )
126 const SvxExtFileField* pFileField = static_cast<const SvxExtFileField*>(pField);
127 //SvxExtFileField aFileField( *pFileField );
129 if( pFileField->GetType() == SvxFileType::Fix )
130 CheckItem( 1 );
131 else
132 CheckItem( 2 );
134 InsertItem( nID++, SdResId( STR_FILEFORMAT_NAME_EXT ), nStyle );
135 InsertItem( nID++, SdResId( STR_FILEFORMAT_FULLPATH ), nStyle );
136 InsertItem( nID++, SdResId( STR_FILEFORMAT_PATH ), nStyle );
137 InsertItem( nID++, SdResId( STR_FILEFORMAT_NAME ), nStyle );
139 CheckItem( static_cast<sal_uInt16>( pFileField->GetFormat() ) + 3 );
141 else if( dynamic_cast< const SvxAuthorField *>( pField ) != nullptr )
143 const SvxAuthorField* pAuthorField = static_cast<const SvxAuthorField*>(pField);
144 SvxAuthorField aAuthorField( *pAuthorField );
146 if( pAuthorField->GetType() == SvxAuthorType::Fix )
147 CheckItem( 1 );
148 else
149 CheckItem( 2 );
151 for( sal_uInt16 i = 0; i < 4; i++ )
153 aAuthorField.SetFormat( static_cast<SvxAuthorFormat>(i) );
154 InsertItem( nID++, aAuthorField.GetFormatted(), nStyle );
156 CheckItem( static_cast<sal_uInt16>( pAuthorField->GetFormat() ) + 3 );
161 * Returns a new field, owned by caller.
162 * Returns NULL if nothing changed.
164 SvxFieldData* SdFieldPopup::GetField()
166 SvxFieldData* pNewField = nullptr;
167 sal_uInt16 nCount = GetItemCount();
169 if( dynamic_cast< const SvxDateField *>( pField ) != nullptr )
171 const SvxDateField* pDateField = static_cast<const SvxDateField*>(pField);
172 SvxDateType eType;
173 SvxDateFormat eFormat;
174 sal_uInt16 i;
176 if( IsItemChecked( 1 ) )
177 eType = SvxDateType::Fix;
178 else
179 eType = SvxDateType::Var;
181 for( i = 3; i <= nCount; i++ )
183 if( IsItemChecked( i ) )
184 break;
186 eFormat = static_cast<SvxDateFormat>( i - 1 );
188 if( pDateField->GetFormat() != eFormat ||
189 pDateField->GetType() != eType )
191 pNewField = new SvxDateField( *pDateField );
192 static_cast<SvxDateField*>( pNewField )->SetType( eType );
193 static_cast<SvxDateField*>( pNewField )->SetFormat( eFormat );
195 if( (pDateField->GetType() == SvxDateType::Var) && (eType == SvxDateType::Fix) )
197 Date aDate( Date::SYSTEM );
198 static_cast<SvxDateField*>( pNewField )->SetFixDate( aDate );
202 else if( dynamic_cast< const SvxExtTimeField *>( pField ) != nullptr )
204 const SvxExtTimeField* pTimeField = static_cast<const SvxExtTimeField*>(pField);
205 SvxTimeType eType;
206 SvxTimeFormat eFormat;
207 sal_uInt16 i;
209 if( IsItemChecked( 1 ) )
210 eType = SvxTimeType::Fix;
211 else
212 eType = SvxTimeType::Var;
214 for( i = 3; i <= nCount; i++ )
216 if( IsItemChecked( i ) )
217 break;
219 eFormat = static_cast<SvxTimeFormat>( i - 1 );
221 if( pTimeField->GetFormat() != eFormat ||
222 pTimeField->GetType() != eType )
224 pNewField = new SvxExtTimeField( *pTimeField );
225 static_cast<SvxExtTimeField*>( pNewField )->SetType( eType );
226 static_cast<SvxExtTimeField*>( pNewField )->SetFormat( eFormat );
228 if( (pTimeField->GetType() == SvxTimeType::Var) && (eType == SvxTimeType::Fix) )
230 tools::Time aTime( tools::Time::SYSTEM );
231 static_cast<SvxExtTimeField*>( pNewField )->SetFixTime( aTime );
236 else if( dynamic_cast< const SvxExtFileField *>( pField ) != nullptr )
238 const SvxExtFileField* pFileField = static_cast<const SvxExtFileField*>(pField);
239 SvxFileType eType;
240 SvxFileFormat eFormat;
241 sal_uInt16 i;
243 if( IsItemChecked( 1 ) )
244 eType = SvxFileType::Fix;
245 else
246 eType = SvxFileType::Var;
248 for( i = 3; i <= nCount; i++ )
250 if( IsItemChecked( i ) )
251 break;
253 eFormat = static_cast<SvxFileFormat>( i - 3 );
255 if( pFileField->GetFormat() != eFormat ||
256 pFileField->GetType() != eType )
258 ::sd::DrawDocShell* pDocSh = dynamic_cast<::sd::DrawDocShell* >( SfxObjectShell::Current() );
260 if( pDocSh )
262 SvxExtFileField aFileField( *pFileField );
264 OUString aName;
265 if( pDocSh->HasName() )
266 aName = pDocSh->GetMedium()->GetName();
268 // Get current filename, not the one stored in the old field
269 pNewField = new SvxExtFileField( aName );
270 static_cast<SvxExtFileField*>( pNewField )->SetType( eType );
271 static_cast<SvxExtFileField*>( pNewField )->SetFormat( eFormat );
275 else if( dynamic_cast< const SvxAuthorField *>( pField ) != nullptr )
277 const SvxAuthorField* pAuthorField = static_cast<const SvxAuthorField*>(pField);
278 SvxAuthorType eType;
279 SvxAuthorFormat eFormat;
280 sal_uInt16 i;
282 if( IsItemChecked( 1 ) )
283 eType = SvxAuthorType::Fix;
284 else
285 eType = SvxAuthorType::Var;
287 for( i = 3; i <= nCount; i++ )
289 if( IsItemChecked( i ) )
290 break;
292 eFormat = static_cast<SvxAuthorFormat>( i - 3 );
294 if( pAuthorField->GetFormat() != eFormat ||
295 pAuthorField->GetType() != eType )
297 // Get current state of address, not the old one
298 SvtUserOptions aUserOptions;
299 pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
300 static_cast<SvxAuthorField*>( pNewField )->SetType( eType );
301 static_cast<SvxAuthorField*>( pNewField )->SetFormat( eFormat );
304 return pNewField;
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */