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