Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <string.h>
21 : #include <hintids.hxx>
22 : #include <i18nlangtag/lang.h>
23 : #include <i18nlangtag/languagetag.hxx>
24 : #include <vcl/msgbox.hxx>
25 : #include <svtools/parhtml.hxx>
26 : #include <sot/storage.hxx>
27 : #include <comphelper/classids.hxx>
28 : #include <sfx2/app.hxx>
29 : #include <sfx2/docfilt.hxx>
30 : #include <sfx2/fcontnr.hxx>
31 : #include <sfx2/docfile.hxx>
32 : #include <editeng/lrspitem.hxx>
33 : #include <editeng/tstpitem.hxx>
34 : #include <doc.hxx>
35 : #include <docary.hxx>
36 : #include <pam.hxx>
37 : #include <shellio.hxx>
38 : #include <docsh.hxx>
39 : #include <wdocsh.hxx>
40 : #include <fltini.hxx>
41 : #include <hints.hxx>
42 : #include <init.hxx>
43 : #include <frmatr.hxx>
44 : #include <fmtfsize.hxx>
45 : #include <swtable.hxx>
46 : #include <fmtcntnt.hxx>
47 : #include <editeng/boxitem.hxx>
48 : #include <frmfmt.hxx>
49 : #include <numrule.hxx>
50 : #include <ndtxt.hxx>
51 : #include <swfltopt.hxx>
52 : #include <swerror.h>
53 : #include <swdll.hxx>
54 : #include <osl/module.hxx>
55 : #include <comphelper/processfactory.hxx>
56 : #include <com/sun/star/beans/XPropertySet.hpp>
57 : #include <com/sun/star/util/XMacroExpander.hpp>
58 : #include <rtl/bootstrap.hxx>
59 :
60 : using namespace utl;
61 : using namespace com::sun::star::uno;
62 : using namespace com::sun::star;
63 :
64 : SwRead ReadAscii = 0, ReadHTML = 0, ReadXML = 0;
65 :
66 : Reader* GetRTFReader();
67 : Reader* GetWW8Reader();
68 :
69 : // Note: if editing, please don't forget to modify also the enum
70 : // ReaderWriterEnum and aFilterDetect in shellio.hxx
71 59 : SwReaderWriterEntry aReaderWriter[] =
72 : {
73 : SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, true ),
74 : SwReaderWriterEntry( 0, &::GetASCWriter, false ),
75 : SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer, true ),
76 : SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer, true ),
77 : SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, true ),
78 : SwReaderWriterEntry( 0, &::GetHTMLWriter, true ),
79 : SwReaderWriterEntry( &::GetWW8Reader, 0, true ),
80 : SwReaderWriterEntry( 0, &::GetXMLWriter, true ),
81 : SwReaderWriterEntry( 0, &::GetASCWriter, false ),
82 : SwReaderWriterEntry( 0, &::GetASCWriter, true )
83 59 : };
84 :
85 149 : Reader* SwReaderWriterEntry::GetReader()
86 : {
87 149 : if ( pReader )
88 139 : return pReader;
89 10 : else if ( fnGetReader )
90 : {
91 10 : pReader = (*fnGetReader)();
92 10 : return pReader;
93 : }
94 0 : return NULL;
95 : }
96 :
97 8124 : void SwReaderWriterEntry::GetWriter( const OUString& rNm, const OUString& rBaseURL, WriterRef& xWrt ) const
98 : {
99 8124 : if ( fnGetWriter )
100 8124 : (*fnGetWriter)( rNm, rBaseURL, xWrt );
101 : else
102 0 : xWrt = WriterRef(0);
103 8124 : }
104 :
105 0 : SwRead SwGetReaderXML() // SW_DLLPUBLIC
106 : {
107 0 : return ReadXML;
108 : }
109 :
110 295 : inline void _SetFltPtr( sal_uInt16 rPos, SwRead pReader )
111 : {
112 295 : aReaderWriter[ rPos ].pReader = pReader;
113 295 : }
114 :
115 : namespace sw {
116 :
117 59 : Filters::Filters()
118 : {
119 59 : _SetFltPtr( READER_WRITER_BAS, (ReadAscii = new AsciiReader) );
120 59 : _SetFltPtr( READER_WRITER_HTML, (ReadHTML = new HTMLReader) );
121 59 : _SetFltPtr( READER_WRITER_XML, (ReadXML = new XMLReader) );
122 59 : _SetFltPtr( READER_WRITER_TEXT_DLG, ReadAscii );
123 59 : _SetFltPtr( READER_WRITER_TEXT, ReadAscii );
124 59 : }
125 :
126 118 : Filters::~Filters()
127 : {
128 : // kill Readers
129 649 : for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
130 : {
131 590 : SwReaderWriterEntry& rEntry = aReaderWriter[n];
132 590 : if( rEntry.bDelReader && rEntry.pReader )
133 187 : delete rEntry.pReader, rEntry.pReader = NULL;
134 : }
135 59 : }
136 :
137 : #ifndef DISABLE_DYNLOADING
138 :
139 43 : oslGenericFunction Filters::GetMswordLibSymbol( const char *pSymbol )
140 : {
141 43 : if (!msword_.is())
142 : {
143 9 : OUString url("$LO_LIB_DIR/" SVLIBRARY("msword"));
144 9 : rtl::Bootstrap::expandMacros(url);
145 9 : bool ok = msword_.load( url, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY );
146 9 : SAL_WARN_IF(!ok, "sw", "failed to load msword library");
147 : }
148 43 : if (msword_.is())
149 43 : return msword_.getFunctionSymbol( OUString::createFromAscii( pSymbol ) );
150 0 : return NULL;
151 : }
152 :
153 : #endif
154 :
155 : }
156 :
157 : namespace SwReaderWriter {
158 :
159 1 : Reader* GetReader( ReaderWriterEnum eReader )
160 : {
161 1 : return aReaderWriter[eReader].GetReader();
162 : }
163 :
164 8124 : void GetWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
165 : {
166 72905 : for( int n = 0; n < MAXFILTER; ++n )
167 72905 : if ( aFilterDetect[n].IsFilter( rFltName ) )
168 : {
169 8124 : aReaderWriter[n].GetWriter( rFltName, rBaseURL, xRet );
170 8124 : break;
171 : }
172 8124 : }
173 :
174 148 : SwRead GetReader( const OUString& rFltName )
175 : {
176 148 : SwRead pRead = 0;
177 651 : for( int n = 0; n < MAXFILTER; ++n )
178 : {
179 651 : if ( aFilterDetect[n].IsFilter( rFltName ) )
180 : {
181 148 : pRead = aReaderWriter[n].GetReader();
182 : // add special treatment for some readers
183 148 : if ( pRead )
184 148 : pRead->SetFltName( rFltName );
185 148 : break;
186 : }
187 : }
188 148 : return pRead;
189 : }
190 :
191 : } // namespace SwReaderWriter
192 :
193 8108 : bool Writer::IsStgWriter() const { return false; }
194 :
195 134 : bool StgWriter::IsStgWriter() const { return true; }
196 :
197 : // Read Filter Flags; used by WW8 / W4W / EXCEL / LOTUS
198 :
199 : /*
200 : <FilterFlags>
201 : <Excel_Lotus>
202 : <MinRow cfg:type="long">0</MinRow>
203 : <MaxRow cfg:type="long">0</MaxRow>
204 : <MinCol cfg:type="long">0</MinCol>
205 : <MaxCol cfg:type="long">0</MaxCol>
206 : </Excel_Lotus>
207 : <W4W>
208 : <W4WHD cfg:type="long">0</W4WHD>
209 : <W4WFT cfg:type="long">0</W4WFT>
210 : <W4W000 cfg:type="long">0</W4W000>
211 : </W4W>
212 : <WinWord>
213 : <WW1F cfg:type="long">0</WW1F>
214 : <WW cfg:type="long">0</WW>
215 : <WW8 cfg:type="long">0</WW8>
216 : <WWF cfg:type="long">0</WWF>
217 : <WWFA0 cfg:type="long">0</WWFA0>
218 : <WWFA1 cfg:type="long">0</WWFA1>
219 : <WWFA2 cfg:type="long">0</WWFA2>
220 : <WWFB0 cfg:type="long">0</WWFB0>
221 : <WWFB1 cfg:type="long">0</WWFB1>
222 : <WWFB2 cfg:type="long">0</WWFB2>
223 : <WWFLX cfg:type="long">0</WWFLX>
224 : <WWFLY cfg:type="long">0</WWFLY>
225 : <WWFT cfg:type="long">0</WWFT>
226 : <WWWR cfg:type="long">0</WWWR>
227 : </WinWord>
228 : <Writer>
229 : <SW3Imp cfg:type="long">0</SW3Imp>
230 : </Writer>
231 : </FilterFlags>
232 : */
233 :
234 : #define FILTER_OPTION_ROOT OUString("Office.Writer/FilterFlags")
235 :
236 127 : SwFilterOptions::SwFilterOptions( sal_uInt16 nCnt, const sal_Char** ppNames,
237 : sal_uInt32* pValues )
238 127 : : ConfigItem( FILTER_OPTION_ROOT )
239 : {
240 127 : GetValues( nCnt, ppNames, pValues );
241 127 : }
242 :
243 127 : void SwFilterOptions::GetValues( sal_uInt16 nCnt, const sal_Char** ppNames,
244 : sal_uInt32* pValues )
245 : {
246 127 : Sequence<OUString> aNames( nCnt );
247 127 : OUString* pNames = aNames.getArray();
248 : sal_uInt16 n;
249 :
250 1778 : for( n = 0; n < nCnt; ++n )
251 1651 : pNames[ n ] = OUString::createFromAscii( ppNames[ n ] );
252 254 : Sequence<Any> aValues = GetProperties( aNames );
253 :
254 127 : if( nCnt == aValues.getLength() )
255 : {
256 127 : const Any* pAnyValues = aValues.getConstArray();
257 1778 : for( n = 0; n < nCnt; ++n )
258 1651 : pValues[ n ] = pAnyValues[ n ].hasValue()
259 1651 : ? *static_cast<sal_uInt32 const *>(pAnyValues[ n ].getValue())
260 3302 : : 0;
261 : }
262 : else
263 : {
264 0 : for( n = 0; n < nCnt; ++n )
265 0 : pValues[ n ] = 0;
266 127 : }
267 127 : }
268 :
269 0 : void SwFilterOptions::ImplCommit() {}
270 0 : void SwFilterOptions::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
271 :
272 128 : void StgReader::SetFltName( const OUString& rFltNm )
273 : {
274 128 : if( SW_STORAGE_READER & GetReaderType() )
275 128 : aFltName = rFltNm;
276 128 : }
277 :
278 125 : SwRelNumRuleSpaces::SwRelNumRuleSpaces( SwDoc& rDoc, bool bNDoc )
279 : {
280 125 : pNumRuleTable = new SwNumRuleTable();
281 125 : pNumRuleTable->reserve(8);
282 125 : if( !bNDoc )
283 : pNumRuleTable->insert( pNumRuleTable->begin(),
284 0 : rDoc.GetNumRuleTable().begin(), rDoc.GetNumRuleTable().end() );
285 125 : }
286 :
287 125 : SwRelNumRuleSpaces::~SwRelNumRuleSpaces()
288 : {
289 125 : if( pNumRuleTable )
290 : {
291 125 : pNumRuleTable->clear();
292 125 : delete pNumRuleTable;
293 : }
294 125 : }
295 :
296 3 : void CalculateFlySize(SfxItemSet& rFlySet, const SwNodeIndex& rAnchor,
297 : SwTwips nPageWidth)
298 : {
299 3 : const SfxPoolItem* pItem = 0;
300 3 : if( SfxItemState::SET != rFlySet.GetItemState( RES_FRM_SIZE, true, &pItem ) ||
301 0 : MINFLY > static_cast<const SwFormatFrmSize*>(pItem)->GetWidth() )
302 : {
303 3 : SwFormatFrmSize aSz(static_cast<const SwFormatFrmSize&>(rFlySet.Get(RES_FRM_SIZE, true)));
304 3 : if (pItem)
305 0 : aSz = static_cast<const SwFormatFrmSize&>(*pItem);
306 :
307 : SwTwips nWidth;
308 : // determine the width; if there is a table use the width of the table;
309 : // otherwise use the width of the page
310 3 : const SwTableNode* pTableNd = rAnchor.GetNode().FindTableNode();
311 3 : if( pTableNd )
312 0 : nWidth = pTableNd->GetTable().GetFrameFormat()->GetFrmSize().GetWidth();
313 : else
314 3 : nWidth = nPageWidth;
315 :
316 3 : const SwNodeIndex* pSttNd = static_cast<const SwFormatContent&>(rFlySet.Get( RES_CNTNT )).
317 3 : GetContentIdx();
318 3 : if( pSttNd )
319 : {
320 3 : bool bOnlyOneNode = true;
321 3 : sal_uLong nMinFrm = 0;
322 3 : sal_uLong nMaxFrm = 0;
323 3 : SwTextNode* pFirstTextNd = 0;
324 3 : SwNodeIndex aIdx( *pSttNd, 1 );
325 6 : SwNodeIndex aEnd( *pSttNd->GetNode().EndOfSectionNode() );
326 9 : while( aIdx < aEnd )
327 : {
328 3 : SwTextNode *pTextNd = aIdx.GetNode().GetTextNode();
329 3 : if( pTextNd )
330 : {
331 3 : if( !pFirstTextNd )
332 3 : pFirstTextNd = pTextNd;
333 0 : else if( pFirstTextNd != pTextNd )
334 : {
335 : // forget it
336 0 : bOnlyOneNode = false;
337 0 : break;
338 : }
339 :
340 : sal_uLong nAbsMinCnts;
341 3 : pTextNd->GetMinMaxSize( aIdx.GetIndex(), nMinFrm, nMaxFrm, nAbsMinCnts );
342 : }
343 3 : ++aIdx;
344 : }
345 :
346 3 : if( bOnlyOneNode )
347 : {
348 3 : if( nMinFrm < MINLAY && pFirstTextNd )
349 : {
350 : // if the first node dont contained any content, then
351 : // insert one char in it calc again and delete once again
352 0 : SwIndex aNdIdx( pFirstTextNd );
353 0 : pFirstTextNd->InsertText(OUString("MM"), aNdIdx);
354 : sal_uLong nAbsMinCnts;
355 : pFirstTextNd->GetMinMaxSize( pFirstTextNd->GetIndex(),
356 0 : nMinFrm, nMaxFrm, nAbsMinCnts );
357 0 : aNdIdx -= 2;
358 0 : pFirstTextNd->EraseText( aNdIdx, 2 );
359 : }
360 :
361 : // consider border and distance to content
362 3 : const SvxBoxItem& rBoxItem = static_cast<const SvxBoxItem&>(rFlySet.Get( RES_BOX ));
363 3 : SvxBoxItemLine nLine = SvxBoxItemLine::LEFT;
364 9 : for( int i = 0; i < 2; ++i )
365 : {
366 6 : const editeng::SvxBorderLine* pLn = rBoxItem.GetLine( nLine );
367 6 : if( pLn )
368 : {
369 0 : sal_uInt16 nWidthTmp = pLn->GetOutWidth() + pLn->GetInWidth();
370 0 : nWidthTmp = nWidthTmp + rBoxItem.GetDistance( nLine );
371 0 : nMinFrm += nWidthTmp;
372 0 : nMaxFrm += nWidthTmp;
373 : }
374 6 : nLine = SvxBoxItemLine::RIGHT;
375 : }
376 :
377 : // enforce minimum width for contents
378 3 : if( nMinFrm < MINLAY )
379 0 : nMinFrm = MINLAY;
380 3 : if( nMaxFrm < MINLAY )
381 0 : nMaxFrm = MINLAY;
382 :
383 3 : if( nWidth > (sal_uInt16)nMaxFrm )
384 3 : nWidth = nMaxFrm;
385 0 : else if( nWidth > (sal_uInt16)nMinFrm )
386 0 : nWidth = nMinFrm;
387 3 : }
388 : }
389 :
390 3 : if( MINFLY > nWidth )
391 0 : nWidth = MINFLY;
392 :
393 3 : aSz.SetWidth( nWidth );
394 3 : if( MINFLY > aSz.GetHeight() )
395 3 : aSz.SetHeight( MINFLY );
396 3 : rFlySet.Put( aSz );
397 : }
398 0 : else if( MINFLY > static_cast<const SwFormatFrmSize*>(pItem)->GetHeight() )
399 : {
400 0 : SwFormatFrmSize aSz( *static_cast<const SwFormatFrmSize*>(pItem) );
401 0 : aSz.SetHeight( MINFLY );
402 0 : rFlySet.Put( aSz );
403 : }
404 3 : }
405 :
406 : namespace
407 : {
408 :
409 : struct CharSetNameMap
410 : {
411 : rtl_TextEncoding eCode;
412 : const sal_Char* pName;
413 : };
414 :
415 3 : const CharSetNameMap *GetCharSetNameMap()
416 : {
417 : static const CharSetNameMap aMapArr[] =
418 : {
419 : # define IMPLENTRY(X) { RTL_TEXTENCODING_##X, #X }
420 : IMPLENTRY(DONTKNOW),
421 : IMPLENTRY(MS_1252),
422 : IMPLENTRY(APPLE_ROMAN),
423 : IMPLENTRY(IBM_437),
424 : IMPLENTRY(IBM_850),
425 : IMPLENTRY(IBM_860),
426 : IMPLENTRY(IBM_861),
427 : IMPLENTRY(IBM_863),
428 : IMPLENTRY(IBM_865),
429 : IMPLENTRY(SYMBOL),
430 : IMPLENTRY(ASCII_US),
431 : IMPLENTRY(ISO_8859_1),
432 : IMPLENTRY(ISO_8859_2),
433 : IMPLENTRY(ISO_8859_3),
434 : IMPLENTRY(ISO_8859_4),
435 : IMPLENTRY(ISO_8859_5),
436 : IMPLENTRY(ISO_8859_6),
437 : IMPLENTRY(ISO_8859_7),
438 : IMPLENTRY(ISO_8859_8),
439 : IMPLENTRY(ISO_8859_9),
440 : IMPLENTRY(ISO_8859_14),
441 : IMPLENTRY(ISO_8859_15),
442 : IMPLENTRY(IBM_737),
443 : IMPLENTRY(IBM_775),
444 : IMPLENTRY(IBM_852),
445 : IMPLENTRY(IBM_855),
446 : IMPLENTRY(IBM_857),
447 : IMPLENTRY(IBM_862),
448 : IMPLENTRY(IBM_864),
449 : IMPLENTRY(IBM_866),
450 : IMPLENTRY(IBM_869),
451 : IMPLENTRY(MS_874),
452 : IMPLENTRY(MS_1250),
453 : IMPLENTRY(MS_1251),
454 : IMPLENTRY(MS_1253),
455 : IMPLENTRY(MS_1254),
456 : IMPLENTRY(MS_1255),
457 : IMPLENTRY(MS_1256),
458 : IMPLENTRY(MS_1257),
459 : IMPLENTRY(MS_1258),
460 : IMPLENTRY(APPLE_ARABIC),
461 : IMPLENTRY(APPLE_CENTEURO),
462 : IMPLENTRY(APPLE_CROATIAN),
463 : IMPLENTRY(APPLE_CYRILLIC),
464 : IMPLENTRY(APPLE_DEVANAGARI),
465 : IMPLENTRY(APPLE_FARSI),
466 : IMPLENTRY(APPLE_GREEK),
467 : IMPLENTRY(APPLE_GUJARATI),
468 : IMPLENTRY(APPLE_GURMUKHI),
469 : IMPLENTRY(APPLE_HEBREW),
470 : IMPLENTRY(APPLE_ICELAND),
471 : IMPLENTRY(APPLE_ROMANIAN),
472 : IMPLENTRY(APPLE_THAI),
473 : IMPLENTRY(APPLE_TURKISH),
474 : IMPLENTRY(APPLE_UKRAINIAN),
475 : IMPLENTRY(APPLE_CHINSIMP),
476 : IMPLENTRY(APPLE_CHINTRAD),
477 : IMPLENTRY(APPLE_JAPANESE),
478 : IMPLENTRY(APPLE_KOREAN),
479 : IMPLENTRY(MS_932),
480 : IMPLENTRY(MS_936),
481 : IMPLENTRY(MS_949),
482 : IMPLENTRY(MS_950),
483 : IMPLENTRY(SHIFT_JIS),
484 : IMPLENTRY(GB_2312),
485 : IMPLENTRY(GBT_12345),
486 : IMPLENTRY(GBK),
487 : IMPLENTRY(BIG5),
488 : IMPLENTRY(EUC_JP),
489 : IMPLENTRY(EUC_CN),
490 : IMPLENTRY(EUC_TW),
491 : IMPLENTRY(ISO_2022_JP),
492 : IMPLENTRY(ISO_2022_CN),
493 : IMPLENTRY(KOI8_R),
494 : IMPLENTRY(KOI8_U),
495 : IMPLENTRY(UTF7),
496 : IMPLENTRY(UTF8),
497 : IMPLENTRY(ISO_8859_10),
498 : IMPLENTRY(ISO_8859_13),
499 : IMPLENTRY(EUC_KR),
500 : IMPLENTRY(ISO_2022_KR),
501 : IMPLENTRY(JIS_X_0201),
502 : IMPLENTRY(JIS_X_0208),
503 : IMPLENTRY(JIS_X_0212),
504 : IMPLENTRY(MS_1361),
505 : IMPLENTRY(GB_18030),
506 : IMPLENTRY(BIG5_HKSCS),
507 : IMPLENTRY(TIS_620),
508 : IMPLENTRY(PT154),
509 : IMPLENTRY(UCS4),
510 : IMPLENTRY(UCS2),
511 : IMPLENTRY(UNICODE),
512 : {0,0} //Last
513 : };
514 3 : return &aMapArr[0];
515 : }
516 :
517 : /*
518 : Get a rtl_TextEncoding from its name
519 : */
520 3 : rtl_TextEncoding CharSetFromName(const OUString& rChrSetStr)
521 : {
522 3 : const CharSetNameMap *pStart = GetCharSetNameMap();
523 3 : rtl_TextEncoding nRet = pStart->eCode;
524 :
525 231 : for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
526 : {
527 231 : if(rChrSetStr.equalsIgnoreAsciiCaseAscii(pMap->pName))
528 : {
529 3 : nRet = pMap->eCode;
530 3 : break;
531 : }
532 : }
533 :
534 : OSL_ENSURE(nRet != pStart->eCode, "TXT: That was an unknown language!");
535 :
536 3 : return nRet;
537 : }
538 :
539 : /*
540 : Get the String name of an rtl_TextEncoding
541 : */
542 0 : OUString NameFromCharSet(rtl_TextEncoding nChrSet)
543 : {
544 0 : const CharSetNameMap *pStart = GetCharSetNameMap();
545 0 : const char *pRet = pStart->pName;
546 :
547 0 : for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
548 : {
549 0 : if (nChrSet == pMap->eCode)
550 : {
551 0 : pRet = pMap->pName;
552 0 : break;
553 : }
554 : }
555 :
556 : OSL_ENSURE(pRet != pStart->pName, "TXT: That was an unknown language!");
557 :
558 0 : return OUString::createFromAscii(pRet);
559 : }
560 :
561 : }
562 :
563 : // for the automatic conversion (mail/news/...)
564 : // The user data contains the options for the ascii import/export filter.
565 : // The format is:
566 : // 1. CharSet - as ascii chars
567 : // 2. LineEnd - as CR/LR/CRLF
568 : // 3. Fontname
569 : // 4. Language
570 : // the delimiter character is ","
571 :
572 3 : void SwAsciiOptions::ReadUserData( const OUString& rStr )
573 : {
574 3 : sal_Int32 nToken = 0;
575 3 : int nCnt = 0;
576 12 : do {
577 12 : const OUString sToken = rStr.getToken( 0, ',', nToken );
578 12 : if (!sToken.isEmpty())
579 : {
580 12 : switch( nCnt )
581 : {
582 : case 0: // CharSet
583 3 : eCharSet = CharSetFromName(sToken);
584 3 : break;
585 : case 1: // LineEnd
586 3 : if (sToken.equalsIgnoreAsciiCase("CRLF"))
587 0 : eCRLF_Flag = LINEEND_CRLF;
588 3 : else if (sToken.equalsIgnoreAsciiCase("LF"))
589 3 : eCRLF_Flag = LINEEND_LF;
590 : else
591 0 : eCRLF_Flag = LINEEND_CR;
592 3 : break;
593 : case 2: // fontname
594 3 : sFont = sToken;
595 3 : break;
596 : case 3: // Language
597 3 : nLanguage = LanguageTag::convertToLanguageTypeWithFallback( sToken );
598 3 : break;
599 : }
600 : }
601 12 : ++nCnt;
602 12 : } while( -1 != nToken );
603 3 : }
604 :
605 0 : void SwAsciiOptions::WriteUserData(OUString& rStr)
606 : {
607 : // 1. charset
608 0 : rStr = NameFromCharSet(eCharSet) + ",";
609 :
610 : // 2. LineEnd
611 0 : switch(eCRLF_Flag)
612 : {
613 : case LINEEND_CRLF:
614 0 : rStr += "CRLF";
615 0 : break;
616 : case LINEEND_CR:
617 0 : rStr += "CR";
618 0 : break;
619 : case LINEEND_LF:
620 0 : rStr += "LF";
621 0 : break;
622 : }
623 0 : rStr += ",";
624 :
625 : // 3. Fontname
626 0 : rStr += sFont + ",";
627 :
628 : // 4. Language
629 0 : if (nLanguage)
630 : {
631 0 : rStr += LanguageTag::convertToBcp47(nLanguage);
632 : }
633 0 : rStr += ",";
634 0 : }
635 :
636 : #ifdef DISABLE_DYNLOADING
637 :
638 : extern "C" {
639 : Reader *ImportRTF();
640 : void ExportRTF( const OUString&, const OUString& rBaseURL, WriterRef& );
641 : Reader *ImportDOC();
642 : void ExportDOC( const OUString&, const OUString& rBaseURL, WriterRef& );
643 : sal_uLong SaveOrDelMSVBAStorage_ww8( SfxObjectShell&, SotStorage&, sal_Bool, const OUString& );
644 : sal_uLong GetSaveWarningOfMSVBAStorage_ww8( SfxObjectShell& );
645 : }
646 :
647 : #endif
648 :
649 1 : Reader* GetRTFReader()
650 : {
651 : #ifndef DISABLE_DYNLOADING
652 :
653 1 : FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportRTF" ) );
654 :
655 1 : if ( pFunction )
656 1 : return (*pFunction)();
657 :
658 0 : return NULL;
659 : #else
660 : return ImportRTF();
661 : #endif
662 :
663 : }
664 :
665 1 : void GetRTFWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
666 : {
667 : #ifndef DISABLE_DYNLOADING
668 1 : FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportRTF" ) );
669 :
670 1 : if ( pFunction )
671 1 : (*pFunction)( rFltName, rBaseURL, xRet );
672 : else
673 0 : xRet = WriterRef(0);
674 : #else
675 : ExportRTF( rFltName, rBaseURL, xRet );
676 : #endif
677 1 : }
678 :
679 9 : Reader* GetWW8Reader()
680 : {
681 : #ifndef DISABLE_DYNLOADING
682 9 : FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportDOC" ) );
683 :
684 9 : if ( pFunction )
685 9 : return (*pFunction)();
686 :
687 0 : return NULL;
688 : #else
689 : return ImportDOC();
690 : #endif
691 : }
692 :
693 32 : void GetWW8Writer( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet )
694 : {
695 : #ifndef DISABLE_DYNLOADING
696 32 : FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportDOC" ) );
697 :
698 32 : if ( pFunction )
699 32 : (*pFunction)( rFltName, rBaseURL, xRet );
700 : else
701 0 : xRet = WriterRef(0);
702 : #else
703 : ExportDOC( rFltName, rBaseURL, xRet );
704 : #endif
705 32 : }
706 :
707 : typedef sal_uLong ( SAL_CALL *SaveOrDel )( SfxObjectShell&, SotStorage&, sal_Bool, const OUString& );
708 : typedef sal_uLong ( SAL_CALL *GetSaveWarning )( SfxObjectShell& );
709 :
710 0 : sal_uLong SaveOrDelMSVBAStorage( SfxObjectShell& rDoc, SotStorage& rStor, bool bSaveInto, const OUString& rStorageName )
711 : {
712 : #ifndef DISABLE_DYNLOADING
713 0 : SaveOrDel pFunction = reinterpret_cast<SaveOrDel>( SwGlobals::getFilters().GetMswordLibSymbol( "SaveOrDelMSVBAStorage_ww8" ) );
714 0 : if( pFunction )
715 0 : return pFunction( rDoc, rStor, bSaveInto, rStorageName );
716 0 : return ERRCODE_NONE;
717 : #else
718 : return SaveOrDelMSVBAStorage_ww8( rDoc, rStor, bSaveInto, rStorageName );
719 : #endif
720 : }
721 :
722 0 : sal_uLong GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocS )
723 : {
724 : #ifndef DISABLE_DYNLOADING
725 0 : GetSaveWarning pFunction = reinterpret_cast<GetSaveWarning>( SwGlobals::getFilters().GetMswordLibSymbol( "GetSaveWarningOfMSVBAStorage_ww8" ) );
726 0 : if( pFunction )
727 0 : return pFunction( rDocS );
728 0 : return ERRCODE_NONE;
729 : #else
730 : return GetSaveWarningOfMSVBAStorage_ww8( rDocS );
731 : #endif
732 177 : }
733 :
734 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|