1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sw3convert.cxx,v $
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_sw.hxx"
39 #include "hintids.hxx"
40 #include <tools/resid.hxx>
41 #include <svtools/macitem.hxx>
42 #include <svtools/zforlist.hxx>
43 #include <svtools/zformat.hxx>
44 #include <svtools/urihelper.hxx>
45 #include <sfx2/linkmgr.hxx>
47 #ifndef _SVSTDARR_USHORTS_DECL
48 #define _SVSTDARR_USHORTS
49 #include <svtools/svstdarr.hxx>
51 #include <svx/lrspitem.hxx>
52 #include <svx/tstpitem.hxx>
53 #include <fmtinfmt.hxx>
60 #include "docufld.hxx"
70 //really used ids from old sw3ids.hxx
71 #define SWG_INETBROWSER 0x000e // URL-Grf-Nodes, Browse-Flag, Format-Ums.
72 #define SWG_NEWFIELDS 0x0200 // Felder mit Numberformatter-Zahlenformat
73 #define SWG_EXPORT40 0x0110 // Version fuer 4.0-Export ab 5.0
75 using namespace nsSwDocInfoSubType
;
78 //#include "poolfmt.hxx" // fuer InSetExpField
79 //#include "poolfmt.hrc" // fuer InSetExpField
81 //#if !defined(UNX) && !defined(MSC) && !defined(PPC) && !defined(CSET) && !defined(__MWERKS__) && !defined(WTC)
83 //#define FIELDFNTAB_SIZE 37
84 //#if FIELDFNTAB_SIZE != RES_FIELDS_END - RES_FIELDS_BEGIN
85 //#error Feld-Tabelle ist ungueltigt. Wurden neue Hint-IDs zugefuegt ??
90 //#define SWG_AUTHORITY_ENTRY_LCL 'E'
92 //sal_Char __FAR_DATA sSW3IO_FixedField[] = "FixedExport";
93 //sal_Char __FAR_DATA sSW3IO_AuthorityField[] = "AuthorityExport";
95 //sal_Char __FAR_DATA sSW3IO_DropDownField[] = "DropDownExport";
99 NfIndexTableOffset eFormatIdx
;
103 static OldFormats aOldDateFmt40
[] =
106 { NF_DATE_SYSTEM_SHORT
, DFF_SSYS
}, // Kurzes Systemdatum
107 { NF_DATE_SYSTEM_LONG
, DFF_LSYS
}, // Langes Systemdatum
108 { NF_DATE_SYS_DDMMYY
, DFF_DMY
}, // 06.10.64
109 { NF_DATE_SYS_DDMMYYYY
, DFF_DMYY
}, // 06.10.1964
110 { NF_DATE_SYS_DMMMYY
, DFF_DMMY
}, // 06. Okt 64
111 { NF_DATE_SYS_DMMMYYYY
, DFF_DMMYY
}, // 06. Okt 1964
112 { NF_DATE_DIN_DMMMMYYYY
, DFF_DMMMYY
}, // 06. Oktober 1964
113 { NF_DATE_DIN_DMMMMYYYY
, DFF_DMMMY
}, // 06. Oktober 64
114 { NF_DATE_SYS_NNDMMMYY
, DFF_DDMMY
}, // Di, 06. Okt 64
115 { NF_DATE_SYS_NNDMMMMYYYY
, DFF_DDMMMY
}, // Di, 06. Oktober 64
116 { NF_DATE_SYS_NNDMMMMYYYY
, DFF_DDMMMYY
}, // Di, 06. Oktober 1964
117 { NF_DATE_SYS_NNNNDMMMMYYYY
, DFF_DDDMMMYY
}, // Dienstag, 06. Oktober 1964
118 { NF_DATE_SYS_NNNNDMMMMYYYY
, DFF_DDDMMMY
}, // Dienstag, 06. Oktober 64
119 { NF_DATE_SYS_MMYY
, DFF_MY
}, // 10.64
120 { NF_DATE_DIN_MMDD
, DFF_MD
}, // 10-06
121 { NF_DATE_DIN_YYMMDD
, DFF_YMD
}, // 64-10-06
122 { NF_DATE_DIN_YYYYMMDD
, DFF_YYMD
}, // 1964-10-06
124 { NF_NUMERIC_START
, 0 } // Tabellenende
127 static OldFormats aOldDateFmt30
[] =
130 { NF_DATE_SYSTEM_SHORT
, DFF_SSYS
}, // Kurzes Systemdatum
131 { NF_DATE_SYSTEM_LONG
, DFF_LSYS
}, // Langes Systemdatum
132 { NF_DATE_SYS_DDMMYY
, DFF_DMY
}, // 06.10.64
133 { NF_DATE_SYS_DDMMYYYY
, DFF_DMYY
}, // 06.10.1964
134 { NF_DATE_SYS_DMMMYY
, DFF_DMMY
}, // 06. Okt 64
135 { NF_DATE_SYS_DMMMYYYY
, 4 /*DFF_DMMYY*/ }, // 06. Okt 1964
136 { NF_DATE_DIN_DMMMMYYYY
, 5 /*DFF_DMMMYY*/ }, // 06. Oktober 1964
137 { NF_DATE_DIN_DMMMMYYYY
, 5 /*DFF_DMMMY*/ }, // 06. Oktober 64
138 { NF_DATE_SYS_NNDMMMMYYYY
, 6 /*DFF_DDMMMYY*/ }, // Di, 06. Oktober 1964
139 { NF_DATE_SYS_NNDMMMYY
, 6 /*DFF_DDMMY*/ }, // Di, 06. Okt 64
140 { NF_DATE_SYS_NNDMMMMYYYY
, 6 /*DFF_DDMMMY*/ }, // Di, 06. Oktober 64
141 { NF_DATE_SYS_NNNNDMMMMYYYY
, 7 /*DFF_DDDMMMYY*/ }, // Dienstag, 06. Oktober 1964
142 { NF_DATE_SYS_NNNNDMMMMYYYY
, 7 /*DFF_DDDMMMY*/ }, // Dienstag, 06. Oktober 64
143 { NF_DATE_SYS_MMYY
, 2 /*DFF_MY*/ }, // 10.64
144 { NF_DATE_DIN_MMDD
, DFF_MD
}, // 10-06
145 { NF_DATE_DIN_YYMMDD
, DFF_YMD
}, // 64-10-06
146 { NF_DATE_DIN_YYYYMMDD
, DFF_YYMD
}, // 1964-10-06
148 { NF_NUMERIC_START
, 0 } // Tabellenende
151 static OldFormats aOldTimeFmt
[] =
154 { NF_TIME_HHMMSS
, TF_SYSTEM
}, // Systemzeit
155 { NF_TIME_HHMM
, TF_SSMM_24
}, // 23:25
156 { NF_TIME_HHMMAMPM
, TF_SSMM_12
}, // 11:25 PM
158 { NF_NUMERIC_START
, 0 } // Tabellenende
161 static OldFormats aOldGetSetExpFmt40
[] =
163 { NF_TEXT
, VVF_CMD
}, // Kommando anzeigen
164 { NF_TEXT
, VVF_INVISIBLE
}, // unsichtbar
165 { NF_PERCENT_INT
, VVF_XXP
}, // 1234%
166 { NF_PERCENT_DEC2
, VVF_XX_XXP
}, // 1.234,56%
167 { NF_TEXT
, VVF_CLEAR
}, // ???
169 { NF_NUMBER_SYSTEM
, VVF_SYS
}, // Zahlenformat aus der
171 { NF_NUMBER_INT
, VVF_X
}, // 1234
172 { NF_NUMBER_DEC2
, VVF_X_X
}, // 1234,5
173 { NF_NUMBER_DEC2
, VVF_X_XX
}, // 1245,56
174 { NF_NUMBER_1000DEC2
, VVF_XX_XX
}, // 1.234,56
175 { NF_NUMBER_1000DEC2
, VVF_XX_X
}, // 1.234,5
176 { NF_NUMBER_1000DEC2
, VVF_XX_XXX
}, // 1.234,567
177 { NF_CURRENCY_1000DEC2
, VVF_SYS_CUR
}, // W?hrungsformat aus der
180 { NF_CURRENCY_1000INT
, VVF_X_CUR
}, // 1234 DM
181 { NF_CURRENCY_1000DEC2
, VVF_XX_XX_CUR
}, // 1234,56 DM 1234,00 DM
182 { NF_CURRENCY_1000DEC2_DASHED
, VVF_XX_X0_CUR
}, // 1234,56 DM 1234,-- DM
183 { NF_CURRENCY_1000INT
, VVF_CUR_X
}, // DM 1234
184 { NF_CURRENCY_1000DEC2
, VVF_CUR_XX_XX
}, // DM 1234,56 DM 1234,00
185 { NF_CURRENCY_1000DEC2_DASHED
, VVF_CUR_XX_X0
}, // DM 1234,56 DM 1234,--
187 { NF_NUMERIC_START
, 0 } // Tabellenende
190 static OldFormats aOldGetSetExpFmt30
[] =
192 { NF_TEXT
, VVF_CMD
}, // Kommando anzeigen
193 { NF_TEXT
, VVF_INVISIBLE
}, // unsichtbar
194 { NF_PERCENT_INT
, VVF_XXP
}, // 1234%
195 { NF_PERCENT_DEC2
, VVF_XX_XXP
}, // 1.234,56%
196 { NF_TEXT
, VVF_CLEAR
}, // ???
198 { NF_NUMBER_SYSTEM
, 0x0020 }, // Zahlenformat aus der
200 { NF_NUMBER_INT
, 0x0080 }, // 1234
201 { NF_NUMBER_1000DEC2
, 0x0100 }, // 1.234,56
202 { NF_NUMBER_DEC2
, 0x0100 }, // 1234,5
203 { NF_NUMBER_DEC2
, 0x0100 }, // 1245,56
204 { NF_NUMBER_1000DEC2
, 0x0100 }, // 1.234,5
205 { NF_NUMBER_1000DEC2
, 0x0100 }, // 1.234,567
206 { NF_CURRENCY_1000DEC2
, 0x0200 }, // W?hrungsformat aus der
209 { NF_CURRENCY_1000INT
, 0x1000 }, // 1234 DM
210 { NF_CURRENCY_1000DEC2
, 0x1000 }, // 1234,56 DM 1234,00 DM
211 { NF_CURRENCY_1000DEC2_DASHED
, 0x1000 }, // 1234,56 DM 1234,-- DM
212 { NF_CURRENCY_1000INT
, 0x1000 }, // DM 1234
213 { NF_CURRENCY_1000DEC2
, 0x1000 }, // DM 1234,56 DM 1234,00
214 { NF_CURRENCY_1000DEC2_DASHED
, 0x1000 }, // DM 1234,56 DM 1234,--
216 { NF_NUMERIC_START
, 0 } // Tabellenende
219 SW_DLLPUBLIC
void sw3io_ConvertFromOldField( SwDoc
& rDoc
, USHORT
& rWhich
,
220 USHORT
& rSubType
, ULONG
&rFmt
,
223 const OldFormats
*pOldFmt
= 0L;
229 if( nVersion
< SWG_NEWFIELDS
)
232 if( RES_FIXDATEFLD
== rWhich
)
233 rSubType
|= FIXEDFLD
;
234 rWhich
= RES_DATETIMEFLD
;
235 pOldFmt
= nVersion
<SWG_INETBROWSER
? aOldDateFmt30
242 if( nVersion
< SWG_NEWFIELDS
)
245 if( RES_FIXTIMEFLD
== rWhich
)
246 rSubType
|= FIXEDFLD
;
247 rWhich
= RES_DATETIMEFLD
;
248 pOldFmt
= aOldTimeFmt
;
253 if( nVersion
< SWG_NEWFIELDS
)
255 rSubType
= nsSwExtendedSubType::SUB_OWN_FMT
;
256 pOldFmt
= nVersion
<SWG_INETBROWSER
? aOldGetSetExpFmt30
257 : aOldGetSetExpFmt40
;
265 if( nVersion
< SWG_NEWFIELDS
)
267 if( rFmt
== VVF_INVISIBLE
)
269 rSubType
= nsSwExtendedSubType::SUB_INVISIBLE
;
272 else if( rFmt
== VVF_CMD
)
274 rSubType
= nsSwExtendedSubType::SUB_CMD
;
279 // Kleiner Hack: Bei Numernkreisen wird das
280 // unkonvertierte Format noch benoetigt. Wir merken es
281 // uns voruebergehend mal im Subtyp, sofern es
282 // ueberhaupt als entsprechendes Format in Frage kommt.
283 if( RES_SETEXPFLD
==rWhich
&&
284 /*rFmt >= (USHORT)SVX_NUM_CHARS_UPPER_LETTER && always true*/
285 rFmt
<= (USHORT
)SVX_NUM_BITMAP
)
287 rSubType
= (USHORT
)rFmt
;
289 pOldFmt
= nVersion
<SWG_INETBROWSER
? aOldGetSetExpFmt30
290 : aOldGetSetExpFmt40
;
295 if( nVersion
< SWG_NEWFIELDS
)
299 case RF_AUTHOR
: rSubType
= DI_SUB_AUTHOR
; break;
300 case RF_TIME
: rSubType
= DI_SUB_TIME
; break;
301 case RF_DATE
: rSubType
= DI_SUB_DATE
; break;
302 case RF_ALL
: rSubType
= DI_SUB_DATE
; break;
311 SvNumberFormatter
*pFormatter
= rDoc
.GetNumberFormatter();
314 while( pOldFmt
[i
].eFormatIdx
!= NF_NUMERIC_START
||
315 pOldFmt
[i
].nOldFormat
)
317 if( rFmt
== pOldFmt
[i
].nOldFormat
)
319 rFmt
= pFormatter
->GetFormatIndex(pOldFmt
[i
].eFormatIdx
, LANGUAGE_SYSTEM
);
326 SW_DLLPUBLIC
void sw3io_ConvertToOldField( const SwField
* pFld
, USHORT
& rWhich
,
327 ULONG
& rFmt
, ULONG nFFVersion
)
329 const OldFormats
*pOldFmt
= 0L;
330 ULONG nOldFmt
= rFmt
;
335 if( SOFFICE_FILEFORMAT_40
>= nFFVersion
)
337 switch (pFld
->GetSubType() & 0xff00)
339 case DI_SUB_AUTHOR
: rFmt
= RF_AUTHOR
; break;
340 case DI_SUB_TIME
: rFmt
= RF_TIME
; break;
341 case DI_SUB_DATE
: rFmt
= RF_DATE
; break;
346 case RES_DATETIMEFLD
:
347 if( SOFFICE_FILEFORMAT_40
>= nFFVersion
)
349 USHORT nSubType
= ((SwDateTimeField
*) pFld
)->GetSubType();
352 case DATEFLD
: rWhich
= RES_DATEFLD
; break;
353 case TIMEFLD
: rWhich
= RES_TIMEFLD
; break;
354 case DATEFLD
|FIXEDFLD
: rWhich
= RES_FIXDATEFLD
; break;
355 case TIMEFLD
|FIXEDFLD
: rWhich
= RES_FIXTIMEFLD
; break;
358 if( nSubType
& DATEFLD
)
361 pOldFmt
= aOldDateFmt40
;
366 pOldFmt
= aOldTimeFmt
;
376 if( SOFFICE_FILEFORMAT_40
>= nFFVersion
)
378 USHORT nSubType
= pFld
->GetSubType();
380 if (nSubType
& nsSwExtendedSubType::SUB_INVISIBLE
)
381 rFmt
= VVF_INVISIBLE
;
382 else if (nSubType
& nsSwExtendedSubType::SUB_CMD
)
384 else if( !(nsSwGetSetExpType::GSE_SEQ
& nSubType
) )
386 pOldFmt
= aOldGetSetExpFmt40
;
393 if( SOFFICE_FILEFORMAT_31
== nFFVersion
)
404 // case REF_PAGE_PGDESC:
412 if( pOldFmt
&& nOldFmt
)
416 SvNumberFormatter
*pFormatter
= ((SwValueField
*)pFld
)->GetDoc()->GetNumberFormatter();
417 const SvNumberformat
* pEntry
= pFormatter
->GetEntry( nOldFmt
);
421 while( pOldFmt
[i
].eFormatIdx
!= NF_NUMERIC_START
||
422 pOldFmt
[i
].nOldFormat
)
424 ULONG nKey
= pFormatter
->GetFormatIndex(
425 pOldFmt
[i
].eFormatIdx
, pEntry
->GetLanguage() );
427 if( nOldFmt
== nKey
)
429 rFmt
= pOldFmt
[i
].nOldFormat
;