bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / dlg / dlgfield.cxx
blobac42f45854c447c1b05d21134815b267e2d63a98
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/editeng.hxx>
21 #include <editeng/eeitem.hxx>
22 #include <editeng/flditem.hxx>
23 #include <svl/zforlist.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <sfx2/docfile.hxx>
26 #include <svl/itemset.hxx>
27 #include <editeng/langitem.hxx>
28 #include <unotools/useroptions.hxx>
30 #include "strings.hrc"
31 #include "dlgfield.hrc"
32 #include "sdattr.hxx"
33 #include "sdresid.hxx"
34 #include "sdmod.hxx"
35 #include "dlgfield.hxx"
36 #include "drawdoc.hxx"
37 #include "DrawDocShell.hxx"
39 /**
40 * dialog to edit field commands
42 SdModifyFieldDlg::SdModifyFieldDlg( Window* pWindow, const SvxFieldData* pInField, const SfxItemSet& rSet ) :
43 ModalDialog ( pWindow, SdResId( DLG_FIELD_MODIFY ) ),
44 aGrpType ( this, SdResId( GRP_TYPE ) ),
45 aRbtFix ( this, SdResId( RBT_FIX ) ),
46 aRbtVar ( this, SdResId( RBT_VAR ) ),
47 maFtLanguage( this, SdResId( FT_LANGUAGE ) ),
48 maLbLanguage( this, SdResId( LB_LANGUAGE ) ),
49 aFtFormat ( this, SdResId( FT_FORMAT ) ),
50 aLbFormat ( this, SdResId( LB_FORMAT ) ),
51 aBtnOK ( this, SdResId( BTN_OK ) ),
52 aBtnCancel ( this, SdResId( BTN_CANCEL ) ),
53 aBtnHelp ( this, SdResId( BTN_HELP ) ),
54 maInputSet ( rSet ),
55 pField ( pInField )
57 FreeResource();
59 maLbLanguage.SetLanguageList( LANG_LIST_ALL|LANG_LIST_ONLY_KNOWN, false );
60 maLbLanguage.SetSelectHdl( LINK( this, SdModifyFieldDlg, LanguageChangeHdl ) );
61 FillControls();
64 /**
65 * Returns the new field, owned by caller.
66 * Returns NULL if nothing has changed.
68 SvxFieldData* SdModifyFieldDlg::GetField()
70 SvxFieldData* pNewField = NULL;
72 if( aRbtFix.IsChecked() != aRbtFix.GetSavedValue() ||
73 aRbtVar.IsChecked() != aRbtVar.GetSavedValue() ||
74 aLbFormat.GetSelectEntryPos() != aLbFormat.GetSavedValue() )
76 if( pField->ISA( SvxDateField ) )
78 const SvxDateField* pDateField = (const SvxDateField*) pField;
79 SvxDateType eType;
80 SvxDateFormat eFormat;
82 if( aRbtFix.IsChecked() )
83 eType = SVXDATETYPE_FIX;
84 else
85 eType = SVXDATETYPE_VAR;
87 eFormat = (SvxDateFormat) ( aLbFormat.GetSelectEntryPos() + 2 );
89 pNewField = new SvxDateField( *pDateField );
90 ( (SvxDateField*) pNewField )->SetType( eType );
91 ( (SvxDateField*) pNewField )->SetFormat( eFormat );
93 else if( pField->ISA( SvxExtTimeField ) )
95 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
96 SvxTimeType eType;
97 SvxTimeFormat eFormat;
99 if( aRbtFix.IsChecked() )
100 eType = SVXTIMETYPE_FIX;
101 else
102 eType = SVXTIMETYPE_VAR;
104 eFormat = (SvxTimeFormat) ( aLbFormat.GetSelectEntryPos() + 2 );
106 pNewField = new SvxExtTimeField( *pTimeField );
107 ( (SvxExtTimeField*) pNewField )->SetType( eType );
108 ( (SvxExtTimeField*) pNewField )->SetFormat( eFormat );
110 else if( pField->ISA( SvxExtFileField ) )
112 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
113 SvxFileType eType;
114 SvxFileFormat eFormat;
116 if( aRbtFix.IsChecked() )
117 eType = SVXFILETYPE_FIX;
118 else
119 eType = SVXFILETYPE_VAR;
121 eFormat = (SvxFileFormat) ( aLbFormat.GetSelectEntryPos() );
123 ::sd::DrawDocShell* pDocSh = PTR_CAST( ::sd::DrawDocShell,
124 SfxObjectShell::Current() );
126 if( pDocSh )
128 SvxExtFileField aFileField( *pFileField );
130 String aName;
131 if( pDocSh->HasName() )
132 aName = pDocSh->GetMedium()->GetName();
134 // Get current filename, not the one stored in the old field
135 pNewField = new SvxExtFileField( aName );
136 ( (SvxExtFileField*) pNewField )->SetType( eType );
137 ( (SvxExtFileField*) pNewField )->SetFormat( eFormat );
140 else if( pField->ISA( SvxAuthorField ) )
142 SvxAuthorType eType;
143 SvxAuthorFormat eFormat;
145 if( aRbtFix.IsChecked() )
146 eType = SVXAUTHORTYPE_FIX;
147 else
148 eType = SVXAUTHORTYPE_VAR;
150 eFormat = (SvxAuthorFormat) ( aLbFormat.GetSelectEntryPos() );
152 // Get current state of address, not the old one
153 SvtUserOptions aUserOptions;
154 pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
155 ( (SvxAuthorField*) pNewField )->SetType( eType );
156 ( (SvxAuthorField*) pNewField )->SetFormat( eFormat );
160 return( pNewField );
163 void SdModifyFieldDlg::FillFormatList()
165 LanguageType eLangType = maLbLanguage.GetSelectLanguage();
167 aLbFormat.Clear();
169 if( pField->ISA( SvxDateField ) )
171 const SvxDateField* pDateField = (const SvxDateField*) pField;
172 SvxDateField aDateField( *pDateField );
174 //SVXDATEFORMAT_APPDEFAULT, // not used
175 //SVXDATEFORMAT_SYSTEM, // not used
176 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_SMALL ) ) );
177 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_BIG ) ) );
179 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
180 aDateField.SetFormat( SVXDATEFORMAT_A ); // 13.02.96
181 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
182 aDateField.SetFormat( SVXDATEFORMAT_B ); // 13.02.1996
183 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
184 aDateField.SetFormat( SVXDATEFORMAT_C ); // 13.Feb 1996
185 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
186 aDateField.SetFormat( SVXDATEFORMAT_D ); // 13.Februar 1996
187 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
188 aDateField.SetFormat( SVXDATEFORMAT_E ); // Die, 13.Februar 1996
189 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
190 aDateField.SetFormat( SVXDATEFORMAT_F ); // Dienstag, 13.Februar 1996
191 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
193 aLbFormat.SelectEntryPos( (sal_uInt16) ( pDateField->GetFormat() - 2 ) );
195 else if( pField->ISA( SvxExtTimeField ) )
197 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
198 SvxExtTimeField aTimeField( *pTimeField );
200 //SVXTIMEFORMAT_APPDEFAULT, // not used
201 //SVXTIMEFORMAT_SYSTEM, // not used
202 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_NORMAL ) ) );
204 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
205 aTimeField.SetFormat( SVXTIMEFORMAT_24_HM ); // 13:49
206 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
207 aTimeField.SetFormat( SVXTIMEFORMAT_24_HMS ); // 13:49:38
208 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
209 aTimeField.SetFormat( SVXTIMEFORMAT_24_HMSH ); // 13:49:38.78
210 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
211 aTimeField.SetFormat( SVXTIMEFORMAT_12_HM ); // 01:49
212 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
213 aTimeField.SetFormat( SVXTIMEFORMAT_12_HMS ); // 01:49:38
214 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
215 aTimeField.SetFormat( SVXTIMEFORMAT_12_HMSH ); // 01:49:38.78
216 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
217 //SVXTIMEFORMAT_AM_HM, // 01:49 PM
218 //SVXTIMEFORMAT_AM_HMS, // 01:49:38 PM
219 //SVXTIMEFORMAT_AM_HMSH // 01:49:38.78 PM
221 aLbFormat.SelectEntryPos( (sal_uInt16) ( pTimeField->GetFormat() - 2 ) );
223 else if( pField->ISA( SvxExtFileField ) )
225 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
226 SvxExtFileField aFileField( *pFileField );
228 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_NAME_EXT ) ) );
229 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_FULLPATH ) ) );
230 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_PATH ) ) );
231 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_NAME ) ) );
233 aLbFormat.SelectEntryPos( (sal_uInt16) ( pFileField->GetFormat() ) );
235 else if( pField->ISA( SvxAuthorField ) )
237 const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
238 SvxAuthorField aAuthorField( *pAuthorField );
240 for( sal_uInt16 i = 0; i < 4; i++ )
242 aAuthorField.SetFormat( (SvxAuthorFormat) i );
243 aLbFormat.InsertEntry( aAuthorField.GetFormatted() );
246 aLbFormat.SelectEntryPos( (sal_uInt16) ( pAuthorField->GetFormat() ) );
253 void SdModifyFieldDlg::FillControls()
255 aLbFormat.Clear();
257 if( pField->ISA( SvxDateField ) )
259 const SvxDateField* pDateField = (const SvxDateField*) pField;
260 SvxDateField aDateField( *pDateField );
262 if( pDateField->GetType() == SVXDATETYPE_FIX )
263 aRbtFix.Check();
264 else
265 aRbtVar.Check();
267 else if( pField->ISA( SvxExtTimeField ) )
269 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
270 SvxExtTimeField aTimeField( *pTimeField );
272 if( pTimeField->GetType() == SVXTIMETYPE_FIX )
273 aRbtFix.Check();
274 else
275 aRbtVar.Check();
277 else if( pField->ISA( SvxExtFileField ) )
279 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
280 SvxExtFileField aFileField( *pFileField );
282 if( pFileField->GetType() == SVXFILETYPE_FIX )
283 aRbtFix.Check();
284 else
285 aRbtVar.Check();
287 else if( pField->ISA( SvxAuthorField ) )
289 const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
290 SvxAuthorField aAuthorField( *pAuthorField );
292 if( pAuthorField->GetType() == SVXAUTHORTYPE_FIX )
293 aRbtFix.Check();
294 else
295 aRbtVar.Check();
297 aRbtFix.SaveValue();
298 aRbtVar.SaveValue();
300 const SfxPoolItem* pItem;
301 if( SFX_ITEM_SET == maInputSet.GetItemState(EE_CHAR_LANGUAGE, sal_True, &pItem ) )
302 maLbLanguage.SelectLanguage( static_cast<const SvxLanguageItem*>(pItem)->GetLanguage() );
304 maLbLanguage.SaveValue();
306 FillFormatList();
307 aLbFormat.SaveValue();
311 IMPL_LINK_NOARG(SdModifyFieldDlg, LanguageChangeHdl)
313 FillFormatList();
315 return 0L;
318 SfxItemSet SdModifyFieldDlg::GetItemSet()
320 SfxItemSet aOutput( *maInputSet.GetPool(), EE_CHAR_LANGUAGE, EE_CHAR_LANGUAGE_CTL );
322 if( maLbLanguage.GetSelectEntryPos() != maLbLanguage.GetSavedValue() )
324 LanguageType eLangType = maLbLanguage.GetSelectLanguage();
325 SvxLanguageItem aItem( eLangType, EE_CHAR_LANGUAGE );
326 aOutput.Put( aItem );
328 SvxLanguageItem aItemCJK( eLangType, EE_CHAR_LANGUAGE_CJK );
329 aOutput.Put( aItemCJK );
331 SvxLanguageItem aItemCTL( eLangType, EE_CHAR_LANGUAGE_CTL );
332 aOutput.Put( aItemCTL );
335 return aOutput;
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */