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_sw.hxx" 30 31 32 33 #include <stdlib.h> 34 35 #include <stdio.h> 36 #include "hintids.hxx" 37 #include <tools/resid.hxx> 38 #include <svl/macitem.hxx> 39 #include <svl/zforlist.hxx> 40 #include <svl/zformat.hxx> 41 #include <svl/urihelper.hxx> 42 #include <sfx2/linkmgr.hxx> 43 44 #ifndef _SVSTDARR_USHORTS_DECL 45 #define _SVSTDARR_USHORTS 46 #include <svl/svstdarr.hxx> 47 #endif 48 #include <editeng/lrspitem.hxx> 49 #include <editeng/tstpitem.hxx> 50 #include <fmtinfmt.hxx> 51 #include <fmtfld.hxx> 52 #include <frmatr.hxx> 53 #include "doc.hxx" 54 #include "docary.hxx" 55 #include "fldbas.hxx" 56 #include "flddat.hxx" 57 #include "docufld.hxx" 58 #include "chpfld.hxx" 59 #include "ddefld.hxx" 60 #include "expfld.hxx" 61 #include "reffld.hxx" 62 #include "usrfld.hxx" 63 #include "dbfld.hxx" 64 #include "txtfld.hxx" 65 #include "ndtxt.hxx" 66 67 //really used ids from old sw3ids.hxx 68 #define SWG_INETBROWSER 0x000e // URL-Grf-Nodes, Browse-Flag, Format-Ums. 69 #define SWG_NEWFIELDS 0x0200 // Felder mit Numberformatter-Zahlenformat 70 #define SWG_EXPORT40 0x0110 // Version fuer 4.0-Export ab 5.0 71 72 using namespace nsSwDocInfoSubType; 73 74 75 //#include "poolfmt.hxx" // fuer InSetExpField 76 //#include "poolfmt.hrc" // fuer InSetExpField 77 78 //#if !defined(UNX) && !defined(MSC) && !defined(PPC) && !defined(CSET) && !defined(__MWERKS__) && !defined(WTC) 79 80 //#define FIELDFNTAB_SIZE 37 81 //#if FIELDFNTAB_SIZE != RES_FIELDS_END - RES_FIELDS_BEGIN 82 //#error Feld-Tabelle ist ungueltigt. Wurden neue Hint-IDs zugefuegt ?? 83 //#endif 84 85 //#endif 86 87 //#define SWG_AUTHORITY_ENTRY_LCL 'E' 88 89 //sal_Char __FAR_DATA sSW3IO_FixedField[] = "FixedExport"; 90 //sal_Char __FAR_DATA sSW3IO_AuthorityField[] = "AuthorityExport"; 91 /* #108791# */ 92 //sal_Char __FAR_DATA sSW3IO_DropDownField[] = "DropDownExport"; 93 94 struct OldFormats 95 { 96 NfIndexTableOffset eFormatIdx; 97 sal_uInt16 nOldFormat; 98 }; 99 100 static OldFormats aOldDateFmt40[] = 101 { 102 // Datumsfelder: 103 { NF_DATE_SYSTEM_SHORT, DFF_SSYS }, // Kurzes Systemdatum 104 { NF_DATE_SYSTEM_LONG, DFF_LSYS }, // Langes Systemdatum 105 { NF_DATE_SYS_DDMMYY, DFF_DMY }, // 06.10.64 106 { NF_DATE_SYS_DDMMYYYY, DFF_DMYY }, // 06.10.1964 107 { NF_DATE_SYS_DMMMYY, DFF_DMMY }, // 06. Okt 64 108 { NF_DATE_SYS_DMMMYYYY, DFF_DMMYY }, // 06. Okt 1964 109 { NF_DATE_DIN_DMMMMYYYY, DFF_DMMMYY }, // 06. Oktober 1964 110 { NF_DATE_DIN_DMMMMYYYY, DFF_DMMMY }, // 06. Oktober 64 111 { NF_DATE_SYS_NNDMMMYY, DFF_DDMMY }, // Di, 06. Okt 64 112 { NF_DATE_SYS_NNDMMMMYYYY, DFF_DDMMMY }, // Di, 06. Oktober 64 113 { NF_DATE_SYS_NNDMMMMYYYY, DFF_DDMMMYY }, // Di, 06. Oktober 1964 114 { NF_DATE_SYS_NNNNDMMMMYYYY, DFF_DDDMMMYY }, // Dienstag, 06. Oktober 1964 115 { NF_DATE_SYS_NNNNDMMMMYYYY, DFF_DDDMMMY }, // Dienstag, 06. Oktober 64 116 { NF_DATE_SYS_MMYY, DFF_MY }, // 10.64 117 { NF_DATE_DIN_MMDD, DFF_MD }, // 10-06 118 { NF_DATE_DIN_YYMMDD, DFF_YMD }, // 64-10-06 119 { NF_DATE_DIN_YYYYMMDD, DFF_YYMD }, // 1964-10-06 120 121 { NF_NUMERIC_START, 0 } // Tabellenende 122 }; 123 124 static OldFormats aOldDateFmt30[] = 125 { 126 // Datumsfelder: 127 { NF_DATE_SYSTEM_SHORT, DFF_SSYS }, // Kurzes Systemdatum 128 { NF_DATE_SYSTEM_LONG, DFF_LSYS }, // Langes Systemdatum 129 { NF_DATE_SYS_DDMMYY, DFF_DMY }, // 06.10.64 130 { NF_DATE_SYS_DDMMYYYY, DFF_DMYY }, // 06.10.1964 131 { NF_DATE_SYS_DMMMYY, DFF_DMMY }, // 06. Okt 64 132 { NF_DATE_SYS_DMMMYYYY, 4 /*DFF_DMMYY*/ }, // 06. Okt 1964 133 { NF_DATE_DIN_DMMMMYYYY, 5 /*DFF_DMMMYY*/ }, // 06. Oktober 1964 134 { NF_DATE_DIN_DMMMMYYYY, 5 /*DFF_DMMMY*/ }, // 06. Oktober 64 135 { NF_DATE_SYS_NNDMMMMYYYY, 6 /*DFF_DDMMMYY*/ }, // Di, 06. Oktober 1964 136 { NF_DATE_SYS_NNDMMMYY, 6 /*DFF_DDMMY*/ }, // Di, 06. Okt 64 137 { NF_DATE_SYS_NNDMMMMYYYY, 6 /*DFF_DDMMMY*/ }, // Di, 06. Oktober 64 138 { NF_DATE_SYS_NNNNDMMMMYYYY, 7 /*DFF_DDDMMMYY*/ }, // Dienstag, 06. Oktober 1964 139 { NF_DATE_SYS_NNNNDMMMMYYYY, 7 /*DFF_DDDMMMY*/ }, // Dienstag, 06. Oktober 64 140 { NF_DATE_SYS_MMYY, 2 /*DFF_MY*/ }, // 10.64 141 { NF_DATE_DIN_MMDD, DFF_MD }, // 10-06 142 { NF_DATE_DIN_YYMMDD, DFF_YMD }, // 64-10-06 143 { NF_DATE_DIN_YYYYMMDD, DFF_YYMD }, // 1964-10-06 144 145 { NF_NUMERIC_START, 0 } // Tabellenende 146 }; 147 148 static OldFormats aOldTimeFmt[] = 149 { 150 // Zeitfelder: 151 { NF_TIME_HHMMSS, TF_SYSTEM }, // Systemzeit 152 { NF_TIME_HHMM, TF_SSMM_24 }, // 23:25 153 { NF_TIME_HHMMAMPM, TF_SSMM_12 }, // 11:25 PM 154 155 { NF_NUMERIC_START, 0 } // Tabellenende 156 }; 157 158 static OldFormats aOldGetSetExpFmt40[] = 159 { 160 { NF_TEXT, VVF_CMD }, // Kommando anzeigen 161 { NF_TEXT, VVF_INVISIBLE }, // unsichtbar 162 { NF_PERCENT_INT, VVF_XXP }, // 1234% 163 { NF_PERCENT_DEC2, VVF_XX_XXP }, // 1.234,56% 164 { NF_TEXT, VVF_CLEAR }, // ??? 165 166 { NF_NUMBER_SYSTEM, VVF_SYS }, // Zahlenformat aus der 167 // Systemeinstellung 168 { NF_NUMBER_INT, VVF_X }, // 1234 169 { NF_NUMBER_DEC2, VVF_X_X }, // 1234,5 170 { NF_NUMBER_DEC2, VVF_X_XX }, // 1245,56 171 { NF_NUMBER_1000DEC2, VVF_XX_XX }, // 1.234,56 172 { NF_NUMBER_1000DEC2, VVF_XX_X }, // 1.234,5 173 { NF_NUMBER_1000DEC2, VVF_XX_XXX }, // 1.234,567 174 { NF_CURRENCY_1000DEC2, VVF_SYS_CUR }, // W?hrungsformat aus der 175 // Systemeinstellung 176 // (1.234,00 DM) 177 { NF_CURRENCY_1000INT, VVF_X_CUR }, // 1234 DM 178 { NF_CURRENCY_1000DEC2, VVF_XX_XX_CUR }, // 1234,56 DM 1234,00 DM 179 { NF_CURRENCY_1000DEC2_DASHED, VVF_XX_X0_CUR }, // 1234,56 DM 1234,-- DM 180 { NF_CURRENCY_1000INT, VVF_CUR_X }, // DM 1234 181 { NF_CURRENCY_1000DEC2, VVF_CUR_XX_XX }, // DM 1234,56 DM 1234,00 182 { NF_CURRENCY_1000DEC2_DASHED, VVF_CUR_XX_X0 }, // DM 1234,56 DM 1234,-- 183 184 { NF_NUMERIC_START, 0 } // Tabellenende 185 }; 186 187 static OldFormats aOldGetSetExpFmt30[] = 188 { 189 { NF_TEXT, VVF_CMD }, // Kommando anzeigen 190 { NF_TEXT, VVF_INVISIBLE }, // unsichtbar 191 { NF_PERCENT_INT, VVF_XXP }, // 1234% 192 { NF_PERCENT_DEC2, VVF_XX_XXP }, // 1.234,56% 193 { NF_TEXT, VVF_CLEAR }, // ??? 194 195 { NF_NUMBER_SYSTEM, 0x0020 }, // Zahlenformat aus der 196 // Systemeinstellung 197 { NF_NUMBER_INT, 0x0080 }, // 1234 198 { NF_NUMBER_1000DEC2, 0x0100 }, // 1.234,56 199 { NF_NUMBER_DEC2, 0x0100 }, // 1234,5 200 { NF_NUMBER_DEC2, 0x0100 }, // 1245,56 201 { NF_NUMBER_1000DEC2, 0x0100 }, // 1.234,5 202 { NF_NUMBER_1000DEC2, 0x0100 }, // 1.234,567 203 { NF_CURRENCY_1000DEC2, 0x0200 }, // W?hrungsformat aus der 204 // Systemeinstellung 205 // (1.234,00 DM) 206 { NF_CURRENCY_1000INT, 0x1000 }, // 1234 DM 207 { NF_CURRENCY_1000DEC2, 0x1000 }, // 1234,56 DM 1234,00 DM 208 { NF_CURRENCY_1000DEC2_DASHED, 0x1000 }, // 1234,56 DM 1234,-- DM 209 { NF_CURRENCY_1000INT, 0x1000 }, // DM 1234 210 { NF_CURRENCY_1000DEC2, 0x1000 }, // DM 1234,56 DM 1234,00 211 { NF_CURRENCY_1000DEC2_DASHED, 0x1000 }, // DM 1234,56 DM 1234,-- 212 213 { NF_NUMERIC_START, 0 } // Tabellenende 214 }; 215 216 SW_DLLPUBLIC void sw3io_ConvertFromOldField( SwDoc& rDoc, sal_uInt16& rWhich, 217 sal_uInt16& rSubType, sal_uLong &rFmt, 218 sal_uInt16 nVersion ) 219 { 220 const OldFormats *pOldFmt = 0L; 221 222 switch( rWhich ) 223 { 224 case RES_DATEFLD: 225 case RES_FIXDATEFLD: 226 if( nVersion < SWG_NEWFIELDS ) 227 { 228 rSubType = DATEFLD; 229 if( RES_FIXDATEFLD == rWhich ) 230 rSubType |= FIXEDFLD; 231 rWhich = RES_DATETIMEFLD; 232 pOldFmt = nVersion<SWG_INETBROWSER ? aOldDateFmt30 233 : aOldDateFmt40; 234 } 235 break; 236 237 case RES_TIMEFLD: 238 case RES_FIXTIMEFLD: 239 if( nVersion < SWG_NEWFIELDS ) 240 { 241 rSubType = TIMEFLD; 242 if( RES_FIXTIMEFLD == rWhich ) 243 rSubType |= FIXEDFLD; 244 rWhich = RES_DATETIMEFLD; 245 pOldFmt = aOldTimeFmt; 246 } 247 break; 248 249 case RES_DBFLD: 250 if( nVersion < SWG_NEWFIELDS ) 251 { 252 rSubType = nsSwExtendedSubType::SUB_OWN_FMT; 253 pOldFmt = nVersion<SWG_INETBROWSER ? aOldGetSetExpFmt30 254 : aOldGetSetExpFmt40; 255 } 256 break; 257 258 case RES_TABLEFLD: 259 case RES_GETEXPFLD: 260 case RES_SETEXPFLD: 261 case RES_USERFLD: 262 if( nVersion < SWG_NEWFIELDS ) 263 { 264 if( rFmt == VVF_INVISIBLE ) 265 { 266 rSubType = nsSwExtendedSubType::SUB_INVISIBLE; 267 rFmt = 0; 268 } 269 else if( rFmt == VVF_CMD ) 270 { 271 rSubType = nsSwExtendedSubType::SUB_CMD; 272 rFmt = 0; 273 } 274 else 275 { 276 // Kleiner Hack: Bei Numernkreisen wird das 277 // unkonvertierte Format noch benoetigt. Wir merken es 278 // uns voruebergehend mal im Subtyp, sofern es 279 // ueberhaupt als entsprechendes Format in Frage kommt. 280 if( RES_SETEXPFLD==rWhich && 281 /*rFmt >= (sal_uInt16)SVX_NUM_CHARS_UPPER_LETTER && always true*/ 282 rFmt <= (sal_uInt16)SVX_NUM_BITMAP ) 283 { 284 rSubType = (sal_uInt16)rFmt; 285 } 286 pOldFmt = nVersion<SWG_INETBROWSER ? aOldGetSetExpFmt30 287 : aOldGetSetExpFmt40; 288 } 289 } 290 break; 291 case RES_DOCINFOFLD: 292 if( nVersion < SWG_NEWFIELDS ) 293 { 294 switch( rFmt ) 295 { 296 case RF_AUTHOR: rSubType = DI_SUB_AUTHOR; break; 297 case RF_TIME: rSubType = DI_SUB_TIME; break; 298 case RF_DATE: rSubType = DI_SUB_DATE; break; 299 case RF_ALL: rSubType = DI_SUB_DATE; break; 300 } 301 rFmt = 0; 302 } 303 break; 304 } 305 306 if( pOldFmt ) 307 { 308 SvNumberFormatter *pFormatter = rDoc.GetNumberFormatter(); 309 sal_uInt16 i = 0; 310 311 while( pOldFmt[i].eFormatIdx != NF_NUMERIC_START || 312 pOldFmt[i].nOldFormat) 313 { 314 if( rFmt == pOldFmt[i].nOldFormat ) 315 { 316 rFmt = pFormatter->GetFormatIndex(pOldFmt[i].eFormatIdx, LANGUAGE_SYSTEM); 317 break; 318 } 319 i++; 320 } 321 } 322 } 323 SW_DLLPUBLIC void sw3io_ConvertToOldField( const SwField* pFld, sal_uInt16& rWhich, 324 sal_uLong& rFmt, sal_uLong nFFVersion ) 325 { 326 const OldFormats *pOldFmt = 0L; 327 sal_uLong nOldFmt = rFmt; 328 329 switch( rWhich ) 330 { 331 case RES_DOCINFOFLD: 332 if( SOFFICE_FILEFORMAT_40 >= nFFVersion ) 333 { 334 switch (pFld->GetSubType() & 0xff00) 335 { 336 case DI_SUB_AUTHOR: rFmt = RF_AUTHOR; break; 337 case DI_SUB_TIME: rFmt = RF_TIME; break; 338 case DI_SUB_DATE: rFmt = RF_DATE; break; 339 } 340 } 341 break; 342 343 case RES_DATETIMEFLD: 344 if( SOFFICE_FILEFORMAT_40 >= nFFVersion ) 345 { 346 sal_uInt16 nSubType = ((SwDateTimeField*) pFld)->GetSubType(); 347 switch( nSubType ) 348 { 349 case DATEFLD: rWhich = RES_DATEFLD; break; 350 case TIMEFLD: rWhich = RES_TIMEFLD; break; 351 case DATEFLD|FIXEDFLD: rWhich = RES_FIXDATEFLD; break; 352 case TIMEFLD|FIXEDFLD: rWhich = RES_FIXTIMEFLD; break; 353 } 354 355 if( nSubType & DATEFLD ) 356 { 357 rFmt = DFF_DMY; 358 pOldFmt = aOldDateFmt40; 359 } 360 else 361 { 362 rFmt = TF_SYSTEM; 363 pOldFmt = aOldTimeFmt; 364 } 365 } 366 break; 367 368 case RES_DBFLD: 369 case RES_TABLEFLD: 370 case RES_GETEXPFLD: 371 case RES_SETEXPFLD: 372 case RES_USERFLD: 373 if( SOFFICE_FILEFORMAT_40 >= nFFVersion ) 374 { 375 sal_uInt16 nSubType = pFld->GetSubType(); 376 377 if (nSubType & nsSwExtendedSubType::SUB_INVISIBLE) 378 rFmt = VVF_INVISIBLE; 379 else if (nSubType & nsSwExtendedSubType::SUB_CMD) 380 rFmt = VVF_CMD; 381 else if( !(nsSwGetSetExpType::GSE_SEQ & nSubType) ) 382 { 383 pOldFmt = aOldGetSetExpFmt40; 384 rFmt = VVF_SYS; 385 } 386 } 387 break; 388 389 case RES_GETREFFLD: 390 if( SOFFICE_FILEFORMAT_31 == nFFVersion ) 391 { 392 switch( rFmt ) 393 { 394 case REF_PAGE: 395 case REF_CHAPTER: 396 case REF_CONTENT: 397 break; 398 399 default: 400 // case REF_UPDOWN: 401 // case REF_PAGE_PGDESC: 402 rFmt = REF_PAGE; 403 break; 404 } 405 } 406 break; 407 } 408 409 if( pOldFmt && nOldFmt ) 410 { 411 sal_uInt16 i = 0; 412 413 SvNumberFormatter *pFormatter = ((SwValueField*)pFld)->GetDoc()->GetNumberFormatter(); 414 const SvNumberformat* pEntry = pFormatter->GetEntry( nOldFmt ); 415 416 if( pEntry ) 417 { 418 while( pOldFmt[i].eFormatIdx != NF_NUMERIC_START || 419 pOldFmt[i].nOldFormat ) 420 { 421 sal_uLong nKey = pFormatter->GetFormatIndex( 422 pOldFmt[i].eFormatIdx, pEntry->GetLanguage() ); 423 424 if( nOldFmt == nKey ) 425 { 426 rFmt = pOldFmt[i].nOldFormat; 427 break; 428 } 429 i++; 430 } 431 } 432 } 433 } 434