Update ooo320-m1
[ooovba.git] / sw / source / filter / basflt / fltini.cxx
blob4e55ee6ce6056b074f9ad1155d2ab1946659269d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fltini.cxx,v $
10 * $Revision: 1.59 $
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"
33 #define _SVSTDARR_STRINGS
35 #include <string.h>
36 #include <stdio.h> // sscanf
37 #include <hintids.hxx>
38 #include <i18npool/lang.h>
39 #include <i18npool/mslangid.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <svtools/parhtml.hxx>
42 #include <svtools/svstdarr.hxx>
43 #include <sot/storage.hxx>
44 #include <sot/clsids.hxx>
45 #include <sfx2/app.hxx>
46 #include <sfx2/docfilt.hxx>
47 #include <sfx2/fcontnr.hxx>
48 #include <sfx2/docfile.hxx>
49 #include <svx/lrspitem.hxx>
50 #include <svx/tstpitem.hxx>
51 #include <doc.hxx>
52 #include <docary.hxx>
53 #include <pam.hxx>
54 #include <shellio.hxx>
55 #include <errhdl.hxx>
56 #include <docsh.hxx>
57 #include <wdocsh.hxx>
58 #include <fltini.hxx>
59 #include <hints.hxx>
60 #include <frmatr.hxx>
61 #include <fmtfsize.hxx>
62 #include <swtable.hxx>
63 #include <fmtcntnt.hxx>
64 #include <svx/boxitem.hxx>
65 #include <frmatr.hxx>
66 #include <frmfmt.hxx>
67 #include <numrule.hxx>
68 #include <ndtxt.hxx>
69 #include <swfltopt.hxx>
70 #include <swerror.h>
71 #include <osl/module.hxx>
73 using namespace utl;
74 using rtl::OUString;
75 using namespace com::sun::star::uno;
77 SwRead ReadAscii = 0, /*ReadSwg = 0, ReadSw3 = 0,*/
78 ReadHTML = 0, ReadXML = 0;
80 Reader* GetRTFReader();
81 Reader* GetWW8Reader();
83 // Note: if editing, please don't forget to modify also the enum
84 // ReaderWriterEnum and aFilterDetect in shellio.hxx
85 SwReaderWriterEntry aReaderWriter[] =
87 SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, TRUE ),
88 SwReaderWriterEntry( 0, &::GetASCWriter, FALSE ),
89 SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer, TRUE ),
90 SwReaderWriterEntry( &::GetWW8Reader, &::GetWW8Writer, TRUE ),
91 SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, TRUE ),
92 SwReaderWriterEntry( 0, &::GetHTMLWriter, TRUE ),
93 SwReaderWriterEntry( 0, 0, TRUE ),
94 SwReaderWriterEntry( &::GetWW8Reader, 0, TRUE ),
95 SwReaderWriterEntry( 0, &::GetXMLWriter, TRUE ),
96 SwReaderWriterEntry( 0, &::GetASCWriter, TRUE ),
97 SwReaderWriterEntry( 0, &::GetASCWriter, TRUE )
100 Reader* SwReaderWriterEntry::GetReader()
102 if ( pReader )
103 return pReader;
104 else if ( fnGetReader )
106 pReader = (*fnGetReader)();
107 return pReader;
109 return NULL;
112 void SwReaderWriterEntry::GetWriter( const String& rNm, const String& rBaseURL, WriterRef& xWrt ) const
114 if ( fnGetWriter )
115 (*fnGetWriter)( rNm, rBaseURL, xWrt );
116 else
117 xWrt = WriterRef(0);
120 /*SwRead SwGetReaderSw3() // SW_DLLPUBLIC
122 return ReadSw3;
125 SwRead SwGetReaderXML() // SW_DLLPUBLIC
127 return ReadXML;
130 bool IsDocShellRegistered()
132 return 0 != SwDocShell::_GetInterface();
135 inline void _SetFltPtr( USHORT rPos, SwRead pReader )
137 aReaderWriter[ rPos ].pReader = pReader;
140 void _InitFilter()
142 _SetFltPtr( READER_WRITER_BAS, (ReadAscii = new AsciiReader) );
143 _SetFltPtr( READER_WRITER_HTML, (ReadHTML = new HTMLReader) );
144 _SetFltPtr( READER_WRITER_WW1, new WW1Reader );
145 _SetFltPtr( READER_WRITER_XML, (ReadXML = new XMLReader) );
147 #ifdef NEW_WW97_EXPORT
148 aReaderWriter[ READER_WRITER_WW1 ].fnGetWriter = &::GetWW8Writer;
149 aReaderWriter[ READER_WRITER_WW5 ].fnGetWriter = &::GetWW8Writer;
150 #endif
152 _SetFltPtr( READER_WRITER_TEXT_DLG, ReadAscii );
153 _SetFltPtr( READER_WRITER_TEXT, ReadAscii );
156 void _FinitFilter()
158 // die Reader vernichten
159 for( USHORT n = 0; n < MAXFILTER; ++n )
161 SwReaderWriterEntry& rEntry = aReaderWriter[n];
162 if( rEntry.bDelReader && rEntry.pReader )
163 delete rEntry.pReader, rEntry.pReader = NULL;
168 /* \f */
170 namespace SwReaderWriter {
172 Reader* GetReader( ReaderWriterEnum eReader )
174 return aReaderWriter[eReader].GetReader();
177 void GetWriter( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
179 for( USHORT n = 0; n < MAXFILTER; ++n )
180 if( aFilterDetect[n].IsFilter( rFltName ) )
182 aReaderWriter[n].GetWriter( rFltName, rBaseURL, xRet );
183 break;
187 SwRead GetReader( const String& rFltName )
189 SwRead pRead = 0;
190 for( USHORT n = 0; n < MAXFILTER; ++n )
191 if( aFilterDetect[n].IsFilter( rFltName ) )
193 pRead = aReaderWriter[n].GetReader();
194 // fuer einige Reader noch eine Sonderbehandlung:
195 if ( pRead )
196 pRead->SetFltName( rFltName );
197 break;
199 return pRead;
202 } // namespace SwReaderWriter
204 /* \f */
206 /////////////// die Storage Reader/Writer ////////////////////////////////
208 /*void GetSw3Writer( const String&, const String& rBaseURL, WriterRef& xRet )
210 DBG_ERROR( "Shouldn't happen!");
211 xRet = new Sw3Writer;
215 ULONG StgReader::OpenMainStream( SvStorageStreamRef& rRef, USHORT& rBuffSize )
217 ULONG nRet = ERR_SWG_READ_ERROR;
218 ASSERT( pStg, "wo ist mein Storage?" );
219 const SfxFilter* pFltr = SwIoSystem::GetFilterOfFormat( aFltName );
220 if( pFltr )
222 rRef = pStg->OpenSotStream( SwIoSystem::GetSubStorageName( *pFltr ),
223 STREAM_READ | STREAM_SHARE_DENYALL );
225 if( rRef.Is() )
227 if( SVSTREAM_OK == rRef->GetError() )
229 USHORT nOld = rRef->GetBufferSize();
230 rRef->SetBufferSize( rBuffSize );
231 rBuffSize = nOld;
232 nRet = 0;
234 else
235 nRet = rRef->GetError();
238 return nRet;
241 /* \f */
243 ULONG Sw3Reader::Read( SwDoc &rDoc, SwPaM &rPam, const String & )
245 ULONG nRet;
246 if( pStg && pIO )
248 // TRUE: Vorlagen ueberschreiben
249 pIO->SetReadOptions( aOpt,TRUE );
250 if( !bInsertMode )
252 // Im Laden-Modus darf der PaM-Content-Teil nicht
253 // in den Textbereich zeigen (Nodes koennen geloescht werden)
254 rPam.GetBound( TRUE ).nContent.Assign( 0, 0 );
255 rPam.GetBound( FALSE ).nContent.Assign( 0, 0 );
257 nRet = pIO->Load( pStg, bInsertMode ? &rPam : 0 );
258 aOpt.ResetAllFmtsOnly();
259 pIO->SetReadOptions( aOpt, TRUE );
261 else
263 ASSERT( !this, "Sw3-Read ohne Storage und/oder IO-System" );
264 nRet = ERR_SWG_READ_ERROR;
266 return nRet;
269 // read the sections of the document, which is equal to the medium.
270 // returns the count of it
271 USHORT Sw3Reader::GetSectionList( SfxMedium& rMedium,
272 SvStrings& rStrings ) const
274 SvStorageRef aStg( rMedium.GetStorage() );
275 const SfxFilter* pFlt = rMedium.GetFilter();
276 ASSERT( pFlt && pFlt->GetVersion(),
277 "Kein Filter oder Filter ohne FF-Version" );
278 if( pFlt && pFlt->GetVersion() )
279 aStg->SetVersion( (long)pFlt->GetVersion() );
281 if( pIO )
282 pIO->GetSectionList( &aStg, rStrings );
283 return rStrings.Count();
284 return 0;
288 /*ULONG Sw3Writer::WriteStorage()
290 ULONG nRet;
291 if( pIO )
293 // der gleiche Storage -> Save, sonst SaveAs aufrufen
294 if( !bSaveAs )
295 nRet = pIO->Save( pOrigPam, bWriteAll );
296 else
297 nRet = pIO->SaveAs( pStg, pOrigPam, bWriteAll );
299 pIO = 0; // nach dem Schreiben ist der Pointer ungueltig !!
301 else
303 ASSERT( !this, "Sw3-Writer ohne IO-System" )
304 nRet = ERR_SWG_WRITE_ERROR;
306 return nRet;
309 ULONG Sw3Writer::WriteMedium( SfxMedium& )
311 DBG_ERROR( "Shouldn't be used currently!");
312 return WriteStorage();
315 BOOL Sw3Writer::IsSw3Writer() const { return TRUE; }
318 void Writer::SetPasswd( const String& ) {}
321 void Writer::SetVersion( const String&, long ) {}
324 BOOL Writer::IsStgWriter() const { return FALSE; }
325 //BOOL Writer::IsSw3Writer() const { return FALSE; }
327 BOOL StgWriter::IsStgWriter() const { return TRUE; }
329 /* \f */
333 BOOL SwReader::NeedsPasswd( const Reader& /*rOptions*/ )
335 BOOL bRes = FALSE;
336 return bRes;
340 BOOL SwReader::CheckPasswd( const String& /*rPasswd*/, const Reader& /*rOptions*/ )
342 return TRUE;
346 /* \f */
348 //-----------------------------------------------------------------------
349 // Filter Flags lesen, wird von WW8 / W4W / EXCEL / LOTUS benutzt.
350 //-----------------------------------------------------------------------
353 <FilterFlags>
354 <Excel_Lotus>
355 <MinRow cfg:type="long">0</MinRow>
356 <MaxRow cfg:type="long">0</MaxRow>
357 <MinCol cfg:type="long">0</MinCol>
358 <MaxCol cfg:type="long">0</MaxCol>
359 </Excel_Lotus>
360 <W4W>
361 <W4WHD cfg:type="long">0</W4WHD>
362 <W4WFT cfg:type="long">0</W4WFT>
363 <W4W000 cfg:type="long">0</W4W000>
364 </W4W>
365 <WinWord>
366 <WW1F cfg:type="long">0</WW1F>
367 <WW cfg:type="long">0</WW>
368 <WW8 cfg:type="long">0</WW8>
369 <WWF cfg:type="long">0</WWF>
370 <WWFA0 cfg:type="long">0</WWFA0>
371 <WWFA1 cfg:type="long">0</WWFA1>
372 <WWFA2 cfg:type="long">0</WWFA2>
373 <WWFB0 cfg:type="long">0</WWFB0>
374 <WWFB1 cfg:type="long">0</WWFB1>
375 <WWFB2 cfg:type="long">0</WWFB2>
376 <WWFLX cfg:type="long">0</WWFLX>
377 <WWFLY cfg:type="long">0</WWFLY>
378 <WWFT cfg:type="long">0</WWFT>
379 <WWWR cfg:type="long">0</WWWR>
380 </WinWord>
381 <Writer>
382 <SW3Imp cfg:type="long">0</SW3Imp>
383 </Writer>
384 </FilterFlags>
387 #define FILTER_OPTION_ROOT String::CreateFromAscii( \
388 RTL_CONSTASCII_STRINGPARAM( "Office.Writer/FilterFlags" ) )
390 SwFilterOptions::SwFilterOptions( sal_uInt16 nCnt, const sal_Char** ppNames,
391 sal_uInt32* pValues )
392 : ConfigItem( FILTER_OPTION_ROOT )
394 GetValues( nCnt, ppNames, pValues );
397 void SwFilterOptions::GetValues( sal_uInt16 nCnt, const sal_Char** ppNames,
398 sal_uInt32* pValues )
400 Sequence<OUString> aNames( nCnt );
401 OUString* pNames = aNames.getArray();
402 USHORT n;
404 for( n = 0; n < nCnt; ++n )
405 pNames[ n ] = OUString::createFromAscii( ppNames[ n ] );
406 Sequence<Any> aValues = GetProperties( aNames );
408 if( nCnt == aValues.getLength() )
410 const Any* pAnyValues = aValues.getConstArray();
411 for( n = 0; n < nCnt; ++n )
412 pValues[ n ] = pAnyValues[ n ].hasValue()
413 ? *(sal_uInt32*)pAnyValues[ n ].getValue()
414 : 0;
416 else
417 for( n = 0; n < nCnt; ++n )
418 pValues[ n ] = 0;
421 /* \f */
424 void StgReader::SetFltName( const String& rFltNm )
426 if( SW_STORAGE_READER & GetReaderType() )
427 aFltName = rFltNm;
431 /* \f */
433 SwRelNumRuleSpaces::SwRelNumRuleSpaces( SwDoc& rDoc, BOOL bNDoc )
434 : bNewDoc( bNDoc )
436 pNumRuleTbl = new SwNumRuleTbl( 8, 8 );
437 if( !bNDoc )
438 pNumRuleTbl->Insert( &rDoc.GetNumRuleTbl(), 0 );
441 SwRelNumRuleSpaces::~SwRelNumRuleSpaces()
443 if( pNumRuleTbl )
445 pNumRuleTbl->Remove( 0, pNumRuleTbl->Count() );
446 delete pNumRuleTbl;
450 void SwRelNumRuleSpaces::SetNumRelSpaces( SwDoc& rDoc )
452 const SwNumRuleTbl* pRuleTbl = NULL;
454 if( !bNewDoc )
456 // jetzt alle schon vorhanden NumRules aus dem Array entfernen,
457 // damit nur die neuen angepasst werden
458 SwNumRuleTbl aNumRuleTbl;
459 aNumRuleTbl.Insert( pNumRuleTbl, 0 );
460 pNumRuleTbl->Remove( 0, pNumRuleTbl->Count() );
461 const SwNumRuleTbl& rRuleTbl = rDoc.GetNumRuleTbl();
462 SwNumRule* pRule;
464 for( USHORT n = 0; n < rRuleTbl.Count(); ++n )
465 if( USHRT_MAX == aNumRuleTbl.GetPos( ( pRule = rRuleTbl[ n ] )))
466 // war noch nicht vorhanden, also neu
467 pNumRuleTbl->Insert( pRule, pNumRuleTbl->Count() );
469 aNumRuleTbl.Remove( 0, aNumRuleTbl.Count() );
471 pRuleTbl = pNumRuleTbl;
473 else
475 pRuleTbl = &rDoc.GetNumRuleTbl();
478 if( pRuleTbl )
480 for( USHORT n = pRuleTbl->Count(); n; )
482 SwNumRule* pRule = (*pRuleTbl)[ --n ];
483 // Rule noch gueltig und am Doc vorhanden?
484 if( USHRT_MAX != rDoc.GetNumRuleTbl().GetPos( pRule ))
486 // --> OD 2008-02-19 #refactorlists#
487 // SwNumRuleInfo aUpd( pRule->GetName() );
488 // aUpd.MakeList( rDoc );
490 // // bei allen nmumerierten Absaetzen vom linken Rand
491 // // den absoluten Wert des NumFormates abziehen
492 // for( ULONG nUpdPos = 0; nUpdPos < aUpd.GetList().Count();
493 // ++nUpdPos )
494 // {
495 // SwTxtNode* pNd = aUpd.GetList().GetObject( nUpdPos );
496 // SetNumLSpace( *pNd, *pRule );
497 // }
498 SwNumRule::tTxtNodeList aTxtNodeList;
499 pRule->GetTxtNodeList( aTxtNodeList );
500 for ( SwNumRule::tTxtNodeList::iterator aIter = aTxtNodeList.begin();
501 aIter != aTxtNodeList.end(); ++aIter )
503 SwTxtNode* pNd = *aIter;
504 SetNumLSpace( *pNd, *pRule );
506 // <--
511 if( pNumRuleTbl )
513 pNumRuleTbl->Remove( 0, pNumRuleTbl->Count() );
514 delete pNumRuleTbl, pNumRuleTbl = 0;
517 if( bNewDoc )
519 SetOultineRelSpaces( SwNodeIndex( rDoc.GetNodes() ),
520 SwNodeIndex( rDoc.GetNodes().GetEndOfContent()));
524 void SwRelNumRuleSpaces::SetOultineRelSpaces( const SwNodeIndex& rStt,
525 const SwNodeIndex& rEnd )
527 SwDoc* pDoc = rStt.GetNode().GetDoc();
528 const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds();
529 if( rOutlNds.Count() )
531 USHORT nPos;
532 rOutlNds.Seek_Entry( &rStt.GetNode(), &nPos );
533 for( ; nPos < rOutlNds.Count() &&
534 rOutlNds[ nPos ]->GetIndex() < rEnd.GetIndex(); ++nPos )
536 SwTxtNode* pNd = rOutlNds[ nPos ]->GetTxtNode();
537 if( pNd->IsOutline() && !pNd->GetNumRule() )
538 SetNumLSpace( *pNd, *pDoc->GetOutlineNumRule() );
543 void SwRelNumRuleSpaces::SetNumLSpace( SwTxtNode& rNd, const SwNumRule& rRule )
545 BOOL bOutlineRule = OUTLINE_RULE == rRule.GetRuleType();
546 // --> OD 2005-11-18 #128056#
547 // correction of refactoring done by cws swnumtree:
548 // - assure a correct level for retrieving numbering format.
549 // BYTE nLvl = rNd.GetLevel();
550 BYTE nLvl = 0;
551 if ( rNd.GetActualListLevel() >= 0 && rNd.GetActualListLevel() < MAXLEVEL )
553 nLvl = static_cast< BYTE >(rNd.GetActualListLevel());
555 // <--
556 const SwNumFmt& rFmt = rRule.Get( nLvl );
557 const SvxLRSpaceItem& rLR = rNd.GetSwAttrSet().GetLRSpace();
559 SvxLRSpaceItem aLR( rLR );
560 aLR.SetTxtFirstLineOfst( 0 );
562 // sagt der Node, das die Numerierung den Wert vorgibt?
563 if( !bOutlineRule && rNd.IsSetNumLSpace() )
564 aLR.SetTxtLeft( 0 );
565 else
567 long nLeft = rFmt.GetAbsLSpace(), nParaLeft = rLR.GetTxtLeft();
568 if( 0 < rLR.GetTxtFirstLineOfst() )
569 nParaLeft += rLR.GetTxtFirstLineOfst();
570 else if( nParaLeft >= nLeft )
571 // #82963#/#82962#: set correct paragraph indent
572 nParaLeft -= nLeft;
573 else
574 //#83154#, Don't think any of the older #80856# bugfix code is
575 //relevent anymore.
576 nParaLeft = rLR.GetTxtLeft()+rLR.GetTxtFirstLineOfst();
577 aLR.SetTxtLeft( nParaLeft );
580 if( aLR.GetTxtLeft() != rLR.GetTxtLeft() )
582 //bevor rLR geloescht wird!
583 long nOffset = rLR.GetTxtLeft() - aLR.GetTxtLeft();
584 rNd.SetAttr( aLR );
586 // Tabs anpassen !!
587 const SfxPoolItem* pItem;
588 if( SFX_ITEM_SET == rNd.GetSwAttrSet().GetItemState(
589 RES_PARATR_TABSTOP, TRUE, &pItem ))
591 SvxTabStopItem aTStop( *(SvxTabStopItem*)pItem );
592 for( USHORT n = 0; n < aTStop.Count(); ++n )
594 SvxTabStop& rTab = (SvxTabStop&)aTStop[ n ];
595 if( SVX_TAB_ADJUST_DEFAULT != rTab.GetAdjustment() )
597 if( !rTab.GetTabPos() )
599 aTStop.Remove( n );
600 --n;
602 else
603 rTab.GetTabPos() += nOffset;
606 rNd.SetAttr( aTStop );
611 /* \f */
614 void CalculateFlySize(SfxItemSet& rFlySet, const SwNodeIndex& rAnchor,
615 SwTwips nPageWidth)
617 const SfxPoolItem* pItem = 0;
618 if( SFX_ITEM_SET != rFlySet.GetItemState( RES_FRM_SIZE, TRUE, &pItem ) ||
619 MINFLY > ((SwFmtFrmSize*)pItem)->GetWidth() )
621 SwFmtFrmSize aSz((SwFmtFrmSize&)rFlySet.Get(RES_FRM_SIZE, TRUE));
622 if (pItem)
623 aSz = (SwFmtFrmSize&)(*pItem);
625 SwTwips nWidth;
626 // dann die Breite des Flys selbst bestimmen. Ist eine Tabelle
627 // defininiert, dann benutze deren Breite, sonst die Breite der
628 // Seite
629 const SwTableNode* pTblNd = rAnchor.GetNode().FindTableNode();
630 if( pTblNd )
631 nWidth = pTblNd->GetTable().GetFrmFmt()->GetFrmSize().GetWidth();
632 else
633 nWidth = nPageWidth;
635 const SwNodeIndex* pSttNd = ((SwFmtCntnt&)rFlySet.Get( RES_CNTNT )).
636 GetCntntIdx();
637 if( pSttNd )
639 BOOL bOnlyOneNode = TRUE;
640 ULONG nMinFrm = 0;
641 ULONG nMaxFrm = 0;
642 SwTxtNode* pFirstTxtNd = 0;
643 SwNodeIndex aIdx( *pSttNd, 1 );
644 SwNodeIndex aEnd( *pSttNd->GetNode().EndOfSectionNode() );
645 while( aIdx < aEnd )
647 SwTxtNode *pTxtNd = aIdx.GetNode().GetTxtNode();
648 if( pTxtNd )
650 if( !pFirstTxtNd )
651 pFirstTxtNd = pTxtNd;
652 else if( pFirstTxtNd != pTxtNd )
654 // forget it
655 bOnlyOneNode = FALSE;
656 break;
659 ULONG nAbsMinCnts;
660 pTxtNd->GetMinMaxSize( aIdx.GetIndex(), nMinFrm,
661 nMaxFrm, nAbsMinCnts );
663 aIdx++;
666 if( bOnlyOneNode )
668 if( nMinFrm < MINLAY && pFirstTxtNd )
670 // if the first node dont contained any content, then
671 // insert one char in it calc again and delete once again
672 SwIndex aNdIdx( pFirstTxtNd );
673 pFirstTxtNd->InsertText( String::CreateFromAscii(
674 RTL_CONSTASCII_STRINGPARAM( "MM" )), aNdIdx );
675 ULONG nAbsMinCnts;
676 pFirstTxtNd->GetMinMaxSize( pFirstTxtNd->GetIndex(),
677 nMinFrm, nMaxFrm, nAbsMinCnts );
678 aNdIdx -= 2;
679 pFirstTxtNd->EraseText( aNdIdx, 2 );
682 // Umrandung und Abstand zum Inhalt beachten
683 const SvxBoxItem& rBoxItem = (SvxBoxItem&)rFlySet.Get( RES_BOX );
684 USHORT nLine = BOX_LINE_LEFT;
685 for( int i = 0; i < 2; ++i )
687 const SvxBorderLine* pLn = rBoxItem.GetLine( nLine );
688 if( pLn )
690 USHORT nWidthTmp = pLn->GetOutWidth() + pLn->GetInWidth();
691 nWidthTmp = nWidthTmp + rBoxItem.GetDistance( nLine );
692 nMinFrm += nWidthTmp;
693 nMaxFrm += nWidthTmp;
695 nLine = BOX_LINE_RIGHT;
698 // Mindestbreite fuer Inhalt einhalten
699 if( nMinFrm < MINLAY )
700 nMinFrm = MINLAY;
701 if( nMaxFrm < MINLAY )
702 nMaxFrm = MINLAY;
704 if( nWidth > (USHORT)nMaxFrm )
705 nWidth = nMaxFrm;
706 else if( nWidth > (USHORT)nMinFrm )
707 nWidth = nMinFrm;
711 if( MINFLY > nWidth )
712 nWidth = MINFLY;
714 aSz.SetWidth( nWidth );
715 if( MINFLY > aSz.GetHeight() )
716 aSz.SetHeight( MINFLY );
717 rFlySet.Put( aSz );
719 else if( MINFLY > ((SwFmtFrmSize*)pItem)->GetHeight() )
721 SwFmtFrmSize aSz( *(SwFmtFrmSize*)pItem );
722 aSz.SetHeight( MINFLY );
723 rFlySet.Put( aSz );
727 /* \f */
728 struct CharSetNameMap
730 rtl_TextEncoding eCode;
731 const sal_Char* pName;
734 const CharSetNameMap *GetCharSetNameMap()
736 static const CharSetNameMap aMapArr[] =
738 # define IMPLENTRY(X) { RTL_TEXTENCODING_##X, "" #X "" }
739 IMPLENTRY(DONTKNOW),
740 IMPLENTRY(MS_1252),
741 IMPLENTRY(APPLE_ROMAN),
742 IMPLENTRY(IBM_437),
743 IMPLENTRY(IBM_850),
744 IMPLENTRY(IBM_860),
745 IMPLENTRY(IBM_861),
746 IMPLENTRY(IBM_863),
747 IMPLENTRY(IBM_865),
748 IMPLENTRY(SYMBOL),
749 IMPLENTRY(ASCII_US),
750 IMPLENTRY(ISO_8859_1),
751 IMPLENTRY(ISO_8859_2),
752 IMPLENTRY(ISO_8859_3),
753 IMPLENTRY(ISO_8859_4),
754 IMPLENTRY(ISO_8859_5),
755 IMPLENTRY(ISO_8859_6),
756 IMPLENTRY(ISO_8859_7),
757 IMPLENTRY(ISO_8859_8),
758 IMPLENTRY(ISO_8859_9),
759 IMPLENTRY(ISO_8859_14),
760 IMPLENTRY(ISO_8859_15),
761 IMPLENTRY(IBM_737),
762 IMPLENTRY(IBM_775),
763 IMPLENTRY(IBM_852),
764 IMPLENTRY(IBM_855),
765 IMPLENTRY(IBM_857),
766 IMPLENTRY(IBM_862),
767 IMPLENTRY(IBM_864),
768 IMPLENTRY(IBM_866),
769 IMPLENTRY(IBM_869),
770 IMPLENTRY(MS_874),
771 IMPLENTRY(MS_1250),
772 IMPLENTRY(MS_1251),
773 IMPLENTRY(MS_1253),
774 IMPLENTRY(MS_1254),
775 IMPLENTRY(MS_1255),
776 IMPLENTRY(MS_1256),
777 IMPLENTRY(MS_1257),
778 IMPLENTRY(MS_1258),
779 IMPLENTRY(APPLE_ARABIC),
780 IMPLENTRY(APPLE_CENTEURO),
781 IMPLENTRY(APPLE_CROATIAN),
782 IMPLENTRY(APPLE_CYRILLIC),
783 IMPLENTRY(APPLE_DEVANAGARI),
784 IMPLENTRY(APPLE_FARSI),
785 IMPLENTRY(APPLE_GREEK),
786 IMPLENTRY(APPLE_GUJARATI),
787 IMPLENTRY(APPLE_GURMUKHI),
788 IMPLENTRY(APPLE_HEBREW),
789 IMPLENTRY(APPLE_ICELAND),
790 IMPLENTRY(APPLE_ROMANIAN),
791 IMPLENTRY(APPLE_THAI),
792 IMPLENTRY(APPLE_TURKISH),
793 IMPLENTRY(APPLE_UKRAINIAN),
794 IMPLENTRY(APPLE_CHINSIMP),
795 IMPLENTRY(APPLE_CHINTRAD),
796 IMPLENTRY(APPLE_JAPANESE),
797 IMPLENTRY(APPLE_KOREAN),
798 IMPLENTRY(MS_932),
799 IMPLENTRY(MS_936),
800 IMPLENTRY(MS_949),
801 IMPLENTRY(MS_950),
802 IMPLENTRY(SHIFT_JIS),
803 IMPLENTRY(GB_2312),
804 IMPLENTRY(GBT_12345),
805 IMPLENTRY(GBK),
806 IMPLENTRY(BIG5),
807 IMPLENTRY(EUC_JP),
808 IMPLENTRY(EUC_CN),
809 IMPLENTRY(EUC_TW),
810 IMPLENTRY(ISO_2022_JP),
811 IMPLENTRY(ISO_2022_CN),
812 IMPLENTRY(KOI8_R),
813 IMPLENTRY(KOI8_U),
814 IMPLENTRY(UTF7),
815 IMPLENTRY(UTF8),
816 IMPLENTRY(ISO_8859_10),
817 IMPLENTRY(ISO_8859_13),
818 IMPLENTRY(EUC_KR),
819 IMPLENTRY(ISO_2022_KR),
820 IMPLENTRY(JIS_X_0201),
821 IMPLENTRY(JIS_X_0208),
822 IMPLENTRY(JIS_X_0212),
823 IMPLENTRY(MS_1361),
824 IMPLENTRY(GB_18030),
825 IMPLENTRY(BIG5_HKSCS),
826 IMPLENTRY(TIS_620),
827 IMPLENTRY(PT154),
828 IMPLENTRY(UCS4),
829 IMPLENTRY(UCS2),
830 IMPLENTRY(UNICODE),
831 {0,0} //Last
833 return &aMapArr[0];
836 Get a rtl_TextEncoding from its name
838 rtl_TextEncoding CharSetFromName(const String& rChrSetStr)
840 const CharSetNameMap *pStart = GetCharSetNameMap();
841 rtl_TextEncoding nRet = pStart->eCode;
843 for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
845 if(rChrSetStr.EqualsIgnoreCaseAscii(pMap->pName))
847 nRet = pMap->eCode;
848 break;
852 ASSERT(nRet != pStart->eCode, "TXT: That was an unknown language!");
854 return nRet;
859 Get the String name of an rtl_TextEncoding
861 String NameFromCharSet(rtl_TextEncoding nChrSet)
863 const CharSetNameMap *pStart = GetCharSetNameMap();
864 const char *pRet = pStart->pName;
866 for(const CharSetNameMap *pMap = pStart; pMap->pName; ++pMap)
868 if (nChrSet == pMap->eCode)
870 pRet = pMap->pName;
871 break;
875 ASSERT(pRet != pStart->pName, "TXT: That was an unknown language!");
877 return String::CreateFromAscii(pRet);
880 // for the automatic conversion (mail/news/...)
881 // The user data contains the options for the ascii import/export filter.
882 // The format is:
883 // 1. CharSet - as ascii chars
884 // 2. LineEnd - as CR/LR/CRLF
885 // 3. Fontname
886 // 4. Language
887 // the delimetercharacter is ","
890 void SwAsciiOptions::ReadUserData( const String& rStr )
892 xub_StrLen nToken = 0;
893 USHORT nCnt = 0;
894 String sToken;
895 do {
896 if( 0 != (sToken = rStr.GetToken( 0, ',', nToken )).Len() )
898 switch( nCnt )
900 case 0: // CharSet
901 eCharSet = CharSetFromName(sToken);
902 break;
903 case 1: // LineEnd
904 if( sToken.EqualsIgnoreCaseAscii( "CRLF" ))
905 eCRLF_Flag = LINEEND_CRLF;
906 else if( sToken.EqualsIgnoreCaseAscii( "LF" ))
907 eCRLF_Flag = LINEEND_LF;
908 else
909 eCRLF_Flag = LINEEND_CR;
910 break;
911 case 2: // fontname
912 sFont = sToken;
913 break;
914 case 3: // Language
915 nLanguage = MsLangId::convertIsoStringToLanguage( sToken );
916 break;
919 ++nCnt;
920 } while( STRING_NOTFOUND != nToken );
923 void SwAsciiOptions::WriteUserData( String& rStr )
925 // 1. charset
926 rStr = NameFromCharSet(eCharSet);
927 rStr += ',';
929 // 2. LineEnd
930 switch(eCRLF_Flag)
932 case LINEEND_CRLF:
933 rStr.AppendAscii( "CRLF" );
934 break;
935 case LINEEND_CR:
936 rStr.AppendAscii( "CR" );
937 break;
938 case LINEEND_LF:
939 rStr.AppendAscii( "LF" );
940 break;
942 rStr += ',';
944 // 3. Fontname
945 rStr += sFont;
946 rStr += ',';
948 // 4. Language
949 if (nLanguage)
951 rtl::OUString sTmp = MsLangId::convertLanguageToIsoString( nLanguage );
952 rStr += (String)sTmp;
954 rStr += ',';
957 extern "C" { static void SAL_CALL thisModule() {} }
959 static oslGenericFunction GetMswordLibSymbol( const char *pSymbol )
961 static ::osl::Module aModule;
962 if ( aModule.is() ||
963 aModule.loadRelative( &thisModule,
964 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "msword" ) ) ) ) )
966 return aModule.getFunctionSymbol( ::rtl::OUString::createFromAscii( pSymbol ) );
969 return NULL;
972 Reader* GetRTFReader()
974 FnGetReader pFunction = reinterpret_cast<FnGetReader>( GetMswordLibSymbol( "ImportRTF" ) );
976 if ( pFunction )
977 return (*pFunction)();
979 return NULL;
982 void GetRTFWriter( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
984 FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( GetMswordLibSymbol( "ExportRTF" ) );
986 if ( pFunction )
987 (*pFunction)( rFltName, rBaseURL, xRet );
988 else
989 xRet = WriterRef(0);
992 Reader* GetWW8Reader()
994 FnGetReader pFunction = reinterpret_cast<FnGetReader>( GetMswordLibSymbol( "ImportDOC" ) );
996 if ( pFunction )
997 return (*pFunction)();
999 return NULL;
1002 void GetWW8Writer( const String& rFltName, const String& rBaseURL, WriterRef& xRet )
1004 FnGetWriter pFunction = reinterpret_cast<FnGetWriter>( GetMswordLibSymbol( "ExportDOC" ) );
1006 if ( pFunction )
1007 (*pFunction)( rFltName, rBaseURL, xRet );
1008 else
1009 xRet = WriterRef(0);