merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / app / sdpopup.cxx
blobbe9fbb0e73fbcb2da3e1b9c2642bbd10bbd2577f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdpopup.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
35 #include <svx/eeitem.hxx>
37 #include <svx/editeng.hxx>
38 #include <svx/flditem.hxx>
39 #include <svtools/zforlist.hxx>
40 #include <sfx2/objsh.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <svtools/useroptions.hxx>
44 #include "strings.hrc"
45 #include "sdpopup.hxx"
46 #include "sdresid.hxx"
47 #include "sdmod.hxx"
48 #include "drawdoc.hxx"
49 #include "DrawDocShell.hxx"
51 /*************************************************************************
53 |* PopupMenu zum Bearbeiten von Feldbefehlen
55 \************************************************************************/
57 SdFieldPopup::SdFieldPopup( const SvxFieldData* pInField, LanguageType eLanguage ) :
58 PopupMenu (),
59 pField ( pInField )
61 Fill( eLanguage );
64 /*************************************************************************
66 |* Dtor
68 \************************************************************************/
70 SdFieldPopup::~SdFieldPopup()
74 /*************************************************************************
76 |* Fill
78 \************************************************************************/
80 void SdFieldPopup::Fill( LanguageType eLanguage )
82 USHORT nID = 1;
83 USHORT nStyle = MIB_RADIOCHECK | MIB_AUTOCHECK;
84 InsertItem( nID++, String( SdResId( STR_FIX ) ), nStyle );
85 InsertItem( nID++, String( SdResId( STR_VAR ) ), nStyle );
86 InsertSeparator();
88 if( pField->ISA( SvxDateField ) )
90 const SvxDateField* pDateField = (const SvxDateField*) pField;
91 SvxDateField aDateField( *pDateField );
93 if( pDateField->GetType() == SVXDATETYPE_FIX )
94 CheckItem( 1 );
95 else
96 CheckItem( 2 );
98 //SVXDATEFORMAT_APPDEFAULT, // Wird nicht benutzt
99 //SVXDATEFORMAT_SYSTEM, // Wird nicht benutzt
100 InsertItem( nID++, String( SdResId( STR_STANDARD_SMALL ) ), nStyle );
101 InsertItem( nID++, String( SdResId( STR_STANDARD_BIG ) ), nStyle );
103 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
104 aDateField.SetFormat( SVXDATEFORMAT_A ); // 13.02.96
105 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
106 aDateField.SetFormat( SVXDATEFORMAT_B ); // 13.02.1996
107 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
108 aDateField.SetFormat( SVXDATEFORMAT_C ); // 13.Feb 1996
109 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
111 aDateField.SetFormat( SVXDATEFORMAT_D ); // 13.Februar 1996
112 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
113 aDateField.SetFormat( SVXDATEFORMAT_E ); // Die, 13.Februar 1996
114 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
115 aDateField.SetFormat( SVXDATEFORMAT_F ); // Dienstag, 13.Februar 1996
116 InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
118 CheckItem( (USHORT) ( pDateField->GetFormat() ) + 1 ); // - 2 + 3 !
120 else if( pField->ISA( SvxExtTimeField ) )
122 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
123 SvxExtTimeField aTimeField( *pTimeField );
125 if( pTimeField->GetType() == SVXTIMETYPE_FIX )
126 CheckItem( 1 );
127 else
128 CheckItem( 2 );
130 //SVXTIMEFORMAT_APPDEFAULT, // Wird nicht benutzt
131 //SVXTIMEFORMAT_SYSTEM, // Wird nicht benutzt
132 InsertItem( nID++, String( SdResId( STR_STANDARD_NORMAL ) ), nStyle );
134 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
135 aTimeField.SetFormat( SVXTIMEFORMAT_24_HM ); // 13:49
136 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
137 aTimeField.SetFormat( SVXTIMEFORMAT_24_HMS ); // 13:49:38
138 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
139 aTimeField.SetFormat( SVXTIMEFORMAT_24_HMSH ); // 13:49:38.78
140 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
142 aTimeField.SetFormat( SVXTIMEFORMAT_12_HM ); // 01:49
143 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
144 aTimeField.SetFormat( SVXTIMEFORMAT_12_HMS ); // 01:49:38
145 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
146 aTimeField.SetFormat( SVXTIMEFORMAT_12_HMSH ); // 01:49:38.78
147 InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
148 //SVXTIMEFORMAT_AM_HM, // 01:49 PM
149 //SVXTIMEFORMAT_AM_HMS, // 01:49:38 PM
150 //SVXTIMEFORMAT_AM_HMSH // 01:49:38.78 PM
152 CheckItem( (USHORT) ( pTimeField->GetFormat() ) + 1 ); // - 2 + 3 !
154 else if( pField->ISA( SvxExtFileField ) )
156 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
157 //SvxExtFileField aFileField( *pFileField );
159 if( pFileField->GetType() == SVXFILETYPE_FIX )
160 CheckItem( 1 );
161 else
162 CheckItem( 2 );
164 InsertItem( nID++, String( SdResId( STR_FILEFORMAT_NAME_EXT ) ), nStyle );
165 InsertItem( nID++, String( SdResId( STR_FILEFORMAT_FULLPATH ) ), nStyle );
166 InsertItem( nID++, String( SdResId( STR_FILEFORMAT_PATH ) ), nStyle );
167 InsertItem( nID++, String( SdResId( STR_FILEFORMAT_NAME ) ), nStyle );
169 CheckItem( (USHORT) ( pFileField->GetFormat() ) + 3 );
171 else if( pField->ISA( SvxAuthorField ) )
173 const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
174 SvxAuthorField aAuthorField( *pAuthorField );
176 if( pAuthorField->GetType() == SVXAUTHORTYPE_FIX )
177 CheckItem( 1 );
178 else
179 CheckItem( 2 );
181 for( USHORT i = 0; i < 4; i++ )
183 aAuthorField.SetFormat( (SvxAuthorFormat) i );
184 InsertItem( nID++, aAuthorField.GetFormatted(), nStyle );
186 CheckItem( (USHORT) ( pAuthorField->GetFormat() ) + 3 );
190 /*************************************************************************
192 |* Gibt das neue Feld zurueck, gehoert dem Caller.
193 |* Liefert NULL, wenn sich nichts geaendert hat.
195 \************************************************************************/
197 SvxFieldData* SdFieldPopup::GetField()
199 SvxFieldData* pNewField = NULL;
200 USHORT nCount = GetItemCount();
202 if( pField->ISA( SvxDateField ) )
204 const SvxDateField* pDateField = (const SvxDateField*) pField;
205 SvxDateType eType;
206 SvxDateFormat eFormat;
207 USHORT i;
209 if( IsItemChecked( 1 ) )
210 eType = SVXDATETYPE_FIX;
211 else
212 eType = SVXDATETYPE_VAR;
214 for( i = 3; i <= nCount; i++ )
216 if( IsItemChecked( i ) )
217 break;
219 eFormat = (SvxDateFormat) ( i - 1 );
221 if( pDateField->GetFormat() != eFormat ||
222 pDateField->GetType() != eType )
224 pNewField = new SvxDateField( *pDateField );
225 ( (SvxDateField*) pNewField )->SetType( eType );
226 ( (SvxDateField*) pNewField )->SetFormat( eFormat );
228 if( (pDateField->GetType() == SVXDATETYPE_VAR) && (eType == SVXDATETYPE_FIX) )
230 Date aDate;
231 ( (SvxDateField*) pNewField )->SetFixDate( aDate );
235 else if( pField->ISA( SvxExtTimeField ) )
237 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
238 SvxTimeType eType;
239 SvxTimeFormat eFormat;
240 USHORT i;
242 if( IsItemChecked( 1 ) )
243 eType = SVXTIMETYPE_FIX;
244 else
245 eType = SVXTIMETYPE_VAR;
247 for( i = 3; i <= nCount; i++ )
249 if( IsItemChecked( i ) )
250 break;
252 eFormat = (SvxTimeFormat) ( i - 1 );
254 if( pTimeField->GetFormat() != eFormat ||
255 pTimeField->GetType() != eType )
257 pNewField = new SvxExtTimeField( *pTimeField );
258 ( (SvxExtTimeField*) pNewField )->SetType( eType );
259 ( (SvxExtTimeField*) pNewField )->SetFormat( eFormat );
261 if( (pTimeField->GetType() == SVXTIMETYPE_VAR) && (eType == SVXTIMETYPE_FIX) )
263 Time aTime;
264 ( (SvxExtTimeField*) pNewField )->SetFixTime( aTime );
269 else if( pField->ISA( SvxExtFileField ) )
271 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
272 SvxFileType eType;
273 SvxFileFormat eFormat;
274 USHORT i;
276 if( IsItemChecked( 1 ) )
277 eType = SVXFILETYPE_FIX;
278 else
279 eType = SVXFILETYPE_VAR;
281 for( i = 3; i <= nCount; i++ )
283 if( IsItemChecked( i ) )
284 break;
286 eFormat = (SvxFileFormat) ( i - 3 );
288 if( pFileField->GetFormat() != eFormat ||
289 pFileField->GetType() != eType )
291 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell,
292 SfxObjectShell::Current() );
294 if( pDocSh )
296 SvxExtFileField aFileField( *pFileField );
298 String aName;
299 if( pDocSh->HasName() )
300 aName = pDocSh->GetMedium()->GetName();
302 // #91225# Get current filename, not the one stored in the old field
303 pNewField = new SvxExtFileField( aName );
304 ( (SvxExtFileField*) pNewField )->SetType( eType );
305 ( (SvxExtFileField*) pNewField )->SetFormat( eFormat );
309 else if( pField->ISA( SvxAuthorField ) )
311 const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
312 SvxAuthorType eType;
313 SvxAuthorFormat eFormat;
314 USHORT i;
316 if( IsItemChecked( 1 ) )
317 eType = SVXAUTHORTYPE_FIX;
318 else
319 eType = SVXAUTHORTYPE_VAR;
321 for( i = 3; i <= nCount; i++ )
323 if( IsItemChecked( i ) )
324 break;
326 eFormat = (SvxAuthorFormat) ( i - 3 );
328 if( pAuthorField->GetFormat() != eFormat ||
329 pAuthorField->GetType() != eType )
331 // #91225# Get current state of address, not the old one
332 SvtUserOptions aUserOptions;
333 pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
334 ( (SvxAuthorField*) pNewField )->SetType( eType );
335 ( (SvxAuthorField*) pNewField )->SetFormat( eFormat );
338 return( pNewField );