1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sd.hxx" 30 31 #ifdef SD_DLLIMPLEMENTATION 32 #undef SD_DLLIMPLEMENTATION 33 #endif 34 35 36 37 #include <editeng/editeng.hxx> 38 #include <editeng/eeitem.hxx> 39 #include <editeng/flditem.hxx> 40 #include <svl/zforlist.hxx> 41 #include <sfx2/objsh.hxx> 42 #include <sfx2/docfile.hxx> 43 #include <svl/itemset.hxx> 44 #include <editeng/langitem.hxx> 45 #include <unotools/useroptions.hxx> 46 47 #include "strings.hrc" 48 #include "dlgfield.hrc" 49 #include "sdattr.hxx" 50 #include "sdresid.hxx" 51 #include "sdmod.hxx" 52 #include "dlgfield.hxx" 53 #include "drawdoc.hxx" 54 #include "DrawDocShell.hxx" 55 56 /************************************************************************* 57 |* 58 |* Dialog zum Bearbeiten von Feldbefehlen 59 |* 60 \************************************************************************/ 61 62 SdModifyFieldDlg::SdModifyFieldDlg( Window* pWindow, const SvxFieldData* pInField, const SfxItemSet& rSet ) : 63 ModalDialog ( pWindow, SdResId( DLG_FIELD_MODIFY ) ), 64 aGrpType ( this, SdResId( GRP_TYPE ) ), 65 aRbtFix ( this, SdResId( RBT_FIX ) ), 66 aRbtVar ( this, SdResId( RBT_VAR ) ), 67 maFtLanguage( this, SdResId( FT_LANGUAGE ) ), 68 maLbLanguage( this, SdResId( LB_LANGUAGE ) ), 69 aFtFormat ( this, SdResId( FT_FORMAT ) ), 70 aLbFormat ( this, SdResId( LB_FORMAT ) ), 71 aBtnOK ( this, SdResId( BTN_OK ) ), 72 aBtnCancel ( this, SdResId( BTN_CANCEL ) ), 73 aBtnHelp ( this, SdResId( BTN_HELP ) ), 74 maInputSet ( rSet ), 75 pField ( pInField ) 76 { 77 FreeResource(); 78 79 maLbLanguage.SetLanguageList( LANG_LIST_ALL|LANG_LIST_ONLY_KNOWN, false ); 80 maLbLanguage.SetSelectHdl( LINK( this, SdModifyFieldDlg, LanguageChangeHdl ) ); 81 FillControls(); 82 } 83 84 /************************************************************************* 85 |* 86 |* Gibt das neue Feld zurueck, gehoert dem Caller. 87 |* Liefert NULL, wenn sich nichts geaendert hat. 88 |* 89 \************************************************************************/ 90 91 SvxFieldData* SdModifyFieldDlg::GetField() 92 { 93 SvxFieldData* pNewField = NULL; 94 95 if( aRbtFix.IsChecked() != aRbtFix.GetSavedValue() || 96 aRbtVar.IsChecked() != aRbtVar.GetSavedValue() || 97 aLbFormat.GetSelectEntryPos() != aLbFormat.GetSavedValue() ) 98 { 99 if( pField->ISA( SvxDateField ) ) 100 { 101 const SvxDateField* pDateField = (const SvxDateField*) pField; 102 SvxDateType eType; 103 SvxDateFormat eFormat; 104 105 if( aRbtFix.IsChecked() ) 106 eType = SVXDATETYPE_FIX; 107 else 108 eType = SVXDATETYPE_VAR; 109 110 eFormat = (SvxDateFormat) ( aLbFormat.GetSelectEntryPos() + 2 ); 111 112 pNewField = new SvxDateField( *pDateField ); 113 ( (SvxDateField*) pNewField )->SetType( eType ); 114 ( (SvxDateField*) pNewField )->SetFormat( eFormat ); 115 } 116 else if( pField->ISA( SvxExtTimeField ) ) 117 { 118 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField; 119 SvxTimeType eType; 120 SvxTimeFormat eFormat; 121 122 if( aRbtFix.IsChecked() ) 123 eType = SVXTIMETYPE_FIX; 124 else 125 eType = SVXTIMETYPE_VAR; 126 127 eFormat = (SvxTimeFormat) ( aLbFormat.GetSelectEntryPos() + 2 ); 128 129 pNewField = new SvxExtTimeField( *pTimeField ); 130 ( (SvxExtTimeField*) pNewField )->SetType( eType ); 131 ( (SvxExtTimeField*) pNewField )->SetFormat( eFormat ); 132 } 133 else if( pField->ISA( SvxExtFileField ) ) 134 { 135 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField; 136 SvxFileType eType; 137 SvxFileFormat eFormat; 138 139 if( aRbtFix.IsChecked() ) 140 eType = SVXFILETYPE_FIX; 141 else 142 eType = SVXFILETYPE_VAR; 143 144 eFormat = (SvxFileFormat) ( aLbFormat.GetSelectEntryPos() ); 145 146 ::sd::DrawDocShell* pDocSh = PTR_CAST( ::sd::DrawDocShell, 147 SfxObjectShell::Current() ); 148 149 if( pDocSh ) 150 { 151 SvxExtFileField aFileField( *pFileField ); 152 153 String aName; 154 if( pDocSh->HasName() ) 155 aName = pDocSh->GetMedium()->GetName(); 156 157 // #91225# Get current filename, not the one stored in the old field 158 pNewField = new SvxExtFileField( aName ); 159 ( (SvxExtFileField*) pNewField )->SetType( eType ); 160 ( (SvxExtFileField*) pNewField )->SetFormat( eFormat ); 161 } 162 } 163 else if( pField->ISA( SvxAuthorField ) ) 164 { 165 SvxAuthorType eType; 166 SvxAuthorFormat eFormat; 167 168 if( aRbtFix.IsChecked() ) 169 eType = SVXAUTHORTYPE_FIX; 170 else 171 eType = SVXAUTHORTYPE_VAR; 172 173 eFormat = (SvxAuthorFormat) ( aLbFormat.GetSelectEntryPos() ); 174 175 // #91225# Get current state of address, not the old one 176 SvtUserOptions aUserOptions; 177 pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() ); 178 ( (SvxAuthorField*) pNewField )->SetType( eType ); 179 ( (SvxAuthorField*) pNewField )->SetFormat( eFormat ); 180 } 181 } 182 183 return( pNewField ); 184 } 185 186 /************************************************************************* 187 |* 188 |* 189 |* 190 \************************************************************************/ 191 192 void SdModifyFieldDlg::FillFormatList() 193 { 194 LanguageType eLangType = maLbLanguage.GetSelectLanguage(); 195 196 aLbFormat.Clear(); 197 198 if( pField->ISA( SvxDateField ) ) 199 { 200 const SvxDateField* pDateField = (const SvxDateField*) pField; 201 SvxDateField aDateField( *pDateField ); 202 203 //SVXDATEFORMAT_APPDEFAULT, // Wird nicht benutzt 204 //SVXDATEFORMAT_SYSTEM, // Wird nicht benutzt 205 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_SMALL ) ) ); 206 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_BIG ) ) ); 207 208 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter(); 209 aDateField.SetFormat( SVXDATEFORMAT_A ); // 13.02.96 210 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); 211 aDateField.SetFormat( SVXDATEFORMAT_B ); // 13.02.1996 212 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); 213 aDateField.SetFormat( SVXDATEFORMAT_C ); // 13.Feb 1996 214 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); 215 aDateField.SetFormat( SVXDATEFORMAT_D ); // 13.Februar 1996 216 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); 217 aDateField.SetFormat( SVXDATEFORMAT_E ); // Die, 13.Februar 1996 218 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); 219 aDateField.SetFormat( SVXDATEFORMAT_F ); // Dienstag, 13.Februar 1996 220 aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) ); 221 222 aLbFormat.SelectEntryPos( (sal_uInt16) ( pDateField->GetFormat() - 2 ) ); 223 } 224 else if( pField->ISA( SvxExtTimeField ) ) 225 { 226 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField; 227 SvxExtTimeField aTimeField( *pTimeField ); 228 229 //SVXTIMEFORMAT_APPDEFAULT, // Wird nicht benutzt 230 //SVXTIMEFORMAT_SYSTEM, // Wird nicht benutzt 231 aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_NORMAL ) ) ); 232 233 SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter(); 234 aTimeField.SetFormat( SVXTIMEFORMAT_24_HM ); // 13:49 235 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) ); 236 aTimeField.SetFormat( SVXTIMEFORMAT_24_HMS ); // 13:49:38 237 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) ); 238 aTimeField.SetFormat( SVXTIMEFORMAT_24_HMSH ); // 13:49:38.78 239 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) ); 240 aTimeField.SetFormat( SVXTIMEFORMAT_12_HM ); // 01:49 241 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) ); 242 aTimeField.SetFormat( SVXTIMEFORMAT_12_HMS ); // 01:49:38 243 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) ); 244 aTimeField.SetFormat( SVXTIMEFORMAT_12_HMSH ); // 01:49:38.78 245 aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) ); 246 //SVXTIMEFORMAT_AM_HM, // 01:49 PM 247 //SVXTIMEFORMAT_AM_HMS, // 01:49:38 PM 248 //SVXTIMEFORMAT_AM_HMSH // 01:49:38.78 PM 249 250 aLbFormat.SelectEntryPos( (sal_uInt16) ( pTimeField->GetFormat() - 2 ) ); 251 } 252 else if( pField->ISA( SvxExtFileField ) ) 253 { 254 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField; 255 SvxExtFileField aFileField( *pFileField ); 256 257 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_NAME_EXT ) ) ); 258 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_FULLPATH ) ) ); 259 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_PATH ) ) ); 260 aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_NAME ) ) ); 261 262 aLbFormat.SelectEntryPos( (sal_uInt16) ( pFileField->GetFormat() ) ); 263 } 264 else if( pField->ISA( SvxAuthorField ) ) 265 { 266 const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField; 267 SvxAuthorField aAuthorField( *pAuthorField ); 268 269 for( sal_uInt16 i = 0; i < 4; i++ ) 270 { 271 aAuthorField.SetFormat( (SvxAuthorFormat) i ); 272 aLbFormat.InsertEntry( aAuthorField.GetFormatted() ); 273 } 274 275 aLbFormat.SelectEntryPos( (sal_uInt16) ( pAuthorField->GetFormat() ) ); 276 277 } 278 279 280 } 281 282 void SdModifyFieldDlg::FillControls() 283 { 284 aLbFormat.Clear(); 285 286 if( pField->ISA( SvxDateField ) ) 287 { 288 const SvxDateField* pDateField = (const SvxDateField*) pField; 289 SvxDateField aDateField( *pDateField ); 290 291 if( pDateField->GetType() == SVXDATETYPE_FIX ) 292 aRbtFix.Check(); 293 else 294 aRbtVar.Check(); 295 } 296 else if( pField->ISA( SvxExtTimeField ) ) 297 { 298 const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField; 299 SvxExtTimeField aTimeField( *pTimeField ); 300 301 if( pTimeField->GetType() == SVXTIMETYPE_FIX ) 302 aRbtFix.Check(); 303 else 304 aRbtVar.Check(); 305 } 306 else if( pField->ISA( SvxExtFileField ) ) 307 { 308 const SvxExtFileField* pFileField = (const SvxExtFileField*) pField; 309 SvxExtFileField aFileField( *pFileField ); 310 311 if( pFileField->GetType() == SVXFILETYPE_FIX ) 312 aRbtFix.Check(); 313 else 314 aRbtVar.Check(); 315 } 316 else if( pField->ISA( SvxAuthorField ) ) 317 { 318 const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField; 319 SvxAuthorField aAuthorField( *pAuthorField ); 320 321 if( pAuthorField->GetType() == SVXAUTHORTYPE_FIX ) 322 aRbtFix.Check(); 323 else 324 aRbtVar.Check(); 325 } 326 aRbtFix.SaveValue(); 327 aRbtVar.SaveValue(); 328 329 const SfxPoolItem* pItem; 330 if( SFX_ITEM_SET == maInputSet.GetItemState(EE_CHAR_LANGUAGE, sal_True, &pItem ) ) 331 maLbLanguage.SelectLanguage( static_cast<const SvxLanguageItem*>(pItem)->GetLanguage() ); 332 333 maLbLanguage.SaveValue(); 334 335 FillFormatList(); 336 aLbFormat.SaveValue(); 337 } 338 339 340 IMPL_LINK( SdModifyFieldDlg, LanguageChangeHdl, void *, EMPTYARG ) 341 { 342 FillFormatList(); 343 344 return 0L; 345 } 346 347 SfxItemSet SdModifyFieldDlg::GetItemSet() 348 { 349 SfxItemSet aOutput( *maInputSet.GetPool(), EE_CHAR_LANGUAGE, EE_CHAR_LANGUAGE_CTL ); 350 351 if( maLbLanguage.GetSelectEntryPos() != maLbLanguage.GetSavedValue() ) 352 { 353 LanguageType eLangType = maLbLanguage.GetSelectLanguage(); 354 SvxLanguageItem aItem( eLangType, EE_CHAR_LANGUAGE ); 355 aOutput.Put( aItem ); 356 357 SvxLanguageItem aItemCJK( eLangType, EE_CHAR_LANGUAGE_CJK ); 358 aOutput.Put( aItemCJK ); 359 360 SvxLanguageItem aItemCTL( eLangType, EE_CHAR_LANGUAGE_CTL ); 361 aOutput.Put( aItemCTL ); 362 } 363 364 return aOutput; 365 } 366 367