diff options
Diffstat (limited to 'sfx2/source/bastyp')
-rw-r--r-- | sfx2/source/bastyp/bastyp.hrc | 38 | ||||
-rw-r--r-- | sfx2/source/bastyp/bastyp.src | 66 | ||||
-rw-r--r-- | sfx2/source/bastyp/bitset.cxx | 395 | ||||
-rw-r--r-- | sfx2/source/bastyp/fltfnc.cxx | 1227 | ||||
-rw-r--r-- | sfx2/source/bastyp/fltfnc.src | 75 | ||||
-rw-r--r-- | sfx2/source/bastyp/fltlst.cxx | 118 | ||||
-rw-r--r-- | sfx2/source/bastyp/fltlst.hxx | 67 | ||||
-rw-r--r-- | sfx2/source/bastyp/frmhtml.cxx | 163 | ||||
-rw-r--r-- | sfx2/source/bastyp/frmhtmlw.cxx | 381 | ||||
-rw-r--r-- | sfx2/source/bastyp/helper.cxx | 879 | ||||
-rw-r--r-- | sfx2/source/bastyp/makefile.mk | 66 | ||||
-rw-r--r-- | sfx2/source/bastyp/mieclip.cxx | 95 | ||||
-rw-r--r-- | sfx2/source/bastyp/minarray.cxx | 736 | ||||
-rw-r--r-- | sfx2/source/bastyp/misc.cxx | 75 | ||||
-rw-r--r-- | sfx2/source/bastyp/progress.cxx | 753 | ||||
-rw-r--r-- | sfx2/source/bastyp/sfxhtml.cxx | 451 | ||||
-rw-r--r-- | sfx2/source/bastyp/sfxresid.cxx | 73 |
17 files changed, 5658 insertions, 0 deletions
diff --git a/sfx2/source/bastyp/bastyp.hrc b/sfx2/source/bastyp/bastyp.hrc new file mode 100644 index 000000000000..b585ac79f035 --- /dev/null +++ b/sfx2/source/bastyp/bastyp.hrc @@ -0,0 +1,38 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <sfx2/sfx.hrc> + +//fuer das Mapping Fehlercode -> ResId + +#define RC_BASTYP RID_SFX_BASTYP_START +#define STR_FILTER_NOT_INSTALLED (RC_BASTYP + 9) +#define STR_FILTER_CONSULT_SERVICE (RC_BASTYP + 10) +#define STR_MEMEXCEPTION (RC_BASTYP + 28) +#define MSG_MEM_WARN (RC_BASTYP + 29) +#define STR_HTML_GENERATOR (RC_BASTYP + 30) + diff --git a/sfx2/source/bastyp/bastyp.src b/sfx2/source/bastyp/bastyp.src new file mode 100644 index 000000000000..5ef74f5874b3 --- /dev/null +++ b/sfx2/source/bastyp/bastyp.src @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "bastyp.hrc" + +String STR_HTML_GENERATOR +{ + Text = "%PRODUCTNAME %PRODUCTVERSION %PRODUCTEXTENSION (%1)" ; +}; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sfx2/source/bastyp/bitset.cxx b/sfx2/source/bastyp/bitset.cxx new file mode 100644 index 000000000000..df35593a9a18 --- /dev/null +++ b/sfx2/source/bastyp/bitset.cxx @@ -0,0 +1,395 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" +#include <tools/debug.hxx> +#ifndef GCC +#endif + +#include "bitset.hxx" + +#include <string.h> // memset(), memcpy() +#include <limits.h> // USHRT_MAX + +//==================================================================== +// add nOffset to each bit-value in the set + +BitSet BitSet::operator<<( USHORT nOffset ) const +{ + DBG_MEMTEST(); + // create a work-copy, return it if nothing to shift + BitSet aSet(*this); + if ( nOffset == 0 ) + return aSet; + + // compute the shiftment in long-words and bits + USHORT nBlockDiff = nOffset / 32; + ULONG nBitValDiff = nOffset % 32; + + // compute the new number of bits + for ( USHORT nBlock = 0; nBlock < nBlockDiff; ++nBlock ) + aSet.nCount = aSet.nCount - CountBits( *(aSet.pBitmap+nBlock) ); + aSet.nCount = aSet.nCount - + CountBits( *(aSet.pBitmap+nBlockDiff) >> (32-nBitValDiff) ); + + // shift complete long-words + USHORT nTarget, nSource; + for ( nTarget = 0, nSource = nBlockDiff; + (nSource+1) < aSet.nBlocks; + ++nTarget, ++nSource ) + *(aSet.pBitmap+nTarget) = + ( *(aSet.pBitmap+nSource) << nBitValDiff ) | + ( *(aSet.pBitmap+nSource+1) >> (32-nBitValDiff) ); + + // shift the remainder (if in total minor 32 bits, only this) + *(aSet.pBitmap+nTarget) = *(aSet.pBitmap+nSource) << nBitValDiff; + + // determine the last used block + while ( *(aSet.pBitmap+nTarget) == 0 ) + --nTarget; + + // shorten the block-array + if ( nTarget < aSet.nBlocks ) + { + ULONG* pNewMap = new ULONG[nTarget]; + memcpy( pNewMap, aSet.pBitmap, 4 * nTarget ); + delete [] aSet.pBitmap; + aSet.pBitmap = pNewMap; + aSet.nBlocks = nTarget; + } + + return aSet; +} + +//-------------------------------------------------------------------- + +// substracts nOffset from each bit-value in the set + +BitSet BitSet::operator>>( USHORT ) const +{ + DBG_MEMTEST(); + return BitSet(); +} + +//-------------------------------------------------------------------- + +// internal code for operator= and copy-ctor + +void BitSet::CopyFrom( const BitSet& rSet ) +{ + DBG_MEMTEST(); + nCount = rSet.nCount; + nBlocks = rSet.nBlocks; + if ( rSet.nBlocks ) + { + DBG_MEMTEST(); + pBitmap = new ULONG[nBlocks]; + memcpy( pBitmap, rSet.pBitmap, 4 * nBlocks ); + } + else + pBitmap = 0; +} + +//-------------------------------------------------------------------- + +// creates an empty bitset + +BitSet::BitSet() +{ + DBG_MEMTEST(); + nCount = 0; + nBlocks = 0; + pBitmap = 0; +} + +//-------------------------------------------------------------------- + +// creates a copy of bitset rOrig + +BitSet::BitSet( const BitSet& rOrig ) +{ + DBG_MEMTEST(); + CopyFrom(rOrig); +} + +//-------------------------------------------------------------------- + +// creates a bitset from an array + +BitSet::BitSet( USHORT* pArray, USHORT nSize ): + nCount(nSize) +{ + DBG_MEMTEST(); + // find the highest bit to set + USHORT nMax = 0; + for ( USHORT n = 0; n < nCount; ++n ) + if ( pArray[n] > nMax ) + nMax = pArray[n]; + + // if there are bits at all + if ( nMax > 0 ) + { + // allocate memory for all blocks needed + nBlocks = nMax / 32 + 1; + pBitmap = new ULONG[nBlocks]; + memset( pBitmap, 0, 4 * nBlocks ); + + // set all the bits + for ( USHORT n = 0; n < nCount; ++n ) + { + // compute the block no. and bitvalue + USHORT nBlock = n / 32; + ULONG nBitVal = 1L << (n % 32); + + // set a single bit + if ( ( *(pBitmap+nBlock) & nBitVal ) == 0 ) + { + *(pBitmap+nBlock) |= nBitVal; + ++nCount; + } + } + } + else + { + // initalize emtpy set + nBlocks = 0; + pBitmap = 0; + } +} + +//-------------------------------------------------------------------- + +// frees the storage + +BitSet::~BitSet() +{ + DBG_MEMTEST(); + delete [] pBitmap; +} + +//-------------------------------------------------------------------- + +// creates a bitmap with all bits in rRange set + +BitSet::BitSet( const Range& ) +{ + DBG_MEMTEST(); +} + +//-------------------------------------------------------------------- + +// assignment from another bitset + +BitSet& BitSet::operator=( const BitSet& rOrig ) +{ + DBG_MEMTEST(); + if ( this != &rOrig ) + { + delete [] pBitmap; + CopyFrom(rOrig); + } + return *this; +} + +//-------------------------------------------------------------------- + +// assignment from a single bit + +BitSet& BitSet::operator=( USHORT nBit ) +{ + DBG_MEMTEST(); + delete [] pBitmap; + + nBlocks = nBit / 32; + ULONG nBitVal = 1L << (nBit % 32); + nCount = 1; + + pBitmap = new ULONG[nBlocks]; + memset( pBitmap + nBlocks, 0, 4 * nBlocks ); + + *(pBitmap+nBlocks) = nBitVal; + + return *this; +} + +//-------------------------------------------------------------------- + +// creates the asymetric difference with another bitset + +BitSet& BitSet::operator-=(USHORT nBit) +{ + DBG_MEMTEST(); + USHORT nBlock = nBit / 32; + ULONG nBitVal = 1L << (nBit % 32); + + if ( nBlock >= nBlocks ) + return *this; + + if ( (*(pBitmap+nBlock) & nBitVal) ) + { + *(pBitmap+nBlock) &= ~nBitVal; + --nCount; + } + + return *this; +} + +//-------------------------------------------------------------------- + +// unites with the bits of rSet + +BitSet& BitSet::operator|=( const BitSet& rSet ) +{ + DBG_MEMTEST(); + USHORT nMax = Min(nBlocks, rSet.nBlocks); + + // expand the bitmap + if ( nBlocks < rSet.nBlocks ) + { + ULONG *pNewMap = new ULONG[rSet.nBlocks]; + memset( pNewMap + nBlocks, 0, 4 * (rSet.nBlocks - nBlocks) ); + + if ( pBitmap ) + { + memcpy( pNewMap, pBitmap, 4 * nBlocks ); + delete [] pBitmap; + } + pBitmap = pNewMap; + nBlocks = rSet.nBlocks; + } + + // add the bits blocks by block + for ( USHORT nBlock = 0; nBlock < nMax; ++nBlock ) + { + // compute numberof additional bits + ULONG nDiff = ~*(pBitmap+nBlock) & *(rSet.pBitmap+nBlock); + nCount = nCount + CountBits(nDiff); + + *(pBitmap+nBlock) |= *(rSet.pBitmap+nBlock); + } + + return *this; +} + +//-------------------------------------------------------------------- + +// unites with a single bit + +BitSet& BitSet::operator|=( USHORT nBit ) +{ + DBG_MEMTEST(); + USHORT nBlock = nBit / 32; + ULONG nBitVal = 1L << (nBit % 32); + + if ( nBlock >= nBlocks ) + { + ULONG *pNewMap = new ULONG[nBlock+1]; + memset( pNewMap + nBlocks, 0, 4 * (nBlock - nBlocks + 1) ); + + if ( pBitmap ) + { + memcpy( pNewMap, pBitmap, 4 * nBlocks ); + delete [] pBitmap; + } + pBitmap = pNewMap; + nBlocks = nBlock+1; + } + + if ( (*(pBitmap+nBlock) & nBitVal) == 0 ) + { + *(pBitmap+nBlock) |= nBitVal; + ++nCount; + } + + return *this; +} + +//-------------------------------------------------------------------- + +// determines if the bit is set (may be the only one) + +BOOL BitSet::Contains( USHORT nBit ) const +{ + DBG_MEMTEST(); + USHORT nBlock = nBit / 32; + ULONG nBitVal = 1L << (nBit % 32); + + if ( nBlock >= nBlocks ) + return FALSE; + return ( nBitVal & *(pBitmap+nBlock) ) == nBitVal; +} + +//-------------------------------------------------------------------- + +// determines if the bitsets are equal + +BOOL BitSet::operator==( const BitSet& rSet ) const +{ + DBG_MEMTEST(); + if ( nBlocks != rSet.nBlocks ) + return FALSE; + + USHORT nBlock = nBlocks; + while ( nBlock-- > 0 ) + if ( *(pBitmap+nBlock) != *(rSet.pBitmap+nBlock) ) + return FALSE; + + return TRUE; +} + +//-------------------------------------------------------------------- + +// counts the number of 1-bits in the parameter + +USHORT BitSet::CountBits( ULONG nBits ) +{ + USHORT nCount = 0; + int nBit = 32; + while ( nBit-- && nBits ) + { if ( ( (long)nBits ) < 0 ) + ++nCount; + nBits = nBits << 1; + } + return nCount; +} + +//-------------------------------------------------------------------- + +USHORT IndexBitSet::GetFreeIndex() +{ + for(USHORT i=0;i<USHRT_MAX;i++) + if(!Contains(i)) + { + *this|=i; + return i; + } + DBG_ASSERT(FALSE, "IndexBitSet enthaelt mehr als USHRT_MAX Eintraege"); + return 0; +} + + diff --git a/sfx2/source/bastyp/fltfnc.cxx b/sfx2/source/bastyp/fltfnc.cxx new file mode 100644 index 000000000000..d11b8b5130ed --- /dev/null +++ b/sfx2/source/bastyp/fltfnc.cxx @@ -0,0 +1,1227 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#include "fltfnc.hxx" +#include <com/sun/star/uno/Exception.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/datatransfer/DataFlavor.hpp> +#include <com/sun/star/document/XTypeDetection.hpp> +#include <com/sun/star/container/XContainerQuery.hpp> + +#include <comphelper/sequenceashashmap.hxx> + +#ifndef _EXCHANGE_HXX //autogen +#include <sot/exchange.hxx> +#endif +#include <tools/config.hxx> +#include <basic/sbmeth.hxx> +#include <basic/basmgr.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbxobj.hxx> +#include <basic/sbxmeth.hxx> +#include <basic/sbxcore.hxx> +#ifndef _MSGBOX_HXX //autogen +#include <vcl/msgbox.hxx> +#endif +#ifndef _RTL_USTRING_HXX //autogen +#include <rtl/ustring.hxx> +#endif +#include <rtl/ustrbuf.hxx> +#include <svl/eitem.hxx> +#include <svl/intitem.hxx> +#include <svl/stritem.hxx> +#include <svl/lckbitem.hxx> +#include <svl/inettype.hxx> +#include <svl/rectitem.hxx> + +#include <sot/storage.hxx> +#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> +#include <com/sun/star/frame/XDispatch.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/frame/XDispatchProviderInterception.hpp> +#include <com/sun/star/frame/FeatureStateEvent.hpp> +#include <com/sun/star/frame/DispatchDescriptor.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XFrameActionListener.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/FrameActionEvent.hpp> +#include <com/sun/star/frame/FrameAction.hpp> +#include <com/sun/star/frame/XFrameLoader.hpp> +#include <com/sun/star/frame/XLoadEventListener.hpp> +#include <com/sun/star/frame/XFilterDetect.hpp> +#include <com/sun/star/loader/XImplementationLoader.hpp> +#include <com/sun/star/loader/CannotActivateFactoryException.hpp> +#ifndef _UNOTOOLS_PROCESSFACTORY_HXX +#include <comphelper/processfactory.hxx> +#endif +#include <com/sun/star/beans/PropertyValue.hpp> + +#include <sal/types.h> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/ucb/XContent.hpp> +#include <rtl/ustring.hxx> +#include <vos/process.hxx> +#include <unotools/pathoptions.hxx> +#include <unotools/moduleoptions.hxx> +#include <comphelper/mediadescriptor.hxx> +#include <tools/urlobj.hxx> + +#include <rtl/logfile.hxx> + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::ucb; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::beans; +using namespace ::vos; +#include <svl/ctypeitm.hxx> +#include <svtools/sfxecode.hxx> +#include <unotools/syslocale.hxx> + +#include "sfxhelp.hxx" +#include "sfxbasic.hxx" +#include <sfx2/docfilt.hxx> +#include <sfx2/docfac.hxx> +#include "sfxtypes.hxx" +#include <sfx2/sfxuno.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/progress.hxx> +#include "openflag.hxx" +#include "bastyp.hrc" +#include "sfxresid.hxx" +#include <sfx2/doctempl.hxx> +#include <sfx2/frame.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/viewfrm.hxx> +#include "helper.hxx" +#include "fltlst.hxx" +#include <sfx2/request.hxx> +#include "arrdecl.hxx" +#include <sfx2/appuno.hxx> +#include <sfx2/viewfrm.hxx> + +static SfxFilterList_Impl* pFilterArr = 0; +static BOOL bFirstRead = TRUE; + +static void CreateFilterArr() +{ + pFilterArr = new SfxFilterList_Impl; + new SfxFilterListener(); +} + +//---------------------------------------------------------------- +inline String ToUpper_Impl( const String &rStr ) +{ + return SvtSysLocale().GetCharClass().upper( rStr ); +} + +//---------------------------------------------------------------- +class SfxFilterContainer_Impl +{ +public: + String aName; + String aServiceName; + + SfxFilterContainer_Impl( const String& rName ) + : aName( rName ) + { + aServiceName = SfxObjectShell::GetServiceNameFromFactory( rName ); + } +}; + +#define IMPL_FORWARD_LOOP( aMethod, ArgType, aArg ) \ +const SfxFilter* SfxFilterContainer::aMethod( ArgType aArg, SfxFilterFlags nMust, SfxFilterFlags nDont ) const \ +{\ + SfxFilterMatcher aMatch( pImpl->aName ); \ + return aMatch.aMethod( aArg, nMust, nDont ); \ +} + +IMPL_FORWARD_LOOP( GetFilter4Mime, const String&, rMime ); +IMPL_FORWARD_LOOP( GetFilter4ClipBoardId, sal_uInt32, nId ); +IMPL_FORWARD_LOOP( GetFilter4EA, const String&, rEA ); +IMPL_FORWARD_LOOP( GetFilter4Extension, const String&, rExt ); +IMPL_FORWARD_LOOP( GetFilter4FilterName, const String&, rName ); +IMPL_FORWARD_LOOP( GetFilter4UIName, const String&, rName ); + +const SfxFilter* SfxFilterContainer::GetAnyFilter( SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + SfxFilterMatcher aMatch( pImpl->aName ); + return aMatch.GetAnyFilter( nMust, nDont ); +} + +//---------------------------------------------------------------- + +SfxFilterContainer::SfxFilterContainer( const String& rName ) +{ + pImpl = new SfxFilterContainer_Impl( rName ); +} + +//---------------------------------------------------------------- + +SfxFilterContainer::~SfxFilterContainer() +{ +} + +//---------------------------------------------------------------- + +const String SfxFilterContainer::GetName() const +{ + return pImpl->aName; +} + +const SfxFilter* SfxFilterContainer::GetDefaultFilter_Impl( const String& rName ) +{ + // Try to find out the type of factory. + // Interpret given name as Service- and ShortName! + SvtModuleOptions aOpt; + SvtModuleOptions::EFactory eFactory = aOpt.ClassifyFactoryByServiceName(rName); + if (eFactory == SvtModuleOptions::E_UNKNOWN_FACTORY) + eFactory = aOpt.ClassifyFactoryByShortName(rName); + + // could not classify factory by its service nor by its short name. + // Must be an unknown factory! => return NULL + if (eFactory == SvtModuleOptions::E_UNKNOWN_FACTORY) + return NULL; + + // For the following code we need some additional informations. + String sServiceName = aOpt.GetFactoryName(eFactory); + String sShortName = aOpt.GetFactoryShortName(eFactory); + String sDefaultFilter = aOpt.GetFactoryDefaultFilter(eFactory); + + // Try to get the default filter. Dont fiorget to verify it. + // May the set default filter does not exists any longer or + // does not fit the given factory. + const SfxFilterMatcher aMatcher; + const SfxFilter* pFilter = aMatcher.GetFilter4FilterName(sDefaultFilter); + + if ( + (pFilter ) && + (pFilter->GetServiceName().CompareIgnoreCaseToAscii( sServiceName ) != COMPARE_EQUAL) + ) + { + pFilter = 0; + } + + // If at least no default filter could be located - use any filter of this + // factory. + if (!pFilter) + { + if ( bFirstRead ) + ReadFilters_Impl(); + + sal_uInt16 nCount = ( sal_uInt16 ) pFilterArr->Count(); + for( sal_uInt16 n = 0; n < nCount; n++ ) + { + const SfxFilter* pCheckFilter = pFilterArr->GetObject( n ); + if ( pCheckFilter->GetServiceName().CompareIgnoreCaseToAscii( sServiceName ) == COMPARE_EQUAL ) + { + pFilter = pCheckFilter; + break; + } + } + } + + return pFilter; +} + + +//---------------------------------------------------------------- + +class SfxFilterMatcherArr_Impl; +static SfxFilterMatcherArr_Impl* pImplArr = 0; + +// Impl-Data is shared between all FilterMatchers of the same factory +class SfxFilterMatcher_Impl +{ +public: + ::rtl::OUString aName; + SfxFilterList_Impl* pList; // is created on demand + + void InitForIterating() const; + void Update(); + SfxFilterMatcher_Impl() + : pList(0) + {} +}; + +DECL_PTRARRAY( SfxFilterMatcherArr_Impl, SfxFilterMatcher_Impl*, 2, 2 ) + +SfxFilterMatcher::SfxFilterMatcher( const String& rName ) + : pImpl( 0 ) +{ + if ( !pImplArr ) + // keep track of created filter matchers to recycle the FilterLists + pImplArr = new SfxFilterMatcherArr_Impl; + + String aName = SfxObjectShell::GetServiceNameFromFactory( rName ); + DBG_ASSERT(aName.Len(), "Found boes type :-)"); + for ( USHORT n=0; n<pImplArr->Count(); n++ ) + { + // find the impl-Data of any comparable FilterMatcher that was created before + SfxFilterMatcher_Impl* pImp = pImplArr->GetObject(n); + if ( String(pImp->aName) == aName ) + pImpl = pImp; + } + + if ( !pImpl ) + { + // first Matcher created for this factory + pImpl = new SfxFilterMatcher_Impl; + pImpl->aName = aName; + pImplArr->Insert( pImplArr->Count(), pImpl ); + } +} + +SfxFilterMatcher::SfxFilterMatcher() +{ + // global FilterMatcher always uses global filter array (also created on demand) + pImpl = new SfxFilterMatcher_Impl; +} + +SfxFilterMatcher::~SfxFilterMatcher() +{ + if ( !pImpl->aName.getLength() ) + // only the global Matcher owns his ImplData + delete pImpl; +} + +void SfxFilterMatcher_Impl::Update() +{ + if ( pList ) + { + // this List was already used + pList->Clear(); + for ( USHORT n=0; n<pFilterArr->Count(); n++ ) + { + SfxFilter* pFilter = pFilterArr->GetObject(n); + if ( pFilter->GetServiceName() == String(aName) ) + pList->Insert( pFilter, LIST_APPEND ); + } + } +} + +void SfxFilterMatcher_Impl::InitForIterating() const +{ + if ( pList ) + return; + + if ( bFirstRead ) + // global filter array has not been created yet + SfxFilterContainer::ReadFilters_Impl(); + + if ( aName.getLength() ) + { + // matcher of factory: use only filters of that document type + ((SfxFilterMatcher_Impl*)this)->pList = new SfxFilterList_Impl; + ((SfxFilterMatcher_Impl*)this)->Update(); + } + else + { + // global matcher: use global filter array + ((SfxFilterMatcher_Impl*)this)->pList = pFilterArr; + } +} + +const SfxFilter* SfxFilterMatcher::GetAnyFilter( SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + pImpl->InitForIterating(); + sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); + for( sal_uInt16 n = 0; n < nCount; n++ ) + { + const SfxFilter* pFilter = pImpl->pList->GetObject( n ); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) ) + return pFilter; + } + + return NULL; +} + +//---------------------------------------------------------------- + +sal_uInt32 SfxFilterMatcher::GuessFilterIgnoringContent( + SfxMedium& rMedium, + const SfxFilter**ppFilter, + SfxFilterFlags /*nMust*/, + SfxFilterFlags /*nDont*/ ) const +{ + Reference< XTypeDetection > xDetection( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection")), UNO_QUERY ); + ::rtl::OUString sTypeName; + try + { + //!MBA: nmust, ndont? + sTypeName = xDetection->queryTypeByURL( rMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); + } + catch( Exception& ) + { + } + + *ppFilter = NULL; + if ( sTypeName.getLength() ) + *ppFilter = GetFilter4EA( sTypeName ); + + return *ppFilter ? ERRCODE_NONE : ERRCODE_ABORT; +} + +//---------------------------------------------------------------- + +#define CHECKERROR() \ +if( nErr == 1 || nErr == USHRT_MAX || nErr == ULONG_MAX ) \ +{ \ + ByteString aText = "Fehler in FilterDetection: Returnwert ";\ + aText += ByteString::CreateFromInt32(nErr); \ + if( pFilter ) \ + { \ + aText += ' '; \ + aText += ByteString(U2S(pFilter->GetFilterName())); \ + } \ + DBG_ERROR( aText.GetBuffer() ); \ + nErr = ERRCODE_ABORT; \ +} + +//---------------------------------------------------------------- + +sal_uInt32 SfxFilterMatcher::GuessFilter( SfxMedium& rMedium, const SfxFilter**ppFilter, SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + return GuessFilterControlDefaultUI( rMedium, ppFilter, nMust, nDont, sal_True ); +} + +//---------------------------------------------------------------- + +sal_uInt32 SfxFilterMatcher::GuessFilterControlDefaultUI( SfxMedium& rMedium, const SfxFilter** ppFilter, SfxFilterFlags nMust, SfxFilterFlags nDont, sal_Bool /*bDefUI*/ ) const +{ + const SfxFilter* pOldFilter = *ppFilter; + + // no detection service -> nothing to do ! + Reference< XTypeDetection > xDetection( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection")), UNO_QUERY ); + if (!xDetection.is()) + return ERRCODE_ABORT; + + ::rtl::OUString sTypeName; + try + { + // open the stream one times only ... + // Otherwhise it will be tried more then once and show the same interaction more then once ... + + ::rtl::OUString sURL( rMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInStream = rMedium.GetInputStream(); + + // stream exists => deep detection (with preselection ... if possible) + if (xInStream.is()) + { + ::comphelper::MediaDescriptor aDescriptor; + + aDescriptor[::comphelper::MediaDescriptor::PROP_URL() ] <<= sURL; + aDescriptor[::comphelper::MediaDescriptor::PROP_INPUTSTREAM() ] <<= xInStream; + aDescriptor[::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= rMedium.GetInteractionHandler(); + + if ( pImpl->aName.getLength() ) + aDescriptor[::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE()] <<= pImpl->aName; + + if ( pOldFilter ) + { + aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME() ] <<= ::rtl::OUString( pOldFilter->GetTypeName() ); + aDescriptor[::comphelper::MediaDescriptor::PROP_FILTERNAME()] <<= ::rtl::OUString( pOldFilter->GetFilterName() ); + } + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lDescriptor = aDescriptor.getAsConstPropertyValueList(); + sTypeName = xDetection->queryTypeByDescriptor(lDescriptor, sal_True); // lDescriptor is used as In/Out param ... dont use aDescriptor.getAsConstPropertyValueList() directly! + } + // no stream exists => try flat detection without preselection as fallback + else + sTypeName = xDetection->queryTypeByURL(sURL); + + if (sTypeName.getLength()) + { + // detect filter by given type + // In case of this matcher is bound to a particular document type: + // If there is no acceptable type for this document at all, the type detection has possibly returned something else. + // The DocumentService property is only a preselection, and all preselections are considered as optional! + // This "wrong" type will be sorted out now because we match only allowed filters to the detected type + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > lQuery(1); + lQuery[0].Name = ::rtl::OUString::createFromAscii("Name"); + lQuery[0].Value <<= sTypeName; + + const SfxFilter* pFilter = GetFilterForProps(lQuery, nMust, nDont); + if (pFilter) + { + *ppFilter = pFilter; + return ERRCODE_NONE; + } + } + } + catch(const Exception&) + {} + + return ERRCODE_ABORT; +} + +//---------------------------------------------------------------- +sal_Bool SfxFilterMatcher::IsFilterInstalled_Impl( const SfxFilter* pFilter ) +{ + if ( pFilter->GetFilterFlags() & SFX_FILTER_MUSTINSTALL ) + { + // Hier k"onnte noch eine Nachinstallation angeboten werden + String aText( SfxResId( STR_FILTER_NOT_INSTALLED ) ); + aText.SearchAndReplaceAscii( "$(FILTER)", pFilter->GetUIName() ); + QueryBox aQuery( NULL, WB_YES_NO | WB_DEF_YES, aText ); + short nRet = aQuery.Execute(); + if ( nRet == RET_YES ) + { +#ifdef DBG_UTIL + // Setup starten + InfoBox( NULL, DEFINE_CONST_UNICODE("Hier soll jetzt das Setup starten!") ).Execute(); +#endif + // Installation mu\s hier noch mitteilen, ob es geklappt hat, dann kann das + // Filterflag gel"oscht werden + } + + return ( !(pFilter->GetFilterFlags() & SFX_FILTER_MUSTINSTALL) ); + } + else if ( pFilter->GetFilterFlags() & SFX_FILTER_CONSULTSERVICE ) + { + String aText( SfxResId( STR_FILTER_CONSULT_SERVICE ) ); + aText.SearchAndReplaceAscii( "$(FILTER)", pFilter->GetUIName() ); + InfoBox ( NULL, aText ).Execute(); + return sal_False; + } + else + return sal_True; +} + + +sal_uInt32 SfxFilterMatcher::DetectFilter( SfxMedium& rMedium, const SfxFilter**ppFilter, sal_Bool /*bPlugIn*/, sal_Bool bAPI ) const +/* [Beschreibung] + + Hier wird noch die Filterauswahlbox hochgezogen. Sonst GuessFilter + */ + +{ + const SfxFilter* pOldFilter = rMedium.GetFilter(); + if ( pOldFilter ) + { + if( !IsFilterInstalled_Impl( pOldFilter ) ) + pOldFilter = 0; + else + { + SFX_ITEMSET_ARG( rMedium.GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False); + if ( ( pOldFilter->GetFilterFlags() & SFX_FILTER_PACKED ) && pSalvageItem ) + // Salvage is always done without packing + pOldFilter = 0; + } + } + + const SfxFilter* pFilter = pOldFilter; + + sal_Bool bPreview = rMedium.IsPreview_Impl(); + SFX_ITEMSET_ARG(rMedium.GetItemSet(), pReferer, SfxStringItem, SID_REFERER, FALSE); + if ( bPreview && rMedium.IsRemote() && ( !pReferer || pReferer->GetValue().CompareToAscii("private:searchfolder:",21 ) != COMPARE_EQUAL ) ) + return ERRCODE_ABORT; + + ErrCode nErr = GuessFilter( rMedium, &pFilter ); + if ( nErr == ERRCODE_ABORT ) + return nErr; + + if ( nErr == ERRCODE_IO_PENDING ) + { + *ppFilter = pFilter; + return nErr; + } + + if ( !pFilter ) + { + const SfxFilter* pInstallFilter = NULL; + + // Jetzt auch Filter testen, die nicht installiert sind ( ErrCode ist irrelevant ) + GuessFilter( rMedium, &pInstallFilter, SFX_FILTER_IMPORT, SFX_FILTER_CONSULTSERVICE ); + if ( pInstallFilter ) + { + if ( IsFilterInstalled_Impl( pInstallFilter ) ) + // Eventuell wurde der Filter nachinstalliert + pFilter = pInstallFilter; + } + else + { + // Jetzt auch Filter testen, die erst von Star bezogen werden m"ussen ( ErrCode ist irrelevant ) + GuessFilter( rMedium, &pInstallFilter, SFX_FILTER_IMPORT, 0 ); + if ( pInstallFilter ) + IsFilterInstalled_Impl( pInstallFilter ); + } + } + + sal_Bool bHidden = bPreview; + SFX_ITEMSET_ARG( rMedium.GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False); + if ( !bHidden && pFlags ) + { + String aFlags( pFlags->GetValue() ); + aFlags.ToUpperAscii(); + if( STRING_NOTFOUND != aFlags.Search( 'H' ) ) + bHidden = sal_True; + } +/* + if ( ( !pFilter || nErr == ERRCODE_SFX_CONSULTUSER ) && !bAPI && !bHidden ) + { + if ( !pFilter ) + pFilter = pOldFilter; + + String aTmpName; + if ( pFilter ) + aTmpName = pFilter->GetUIName(); + + SfxFilterMatcher *pMatcher; + if( bPlugIn && pFilter ) + pMatcher = new SfxFilterMatcher( (SfxFilterContainer *) pFilter->GetFilterContainer() ); + else + pMatcher = (SfxFilterMatcher*) this; + + SfxFilterDialog *pDlg = new SfxFilterDialog( 0, &rMedium, *pMatcher, pFilter ? &aTmpName: 0, 0 ); + const sal_Bool bOk = RET_OK == pDlg->Execute(); + if (bOk) + pFilter = pMatcher->GetFilter4UIName( pDlg->GetSelectEntry()); + + if( bPlugIn && pFilter ) + delete pMatcher; + delete pDlg; + + if ( !bOk) + nErr = ERRCODE_ABORT; + else + nErr = ERRCODE_NONE; + } +*/ + *ppFilter = pFilter; + + if ( bHidden || (bAPI && nErr == ERRCODE_SFX_CONSULTUSER) ) + nErr = pFilter ? ERRCODE_NONE : ERRCODE_ABORT; + return nErr; +} + +const SfxFilter* SfxFilterMatcher::GetFilterForProps( const com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue >& aSeq, SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory(); + ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerQuery > xTypeCFG; + if( xServiceManager.is() == sal_True ) + xTypeCFG = ::com::sun::star::uno::Reference < com::sun::star::container::XContainerQuery >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY ); + if ( xTypeCFG.is() ) + { + // make query for all types matching the properties + ::com::sun::star::uno::Reference < com::sun::star::container::XEnumeration > xEnum = xTypeCFG->createSubSetEnumerationByProperties( aSeq ); + while ( xEnum->hasMoreElements() ) + { + ::comphelper::SequenceAsHashMap aProps( xEnum->nextElement() ); + ::rtl::OUString aValue; + + // try to get the preferred filter (works without loading all filters!) + if ( (aProps[::rtl::OUString::createFromAscii("PreferredFilter")] >>= aValue) && aValue.getLength() ) + { + const SfxFilter* pFilter = SfxFilter::GetFilterByName( aValue ); + if ( !pFilter || (pFilter->GetFilterFlags() & nMust) != nMust || (pFilter->GetFilterFlags() & nDont ) ) + // check for filter flags + // pFilter == 0: if preferred filter is a Writer filter, but Writer module is not installed + continue; + + if ( pImpl->aName.getLength() ) + { + // if this is not the global FilterMatcher: check if filter matches the document type + ::rtl::OUString aService; + if ( pFilter->GetServiceName() != String(pImpl->aName) ) + { + // preferred filter belongs to another document type; now we must search the filter + pImpl->InitForIterating(); + aProps[::rtl::OUString::createFromAscii("Name")] >>= aValue; + pFilter = GetFilter4EA( aValue, nMust, nDont ); + if ( pFilter ) + return pFilter; + } + else + return pFilter; + } + else + return pFilter; + } + } + } + + return 0; +} + +const SfxFilter* SfxFilterMatcher::GetFilter4Mime( const String& rMediaType,SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + if ( pImpl->pList ) + { + sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); + for( sal_uInt16 n = 0; n < nCount; n++ ) + { + const SfxFilter* pFilter = pImpl->pList->GetObject( n ); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetMimeType() == rMediaType ) + return pFilter; + } + + return 0; + } + + com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1); + aSeq[0].Name = ::rtl::OUString::createFromAscii("MediaType"); + aSeq[0].Value <<= ::rtl::OUString( rMediaType ); + return GetFilterForProps( aSeq, nMust, nDont ); +} + +const SfxFilter* SfxFilterMatcher::GetFilter4EA( const String& rType,SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + if ( pImpl->pList ) + { + sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); + const SfxFilter* pFirst = 0; + for( sal_uInt16 n = 0; n < nCount; n++ ) + { + const SfxFilter* pFilter = pImpl->pList->GetObject( n ); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetTypeName() == rType ) + { + if (nFlags & SFX_FILTER_PREFERED) + return pFilter; + if (!pFirst) + pFirst = pFilter; + } + } + if (pFirst) + return pFirst; + + return 0; + } + + com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1); + aSeq[0].Name = ::rtl::OUString::createFromAscii("Name"); + aSeq[0].Value <<= ::rtl::OUString( rType ); + return GetFilterForProps( aSeq, nMust, nDont ); +} + +const SfxFilter* SfxFilterMatcher::GetFilter4Extension( const String& rExt, SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + if ( pImpl->pList ) + { + sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); + for( sal_uInt16 n = 0; n < nCount; n++ ) + { + const SfxFilter* pFilter = pImpl->pList->GetObject( n ); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) ) + { + String sWildCard = ToUpper_Impl( pFilter->GetWildcard().GetWildCard() ); + String sExt = ToUpper_Impl( rExt ); + + if (!sExt.Len()) + continue; + + if (sExt.GetChar(0) != (sal_Unicode)'.') + sExt.Insert((sal_Unicode)'.', 0); + + WildCard aCheck(sWildCard, ';'); + if (aCheck.Matches(sExt)) + return pFilter; + } + } + + return 0; + } + + // Use extension without dot! + String sExt( rExt ); + if ( sExt.Len() && ( sExt.GetChar(0) == (sal_Unicode)'.' )) + sExt.Erase(0,1); + + com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1); + aSeq[0].Name = ::rtl::OUString::createFromAscii("Extensions"); + ::com::sun::star::uno::Sequence < ::rtl::OUString > aExts(1); + aExts[0] = sExt; + aSeq[0].Value <<= aExts; + return GetFilterForProps( aSeq, nMust, nDont ); +} + +const SfxFilter* SfxFilterMatcher::GetFilter4ClipBoardId( sal_uInt32 nId, SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + /* + if ( pImpl->pList ) + { + sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); + for( sal_uInt16 n = 0; n < nCount; n++ ) + { + const SfxFilter* pFilter = pImpl->pList->GetObject( n ); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFormat() == nId ) + return pFilter; + } + + return 0; + } + */ + + if (nId == 0) + return 0; + + com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1); + ::rtl::OUString aName = SotExchange::GetFormatName( nId ); + aSeq[0].Name = ::rtl::OUString::createFromAscii("ClipboardFormat"); + aSeq[0].Value <<= aName; + return GetFilterForProps( aSeq, nMust, nDont ); +} + +const SfxFilter* SfxFilterMatcher::GetFilter4UIName( const String& rName, SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + pImpl->InitForIterating(); + const SfxFilter* pFirstFilter=0; + sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); + for( sal_uInt16 n = 0; n < nCount; n++ ) + { + const SfxFilter* pFilter = pImpl->pList->GetObject( n ); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if ( (nFlags & nMust) == nMust && + !(nFlags & nDont ) && pFilter->GetUIName() == rName ) + { + if ( pFilter->GetFilterFlags() & SFX_FILTER_PREFERED ) + return pFilter; + else if ( !pFirstFilter ) + pFirstFilter = pFilter; + } + } + return pFirstFilter; +} + +const SfxFilter* SfxFilterMatcher::GetFilter4FilterName( const String& rName, SfxFilterFlags nMust, SfxFilterFlags nDont ) const +{ + String aName( rName ); + USHORT nIndex = aName.SearchAscii(": "); + if ( nIndex != STRING_NOTFOUND ) + { + DBG_ERROR("Old filter name used!"); + aName = rName.Copy( nIndex + 2 ); + } + + if ( bFirstRead ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory(); + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG ; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xTypeCFG ; + if( xServiceManager.is() == sal_True ) + { + xFilterCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY ); + xTypeCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY ); + } + + if( xFilterCFG.is() && xTypeCFG.is() ) + { + if ( !pFilterArr ) + CreateFilterArr(); + else + { + for( sal_uInt16 n=0; n<pFilterArr->Count(); n++ ) + { + const SfxFilter* pFilter = pFilterArr->GetObject( n ); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFilterName().CompareIgnoreCaseToAscii( aName ) == COMPARE_EQUAL ) + return pFilter; + } + } + + SfxFilterContainer::ReadSingleFilter_Impl( rName, xTypeCFG, xFilterCFG, FALSE ); + } + } + + SfxFilterList_Impl* pList = pImpl->pList; + if ( !pList ) + pList = pFilterArr; + + sal_uInt16 nCount = ( sal_uInt16 ) pList->Count(); + for( sal_uInt16 n = 0; n < nCount; n++ ) + { + const SfxFilter* pFilter = pList->GetObject( n ); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFilterName().CompareIgnoreCaseToAscii( aName ) == COMPARE_EQUAL ) + return pFilter; + } + + return NULL; +} + +IMPL_STATIC_LINK( SfxFilterMatcher, MaybeFileHdl_Impl, String*, pString ) +{ + const SfxFilter* pFilter = pThis->GetFilter4Extension( *pString, SFX_FILTER_IMPORT ); + if( pFilter && !pFilter->GetWildcard().Matches( String() ) && + pFilter->GetWildcard() != DEFINE_CONST_UNICODE("*.*") && pFilter->GetWildcard() != '*' ) + return sal_True; + return sal_False; +} + +//---------------------------------------------------------------- + +SfxFilterMatcherIter::SfxFilterMatcherIter( + const SfxFilterMatcher* pMatchP, + SfxFilterFlags nOrMaskP, SfxFilterFlags nAndMaskP ) + : nOrMask( nOrMaskP ), nAndMask( nAndMaskP ), + nCurrent(0), pMatch( pMatchP->pImpl) +{ + if( nOrMask == 0xffff ) //Wg. Fehlbuild auf s + nOrMask = 0; + pMatch->InitForIterating(); +} + +//---------------------------------------------------------------- + +const SfxFilter* SfxFilterMatcherIter::Find_Impl() +{ + const SfxFilter* pFilter = 0; + while( nCurrent < pMatch->pList->Count() ) + { + pFilter = pMatch->pList->GetObject(nCurrent++); + SfxFilterFlags nFlags = pFilter->GetFilterFlags(); + if( ((nFlags & nOrMask) == nOrMask ) && !(nFlags & nAndMask ) ) + break; + pFilter = 0; + } + + return pFilter; +} + +const SfxFilter* SfxFilterMatcherIter::First() +{ + nCurrent = 0; + return Find_Impl(); +} + +//---------------------------------------------------------------- + +const SfxFilter* SfxFilterMatcherIter::Next() +{ + return Find_Impl(); +} + +/*--------------------------------------------------------------- + helper to build own formated string from given stringlist by + using given seperator + ---------------------------------------------------------------*/ +::rtl::OUString implc_convertStringlistToString( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& lList , + const sal_Unicode& cSeperator, + const ::rtl::OUString& sPrefix ) +{ + ::rtl::OUStringBuffer sString ( 1000 ) ; + sal_Int32 nCount = lList.getLength(); + sal_Int32 nItem = 0 ; + for( nItem=0; nItem<nCount; ++nItem ) + { + if( sPrefix.getLength() > 0 ) + { + sString.append( sPrefix ); + } + sString.append( lList[nItem] ); + if( nItem+1<nCount ) + { + sString.append( cSeperator ); + } + } + return sString.makeStringAndClear(); +} + + +void SfxFilterContainer::ReadSingleFilter_Impl( + const ::rtl::OUString& rName, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xTypeCFG, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xFilterCFG, + BOOL bUpdate + ) +{ + ::rtl::OUString sFilterName( rName ); + SfxFilterList_Impl& rList = *pFilterArr; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lFilterProperties ; + ::com::sun::star::uno::Any aResult; + try + { + aResult = xFilterCFG->getByName( sFilterName ); + } + catch( ::com::sun::star::container::NoSuchElementException& ) + { + aResult = ::com::sun::star::uno::Any(); + } + + if( aResult >>= lFilterProperties ) + { + // collect informations to add filter to container + // (attention: some informations aren't available on filter directly ... you must search for corresponding type too!) + sal_Int32 nFlags = 0 ; + sal_Int32 nClipboardId = 0 ; + sal_Int32 nDocumentIconId = 0 ; + sal_Int32 nFormatVersion = 0 ; + ::rtl::OUString sMimeType ; + ::rtl::OUString sType ; + ::rtl::OUString sUIName ; + ::rtl::OUString sHumanName ; + ::rtl::OUString sDefaultTemplate ; + ::rtl::OUString sUserData ; + ::rtl::OUString sExtension ; + ::rtl::OUString sPattern ; + ::rtl::OUString sServiceName ; + + // first get directly available properties + sal_Int32 nFilterPropertyCount = lFilterProperties.getLength(); + sal_Int32 nFilterProperty = 0 ; + for( nFilterProperty=0; nFilterProperty<nFilterPropertyCount; ++nFilterProperty ) + { + if( lFilterProperties[nFilterProperty].Name.compareToAscii( "FileFormatVersion" ) == 0 ) + { + lFilterProperties[nFilterProperty].Value >>= nFormatVersion; + } + else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "TemplateName" ) == 0 ) + { + lFilterProperties[nFilterProperty].Value >>= sDefaultTemplate; + } + else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "Flags" ) == 0 ) + { + lFilterProperties[nFilterProperty].Value >>= nFlags; + } + else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "UIName" ) == 0 ) + { + lFilterProperties[nFilterProperty].Value >>= sUIName; + } + else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "UserData" ) == 0 ) + { + ::com::sun::star::uno::Sequence< ::rtl::OUString > lUserData; + lFilterProperties[nFilterProperty].Value >>= lUserData; + sUserData = implc_convertStringlistToString( lUserData, ',', ::rtl::OUString() ); + } + else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "DocumentService" ) == 0 ) + { + lFilterProperties[nFilterProperty].Value >>= sServiceName; + } + else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "Type" ) == 0 ) + { + lFilterProperties[nFilterProperty].Value >>= sType; + // Try to get filter .. but look for any exceptions! + // May be filter was deleted by another thread ... + try + { + aResult = xTypeCFG->getByName( sType ); + } + catch( ::com::sun::star::container::NoSuchElementException& ) + { + aResult = ::com::sun::star::uno::Any(); + } + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lTypeProperties; + if( aResult >>= lTypeProperties ) + { + // get indirect available properties then (types) + sal_Int32 nTypePropertyCount = lTypeProperties.getLength(); + sal_Int32 nTypeProperty = 0 ; + for( nTypeProperty=0; nTypeProperty<nTypePropertyCount; ++nTypeProperty ) + { + if( lTypeProperties[nTypeProperty].Name.compareToAscii( "ClipboardFormat" ) == 0 ) + { + lTypeProperties[nTypeProperty].Value >>= sHumanName; + } + else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "DocumentIconID" ) == 0 ) + { + lTypeProperties[nTypeProperty].Value >>= nDocumentIconId; + } + else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "MediaType" ) == 0 ) + { + lTypeProperties[nTypeProperty].Value >>= sMimeType; + } + else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "Extensions" ) == 0 ) + { + ::com::sun::star::uno::Sequence< ::rtl::OUString > lExtensions; + lTypeProperties[nTypeProperty].Value >>= lExtensions; + sExtension = implc_convertStringlistToString( lExtensions, ';', DEFINE_CONST_UNICODE("*.") ); + } + else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "URLPattern" ) == 0 ) + { + ::com::sun::star::uno::Sequence< ::rtl::OUString > lPattern; + lTypeProperties[nTypeProperty].Value >>= lPattern; + sPattern = implc_convertStringlistToString( lPattern, ';', ::rtl::OUString() ); + } + } + } + } + } + + if ( !sServiceName.getLength() ) + return; + + // old formats are found ... using HumanPresentableName! + if( sHumanName.getLength() ) + { + nClipboardId = SotExchange::RegisterFormatName( sHumanName ); + + // #100570# For external filters ignore clipboard IDs + if((nFlags & SFX_FILTER_STARONEFILTER) == SFX_FILTER_STARONEFILTER) + { + nClipboardId = 0; + } + } + // register SfxFilter + // first erase module name from old filter names! + // e.g: "scalc: DIF" => "DIF" + sal_Int32 nStartRealName = sFilterName.indexOf( DEFINE_CONST_UNICODE(": "), 0 ); + if( nStartRealName != -1 ) + { + DBG_ERROR("Old format, not supported!"); + sFilterName = sFilterName.copy( nStartRealName+2 ); + } + + SfxFilter* pFilter = bUpdate ? (SfxFilter*) SfxFilter::GetFilterByName( sFilterName ) : 0; + BOOL bNew = FALSE; + if (!pFilter) + { + bNew = TRUE; + pFilter = new SfxFilter( sFilterName , + sExtension , + nFlags , + nClipboardId , + sType , + (USHORT)nDocumentIconId , + sMimeType , + sUserData , + sServiceName ); + } + else + { + pFilter->aFilterName = sFilterName; + pFilter->aWildCard = WildCard(sExtension, ';'); + pFilter->nFormatType = nFlags; + pFilter->lFormat = nClipboardId; + pFilter->aTypeName = sType; + pFilter->nDocIcon = (USHORT)nDocumentIconId; + pFilter->aMimeType = sMimeType; + pFilter->aUserData = sUserData; + pFilter->aServiceName = sServiceName; + } + + // Don't forget to set right UIName! + // Otherwise internal name is used as fallback ... + pFilter->SetUIName( sUIName ); + pFilter->SetDefaultTemplate( sDefaultTemplate ); + if( nFormatVersion ) + { + pFilter->SetVersion( nFormatVersion ); + } + pFilter->SetURLPattern(sPattern); + + if (bNew) + rList.Insert( pFilter, USHRT_MAX ); + } +} + +void SfxFilterContainer::ReadFilters_Impl( BOOL bUpdate ) +{ + RTL_LOGFILE_CONTEXT( aMeasure, "sfx2 (as96863) ::SfxFilterContainer::ReadFilters" ); + if ( !pFilterArr ) + CreateFilterArr(); + + bFirstRead = FALSE; + SfxFilterList_Impl& rList = *pFilterArr; + + try + { + // get the FilterFactory service to access the registered filters ... and types! + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory(); + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG ; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xTypeCFG ; + if( xServiceManager.is() == sal_True ) + { + xFilterCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY ); + xTypeCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY ); + } + + if( + ( xFilterCFG.is() == sal_True ) && + ( xTypeCFG.is() == sal_True ) + ) + { + // select right query to get right set of filters for search modul + ::com::sun::star::uno::Sequence< ::rtl::OUString > lFilterNames = xFilterCFG->getElementNames(); + if ( lFilterNames.getLength() ) + { + // If list of filters already exist ... + // ReadExternalFilters must work in update mode. + // Best way seams to mark all filters NOT_INSTALLED + // and change it back for all valid filters afterwards. + if( rList.Count() > 0 ) + { + bUpdate = TRUE; + USHORT nCount = (USHORT)rList.Count(); + SfxFilter* pFilter; + for (USHORT f=0; f<nCount; ++f) + { + pFilter = NULL; + pFilter = rList.GetObject(f); + pFilter->nFormatType |= SFX_FILTER_NOTINSTALLED; + } + } + + // get all properties of filters ... put it into the filter container + sal_Int32 nFilterCount = lFilterNames.getLength(); + sal_Int32 nFilter=0; + for( nFilter=0; nFilter<nFilterCount; ++nFilter ) + { + // Try to get filter .. but look for any exceptions! + // May be filter was deleted by another thread ... + ::rtl::OUString sFilterName = lFilterNames[nFilter]; + + // This debug code can be used to break on inserting/updating + // special debug filters at runtime. + // Otherwise you have to check more then 300 filter names manually .-) + // And conditional breakpoints on unicode values seams not to be supported .-( + #ifdef DEBUG + bool bDBGStop = FALSE; + if (sFilterName.indexOf(::rtl::OUString::createFromAscii("DBG_"))>-1) + bDBGStop = TRUE; + #endif + + ReadSingleFilter_Impl( sFilterName, xTypeCFG, xFilterCFG, bUpdate ); + } + } + } + } + catch( ::com::sun::star::uno::Exception& ) + { + DBG_ASSERT( sal_False, "SfxFilterContainer::ReadFilter()\nException detected. Possible not all filters could be cached.\n" ); + } + + if ( pImplArr && bUpdate ) + { + // global filter arry was modified, factory specific ones might need an update too + for ( USHORT n=0; n<pImplArr->Count(); n++ ) + pImplArr->GetObject(n)->Update(); + } +} diff --git a/sfx2/source/bastyp/fltfnc.src b/sfx2/source/bastyp/fltfnc.src new file mode 100644 index 000000000000..4203163eceeb --- /dev/null +++ b/sfx2/source/bastyp/fltfnc.src @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + // include --------------------------------------------------------------- +#include <sfx2/sfx.hrc> +#include "bastyp.hrc" +#include "helpid.hrc" +String STR_FILTER_NOT_INSTALLED +{ + Text [ en-US ] = "The selected filter $(FILTER) has not been installed.\nWould you like to do this now?"; +}; + +String STR_FILTER_CONSULT_SERVICE +{ + Text [ en-US ] = "The selected filter $(FILTER) is not included in your edition.\nYou can find information about orders on our homepage."; +}; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sfx2/source/bastyp/fltlst.cxx b/sfx2/source/bastyp/fltlst.cxx new file mode 100644 index 000000000000..aab358b50220 --- /dev/null +++ b/sfx2/source/bastyp/fltlst.cxx @@ -0,0 +1,118 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#include "fltlst.hxx" + +//***************************************************************************************************************** +// includes +//***************************************************************************************************************** +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <comphelper/processfactory.hxx> + +#include <sfx2/sfxuno.hxx> +#include <sfx2/docfac.hxx> + +#include <vcl/svapp.hxx> +#include <vos/mutex.hxx> + +//***************************************************************************************************************** +// namespaces +//***************************************************************************************************************** +using namespace ::com::sun::star; + +//***************************************************************************************************************** +// definitions +//***************************************************************************************************************** + +/*-************************************************************************************************************//** + @short ctor + @descr These initialize an instance of a SfxFilterListener class. Created object listen automaticly + on right FilterFactory-Service for all changes and synchronize right SfxFilterContainer with + corresponding framework-cache. + We use given "sFactory" value to decide which query must be used to fill "pContainer" with new values. + Given "pContainer" hold us alive as uno reference and we use it to syschronize it with framework caches. + We will die, if he die! see dtor for further informations. + + @seealso dtor + @seealso class framework::FilterCache + @seealso service ::document::FilterFactory + + @param "sFactory" , short name of module which contains filter container + @param "pContainer", pointer to filter container which will be informed + @return - + + @onerror We show some assertions in non product version. + Otherwise we do nothing! + @threadsafe yes + + @last_change 17.10.2001 10:27 +*//*-*************************************************************************************************************/ +SfxFilterListener::SfxFilterListener() +{ + uno::Reference< lang::XMultiServiceFactory > xSmgr = ::comphelper::getProcessServiceFactory(); + if( xSmgr.is() == sal_True ) + { + uno::Reference< util::XRefreshable > xNotifier( xSmgr->createInstance( DEFINE_CONST_OUSTRING("com.sun.star.document.FilterConfigRefresh") ), uno::UNO_QUERY ); + if( xNotifier.is() == sal_True ) + { + m_xFilterCache = xNotifier; + m_xFilterCache->addRefreshListener( this ); + } + } +} + +SfxFilterListener::~SfxFilterListener() +{ +} + +void SAL_CALL SfxFilterListener::refreshed( const lang::EventObject& aSource ) throw( uno::RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + uno::Reference< util::XRefreshable > xContainer( aSource.Source, uno::UNO_QUERY ); + if( + (xContainer.is() ) && + (xContainer==m_xFilterCache) + ) + { + SfxFilterContainer::ReadFilters_Impl( TRUE ); + } +} + +void SAL_CALL SfxFilterListener::disposing( const lang::EventObject& aSource ) throw( uno::RuntimeException ) +{ + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + uno::Reference< util::XRefreshable > xNotifier( aSource.Source, uno::UNO_QUERY ); + if (!xNotifier.is()) + return; + + if (xNotifier == m_xFilterCache) + m_xFilterCache.clear(); +} diff --git a/sfx2/source/bastyp/fltlst.hxx b/sfx2/source/bastyp/fltlst.hxx new file mode 100644 index 000000000000..b3afb425634d --- /dev/null +++ b/sfx2/source/bastyp/fltlst.hxx @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SFX_FLTLST_HXX +#define _SFX_FLTLST_HXX + +//***************************************************************************************************************** +// includes +//***************************************************************************************************************** +#include <sfx2/fcontnr.hxx> +#include <cppuhelper/implbase1.hxx> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/util/XRefreshable.hpp> +#include <com/sun/star/util/XRefreshListener.hpp> +#include <com/sun/star/document/XEventListener.hpp> +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> + +//***************************************************************************************************************** +// declarations +//***************************************************************************************************************** +class SfxFilterListener : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XRefreshListener > +{ + // member + private: + ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshable > m_xFilterCache; + + // c++ interface + public: + SfxFilterListener(); + ~SfxFilterListener(); + + // uno interface + public: + // XRefreshListener + virtual void SAL_CALL refreshed( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException ); + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException ); + +}; // SfxFilterListener + +#endif // _SFX_FLTLST_HXX diff --git a/sfx2/source/bastyp/frmhtml.cxx b/sfx2/source/bastyp/frmhtml.cxx new file mode 100644 index 000000000000..8ecfa6b3081a --- /dev/null +++ b/sfx2/source/bastyp/frmhtml.cxx @@ -0,0 +1,163 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#include <tools/list.hxx> +#include <tools/table.hxx> +#include <svtools/htmltokn.h> +#include <svtools/asynclink.hxx> + +#define _SVSTDARR_USHORTS +#define _SVSTDARR_ULONGS +#include <svl/svstdarr.hxx> + +#include <sfx2/sfx.hrc> + +#include <sfx2/frmhtml.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/evntconf.hxx> +#include <sfx2/request.hxx> +#include <sfx2/fcontnr.hxx> +#include "sfxtypes.hxx" + +#define SFX_HTMLFRMSIZE_REL 0x0001 +#define SFX_HTMLFRMSIZE_PERCENT 0x0002 + +static sal_Char __READONLY_DATA sHTML_SC_yes[] = "YES"; +static sal_Char __READONLY_DATA sHTML_SC_no[] = "NO"; +static sal_Char __READONLY_DATA sHTML_SC_auto[] = "AUTO"; + +#define HTML_O_READONLY "READONLY" +#define HTML_O_EDIT "EDIT" + +static HTMLOptionEnum __READONLY_DATA aScollingTable[] = +{ + { sHTML_SC_yes, ScrollingYes }, + { sHTML_SC_no, ScrollingNo }, + { sHTML_SC_auto, ScrollingAuto }, + { 0, 0 } +}; + +void SfxFrameHTMLParser::ParseFrameOptions( SfxFrameDescriptor *pFrame, const HTMLOptions *pOptions, const String& rBaseURL ) +{ + // die Optionen holen und setzen + Size aMargin( pFrame->GetMargin() ); + + // MIB 15.7.97: Netscape scheint marginwidth auf 0 zu setzen, sobald + // marginheight gesetzt wird und umgekehrt. Machen wir jetzt wegen + // bug #41665# auch so. + // Netscape l"a\st aber ein direktes Setzen auf 0 nicht zu, IE4.0 schon. + // Den Bug machen wir nicht mit! + BOOL bMarginWidth = FALSE, bMarginHeight = FALSE; + + USHORT nArrLen = pOptions->Count(); + for ( USHORT i=0; i<nArrLen; i++ ) + { + const HTMLOption *pOption = (*pOptions)[i]; + switch( pOption->GetToken() ) + { + case HTML_O_BORDERCOLOR: + { + Color aColor; + pOption->GetColor( aColor ); + pFrame->SetWallpaper( Wallpaper( aColor ) ); + break; + } + case HTML_O_SRC: + pFrame->SetURL( + String( + INetURLObject::GetAbsURL( + rBaseURL, pOption->GetString())) ); + break; + case HTML_O_NAME: + pFrame->SetName( pOption->GetString() ); + break; + case HTML_O_MARGINWIDTH: + aMargin.Width() = pOption->GetNumber(); + +// if( aMargin.Width() < 1 ) +// aMargin.Width() = 1; + if( !bMarginHeight ) + aMargin.Height() = 0; + bMarginWidth = TRUE; + break; + case HTML_O_MARGINHEIGHT: + aMargin.Height() = pOption->GetNumber(); + +// if( aMargin.Height() < 1 ) +// aMargin.Height() = 1; + if( !bMarginWidth ) + aMargin.Width() = 0; + bMarginHeight = TRUE; + break; + case HTML_O_SCROLLING: + pFrame->SetScrollingMode( + (ScrollingMode)pOption->GetEnum( aScollingTable, + ScrollingAuto ) ); + break; + case HTML_O_FRAMEBORDER: + { + String aStr = pOption->GetString(); + BOOL bBorder = TRUE; + if ( aStr.EqualsIgnoreCaseAscii("NO") || + aStr.EqualsIgnoreCaseAscii("0") ) + bBorder = FALSE; + pFrame->SetFrameBorder( bBorder ); + break; + } + case HTML_O_NORESIZE: + pFrame->SetResizable( FALSE ); + break; + default: + if ( pOption->GetTokenString().EqualsIgnoreCaseAscii( + HTML_O_READONLY ) ) + { + String aStr = pOption->GetString(); + BOOL bReadonly = TRUE; + if ( aStr.EqualsIgnoreCaseAscii("FALSE") ) + bReadonly = FALSE; + pFrame->SetReadOnly( bReadonly ); + } + else if ( pOption->GetTokenString().EqualsIgnoreCaseAscii( + HTML_O_EDIT ) ) + { + String aStr = pOption->GetString(); + BOOL bEdit = TRUE; + if ( aStr.EqualsIgnoreCaseAscii("FALSE") ) + bEdit = FALSE; + pFrame->SetEditable( bEdit ); + } + + break; + } + } + + pFrame->SetMargin( aMargin ); +} diff --git a/sfx2/source/bastyp/frmhtmlw.cxx b/sfx2/source/bastyp/frmhtmlw.cxx new file mode 100644 index 000000000000..df81eb3f4039 --- /dev/null +++ b/sfx2/source/bastyp/frmhtmlw.cxx @@ -0,0 +1,381 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#ifndef _INETDEF_HXX +#include <svl/inetdef.hxx> +#endif +#include "svtools/htmlkywd.hxx" + +//!(dv) #include <chaos2/cntapi.hxx> +#include <rtl/tencinfo.h> + +#include <unotools/configmgr.hxx> +#include "svl/urihelper.hxx" +#include <tools/datetime.hxx> + +#include <sfx2/frmhtmlw.hxx> +#include <sfx2/evntconf.hxx> +#include <sfx2/frame.hxx> +#include <sfx2/app.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/docfile.hxx> +#include "sfxresid.hxx" +#include <sfx2/objsh.hxx> +#include <sfx2/sfx.hrc> +#include "bastyp.hrc" + +#include <comphelper/string.hxx> +#include <comphelper/processfactory.hxx> + +#include <com/sun/star/script/XTypeConverter.hpp> +#include <com/sun/star/document/XDocumentProperties.hpp> + + +// ----------------------------------------------------------------------- + +using namespace ::com::sun::star; + +static sal_Char __READONLY_DATA sHTML_SC_yes[] = "YES"; +static sal_Char __READONLY_DATA sHTML_SC_no[] = "NO"; +static sal_Char __READONLY_DATA sHTML_SC_auto[] = "AUTO"; +static sal_Char __READONLY_DATA sHTML_MIME_text_html[] = "text/html; charset="; + +/* not used anymore? +static HTMLOutEvent __FAR_DATA aFrameSetEventTable[] = +{ + { sHTML_O_SDonload, sHTML_O_onload, SFX_EVENT_OPENDOC }, + { sHTML_O_SDonunload, sHTML_O_onunload, SFX_EVENT_PREPARECLOSEDOC }, + { sHTML_O_SDonfocus, sHTML_O_onfocus, SFX_EVENT_ACTIVATEDOC }, + { sHTML_O_SDonblur, sHTML_O_onblur, SFX_EVENT_DEACTIVATEDOC }, + { 0, 0, 0 } +}; +*/ + +#if defined(UNX) +const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\012"; +#else +const sal_Char __FAR_DATA SfxFrameHTMLWriter::sNewLine[] = "\015\012"; +#endif + +void SfxFrameHTMLWriter::OutMeta( SvStream& rStrm, + const sal_Char *pIndent, + const String& rName, + const String& rContent, BOOL bHTTPEquiv, + rtl_TextEncoding eDestEnc, + String *pNonConvertableChars ) +{ + rStrm << sNewLine; + if( pIndent ) + rStrm << pIndent; + + ByteString sOut( '<' ); + (((sOut += OOO_STRING_SVTOOLS_HTML_meta) += ' ') + += (bHTTPEquiv ? OOO_STRING_SVTOOLS_HTML_O_httpequiv : OOO_STRING_SVTOOLS_HTML_O_name)) += "=\""; + rStrm << sOut.GetBuffer(); + + HTMLOutFuncs::Out_String( rStrm, rName, eDestEnc, pNonConvertableChars ); + + ((sOut = "\" ") += OOO_STRING_SVTOOLS_HTML_O_content) += "=\""; + rStrm << sOut.GetBuffer(); + + HTMLOutFuncs::Out_String( rStrm, rContent, eDestEnc, pNonConvertableChars ) << "\">"; +} + +void SfxFrameHTMLWriter::Out_DocInfo( SvStream& rStrm, const String& rBaseURL, + const uno::Reference<document::XDocumentProperties> & i_xDocProps, + const sal_Char *pIndent, + rtl_TextEncoding eDestEnc, + String *pNonConvertableChars ) +{ + const sal_Char *pCharSet = + rtl_getBestMimeCharsetFromTextEncoding( eDestEnc ); + + if( pCharSet ) + { + String aContentType = String::CreateFromAscii( sHTML_MIME_text_html ); + aContentType.AppendAscii( pCharSet ); + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_content_type, aContentType, TRUE, + eDestEnc, pNonConvertableChars ); + } + + // Titel (auch wenn er leer ist) + rStrm << sNewLine; + if( pIndent ) + rStrm << pIndent; + HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title ); + if( i_xDocProps.is() ) + { + const String& rTitle = i_xDocProps->getTitle(); + if( rTitle.Len() ) + HTMLOutFuncs::Out_String( rStrm, rTitle, eDestEnc, pNonConvertableChars ); + } + HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title, FALSE ); + + // Target-Frame + if( i_xDocProps.is() ) + { + const String& rTarget = i_xDocProps->getDefaultTarget(); + if( rTarget.Len() ) + { + rStrm << sNewLine; + if( pIndent ) + rStrm << pIndent; + + ByteString sOut( '<' ); + (((sOut += OOO_STRING_SVTOOLS_HTML_base) += ' ') += OOO_STRING_SVTOOLS_HTML_O_target) += "=\""; + rStrm << sOut.GetBuffer(); + HTMLOutFuncs::Out_String( rStrm, rTarget, eDestEnc, pNonConvertableChars ) + << "\">"; + } + } + + // Who we are + String sGenerator( SfxResId( STR_HTML_GENERATOR ) ); + sGenerator.SearchAndReplaceAscii( "%1", String( DEFINE_CONST_UNICODE( TOOLS_INETDEF_OS ) ) ); + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_generator, sGenerator, FALSE, eDestEnc, pNonConvertableChars ); + + if( i_xDocProps.is() ) + { + // Reload + if( (i_xDocProps->getAutoloadSecs() != 0) || + !i_xDocProps->getAutoloadURL().equalsAscii("") ) + { + String sContent = String::CreateFromInt32( + i_xDocProps->getAutoloadSecs() ); + + const String &rReloadURL = i_xDocProps->getAutoloadURL(); + if( rReloadURL.Len() ) + { + sContent.AppendAscii( ";URL=" ); + sContent += String( + URIHelper::simpleNormalizedMakeRelative( + rBaseURL, rReloadURL)); + } + + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_refresh, sContent, TRUE, + eDestEnc, pNonConvertableChars ); + } + + // Author + const String& rAuthor = i_xDocProps->getAuthor(); + if( rAuthor.Len() ) + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_author, rAuthor, FALSE, + eDestEnc, pNonConvertableChars ); + + // created + ::util::DateTime uDT = i_xDocProps->getCreationDate(); + Date aD(uDT.Day, uDT.Month, uDT.Year); + Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + String sOut = String::CreateFromInt32(aD.GetDate()); + sOut += ';'; + sOut += String::CreateFromInt32(aT.GetTime()); + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_created, sOut, FALSE, + eDestEnc, pNonConvertableChars ); + + // changedby + const String& rChangedBy = i_xDocProps->getModifiedBy(); + if( rChangedBy.Len() ) + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changedby, rChangedBy, FALSE, + eDestEnc, pNonConvertableChars ); + + // changed + uDT = i_xDocProps->getModificationDate(); + Date aD2(uDT.Day, uDT.Month, uDT.Year); + Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + sOut = String::CreateFromInt32(aD2.GetDate()); + sOut += ';'; + sOut += String::CreateFromInt32(aT2.GetTime()); + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changed, sOut, FALSE, + eDestEnc, pNonConvertableChars ); + + // Subject + const String& rTheme = i_xDocProps->getSubject(); + if( rTheme.Len() ) + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_classification, rTheme, FALSE, + eDestEnc, pNonConvertableChars ); + + // Description + const String& rComment = i_xDocProps->getDescription(); + if( rComment.Len() ) + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_description, rComment, FALSE, + eDestEnc, pNonConvertableChars); + + // Keywords + String Keywords = ::comphelper::string::convertCommaSeparated( + i_xDocProps->getKeywords()); + if( Keywords.Len() ) + OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_keywords, Keywords, FALSE, + eDestEnc, pNonConvertableChars); + + uno::Reference < script::XTypeConverter > xConverter( + ::comphelper::getProcessServiceFactory()->createInstance( + ::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), + uno::UNO_QUERY_THROW ); + uno::Reference<beans::XPropertySet> xUserDefinedProps( + i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); + DBG_ASSERT(xUserDefinedProps.is(), "UserDefinedProperties is null"); + uno::Reference<beans::XPropertySetInfo> xPropInfo = + xUserDefinedProps->getPropertySetInfo(); + DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null"); + uno::Sequence<beans::Property> props = xPropInfo->getProperties(); + for (sal_Int32 i = 0; i < props.getLength(); ++i) { + try { + ::rtl::OUString name = props[i].Name; + ::rtl::OUString str; + uno::Any aStr = xConverter->convertToSimpleType( + xUserDefinedProps->getPropertyValue(name), + uno::TypeClass_STRING); + aStr >>= str; + String valstr(str); + valstr.EraseTrailingChars(); + OutMeta( rStrm, pIndent, name, valstr, FALSE, + eDestEnc, pNonConvertableChars ); + } catch (uno::Exception &) { + // may happen with concurrent modification... + DBG_WARNING("SfxFrameHTMLWriter::Out_DocInfo: exception"); + } + } + } +} +/* +void SfxFrameHTMLWriter::OutHeader( rtl_TextEncoding eDestEnc ) +{ + // <HTML> + // <HEAD> + // <TITLE>Titel</TITLE> + // </HEAD> + HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_html ) << sNewLine; + HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_head ); + + Out_DocInfo( Strm(), &pDoc->GetDocInfo(), "\t", eDestEnc ); + Strm() << sNewLine; + HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_head, FALSE ) << sNewLine; + +//! OutScript(); // Hier fehlen noch die Scripten im Header +} +*/ + +void SfxFrameHTMLWriter::Out_FrameDescriptor( + SvStream& rOut, const String& rBaseURL, const uno::Reference < beans::XPropertySet >& xSet, + rtl_TextEncoding eDestEnc, String *pNonConvertableChars ) +{ + try + { + ByteString sOut; + ::rtl::OUString aStr; + uno::Any aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameURL") ); + if ( (aAny >>= aStr) && aStr.getLength() ) + { + String aURL = INetURLObject( aStr ).GetMainURL( INetURLObject::DECODE_TO_IURI ); + if( aURL.Len() ) + { + aURL = URIHelper::simpleNormalizedMakeRelative( + rBaseURL, aURL ); + ((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_src) += "=\""; + rOut << sOut.GetBuffer(); + HTMLOutFuncs::Out_String( rOut, aURL, eDestEnc, pNonConvertableChars ); + sOut = '\"'; + } + } + + aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameName") ); + if ( (aAny >>= aStr) && aStr.getLength() ) + { + ((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_name) += "=\""; + rOut << sOut.GetBuffer(); + HTMLOutFuncs::Out_String( rOut, aStr, eDestEnc, pNonConvertableChars ); + sOut = '\"'; + } + + sal_Int32 nVal = SIZE_NOT_SET; + aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth") ); + if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET ) + (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_marginwidth) += '=') += ByteString::CreateFromInt32( nVal ); + aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight") ); + if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET ) + (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_marginheight) += '=') += ByteString::CreateFromInt32( nVal ); + + sal_Bool bVal = sal_True; + aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll") ); + if ( (aAny >>= bVal) && !bVal ) + { + aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode") ); + if ( aAny >>= bVal ) + { + const sal_Char *pStr = bVal ? sHTML_SC_yes : sHTML_SC_no; + (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_scrolling) += '=') += pStr; + } + } + + // frame border (MS+Netscape-Erweiterung) + aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder") ); + if ( (aAny >>= bVal) && !bVal ) + { + aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder") ); + if ( aAny >>= bVal ) + { + const char* pStr = bVal ? sHTML_SC_yes : sHTML_SC_no; + (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_frameborder) += '=') += pStr; + } + } + + // TODO/LATER: currently not supported attributes + // resize + //if( !pFrame->IsResizable() ) + // (sOut += ' ') += sHTML_O_noresize; + // + //if ( pFrame->GetWallpaper() ) + //{ + // ((sOut += ' ') += sHTML_O_bordercolor) += '='; + // rOut << sOut.GetBuffer(); + // HTMLOutFuncs::Out_Color( rOut, pFrame->GetWallpaper()->GetColor(), eDestEnc ); + //} + //else + rOut << sOut.GetBuffer(); + } + catch ( uno::Exception& ) + { + } +} + +String SfxFrameHTMLWriter::CreateURL( SfxFrame* pFrame ) +{ + String aRet; + SfxObjectShell* pShell = pFrame->GetCurrentDocument(); + if( !aRet.Len() && pShell ) + { + aRet = pShell->GetMedium()->GetName(); +//!(dv) CntAnchor::ToPresentationURL( aRet ); + } + + return aRet; +} + + diff --git a/sfx2/source/bastyp/helper.cxx b/sfx2/source/bastyp/helper.cxx new file mode 100644 index 000000000000..091651fedbc2 --- /dev/null +++ b/sfx2/source/bastyp/helper.cxx @@ -0,0 +1,879 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#include "helper.hxx" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/ucb/CommandAbortedException.hpp> +#include <com/sun/star/ucb/IllegalIdentifierException.hpp> +#include <com/sun/star/ucb/NameClash.hpp> +#include <com/sun/star/ucb/NumberedSortingInfo.hpp> +#include <com/sun/star/ucb/TransferInfo.hpp> +#include <com/sun/star/ucb/XAnyCompareFactory.hpp> +#include <com/sun/star/ucb/XCommandInfo.hpp> +#include <com/sun/star/ucb/XContentAccess.hpp> +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <unotools/localedatawrapper.hxx> +#include <rtl/strbuf.hxx> + +#include <tools/ref.hxx> +#include <tools/debug.hxx> +#include <tools/urlobj.hxx> +#include <tools/datetime.hxx> +#include <vcl/svapp.hxx> +#include <ucbhelper/content.hxx> +#include <ucbhelper/commandenvironment.hxx> +#include <comphelper/processfactory.hxx> +#include <osl/file.hxx> + +using namespace com::sun::star; +using namespace rtl; +using namespace comphelper; +using namespace osl; + +DECLARE_LIST( StringList_Impl, OUString* ) + +#define CONVERT_DATETIME( aUnoDT, aToolsDT ) \ + aToolsDT = DateTime( Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ), \ + Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ) ); + +void AppendDateTime_Impl( const util::DateTime rDT, + String& rRow, const LocaleDataWrapper& rWrapper ) +{ + DateTime aDT; + CONVERT_DATETIME( rDT, aDT ); + String aDateStr = rWrapper.getDate( aDT ); + aDateStr += String::CreateFromAscii( ", " ); + aDateStr += rWrapper.getTime( aDT ); + rRow += aDateStr; +} + +// SfxContentHelper ------------------------------------------------------ + +sal_Bool SfxContentHelper::Transfer_Impl( const String& rSource, const String& rDest, sal_Bool bMoveData, sal_Int32 nNameClash ) +{ + sal_Bool bRet = sal_True, bKillSource = sal_False; + INetURLObject aSourceObj( rSource ); + DBG_ASSERT( aSourceObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + + INetURLObject aDestObj( rDest ); + DBG_ASSERT( aDestObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + if ( bMoveData && aSourceObj.GetProtocol() != aDestObj.GetProtocol() ) + { + bMoveData = sal_False; + bKillSource = sal_True; + } + String aName = aDestObj.getName(); + aDestObj.removeSegment(); + aDestObj.setFinalSlash(); + + try + { + ::ucbhelper::Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + uno::Reference< ucb::XCommandInfo > xInfo = aDestPath.getCommands(); + OUString aTransferName = OUString::createFromAscii( "transfer" ); + if ( xInfo->hasCommandByName( aTransferName ) ) + { + aDestPath.executeCommand( aTransferName, uno::makeAny( + ucb::TransferInfo( bMoveData, aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), aName, nNameClash ) ) ); + } + else + { + DBG_ERRORFILE( "transfer command not available" ); + } + } + catch( ucb::CommandAbortedException& ) + { + bRet = sal_False; + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + bRet = sal_False; + } + + if ( bKillSource ) + SfxContentHelper::Kill( rSource ); + + return bRet; +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::IsDocument( const String& rContent ) +{ + sal_Bool bRet = sal_False; + INetURLObject aObj( rContent ); + DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + + try + { + ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + bRet = aCnt.isDocument(); + } + catch( ucb::CommandAbortedException& ) + { + DBG_WARNING( "CommandAbortedException" ); + } + catch( ucb::IllegalIdentifierException& ) + { + DBG_WARNING( "IllegalIdentifierException" ); + } + catch( ucb::ContentCreationException& ) + { + DBG_WARNING( "IllegalIdentifierException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + } + + return bRet; +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::IsFolder( const String& rContent ) +{ + sal_Bool bRet = sal_False; + INetURLObject aObj( rContent ); + DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + try + { + ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + bRet = aCnt.isFolder(); + } + catch( ucb::CommandAbortedException& ) + { + DBG_WARNING( "CommandAbortedException" ); + } + catch( ucb::IllegalIdentifierException& ) + { + DBG_WARNING( "IllegalIdentifierException" ); + } + catch( ucb::ContentCreationException& ) + { + DBG_WARNING( "IllegalIdentifierException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + } + + return bRet; +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::GetTitle( const String& rContent, String& rTitle ) +{ + sal_Bool bRet = sal_False; + INetURLObject aObj( rContent ); + DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + try + { + ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + OUString aTemp; + aCnt.getPropertyValue( OUString::createFromAscii( "Title" ) ) >>= aTemp; + rTitle = String( aTemp ); + bRet = sal_True; + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "CommandAbortedException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + } + return bRet; +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::Kill( const String& rContent ) +{ + sal_Bool bRet = sal_True; + INetURLObject aDeleteObj( rContent ); + DBG_ASSERT( aDeleteObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + + try + { + ::ucbhelper::Content aCnt( aDeleteObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + aCnt.executeCommand( OUString::createFromAscii( "delete" ), uno::makeAny( sal_Bool( sal_True ) ) ); + } + catch( ucb::CommandAbortedException& ) + { + DBG_WARNING( "CommandAbortedException" ); + bRet = sal_False; + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + bRet = sal_False; + } + + return bRet; +} + +// ----------------------------------------------------------------------- + +uno::Sequence < OUString > SfxContentHelper::GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted ) +{ + StringList_Impl* pFiles = NULL; + INetURLObject aFolderObj( rFolder ); + DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + try + { + ::ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + uno::Reference< sdbc::XResultSet > xResultSet; + uno::Sequence< OUString > aProps(2); + OUString* pProps = aProps.getArray(); + pProps[0] = OUString::createFromAscii( "Title" ); + pProps[1] = OUString::createFromAscii( "IsFolder" ); + + try + { + ::ucbhelper::ResultSetInclude eInclude = bFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY; + if ( !bSorted ) + { + xResultSet = aCnt.createCursor( aProps, eInclude ); + } + else + { + uno::Reference< ucb::XDynamicResultSet > xDynResultSet; + xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude ); + + uno::Reference < ucb::XAnyCompareFactory > xFactory; + uno::Reference < lang::XMultiServiceFactory > xMgr = getProcessServiceFactory(); + uno::Reference < ucb::XSortedDynamicResultSetFactory > xSRSFac( + xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), uno::UNO_QUERY ); + + uno::Sequence< ucb::NumberedSortingInfo > aSortInfo( 2 ); + ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray(); + pInfo[ 0 ].ColumnIndex = 2; + pInfo[ 0 ].Ascending = sal_False; + pInfo[ 1 ].ColumnIndex = 1; + pInfo[ 1 ].Ascending = sal_True; + + uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet; + xDynamicResultSet = + xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xFactory ); + if ( xDynamicResultSet.is() ) + { + xResultSet = xDynamicResultSet->getStaticResultSet(); + } + } + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "createCursor: CommandAbortedException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "createCursor: Any other exception" ); + } + + if ( xResultSet.is() ) + { + pFiles = new StringList_Impl; + uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); + try + { + while ( xResultSet->next() ) + { + OUString aId = xContentAccess->queryContentIdentifierString(); + OUString* pFile = new OUString( aId ); + pFiles->Insert( pFile, LIST_APPEND ); + } + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "XContentAccess::next(): Any other exception" ); + } + } + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "GetFolderContents: Any other exception" ); + } + + if ( pFiles ) + { + ULONG nCount = pFiles->Count(); + uno::Sequence < OUString > aRet( nCount ); + OUString* pRet = aRet.getArray(); + for ( ULONG i = 0; i < nCount; ++i ) + { + OUString* pFile = pFiles->GetObject(i); + pRet[i] = *( pFile ); + delete pFile; + } + delete pFiles; + return aRet; + } + else + return uno::Sequence < OUString > (); +} + +// ----------------------------------------------------------------------- + +uno::Sequence < OUString > SfxContentHelper::GetFolderContentProperties( const String& rFolder, sal_Bool bIsFolder ) +{ + StringList_Impl* pProperties = NULL; + INetURLObject aFolderObj( rFolder ); + DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + try + { + uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > ( + xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY ); + + ::ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) ); + uno::Reference< sdbc::XResultSet > xResultSet; + uno::Sequence< OUString > aProps(5); + OUString* pProps = aProps.getArray(); + pProps[0] = OUString::createFromAscii( "Title" ); + pProps[1] = OUString::createFromAscii( "ContentType" ); + pProps[2] = OUString::createFromAscii( "Size" ); + pProps[3] = OUString::createFromAscii( "DateModified" ); + pProps[4] = OUString::createFromAscii( "IsFolder" ); + + try + { + uno::Reference< ucb::XDynamicResultSet > xDynResultSet; + ::ucbhelper::ResultSetInclude eInclude = bIsFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY; + xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude ); + + uno::Reference < ucb::XAnyCompareFactory > xCmpFactory; + uno::Reference < lang::XMultiServiceFactory > xMgr = getProcessServiceFactory(); + uno::Reference < ucb::XSortedDynamicResultSetFactory > xSRSFac( + xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), uno::UNO_QUERY ); + + uno::Sequence< ucb::NumberedSortingInfo > aSortInfo( 2 ); + ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray(); + pInfo[ 0 ].ColumnIndex = 5; + pInfo[ 0 ].Ascending = sal_False; + pInfo[ 1 ].ColumnIndex = 1; + pInfo[ 1 ].Ascending = sal_True; + + uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet; + xDynamicResultSet = + xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xCmpFactory ); + if ( xDynamicResultSet.is() ) + { + xResultSet = xDynamicResultSet->getStaticResultSet(); + } + +// if ( xDynResultSet.is() ) +// xResultSet = xDynResultSet->getStaticResultSet(); + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "createCursor: CommandAbortedException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "createCursor: Any other exception" ); + } + + if ( xResultSet.is() ) + { + LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() ); + pProperties = new StringList_Impl; + uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); + uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); + ULONG nFolderPos = LIST_APPEND; + + try + { + while ( xResultSet->next() ) + { + String aTitle( xRow->getString(1) ); + String aType( xRow->getString(2) ); + sal_Int64 nSize = xRow->getLong(3); + util::DateTime aDT = xRow->getTimestamp(4); + sal_Bool bFolder = xRow->getBoolean(5); + + String aRow = aTitle; + aRow += '\t'; +//! aRow += aType; +//! aRow += '\t'; + aRow += String::CreateFromInt64( nSize ); + aRow += '\t'; + AppendDateTime_Impl( aDT, aRow, aLocaleWrapper ); + aRow += '\t'; + aRow += String( xContentAccess->queryContentIdentifierString() ); + aRow += '\t'; + aRow += bFolder ? '1' : '0'; + OUString* pRow = new OUString( aRow ); + ULONG nPos = LIST_APPEND; + if ( bFolder ) + { + if ( LIST_APPEND == nFolderPos ) + nFolderPos = 0; + else + nFolderPos++; + nPos = nFolderPos; + } + pProperties->Insert( pRow, nPos ); + } + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "XContentAccess::next(): Any other exception" ); + } + } + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "GetFolderContents: Any other exception" ); + } + + if ( pProperties ) + { + ULONG nCount = pProperties->Count(); + uno::Sequence < OUString > aRet( nCount ); + OUString* pRet = aRet.getArray(); + for ( ULONG i = 0; i < nCount; ++i ) + { + OUString* pProperty = pProperties->GetObject(i); + pRet[i] = *( pProperty ); + delete pProperty; + } + delete pProperties; + return aRet; + } + else + return uno::Sequence < OUString > (); +} + +// ----------------------------------------------------------------------- + +uno::Sequence < OUString > SfxContentHelper::GetResultSet( const String& rURL ) +{ + StringList_Impl* pList = NULL; + try + { + ::ucbhelper::Content aCnt( rURL, uno::Reference< ucb::XCommandEnvironment >() ); + uno::Reference< sdbc::XResultSet > xResultSet; + uno::Reference< ucb::XDynamicResultSet > xDynResultSet; + uno::Sequence< OUString > aProps(3); + OUString* pProps = aProps.getArray(); + pProps[0] = OUString::createFromAscii( "Title" ); + pProps[1] = OUString::createFromAscii( "ContentType" ); + pProps[2] = OUString::createFromAscii( "IsFolder" ); + + try + { + xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS ); + if ( xDynResultSet.is() ) + xResultSet = xDynResultSet->getStaticResultSet(); + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "createCursor: CommandAbortedException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "createCursor: Any other exception" ); + } + + if ( xResultSet.is() ) + { + pList = new StringList_Impl; + uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); + uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); + + try + { + while ( xResultSet->next() ) + { + String aTitle( xRow->getString(1) ); + String aType( xRow->getString(2) ); + String aRow = aTitle; + aRow += '\t'; + aRow += aType; + aRow += '\t'; + aRow += String( xContentAccess->queryContentIdentifierString() ); + OUString* pRow = new OUString( aRow ); + pList->Insert( pRow, LIST_APPEND ); + } + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "XContentAccess::next(): Any other exception" ); + } + } + } + catch( uno::Exception& e ) + { + (void) e; + DBG_ERRORFILE( + rtl::OUStringToOString( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "GetResultSet: Any other exception: ")) + + e.Message), + RTL_TEXTENCODING_UTF8). + getStr()); + } + + if ( pList ) + { + ULONG nCount = pList->Count(); + uno::Sequence < OUString > aRet( nCount ); + OUString* pRet = aRet.getArray(); + for ( ULONG i = 0; i < nCount; ++i ) + { + OUString* pEntry = pList->GetObject(i); + pRet[i] = *( pEntry ); + delete pEntry; + } + delete pList; + return aRet; + } + else + return uno::Sequence < OUString > (); +} + +// ----------------------------------------------------------------------- + +uno::Sequence< OUString > SfxContentHelper::GetHelpTreeViewContents( const String& rURL ) +{ + StringList_Impl* pProperties = NULL; + try + { + uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > ( + xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY ); + + ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) ); + uno::Reference< sdbc::XResultSet > xResultSet; + uno::Sequence< OUString > aProps(2); + OUString* pProps = aProps.getArray(); + pProps[0] = OUString::createFromAscii( "Title" ); + pProps[1] = OUString::createFromAscii( "IsFolder" ); + + try + { + uno::Reference< ucb::XDynamicResultSet > xDynResultSet; + xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS ); + if ( xDynResultSet.is() ) + xResultSet = xDynResultSet->getStaticResultSet(); + } + catch( ucb::CommandAbortedException& ) + { + } + catch( uno::Exception& ) + { + } + + if ( xResultSet.is() ) + { + pProperties = new StringList_Impl; + uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); + uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); + + try + { + while ( xResultSet->next() ) + { + String aTitle( xRow->getString(1) ); + sal_Bool bFolder = xRow->getBoolean(2); + String aRow = aTitle; + aRow += '\t'; + aRow += String( xContentAccess->queryContentIdentifierString() ); + aRow += '\t'; + aRow += bFolder ? '1' : '0'; + OUString* pRow = new OUString( aRow ); + pProperties->Insert( pRow, LIST_APPEND ); + } + } + catch( ucb::CommandAbortedException& ) + { + } + catch( uno::Exception& ) + { + } + } + } + catch( uno::Exception& ) + { + } + + if ( pProperties ) + { + ULONG nCount = pProperties->Count(); + uno::Sequence < OUString > aRet( nCount ); + OUString* pRet = aRet.getArray(); + for ( ULONG i = 0; i < nCount; ++i ) + { + OUString* pProperty = pProperties->GetObject(i); + pRet[i] = *( pProperty ); + delete pProperty; + } + delete pProperties; + return aRet; + } + else + return uno::Sequence < OUString > (); +} + +// ----------------------------------------------------------------------- + +String SfxContentHelper::GetActiveHelpString( const String& rURL ) +{ + String aRet; + try + { + uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > ( + xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY ); + ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) ); + // open the "active help" stream + uno::Reference< io::XInputStream > xStream = aCnt.openStream(); + // and convert it to a String + uno::Sequence< sal_Int8 > lData; + sal_Int32 nRead = xStream->readBytes( lData, 1024 ); + while ( nRead > 0 ) + { + OStringBuffer sBuffer( nRead ); + for( sal_Int32 i = 0; i < nRead; ++i ) + sBuffer.append( (sal_Char)lData[i] ); + OUString sString = OStringToOUString( sBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ); + aRet += String( sString ); + + nRead = xStream->readBytes( lData, 1024 ); + } + } + catch( uno::Exception& ) + { + } + + return aRet; +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::IsHelpErrorDocument( const String& rURL ) +{ + sal_Bool bRet = sal_False; + try + { + ::ucbhelper::Content aCnt( INetURLObject( rURL ).GetMainURL( INetURLObject::NO_DECODE ), + uno::Reference< ucb::XCommandEnvironment > () ); + if ( !( aCnt.getPropertyValue( OUString::createFromAscii( "IsErrorDocument" ) ) >>= bRet ) ) + { + DBG_ERRORFILE( "Property 'IsErrorDocument' is missing" ); + } + } + catch( uno::Exception& ) + { + } + + return bRet; +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::CopyTo( const String& rSource, const String& rDest ) +{ + return Transfer_Impl( rSource, rDest, sal_False, ucb::NameClash::ERROR ); +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::MoveTo( const String& rSource, const String& rDest, sal_Int32 nNameClash ) +{ + return Transfer_Impl( rSource, rDest, sal_True, nNameClash ); +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::MakeFolder( const String& rFolder ) +{ + INetURLObject aURL( rFolder ); + DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + String aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); + aURL.removeSegment(); + uno::Sequence < OUString > aNames(2); + OUString* pNames = aNames.getArray(); + pNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ); + pNames[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ); + uno::Sequence<uno::Any> aValues(2); + uno::Any* pValues = aValues.getArray(); + pValues[0] = uno::makeAny( OUString( aTitle ) ); + pValues[1] = uno::makeAny( sal_Bool( sal_True ) ); + uno::Reference< ucb::XCommandEnvironment > aCmdEnv; + sal_Bool bRet = sal_False; + try + { + ::ucbhelper::Content aCnt( aURL.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv ); + ::ucbhelper::Content aNewFolder; + OUString aType( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.staroffice.fsys-folder" ) ); + bRet = aCnt.insertNewContent( aType, aNames, aValues, aNewFolder ); + } + catch( ucb::CommandAbortedException& ) + { + // double name? + } + catch( ucb::IllegalIdentifierException& ) + { + DBG_ERRORFILE( "Illegal identifier" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + } + + return bRet; +} + +// ----------------------------------------------------------------------- + +ErrCode SfxContentHelper::QueryDiskSpace( const String& rPath, sal_Int64& rFreeBytes ) +{ + ErrCode nErr = 0; + rFreeBytes = 0; + INetURLObject aObj( rPath ); + DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + try + { + ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + aCnt.getPropertyValue( OUString::createFromAscii( "FreeSpace" ) ) >>= rFreeBytes; + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "CommandAbortedException" ); + nErr = ERRCODE_IO_GENERAL; + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + nErr = ERRCODE_IO_GENERAL; + } + return nErr; +} + +// ----------------------------------------------------------------------- + +ULONG SfxContentHelper::GetSize( const String& rContent ) +{ + ULONG nSize = 0; + sal_Int64 nTemp = 0; + INetURLObject aObj( rContent ); + DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + try + { + ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + aCnt.getPropertyValue( OUString::createFromAscii( "Size" ) ) >>= nTemp; + } + catch( ucb::CommandAbortedException& ) + { + DBG_ERRORFILE( "CommandAbortedException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + } + nSize = (UINT32)nTemp; + return nSize; +} + +// ----------------------------------------------------------------------- +// please don't use it (only used in appbas.cxx and appcfg.cxx) +sal_Bool SfxContentHelper::Exists( const String& rContent ) +{ + sal_Bool bRet = sal_False; + INetURLObject aObj( rContent ); + DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); + + try + { + ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + // just try to get the property; if no exception is thrown, the content exists! + aCnt.isDocument(); + bRet = sal_True; + } + catch( ucb::CommandAbortedException& ) + { + DBG_WARNING( "CommandAbortedException" ); + } + catch( ucb::IllegalIdentifierException& ) + { + DBG_WARNING( "IllegalIdentifierException" ); + } + catch( ucb::ContentCreationException& ) + { + DBG_WARNING( "IllegalIdentifierException" ); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "Any other exception" ); + } + + return bRet; + +} + +// ----------------------------------------------------------------------- + +sal_Bool SfxContentHelper::Find( const String& rFolder, const String& rName, String& rFile ) +{ + sal_Bool bRet = sal_False; + rtl::OUString aFile; + + if ( FileBase::searchFileURL( rName, rFolder, aFile ) == FileBase::E_None ) + { + rFile = aFile; + bRet = sal_True; + } + + return bRet; +} + + diff --git a/sfx2/source/bastyp/makefile.mk b/sfx2/source/bastyp/makefile.mk new file mode 100644 index 000000000000..75c0cace40d6 --- /dev/null +++ b/sfx2/source/bastyp/makefile.mk @@ -0,0 +1,66 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=sfx2 +TARGET=bastyp +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- + +SLOFILES =\ + $(SLO)$/sfxhtml.obj \ + $(SLO)$/frmhtml.obj \ + $(SLO)$/frmhtmlw.obj \ + $(SLO)$/misc.obj \ + $(SLO)$/progress.obj \ + $(SLO)$/sfxresid.obj \ + $(SLO)$/bitset.obj \ + $(SLO)$/minarray.obj \ + $(SLO)$/fltfnc.obj \ + $(SLO)$/mieclip.obj \ + $(SLO)$/fltlst.obj \ + $(SLO)$/helper.obj + +SRS1NAME=$(TARGET) +SRC1FILES =\ + fltfnc.src \ + bastyp.src + +EXCEPTIONSFILES =\ + $(SLO)$/helper.obj + +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + diff --git a/sfx2/source/bastyp/mieclip.cxx b/sfx2/source/bastyp/mieclip.cxx new file mode 100644 index 000000000000..ee2b15d34ab9 --- /dev/null +++ b/sfx2/source/bastyp/mieclip.cxx @@ -0,0 +1,95 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" +#include <tools/stream.hxx> +#include <tools/cachestr.hxx> + +#include <sot/storage.hxx> +#include <sot/formats.hxx> + +#include <mieclip.hxx> +#include <sfx2/sfxuno.hxx> + +MSE40HTMLClipFormatObj::~MSE40HTMLClipFormatObj() +{ + delete pStrm; +} + +SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream ) +{ + BOOL bRet = FALSE; + if( pStrm ) + delete pStrm, pStrm = 0; + + ByteString sLine, sVersion; + ULONG nStt = 0, nEnd = 0; + USHORT nIndex = 0; + + rStream.Seek(STREAM_SEEK_TO_BEGIN); + rStream.ResetError(); + + if( rStream.ReadLine( sLine ) && + sLine.GetToken( 0, ':', nIndex ) == "Version" ) + { + sVersion = sLine.Copy( nIndex ); + while( rStream.ReadLine( sLine ) ) + { + nIndex = 0; + ByteString sTmp( sLine.GetToken( 0, ':', nIndex ) ); + if( sTmp == "StartHTML" ) + nStt = (ULONG)(sLine.Erase( 0, nIndex ).ToInt32()); + else if( sTmp == "EndHTML" ) + nEnd = (ULONG)(sLine.Erase( 0, nIndex ).ToInt32()); + else if( sTmp == "SourceURL" ) + sBaseURL = String(S2U(sLine.Erase( 0, nIndex ))); + + if( nEnd && nStt && + ( sBaseURL.Len() || rStream.Tell() >= nStt )) + { + bRet = TRUE; + break; + } + } + } + + if( bRet ) + { + rStream.Seek( nStt ); + + pStrm = new SvCacheStream( ( nEnd - nStt < 0x10000l + ? nEnd - nStt + 32 + : 0 )); + *pStrm << rStream; + pStrm->SetStreamSize( nEnd - nStt + 1L ); + pStrm->Seek( STREAM_SEEK_TO_BEGIN ); + } + + return pStrm; +} + diff --git a/sfx2/source/bastyp/minarray.cxx b/sfx2/source/bastyp/minarray.cxx new file mode 100644 index 000000000000..978239239cea --- /dev/null +++ b/sfx2/source/bastyp/minarray.cxx @@ -0,0 +1,736 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#ifndef GCC +#endif + +#include <sfx2/minarray.hxx> + +// ----------------------------------------------------------------------- + +SfxPtrArr::SfxPtrArr( BYTE nInitSize, BYTE nGrowSize ): + nUsed( 0 ), + nGrow( nGrowSize ? nGrowSize : 1 ), + nUnused( nInitSize ) +{ + DBG_MEMTEST(); + USHORT nMSCBug = nInitSize; + + if ( nMSCBug > 0 ) + pData = new void*[nMSCBug]; + else + pData = 0; +} + +// ----------------------------------------------------------------------- + +SfxPtrArr::SfxPtrArr( const SfxPtrArr& rOrig ) +{ + DBG_MEMTEST(); + nUsed = rOrig.nUsed; + nGrow = rOrig.nGrow; + nUnused = rOrig.nUnused; + + if ( rOrig.pData != 0 ) + { + pData = new void*[nUsed+nUnused]; + memcpy( pData, rOrig.pData, nUsed*sizeof(void*) ); + } + else + pData = 0; +} + +// ----------------------------------------------------------------------- + +SfxPtrArr::~SfxPtrArr() +{ + DBG_MEMTEST(); + delete [] pData; +} + +// ----------------------------------------------------------------------- + +SfxPtrArr& SfxPtrArr::operator=( const SfxPtrArr& rOrig ) +{ + DBG_MEMTEST(); + + delete [] pData; + + nUsed = rOrig.nUsed; + nGrow = rOrig.nGrow; + nUnused = rOrig.nUnused; + + if ( rOrig.pData != 0 ) + { + pData = new void*[nUsed+nUnused]; + memcpy( pData, rOrig.pData, nUsed*sizeof(void*) ); + } + else + pData = 0; + return *this; +} + +// ----------------------------------------------------------------------- + +void SfxPtrArr::Append( void* aElem ) +{ + DBG_MEMTEST(); + DBG_ASSERT( sal::static_int_cast< unsigned >(nUsed+1) < ( USHRT_MAX / sizeof(void*) ), "array too large" ); + // musz das Array umkopiert werden? + if ( nUnused == 0 ) + { + USHORT nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow; + void** pNewData = new void*[nNewSize]; + if ( pData ) + { + DBG_ASSERT( nUsed <= nNewSize, "" ); + memmove( pNewData, pData, sizeof(void*)*nUsed ); + delete [] pData; + } + nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed); + pData = pNewData; + } + + // jetzt hinten in den freien Raum schreiben + pData[nUsed] = aElem; + ++nUsed; + --nUnused; +} + +// ----------------------------------------------------------------------- + +USHORT SfxPtrArr::Remove( USHORT nPos, USHORT nLen ) +{ + DBG_MEMTEST(); + // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird + nLen = Min( (USHORT)(nUsed-nPos), nLen ); + + // einfache Aufgaben erfordern einfache Loesungen! + if ( nLen == 0 ) + return 0; + + // bleibt vielleicht keiner uebrig + if ( (nUsed-nLen) == 0 ) + { + delete [] pData; + pData = 0; + nUsed = 0; + nUnused = 0; + return nLen; + } + + // feststellen, ob das Array dadurch physikalisch schrumpft... + if ( (nUnused+nLen) >= nGrow ) + { + // auf die naechste Grow-Grenze aufgerundet verkleinern + USHORT nNewUsed = nUsed-nLen; + USHORT nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow; + DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize, + "shrink size computation failed" ); + void** pNewData = new void*[nNewSize]; + if ( nPos > 0 ) + { + DBG_ASSERT( nPos <= nNewSize, "" ); + memmove( pNewData, pData, sizeof(void*)*nPos ); + } + if ( nNewUsed != nPos ) + memmove( pNewData+nPos, pData+nPos+nLen, + sizeof(void*)*(nNewUsed-nPos) ); + delete [] pData; + pData = pNewData; + nUsed = nNewUsed; + nUnused = sal::static_int_cast< BYTE >(nNewSize - nNewUsed); + return nLen; + } + + // in allen anderen Faellen nur zusammenschieben + if ( nUsed-nPos-nLen > 0 ) + memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(void*) ); + nUsed = nUsed - nLen; + nUnused = sal::static_int_cast< BYTE >(nUnused + nLen); + return nLen; +} + +// ----------------------------------------------------------------------- + +BOOL SfxPtrArr::Remove( void* aElem ) +{ + DBG_MEMTEST(); + // einfache Aufgaben ... + if ( nUsed == 0 ) + return FALSE; + + // rueckwaerts, da meist der letzte zuerst wieder entfernt wird + void* *pIter = pData + nUsed - 1; + for ( USHORT n = 0; n < nUsed; ++n, --pIter ) + if ( *pIter == aElem ) + { + Remove(nUsed-n-1, 1); + return TRUE; + } + return FALSE; +} + +// ----------------------------------------------------------------------- + +BOOL SfxPtrArr::Replace( void* aOldElem, void* aNewElem ) +{ + DBG_MEMTEST(); + // einfache Aufgaben ... + if ( nUsed == 0 ) + return FALSE; + + // rueckwaerts, da meist der letzte zuerst wieder entfernt wird + void* *pIter = pData + nUsed - 1; + for ( USHORT n = 0; n < nUsed; ++n, --pIter ) + if ( *pIter == aOldElem ) + { + pData[nUsed-n-1] = aNewElem; + return TRUE; + } + return FALSE; +} + +// ----------------------------------------------------------------------- + +BOOL SfxPtrArr::Contains( const void* rItem ) const +{ + DBG_MEMTEST(); + if ( !nUsed ) + return FALSE; + + for ( USHORT n = 0; n < nUsed; ++n ) + { + void* p = GetObject(n); + if ( p == rItem ) + return TRUE; + } + + return FALSE; +} + +// ----------------------------------------------------------------------- + +void SfxPtrArr::Insert( USHORT nPos, void* rElem ) +{ + DBG_MEMTEST(); + DBG_ASSERT( sal::static_int_cast< unsigned >(nUsed+1) < ( USHRT_MAX / sizeof(void*) ), "array too large" ); + // musz das Array umkopiert werden? + if ( nUnused == 0 ) + { + // auf die naechste Grow-Grenze aufgerundet vergroeszern + USHORT nNewSize = nUsed+nGrow; + void** pNewData = new void*[nNewSize]; + + if ( pData ) + { + DBG_ASSERT( nUsed < nNewSize, "" ); + memmove( pNewData, pData, sizeof(void*)*nUsed ); + delete [] pData; + } + nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed); + pData = pNewData; + } + + // jetzt den hinteren Teil verschieben + if ( nPos < nUsed ) + memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(void*) ); + + // jetzt in den freien Raum schreiben + memmove( pData+nPos, &rElem, sizeof(void*) ); + nUsed += 1; + nUnused -= 1; +} + +// class ByteArr --------------------------------------------------------- + +ByteArr::ByteArr( BYTE nInitSize, BYTE nGrowSize ): + nUsed( 0 ), + nGrow( nGrowSize ? nGrowSize : 1 ), + nUnused( nInitSize ) +{ + DBG_MEMTEST(); + USHORT nMSCBug = nInitSize; + + if ( nInitSize > 0 ) + pData = new char[nMSCBug]; + else + pData = 0; +} + +// ----------------------------------------------------------------------- + +ByteArr::ByteArr( const ByteArr& rOrig ) +{ + DBG_MEMTEST(); + nUsed = rOrig.nUsed; + nGrow = rOrig.nGrow; + nUnused = rOrig.nUnused; + + if ( rOrig.pData != 0 ) + { + pData = new char[nUsed+nUnused]; + memcpy( pData, rOrig.pData, nUsed*sizeof(char) ); + } + else + pData = 0; +} + +// ----------------------------------------------------------------------- + +ByteArr::~ByteArr() +{ + DBG_MEMTEST(); + delete [] pData; +} + +// ----------------------------------------------------------------------- + +ByteArr& ByteArr::operator=( const ByteArr& rOrig ) +{ + DBG_MEMTEST(); + + delete [] pData; + + nUsed = rOrig.nUsed; + nGrow = rOrig.nGrow; + nUnused = rOrig.nUnused; + + if ( rOrig.pData != 0 ) + { + pData = new char[nUsed+nUnused]; + memcpy( pData, rOrig.pData, nUsed*sizeof(char) ); + } + else + pData = 0; + return *this; +} + +// ----------------------------------------------------------------------- + +void ByteArr::Append( char aElem ) +{ + DBG_MEMTEST(); + // musz das Array umkopiert werden? + if ( nUnused == 0 ) + { + USHORT nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow; + char* pNewData = new char[nNewSize]; + if ( pData ) + { + DBG_ASSERT( nUsed <= nNewSize, "" ); + memmove( pNewData, pData, sizeof(char)*nUsed ); + delete [] pData; + } + nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed); + pData = pNewData; + } + + // jetzt hinten in den freien Raum schreiben + pData[nUsed] = aElem; + ++nUsed; + --nUnused; +} + +// ----------------------------------------------------------------------- + +USHORT ByteArr::Remove( USHORT nPos, USHORT nLen ) +{ + DBG_MEMTEST(); + // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird + nLen = Min( (USHORT)(nUsed-nPos), nLen ); + + // einfache Aufgaben erfordern einfache Loesungen! + if ( nLen == 0 ) + return 0; + + // bleibt vielleicht keiner uebrig + if ( (nUsed-nLen) == 0 ) + { + delete [] pData; + pData = 0; + nUsed = 0; + nUnused = 0; + return nLen; + } + + // feststellen, ob das Array dadurch physikalisch schrumpft... + if ( (nUnused+nLen) >= nGrow ) + { + // auf die naechste Grow-Grenze aufgerundet verkleinern + USHORT nNewUsed = nUsed-nLen; + USHORT nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow; + DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize, + "shrink size computation failed" ); + char* pNewData = new char[nNewSize]; + if ( nPos > 0 ) + { + DBG_ASSERT( nPos <= nNewSize, "" ); + memmove( pNewData, pData, sizeof(char)*nPos ); + } + if ( nNewUsed != nPos ) + memmove( pNewData+nPos, pData+nPos+nLen, + sizeof(char)*(nNewUsed-nPos) ); + delete [] pData; + pData = pNewData; + nUsed = nNewUsed; + nUnused = sal::static_int_cast< BYTE >(nNewSize - nNewUsed); + return nLen; + } + + // in allen anderen Faellen nur zusammenschieben + if ( nUsed-nPos-nLen > 0 ) + memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(char) ); + nUsed = nUsed - nLen; + nUnused = sal::static_int_cast< BYTE >(nUnused + nLen); + return nLen; +} + +// ----------------------------------------------------------------------- + +BOOL ByteArr::Remove( char aElem ) +{ + DBG_MEMTEST(); + // einfache Aufgaben ... + if ( nUsed == 0 ) + return FALSE; + + // rueckwaerts, da meist der letzte zuerst wieder entfernt wird + char *pIter = pData + nUsed - 1; + for ( USHORT n = 0; n < nUsed; ++n, --pIter ) + if ( *pIter == aElem ) + { + Remove(nUsed-n-1, 1); + return TRUE; + } + return FALSE; +} + +// ----------------------------------------------------------------------- + +BOOL ByteArr::Contains( const char rItem ) const +{ + DBG_MEMTEST(); + if ( !nUsed ) + return FALSE; + + for ( USHORT n = 0; n < nUsed; ++n ) + { + char p = GetObject(n); + if ( p == rItem ) + return TRUE; + } + + return FALSE; +} + +// ----------------------------------------------------------------------- + +void ByteArr::Insert( USHORT nPos, char rElem ) +{ + DBG_MEMTEST(); + // musz das Array umkopiert werden? + if ( nUnused == 0 ) + { + // auf die naechste Grow-Grenze aufgerundet vergroeszern + USHORT nNewSize = nUsed+nGrow; + char* pNewData = new char[nNewSize]; + + if ( pData ) + { + DBG_ASSERT( nUsed < nNewSize, "" ); + memmove( pNewData, pData, sizeof(char)*nUsed ); + delete [] pData; + } + nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed); + pData = pNewData; + } + + // jetzt den hinteren Teil verschieben + if ( nPos < nUsed ) + memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(char) ); + + // jetzt in den freien Raum schreiben + memmove( pData+nPos, &rElem, sizeof(char) ); + nUsed += 1; + nUnused -= 1; +} + +// ----------------------------------------------------------------------- + +char ByteArr::operator[]( USHORT nPos ) const +{ + DBG_MEMTEST(); + DBG_ASSERT( nPos < nUsed, "" ); + return *(pData+nPos); +} + +// ----------------------------------------------------------------------- + +char& ByteArr::operator [] (USHORT nPos) +{ + DBG_MEMTEST(); + DBG_ASSERT( nPos < nUsed, "" ); + return *(pData+nPos); +} + +// class WordArr --------------------------------------------------------- + +WordArr::WordArr( BYTE nInitSize, BYTE nGrowSize ): + nUsed( 0 ), + nGrow( nGrowSize ? nGrowSize : 1 ), + nUnused( nInitSize ) +{ + DBG_MEMTEST(); + USHORT nMSCBug = nInitSize; + + if ( nInitSize > 0 ) + pData = new short[nMSCBug]; + else + pData = 0; +} + +// ----------------------------------------------------------------------- + +WordArr::WordArr( const WordArr& rOrig ) +{ + DBG_MEMTEST(); + nUsed = rOrig.nUsed; + nGrow = rOrig.nGrow; + nUnused = rOrig.nUnused; + + if ( rOrig.pData != 0 ) + { + pData = new short[nUsed+nUnused]; + memcpy( pData, rOrig.pData, nUsed*sizeof(short) ); + } + else + pData = 0; +} + +// ----------------------------------------------------------------------- + +WordArr::~WordArr() +{ + DBG_MEMTEST(); + delete [] pData; +} + +// ----------------------------------------------------------------------- + +WordArr& WordArr::operator=( const WordArr& rOrig ) +{ + DBG_MEMTEST(); + + delete [] pData; + + nUsed = rOrig.nUsed; + nGrow = rOrig.nGrow; + nUnused = rOrig.nUnused; + + if ( rOrig.pData != 0 ) + { + pData = new short[nUsed+nUnused]; + memcpy( pData, rOrig.pData, nUsed*sizeof(short) ); + } + else + pData = 0; + return *this; +} + +// ----------------------------------------------------------------------- + +void WordArr::Append( short aElem ) +{ + DBG_MEMTEST(); + // musz das Array umkopiert werden? + if ( nUnused == 0 ) + { + USHORT nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow; + short* pNewData = new short[nNewSize]; + if ( pData ) + { + DBG_ASSERT( nUsed <= nNewSize, " " ); + memmove( pNewData, pData, sizeof(short)*nUsed ); + delete [] pData; + } + nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed); + pData = pNewData; + } + + // jetzt hinten in den freien Raum schreiben + pData[nUsed] = aElem; + ++nUsed; + --nUnused; +} + +// ----------------------------------------------------------------------- + +USHORT WordArr::Remove( USHORT nPos, USHORT nLen ) +{ + DBG_MEMTEST(); + // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird + nLen = Min( (USHORT)(nUsed-nPos), nLen ); + + // einfache Aufgaben erfordern einfache Loesungen! + if ( nLen == 0 ) + return 0; + + // bleibt vielleicht keiner uebrig + if ( (nUsed-nLen) == 0 ) + { + delete [] pData; + pData = 0; + nUsed = 0; + nUnused = 0; + return nLen; + } + + // feststellen, ob das Array dadurch physikalisch schrumpft... + if ( (nUnused+nLen) >= nGrow ) + { + // auf die naechste Grow-Grenze aufgerundet verkleinern + USHORT nNewUsed = nUsed-nLen; + USHORT nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow; + DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize, + "shrink size computation failed" ); + short* pNewData = new short[nNewSize]; + if ( nPos > 0 ) + { + DBG_ASSERT( nPos <= nNewSize, "" ); + memmove( pNewData, pData, sizeof(short)*nPos ); + } + if ( nNewUsed != nPos ) + memmove( pNewData+nPos, pData+nPos+nLen, + sizeof(short)*(nNewUsed-nPos) ); + delete [] pData; + pData = pNewData; + nUsed = nNewUsed; + nUnused = sal::static_int_cast< BYTE >(nNewSize - nNewUsed); + return nLen; + } + + // in allen anderen Faellen nur zusammenschieben + if ( nUsed-nPos-nLen > 0 ) + memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(short) ); + nUsed = nUsed - nLen; + nUnused = sal::static_int_cast< BYTE >(nUnused + nLen); + return nLen; +} + +// ----------------------------------------------------------------------- + +BOOL WordArr::Remove( short aElem ) +{ + DBG_MEMTEST(); + // einfache Aufgaben ... + if ( nUsed == 0 ) + return FALSE; + + // rueckwaerts, da meist der letzte zuerst wieder entfernt wird + short *pIter = pData + nUsed - 1; + for ( USHORT n = 0; n < nUsed; ++n, --pIter ) + if ( *pIter == aElem ) + { + Remove(nUsed-n-1, 1); + return TRUE; + } + return FALSE; +} + +// ----------------------------------------------------------------------- + +BOOL WordArr::Contains( const short rItem ) const +{ + DBG_MEMTEST(); + if ( !nUsed ) + return FALSE; + + for ( USHORT n = 0; n < nUsed; ++n ) + { + short p = GetObject(n); + if ( p == rItem ) + return TRUE; + } + + return FALSE; +} + +// ----------------------------------------------------------------------- + +void WordArr::Insert( USHORT nPos, short rElem ) +{ + DBG_MEMTEST(); + // musz das Array umkopiert werden? + if ( nUnused == 0 ) + { + // auf die naechste Grow-Grenze aufgerundet vergroeszern + USHORT nNewSize = nUsed+nGrow; + short* pNewData = new short[nNewSize]; + + if ( pData ) + { + DBG_ASSERT( nUsed < nNewSize, "" ); + memmove( pNewData, pData, sizeof(short)*nUsed ); + delete [] pData; + } + nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed); + pData = pNewData; + } + + // jetzt den hinteren Teil verschieben + if ( nPos < nUsed ) + memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(short) ); + + // jetzt in den freien Raum schreiben + memmove( pData+nPos, &rElem, sizeof(short) ); + nUsed += 1; + nUnused -= 1; +} + +// ----------------------------------------------------------------------- + +short WordArr::operator[]( USHORT nPos ) const +{ + DBG_MEMTEST(); + DBG_ASSERT( nPos < nUsed, "" ); + return *(pData+nPos); +} + +// ----------------------------------------------------------------------- + +short& WordArr::operator [] (USHORT nPos) +{ + DBG_MEMTEST(); + DBG_ASSERT( nPos < nUsed, "" ); + return *(pData+nPos); +} + + diff --git a/sfx2/source/bastyp/misc.cxx b/sfx2/source/bastyp/misc.cxx new file mode 100644 index 000000000000..49938c729b36 --- /dev/null +++ b/sfx2/source/bastyp/misc.cxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#ifndef GCC +#endif + +#include "sfxtypes.hxx" + +//-------------------------------------------------------------------- + +#if defined(DBG_UTIL) && ( defined(WNT) || defined(OS2) ) +unsigned SfxStack::nLevel = 0; +#endif + +//-------------------------------------------------------------------- + +String SearchAndReplace( const String &rSource, + const String &rToReplace, + const String &rReplacement ) +{ + String aTarget( rSource ); + USHORT nPos = rSource.Search( rToReplace ); + if ( nPos != STRING_NOTFOUND ) + { + aTarget.Erase( nPos, rToReplace.Len() ); + return aTarget.Insert( rReplacement, nPos ); + } + return rSource; +} + +//-------------------------------------------------------------------- + +String SfxStringEncode( const String &rSource, const char * ) +{ + String aRet; + String aCoded(rSource); + return aRet; +} + +//-------------------------------------------------------------------- + +String SfxStringDecode( const String &, const char * ) +{ + String aRet; + return aRet; +} + + diff --git a/sfx2/source/bastyp/progress.cxx b/sfx2/source/bastyp/progress.cxx new file mode 100644 index 000000000000..649ae121c274 --- /dev/null +++ b/sfx2/source/bastyp/progress.cxx @@ -0,0 +1,753 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#include <sfx2/progress.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/task/XStatusIndicatorFactory.hpp> + +#ifndef _SBX_HXX //autogen +#include <basic/sbx.hxx> +#endif + +#include <svl/eitem.hxx> +#include <tools/time.hxx> + +// wg. nRescheduleLocks +#include "appdata.hxx" +#include <sfx2/request.hxx> +#include <sfx2/frame.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/viewsh.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/app.hxx> +#include <sfx2/dispatch.hxx> +#include "sfxtypes.hxx" +#include <sfx2/docfile.hxx> +#include "workwin.hxx" +#include "sfxresid.hxx" +#include "bastyp.hrc" +#include <sfx2/msg.hxx> + +#include <time.h> + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::task; + +void AddNumber_Impl( String& aNumber, sal_uInt32 nArg ) +{ + if ( nArg >= 10240 ) + { + aNumber += String::CreateFromInt32( (sal_uInt16)( ( nArg + 512 ) / 1024 ) ); + aNumber += ' '; + aNumber += SfxResId( STR_KB ); + } + else + { + aNumber += String::CreateFromInt32( nArg ); + aNumber += ' '; + aNumber += SfxResId( STR_BYTES ); + } +} + +struct SfxProgress_Impl +{ + Reference < XStatusIndicator > xStatusInd; + String aText, aStateText; + ULONG nMax; + clock_t nCreate; + clock_t nNextReschedule; + BOOL bLocked, bAllDocs; + BOOL bWaitMode; + BOOL bAllowRescheduling; + BOOL bRunning; + BOOL bIsStatusText; + + SfxProgress* pActiveProgress; + SfxObjectShellRef xObjSh; + SfxWorkWindow* pWorkWin; + SfxViewFrame* pView; + + SfxProgress_Impl( const String& ); + void Enable_Impl( BOOL ); + +}; + +//======================================================================== + +#define TIMEOUT_PROGRESS 5L /* 10th s */ +#define MAXPERCENT_PROGRESS 33 + +#define TIMEOUT_RESCHEDULE 10L /* 10th s */ +#define MAXPERCENT_RESCHEDULE 50 + +#define Progress +#include "sfxslots.hxx" + +#define aTypeLibInfo aProgressTypeLibImpl + +//======================================================================== +extern ULONG Get10ThSec(); + +// ----------------------------------------------------------------------- + +void SfxProgress_Impl::Enable_Impl( BOOL bEnable ) +{ + SfxObjectShell* pDoc = bAllDocs ? NULL : (SfxObjectShell*) xObjSh; + SfxViewFrame *pFrame= SfxViewFrame::GetFirst(pDoc); + while ( pFrame ) + { + pFrame->Enable(bEnable); + pFrame->GetDispatcher()->Lock( !bEnable ); + pFrame = SfxViewFrame::GetNext(*pFrame, pDoc); + } + + if ( pView ) + { + pView->Enable( bEnable ); + pView->GetDispatcher()->Lock( !bEnable ); + } + + if ( !pDoc ) + SFX_APP()->GetAppDispatcher_Impl()->Lock( !bEnable ); +} + +// ----------------------------------------------------------------------- + +SfxProgress_Impl::SfxProgress_Impl( const String &/*rTitle*/ ) + : pActiveProgress( 0 ) +{ +} + +// ----------------------------------------------------------------------- + +SfxProgress::SfxProgress +( + SfxObjectShell* pObjSh, /* SfxObjectShell, an der die Aktion ausgef"uhrt + wird. Kann NULL sein, dann wird die Applikation + verwendet */ + + const String& rText, /* Text, der in der Statuszeile vor den Statusmonitor + erscheint */ + + ULONG nRange, /* Maximalwert des Bereiches */ + + BOOL bAll /* alle Dokumente oder nur das Dokument des ViewFrames + disablen (FALSE) */ + ,BOOL bWait /* initial den Wait-Pointer aktivieren (TRUE) */ +) + +/* [Beschreibung] + + Der Konstruktor der Klasse SfxProgress schaltet den als Parameter + "ubergebenen SfxObjectShell und SfxViewFrames, welche dieses Dokument + anzeigen in einen Progress-Mode. D.h. solange eine dieser SfxViewFrame + Instanzen aktiv ist, ist der dazugeh"orige SfxDispatcher und das + dazugeh"orige Window disabled. In der Statuszeile wird ein Balken zur + Fortschritts-Anzeige angezeigt. +*/ + +: pImp( new SfxProgress_Impl( rText ) ), + nVal(0), + bSuspended(TRUE) +{ + pImp->bRunning = TRUE; + pImp->bAllowRescheduling = Application::IsInExecute();; + + pImp->xObjSh = pObjSh; + pImp->aText = rText; + pImp->nMax = nRange; + pImp->bLocked = FALSE; + pImp->bWaitMode = bWait; + pImp->bIsStatusText = FALSE; + pImp->nCreate = Get10ThSec(); + pImp->nNextReschedule = pImp->nCreate; + DBG( DbgOutf( "SfxProgress: created for '%s' at %luds", + rText.GetBuffer(), pImp->nCreate ) ); + pImp->bAllDocs = bAll; + pImp->pWorkWin = 0; + pImp->pView = 0; + + pImp->pActiveProgress = GetActiveProgress( pObjSh ); + if ( pObjSh ) + pObjSh->SetProgress_Impl(this); + else if( !pImp->pActiveProgress ) + SFX_APP()->SetProgress_Impl(this); + Resume(); +} + +// ----------------------------------------------------------------------- + +SfxProgress::~SfxProgress() + +/* [Beschreibung] + + Der Destruktor der Klasse SfxProgress restauriert den alten Zustand; + die Dokumente werden wieder freigeschaltet und die Statuszeile zeigt + wieder Items an. +*/ + +{ + Stop(); + if ( pImp->xStatusInd.is() ) + pImp->xStatusInd->end(); + + if( pImp->bIsStatusText == TRUE ) + GetpApp()->HideStatusText( ); + delete pImp; +} + +// ----------------------------------------------------------------------- + +void SfxProgress::Stop() + +/* [Beschreibung] + + Vorzeitiges Beenden des <SfxProgress>. +*/ + +{ + if( pImp->pActiveProgress ) + { + if ( pImp->xObjSh.Is() && pImp->xObjSh->GetProgress() == this ) + pImp->xObjSh->SetProgress_Impl(0); + return; + } + + if ( !pImp->bRunning ) + return; + pImp->bRunning = FALSE; + DBG( DbgOutf( "SfxProgress: destroyed at %luds", Get10ThSec() ) ); + + Suspend(); + if ( pImp->xObjSh.Is() ) + pImp->xObjSh->SetProgress_Impl(0); + else + SFX_APP()->SetProgress_Impl(0); + if ( pImp->bLocked ) + pImp->Enable_Impl(TRUE); +} + +// ----------------------------------------------------------------------- + +void SfxProgress::SetText +( + const String& /* neuer Text */ +) + +/* [Beschreibung] + + "Andert den Text, der links neben dem Fortschritts-Balken + angezeigt wird. +*/ + +{ + if( pImp->pActiveProgress ) return; + if ( pImp->xStatusInd.is() ) + { + pImp->xStatusInd->reset(); + pImp->xStatusInd->start( pImp->aText, pImp->nMax ); + } +} + +// ----------------------------------------------------------------------- + +const String& SfxProgress::GetStateText_Impl() const +{ + return pImp->aStateText; +} + +// ----------------------------------------------------------------------- +/* +IMPL_STATIC_LINK( SfxProgress, SetStateHdl, PlugInLoadStatus*, pStatus ) +{ + INetRequest* pReq = 0; + const INetHint *pHint = PTR_CAST( INetHint, pStatus->pHint ); + pReq = PTR_CAST( INetRequest, pStatus->pBC ); + + String aString; + if( pReq ) + aString = SfxMedium::GetStatusString( pHint->GetId(), pReq, pHint ); + if( aString.Len() ) + { + GetpApp()->ShowStatusText( aString ); + if( pThis ) + pThis->pImp->bIsStatusText = TRUE; + } + return 0; +} +*/ + +// ----------------------------------------------------------------------- + +// muss in AppDaten +static ULONG nLastTime = 0; + +long TimeOut_Impl( void*, void* pArgV ) +{ + Timer *pArg = (Timer*)pArgV; + if( Time::GetSystemTicks() - nLastTime > 3000 ) + { + GetpApp()->HideStatusText(); + nLastTime = 0; + delete pArg; + } + else pArg->Start(); + return 0; +} + +// ----------------------------------------------------------------------- + +BOOL SfxProgress::SetStateText +( + ULONG nNewVal, /* neuer Wert f"ur die Fortschritts-Anzeige */ + const String& rNewVal, /* Status als Text */ + ULONG nNewRange /* neuer Maximalwert, 0 f"ur Beibehaltung des alten */ +) + +{ + pImp->aStateText = rNewVal; + return SetState( nNewVal, nNewRange ); +} + +// ----------------------------------------------------------------------- + +BOOL SfxProgress::SetState +( + ULONG nNewVal, /* neuer Wert f"ur die Fortschritts-Anzeige */ + + ULONG nNewRange /* neuer Maximalwert, 0 f"ur Beibehaltung des alten */ +) +/* [Beschreibung] + + Setzen des aktuellen Status; nach einem zeitlichen Versatz + wird Reschedule aufgerufen. + + + [R"uckgabewert] + + BOOL TRUE + Fortfahren mit der Aktion + + FALSE + Abbrechen der Aktion +*/ + +{ + // wurde via Stop-Button angehalten? +// if ( pImp->IsCancelled() ) +// return FALSE; + + if( pImp->pActiveProgress ) return TRUE; + + // neuen Wert "ubernehmen + BOOL bOver=FALSE; + nVal = nNewVal; + + // neuer Range? + if ( nNewRange && nNewRange != pImp->nMax ) + { + DBG( DbgOutf( "SfxProgress: range changed from %lu to %lu", + pImp->nMax, nNewRange ) ); + pImp->nMax = nNewRange; + bOver = TRUE; + } + + if ( !pImp->xStatusInd.is() ) + { + // get the active ViewFrame of the document this progress is working on + // if it doesn't work on a document, take the current ViewFrame + SfxObjectShell* pObjSh = pImp->xObjSh; + pImp->pView = SfxViewFrame::Current(); + DBG_ASSERT( pImp->pView || pObjSh, "Can't make progress bar!"); + if ( pObjSh && ( !pImp->pView || pObjSh != pImp->pView->GetObjectShell() ) ) + { + // current document does not belong to current ViewFrame; take it's first visible ViewFrame + SfxViewFrame* pDocView = SfxViewFrame::GetFirst( pObjSh ); + if ( pDocView ) + pImp->pView = pDocView; + else + { + // don't show status indicator for hidden documents (only valid while loading) + SfxMedium* pMedium = pObjSh->GetMedium(); + SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, FALSE ); + if ( !pHiddenItem || !pHiddenItem->GetValue() ) + { + // not in a view, perhaps it's just loading + //SfxFrame* pFrame = pMedium->GetLoadTargetFrame(); + //if ( pFrame && pFrame->GetCurrentViewFrame() ) + //{ + // recycling frame + //pImp->pView = pFrame->GetCurrentViewFrame(); + //} + //else + { + SFX_ITEMSET_ARG( pMedium->GetItemSet(), pIndicatorItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, FALSE ); + Reference< XStatusIndicator > xInd; + if ( pIndicatorItem && (pIndicatorItem->GetValue()>>=xInd) ) + pImp->xStatusInd = xInd; + } + } + } + } + else if ( pImp->pView ) + { + pImp->pWorkWin = SFX_APP()->GetWorkWindow_Impl( pImp->pView ); + if ( pImp->pWorkWin ) + pImp->xStatusInd = pImp->pWorkWin->GetStatusIndicator(); + } + + if ( pImp->xStatusInd.is() ) + { + pImp->xStatusInd->start( pImp->aText, pImp->nMax ); + pImp->pView = NULL; + } + } + + if ( pImp->xStatusInd.is() ) + { + pImp->xStatusInd->setValue( nNewVal ); + } + + return TRUE; +} + +// ----------------------------------------------------------------------- + +void SfxProgress::Resume() + +/* [Beschreibung] + + Nimmt die Anzeige des Status nach einer Unterbrechung wieder auf. + + [Querverweise] + <SfxProgress::Suspend()> +*/ + +{ + if( pImp->pActiveProgress ) return; + if ( bSuspended ) + { + DBG( DbgOutf( "SfxProgress: resumed" ) ); + if ( pImp->xStatusInd.is() ) + { + pImp->xStatusInd->start( pImp->aText, pImp->nMax ); + pImp->xStatusInd->setValue( nVal ); + } + + if ( pImp->bWaitMode ) + { + if ( pImp->xObjSh.Is() && !pImp->bAllDocs ) + { + for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh); + pFrame; + pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) ) + pFrame->GetWindow().EnterWait(); + } + } + + if ( pImp->xObjSh ) + { + SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh); + if ( pFrame ) + pFrame->GetBindings().ENTERREGISTRATIONS(); + } + + bSuspended = FALSE; + } +} + +// ----------------------------------------------------------------------- + +void SfxProgress::Suspend() + +/* [Beschreibung] + + Unterbricht die Anzeige des Status + + [Querverweise] + <SfxProgress::Resume()> +*/ + +{ + if( pImp->pActiveProgress ) return; + if ( !bSuspended ) + { + DBG( DbgOutf( "SfxProgress: suspended" ) ); + bSuspended = TRUE; + + if ( pImp->xStatusInd.is() ) + { + pImp->xStatusInd->reset(); + } + + if ( pImp->xObjSh.Is() && !pImp->bAllDocs ) + { + for ( SfxViewFrame *pFrame = + SfxViewFrame::GetFirst(pImp->xObjSh); + pFrame; + pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) ) + pFrame->GetWindow().LeaveWait(); + } + if ( pImp->xObjSh.Is() ) + { + SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh); + if ( pFrame ) + pFrame->GetBindings().LEAVEREGISTRATIONS(); + } + } +} + +// ----------------------------------------------------------------------- + +void SfxProgress::Lock() +{ + if( pImp->pActiveProgress ) return; + // kein Reschedule bei Embedded-Objekten, + // da wir gegen das OLE Protokoll wehrlos sind + if ( !pImp->xObjSh.Is() ) + { + for ( SfxObjectShell *pDocSh = SfxObjectShell::GetFirst(); + pDocSh; + pDocSh = SfxObjectShell::GetNext(*pDocSh) ) + { + SfxObjectCreateMode eMode = pDocSh->GetCreateMode(); + if ( ( eMode == SFX_CREATE_MODE_EMBEDDED ) || + ( eMode == SFX_CREATE_MODE_PREVIEW ) ) + { + DBG( DbgOutf( "SfxProgress: not locked because EMBEDDED/PREVIEW found" ) ); + pImp->bAllowRescheduling = FALSE; + } + } + } + else + { + SfxObjectCreateMode eMode = pImp->xObjSh->GetCreateMode(); + if ( ( eMode == SFX_CREATE_MODE_EMBEDDED ) || + ( eMode == SFX_CREATE_MODE_PREVIEW ) ) + { + DBG( DbgOutf( "SfxProgress: not locked because ObjectShell is EMBEDDED/PREVIEW" ) ); + pImp->bAllowRescheduling = FALSE; + } + } + + pImp->Enable_Impl( FALSE ); + + DBG( DbgOutf( "SfxProgress: locked" ) ); + pImp->bLocked = TRUE; +} + +// ----------------------------------------------------------------------- + +void SfxProgress::UnLock() +{ + if( pImp->pActiveProgress ) return; + if ( !pImp->bLocked ) + return; + + DBG( DbgOutf( "SfxProgress: unlocked" ) ); + pImp->bLocked = FALSE; + pImp->Enable_Impl(TRUE); +} + +// ----------------------------------------------------------------------- + +void SfxProgress::Reschedule() + +/* [Beschreibung] + + Reschedule von au"sen rufbar + +*/ + +{ + SFX_STACK(SfxProgress::Reschedule); + + if( pImp->pActiveProgress ) return; + SfxApplication* pApp = SFX_APP(); + if ( pImp->bLocked && 0 == pApp->Get_Impl()->nRescheduleLocks ) + { + DBG_ASSERTWARNING( pApp->IsInAsynchronCall_Impl(), + "Reschedule in synchron-call-stack" ); + + SfxAppData_Impl *pAppData = pApp->Get_Impl(); + ++pAppData->nInReschedule; + Application::Reschedule(); + --pAppData->nInReschedule; + } +} + +// ----------------------------------------------------------------------- + +void SfxProgress::SetWaitMode +( + BOOL bWait /* TRUE + Wartecursor wird verwendet + + FALSE + Es wird kein Wartecursor verwendet */ +) + +/* [Beschreibung] + + Wartecursor-Modus umschalten. + +*/ + +{ + if( pImp->pActiveProgress ) return; + if ( !bSuspended && pImp->bWaitMode != bWait ) + { + if ( bWait ) + { + if ( pImp->xObjSh.Is() && !pImp->bAllDocs ) + { + for ( SfxViewFrame *pFrame = + SfxViewFrame::GetFirst(pImp->xObjSh); + pFrame; + pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) ) + pFrame->GetWindow().EnterWait(); + } + } + else + { + if ( pImp->xObjSh.Is() && !pImp->bAllDocs ) + { + for ( SfxViewFrame *pFrame = + SfxViewFrame::GetFirst(pImp->xObjSh); + pFrame; + pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) ) + pFrame->GetWindow().LeaveWait(); + } + } + } + + pImp->bWaitMode = bWait; +} + +// ----------------------------------------------------------------------- + +BOOL SfxProgress::GetWaitMode() const + +/* [Beschreibung] + + Wartecursor-Modus abfragen. + +*/ + +{ + return pImp->bWaitMode; +} + +// ----------------------------------------------------------------------- + +SfxProgress* SfxProgress::GetActiveProgress +( + SfxObjectShell* pDocSh /* <SfxObjectShell>, die nach einem laufenden + <SfxProgress> gefragt werden soll, oder + 0, wenn ein f"ur die gesamte Applikation + laufender SfxProgress erfragt werden soll. + Der Pointer braucht nur zum Zeitpunkt des + Aufrufs g"ultig zu sein. */ +) + +/* [Beschreibung] + + Mit dieser Methode kann erfragt werden, ob und welcher <SfxProgress>- + f"ur eine bestimmte Instanz von SfxObjectShell oder gar die gesamte + Applikation zur Zeit aktiv ist. Dies kann z.B. zum Abfangen von + Time-Out-Events etc. verwendet werden. + + Anstelle eines Pointer auf den SfxProgress der SfxObjectShell wird + ggf. der auf den SfxProgress der Applikation geliefert, mit der + Abfrage 'SfxProgress::GetActiveProgress(pMyDocSh)' wird also + insofern vorhanden der SfxProgress von 'pMyDocSh' geliefert, + sonst der SfxProgress der Applikation bzw. ein 0-Pointer. + + + [Anmerkung] + + "auft kein SfxProgress an der Applikation und ebenfalls keiner an + der angegebenen SfxObjectShell, dann wird immer 0 zur"uckgeliefert, + auch wenn an einer anderen SfxObjectShell ein SfxProgress l"uft. + + + [Querverweise] + + <SfxApplication::GetProgress()const> + <SfxObjectShell::GetProgress()const> +*/ + +{ + if ( !SfxApplication::Is_Impl() ) + return 0; + + SfxProgress *pProgress = 0; + if ( pDocSh ) + pProgress = pDocSh->GetProgress(); + if ( !pProgress ) + pProgress = SFX_APP()->GetProgress(); + return pProgress; +} + +// ----------------------------------------------------------------------- + +void SfxProgress::EnterLock() +{ + SFX_APP()->Get_Impl()->nRescheduleLocks++; +} + +// ----------------------------------------------------------------------- + +void SfxProgress::LeaveLock() +{ + SfxAppData_Impl *pImp = SFX_APP()->Get_Impl(); + DBG_ASSERT( 0 != pImp->nRescheduleLocks, "SFxProgress::LeaveLock but no locks" ); + pImp->nRescheduleLocks--; +} + +// ----------------------------------------------------------------------- + +FASTBOOL SfxProgress::StatusBarManagerGone_Impl +( + SfxStatusBarManager * // dieser <SfxStatusBarManager> wird zerst"ort +) + +/* [Beschreibung] + + Interne Methode zum Benachrichtigen des SfxProgress, da\s der angegebene + SfxStatusBarManger zerst"ort wird. Damit der Progress ihn loslassen + kann. +*/ + +{ + return TRUE; +} + diff --git a/sfx2/source/bastyp/sfxhtml.cxx b/sfx2/source/bastyp/sfxhtml.cxx new file mode 100644 index 000000000000..6132e958b900 --- /dev/null +++ b/sfx2/source/bastyp/sfxhtml.cxx @@ -0,0 +1,451 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#include <tools/urlobj.hxx> + +#include <sfx2/objsh.hxx> +#include <sfx2/docfile.hxx> +#include "openflag.hxx" + +#include <svtools/htmlkywd.hxx> +#include <svtools/htmltokn.h> +#include <svtools/imap.hxx> +#include <svtools/imapcirc.hxx> +#include <svtools/imapobj.hxx> +#include <svtools/imappoly.hxx> +#include <svtools/imaprect.hxx> +#ifndef _SVSTDARR_ULONGS_DECL +#define _SVSTDARR_ULONGS +#include <svl/svstdarr.hxx> +#endif +#include <svl/zforlist.hxx> +#include <rtl/tencinfo.h> +#include <tools/tenccvt.hxx> + +#include <sfx2/sfxhtml.hxx> + +#include <com/sun/star/beans/XPropertyContainer.hpp> + + +using namespace ::com::sun::star; + + +sal_Char __FAR_DATA sHTML_MIME_text[] = "text/"; +sal_Char __FAR_DATA sHTML_MIME_application[] = "application/"; +sal_Char __FAR_DATA sHTML_MIME_experimental[] = "x-"; + +// <INPUT TYPE=xxx> +#ifdef __MINGW32__ // for runtime pseudo reloc +static HTMLOptionEnum aAreaShapeOptEnums[] = +#else +static HTMLOptionEnum __READONLY_DATA aAreaShapeOptEnums[] = +#endif +{ + { OOO_STRING_SVTOOLS_HTML_SH_rect, IMAP_OBJ_RECTANGLE }, + { OOO_STRING_SVTOOLS_HTML_SH_rectangle, IMAP_OBJ_RECTANGLE }, + { OOO_STRING_SVTOOLS_HTML_SH_circ, IMAP_OBJ_CIRCLE }, + { OOO_STRING_SVTOOLS_HTML_SH_circle, IMAP_OBJ_CIRCLE }, + { OOO_STRING_SVTOOLS_HTML_SH_poly, IMAP_OBJ_POLYGON }, + { OOO_STRING_SVTOOLS_HTML_SH_polygon, IMAP_OBJ_POLYGON }, + { 0, 0 } +}; + +SfxHTMLParser::SfxHTMLParser( SvStream& rStream, BOOL bIsNewDoc, + SfxMedium *pMed ) : + HTMLParser( rStream, bIsNewDoc ), + pMedium( pMed ), pDLMedium( 0 ), + nMetaTags( 0 ) +{ + DBG_ASSERT( RTL_TEXTENCODING_DONTKNOW == GetSrcEncoding( ), + "SfxHTMLParser::SfxHTMLParser: Wo kommt der ZS her?" ); + DBG_ASSERT( !IsSwitchToUCS2(), + "SfxHTMLParser::SfxHTMLParser: Switch to UCS2?" ); + + // Altough the real default encoding is ISO8859-1, we use MS-1252 + // als default encoding. + SetSrcEncoding( GetExtendedCompatibilityTextEncoding( RTL_TEXTENCODING_ISO_8859_1 ) ); + + // If the file starts with a BOM, switch to UCS2. + SetSwitchToUCS2( TRUE ); +} + +__EXPORT SfxHTMLParser::~SfxHTMLParser() +{ + DBG_ASSERT( !pDLMedium, "Da ist ein File-Download stehengeblieben" ); + delete pDLMedium; +} + +BOOL SfxHTMLParser::ParseMapOptions(ImageMap * pImageMap, + const HTMLOptions * pOptions) +{ + DBG_ASSERT( pImageMap, "ParseMapOptions: keine Image-Map" ); + DBG_ASSERT( pOptions, "ParseMapOptions: keine Optionen" ); + + String aName; + + for( USHORT i=pOptions->Count(); i; ) + { + const HTMLOption *pOption = (*pOptions)[--i]; + switch( pOption->GetToken() ) + { + case HTML_O_NAME: + aName = pOption->GetString(); + break; + } + } + + if( aName.Len() ) + pImageMap->SetName( aName ); + + return aName.Len() > 0; +} + +BOOL SfxHTMLParser::ParseAreaOptions(ImageMap * pImageMap, const String& rBaseURL, + const HTMLOptions * pOptions, + USHORT nEventMouseOver, + USHORT nEventMouseOut ) +{ + DBG_ASSERT( pImageMap, "ParseAreaOptions: keine Image-Map" ); + DBG_ASSERT( pOptions, "ParseAreaOptions: keine Optionen" ); + + USHORT nShape = IMAP_OBJ_RECTANGLE; + SvULongs aCoords; + String aName, aHRef, aAlt, aTarget, sEmpty; + BOOL bNoHRef = FALSE; + SvxMacroTableDtor aMacroTbl; + + for( USHORT i=pOptions->Count(); i; ) + { + USHORT nEvent = 0; + ScriptType eScrpType = STARBASIC; + const HTMLOption *pOption = (*pOptions)[--i]; + switch( pOption->GetToken() ) + { + case HTML_O_NAME: + aName = pOption->GetString(); + break; + case HTML_O_SHAPE: + pOption->GetEnum( nShape, aAreaShapeOptEnums ); + break; + case HTML_O_COORDS: + pOption->GetNumbers( aCoords, TRUE ); + break; + case HTML_O_HREF: + aHRef = INetURLObject::GetAbsURL( rBaseURL, pOption->GetString() ); + break; + case HTML_O_NOHREF: + bNoHRef = TRUE; + break; + case HTML_O_ALT: + aAlt = pOption->GetString(); + break; + case HTML_O_TARGET: + aTarget = pOption->GetString(); + break; + + case HTML_O_ONMOUSEOVER: + eScrpType = JAVASCRIPT; + case HTML_O_SDONMOUSEOVER: + nEvent = nEventMouseOver; + goto IMAPOBJ_SETEVENT; + + case HTML_O_ONMOUSEOUT: + eScrpType = JAVASCRIPT; + case HTML_O_SDONMOUSEOUT: + nEvent = nEventMouseOut; + goto IMAPOBJ_SETEVENT; +IMAPOBJ_SETEVENT: + if( nEvent ) + { + String sTmp( pOption->GetString() ); + if( sTmp.Len() ) + { + sTmp.ConvertLineEnd(); + aMacroTbl.Insert( nEvent, + new SvxMacro( sTmp, sEmpty, eScrpType )); + } + } + break; + } + } + + if( bNoHRef ) + aHRef.Erase(); + + BOOL bNewArea = TRUE; + switch( nShape ) + { + case IMAP_OBJ_RECTANGLE: + if( aCoords.Count() >=4 ) + { + Rectangle aRec( aCoords[0], aCoords[1], + aCoords[2], aCoords[3] ); + IMapRectangleObject aMapRObj( aRec, aHRef, aAlt, String(), aTarget, aName, + !bNoHRef ); + if( aMacroTbl.Count() ) + aMapRObj.SetMacroTable( aMacroTbl ); + pImageMap->InsertIMapObject( aMapRObj ); + } + break; + case IMAP_OBJ_CIRCLE: + if( aCoords.Count() >=3 ) + { + Point aPoint( aCoords[0], aCoords[1] ); + IMapCircleObject aMapCObj( aPoint, aCoords[2],aHRef, aAlt, String(), + aTarget, aName, !bNoHRef ); + if( aMacroTbl.Count() ) + aMapCObj.SetMacroTable( aMacroTbl ); + pImageMap->InsertIMapObject( aMapCObj ); + } + break; + case IMAP_OBJ_POLYGON: + if( aCoords.Count() >=6 ) + { + USHORT nCount = aCoords.Count() / 2; + Polygon aPoly( nCount ); + for( USHORT i=0; i<nCount; i++ ) + aPoly[i] = Point( aCoords[2*i], aCoords[2*i+1] ); + IMapPolygonObject aMapPObj( aPoly, aHRef, aAlt, String(), aTarget, aName, + !bNoHRef ); + if( aMacroTbl.Count() ) + aMapPObj.SetMacroTable( aMacroTbl ); + pImageMap->InsertIMapObject( aMapPObj ); + } + break; + default: + bNewArea = FALSE; + } + + return bNewArea; +} + + +void SfxHTMLParser::StartFileDownload( const String& rURL, int nToken, + SfxObjectShell *pSh ) +{ + DBG_ASSERT( !pDLMedium, "StartFileDwonload bei aktivem Download" ); + if( pDLMedium ) + return; + + pDLMedium = new SfxMedium( rURL, SFX_STREAM_READONLY, FALSE ); + if( pSh ) + { + // Medium registrieren, damit abgebrochen werden kann + pSh->RegisterTransfer( *pDLMedium ); + + // Target-Frame uebertragen, damit auch javascript:-URLs + // "geladen" werden koennen. + //const SfxMedium *pShMedium = pSh->GetMedium(); + //if( pShMedium ) + // pDLMedium->SetLoadTargetFrame( pShMedium->GetLoadTargetFrame() ); + } + + // Download anstossen (Achtung: Kann auch synchron sein). + if ( TRUE /*pMedium->GetDoneLink() == Link()*/ ) + pDLMedium->DownLoad(); + else + { + // Downloading-Flag auf TRUE setzen. Es werden dann auch + // Data-Available-Links, wenn wir in den Pending-Staus gelangen. + SetDownloadingFile( TRUE ); + pDLMedium->DownLoad( STATIC_LINK( this, SfxHTMLParser, FileDownloadDone ) ); + + // Wenn das Dowsnloading-Flag noch gesetzt ist erfolgt der Download + // asynchron. Wir gehen dann in den Pedning-Staus und warten dort. + // Solange sind alle Aufrufe des Data-Avaialble-Link gesperrt. + if( IsDownloadingFile() ) + { + // Den aktuellen Zustand einfrieren und in den Pending-Status gehen. + // Wenn der Download beendet oder abgebrochen wurde, wird ueber + // NewDataRead ein Continue mit dem uebergeben Token angesteossen. + SaveState( nToken ); + eState = SVPAR_PENDING; + } + } +} + +BOOL SfxHTMLParser::GetFileDownloadMIME( String& rMIME ) +{ + return pDLMedium && pDLMedium->GetErrorCode()==0 && + pDLMedium->GetMIMEAndRedirect(rMIME)==0; +} + +BOOL SfxHTMLParser::FinishFileDownload( String& rStr ) +{ + String aStr; + + BOOL bOK = pDLMedium && pDLMedium->GetErrorCode()==0; + if( bOK ) + { + SvStream* pStream = pDLMedium->GetInStream(); + DBG_ASSERT( pStream, "Kein In-Stream vom Medium erhalten" ); + + SvMemoryStream aStream; + if( pStream ) // HACK wegen #65563# + aStream << *pStream; + + aStream.Seek( STREAM_SEEK_TO_END ); + DBG_ASSERT( aStream.Tell() < STRING_MAXLEN, + "File zu lang fuer einen String, Ende abgeschnitten" ); + xub_StrLen nLen = aStream.Tell() < STRING_MAXLEN + ? (xub_StrLen)aStream.Tell() + : STRING_MAXLEN; + + // TODO: untested!!! + rtl_TextEncoding eEnc = + GetExtendedCompatibilityTextEncoding( RTL_TEXTENCODING_ISO_8859_1 ); + String sMime; + if( pDLMedium->GetMIMEAndRedirect( sMime ) == 0 ) + { + rtl_TextEncoding eMimeEnc = GetEncodingByMIME( sMime ); + if( RTL_TEXTENCODING_DONTKNOW != eMimeEnc ) + eEnc = eMimeEnc; + } + + ByteString sBuffer; + sal_Char* pBuffer = sBuffer.AllocBuffer(nLen); + aStream.Seek( 0 ); + aStream.Read((void*)pBuffer, nLen); + rStr = String( S2U(pBuffer) ); + } + + delete pDLMedium; + pDLMedium = 0; + + return bOK; +} + +IMPL_STATIC_LINK( SfxHTMLParser, FileDownloadDone, void*, EMPTYARG ) +{ + // Der Download ist jetzt abgeschlossen. Ausserdem muss/darf der + // Data-Available-Link wieder durchgelassen werden. + pThis->SetDownloadingFile( FALSE ); + + // ... und einmal aufrufen, damit weitergelesen wird. + pThis->CallAsyncCallLink(); + + return 0; +} + +void SfxHTMLParser::GetScriptType_Impl( SvKeyValueIterator *pHTTPHeader ) +{ + aScriptType = DEFINE_CONST_UNICODE(SVX_MACRO_LANGUAGE_JAVASCRIPT); + eScriptType = JAVASCRIPT; + if( pHTTPHeader ) + { + SvKeyValue aKV; + for( BOOL bCont = pHTTPHeader->GetFirst( aKV ); bCont; + bCont = pHTTPHeader->GetNext( aKV ) ) + { + if( aKV.GetKey().EqualsIgnoreCaseAscii( + OOO_STRING_SVTOOLS_HTML_META_content_script_type ) ) + { + if( aKV.GetValue().Len() ) + { + String aTmp( aKV.GetValue() ); + if( aTmp.EqualsIgnoreCaseAscii( sHTML_MIME_text, 0, 5 ) ) + aTmp.Erase( 0, 5 ); + else if( aTmp.EqualsIgnoreCaseAscii( sHTML_MIME_application, + 0, 12 ) ) + aTmp.Erase( 0, 12 ); + else + break; + + if( aTmp.EqualsIgnoreCaseAscii( sHTML_MIME_experimental, 0, + 2 ) ) + { + aTmp.Erase( 0, 2 ); + } + + if( aTmp.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_LG_starbasic ) ) + { + eScriptType = STARBASIC; + aScriptType = DEFINE_CONST_UNICODE(SVX_MACRO_LANGUAGE_STARBASIC); + } + if( !aTmp.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_LG_javascript ) ) + { + eScriptType = EXTENDED_STYPE; + aScriptType = aTmp; + } + } + break; + } + } + } +} + +ScriptType SfxHTMLParser::GetScriptType( SvKeyValueIterator *pHTTPHeader ) const +{ + if( !aScriptType.Len() ) + ((SfxHTMLParser *)this)->GetScriptType_Impl( pHTTPHeader ); + + return eScriptType; +} + +const String& SfxHTMLParser::GetScriptTypeString( + SvKeyValueIterator *pHTTPHeader ) const +{ + if( !aScriptType.Len() ) + ((SfxHTMLParser *)this)->GetScriptType_Impl( pHTTPHeader ); + + return aScriptType; +} + +double SfxHTMLParser::GetTableDataOptionsValNum( sal_uInt32& nNumForm, + LanguageType& eNumLang, const String& aValStr, const String& aNumStr, + SvNumberFormatter& rFormatter ) +{ + LanguageType eParseLang = (LanguageType )aNumStr.ToInt32(); + sal_uInt32 nParseForm = + rFormatter.GetFormatForLanguageIfBuiltIn( 0, eParseLang ); + double fVal; + rFormatter.IsNumberFormat( aValStr, nParseForm, fVal ); + if ( aNumStr.GetTokenCount( ';' ) > 2 ) + { + eNumLang = (LanguageType)aNumStr.GetToken( 1, ';' ).ToInt32(); + xub_StrLen nPos = aNumStr.Search( ';' ); + nPos = aNumStr.Search( ';', nPos + 1 ); + String aFormat( aNumStr.Copy( nPos + 1 ) ); + xub_StrLen nCheckPos; + short nType; + if ( eNumLang != LANGUAGE_SYSTEM ) + rFormatter.PutEntry( aFormat, nCheckPos, nType, nNumForm, eNumLang ); + else + rFormatter.PutandConvertEntry( aFormat, nCheckPos, nType, nNumForm, + eParseLang, eNumLang ); + } + else + { + eNumLang = LANGUAGE_SYSTEM; + nNumForm = rFormatter.GetFormatForLanguageIfBuiltIn( 0, eNumLang ); + } + return fVal; +} + diff --git a/sfx2/source/bastyp/sfxresid.cxx b/sfx2/source/bastyp/sfxresid.cxx new file mode 100644 index 000000000000..11ab5a724099 --- /dev/null +++ b/sfx2/source/bastyp/sfxresid.cxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sfx2.hxx" + +#ifndef GCC +#endif +#include <tools/simplerm.hxx> + +#include "sfxresid.hxx" +#include <sfx2/app.hxx> + +// ----------------------------------------------------------------------- + +static ResMgr* pMgr=NULL; + +SfxResId::SfxResId( USHORT nId ) : + + ResId( nId, *GetResMgr() ) +{ +} + +//============================================================================ +// +// SfxSimpleResId Implementation. +// +//============================================================================ + +SfxSimpleResId::SfxSimpleResId(USHORT nID): + m_sText( SFX_APP()->GetSimpleResManager()->ReadString(nID) ) +{} + +ResMgr* SfxResId::GetResMgr() +{ + if ( !pMgr ) + { + pMgr = SfxApplication::CreateResManager("sfx"); + } + + return pMgr; +} + +void SfxResId::DeleteResMgr() +{ + DELETEZ( pMgr ); +} + + |