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>
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"
33 #include "drawdoc.hxx"
34 #include "DrawDocShell.hxx"
37 * Popup menu for editing of field command
39 SdFieldPopup::SdFieldPopup( const SvxFieldData
* pInField
, LanguageType eLanguage
) :
46 SdFieldPopup::~SdFieldPopup()
50 void SdFieldPopup::Fill( LanguageType eLanguage
)
53 MenuItemBits nStyle
= MenuItemBits::RADIOCHECK
| MenuItemBits::AUTOCHECK
;
54 InsertItem( nID
++, SD_RESSTR( STR_FIX
), nStyle
);
55 InsertItem( nID
++, SD_RESSTR( STR_VAR
), nStyle
);
58 if( pField
->ISA( SvxDateField
) )
60 const SvxDateField
* pDateField
= static_cast<const SvxDateField
*>( pField
);
61 SvxDateField
aDateField( *pDateField
);
63 if( pDateField
->GetType() == SVXDATETYPE_FIX
)
68 //SVXDATEFORMAT_APPDEFAULT, // is not used
69 //SVXDATEFORMAT_SYSTEM, // is not used
70 InsertItem( nID
++, SD_RESSTR( STR_STANDARD_SMALL
), nStyle
);
71 InsertItem( nID
++, SD_RESSTR( 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( (sal_uInt16
) ( pDateField
->GetFormat() ) + 1 ); // - 2 + 3 !
90 else if( pField
->ISA( SvxExtTimeField
) )
92 const SvxExtTimeField
* pTimeField
= static_cast<const SvxExtTimeField
*>( pField
);
93 SvxExtTimeField
aTimeField( *pTimeField
);
95 if( pTimeField
->GetType() == SVXTIMETYPE_FIX
)
100 //SVXTIMEFORMAT_APPDEFAULT, // is not used
101 //SVXTIMEFORMAT_SYSTEM, // is not used
102 InsertItem( nID
++, SD_RESSTR( STR_STANDARD_NORMAL
), nStyle
);
104 SvNumberFormatter
* pNumberFormatter
= SD_MOD()->GetNumberFormatter();
105 aTimeField
.SetFormat( SVXTIMEFORMAT_24_HM
); // 13:49
106 InsertItem( nID
++, aTimeField
.GetFormatted( *pNumberFormatter
, eLanguage
), nStyle
);
107 aTimeField
.SetFormat( SVXTIMEFORMAT_24_HMS
); // 13:49:38
108 InsertItem( nID
++, aTimeField
.GetFormatted( *pNumberFormatter
, eLanguage
), nStyle
);
109 aTimeField
.SetFormat( SVXTIMEFORMAT_24_HMSH
); // 13:49:38.78
110 InsertItem( nID
++, aTimeField
.GetFormatted( *pNumberFormatter
, eLanguage
), nStyle
);
112 aTimeField
.SetFormat( SVXTIMEFORMAT_12_HM
); // 01:49
113 InsertItem( nID
++, aTimeField
.GetFormatted( *pNumberFormatter
, eLanguage
), nStyle
);
114 aTimeField
.SetFormat( SVXTIMEFORMAT_12_HMS
); // 01:49:38
115 InsertItem( nID
++, aTimeField
.GetFormatted( *pNumberFormatter
, eLanguage
), nStyle
);
116 aTimeField
.SetFormat( SVXTIMEFORMAT_12_HMSH
); // 01:49:38.78
117 InsertItem( nID
++, aTimeField
.GetFormatted( *pNumberFormatter
, eLanguage
), nStyle
);
118 //SVXTIMEFORMAT_AM_HM, // 01:49 PM
119 //SVXTIMEFORMAT_AM_HMS, // 01:49:38 PM
120 //SVXTIMEFORMAT_AM_HMSH // 01:49:38.78 PM
122 CheckItem( (sal_uInt16
) ( pTimeField
->GetFormat() ) + 1 ); // - 2 + 3 !
124 else if( pField
->ISA( SvxExtFileField
) )
126 const SvxExtFileField
* pFileField
= static_cast<const SvxExtFileField
*>(pField
);
127 //SvxExtFileField aFileField( *pFileField );
129 if( pFileField
->GetType() == SVXFILETYPE_FIX
)
134 InsertItem( nID
++, SD_RESSTR( STR_FILEFORMAT_NAME_EXT
), nStyle
);
135 InsertItem( nID
++, SD_RESSTR( STR_FILEFORMAT_FULLPATH
), nStyle
);
136 InsertItem( nID
++, SD_RESSTR( STR_FILEFORMAT_PATH
), nStyle
);
137 InsertItem( nID
++, SD_RESSTR( STR_FILEFORMAT_NAME
), nStyle
);
139 CheckItem( (sal_uInt16
) ( pFileField
->GetFormat() ) + 3 );
141 else if( pField
->ISA( SvxAuthorField
) )
143 const SvxAuthorField
* pAuthorField
= static_cast<const SvxAuthorField
*>(pField
);
144 SvxAuthorField
aAuthorField( *pAuthorField
);
146 if( pAuthorField
->GetType() == SVXAUTHORTYPE_FIX
)
151 for( sal_uInt16 i
= 0; i
< 4; i
++ )
153 aAuthorField
.SetFormat( (SvxAuthorFormat
) i
);
154 InsertItem( nID
++, aAuthorField
.GetFormatted(), nStyle
);
156 CheckItem( (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
= NULL
;
167 sal_uInt16 nCount
= GetItemCount();
169 if( pField
->ISA( SvxDateField
) )
171 const SvxDateField
* pDateField
= static_cast<const SvxDateField
*>(pField
);
173 SvxDateFormat eFormat
;
176 if( IsItemChecked( 1 ) )
177 eType
= SVXDATETYPE_FIX
;
179 eType
= SVXDATETYPE_VAR
;
181 for( i
= 3; i
<= nCount
; i
++ )
183 if( IsItemChecked( i
) )
186 eFormat
= (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( pField
->ISA( SvxExtTimeField
) )
204 const SvxExtTimeField
* pTimeField
= static_cast<const SvxExtTimeField
*>(pField
);
206 SvxTimeFormat eFormat
;
209 if( IsItemChecked( 1 ) )
210 eType
= SVXTIMETYPE_FIX
;
212 eType
= SVXTIMETYPE_VAR
;
214 for( i
= 3; i
<= nCount
; i
++ )
216 if( IsItemChecked( i
) )
219 eFormat
= (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( pField
->ISA( SvxExtFileField
) )
238 const SvxExtFileField
* pFileField
= static_cast<const SvxExtFileField
*>(pField
);
240 SvxFileFormat eFormat
;
243 if( IsItemChecked( 1 ) )
244 eType
= SVXFILETYPE_FIX
;
246 eType
= SVXFILETYPE_VAR
;
248 for( i
= 3; i
<= nCount
; i
++ )
250 if( IsItemChecked( i
) )
253 eFormat
= (SvxFileFormat
) ( i
- 3 );
255 if( pFileField
->GetFormat() != eFormat
||
256 pFileField
->GetType() != eType
)
258 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
,
259 SfxObjectShell::Current() );
263 SvxExtFileField
aFileField( *pFileField
);
266 if( pDocSh
->HasName() )
267 aName
= pDocSh
->GetMedium()->GetName();
269 // Get current filename, not the one stored in the old field
270 pNewField
= new SvxExtFileField( aName
);
271 static_cast<SvxExtFileField
*>( pNewField
)->SetType( eType
);
272 static_cast<SvxExtFileField
*>( pNewField
)->SetFormat( eFormat
);
276 else if( pField
->ISA( SvxAuthorField
) )
278 const SvxAuthorField
* pAuthorField
= static_cast<const SvxAuthorField
*>(pField
);
280 SvxAuthorFormat eFormat
;
283 if( IsItemChecked( 1 ) )
284 eType
= SVXAUTHORTYPE_FIX
;
286 eType
= SVXAUTHORTYPE_VAR
;
288 for( i
= 3; i
<= nCount
; i
++ )
290 if( IsItemChecked( i
) )
293 eFormat
= (SvxAuthorFormat
) ( i
- 3 );
295 if( pAuthorField
->GetFormat() != eFormat
||
296 pAuthorField
->GetType() != eType
)
298 // Get current state of address, not the old one
299 SvtUserOptions aUserOptions
;
300 pNewField
= new SvxAuthorField( aUserOptions
.GetFirstName(), aUserOptions
.GetLastName(), aUserOptions
.GetID() );
301 static_cast<SvxAuthorField
*>( pNewField
)->SetType( eType
);
302 static_cast<SvxAuthorField
*>( pNewField
)->SetFormat( eFormat
);
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */