merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / dlg / dlgfield.cxx
blobc9cd19ed2d49fd5567b066f3ed4b53e9b717cc1f
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: dlgfield.cxx,v $
10 * $Revision: 1.15 $
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"
34 #ifdef SD_DLLIMPLEMENTATION
35 #undef SD_DLLIMPLEMENTATION
36 #endif
40 #include <svx/editeng.hxx>
41 #include <svx/eeitem.hxx>
42 #include <svx/flditem.hxx>
43 #include <svtools/zforlist.hxx>
44 #include <sfx2/objsh.hxx>
45 #include <sfx2/docfile.hxx>
46 #include <svtools/itemset.hxx>
47 #include <svx/langitem.hxx>
48 #include <svtools/useroptions.hxx>
50 #include "strings.hrc"
51 #include "dlgfield.hrc"
52 #include "sdattr.hxx"
53 #include "sdresid.hxx"
54 #include "sdmod.hxx"
55 #include "dlgfield.hxx"
56 #include "drawdoc.hxx"
57 #include "DrawDocShell.hxx"
59 /*************************************************************************
61 |* Dialog zum Bearbeiten von Feldbefehlen
63 \************************************************************************/
65 SdModifyFieldDlg::SdModifyFieldDlg( Window* pWindow, const SvxFieldData* pInField, const SfxItemSet& rSet ) :
66 ModalDialog ( pWindow, SdResId( DLG_FIELD_MODIFY ) ),
67 aRbtFix ( this, SdResId( RBT_FIX ) ),
68 aRbtVar ( this, SdResId( RBT_VAR ) ),
69 aGrpType ( this, SdResId( GRP_TYPE ) ),
70 maFtLanguage( this, SdResId( FT_LANGUAGE ) ),
71 maLbLanguage( this, SdResId( LB_LANGUAGE ) ),
72 aFtFormat ( this, SdResId( FT_FORMAT ) ),
73 aLbFormat ( this, SdResId( LB_FORMAT ) ),
74 aBtnOK ( this, SdResId( BTN_OK ) ),
75 aBtnCancel ( this, SdResId( BTN_CANCEL ) ),
76 aBtnHelp ( this, SdResId( BTN_HELP ) ),
77 maInputSet ( rSet ),
78 pField ( pInField )
80 FreeResource();
82 maLbLanguage.SetLanguageList( LANG_LIST_ALL|LANG_LIST_ONLY_KNOWN, false );
83 maLbLanguage.SetSelectHdl( LINK( this, SdModifyFieldDlg, LanguageChangeHdl ) );
84 FillControls();
87 /*************************************************************************
89 |* Gibt das neue Feld zurueck, gehoert dem Caller.
90 |* Liefert NULL, wenn sich nichts geaendert hat.
92 \************************************************************************/
94 SvxFieldData* SdModifyFieldDlg::GetField()
96 SvxFieldData* pNewField = NULL;
98 if( aRbtFix.IsChecked() != aRbtFix.GetSavedValue() ||
99 aRbtVar.IsChecked() != aRbtVar.GetSavedValue() ||
100 aLbFormat.GetSelectEntryPos() != aLbFormat.GetSavedValue() )
102 if( pField->ISA( SvxDateField ) )
104 const SvxDateField* pDateField = (const SvxDateField*) pField;
105 SvxDateType eType;
106 SvxDateFormat eFormat;
108 if( aRbtFix.IsChecked() )
109 eType = SVXDATETYPE_FIX;
110 else
111 eType = SVXDATETYPE_VAR;
113 eFormat = (SvxDateFormat) ( aLbFormat.GetSelectEntryPos() + 2 );
115 pNewField = new SvxDateField( *pDateField );
116 ( (SvxDateField*) pNewField )->SetType( eType );
117 ( (SvxDateField*) pNewField )->SetFormat( eFormat );
119 else if( pField->ISA( SvxExtTimeField ) )
121 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
122 SvxTimeType eType;
123 SvxTimeFormat eFormat;
125 if( aRbtFix.IsChecked() )
126 eType = SVXTIMETYPE_FIX;
127 else
128 eType = SVXTIMETYPE_VAR;
130 eFormat = (SvxTimeFormat) ( aLbFormat.GetSelectEntryPos() + 2 );
132 pNewField = new SvxExtTimeField( *pTimeField );
133 ( (SvxExtTimeField*) pNewField )->SetType( eType );
134 ( (SvxExtTimeField*) pNewField )->SetFormat( eFormat );
136 else if( pField->ISA( SvxExtFileField ) )
138 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
139 SvxFileType eType;
140 SvxFileFormat eFormat;
142 if( aRbtFix.IsChecked() )
143 eType = SVXFILETYPE_FIX;
144 else
145 eType = SVXFILETYPE_VAR;
147 eFormat = (SvxFileFormat) ( aLbFormat.GetSelectEntryPos() );
149 ::sd::DrawDocShell* pDocSh = PTR_CAST( ::sd::DrawDocShell,
150 SfxObjectShell::Current() );
152 if( pDocSh )
154 SvxExtFileField aFileField( *pFileField );
156 String aName;
157 if( pDocSh->HasName() )
158 aName = pDocSh->GetMedium()->GetName();
160 // #91225# Get current filename, not the one stored in the old field
161 pNewField = new SvxExtFileField( aName );
162 ( (SvxExtFileField*) pNewField )->SetType( eType );
163 ( (SvxExtFileField*) pNewField )->SetFormat( eFormat );
166 else if( pField->ISA( SvxAuthorField ) )
168 SvxAuthorType eType;
169 SvxAuthorFormat eFormat;
171 if( aRbtFix.IsChecked() )
172 eType = SVXAUTHORTYPE_FIX;
173 else
174 eType = SVXAUTHORTYPE_VAR;
176 eFormat = (SvxAuthorFormat) ( aLbFormat.GetSelectEntryPos() );
178 // #91225# Get current state of address, not the old one
179 SvtUserOptions aUserOptions;
180 pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
181 ( (SvxAuthorField*) pNewField )->SetType( eType );
182 ( (SvxAuthorField*) pNewField )->SetFormat( eFormat );
186 return( pNewField );
189 /*************************************************************************
193 \************************************************************************/
195 void SdModifyFieldDlg::FillFormatList()
197 LanguageType eLangType = maLbLanguage.GetSelectLanguage();
199 aLbFormat.Clear();
201 if( pField->ISA( SvxDateField ) )
203 const SvxDateField* pDateField = (const SvxDateField*) pField;
204 SvxDateField aDateField( *pDateField );
206 //SVXDATEFORMAT_APPDEFAULT, // Wird nicht benutzt
207 //SVXDATEFORMAT_SYSTEM, // Wird nicht benutzt
208 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_SMALL ) ) );
209 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_BIG ) ) );
211 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
212 aDateField.SetFormat( SVXDATEFORMAT_A ); // 13.02.96
213 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
214 aDateField.SetFormat( SVXDATEFORMAT_B ); // 13.02.1996
215 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
216 aDateField.SetFormat( SVXDATEFORMAT_C ); // 13.Feb 1996
217 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
218 aDateField.SetFormat( SVXDATEFORMAT_D ); // 13.Februar 1996
219 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
220 aDateField.SetFormat( SVXDATEFORMAT_E ); // Die, 13.Februar 1996
221 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
222 aDateField.SetFormat( SVXDATEFORMAT_F ); // Dienstag, 13.Februar 1996
223 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
225 aLbFormat.SelectEntryPos( (USHORT) ( pDateField->GetFormat() - 2 ) );
227 else if( pField->ISA( SvxExtTimeField ) )
229 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
230 SvxExtTimeField aTimeField( *pTimeField );
232 //SVXTIMEFORMAT_APPDEFAULT, // Wird nicht benutzt
233 //SVXTIMEFORMAT_SYSTEM, // Wird nicht benutzt
234 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_NORMAL ) ) );
236 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
237 aTimeField.SetFormat( SVXTIMEFORMAT_24_HM ); // 13:49
238 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
239 aTimeField.SetFormat( SVXTIMEFORMAT_24_HMS ); // 13:49:38
240 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
241 aTimeField.SetFormat( SVXTIMEFORMAT_24_HMSH ); // 13:49:38.78
242 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
243 aTimeField.SetFormat( SVXTIMEFORMAT_12_HM ); // 01:49
244 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
245 aTimeField.SetFormat( SVXTIMEFORMAT_12_HMS ); // 01:49:38
246 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
247 aTimeField.SetFormat( SVXTIMEFORMAT_12_HMSH ); // 01:49:38.78
248 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
249 //SVXTIMEFORMAT_AM_HM, // 01:49 PM
250 //SVXTIMEFORMAT_AM_HMS, // 01:49:38 PM
251 //SVXTIMEFORMAT_AM_HMSH // 01:49:38.78 PM
253 aLbFormat.SelectEntryPos( (USHORT) ( pTimeField->GetFormat() - 2 ) );
255 else if( pField->ISA( SvxExtFileField ) )
257 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
258 SvxExtFileField aFileField( *pFileField );
260 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_NAME_EXT ) ) );
261 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_FULLPATH ) ) );
262 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_PATH ) ) );
263 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_NAME ) ) );
265 aLbFormat.SelectEntryPos( (USHORT) ( pFileField->GetFormat() ) );
267 else if( pField->ISA( SvxAuthorField ) )
269 const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
270 SvxAuthorField aAuthorField( *pAuthorField );
272 for( USHORT i = 0; i < 4; i++ )
274 aAuthorField.SetFormat( (SvxAuthorFormat) i );
275 aLbFormat.InsertEntry( aAuthorField.GetFormatted() );
278 aLbFormat.SelectEntryPos( (USHORT) ( pAuthorField->GetFormat() ) );
285 void SdModifyFieldDlg::FillControls()
287 aLbFormat.Clear();
289 if( pField->ISA( SvxDateField ) )
291 const SvxDateField* pDateField = (const SvxDateField*) pField;
292 SvxDateField aDateField( *pDateField );
294 if( pDateField->GetType() == SVXDATETYPE_FIX )
295 aRbtFix.Check();
296 else
297 aRbtVar.Check();
299 else if( pField->ISA( SvxExtTimeField ) )
301 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
302 SvxExtTimeField aTimeField( *pTimeField );
304 if( pTimeField->GetType() == SVXTIMETYPE_FIX )
305 aRbtFix.Check();
306 else
307 aRbtVar.Check();
309 else if( pField->ISA( SvxExtFileField ) )
311 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
312 SvxExtFileField aFileField( *pFileField );
314 if( pFileField->GetType() == SVXFILETYPE_FIX )
315 aRbtFix.Check();
316 else
317 aRbtVar.Check();
319 else if( pField->ISA( SvxAuthorField ) )
321 const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
322 SvxAuthorField aAuthorField( *pAuthorField );
324 if( pAuthorField->GetType() == SVXAUTHORTYPE_FIX )
325 aRbtFix.Check();
326 else
327 aRbtVar.Check();
329 aRbtFix.SaveValue();
330 aRbtVar.SaveValue();
332 const SfxPoolItem* pItem;
333 if( SFX_ITEM_SET == maInputSet.GetItemState(EE_CHAR_LANGUAGE, TRUE, &pItem ) )
334 maLbLanguage.SelectLanguage( static_cast<const SvxLanguageItem*>(pItem)->GetLanguage() );
336 maLbLanguage.SaveValue();
338 FillFormatList();
339 aLbFormat.SaveValue();
343 IMPL_LINK( SdModifyFieldDlg, LanguageChangeHdl, void *, EMPTYARG )
345 FillFormatList();
347 return 0L;
350 SfxItemSet SdModifyFieldDlg::GetItemSet()
352 SfxItemSet aOutput( *maInputSet.GetPool(), EE_CHAR_LANGUAGE, EE_CHAR_LANGUAGE_CTL );
354 if( maLbLanguage.GetSelectEntryPos() != maLbLanguage.GetSavedValue() )
356 LanguageType eLangType = maLbLanguage.GetSelectLanguage();
357 SvxLanguageItem aItem( eLangType, EE_CHAR_LANGUAGE );
358 aOutput.Put( aItem );
360 SvxLanguageItem aItemCJK( eLangType, EE_CHAR_LANGUAGE_CJK );
361 aOutput.Put( aItemCJK );
363 SvxLanguageItem aItemCTL( eLangType, EE_CHAR_LANGUAGE_CTL );
364 aOutput.Put( aItemCTL );
367 return aOutput;