Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <string.h>
30 : : #include <stdio.h> // sscanf
31 : : #include <hintids.hxx>
32 : : #include <i18npool/lang.h>
33 : : #include <i18npool/mslangid.hxx>
34 : : #include <vcl/msgbox.hxx>
35 : : #include <svtools/parhtml.hxx>
36 : : #include <sot/storage.hxx>
37 : : #include <sot/clsids.hxx>
38 : : #include <sfx2/app.hxx>
39 : : #include <sfx2/docfilt.hxx>
40 : : #include <sfx2/fcontnr.hxx>
41 : : #include <sfx2/docfile.hxx>
42 : : #include <editeng/lrspitem.hxx>
43 : : #include <editeng/tstpitem.hxx>
44 : : #include <doc.hxx>
45 : : #include <docary.hxx>
46 : : #include <pam.hxx>
47 : : #include <shellio.hxx>
48 : : #include <docsh.hxx>
49 : : #include <wdocsh.hxx>
50 : : #include <fltini.hxx>
51 : : #include <hints.hxx>
52 : : #include <init.hxx>
53 : : #include <frmatr.hxx>
54 : : #include <fmtfsize.hxx>
55 : : #include <swtable.hxx>
56 : : #include <fmtcntnt.hxx>
57 : : #include <editeng/boxitem.hxx>
58 : : #include <frmfmt.hxx>
59 : : #include <numrule.hxx>
60 : : #include <ndtxt.hxx>
61 : : #include <swfltopt.hxx>
62 : : #include <swerror.h>
63 : : #include <osl/module.hxx>
64 : : #include <comphelper/processfactory.hxx>
65 : : #include <comphelper/componentcontext.hxx>
66 : : #include <com/sun/star/beans/XPropertySet.hpp>
67 : : #include <com/sun/star/util/XMacroExpander.hpp>
68 : : #include <rtl/uri.hxx>
69 : :
70 : : using namespace utl;
71 : : using rtl::OUString;
72 : : using namespace com::sun::star::uno;
73 : : using namespace com::sun::star;
74 : :
75 : : SwRead ReadAscii = 0, ReadHTML = 0, ReadXML = 0;
76 : :
77 : : Reader* GetRTFReader();
78 : : Reader* GetWW8Reader();
79 : :
80 : : // Note: if editing, please don't forget to modify also the enum
81 : : // ReaderWriterEnum and aFilterDetect in shellio.hxx
82 : : SwReaderWriterEntry aReaderWriter[] =
83 : : {
84 : : SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, sal_True ),
85 : : SwReaderWriterEntry( 0, &::GetASCWriter, sal_False ),
86 : : SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer, sal_True ),
87 : : SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer, sal_True ),
88 : : SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, sal_True ),
89 : : SwReaderWriterEntry( 0, &::GetHTMLWriter, sal_True ),
90 : : SwReaderWriterEntry( 0, 0, sal_True ),
91 : : SwReaderWriterEntry( &::GetWW8Reader, 0, sal_True ),
92 : : SwReaderWriterEntry( 0, &::GetXMLWriter, sal_True ),
93 : : SwReaderWriterEntry( 0, &::GetASCWriter, sal_False ),
94 : : SwReaderWriterEntry( 0, &::GetASCWriter, sal_True )
95 : 73 : };
96 : :
97 : 125 : Reader* SwReaderWriterEntry::GetReader()
98 : : {
99 [ + + ]: 125 : if ( pReader )
100 : 113 : return pReader;
101 [ + - ]: 12 : else if ( fnGetReader )
102 : : {
103 : 12 : pReader = (*fnGetReader)();
104 : 12 : return pReader;
105 : : }
106 : 125 : return NULL;
107 : : }
108 : :
109 : 10479 : void SwReaderWriterEntry::GetWriter( const String& rNm, const String& rBaseURL, WriterRef& xWrt ) const
110 : : {
111 [ + - ]: 10479 : if ( fnGetWriter )
112 : 10479 : (*fnGetWriter)( rNm, rBaseURL, xWrt );
113 : : else
114 [ # # ]: 0 : xWrt = WriterRef(0);
115 : 10479 : }
116 : :
117 : 0 : SwRead SwGetReaderXML() // SW_DLLPUBLIC
118 : : {
119 : 0 : return ReadXML;
120 : : }
121 : :
122 : 0 : bool IsDocShellRegistered()
123 : : {
124 : 0 : return 0 != SwDocShell::_GetInterface();
125 : : }
126 : :
127 : 438 : inline void _SetFltPtr( sal_uInt16 rPos, SwRead pReader )
128 : : {
129 : 438 : aReaderWriter[ rPos ].pReader = pReader;
130 : 438 : }
131 : :
132 : : namespace {
133 : :
134 : 0 : extern "C" { static void SAL_CALL thisModule() {} }
135 : :
136 : : }
137 : :
138 : : namespace sw {
139 : :
140 : 73 : Filters::Filters()
141 : : {
142 [ + - ][ + - ]: 73 : _SetFltPtr( READER_WRITER_BAS, (ReadAscii = new AsciiReader) );
143 [ + - ][ + - ]: 73 : _SetFltPtr( READER_WRITER_HTML, (ReadHTML = new HTMLReader) );
144 [ + - ][ + - ]: 73 : _SetFltPtr( READER_WRITER_WW1, new WW1Reader );
145 [ + - ][ + - ]: 73 : _SetFltPtr( READER_WRITER_XML, (ReadXML = new XMLReader) );
146 : 73 : _SetFltPtr( READER_WRITER_TEXT_DLG, ReadAscii );
147 : 73 : _SetFltPtr( READER_WRITER_TEXT, ReadAscii );
148 : 73 : }
149 : :
150 [ + - ]: 73 : Filters::~Filters()
151 : : {
152 : : // die Reader vernichten
153 [ + + ]: 876 : for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
154 : : {
155 : 803 : SwReaderWriterEntry& rEntry = aReaderWriter[n];
156 [ + + ][ + + ]: 803 : if( rEntry.bDelReader && rEntry.pReader )
157 [ + - ][ + - ]: 304 : delete rEntry.pReader, rEntry.pReader = NULL;
158 : : }
159 : 73 : }
160 : :
161 : 21 : oslGenericFunction Filters::GetMswordLibSymbol( const char *pSymbol )
162 : : {
163 [ + + ]: 21 : if (!msword_.is())
164 : : {
165 : 12 : bool ok = msword_.loadRelative( &thisModule, SVLIBRARY( "msword" ), SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY );
166 : : SAL_WARN_IF(!ok, "sw", "failed to load msword library");
167 : : }
168 [ + - ]: 21 : if (msword_.is())
169 [ + - ]: 21 : return msword_.getFunctionSymbol( ::rtl::OUString::createFromAscii( pSymbol ) );
170 : 21 : return NULL;
171 : : }
172 : :
173 : : }
174 : :
175 : : namespace SwReaderWriter {
176 : :
177 : 0 : Reader* GetReader( ReaderWriterEnum eReader )
178 : : {
179 : 0 : return aReaderWriter[eReader].GetReader();
180 : : }
181 : :
182 : 10479 : void GetWriter( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
183 : : {
184 [ + - ]: 104733 : for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
185 [ + + ]: 104733 : if( aFilterDetect[n].IsFilter( rFltName ) )
186 : : {
187 : 10479 : aReaderWriter[n].GetWriter( rFltName, rBaseURL, xRet );
188 : 10479 : break;
189 : : }
190 : 10479 : }
191 : :
192 : 125 : SwRead GetReader( const String& rFltName )
193 : : {
194 : 125 : SwRead pRead = 0;
195 [ + - ]: 573 : for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
196 [ + + ]: 573 : if( aFilterDetect[n].IsFilter( rFltName ) )
197 : : {
198 : 125 : pRead = aReaderWriter[n].GetReader();
199 : : // fuer einige Reader noch eine Sonderbehandlung:
200 [ + - ]: 125 : if ( pRead )
201 : 125 : pRead->SetFltName( rFltName );
202 : 125 : break;
203 : : }
204 : 125 : return pRead;
205 : : }
206 : :
207 : : } // namespace SwReaderWriter
208 : :
209 : 0 : void Writer::SetPasswd( const String& ) {}
210 : :
211 : :
212 : 0 : void Writer::SetVersion( const String&, long ) {}
213 : :
214 : :
215 : 10475 : sal_Bool Writer::IsStgWriter() const { return sal_False; }
216 : :
217 : 37 : sal_Bool StgWriter::IsStgWriter() const { return sal_True; }
218 : :
219 : :
220 : :
221 : :
222 : 125 : sal_Bool SwReader::NeedsPasswd( const Reader& /*rOptions*/ )
223 : : {
224 : 125 : return sal_False;
225 : : }
226 : :
227 : :
228 : 0 : sal_Bool SwReader::CheckPasswd( const String& /*rPasswd*/, const Reader& /*rOptions*/ )
229 : : {
230 : 0 : return sal_True;
231 : : }
232 : :
233 : :
234 : :
235 : : //-----------------------------------------------------------------------
236 : : // Filter Flags lesen, wird von WW8 / W4W / EXCEL / LOTUS benutzt.
237 : : //-----------------------------------------------------------------------
238 : :
239 : : /*
240 : : <FilterFlags>
241 : : <Excel_Lotus>
242 : : <MinRow cfg:type="long">0</MinRow>
243 : : <MaxRow cfg:type="long">0</MaxRow>
244 : : <MinCol cfg:type="long">0</MinCol>
245 : : <MaxCol cfg:type="long">0</MaxCol>
246 : : </Excel_Lotus>
247 : : <W4W>
248 : : <W4WHD cfg:type="long">0</W4WHD>
249 : : <W4WFT cfg:type="long">0</W4WFT>
250 : : <W4W000 cfg:type="long">0</W4W000>
251 : : </W4W>
252 : : <WinWord>
253 : : <WW1F cfg:type="long">0</WW1F>
254 : : <WW cfg:type="long">0</WW>
255 : : <WW8 cfg:type="long">0</WW8>
256 : : <WWF cfg:type="long">0</WWF>
257 : : <WWFA0 cfg:type="long">0</WWFA0>
258 : : <WWFA1 cfg:type="long">0</WWFA1>
259 : : <WWFA2 cfg:type="long">0</WWFA2>
260 : : <WWFB0 cfg:type="long">0</WWFB0>
261 : : <WWFB1 cfg:type="long">0</WWFB1>
262 : : <WWFB2 cfg:type="long">0</WWFB2>
263 : : <WWFLX cfg:type="long">0</WWFLX>
264 : : <WWFLY cfg:type="long">0</WWFLY>
265 : : <WWFT cfg:type="long">0</WWFT>
266 : : <WWWR cfg:type="long">0</WWWR>
267 : : </WinWord>
268 : : <Writer>
269 : : <SW3Imp cfg:type="long">0</SW3Imp>
270 : : </Writer>
271 : : </FilterFlags>
272 : : */
273 : :
274 : : #define FILTER_OPTION_ROOT rtl::OUString("Office.Writer/FilterFlags")
275 : :
276 : 108 : SwFilterOptions::SwFilterOptions( sal_uInt16 nCnt, const sal_Char** ppNames,
277 : : sal_uInt32* pValues )
278 [ + - ]: 108 : : ConfigItem( FILTER_OPTION_ROOT )
279 : : {
280 [ + - ]: 108 : GetValues( nCnt, ppNames, pValues );
281 : 108 : }
282 : :
283 : 108 : void SwFilterOptions::GetValues( sal_uInt16 nCnt, const sal_Char** ppNames,
284 : : sal_uInt32* pValues )
285 : : {
286 [ + - ]: 108 : Sequence<OUString> aNames( nCnt );
287 [ + - ]: 108 : OUString* pNames = aNames.getArray();
288 : : sal_uInt16 n;
289 : :
290 [ + + ]: 1512 : for( n = 0; n < nCnt; ++n )
291 : 1404 : pNames[ n ] = OUString::createFromAscii( ppNames[ n ] );
292 [ + - ]: 108 : Sequence<Any> aValues = GetProperties( aNames );
293 : :
294 [ + - ]: 108 : if( nCnt == aValues.getLength() )
295 : : {
296 : 108 : const Any* pAnyValues = aValues.getConstArray();
297 [ + + ]: 1512 : for( n = 0; n < nCnt; ++n )
298 : 1404 : pValues[ n ] = pAnyValues[ n ].hasValue()
299 : 1404 : ? *(sal_uInt32*)pAnyValues[ n ].getValue()
300 [ + - ]: 2808 : : 0;
301 : : }
302 : : else
303 [ # # ]: 0 : for( n = 0; n < nCnt; ++n )
304 [ + - ][ + - ]: 108 : pValues[ n ] = 0;
305 : 108 : }
306 : :
307 : 0 : void SwFilterOptions::Commit() {}
308 : 0 : void SwFilterOptions::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
309 : :
310 : :
311 : :
312 : 111 : void StgReader::SetFltName( const String& rFltNm )
313 : : {
314 [ + - ]: 111 : if( SW_STORAGE_READER & GetReaderType() )
315 : 111 : aFltName = rFltNm;
316 : 111 : }
317 : :
318 : :
319 : :
320 : 102 : SwRelNumRuleSpaces::SwRelNumRuleSpaces( SwDoc& rDoc, sal_Bool bNDoc )
321 : 102 : : bNewDoc( bNDoc )
322 : : {
323 [ + - ]: 102 : pNumRuleTbl = new SwNumRuleTbl();
324 : 102 : pNumRuleTbl->reserve(8);
325 [ - + ]: 102 : if( !bNDoc )
326 : : pNumRuleTbl->insert( pNumRuleTbl->begin(),
327 : 0 : rDoc.GetNumRuleTbl().begin(), rDoc.GetNumRuleTbl().end() );
328 : 102 : }
329 : :
330 : 102 : SwRelNumRuleSpaces::~SwRelNumRuleSpaces()
331 : : {
332 [ + - ]: 102 : if( pNumRuleTbl )
333 : : {
334 : 102 : pNumRuleTbl->clear();
335 [ + - ]: 102 : delete pNumRuleTbl;
336 : : }
337 : 102 : }
338 : :
339 : 0 : void SwRelNumRuleSpaces::SetNumRelSpaces( SwDoc& rDoc )
340 : : {
341 : 0 : const SwNumRuleTbl* pRuleTbl = NULL;
342 : :
343 [ # # ]: 0 : if( !bNewDoc )
344 : : {
345 : : // jetzt alle schon vorhanden NumRules aus dem Array entfernen,
346 : : // damit nur die neuen angepasst werden
347 [ # # ]: 0 : SwNumRuleTbl aNumRuleTbl;
348 [ # # ]: 0 : aNumRuleTbl.insert( aNumRuleTbl.begin(), pNumRuleTbl->begin(), pNumRuleTbl->end() );
349 : 0 : pNumRuleTbl->clear();
350 : 0 : const SwNumRuleTbl& rRuleTbl = rDoc.GetNumRuleTbl();
351 : : SwNumRule* pRule;
352 : :
353 [ # # ]: 0 : for( sal_uInt16 n = 0; n < rRuleTbl.size(); ++n )
354 [ # # ][ # # ]: 0 : if( USHRT_MAX == aNumRuleTbl.GetPos( pRule = rRuleTbl[ n ] ))
355 : : // war noch nicht vorhanden, also neu
356 [ # # ]: 0 : pNumRuleTbl->push_back( pRule );
357 : :
358 : 0 : aNumRuleTbl.clear();
359 : :
360 [ # # ]: 0 : pRuleTbl = pNumRuleTbl;
361 : : }
362 : : else
363 : : {
364 : 0 : pRuleTbl = &rDoc.GetNumRuleTbl();
365 : : }
366 : :
367 [ # # ]: 0 : if( pRuleTbl )
368 : : {
369 [ # # ]: 0 : for( sal_uInt16 n = pRuleTbl->size(); n; )
370 : : {
371 : 0 : SwNumRule* pRule = (*pRuleTbl)[ --n ];
372 : : // Rule noch gueltig und am Doc vorhanden?
373 [ # # ]: 0 : if( USHRT_MAX != rDoc.GetNumRuleTbl().GetPos( pRule ))
374 : : {
375 [ # # ]: 0 : SwNumRule::tTxtNodeList aTxtNodeList;
376 [ # # ]: 0 : pRule->GetTxtNodeList( aTxtNodeList );
377 [ # # ][ # # ]: 0 : for ( SwNumRule::tTxtNodeList::iterator aIter = aTxtNodeList.begin();
378 : 0 : aIter != aTxtNodeList.end(); ++aIter )
379 : : {
380 : 0 : SwTxtNode* pNd = *aIter;
381 [ # # ]: 0 : SetNumLSpace( *pNd, *pRule );
382 : 0 : }
383 : : }
384 : : }
385 : : }
386 : :
387 [ # # ]: 0 : if( pNumRuleTbl )
388 : : {
389 : 0 : pNumRuleTbl->clear();
390 [ # # ]: 0 : delete pNumRuleTbl, pNumRuleTbl = 0;
391 : : }
392 : :
393 [ # # ]: 0 : if( bNewDoc )
394 : : {
395 [ # # ]: 0 : SetOultineRelSpaces( SwNodeIndex( rDoc.GetNodes() ),
396 [ # # ][ # # ]: 0 : SwNodeIndex( rDoc.GetNodes().GetEndOfContent()));
[ # # ]
397 : : }
398 : 0 : }
399 : :
400 : 0 : void SwRelNumRuleSpaces::SetOultineRelSpaces( const SwNodeIndex& rStt,
401 : : const SwNodeIndex& rEnd )
402 : : {
403 : 0 : SwDoc* pDoc = rStt.GetNode().GetDoc();
404 : 0 : const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds();
405 [ # # ]: 0 : if( !rOutlNds.empty() )
406 : : {
407 : : sal_uInt16 nPos;
408 [ # # ]: 0 : rOutlNds.Seek_Entry( &rStt.GetNode(), &nPos );
409 [ # # # # ]: 0 : for( ; nPos < rOutlNds.size() &&
[ # # ]
410 [ # # ]: 0 : rOutlNds[ nPos ]->GetIndex() < rEnd.GetIndex(); ++nPos )
411 : : {
412 [ # # ]: 0 : SwTxtNode* pNd = rOutlNds[ nPos ]->GetTxtNode();
413 [ # # ][ # # ]: 0 : if( pNd->IsOutline() && !pNd->GetNumRule() )
[ # # ][ # # ]
[ # # ]
414 [ # # ]: 0 : SetNumLSpace( *pNd, *pDoc->GetOutlineNumRule() );
415 : : }
416 : : }
417 : 0 : }
418 : :
419 : 0 : void SwRelNumRuleSpaces::SetNumLSpace( SwTxtNode& rNd, const SwNumRule& rRule )
420 : : {
421 : 0 : sal_Bool bOutlineRule = OUTLINE_RULE == rRule.GetRuleType();
422 : : // correction of refactoring done by cws swnumtree:
423 : : // - assure a correct level for retrieving numbering format.
424 : 0 : sal_uInt8 nLvl = 0;
425 [ # # ][ # # ]: 0 : if ( rNd.GetActualListLevel() >= 0 && rNd.GetActualListLevel() < MAXLEVEL )
[ # # ][ # # ]
[ # # ]
426 : : {
427 [ # # ]: 0 : nLvl = static_cast< sal_uInt8 >(rNd.GetActualListLevel());
428 : : }
429 : :
430 [ # # ]: 0 : const SwNumFmt& rFmt = rRule.Get( nLvl );
431 [ # # ][ # # ]: 0 : const SvxLRSpaceItem& rLR = rNd.GetSwAttrSet().GetLRSpace();
432 : :
433 [ # # ]: 0 : SvxLRSpaceItem aLR( rLR );
434 [ # # ]: 0 : aLR.SetTxtFirstLineOfst( 0 );
435 : :
436 : : // sagt der Node, das die Numerierung den Wert vorgibt?
437 [ # # ][ # # ]: 0 : if( !bOutlineRule && rNd.IsSetNumLSpace() )
[ # # ]
438 [ # # ]: 0 : aLR.SetTxtLeft( 0 );
439 : : else
440 : : {
441 [ # # ]: 0 : long nLeft = rFmt.GetAbsLSpace(), nParaLeft = rLR.GetTxtLeft();
442 [ # # ]: 0 : if( 0 < rLR.GetTxtFirstLineOfst() )
443 : 0 : nParaLeft += rLR.GetTxtFirstLineOfst();
444 [ # # ]: 0 : else if( nParaLeft >= nLeft )
445 : : // set correct paragraph indent
446 : 0 : nParaLeft -= nLeft;
447 : : else
448 : 0 : nParaLeft = rLR.GetTxtLeft()+rLR.GetTxtFirstLineOfst();
449 [ # # ]: 0 : aLR.SetTxtLeft( nParaLeft );
450 : : }
451 : :
452 [ # # ]: 0 : if( aLR.GetTxtLeft() != rLR.GetTxtLeft() )
453 : : {
454 : : //bevor rLR geloescht wird!
455 : 0 : long nOffset = rLR.GetTxtLeft() - aLR.GetTxtLeft();
456 [ # # ]: 0 : rNd.SetAttr( aLR );
457 : :
458 : : // Tabs anpassen !!
459 : : const SfxPoolItem* pItem;
460 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rNd.GetSwAttrSet().GetItemState(
461 [ # # ]: 0 : RES_PARATR_TABSTOP, sal_True, &pItem ))
462 : : {
463 [ # # ]: 0 : SvxTabStopItem aTStop( *(SvxTabStopItem*)pItem );
464 [ # # ]: 0 : for( sal_uInt16 n = 0; n < aTStop.Count(); ++n )
465 : : {
466 [ # # ]: 0 : SvxTabStop& rTab = (SvxTabStop&)aTStop[ n ];
467 [ # # ]: 0 : if( SVX_TAB_ADJUST_DEFAULT != rTab.GetAdjustment() )
468 : : {
469 [ # # ]: 0 : if( !rTab.GetTabPos() )
470 : : {
471 [ # # ]: 0 : aTStop.Remove( n );
472 : 0 : --n;
473 : : }
474 : : else
475 : 0 : rTab.GetTabPos() += nOffset;
476 : : }
477 : : }
478 [ # # ][ # # ]: 0 : rNd.SetAttr( aTStop );
479 : : }
480 [ # # ]: 0 : }
481 : 0 : }
482 : :
483 : :
484 : :
485 : 9 : void CalculateFlySize(SfxItemSet& rFlySet, const SwNodeIndex& rAnchor,
486 : : SwTwips nPageWidth)
487 : : {
488 : 9 : const SfxPoolItem* pItem = 0;
489 [ + - ]: 9 : if( SFX_ITEM_SET != rFlySet.GetItemState( RES_FRM_SIZE, sal_True, &pItem ) ||
[ - + # # ]
[ + - ]
490 : 0 : MINFLY > ((SwFmtFrmSize*)pItem)->GetWidth() )
491 : : {
492 [ + - ][ + - ]: 9 : SwFmtFrmSize aSz((SwFmtFrmSize&)rFlySet.Get(RES_FRM_SIZE, sal_True));
493 [ - + ]: 9 : if (pItem)
494 [ # # ]: 0 : aSz = (SwFmtFrmSize&)(*pItem);
495 : :
496 : : SwTwips nWidth;
497 : : // dann die Breite des Flys selbst bestimmen. Ist eine Tabelle
498 : : // defininiert, dann benutze deren Breite, sonst die Breite der
499 : : // Seite
500 [ + - ]: 9 : const SwTableNode* pTblNd = rAnchor.GetNode().FindTableNode();
501 [ - + ]: 9 : if( pTblNd )
502 [ # # ]: 0 : nWidth = pTblNd->GetTable().GetFrmFmt()->GetFrmSize().GetWidth();
503 : : else
504 : 9 : nWidth = nPageWidth;
505 : :
506 [ + - ]: 9 : const SwNodeIndex* pSttNd = ((SwFmtCntnt&)rFlySet.Get( RES_CNTNT )).
507 : 9 : GetCntntIdx();
508 [ + - ]: 9 : if( pSttNd )
509 : : {
510 : 9 : sal_Bool bOnlyOneNode = sal_True;
511 : 9 : sal_uLong nMinFrm = 0;
512 : 9 : sal_uLong nMaxFrm = 0;
513 : 9 : SwTxtNode* pFirstTxtNd = 0;
514 [ + - ]: 9 : SwNodeIndex aIdx( *pSttNd, 1 );
515 [ + - ]: 9 : SwNodeIndex aEnd( *pSttNd->GetNode().EndOfSectionNode() );
516 [ + + ]: 18 : while( aIdx < aEnd )
517 : : {
518 : 9 : SwTxtNode *pTxtNd = aIdx.GetNode().GetTxtNode();
519 [ + - ]: 9 : if( pTxtNd )
520 : : {
521 [ + - ]: 9 : if( !pFirstTxtNd )
522 : 9 : pFirstTxtNd = pTxtNd;
523 [ # # ]: 0 : else if( pFirstTxtNd != pTxtNd )
524 : : {
525 : : // forget it
526 : 0 : bOnlyOneNode = sal_False;
527 : : break;
528 : : }
529 : :
530 : : sal_uLong nAbsMinCnts;
531 : : pTxtNd->GetMinMaxSize( aIdx.GetIndex(), nMinFrm,
532 [ + - ]: 9 : nMaxFrm, nAbsMinCnts );
533 : : }
534 [ + - ]: 9 : aIdx++;
535 : : }
536 : :
537 [ + - ]: 9 : if( bOnlyOneNode )
538 : : {
539 [ + - ][ + - ]: 9 : if( nMinFrm < MINLAY && pFirstTxtNd )
540 : : {
541 : : // if the first node dont contained any content, then
542 : : // insert one char in it calc again and delete once again
543 [ + - ][ + - ]: 9 : SwIndex aNdIdx( pFirstTxtNd );
544 [ + - ][ + - ]: 9 : pFirstTxtNd->InsertText(rtl::OUString("MM"), aNdIdx);
[ + - ]
545 : : sal_uLong nAbsMinCnts;
546 : : pFirstTxtNd->GetMinMaxSize( pFirstTxtNd->GetIndex(),
547 [ + - ]: 9 : nMinFrm, nMaxFrm, nAbsMinCnts );
548 [ + - ]: 9 : aNdIdx -= 2;
549 [ + - ][ + - ]: 9 : pFirstTxtNd->EraseText( aNdIdx, 2 );
550 : : }
551 : :
552 : : // Umrandung und Abstand zum Inhalt beachten
553 [ + - ]: 9 : const SvxBoxItem& rBoxItem = (SvxBoxItem&)rFlySet.Get( RES_BOX );
554 : 9 : sal_uInt16 nLine = BOX_LINE_LEFT;
555 [ + + ]: 27 : for( int i = 0; i < 2; ++i )
556 : : {
557 [ + - ]: 18 : const editeng::SvxBorderLine* pLn = rBoxItem.GetLine( nLine );
558 [ - + ]: 18 : if( pLn )
559 : : {
560 [ # # ][ # # ]: 0 : sal_uInt16 nWidthTmp = pLn->GetOutWidth() + pLn->GetInWidth();
561 [ # # ]: 0 : nWidthTmp = nWidthTmp + rBoxItem.GetDistance( nLine );
562 : 0 : nMinFrm += nWidthTmp;
563 : 0 : nMaxFrm += nWidthTmp;
564 : : }
565 : 18 : nLine = BOX_LINE_RIGHT;
566 : : }
567 : :
568 : : // Mindestbreite fuer Inhalt einhalten
569 [ - + ]: 9 : if( nMinFrm < MINLAY )
570 : 0 : nMinFrm = MINLAY;
571 [ - + ]: 9 : if( nMaxFrm < MINLAY )
572 : 0 : nMaxFrm = MINLAY;
573 : :
574 [ + - ]: 9 : if( nWidth > (sal_uInt16)nMaxFrm )
575 : 9 : nWidth = nMaxFrm;
576 [ # # ]: 0 : else if( nWidth > (sal_uInt16)nMinFrm )
577 : 0 : nWidth = nMinFrm;
578 [ + - ][ + - ]: 9 : }
579 : : }
580 : :
581 [ - + ]: 9 : if( MINFLY > nWidth )
582 : 0 : nWidth = MINFLY;
583 : :
584 : 9 : aSz.SetWidth( nWidth );
585 [ + - ]: 9 : if( MINFLY > aSz.GetHeight() )
586 : 9 : aSz.SetHeight( MINFLY );
587 [ + - ][ + - ]: 9 : rFlySet.Put( aSz );
588 : : }
589 [ # # ]: 0 : else if( MINFLY > ((SwFmtFrmSize*)pItem)->GetHeight() )
590 : : {
591 [ # # ]: 0 : SwFmtFrmSize aSz( *(SwFmtFrmSize*)pItem );
592 : 0 : aSz.SetHeight( MINFLY );
593 [ # # ][ # # ]: 0 : rFlySet.Put( aSz );
594 : : }
595 : 9 : }
596 : :
597 : : struct CharSetNameMap
598 : : {
599 : : rtl_TextEncoding eCode;
600 : : const sal_Char* pName;
601 : : };
602 : :
603 : 9 : const CharSetNameMap *GetCharSetNameMap()
604 : : {
605 : : static const CharSetNameMap aMapArr[] =
606 : : {
607 : : # define IMPLENTRY(X) { RTL_TEXTENCODING_##X, "" #X "" }
608 : : IMPLENTRY(DONTKNOW),
609 : : IMPLENTRY(MS_1252),
610 : : IMPLENTRY(APPLE_ROMAN),
611 : : IMPLENTRY(IBM_437),
612 : : IMPLENTRY(IBM_850),
613 : : IMPLENTRY(IBM_860),
614 : : IMPLENTRY(IBM_861),
615 : : IMPLENTRY(IBM_863),
616 : : IMPLENTRY(IBM_865),
617 : : IMPLENTRY(SYMBOL),
618 : : IMPLENTRY(ASCII_US),
619 : : IMPLENTRY(ISO_8859_1),
620 : : IMPLENTRY(ISO_8859_2),
621 : : IMPLENTRY(ISO_8859_3),
622 : : IMPLENTRY(ISO_8859_4),
623 : : IMPLENTRY(ISO_8859_5),
624 : : IMPLENTRY(ISO_8859_6),
625 : : IMPLENTRY(ISO_8859_7),
626 : : IMPLENTRY(ISO_8859_8),
627 : : IMPLENTRY(ISO_8859_9),
628 : : IMPLENTRY(ISO_8859_14),
629 : : IMPLENTRY(ISO_8859_15),
630 : : IMPLENTRY(IBM_737),
631 : : IMPLENTRY(IBM_775),
632 : : IMPLENTRY(IBM_852),
633 : : IMPLENTRY(IBM_855),
634 : : IMPLENTRY(IBM_857),
635 : : IMPLENTRY(IBM_862),
636 : : IMPLENTRY(IBM_864),
637 : : IMPLENTRY(IBM_866),
638 : : IMPLENTRY(IBM_869),
639 : : IMPLENTRY(MS_874),
640 : : IMPLENTRY(MS_1250),
641 : : IMPLENTRY(MS_1251),
642 : : IMPLENTRY(MS_1253),
643 : : IMPLENTRY(MS_1254),
644 : : IMPLENTRY(MS_1255),
645 : : IMPLENTRY(MS_1256),
646 : : IMPLENTRY(MS_1257),
647 : : IMPLENTRY(MS_1258),
648 : : IMPLENTRY(APPLE_ARABIC),
649 : : IMPLENTRY(APPLE_CENTEURO),
650 : : IMPLENTRY(APPLE_CROATIAN),
651 : : IMPLENTRY(APPLE_CYRILLIC),
652 : : IMPLENTRY(APPLE_DEVANAGARI),
653 : : IMPLENTRY(APPLE_FARSI),
654 : : IMPLENTRY(APPLE_GREEK),
655 : : IMPLENTRY(APPLE_GUJARATI),
656 : : IMPLENTRY(APPLE_GURMUKHI),
657 : : IMPLENTRY(APPLE_HEBREW),
658 : : IMPLENTRY(APPLE_ICELAND),
659 : : IMPLENTRY(APPLE_ROMANIAN),
660 : : IMPLENTRY(APPLE_THAI),
661 : : IMPLENTRY(APPLE_TURKISH),
662 : : IMPLENTRY(APPLE_UKRAINIAN),
663 : : IMPLENTRY(APPLE_CHINSIMP),
664 : : IMPLENTRY(APPLE_CHINTRAD),
665 : : IMPLENTRY(APPLE_JAPANESE),
666 : : IMPLENTRY(APPLE_KOREAN),
667 : : IMPLENTRY(MS_932),
668 : : IMPLENTRY(MS_936),
669 : : IMPLENTRY(MS_949),
670 : : IMPLENTRY(MS_950),
671 : : IMPLENTRY(SHIFT_JIS),
672 : : IMPLENTRY(GB_2312),
673 : : IMPLENTRY(GBT_12345),
674 : : IMPLENTRY(GBK),
675 : : IMPLENTRY(BIG5),
676 : : IMPLENTRY(EUC_JP),
677 : : IMPLENTRY(EUC_CN),
678 : : IMPLENTRY(EUC_TW),
679 : : IMPLENTRY(ISO_2022_JP),
680 : : IMPLENTRY(ISO_2022_CN),
681 : : IMPLENTRY(KOI8_R),
682 : : IMPLENTRY(KOI8_U),
683 : : IMPLENTRY(UTF7),
684 : : IMPLENTRY(UTF8),
685 : : IMPLENTRY(ISO_8859_10),
686 : : IMPLENTRY(ISO_8859_13),
687 : : IMPLENTRY(EUC_KR),
688 : : IMPLENTRY(ISO_2022_KR),
689 : : IMPLENTRY(JIS_X_0201),
690 : : IMPLENTRY(JIS_X_0208),
691 : : IMPLENTRY(JIS_X_0212),
692 : : IMPLENTRY(MS_1361),
693 : : IMPLENTRY(GB_18030),
694 : : IMPLENTRY(BIG5_HKSCS),
695 : : IMPLENTRY(TIS_620),
696 : : IMPLENTRY(PT154),
697 : : IMPLENTRY(UCS4),
698 : : IMPLENTRY(UCS2),
699 : : IMPLENTRY(UNICODE),
700 : : {0,0} //Last
701 : : };
702 : 9 : return &aMapArr[0];
703 : : }
704 : : /*
705 : : Get a rtl_TextEncoding from its name
706 : : */
707 : 9 : rtl_TextEncoding CharSetFromName(const String& rChrSetStr)
708 : : {
709 : 9 : const CharSetNameMap *pStart = GetCharSetNameMap();
710 : 9 : rtl_TextEncoding nRet = pStart->eCode;
711 : :
712 [ + - ]: 693 : for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
713 : : {
714 [ + + ]: 693 : if(rChrSetStr.EqualsIgnoreCaseAscii(pMap->pName))
715 : : {
716 : 9 : nRet = pMap->eCode;
717 : 9 : break;
718 : : }
719 : : }
720 : :
721 : : OSL_ENSURE(nRet != pStart->eCode, "TXT: That was an unknown language!");
722 : :
723 : 9 : return nRet;
724 : : }
725 : :
726 : :
727 : : /*
728 : : Get the String name of an rtl_TextEncoding
729 : : */
730 : 0 : String NameFromCharSet(rtl_TextEncoding nChrSet)
731 : : {
732 : 0 : const CharSetNameMap *pStart = GetCharSetNameMap();
733 : 0 : const char *pRet = pStart->pName;
734 : :
735 [ # # ]: 0 : for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
736 : : {
737 [ # # ]: 0 : if (nChrSet == pMap->eCode)
738 : : {
739 : 0 : pRet = pMap->pName;
740 : 0 : break;
741 : : }
742 : : }
743 : :
744 : : OSL_ENSURE(pRet != pStart->pName, "TXT: That was an unknown language!");
745 : :
746 [ # # ]: 0 : return rtl::OUString::createFromAscii(pRet);
747 : : }
748 : :
749 : : // for the automatic conversion (mail/news/...)
750 : : // The user data contains the options for the ascii import/export filter.
751 : : // The format is:
752 : : // 1. CharSet - as ascii chars
753 : : // 2. LineEnd - as CR/LR/CRLF
754 : : // 3. Fontname
755 : : // 4. Language
756 : : // the delimetercharacter is ","
757 : : //
758 : :
759 : 9 : void SwAsciiOptions::ReadUserData( const String& rStr )
760 : : {
761 : 9 : xub_StrLen nToken = 0;
762 : 9 : sal_uInt16 nCnt = 0;
763 [ + - ]: 9 : String sToken;
764 [ + + ]: 36 : do {
765 [ + - ][ + - ]: 36 : if( 0 != (sToken = rStr.GetToken( 0, ',', nToken )).Len() )
[ + - ][ + - ]
766 : : {
767 [ + + + + : 36 : switch( nCnt )
- ]
768 : : {
769 : : case 0: // CharSet
770 [ + - ]: 9 : eCharSet = CharSetFromName(sToken);
771 : 9 : break;
772 : : case 1: // LineEnd
773 [ + - ][ - + ]: 9 : if( sToken.EqualsIgnoreCaseAscii( "CRLF" ))
774 : 0 : eCRLF_Flag = LINEEND_CRLF;
775 [ + - ][ + - ]: 9 : else if( sToken.EqualsIgnoreCaseAscii( "LF" ))
776 : 9 : eCRLF_Flag = LINEEND_LF;
777 : : else
778 : 0 : eCRLF_Flag = LINEEND_CR;
779 : 9 : break;
780 : : case 2: // fontname
781 [ + - ]: 9 : sFont = sToken;
782 : 9 : break;
783 : : case 3: // Language
784 [ + - ][ + - ]: 9 : nLanguage = MsLangId::convertIsoStringToLanguage( sToken );
785 : 36 : break;
786 : : }
787 : : }
788 : 36 : ++nCnt;
789 [ + - ]: 9 : } while( STRING_NOTFOUND != nToken );
790 : 9 : }
791 : :
792 : 0 : void SwAsciiOptions::WriteUserData( String& rStr )
793 : : {
794 : : // 1. charset
795 [ # # ]: 0 : rStr = NameFromCharSet(eCharSet);
796 : 0 : rStr += ',';
797 : :
798 : : // 2. LineEnd
799 [ # # # # ]: 0 : switch(eCRLF_Flag)
800 : : {
801 : : case LINEEND_CRLF:
802 : 0 : rStr.AppendAscii( "CRLF" );
803 : 0 : break;
804 : : case LINEEND_CR:
805 : 0 : rStr.AppendAscii( "CR" );
806 : 0 : break;
807 : : case LINEEND_LF:
808 : 0 : rStr.AppendAscii( "LF" );
809 : 0 : break;
810 : : }
811 : 0 : rStr += ',';
812 : :
813 : : // 3. Fontname
814 : 0 : rStr += sFont;
815 : 0 : rStr += ',';
816 : :
817 : : // 4. Language
818 [ # # ]: 0 : if (nLanguage)
819 : : {
820 [ # # ]: 0 : rtl::OUString sTmp = MsLangId::convertLanguageToIsoString( nLanguage );
821 [ # # ][ # # ]: 0 : rStr += (String)sTmp;
[ # # ]
822 : : }
823 : 0 : rStr += ',';
824 : 0 : }
825 : :
826 : 0 : Reader* GetRTFReader()
827 : : {
828 : 0 : FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportRTF" ) );
829 : :
830 [ # # ]: 0 : if ( pFunction )
831 : 0 : return (*pFunction)();
832 : :
833 : 0 : return NULL;
834 : : }
835 : :
836 : 0 : void GetRTFWriter( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
837 : : {
838 : 0 : FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportRTF" ) );
839 : :
840 [ # # ]: 0 : if ( pFunction )
841 : 0 : (*pFunction)( rFltName, rBaseURL, xRet );
842 : : else
843 [ # # ]: 0 : xRet = WriterRef(0);
844 : 0 : }
845 : :
846 : 12 : Reader* GetWW8Reader()
847 : : {
848 : 12 : FnGetReader pFunction = reinterpret_cast<FnGetReader>( SwGlobals::getFilters().GetMswordLibSymbol( "ImportDOC" ) );
849 : :
850 [ + - ]: 12 : if ( pFunction )
851 : 12 : return (*pFunction)();
852 : :
853 : 12 : return NULL;
854 : : }
855 : :
856 : 9 : void GetWW8Writer( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
857 : : {
858 : 9 : FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( SwGlobals::getFilters().GetMswordLibSymbol( "ExportDOC" ) );
859 : :
860 [ + - ]: 9 : if ( pFunction )
861 : 9 : (*pFunction)( rFltName, rBaseURL, xRet );
862 : : else
863 [ # # ]: 0 : xRet = WriterRef(0);
864 : 9 : }
865 : :
866 : : typedef sal_uLong ( __LOADONCALLAPI *SaveOrDel )( SfxObjectShell&, SotStorage&, sal_Bool, const String& );
867 : : typedef sal_uLong ( __LOADONCALLAPI *GetSaveWarning )( SfxObjectShell& );
868 : :
869 : 0 : sal_uLong SaveOrDelMSVBAStorage( SfxObjectShell& rDoc, SotStorage& rStor, sal_Bool bSaveInto, const String& rStorageName )
870 : : {
871 : 0 : SaveOrDel pFunction = reinterpret_cast<SaveOrDel>( SwGlobals::getFilters().GetMswordLibSymbol( "SaveOrDelMSVBAStorage_ww8" ) );
872 [ # # ]: 0 : if( pFunction )
873 : 0 : return pFunction( rDoc, rStor, bSaveInto, rStorageName );
874 : 0 : return ERRCODE_NONE;
875 : : }
876 : :
877 : 0 : sal_uLong GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocS )
878 : : {
879 : 0 : GetSaveWarning pFunction = reinterpret_cast<GetSaveWarning>( SwGlobals::getFilters().GetMswordLibSymbol( "GetSaveWarningOfMSVBAStorage_ww8" ) );
880 [ # # ]: 0 : if( pFunction )
881 : 0 : return pFunction( rDocS );
882 : 0 : return ERRCODE_NONE;
883 [ + - ][ + - ]: 219 : }
884 : :
885 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|